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

/data/wpcom-themes/depo-masthead/functions.php

https://gitlab.com/Blueprint-Marketing/wordpress-unit-tests
PHP | 340 lines | 258 code | 62 blank | 20 comment | 57 complexity | 654597b2a5182df49c165f5f085aee9a MD5 | raw file
  1. <?php
  2. $content_width = 604;
  3. function continue_reading_excerpt() {
  4. $text = get_the_excerpt();
  5. $text = apply_filters('the_content', $text);
  6. $text = str_replace(']]>', ']]>', $text);
  7. $text = strip_tags($text, '<p>');
  8. $excerpt_length = 50;
  9. $words = explode(' ', $text, $excerpt_length + 1);
  10. if (count($words) > $excerpt_length) {
  11. array_pop($words);
  12. array_push($words, ' ... <a href="'. get_permalink() . '">'.__('Continue reading &raquo;').'</a>');
  13. $text = implode(' ', $words);
  14. }
  15. echo $text;
  16. }
  17. if ( function_exists('register_sidebars') ) {
  18. register_sidebar(array(
  19. 'name' => 'Right',
  20. 'before_widget' => '<li id="%1$s" class="widget %2$s">',
  21. 'after_widget' => '</li>',
  22. 'before_title' => '<h3 class="widgettitle">',
  23. 'after_title' => '</h3>',
  24. ));
  25. register_sidebar(array(
  26. 'name' => 'Middle',
  27. 'before_widget' => '<li id="%1$s" class="widget %2$s">',
  28. 'after_widget' => '</li>',
  29. 'before_title' => '<h3 class="widgettitle">',
  30. 'after_title' => '</h3>',
  31. ));
  32. register_sidebar(array(
  33. 'name' => 'Left',
  34. 'before_widget' => '<li id="%1$s" class="widget %2$s">',
  35. 'after_widget' => '</li>',
  36. 'before_title' => '<h3 class="widgettitle">',
  37. 'after_title' => '</h3>',
  38. ));
  39. }
  40. register_sidebar_widget('Search', 'search_widget');
  41. function search_widget() { ?>
  42. <li id="search_widget" class="widget widget_search">
  43. <?php if ( !is_dynamic_sidebar() ) { ?><h2><?php _e('Etc', 'depo-masthead'); ?></h2><?php } ?>
  44. <form method="get" id="searchform" action="<?php bloginfo('url'); ?>/">
  45. <label class="hidden" for="s"><?php _e('Search for:'); ?></label>
  46. <div><input type="text" value="<?php the_search_query(); ?>" name="s" id="s" />
  47. <input type="submit" id="searchsubmit" value="Search" />
  48. </div>
  49. </form></li><?php
  50. }
  51. register_sidebar_widget(__('DePo About', 'depo-masthead'), 'depo_about_widget');
  52. function depo_about_widget() { ?>
  53. <li id="depo_about">
  54. <?php query_posts('pagename=about'); ?>
  55. <?php while (have_posts()) : the_post(); ?>
  56. <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>
  57. <div class="entry">
  58. <?php continue_reading_excerpt(); ?>
  59. </div>
  60. <?php endwhile; ?>
  61. </li>
  62. <?php
  63. }
  64. register_sidebar_widget(__('DePo Archives & Categories', 'depo-masthead'), 'depo_archives_widget');
  65. function depo_archives_widget() { ?>
  66. <li id="depo_archives">
  67. <h2><?php _e('Archives', 'depo-masthead'); ?></h2>
  68. <ul>
  69. <?php wp_get_archives('type=monthly&number=7'); ?>
  70. </ul>
  71. <ul>
  72. <?php wp_list_categories('show_count=0&number=7&title_li'); ?>
  73. </ul>
  74. <br class="clear" />
  75. </li>
  76. <?php }
  77. register_sidebar_widget(__('RSS Link', 'depo-masthead'), 'rss_widget');
  78. function rss_widget() { ?>
  79. <li id="rss_link" class="widget widget_rss"><a href="<?php bloginfo('rss2_url'); ?>"><?php _e('RSS Feed', 'depo-masthead'); ?></a></li>
  80. <?php
  81. }
  82. /*
  83. Plugin Name: Next/Previous Archive Date
  84. Version: v 2.1
  85. Plugin URI: http://www.scriptygoddess.com/archives/2004/06/27/previous-archive-date-next-archive-date-links/
  86. 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)
  87. Author: Modded by Originally - Jennifer - Scriptygoddess
  88. Author URI: http://jcksn.com
  89. */
  90. function previous_archive_link($user_text='',$before='', $after='') {
  91. global $wpdb, $tableposts, $wp_query;
  92. if (!isset($tableposts))
  93. $tableposts = $wpdb->posts;
  94. //get home url for base of link
  95. $info = get_bloginfo('url');
  96. $info = apply_filters('bloginfo', $info);
  97. $homeurl = convert_chars($info);
  98. $query = $wp_query->query_vars;
  99. $date->month = $query['m'];
  100. $date->year = $query['year'];
  101. $date->monthnum = $query['monthnum'];
  102. if ( $date->monthnum < 10 ) $date->monthnum = "0" . $date->monthnum;
  103. $date->day = $query['day'];
  104. if ( $date->day < 10 ) $date->day = "0" . $date->day;
  105. foreach($date as $key => $value) {
  106. if($value != '' && $value != 0) $m .= $value;
  107. }
  108. if ($m != '') {
  109. switch(strlen($m)) {
  110. case 4:
  111. //archive is year
  112. $m = (int)$m;
  113. $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");
  114. if ($past) {
  115. $link = get_year_link($past->year);
  116. $text = $past->year;
  117. }
  118. break;
  119. case 6:
  120. //archive is month
  121. $thisYear = substr($m, 0, 4);
  122. $thisMonth = substr($m, 4, 2);
  123. if (substr($thisMonth,0,1) == '0')
  124. $thisMonth = substr($m, 5, 1);
  125. $thisMonth = (int)$thisMonth;
  126. $thisYear = (int)$thisYear;
  127. $timestamp = mktime(0, 0, 0, $thisMonth, 1, $thisYear);
  128. $currentdate = date("Y-m-d G:i:s", $timestamp);
  129. //echo $currentdate;
  130. $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");
  131. $timestampfordisplay = mktime(0,0,0,$past->month,1,$past->year);
  132. $forDisplay = __(date("F", $timestampfordisplay));
  133. $forDisplay .= " ".date("Y", $timestampfordisplay);
  134. if ($past) {
  135. $link = get_month_link($past->year,$past->month);
  136. $text = $forDisplay;
  137. }
  138. break;
  139. case 8:
  140. //archive is day YYYYMMDD
  141. $thisYear = substr($m, 0, 4);
  142. $thisMonth = substr($m, 4, 2);
  143. $thisDay = substr($m, 6, 2);
  144. if (substr($thisDay,0,1) == '0') {
  145. $thisDay = substr($m, 7, 1);
  146. }
  147. if (substr($thisMonth,0,1) == '0') {
  148. $thisMonth = substr($m, 5, 1);
  149. }
  150. $thisDay = (int)$thisDay;
  151. $thisMonth = (int)$thisMonth;
  152. $thisYear = (int)$thisYear;
  153. $timestamp = mktime(0, 0, 0, $thisMonth, $thisDay, $thisYear);
  154. $currentdate = date("Y-m-d G:i:s", $timestamp);
  155. //echo $currentdate;
  156. $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");
  157. $timestampfordisplay = mktime(0,0,0,$past->month,$past->day,$past->year);
  158. $forDisplay = __(date("F", $timestampfordisplay));
  159. $forDisplay .= " ".date("j, Y", $timestampfordisplay);
  160. if ($past) {
  161. $link = get_day_link($past->year,$past->month,$past->day);
  162. $text = $forDisplay;
  163. }
  164. break;
  165. }
  166. if($user_text != '') $text = str_replace('%title',$text,$user_text);
  167. if($link) echo $before.'<a href="'.$link.'">'.$text.'</a>'.$after;
  168. }
  169. }
  170. function next_archive_link($user_text='',$before='', $after='') {
  171. global $wpdb, $tableposts, $wp_query;
  172. if (!isset($tableposts))
  173. $tableposts = $wpdb->posts;
  174. //get home url for base of link
  175. $info = get_bloginfo('url');
  176. $info = apply_filters('bloginfo', $info);
  177. $homeurl = convert_chars($info);
  178. $query = $wp_query->query_vars;
  179. $date->month = $query['m'];
  180. $date->year = $query['year'];
  181. $date->monthnum = $query['monthnum'];
  182. if ( $date->monthnum < 10 ) $date->monthnum = "0" . $date->monthnum;
  183. $date->day = $query['day'];
  184. if ( $date->day < 10 ) $date->day = "0" . $date->day;
  185. foreach($date as $key => $value) {
  186. if($value != '' && $value != 0) $m .= $value;
  187. }
  188. if ($m != '') {
  189. switch(strlen($m)) {
  190. case 4:
  191. //archive is year
  192. $m = (int)$m;
  193. $m++;
  194. $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");
  195. if ($past) {
  196. $link = get_year_link($past->year);
  197. $text = $past->year;
  198. }
  199. break;
  200. case 6:
  201. //archive is month
  202. $thisYear = substr($m, 0, 4);
  203. $thisMonth = substr($m, 4, 2);
  204. if (substr($thisMonth,0,1) == '0')
  205. $thisMonth = substr($m, 5, 1);
  206. $thisMonth = (int)$thisMonth;
  207. $thisYear = (int)$thisYear;
  208. $timestamp = mktime(0, 0, 0, $thisMonth+1, 1, $thisYear);
  209. $currentdate = date("Y-m-d G:i:s", $timestamp);
  210. //echo $currentdate;
  211. $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");
  212. $timestampfordisplay = mktime(0,0,0,$past->month,1,$past->year);
  213. $forDisplay = __(date("F", $timestampfordisplay));
  214. $forDisplay .= " ".date("Y", $timestampfordisplay);
  215. if ($past) {
  216. $link = get_month_link($past->year, $past->month);
  217. $text = $forDisplay;
  218. }
  219. break;
  220. case 8:
  221. //archive is day YYYYMMDD
  222. $thisYear = substr($m, 0, 4);
  223. $thisMonth = substr($m, 4, 2);
  224. $thisDay = substr($m, 6, 2);
  225. if (substr($thisDay,0,1) == '0')
  226. $thisDay = substr($m, 7, 1);
  227. if (substr($thisMonth,0,1) == '0')
  228. $thisMonth = substr($m, 5, 1);
  229. $thisDay = (int)$thisDay;
  230. $thisMonth = (int)$thisMonth;
  231. $thisYear = (int)$thisYear;
  232. $timestamp = mktime(0, 0, 0, $thisMonth, $thisDay+1, $thisYear);
  233. $currentdate = date("Y-m-d G:i:s", $timestamp);
  234. //echo $currentdate;
  235. $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");
  236. $timestampfordisplay = mktime(0,0,0,$past->month,$past->day,$past->year);
  237. $forDisplay = __(date("F", $timestampfordisplay));
  238. $forDisplay .= " ".date("j, Y", $timestampfordisplay);
  239. if ($past) {
  240. $link = get_day_link($past->year,$past->month,$past->day);
  241. $text = $forDisplay;
  242. }
  243. break;
  244. }
  245. if($user_text != '') $text = str_replace('%title',$text,$user_text);
  246. if($link) echo $before.'<a href="'.$link.'">'.$text.'</a>'.$after;
  247. }
  248. }
  249. add_action('admin_menu', 'depo_add_theme_page');
  250. function depo_add_theme_page() {
  251. if ( isset( $_GET['page'] ) && $_GET['page'] == basename(__FILE__) ) {
  252. if ( isset( $_POST['action'] ) && 'save' == $_POST['action'] ) {
  253. if(isset($_POST['author-name'])) {
  254. check_admin_referer('depo-name');
  255. if ( '' == $_POST['author-name'] ) {
  256. delete_option('depo-author-name');
  257. } else {
  258. update_option('depo-author-name', attribute_escape($_POST['author-name']));
  259. }
  260. wp_redirect("themes.php?page=functions.php&saved=true");
  261. die;
  262. }
  263. }
  264. }
  265. add_theme_page(__('DePo Options', 'depo-masthead'), __('DePo Options', 'depo-masthead'), 'edit_themes', basename(__FILE__), 'depo_theme_page');
  266. }
  267. function depo_theme_page() {
  268. if ( isset( $_REQUEST['saved'] ) ) echo '<div id="message" class="updated fade"><p><strong>'.__('Options saved.', 'depo-masthead').'</strong></p></div>';
  269. ?>
  270. <div class='wrap'>
  271. <form method="post" action="<?php echo attribute_escape($_SERVER['REQUEST_URI']); ?>">
  272. <?php wp_nonce_field('depo-name'); ?>
  273. <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>
  274. <p><input type="hidden" name="action" value="save" /> <input type="submit" name="submit" value="<?php echo attribute_escape(__('Submit', 'depo-masthead')); ?>" id="submit" /></p>
  275. </form>
  276. </div>
  277. <?php }
  278. ?>