PageRenderTime 50ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/sergiohzlz/reportaprod
PHP | 510 lines | 370 code | 79 blank | 61 comment | 49 complexity | d9931b9b1fdbcbc050be9173805f632d MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, AGPL-1.0, LGPL-2.1
  1. <?php
  2. /*
  3. This file is part of SANDBOX.
  4. SANDBOX is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version.
  5. SANDBOX is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  6. You should have received a copy of the GNU General Public License along with SANDBOX. If not, see http://www.gnu.org/licenses/.
  7. */
  8. $content_width = 530;
  9. $themecolors = array(
  10. 'bg' => 'fff',
  11. 'border' => 'BC0404',
  12. 'text' => '000000',
  13. 'link' => 'BC0404',
  14. 'url' => 'D5A8A8'
  15. );
  16. function notes_comments( $comment, $args, $depth ) {
  17. $GLOBALS['comment'] = $comment;
  18. extract( $args, EXTR_SKIP );
  19. global $notes_comments_alt;
  20. ?>
  21. <li id="comment-<?php comment_ID(); ?>" class="<?php notesil_comment_class(); ?>">
  22. <div class="singlecomment" id="div-comment-<?php comment_ID(); ?>">
  23. <div class="comment-meta"><?php notesil_commenter_link(); ?>
  24. <span class="comment-date">&nbsp;<?php printf( __( 'On %1$s at %2$s', 'notesil' ), get_comment_date(), get_comment_time() ); ?></span>
  25. <div class="comment-actions"><?php printf( __( '<a href="%s" title="Permalink to this comment">Permalink</a>', 'notesil' ), '#comment-' . get_comment_ID() );
  26. echo comment_reply_link(array( 'depth' => $depth, 'max_depth' => $args['max_depth'], 'before' => ' | ' ) );
  27. edit_comment_link( __( 'Edit', 'notesil' ), ' <span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?>
  28. </div>
  29. </div>
  30. <?php if ( $comment->comment_approved == '0' ) _e("\t\t\t\t\t<span class='unapproved'>Your comment is awaiting moderation.</span>\n", 'notesil' ); ?>
  31. <?php comment_text(); ?>
  32. </div>
  33. <?php }
  34. function notes_trackbacks( $comment, $args, $depth ) {
  35. $GLOBALS['comment'] = $comment;
  36. extract( $args, EXTR_SKIP );
  37. global $notes_comments_alt;
  38. ?>
  39. <li id="comment-<?php comment_ID(); ?>" class="<?php notesil_comment_class(); ?>">
  40. <div class="singlecomment">
  41. <div class="comment-author"><?php printf( __( 'By %1$s on %2$s at %3$s', 'notesil' ),
  42. get_comment_author_link(),
  43. get_comment_date(),
  44. get_comment_time() );
  45. edit_comment_link( __( 'Edit', 'notesil' ), ' <span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?></div>
  46. <?php if ( $comment->comment_approved == '0' ) _e( '\t\t\t\t\t<span class="unapproved">Your trackback is awaiting moderation.</span>\n', 'notesil' ); ?>
  47. <?php comment_text(); ?>
  48. </div>
  49. <?php }
  50. function notesil_globalnav() {
  51. if ( $menu = str_replace( array( "\r", "\n", "\t" ), '', wp_list_pages( 'title_li=&sort_column=menu_order&echo=0' ) ) )
  52. $menu = '<ul>' . $menu . '</ul>';
  53. $menu = '<div id="menu">' . $menu . "</div>\n";
  54. echo apply_filters( 'globalnav_menu', $menu ); // Filter to override default globalnav: globalnav_menu
  55. }
  56. // Generates semantic classes for BODY element
  57. function notesil_body_class( $print = true ) {
  58. global $wp_query, $current_user;
  59. // It's surely a WordPress blog, right?
  60. $c = array( 'wordpress' );
  61. // Applies the time- and date-based classes (below) to BODY element
  62. notesil_date_classes( time(), $c );
  63. // Generic semantic classes for what type of content is displayed
  64. is_front_page() ? $c[] = 'home' : null; // For the front page, if set
  65. is_home() ? $c[] = 'blog' : null; // For the blog posts page, if set
  66. is_archive() ? $c[] = 'archive' : null;
  67. is_date() ? $c[] = 'date' : null;
  68. is_search() ? $c[] = 'search' : null;
  69. is_paged() ? $c[] = 'paged' : null;
  70. is_attachment() ? $c[] = 'attachment' : null;
  71. is_404() ? $c[] = 'four04' : null; // CSS does not allow a digit as first character
  72. // Special classes for BODY element when a single post
  73. if ( is_single() ) {
  74. $postID = $wp_query->post->ID;
  75. the_post();
  76. // Adds 'single' class and class with the post ID
  77. $c[] = 'single postid-' . $postID;
  78. // Adds classes for the month, day, and hour when the post was published
  79. if ( isset( $wp_query->post->post_date ) )
  80. notesil_date_classes( mysql2date( 'U', $wp_query->post->post_date ), $c, 's-' );
  81. // Adds category classes for each category on single posts
  82. if ( $cats = get_the_category() )
  83. foreach ( $cats as $cat )
  84. $c[] = 's-category-' . $cat->slug;
  85. // Adds tag classes for each tags on single posts
  86. if ( $tags = get_the_tags() )
  87. foreach ( $tags as $tag )
  88. $c[] = 's-tag-' . $tag->slug;
  89. // Adds MIME-specific classes for attachments
  90. if ( is_attachment() ) {
  91. $mime_type = get_post_mime_type();
  92. $mime_prefix = array( 'application/', 'image/', 'text/', 'audio/', 'video/', 'music/' );
  93. $c[] = 'attachmentid-' . $postID . ' attachment-' . str_replace( $mime_prefix, "", "$mime_type" );
  94. }
  95. // Adds author class for the post author
  96. $c[] = 's-author-' . sanitize_title_with_dashes(strtolower(get_the_author_meta( 'login' )) );
  97. rewind_posts();
  98. }
  99. // Author name classes for BODY on author archives
  100. elseif ( is_author() ) {
  101. $author = $wp_query->get_queried_object();
  102. $c[] = 'author';
  103. $c[] = 'author-' . $author->user_nicename;
  104. }
  105. // Category name classes for BODY on category archvies
  106. elseif ( is_category() ) {
  107. $cat = $wp_query->get_queried_object();
  108. $c[] = 'category';
  109. $c[] = 'category-' . $cat->slug;
  110. }
  111. // Tag name classes for BODY on tag archives
  112. elseif ( is_tag() ) {
  113. $tags = $wp_query->get_queried_object();
  114. $c[] = 'tag';
  115. $c[] = 'tag-' . $tags->slug;
  116. }
  117. // Page author for BODY on 'pages'
  118. elseif ( is_page() ) {
  119. $pageID = $wp_query->post->ID;
  120. $page_children = wp_list_pages("child_of=$pageID&echo=0");
  121. the_post();
  122. $c[] = 'page pageid-' . $pageID;
  123. $c[] = 'page-author-' . sanitize_title_with_dashes(strtolower(get_the_author_meta( 'login' )) );
  124. // Checks to see if the page has children and/or is a child page; props to Adam
  125. if ( $page_children )
  126. $c[] = 'page-parent';
  127. if ( $wp_query->post->post_parent )
  128. $c[] = 'page-child parent-pageid-' . $wp_query->post->post_parent;
  129. if ( is_page_template() ) // Hat tip to Ian, themeshaper.com
  130. $c[] = 'page-template page-template-' . str_replace( '.php', '-php', get_post_meta( $pageID, '_wp_page_template', true ) );
  131. rewind_posts();
  132. }
  133. // Search classes for results or no results
  134. elseif ( is_search() ) {
  135. the_post();
  136. if ( have_posts() ) {
  137. $c[] = 'search-results';
  138. } else {
  139. $c[] = 'search-no-results';
  140. }
  141. rewind_posts();
  142. }
  143. // For when a visitor is logged in while browsing
  144. if ( $current_user->ID )
  145. $c[] = 'loggedin';
  146. // Paged classes; for 'page X' classes of index, single, etc.
  147. if ( ( ( $page = $wp_query->get( 'paged' ) ) || ( $page = $wp_query->get( 'page' ) ) ) && $page > 1 ) {
  148. // Thanks to Prentiss Riddle, twitter.com/pzriddle, for the security fix below.
  149. $page = intval( $page ); // Ensures that an integer (not some dangerous script) is passed for the variable
  150. $c[] = 'paged-' . $page;
  151. if ( is_single() ) {
  152. $c[] = 'single-paged-' . $page;
  153. } elseif ( is_page() ) {
  154. $c[] = 'page-paged-' . $page;
  155. } elseif ( is_category() ) {
  156. $c[] = 'category-paged-' . $page;
  157. } elseif ( is_tag() ) {
  158. $c[] = 'tag-paged-' . $page;
  159. } elseif ( is_date() ) {
  160. $c[] = 'date-paged-' . $page;
  161. } elseif ( is_author() ) {
  162. $c[] = 'author-paged-' . $page;
  163. } elseif ( is_search() ) {
  164. $c[] = 'search-paged-' . $page;
  165. }
  166. }
  167. // Separates classes with a single space, collates classes for BODY
  168. $c = join( ' ', apply_filters( 'body_class', $c ) ); // Available filter: body_class
  169. // And tada!
  170. return $print ? print( $c ) : $c;
  171. }
  172. // Generates semantic classes for each post DIV element
  173. function notesil_post_class( $print = true ) {
  174. global $post, $notesil_post_alt;
  175. // hentry for hAtom compliace, gets 'alt' for every other post DIV, describes the post type and p[n]
  176. $c = array( 'hentry', "p$notesil_post_alt", $post->post_type, $post->post_status );
  177. // Author for the post queried
  178. $c[] = 'author-' . sanitize_title_with_dashes(strtolower(get_the_author_meta( 'login' )) );
  179. // Category for the post queried
  180. foreach ( (array) get_the_category() as $cat )
  181. $c[] = 'category-' . $cat->slug;
  182. // Tags for the post queried; if not tagged, use .untagged
  183. if ( get_the_tags() == null ) {
  184. $c[] = 'untagged';
  185. } else {
  186. foreach ( (array) get_the_tags() as $tag )
  187. $c[] = 'tag-' . $tag->slug;
  188. }
  189. // For password-protected posts
  190. if ( $post->post_password )
  191. $c[] = 'protected';
  192. // Applies the time- and date-based classes (below) to post DIV
  193. notesil_date_classes( mysql2date( 'U', $post->post_date ), $c );
  194. // If it's the other to the every, then add 'alt' class
  195. if ( ++$notesil_post_alt % 2 )
  196. $c[] = 'alt';
  197. // Separates classes with a single space, collates classes for post DIV
  198. $c = join( ' ', apply_filters( 'post_class', $c ) ); // Available filter: post_class
  199. // And tada!
  200. return $print ? print( $c ) : $c;
  201. }
  202. // Define the num val for 'alt' classes (in post DIV and comment LI)
  203. $notesil_post_alt = 1;
  204. // Generates semantic classes for each comment LI element
  205. function notesil_comment_class( $print = true ) {
  206. global $comment, $post, $notesil_comment_alt;
  207. // Collects the comment type (comment, trackback),
  208. $c = array( $comment->comment_type );
  209. // Counts trackbacks (t[n]) or comments (c[n])
  210. if ( $comment->comment_type == 'comment' ) {
  211. $c[] = "c$notesil_comment_alt";
  212. } else {
  213. $c[] = "t$notesil_comment_alt";
  214. }
  215. // If the comment author has an id (registered), then print the log in name
  216. if ( $comment->user_id > 0 ) {
  217. $user = get_userdata( $comment->user_id );
  218. // For all registered users, 'byuser'; to specificy the registered user, 'commentauthor+[log in name]'
  219. $c[] = 'byuser comment-author-' . sanitize_title_with_dashes(strtolower( $user->user_login ) );
  220. // For comment authors who are the author of the post
  221. if ( $comment->user_id === $post->post_author )
  222. $c[] = 'bypostauthor';
  223. }
  224. // If it's the other to the every, then add 'alt' class; collects time- and date-based classes
  225. notesil_date_classes( mysql2date( 'U', $comment->comment_date ), $c, 'c-' );
  226. if ( ++$notesil_comment_alt % 2 )
  227. $c[] = 'alt';
  228. // Separates classes with a single space, collates classes for comment LI
  229. $c = join( ' ', apply_filters( 'comment_class', $c ) ); // Available filter: comment_class
  230. // Tada again!
  231. return $print ? print( $c ) : $c;
  232. }
  233. // Generates time- and date-based classes for BODY, post DIVs, and comment LIs; relative to GMT (UTC)
  234. function notesil_date_classes( $t, &$c, $p = '' ) {
  235. $t = $t + ( get_option( 'gmt_offset' ) * 3600 );
  236. $c[] = $p . 'y' . gmdate( 'Y', $t ); // Year
  237. $c[] = $p . 'm' . gmdate( 'm', $t ); // Month
  238. $c[] = $p . 'd' . gmdate( 'd', $t ); // Day
  239. $c[] = $p . 'h' . gmdate( 'H', $t ); // Hour
  240. }
  241. // For category lists on category archives: Returns other categories except the current one (redundant)
  242. function notesil_cats_meow( $glue ) {
  243. $current_cat = single_cat_title( '', false );
  244. $separator = "\n";
  245. $cats = explode( $separator, get_the_category_list( $separator ) );
  246. foreach ( $cats as $i => $str ) {
  247. if ( strstr( $str, ">$current_cat<" ) ) {
  248. unset( $cats[$i] );
  249. break;
  250. }
  251. }
  252. if ( empty( $cats ) )
  253. return false;
  254. return trim( join( $glue, $cats ) );
  255. }
  256. // For tag lists on tag archives: Returns other tags except the current one (redundant)
  257. function notesil_tag_ur_it( $glue ) {
  258. $current_tag = single_tag_title( '', '', false );
  259. $separator = "\n";
  260. $tags = explode( $separator, get_the_tag_list( "", "$separator", "" ) );
  261. foreach ( $tags as $i => $str ) {
  262. if ( strstr( $str, ">$current_tag<" ) ) {
  263. unset( $tags[$i] );
  264. break;
  265. }
  266. }
  267. if ( empty( $tags ) )
  268. return false;
  269. return trim( join( $glue, $tags ) );
  270. }
  271. // Produces an avatar image with the hCard-compliant photo class
  272. function notesil_commenter_link() {
  273. $commenter = get_comment_author_link();
  274. if ( ereg( '<a[^>]* class=[^>]+>', $commenter ) ) {
  275. $commenter = ereg_replace( '(<a[^>]* class=[\'"]?)', '\\1url ' , $commenter );
  276. } else {
  277. $commenter = ereg_replace( '(<a )/', '\\1class="url "' , $commenter );
  278. }
  279. $avatar_email = get_comment_author_email();
  280. $avatar_size = apply_filters( 'avatar_size', '32' ); // Available filter: avatar_size
  281. $avatar = str_replace( "class='avatar", "class='photo avatar", get_avatar( $avatar_email, $avatar_size ) );
  282. echo $avatar . ' <span class="fn n">' . $commenter . '</span>';
  283. }
  284. // Widgets plugin: intializes the plugin after the widgets above have passed snuff
  285. function notes_sidebar_init() {
  286. // Formats the Sandbox widgets, adding readability-improving whitespace
  287. register_sidebar( array(
  288. 'before_widget' => "\n\t\t\t" . '<li id="%1$s" class="widget %2$s">',
  289. 'after_widget' => "\n\t\t\t</li>\n",
  290. 'before_title' => "\n\t\t\t\t". '<h3 class="widgettitle">',
  291. 'after_title' => "</h3>\n"
  292. ) );
  293. }
  294. add_action( 'init', 'notes_sidebar_init' );
  295. // Translate, if applicable
  296. load_theme_textdomain( 'notesil', get_template_directory() . '/languages' );
  297. // Adds filters for the description/meta content in archives.php
  298. add_filter( 'archive_meta', 'wptexturize' );
  299. add_filter( 'archive_meta', 'convert_smilies' );
  300. add_filter( 'archive_meta', 'convert_chars' );
  301. add_filter( 'archive_meta', 'wpautop' );
  302. //Notes color customizer, inspired by Toni's
  303. function get_notes_colors() {
  304. return array(
  305. 'default' => 'BC0404',
  306. 'black' => '000',
  307. 'darkblue' => '213970',
  308. 'darkgreen' => '3D750B',
  309. 'darkpurple' => '660066',
  310. 'grey' => '6B6B6B',
  311. 'lightblue' => 'BAC5D2',
  312. 'lightgreen' => '749881',
  313. 'lightorange' => 'DC6700',
  314. 'lightpurple' => '9999CC',
  315. 'olive' => '660',
  316. 'strongbrown' => '950'
  317. );
  318. }
  319. function get_notes_color() {
  320. $notes_color = get_option( 'notes_color' );
  321. if ( $notes_color == '' )
  322. $notes_color = 'default';
  323. return clean_notes_color( $notes_color );
  324. }
  325. function notes_color_select() {
  326. echo "<select id='notes_color' name='notes_color' size='4'>";
  327. $colors = get_notes_colors();
  328. $current_color = get_notes_color();
  329. foreach ( $colors as $name => $value ) {
  330. $selected = ( $current_color == $value ) ? " selected='selected'" : '';
  331. echo "<option value='$value'$selected>$name</option>";
  332. }
  333. echo "</select>\n";
  334. }
  335. function notes_color_radios() {
  336. $colors = get_notes_colors();
  337. $current_color = get_notes_color();
  338. $theme_uri = get_template_directory_uri();
  339. $i = 0;
  340. foreach ( $colors as $name => $value ) {
  341. $checked = ( $current_color == $name ) ? " checked='checked'" : '';
  342. echo "<tr valign='middle'><td align='right'><input type='radio' name='notes_color' id='notes_color_{$i}' value='{$name}'$checked /></td><td><label for='notes_color_{$i}'><span style='height:30px; width:80px;background-color:#{$value}; display:block;'>&nbsp;</span></label></td>
  343. <th style='height:20px; width:50px;'>&nbsp;</th>
  344. </tr>\n";
  345. ++$i;
  346. }
  347. }
  348. function clean_notes_color( $notes_color ) {
  349. $notes_colors = get_notes_colors();
  350. if ( array_key_exists( $notes_color, $notes_colors ) )
  351. return $notes_color;
  352. else
  353. return '';
  354. }
  355. function notes_color() {
  356. echo get_notes_color();
  357. }
  358. function notes_css( $body_class ) {
  359. $notes_color = get_notes_color();
  360. if ( !empty( $notes_color ) )
  361. $body_class[]= $notes_color;
  362. return( $body_class );
  363. }
  364. add_filter( 'body_class', 'notes_css' );
  365. add_action( 'admin_menu', 'notes_add_theme_page' );
  366. function notes_add_theme_page() {
  367. global $notes_message;
  368. if ( isset( $_POST['action']) && 'notes_update' == $_POST['action'] ) {
  369. $color = clean_notes_color( $_POST['notes_color'] );
  370. update_option( 'notes_color', $color);
  371. $message = __("Color changed.", 'notesil' );
  372. $notes_message = "<div style=\"background-color: rgb(207, 235, 247);\" id=\"message\" class=\"updated fade\"><p><strong>$message</strong></p></div>";
  373. }
  374. add_theme_page("Theme Options", __("Theme Options", 'notesil' ), 'edit_theme_options', basename(__FILE__), 'notes_theme_page' );
  375. }
  376. function notes_theme_page() {
  377. global $notes_message;
  378. echo $notes_message;
  379. ?>
  380. <div class="wrap">
  381. <h2><?php _e( 'Color selection', 'notesil' ); ?></h2>
  382. <p><?php _e( 'Please select the primary color of your blog theme' ); ?></p>
  383. <form method="post">
  384. <table class="optiontable"><tbody>
  385. <?php notes_color_radios(); ?>
  386. <tr><td> </td><td align="left"><p class="submit left"><input type="submit" name="Submit" value="<?php _e( 'Apply Color &raquo;', 'notesil' ); ?>" /></p></td></tr>
  387. </tbody></table>
  388. <input type="hidden" name="action" value="notes_update" />
  389. </form>
  390. </div>
  391. <?php
  392. }
  393. class Notes_Author_Widget extends WP_Widget {
  394. function Notes_Author_Widget() {
  395. $widget_ops = array( 'classname' => 'widget_notes_author', 'description' => __( 'The author Name, Gravatar, and description', 'notesil' ) );
  396. $this->WP_Widget( 'notes_author', __( 'Notes Author' ), $widget_ops);
  397. }
  398. function widget( $args, $instance ) {
  399. extract( $args );
  400. $title = '';
  401. echo $before_widget;
  402. if ( $title )
  403. echo $before_title . $title . $after_title;
  404. echo get_avatar(get_the_author_meta( 'user_email' ), $size = '60', $default = get_template_directory_uri() . '/i/default-avatar.gif' );
  405. echo '<h3>' . get_the_author_meta( 'display_name' ) . '</h3>';
  406. echo '<p>' . get_the_author_meta( 'description' ) . '</p>';
  407. echo $after_widget;
  408. }
  409. function update( $new_instance, $old_instance ) {
  410. $instance = $old_instance;
  411. $instance['title'] = strip_tags( $new_instance['title'] );
  412. return $instance;
  413. }
  414. function form( $instance ) {
  415. $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
  416. $title = strip_tags( $instance['title'] );
  417. ?>
  418. <p><?php _e( 'Display your Gravatar, and your name and description from <a href="profile.php">your user profile</a>', 'notesil' ); ?>.</p>
  419. <p><?php _e( 'Don\'t have a Gravatar? <a href="http://gravatar.com">Get one now.</a>', 'notesil' ); ?></p>
  420. <?php
  421. }
  422. }
  423. if ( ! defined( 'IS_WPCOM' ) && ! 'IS_WPCOM' ) {
  424. //only activate the authors widget on when not on WPCOM.
  425. add_action( 'widgets_init', create_function( '', 'return register_widget("Notes_Author_Widget");' ) );
  426. }
  427. add_theme_support( 'automatic-feed-links' );
  428. add_custom_background();