PageRenderTime 42ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/sergiohzlz/reportaprod
PHP | 313 lines | 236 code | 60 blank | 17 comment | 54 complexity | 34b3a007036825120a2d26ad59090dd5 MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, AGPL-1.0, LGPL-2.1
  1. <?php
  2. $content_width = 510;
  3. add_theme_support( 'automatic-feed-links' );
  4. // Custom background
  5. add_custom_background();
  6. // Load scripts
  7. function theme_scripts_init() {
  8. if (!is_admin()) { // if this isn't the WordPress admin
  9. // load jQuery
  10. wp_enqueue_script('jquery');
  11. // load theme scripts
  12. wp_enqueue_script('jquery_easing', get_bloginfo('template_url') . '/js/jquery.easing.js', array('jquery'));
  13. wp_enqueue_script('theme_scripts', get_bloginfo('template_url') . '/js/jscript.js', array('jquery'));
  14. wp_enqueue_script('comment_scripts', get_bloginfo('template_url') . '/js/comment.js?1', array('jquery'));
  15. }
  16. }
  17. add_action('init', 'theme_scripts_init');
  18. register_nav_menus( array(
  19. 'primary' => __( 'Primary Navigation', 'monochrome' ),
  20. ) );
  21. function monochrome_page_menu() { // fallback for primary navigation ?>
  22. <ul class="menu" id="menu">
  23. <li class="<?php if (!is_paged() && is_home()) { ?>current_page_item<?php } else { ?>page_item<?php } ?>"><a href="<?php echo home_url( '/' ); ?>"><?php _e('HOME','monochrome'); ?></a></li>
  24. <?php
  25. $options = get_option('mc_options');
  26. if ( 'pages' == $options['header_menu_type'] ) {
  27. wp_list_pages( 'sort_column=menu_order&depth=0&title_li=&exclude=' . $options['exclude_pages'] );
  28. } else {
  29. wp_list_categories( 'depth=0&title_li=&&exclude=' . $options['exclude_category'] );
  30. }
  31. ?>
  32. </ul>
  33. <?php }
  34. // Theme option
  35. class monochrome_options {
  36. function getOptions() {
  37. $options = get_option('mc_options');
  38. if (!is_array($options)) {
  39. $options['show_information'] = true;
  40. $options['information_title'] = '';
  41. $options['information_contents'] = '';
  42. $options['rss_feed'] = true;
  43. $options['search_position'] = 'top';
  44. $options['tag_list'] = false;
  45. $options['header_menu_type'] = 'pages';
  46. $options['author'] = false;
  47. $options['tag'] = true;
  48. $options['pagetop'] = true;
  49. $options['exclude_pages'] = '';
  50. $options['exclude_category'] = '';
  51. update_option('mc_options', $options);
  52. }
  53. return $options;
  54. }
  55. function update() {
  56. if(isset($_POST['pb_save'])) {
  57. $options = monochrome_options::getOptions();
  58. // information
  59. if ($_POST['show_information']) {
  60. $options['show_information'] = (bool)true;
  61. } else {
  62. $options['show_information'] = (bool)false;
  63. }
  64. $options['information_title'] = esc_attr(stripslashes($_POST['information_title']));
  65. $options['information_contents'] = stripslashes(wp_filter_post_kses($_POST['information_contents']));
  66. if ($_POST['rss_feed']) {
  67. $options['rss_feed'] = (bool)true;
  68. } else {
  69. $options['rss_feed'] = (bool)false;
  70. }
  71. // search
  72. $options['search_position'] = esc_attr(stripslashes($_POST['search_position']));
  73. if ($_POST['tag_list']) {
  74. $options['tag_list'] = (bool)true;
  75. } else {
  76. $options['tag_list'] = (bool)false;
  77. }
  78. // header menu
  79. $options['header_menu_type'] = esc_attr(stripslashes($_POST['header_menu_type']));
  80. // exclude pages
  81. $options['exclude_pages'] = esc_attr(stripslashes($_POST['exclude_pages']));
  82. // exclude category
  83. $options['exclude_category'] = esc_attr(stripslashes($_POST['exclude_category']));
  84. // show author
  85. if ($_POST['author']) {
  86. $options['author'] = (bool)true;
  87. } else {
  88. $options['author'] = (bool)false;
  89. }
  90. // show tag
  91. if ($_POST['tag']) {
  92. $options['tag'] = (bool)true;
  93. } else {
  94. $options['tag'] = (bool)false;
  95. }
  96. // show pagetop link
  97. if ($_POST['pagetop']) {
  98. $options['pagetop'] = (bool)true;
  99. } else {
  100. $options['pagetop'] = (bool)false;
  101. }
  102. update_option('mc_options', $options);
  103. } else {
  104. monochrome_options::getOptions();
  105. }
  106. add_theme_page(__('Theme Options', 'monochrome'), __('Theme Options', 'monochrome'), 'edit_theme_options', basename(__FILE__), array('monochrome_options', 'display'));
  107. }
  108. function display() {
  109. $options = monochrome_options::getOptions();
  110. ?>
  111. <div class="wrap">
  112. <h2><?php _e('Monochrome option', 'monochrome'); ?></h2>
  113. <form method="post" action="#" enctype="multipart/form-data">
  114. <p><?php _e('Show Information on sidebar.', 'monochrome'); ?></p>
  115. <p>
  116. <input name="show_information" type="checkbox" value="checkbox" <?php if($options['show_information']) echo "checked='checked'"; ?> /><?php _e('Yes', 'monochrome'); ?><br />
  117. </p>
  118. <br />
  119. <p><?php _e('Information title.', 'monochrome'); ?></p>
  120. <p><input type="text" name="information_title" value="<?php echo($options['information_title']); ?>" /></p>
  121. <br />
  122. <p><?php _e('Information contents. ( HTML tag is available. )', 'monochrome'); ?></p>
  123. <p><textarea name="information_contents" cols="70%" rows="5"><?php echo( esc_textarea( $options['information_contents'] ) ); ?></textarea></p>
  124. <br />
  125. <p><?php _e('Show rss feed on sidebar.', 'monochrome'); ?></p>
  126. <p>
  127. <input name="rss_feed" type="checkbox" value="checkbox" <?php if($options['rss_feed']) echo "checked='checked'"; ?> /><?php _e('Yes', 'monochrome'); ?><br />
  128. </p>
  129. <br />
  130. <p><?php _e('Position of search area on sidebar.', 'monochrome'); ?></p>
  131. <p>
  132. <input name="search_position" type="radio" value="top" <?php if($options['search_position'] != 'bottom') echo "checked='checked'"; ?> /><?php _e('Top', 'monochrome'); ?><br />
  133. <input name="search_position" type="radio" value="bottom" <?php if($options['search_position'] == 'bottom') echo "checked='checked'"; ?> /><?php _e('Bottom', 'monochrome'); ?>
  134. </p>
  135. <br />
  136. <p><?php _e('Show tag list under search area.', 'monochrome'); ?></p>
  137. <p>
  138. <input name="tag_list" type="checkbox" value="checkbox" <?php if($options['tag_list']) echo "checked='checked'"; ?> /><?php _e('Yes', 'monochrome'); ?><br />
  139. </p>
  140. <br />
  141. <p><?php _e('Header menu.', 'monochrome'); ?></p>
  142. <p>
  143. <input name="header_menu_type" type="radio" value="pages" <?php if($options['header_menu_type'] != 'categories') echo "checked='checked'"; ?> /><?php _e('Use pages for header menu.', 'monochrome'); ?><br />
  144. <input name="header_menu_type" type="radio" value="categories" <?php if($options['header_menu_type'] == 'categories') echo "checked='checked'"; ?> /><?php _e('Use categories for header menu.', 'monochrome'); ?>
  145. </p>
  146. <p><em><?php _e('This option may produce undesired results.'); ?></em></p>
  147. <br />
  148. <p><?php _e('Exclude Pages (Page ID\'s you don\'t want displayed in your header navigation. Use a comma-delimited list, eg. 1,2,3)', 'monochrome'); ?></p>
  149. <p><input type="text" name="exclude_pages" value="<?php echo($options['exclude_pages']); ?>" /></p>
  150. <br />
  151. <p><?php _e('Exclude Categories (Category ID\'s you don\'t want displayed in your header navigation. Use a comma-delimited list, eg. 1,2,3)', 'monochrome'); ?></p>
  152. <p><input type="text" name="exclude_category" value="<?php echo($options['exclude_category']); ?>" /></p>
  153. <br />
  154. <p><?php _e('Show author name.', 'monochrome'); ?></p>
  155. <p>
  156. <input name="author" type="checkbox" value="checkbox" <?php if($options['author']) echo "checked='checked'"; ?> /><?php _e('Yes', 'monochrome'); ?><br />
  157. </p>
  158. <br />
  159. <p><?php _e('Show tag.', 'monochrome'); ?></p>
  160. <p>
  161. <input name="tag" type="checkbox" value="checkbox" <?php if($options['tag']) echo "checked='checked'"; ?> /><?php _e('Yes', 'monochrome'); ?><br />
  162. </p>
  163. <br />
  164. <p><?php _e('Check if you want to show Return top link.<br />( NOTICE : Return top link does not work on IE6. )', 'monochrome'); ?></p>
  165. <p><input name="pagetop" type="checkbox" value="checkbox" <?php if($options['pagetop']) echo "checked='checked'"; ?> /><?php _e('Yes', 'monochrome'); ?></p>
  166. <br />
  167. <br />
  168. <p><input class="button-primary" type="submit" name="pb_save" value="<?php _e('Save Changes', 'monochrome'); ?>" /></p>
  169. </form>
  170. </div>
  171. <?php
  172. }
  173. }
  174. // register functions
  175. add_action('admin_menu', array('monochrome_options', 'update'));
  176. // for localization
  177. load_textdomain('monochrome', dirname(__FILE__).'/languages/' . get_locale() . '.mo');
  178. // Sidebar widget
  179. if ( function_exists('register_sidebar') )
  180. register_sidebar(array(
  181. 'before_widget' => '<div class="side_box" id="%1$s">'."\n",
  182. 'after_widget' => "</div>\n",
  183. 'before_title' => '<h3>',
  184. 'after_title' => "</h3>\n",
  185. ));
  186. // Remove [...] from excerpt
  187. function trim_excerpt($text) {
  188. return rtrim($text,'[...]');
  189. }
  190. add_filter('get_the_excerpt', 'trim_excerpt');
  191. function custom_comments($comment, $args, $depth) {
  192. $GLOBALS['comment'] = $comment;
  193. global $commentcount;
  194. if(!$commentcount) {
  195. $commentcount = 0;
  196. }
  197. ?>
  198. <li <?php comment_class(); ?> id="comment-<?php comment_ID() ?>">
  199. <div class="comment-meta">
  200. <div class="comment-meta-left">
  201. <?php if (function_exists('get_avatar') && get_option('show_avatars')) { echo get_avatar($comment, 35); } ?>
  202. <ul class="comment-name-date">
  203. <li class="comment-name">
  204. <?php if (get_comment_author_url()) : ?>
  205. <a id="commentauthor-<?php comment_ID() ?>" class="url <?php if($comment->comment_author_email == get_the_author_email()) {echo 'admin-url';} else {echo 'guest-url';} ?>" href="<?php comment_author_url() ?>" rel="external nofollow">
  206. <?php else : ?>
  207. <span id="commentauthor-<?php comment_ID() ?>">
  208. <?php endif; ?>
  209. <?php comment_author(); ?>
  210. <?php if(get_comment_author_url()) : ?>
  211. </a>
  212. <?php else : ?>
  213. </span>
  214. <?php endif; ?>
  215. </li>
  216. <li class="comment-date"><?php echo get_comment_time(__('F jS, Y', 'monochrome')); ?></li>
  217. </ul>
  218. </div>
  219. <ul class="comment-act">
  220. <?php if (function_exists('comment_reply_link')) {
  221. if ( get_option('thread_comments') == '1' ) { ?>
  222. <li class="comment-reply"><?php comment_reply_link(array_merge( $args, array('add_below' => 'comment-content', 'depth' => $depth, 'max_depth' => $args['max_depth'], 'reply_text' => '<span><span>'.__('REPLY','monochrome').'</span></span>'.$my_comment_count))) ?></li>
  223. <?php } else { ?>
  224. <li class="comment-reply"><a href="javascript:void(0);" onclick="MGJS_CMT.reply('commentauthor-<?php comment_ID() ?>', 'comment-<?php comment_ID() ?>', 'comment');"><?php _e('REPLY', 'monochrome'); ?></a></li>
  225. <?php }
  226. } else { ?>
  227. <li class="comment-reply"><a href="javascript:void(0);" onclick="MGJS_CMT.reply('commentauthor-<?php comment_ID() ?>', 'comment-<?php comment_ID() ?>', 'comment');"><?php _e('REPLY', 'monochrome'); ?></a></li>
  228. <?php } ?>
  229. <li class="comment-quote"><a href="javascript:void(0);" onclick="MGJS_CMT.quote('commentauthor-<?php comment_ID() ?>', 'comment-<?php comment_ID() ?>', 'comment-content-<?php comment_ID() ?>', 'comment');"><?php _e('QUOTE', 'monochrome'); ?></a></li>
  230. <?php edit_comment_link(__('EDIT', 'monochrome'), '<li class="comment-edit">', '</li>'); ?>
  231. </ul>
  232. </div>
  233. <div class="comment-content" id="comment-content-<?php comment_ID() ?>">
  234. <?php if ($comment->comment_approved == '0') : ?>
  235. <span class="comment-note"><?php _e('Your comment is awaiting moderation.', 'monochrome'); ?></span>
  236. <?php endif; ?>
  237. <?php comment_text(); ?>
  238. </div>
  239. <?php }
  240. function widget_monochrome_search() {
  241. ?>
  242. <div class="side_box" id="search_area_top">
  243. <div id="search_area" class="clearfix">
  244. <form method="get" id="searchform" action="<?php bloginfo('url'); ?>/">
  245. <div><input type="text" value="<?php _e('Search','monochrome'); ?>" name="s" id="search_input" onfocus="this.value=''; changefc('white');" /></div>
  246. <div><input type="image" src="<?php bloginfo('template_url'); ?>/img/search_button_n.gif" alt="<?php _e('Search from this blog.','monochrome'); ?>" title="<?php _e('Search from this blog.','monochrome'); ?>" id="search_button" /></div>
  247. </form>
  248. </div>
  249. </div>
  250. <?php
  251. }
  252. unregister_widget('WP_Widget_Search');
  253. wp_register_sidebar_widget('search', __('Search'), 'widget_monochrome_search');