PageRenderTime 52ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/blog/wp-content/themes/depo-masthead/functions.php

https://bitbucket.org/sergiohzlz/reportaprod
PHP | 372 lines | 279 code | 67 blank | 26 comment | 65 complexity | f3eabe2060ade237a3d5b189efee2960 MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, AGPL-1.0, LGPL-2.1
  1. <?php
  2. $content_width = 604;
  3. add_theme_support( 'automatic-feed-links' );
  4. // Custom background
  5. add_custom_background();
  6. function depo_custom_background() {
  7. if ( '' != get_background_color() || '' != get_background_image() ) { ?>
  8. <style type="text/css">
  9. #sidebar { background-image: none; }
  10. #sidebar ul { border-color: #<?php echo get_background_color(); ?>; }
  11. #sidebar .closer { background: none; }
  12. <?php if ( '' != get_background_color() && '' == get_background_image() ) { ?>
  13. body { background-image: none; }
  14. <?php } ?>
  15. </style>
  16. <?php }
  17. }
  18. add_action( 'wp_head', 'depo_custom_background' );
  19. function continue_reading_excerpt() {
  20. $text = get_the_excerpt();
  21. $text = apply_filters('the_content', $text);
  22. $text = str_replace(']]>', ']]>', $text);
  23. $text = strip_tags($text, '<p>');
  24. $excerpt_length = 50;
  25. $words = explode(' ', $text, $excerpt_length + 1);
  26. if (count($words) > $excerpt_length) {
  27. array_pop($words);
  28. array_push($words, ' ... <a href="'. get_permalink() . '">'.__('Continue reading &raquo;').'</a>');
  29. $text = implode(' ', $words);
  30. }
  31. echo $text;
  32. }
  33. if ( function_exists('register_sidebars') ) {
  34. register_sidebar(array(
  35. 'name' => 'Right',
  36. 'before_widget' => '<li id="%1$s" class="widget %2$s">',
  37. 'after_widget' => '</li>',
  38. 'before_title' => '<h3 class="widgettitle">',
  39. 'after_title' => '</h3>',
  40. ));
  41. register_sidebar(array(
  42. 'name' => 'Middle',
  43. 'before_widget' => '<li id="%1$s" class="widget %2$s">',
  44. 'after_widget' => '</li>',
  45. 'before_title' => '<h3 class="widgettitle">',
  46. 'after_title' => '</h3>',
  47. ));
  48. register_sidebar(array(
  49. 'name' => 'Left',
  50. 'before_widget' => '<li id="%1$s" class="widget %2$s">',
  51. 'after_widget' => '</li>',
  52. 'before_title' => '<h3 class="widgettitle">',
  53. 'after_title' => '</h3>',
  54. ));
  55. }
  56. register_sidebar_widget('Search', 'search_widget');
  57. function search_widget() { ?>
  58. <li id="search_widget" class="widget widget_search">
  59. <?php if ( !is_dynamic_sidebar() ) { ?><h2><?php _e('Etc', 'depo-masthead'); ?></h2><?php } ?>
  60. <form method="get" id="searchform" action="<?php bloginfo('url'); ?>/">
  61. <label class="hidden" for="s"><?php _e('Search for:'); ?></label>
  62. <div><input type="text" value="<?php the_search_query(); ?>" name="s" id="s" />
  63. <input type="submit" id="searchsubmit" value="Search" />
  64. </div>
  65. </form></li><?php
  66. }
  67. register_sidebar_widget(__('DePo About', 'depo-masthead'), 'depo_about_widget');
  68. function depo_about_widget() { ?>
  69. <li id="depo_about">
  70. <?php query_posts('pagename=about'); ?>
  71. <?php while (have_posts()) : the_post(); ?>
  72. <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__('Permanent Link to %s', 'depo-masthead'), the_title_attribute('echo=0')); ?>"><?php the_title(); ?></a></h2>
  73. <div class="entry">
  74. <?php continue_reading_excerpt(); ?>
  75. </div>
  76. <?php endwhile; ?>
  77. </li>
  78. <?php
  79. }
  80. register_sidebar_widget(__('DePo Archives & Categories', 'depo-masthead'), 'depo_archives_widget');
  81. function depo_archives_widget() { ?>
  82. <li id="depo_archives">
  83. <h2><?php _e('Archives', 'depo-masthead'); ?></h2>
  84. <ul>
  85. <?php wp_get_archives('type=monthly&number=7'); ?>
  86. </ul>
  87. <ul>
  88. <?php wp_list_categories('number=7&title_li=&orderby=count&order=DESC'); // show the 7 most-used categories ?>
  89. </ul>
  90. <br class="clear" />
  91. </li>
  92. <?php }
  93. register_sidebar_widget(__('RSS Link', 'depo-masthead'), 'rss_widget');
  94. function rss_widget() { ?>
  95. <li id="rss_link" class="widget widget_rss"><a href="<?php bloginfo('rss2_url'); ?>"><?php _e('RSS Feed', 'depo-masthead'); ?></a></li>
  96. <?php
  97. }
  98. /*
  99. Plugin Name: Next/Previous Archive Date
  100. Version: v 2.1
  101. Plugin URI: http://www.scriptygoddess.com/archives/2004/06/27/previous-archive-date-next-archive-date-links/
  102. Description: This plugin will give you two functions for your "date archive" pages that will give you links to the next/previous date. (works for day, month, or year archives)
  103. Author: Modded by Originally - Jennifer - Scriptygoddess
  104. Author URI: http://jcksn.com
  105. */
  106. function previous_archive_link($user_text='',$before='', $after='') {
  107. global $wpdb, $tableposts, $wp_query;
  108. if (!isset($tableposts))
  109. $tableposts = $wpdb->posts;
  110. //get home url for base of link
  111. $info = get_bloginfo('url');
  112. $info = apply_filters('bloginfo', $info);
  113. $homeurl = convert_chars($info);
  114. $query = $wp_query->query_vars;
  115. $date->month = $query['m'];
  116. $date->year = $query['year'];
  117. $date->monthnum = $query['monthnum'];
  118. if ( $date->monthnum < 10 ) $date->monthnum = "0" . $date->monthnum;
  119. $date->day = $query['day'];
  120. if ( $date->day < 10 ) $date->day = "0" . $date->day;
  121. foreach($date as $key => $value) {
  122. if($value != '' && $value != 0) $m .= $value;
  123. }
  124. if ($m != '') {
  125. switch(strlen($m)) {
  126. case 4:
  127. //archive is year
  128. $m = (int)$m;
  129. $past = $wpdb->get_row("SELECT post_date, YEAR(post_date) as year FROM $tableposts WHERE YEAR(post_date) < '".$m."' AND post_type='post' AND post_status='publish' ORDER BY post_date DESC");
  130. if ($past) {
  131. $link = get_year_link($past->year);
  132. $text = $past->year;
  133. }
  134. break;
  135. case 6:
  136. //archive is month
  137. $thisYear = substr($m, 0, 4);
  138. $thisMonth = substr($m, 4, 2);
  139. if (substr($thisMonth,0,1) == '0')
  140. $thisMonth = substr($m, 5, 1);
  141. $thisMonth = (int)$thisMonth;
  142. $thisYear = (int)$thisYear;
  143. $timestamp = mktime(0, 0, 0, $thisMonth, 1, $thisYear);
  144. $currentdate = date("Y-m-d G:i:s", $timestamp);
  145. //echo $currentdate;
  146. $past = $wpdb->get_row("SELECT post_date, YEAR(post_date) as year, MONTH(post_date) as month FROM $tableposts WHERE post_date < '".$currentdate."' AND post_type='post' AND post_status='publish' ORDER BY post_date DESC");
  147. $timestampfordisplay = mktime(0,0,0,$past->month,1,$past->year);
  148. $forDisplay = __(date("F", $timestampfordisplay));
  149. $forDisplay .= " ".date("Y", $timestampfordisplay);
  150. if ($past) {
  151. $link = get_month_link($past->year,$past->month);
  152. $text = $forDisplay;
  153. }
  154. break;
  155. case 8:
  156. //archive is day YYYYMMDD
  157. $thisYear = substr($m, 0, 4);
  158. $thisMonth = substr($m, 4, 2);
  159. $thisDay = substr($m, 6, 2);
  160. if (substr($thisDay,0,1) == '0') {
  161. $thisDay = substr($m, 7, 1);
  162. }
  163. if (substr($thisMonth,0,1) == '0') {
  164. $thisMonth = substr($m, 5, 1);
  165. }
  166. $thisDay = (int)$thisDay;
  167. $thisMonth = (int)$thisMonth;
  168. $thisYear = (int)$thisYear;
  169. $timestamp = mktime(0, 0, 0, $thisMonth, $thisDay, $thisYear);
  170. $currentdate = date("Y-m-d G:i:s", $timestamp);
  171. //echo $currentdate;
  172. $past = $wpdb->get_row("SELECT post_date, YEAR(post_date) as year, MONTH(post_date) as month, DAYOFMONTH(post_date) as day FROM $tableposts WHERE post_date < '".$currentdate."' AND post_type='post' AND post_status='publish' ORDER BY post_date DESC");
  173. $timestampfordisplay = mktime(0,0,0,$past->month,$past->day,$past->year);
  174. $forDisplay = __(date("F", $timestampfordisplay));
  175. $forDisplay .= " ".date("j, Y", $timestampfordisplay);
  176. if ($past) {
  177. $link = get_day_link($past->year,$past->month,$past->day);
  178. $text = $forDisplay;
  179. }
  180. break;
  181. }
  182. if($user_text != '') $text = str_replace('%title',$text,$user_text);
  183. if($link) echo $before.'<a href="'.$link.'">'.$text.'</a>'.$after;
  184. }
  185. }
  186. function next_archive_link($user_text='',$before='', $after='') {
  187. global $wpdb, $tableposts, $wp_query;
  188. if (!isset($tableposts))
  189. $tableposts = $wpdb->posts;
  190. //get home url for base of link
  191. $info = get_bloginfo('url');
  192. $info = apply_filters('bloginfo', $info);
  193. $homeurl = convert_chars($info);
  194. $query = $wp_query->query_vars;
  195. $date->month = $query['m'];
  196. $date->year = $query['year'];
  197. $date->monthnum = $query['monthnum'];
  198. if ( $date->monthnum < 10 ) $date->monthnum = "0" . $date->monthnum;
  199. $date->day = $query['day'];
  200. if ( $date->day < 10 ) $date->day = "0" . $date->day;
  201. foreach($date as $key => $value) {
  202. if($value != '' && $value != 0) $m .= $value;
  203. }
  204. if ($m != '') {
  205. switch(strlen($m)) {
  206. case 4:
  207. //archive is year
  208. $m = (int)$m;
  209. $m++;
  210. $past = $wpdb->get_row("SELECT post_date, YEAR(post_date) as year FROM $tableposts WHERE YEAR(post_date) >= '".$m."' AND post_type='post' AND post_status='publish' ORDER BY post_date ASC");
  211. if ($past) {
  212. $link = get_year_link($past->year);
  213. $text = $past->year;
  214. }
  215. break;
  216. case 6:
  217. //archive is month
  218. $thisYear = substr($m, 0, 4);
  219. $thisMonth = substr($m, 4, 2);
  220. if (substr($thisMonth,0,1) == '0')
  221. $thisMonth = substr($m, 5, 1);
  222. $thisMonth = (int)$thisMonth;
  223. $thisYear = (int)$thisYear;
  224. $timestamp = mktime(0, 0, 0, $thisMonth+1, 1, $thisYear);
  225. $currentdate = date("Y-m-d G:i:s", $timestamp);
  226. //echo $currentdate;
  227. $past = $wpdb->get_row("SELECT post_date, YEAR(post_date) as year, MONTH(post_date) as month FROM $tableposts WHERE post_date >= '".$currentdate."' AND post_type='post' AND post_status='publish' ORDER BY post_date ASC");
  228. $timestampfordisplay = mktime(0,0,0,$past->month,1,$past->year);
  229. $forDisplay = __(date("F", $timestampfordisplay));
  230. $forDisplay .= " ".date("Y", $timestampfordisplay);
  231. if ($past) {
  232. $link = get_month_link($past->year, $past->month);
  233. $text = $forDisplay;
  234. }
  235. break;
  236. case 8:
  237. //archive is day YYYYMMDD
  238. $thisYear = substr($m, 0, 4);
  239. $thisMonth = substr($m, 4, 2);
  240. $thisDay = substr($m, 6, 2);
  241. if (substr($thisDay,0,1) == '0')
  242. $thisDay = substr($m, 7, 1);
  243. if (substr($thisMonth,0,1) == '0')
  244. $thisMonth = substr($m, 5, 1);
  245. $thisDay = (int)$thisDay;
  246. $thisMonth = (int)$thisMonth;
  247. $thisYear = (int)$thisYear;
  248. $timestamp = mktime(0, 0, 0, $thisMonth, $thisDay+1, $thisYear);
  249. $currentdate = date("Y-m-d G:i:s", $timestamp);
  250. //echo $currentdate;
  251. $past = $wpdb->get_row("SELECT post_date, YEAR(post_date) as year, MONTH(post_date) as month, DAYOFMONTH(post_date) as day FROM $tableposts WHERE post_date >= '".$currentdate."' AND post_type='post' AND post_status='publish' ORDER BY post_date ASC");
  252. $timestampfordisplay = mktime(0,0,0,$past->month,$past->day,$past->year);
  253. $forDisplay = __(date("F", $timestampfordisplay));
  254. $forDisplay .= " ".date("j, Y", $timestampfordisplay);
  255. if ($past) {
  256. $link = get_day_link($past->year,$past->month,$past->day);
  257. $text = $forDisplay;
  258. }
  259. break;
  260. }
  261. if($user_text != '') $text = str_replace('%title',$text,$user_text);
  262. if($link) echo $before.'<a href="'.$link.'">'.$text.'</a>'.$after;
  263. }
  264. }
  265. add_action('admin_menu', 'depo_add_theme_page');
  266. function depo_add_theme_page() {
  267. if ( isset( $_GET['page'] ) && $_GET['page'] == basename(__FILE__) ) {
  268. if ( isset( $_POST['action'] ) && 'save' == $_POST['action'] ) {
  269. if(isset($_POST['author-name'])) {
  270. check_admin_referer('depo-name');
  271. if ( '' == $_POST['author-name'] ) {
  272. delete_option('depo-author-name');
  273. } else {
  274. update_option( 'depo-author-name', esc_attr( $_POST['author-name'] ) );
  275. }
  276. wp_redirect("themes.php?page=functions.php&saved=true");
  277. die;
  278. }
  279. }
  280. }
  281. add_theme_page(__('Theme Options', 'depo-masthead'), __('Theme Options', 'depo-masthead'), 'edit_theme_options', basename(__FILE__), 'depo_theme_page');
  282. }
  283. function depo_theme_page() {
  284. if ( isset( $_REQUEST['saved'] ) ) echo '<div id="message" class="updated fade"><p><strong>'.__('Options saved.', 'depo-masthead').'</strong></p></div>';
  285. ?>
  286. <div class='wrap'>
  287. <form method="post" action="<?php echo esc_url( $_SERVER['REQUEST_URI'] ); ?>">
  288. <?php wp_nonce_field('depo-name'); ?>
  289. <p><label for="author-name"><?php _e('Author Box Text:', 'depo-masthead'); ?></label> <input type="text" name="author-name" value="<?php echo get_option('depo-author-name'); ?>" id="author-name" /> <small><?php _e('Leaving this field blank will insert the blog author\'s name.', 'depo-masthead'); ?></small></p>
  290. <p><input type="hidden" name="action" value="save" /> <input type="submit" name="submit" value="<?php esc_attr_e( 'Submit', 'depo-masthead' ); ?>" id="submit" /></p>
  291. </form>
  292. </div>
  293. <?php }
  294. // Header navigation menu
  295. register_nav_menus( array(
  296. 'primary' => __( 'Primary Navigation', 'depomasthead' )
  297. ) );
  298. // Fallback for primary navigation
  299. function depomasthead_page_menu() { ?>
  300. <ul class="menu">
  301. <?php wp_list_pages( 'sort_column=menu_order&depth=1&title_li=' ); ?>
  302. <li><a href="<?php bloginfo( 'url' ); ?>/<?php echo mysql2date( 'Y', get_lastpostdate( 'blog' ) ); ?>/"><?php _e( 'Archives', 'depo-masthead' ); ?></a></li>
  303. <li><a href="<?php bloginfo( 'rss2_url' ); ?>"><?php _e( 'RSS Feed', 'depo-masthead' ); ?></a></li>
  304. </ul>
  305. <?php }