PageRenderTime 48ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/blog/wp-content/themes/chaostheory/functions.php

https://bitbucket.org/sergiohzlz/reportaprod
PHP | 495 lines | 372 code | 77 blank | 46 comment | 56 complexity | c9685c87eb2e11e5045db8541de2eefe MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, AGPL-1.0, LGPL-2.1
  1. <?php
  2. $themecolors = array(
  3. 'bg' => '1B1B1B',
  4. 'border' => '0A0A0A',
  5. 'text' => 'DDDDDD',
  6. 'link' => '6DCFF6'
  7. );
  8. $content_width = 510; // pixels
  9. add_theme_support( 'automatic-feed-links' );
  10. add_custom_background();
  11. register_nav_menus( array(
  12. 'primary' => __( 'Primary Navigation' ),
  13. ) );
  14. // And thus begins the Sandbox guts! Registers our default
  15. // options, specifically loads the 2c-1.css file as default skin
  16. function sandbox_get_option($name) {
  17. $defaults = array(
  18. 'skin' => '2c-l',
  19. );
  20. $options = array_merge($defaults, (array) get_option('sandbox_options'));
  21. if ( isset($options[$name]) )
  22. return $options[$name];
  23. return false;
  24. }
  25. // Andy really goes nuts with arrays, which has been a good thing. Very good.
  26. function sandbox_set_options($new_options) {
  27. $options = (array) get_option('sandbox_options');
  28. $options = array_merge($options, (array) $new_options);
  29. return update_option('sandbox_options', $options);
  30. }
  31. // Template tag: echoes a stylesheet link if one is selected
  32. function sandbox_stylesheets() {
  33. $skin = sandbox_get_option('skin');
  34. if ( $skin != 'none' ) {
  35. ?>
  36. <link rel="stylesheet" type="text/css" media="all" href="<?php echo get_template_directory_uri() . "/skins/$skin.css" ?>" title="Sandbox" />
  37. <?php
  38. }
  39. }
  40. // Template tag: echoes a link to skip navigation if the
  41. // global_navigation option is set to "Y" in the skin file
  42. function sandbox_skipnav() {
  43. if ( !sandbox_get_option('globalnav') )
  44. return;
  45. echo '<p class="access"><a href="#content" title="'.__('Skip navigation to the content', 'chaostheory').'">'.__('Skip navigation', 'chaostheory').'</a></p>';
  46. }
  47. // Template tag: echoes a page list for navigation if the
  48. // global_navigation option is set to "Y" in the skin file
  49. function sandbox_globalnav() {
  50. echo "<div id='globalnav'><ul id='menu'>";
  51. $menu = wp_list_pages('title_li=&sort_column=menu_order&echo=0&depth=1');
  52. echo str_replace(array("\r", "\n", "\t"), '', $menu); // Strip intratag whitespace
  53. echo "</ul></div>";
  54. }
  55. // Template tag: echoes semantic classes in the <body>
  56. function sandbox_body_class( $print = true ) {
  57. global $wp_query, $current_user;
  58. $c = array('wordpress');
  59. sandbox_date_classes(time(), $c);
  60. is_home() ? $c[] = 'home' : null;
  61. is_archive() ? $c[] = 'archive' : null;
  62. is_date() ? $c[] = 'date' : null;
  63. is_search() ? $c[] = 'search' : null;
  64. is_paged() ? $c[] = 'paged' : null;
  65. is_attachment() ? $c[] = 'attachment' : null;
  66. is_404() ? $c[] = 'four04' : null; // CSS does not allow a digit as first character
  67. if ( is_single() ) {
  68. the_post();
  69. $c[] = 'single';
  70. if ( isset($wp_query->post->post_date) )
  71. sandbox_date_classes(mysql2date('U', $wp_query->post->post_date), $c, 's-');
  72. foreach ( (array) get_the_category() as $cat )
  73. $c[] = 's-category-' . $cat->category_nicename;
  74. $c[] = 's-author-' . get_the_author_login();
  75. rewind_posts();
  76. }
  77. else if ( is_author() ) {
  78. $author = $wp_query->get_queried_object();
  79. $c[] = 'author';
  80. $c[] = 'author-' . $author->user_nicename;
  81. }
  82. else if ( is_category() ) {
  83. $cat = $wp_query->get_queried_object();
  84. $c[] = 'category';
  85. $c[] = 'category-' . $cat->category_nicename;
  86. }
  87. else if ( is_page() ) {
  88. the_post();
  89. $c[] = 'page';
  90. $c[] = 'page-author-' . get_the_author_login();
  91. rewind_posts();
  92. }
  93. if ( $current_user->ID )
  94. $c[] = 'loggedin';
  95. $c = join(' ', apply_filters('body_class', $c));
  96. return $print ? print($c) : $c;
  97. }
  98. // Generates semantic classes for each post DIV element
  99. function sandbox_post_class( $print = true ) {
  100. global $post, $sandbox_post_alt;
  101. //gets 'alt' for every other post DIV, describes the post status
  102. $c = array("p$sandbox_post_alt", $post->post_status);
  103. // Author for the post queried
  104. $c[] = 'author-' . sanitize_title_with_dashes(strtolower(get_the_author('login')));
  105. // For password-protected posts
  106. if ( $post->post_password )
  107. $c[] = 'protected';
  108. // Applies the time- and date-based classes (below) to post DIV
  109. sandbox_date_classes(mysql2date('U', $post->post_date), $c);
  110. // If it's the other to the every, then add 'alt' class
  111. if ( ++$sandbox_post_alt % 2 )
  112. $c[] = 'alt';
  113. // Separates classes with a single space, collates classes for post DIV
  114. $c = join(' ', get_post_class( $c, $post->ID ) );
  115. // And tada!
  116. return $print ? print($c) : $c;
  117. }
  118. $sandbox_post_alt = 1;
  119. // Template tag: echoes semantic classes for a comment <li>
  120. function sandbox_comment_class( $print = true ) {
  121. global $comment, $post, $sandbox_comment_alt;
  122. $c = array($comment->comment_type, "c$sandbox_comment_alt");
  123. if ( $comment->user_id > 0 ) {
  124. $user = get_userdata($comment->user_id);
  125. $c[] = "byuser commentauthor-$user->user_login";
  126. if ( $comment->user_id === $post->post_author )
  127. $c[] = 'bypostauthor';
  128. }
  129. sandbox_date_classes(mysql2date('U', $comment->comment_date), $c, 'c-');
  130. if ( ++$sandbox_comment_alt % 2 )
  131. $c[] = 'alt';
  132. if ( is_trackback() ) {
  133. $c[] = 'trackback';
  134. }
  135. $c = join(' ', apply_filters('comment_class', $c));
  136. return $print ? print($c) : $c;
  137. }
  138. // Adds four time- and date-based classes to an array
  139. // with all times relative to GMT (sometimes called UTC)
  140. function sandbox_date_classes($t, &$c, $p = '') {
  141. $t = $t + (get_settings('gmt_offset') * 3600);
  142. $c[] = $p . 'y' . gmdate('Y', $t); // Year
  143. $c[] = $p . 'm' . gmdate('m', $t); // Month
  144. $c[] = $p . 'd' . gmdate('d', $t); // Day
  145. $c[] = $p . 'h' . gmdate('h', $t); // Hour
  146. }
  147. // Returns a list of the post's categories, minus the queried one
  148. function sandbox_cats_meow($glue) {
  149. $current_cat = single_cat_title('', false);
  150. $separator = "\n";
  151. $cats = explode($separator, get_the_category_list($separator));
  152. foreach ( $cats as $i => $str ) {
  153. if ( strstr($str, ">$current_cat<") ) {
  154. unset($cats[$i]);
  155. break;
  156. }
  157. }
  158. if ( empty($cats) )
  159. return false;
  160. return trim(join($glue, $cats));
  161. }
  162. // Sandbox widgets: Replaces the default search widget with one
  163. // that matches what is in the Sandbox sidebar by default
  164. function widget_sandbox_search($args) {
  165. extract($args);
  166. if ( empty($title) )
  167. $title = __('Search', 'chaostheory');
  168. ?>
  169. <?php echo $before_widget ?>
  170. <?php echo $before_title ?><label for="s"><?php echo $title ?></label><?php echo $after_title ?>
  171. <form id="searchform" method="get" action="<?php bloginfo('url') ?>">
  172. <div>
  173. <input id="s" name="s" type="text" value="<?php the_search_query(); ?>" size="10" />
  174. <input id="searchsubmit" name="searchsubmit" type="submit" value="<?php esc_attr_e( 'Find &raquo;', 'chaostheory' ); ?>" />
  175. </div>
  176. </form>
  177. <?php echo $after_widget ?>
  178. <?php
  179. }
  180. // Sandbox widgets: Replaces the default meta widget with one
  181. // that matches what is in the Sandbox sidebar by default
  182. function widget_sandbox_meta($args) {
  183. extract($args);
  184. if ( empty($title) )
  185. $title = __('Meta', 'chaostheory');
  186. ?>
  187. <?php echo $before_widget; ?>
  188. <?php echo $before_title . $title . $after_title; ?>
  189. <ul>
  190. <?php wp_register() ?>
  191. <li><?php wp_loginout() ?></li>
  192. <?php wp_meta() ?>
  193. </ul>
  194. <?php echo $after_widget; ?>
  195. <?php
  196. }
  197. // Sandbox widgets: Adds the Sandbox's home link as a widget, which
  198. // appears when NOT on the home page OR on a page of the home page
  199. function widget_sandbox_homelink($args) {
  200. extract($args);
  201. $options = get_option('widget_sandbox_homelink');
  202. $title = empty($options['title']) ? __('&laquo; Home') : $options['title'];
  203. ?>
  204. <?php if ( !is_home() || is_paged() ) { ?>
  205. <?php echo $before_widget; ?>
  206. <?php echo $before_title ?><a href="<?php bloginfo('url') ?>" title="<?php echo esc_attr( get_bloginfo( 'name' ) ); ?>"><?php echo $title ?></a><?php echo $after_title ?>
  207. <?php echo $after_widget; ?>
  208. <?php } ?>
  209. <?php
  210. }
  211. // Sandbox widgets: Adds the option to set the text for the home link widget
  212. function widget_sandbox_homelink_control() {
  213. $options = $newoptions = get_option('widget_sandbox_homelink');
  214. if ( $_POST["homelink-submit"] ) {
  215. $newoptions['title'] = strip_tags(stripslashes($_POST["homelink-title"]));
  216. }
  217. if ( $options != $newoptions ) {
  218. $options = $newoptions;
  219. update_option('widget_sandbox_homelink', $options);
  220. }
  221. $title = esc_attr( $options['title'] );
  222. ?>
  223. <p style="text-align:left;"><?php _e('Adds a link to the home page on every page <em>except</em> the home.', 'chaostheory'); ?></p>
  224. <p>
  225. <label for="homelink-title">
  226. <?php _e('Link Text:'); ?>
  227. <input class="widefat" id="homelink-title" name="homelink-title" type="text" value="<?php echo $title; ?>" />
  228. </label>
  229. </p>
  230. <input type="hidden" id="homelink-submit" name="homelink-submit" value="1" />
  231. <?php
  232. }
  233. // Sandbox widgets: Adds a widget with the Sandbox RSS links
  234. // as they appear in the default Sandbox sidebar, which are good
  235. function widget_sandbox_rsslinks($args) {
  236. extract($args);
  237. $options = get_option('widget_sandbox_rsslinks');
  238. $title = empty($options['title']) ? __('RSS Links') : $options['title'];
  239. ?>
  240. <?php echo $before_widget; ?>
  241. <?php echo $before_title . $title . $after_title; ?>
  242. <ul>
  243. <li><a href="<?php bloginfo('rss2_url') ?>" title="<?php echo esc_attr( get_bloginfo( 'name' ) ); ?> RSS 2.0 Feed" rel="alternate" type="application/rss+xml"><?php _e('All posts', 'chaostheory') ?></a></li>
  244. <li><a href="<?php bloginfo('comments_rss2_url') ?>" title="<?php echo esc_attr( get_bloginfo( 'name' ) ); ?> Comments RSS 2.0 Feed" rel="alternate" type="application/rss+xml"><?php _e('All comments', 'chaostheory') ?></a></li>
  245. </ul>
  246. <?php echo $after_widget; ?>
  247. <?php
  248. }
  249. // Sandbox widgets: Adds the option to set the text for the RSS link widget
  250. function widget_sandbox_rsslinks_control() {
  251. $options = $newoptions = get_option('widget_sandbox_rsslinks');
  252. if ( $_POST["rsslinks-submit"] ) {
  253. $newoptions['title'] = strip_tags(stripslashes($_POST["rsslinks-title"]));
  254. }
  255. if ( $options != $newoptions ) {
  256. $options = $newoptions;
  257. update_option('widget_sandbox_rsslinks', $options);
  258. }
  259. $title = esc_attr( $options['title'] );
  260. ?>
  261. <p>
  262. <label for="rsslinks-title">
  263. <?php _e('Title:'); ?>
  264. <input class="widefat" id="rsslinks-title" name="rsslinks-title" type="text" value="<?php echo $title; ?>" />
  265. </label>
  266. </p>
  267. <input type="hidden" id="rsslinks-submit" name="rsslinks-submit" value="1" />
  268. <?php
  269. }
  270. // Template tag & Sandbox widget: Creates a string to produce
  271. // links in either WP 2.1 or then WP 2.0 style, relative to install
  272. function widget_sandbox_links() {
  273. wp_list_bookmarks(array('title_before'=>'<h3>', 'title_after'=>'</h3>', 'show_images'=>true));
  274. }
  275. // Sandbox skins menu: creates the array to collect
  276. // information from the skins currently installed
  277. function sandbox_skin_info($skin) {
  278. $info = array(
  279. 'skin_name' => $skin,
  280. 'skin_uri' => '',
  281. 'description' => '',
  282. 'version' => '1.0',
  283. 'author' => __('Anonymous', 'chaostheory'),
  284. 'author_uri' => '',
  285. 'global_navigation' => 'Y',
  286. );
  287. if ( !file_exists(ABSPATH."wp-content/themes/sandbox/skins/$skin.css") )
  288. return array();
  289. $css = (array) file(ABSPATH."wp-content/themes/sandbox/skins/$skin.css");
  290. foreach ( $css as $line ) {
  291. if ( strstr($line, '*/') )
  292. return $info;
  293. if ( !strstr($line, ':') )
  294. continue;
  295. list ( $k, $v ) = explode(':', $line, 2);
  296. $k = str_replace(' ', '_', strtolower(trim($k)));
  297. if ( array_key_exists($k, $info) )
  298. $info[$k] = stripslashes(wp_filter_kses(trim($v)));
  299. }
  300. }
  301. // Sandbox skins menu: Registers the workings of the skins menu
  302. function sandbox_admin_skins() {
  303. $skins = array();
  304. if ( isset ( $_GET['message'] ) ) {
  305. switch ( $_GET['message'] ) {
  306. case 'updated' :
  307. echo "\n<div id='message' class='updated fade'><p>".__('Sandbox skin saved successfully.', 'chaostheory')."</p></div>\n";
  308. break;
  309. }
  310. }
  311. $current_skin = sandbox_get_option('skin');
  312. $_skins = glob(ABSPATH.'wp-content/themes/sandbox/skins/*.css');
  313. foreach ( $_skins as $k => $v ) {
  314. $info = array();
  315. preg_match('/\/([^\/]+).css$/i', $v, $matches);
  316. if ( !empty($matches[1]) ) {
  317. $skins[$matches[1]] = sandbox_skin_info($matches[1]);
  318. }
  319. }
  320. ?>
  321. <script type="text/javascript">
  322. <!-- function showme(o) { document.getElementById('show').src = o.src; } //-->
  323. </script>
  324. <div class="wrap">
  325. <h2><?php _e('Current Skin', 'chaostheory') ?></h2>
  326. <div id="currenttheme">
  327. <?php if ( file_exists(get_template_directory() . "/skins/$current_skin.png") ) : ?>
  328. <img src="<?php echo get_template_directory_uri() . "/skins/$current_skin.png"; ?>" alt="<?php _e('Current skin preview', 'chaostheory'); ?>" />
  329. <?php endif; ?>
  330. <?php
  331. if ( is_array($skins[$current_skin]) )
  332. extract($skins[$current_skin]);
  333. if ( !empty($skin_uri) )
  334. $skin_name = "<a href=\"$skin_uri\" title=\"$skin_name by $author\">$skin_name</a>";
  335. if ( !empty($author_uri) )
  336. $author = "<a href=\"$author_uri\" title=\"$author\">$author</a>";
  337. ?>
  338. <h3><?php printf(__('%1$s %2$s by %3$s'), $skin_name, $version, $author) ; ?></h3>
  339. <p><?php echo $description; ?></p>
  340. </div>
  341. <div class="clearer" style="clear:both;"></div>
  342. <h2><?php _e('Available Skins', 'chaostheory') ?></h2>
  343. <?php
  344. foreach ( $skins as $skin => $info ) :
  345. if ( $skin == $current_skin || !is_array($info) )
  346. continue;
  347. extract($info);
  348. $activate_link = "themes.php?page=skins&amp;action=activate&amp;skin=$skin";
  349. // wp_nonce_url first introduced in WP 2.0.3
  350. if ( function_exists('wp_nonce_url') )
  351. $activate_link = wp_nonce_url($activate_link, 'switch-skin_' . $skin);
  352. ?>
  353. <div class="available-theme">
  354. <h3><a href="<?php echo $activate_link; ?>" title="Activate the <?php echo "$skin_name"; ?> skin"><?php echo "$skin_name $version"; ?></a></h3>
  355. <a href="<?php echo $activate_link; ?>" class="screenshot" title="Activate the <?php echo "$skin_name"; ?> skin">
  356. <?php if ( file_exists(get_template_directory() . "/skins/$skin.png" ) ) : ?>
  357. <img src="<?php echo get_template_directory_uri() . "/skins/$skin.png"; ?>" alt="<?php echo "$skin_name"; ?>" />
  358. <?php endif; ?>
  359. </a>
  360. <p><?php echo $description; ?></p>
  361. </div>
  362. <?php endforeach; ?>
  363. <h2><?php _e('Sandbox Info', 'chaostheory'); ?></h2>
  364. <p><?php printf(__('Check the <a href="%1$s" title="Read the Sandbox readme.html">documentation</a> for help installing new skins and information on the rich semantic markup that makes the Sandbox unique.', 'chaostheory'), get_template_directory_uri() . '/readme.html'); ?></p>
  365. </div>
  366. <?php
  367. }
  368. // Sandbox skins menu: initializes the settings for the skins menu
  369. function sandbox_init() {
  370. load_theme_textdomain('chaostheory');
  371. if ( $GLOBALS['pagenow'] == 'themes.php'
  372. && isset($_GET['page']) && $_GET['page'] == 'skins'
  373. && isset($_GET['action']) && $_GET['action'] == 'activate'
  374. && current_user_can('edit_theme_options') ) {
  375. check_admin_referer('switch-skin_' . $_GET['skin']);
  376. $info = sandbox_skin_info($_GET['skin']);
  377. sandbox_set_options(array(
  378. 'skin' => wp_filter_kses($_GET['skin']),
  379. 'globalnav' => bool_from_yn($info['global_navigation'])
  380. ));
  381. wp_redirect('themes.php?page=skins&message=updated');
  382. }
  383. }
  384. // Sandbox skins menu: tells WordPress (nicely) to load the skins menu
  385. function sandbox_admin_menu() {
  386. add_theme_page(__('Theme Options', 'chaostheory'), __('Theme Options', 'chaostheory'), 'edit_theme_options', 'skins', 'sandbox_admin_skins');
  387. }
  388. // Sandbox widgets: initializes Widgets for the Sandbox
  389. function sandbox_widgets_init() {
  390. // Overrides the Widgets default and uses <h3>'s for sidebar headings
  391. $p = array(
  392. 'before_title' => "<h3 class='widgettitle'>",
  393. 'after_title' => "</h3>\n",
  394. );
  395. // How many? Two?! That's it?
  396. register_sidebars(2, $p);
  397. // Registers the widgets specific to the Sandbox, as set earlier
  398. unregister_widget('WP_Widget_Search');
  399. wp_register_sidebar_widget('search', __('Search', 'chaostheory'), 'widget_sandbox_search');
  400. unregister_widget('WP_Widget_Meta');
  401. wp_register_sidebar_widget('meta', __('Meta', 'chaostheory'), 'widget_sandbox_meta');
  402. unregister_widget('WP_Widget_Links');
  403. wp_register_sidebar_widget('links', __('Links', 'chaostheory'), 'widget_sandbox_links');
  404. register_sidebar_widget(array('Home Link', 'widgets'), 'widget_sandbox_homelink');
  405. register_widget_control(array('Home Link', 'widgets'), 'widget_sandbox_homelink_control', null, 125);
  406. register_sidebar_widget(array('RSS Links', 'widgets'), 'widget_sandbox_rsslinks');
  407. register_widget_control(array('RSS Links', 'widgets'), 'widget_sandbox_rsslinks_control', null, 90);
  408. }
  409. // Runs our code at the end to check that everything needed has loaded
  410. add_action('init', 'sandbox_init', 1);
  411. add_action('widgets_init', 'sandbox_widgets_init');
  412. #add_action('admin_menu', 'sandbox_admin_menu');
  413. // Adds filters for greater compliance
  414. add_filter('archive_meta', 'wptexturize');
  415. add_filter('archive_meta', 'convert_smilies');
  416. add_filter('archive_meta', 'convert_chars');
  417. add_filter('archive_meta', 'wpautop');
  418. ?>