Advertisement
Guest User

Function php code for request

a guest
Apr 29th, 2013
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.83 KB | None | 0 0
  1. <?php
  2. /**
  3. * Socrates Premium Theme for Wordpress
  4. * (c) 2012 Handy Investments LLC
  5. * http://www.socratestheme.com
  6. * Version 3.04
  7. *
  8. * @File functions.php
  9. *
  10. *
  11. Theme Name: Socrates
  12. */
  13. $CURRENT_VERSION = '3.04';
  14.  
  15. // Set path to theme specific functions
  16. $functions_path = TEMPLATEPATH . '/functions/';
  17.  
  18. // Theme Options Panel
  19. require_once($functions_path . 'panel/themeoptions.php');
  20.  
  21. // General
  22. add_theme_support('post-thumbnails'); // Featured Image Support
  23. require_once($functions_path . 'sidebars.php'); // Register Sidebars
  24. require_once($functions_path . 'menus.php'); // Menus WP 3.0
  25. require_once($functions_path . 'native.php'); // Native Image Sizing
  26. require_once($functions_path . 'load-scripts.php'); // Load Scripts and CSS
  27. require_once($functions_path . 'excerpts.php'); // Excerpt Lengths
  28. require_once($functions_path . 'custom-fields.php'); // Custom Fields
  29. require_once($functions_path . 'pagenavi.php'); // Custom Fields
  30.  
  31. // Drag and Drop Contact Forms
  32. require_once($functions_path . 'ajax-contact/ajax-contact.php');
  33.  
  34. // Shortcodes
  35. require_once($functions_path . 'shortcodes/shortcodes.php'); // Shortcodes
  36. require_once($functions_path . 'shortcodes/buttons-shortcode.php'); // Button Shortcode
  37. require_once($functions_path . 'shortcodes/framed-box.php'); // Framed Box Shortcode
  38. require_once($functions_path . 'shortcodes/action.php'); // Action
  39. require_once($functions_path . 'shortcodes/testimonials.php'); // Testimonial Slider
  40. require_once($functions_path . 'widgets/video-sidebar-widgets/video-sidebar-widgets.php'); // Video Widget
  41.  
  42. // Shortcode Editor Buttons
  43. require_once($functions_path . 'shortcodes/editor/buttons/tinyMCE.php');
  44. require_once($functions_path . 'shortcodes/editor/testimonial/tinyMCE.php');
  45. require_once($functions_path . 'shortcodes/editor/alert/tinyMCE.php');
  46.  
  47. if (!function_exists('file_put_contents_socrates')) {
  48. function file_put_contents_socrates($filename, $data) {
  49. $f = @fopen($filename, 'w');
  50. if (!$f) {
  51. return false;
  52. } else {
  53. $bytes = fwrite($f, $data);
  54. fclose($f);
  55. return $bytes;
  56. }
  57. }
  58. }
  59.  
  60. if (!function_exists('file_get_contents_socrates')) {
  61. function file_get_contents_socrates($url) {
  62. $timeout = 30;
  63. $curl = curl_init();
  64.  
  65. curl_setopt($curl, CURLOPT_URL, $url);
  66. curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
  67. curl_setopt($curl, CURLOPT_USERAGENT, sprintf("Mozilla/%d.0", rand(4, 5)));
  68. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  69. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
  70. $html = curl_exec($curl);
  71. curl_close($curl);
  72. return $html;
  73. }
  74.  
  75. }
  76.  
  77. function is_active($silent = false) {
  78. $activation = get_option("socratesactivation");
  79. $activationcache = get_option("socratesactivationcache");
  80. $version = get_option("socratesversion");
  81. if (!is_array($activation)) {return false;} else if ( ($activationcache['time'] > (time()-86400)) && ($activationcache[0] == 'SUCCESS')) {return true;}
  82. else {
  83. $curl_handle = curl_init();
  84. $activateurl = 'http://drm.socratestheme.com/validate.php?code=' . $activation['code'] . '&sitelocation=' . get_bloginfo('url') . '&version=' . $version['version'];
  85. curl_setopt($curl_handle, CURLOPT_URL, $activateurl);
  86. curl_setopt($curl_handle, CURLOPT_TIMEOUT, '3');
  87. curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
  88. $buffer = curl_exec($curl_handle);
  89. curl_close($curl_handle);
  90. $newVersion = FALSE;
  91. if (empty($buffer)) {$buffer = 'UNKNOWN';}
  92. else {
  93. $split = explode('%', $buffer);$split['time'] = time();
  94. update_option("socratesactivationcache", $split);
  95. if ((count($split) == 3) && ($split[0] == 'SUCCESS')) {
  96. return true;
  97. } else {
  98. if (!$silent) {
  99. echo '<strong>Activation Error: ' . $split[1] . '</strong><br>';
  100. }
  101. return false;
  102. }
  103. }
  104. }
  105. return true;
  106. }
  107.  
  108. function soc_activate_form() {
  109. $activation = get_option("socratesactivation");
  110. if ($_POST['activate-submit']) {
  111. $activation['code'] = $_POST['soc-activationcode'];
  112. update_option("socratesactivation", $activation);
  113. } else {
  114. echo '<form name="socrates" method="post" enctype="multipart/form-data" action="' . $_SERVER['REQUEST_URI'] . '">';
  115. echo '<input type="text" name="soc-activationcode" id="soc-activationcode" value="' . $activation['code'] . '">';
  116. echo '<input type="hidden" id="activate-submit" name="activate-submit" value="1">';
  117.  
  118. echo '<input name="save" value="Activate" type="submit">';
  119. echo '</form>';
  120. }
  121. }
  122.  
  123.  
  124. function socrates_dashboard_widget_function() {
  125. global $CURRENT_VERSION,$wpdb;
  126.  
  127. include_once(ABSPATH . WPINC . '/rss.php');
  128. $rss_feed = "http://www.socratestheme.com/dashboard/rss.xml";
  129. if ($_POST['activate-submit']) {
  130. soc_activate_form();
  131. }
  132. echo "<div id='identity'></div>";
  133. if (!is_active()) {
  134. $_POST['activate-submit'] = false;
  135. echo "<b>ENTER ACTIVATION CODE:</b> This copy of Socrates is not active, please activate it by entering your Activation code below:";
  136. soc_activate_form();
  137. } else {
  138. $curl_handle = curl_init();
  139. curl_setopt($curl_handle, CURLOPT_URL, 'http://www.socratestheme.com/dashboard/currentversion.html');
  140. curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
  141. $buffer = curl_exec($curl_handle);
  142. curl_close($curl_handle);
  143. $newVersion = FALSE;
  144. if (empty($buffer)) {
  145. $buffer = 'UNKNOWN';
  146. } else {
  147. $result = preg_match('/[0-9]+\.[0-9]+/', $buffer);
  148. if ($result == FALSE) {
  149. $buffer = 'REGEX_ERROR';
  150. } else if ($result == 0) {
  151. $buffer = 'REGEX_MISMATCH';
  152. } else if ($result == 1) {
  153. if ($CURRENT_VERSION < $buffer) {
  154. $newVersion = TRUE;
  155. }
  156. }
  157. }
  158.  
  159. if ($newVersion == TRUE) {
  160. echo '<strong>An updated version of the Socrates theme is available <a href="http://www.socratestheme.com/downloads">here.</a></strong><br>';
  161. } else {
  162. echo 'Your installation is up to date. ';
  163. }
  164.  
  165. echo 'Installed Version: ' . $CURRENT_VERSION . ' Latest Version: ' . $buffer . '<br><br>';
  166. echo "<ul>";
  167.  
  168. $rss = fetch_rss($rss_feed);
  169. $rss->items = array_slice($rss->items, 0, 6);
  170. $channel = $rss->channel;
  171.  
  172. foreach ($rss->items as $item) {
  173. $parsed_url = parse_url(wp_filter_kses($item['link']));
  174. echo "<li><b><a href=" . wp_filter_kses($item['link']) . ">" . wptexturize(wp_specialchars($item['title'])) . "</a></b></li>";
  175. }
  176. echo "</ul>";
  177. $activation = get_option("socratesactivation");
  178. $activationcache = get_option("socratesactivationcache");
  179. echo '<br>' . $activationcache[1] . '<br>';
  180. echo 'Activation Code: ' . $activation['code'];
  181. }
  182. }
  183.  
  184.  
  185. function socrates_activation_widget_function() {
  186. global $wpdb;
  187. echo "<div id='identity'></div>";
  188. echo '<style>.socactivation {background:#FFFFFF; display:block; z-index:99; top:0; left:0; bottom:0; right:0; margin:0; padding:0; position:absolute; color:#000000; width:100%; height:100%;}</style>';
  189. $activation = get_option("socratesactivation");
  190. $version = get_option("socratesversion");
  191. if (!is_array($activation)) {
  192. echo '<div class="socactivation">Please enter your activation code</div>';
  193. } else {
  194. $curl_handle = curl_init();
  195. $activateurl = 'http://drm.socratestheme.com/validate.php?code=' . $activation['code'] . '&sitelocation=' . get_bloginfo('url') . '&version=' . $version['version'];
  196. curl_setopt($curl_handle, CURLOPT_URL, $activateurl);
  197. curl_setopt($curl_handle, CURLOPT_TIMEOUT, '3');
  198. curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
  199. $buffer = curl_exec($curl_handle);
  200. curl_close($curl_handle);
  201. $newVersion = FALSE;
  202. if (empty($buffer)) {
  203. $buffer = 'UNKNOWN';
  204. } else {
  205. $split = explode('%', $buffer);
  206. if (count($split) == 2) {
  207. if ($split[0] == 'SUCCESS') {
  208. echo $split[1];
  209. } else {
  210. echo '<div class="socactivation">' . $split[0] . '<br>' . $split[1] . '<br><br>Please enter your activation code</div>';
  211. }
  212. }
  213. }
  214. }
  215.  
  216.  
  217. }
  218.  
  219. function custom_footer() {
  220. ?>
  221. <p class="credit"><a href="http://iwp.ro" title="Wordpress Tutorials">Wordpress Tutorials</a> | <a href="http://www.dream-webdesign.ro" title="Design web">Design web</a> | <a href="http://valanz.com" title="Free website design">Free website design</a> | <a href="http://iwp.ro/site-gratis" title="Site Gratis">Site Gratis</a></p>
  222. <?php }
  223.  
  224. // Create the function use in the action hook
  225.  
  226. function add_socrates_dashboard_widget() {
  227. global $CURRENT_VERSION;
  228. $versionSetting['version'] = $CURRENT_VERSION;
  229.  
  230. update_option("socratesversion", $versionSetting);
  231. wp_add_dashboard_widget('socrates_dashboard_widget', 'Socrates Theme News', 'socrates_dashboard_widget_function');
  232. // Globalize the metaboxes array, this holds all the widgets for wp-admin
  233.  
  234. global $wp_meta_boxes;
  235.  
  236. // Get the regular dashboard widgets array
  237. // (which has our new widget already but at the end)
  238.  
  239. $normal_dashboard = $wp_meta_boxes['dashboard']['normal']['core'];
  240.  
  241. // Backup and delete our new dashbaord widget from the end of the array
  242.  
  243. $example_widget_backup = array(
  244. 'socrates_dashboard_widget' => $normal_dashboard['socrates_dashboard_widget']
  245. );
  246. unset($normal_dashboard['socrates_dashboard_widget']);
  247.  
  248. // Merge the two arrays together so our widget is at the beginning
  249.  
  250. $sorted_dashboard = array_merge($example_widget_backup, $normal_dashboard);
  251.  
  252. // Save the sorted array back into the original metaboxes
  253.  
  254. $wp_meta_boxes['dashboard']['normal']['core'] = $sorted_dashboard;
  255.  
  256. }
  257.  
  258. // Hook into the 'wp_dashboard_setup' action to register our other functions
  259.  
  260. add_action('wp_dashboard_setup', 'add_socrates_dashboard_widget');
  261.  
  262. function customize_meta_boxes() {
  263. //retrieve current user info
  264. global $current_user;
  265. get_currentuserinfo();
  266.  
  267. //if current user level is less than 3, remove the postcustom meta box
  268. if ($current_user->user_level < 10)
  269. remove_meta_box('socrates_dashboard_widget', 'dashboard', 'normal');
  270. }
  271.  
  272. add_action('admin_init', 'customize_meta_boxes');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement