PageRenderTime 38ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/sergiohzlz/reportaprod
PHP | 348 lines | 282 code | 54 blank | 12 comment | 36 complexity | 226845d803344c18f8866afd4977b1df MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, AGPL-1.0, LGPL-2.1
  1. <?php
  2. global $depo_post_types;
  3. $content_width = 650;
  4. add_theme_support( 'automatic-feed-links' );
  5. add_custom_background();
  6. if( !function_exists( 'before_post' ) ) { function before_post() { } }
  7. if( !function_exists( 'after_post' ) ) { function after_post() { } }
  8. if ( is_singular() ) wp_enqueue_script( 'comment-reply' );
  9. if ( function_exists('register_sidebar') ) {
  10. register_sidebar(array(
  11. 'name' => 'Left',
  12. 'description' => __( 'An empty left header widget area will show your blog tagline.', 'depo-square' ),
  13. 'before_widget' => '',
  14. 'after_widget' => '',
  15. 'before_title' => '<h3 class="widgettitle">',
  16. 'after_title' => '</h3>',
  17. ));
  18. register_sidebar(array(
  19. 'name' => 'Center',
  20. 'description' => __( 'An empty center header widget area will show your latest status message.', 'depo-square' ),
  21. 'before_widget' => '',
  22. 'after_widget' => '',
  23. 'before_title' => '<h3 class="widgettitle">',
  24. 'after_title' => '</h3>',
  25. ));
  26. register_sidebar(array(
  27. 'name' => 'Right',
  28. 'description' => __( 'An empty right header widget area will show interesting photos from Flickr.', 'depo-square' ),
  29. 'before_widget' => '',
  30. 'after_widget' => '',
  31. 'before_title' => '<h3 class="widgettitle">',
  32. 'after_title' => '</h3>',
  33. ));
  34. }
  35. register_sidebar_widget('DePo Square About', 'depo_square_about_widget');
  36. function depo_square_about_widget() { ?>
  37. <h3>
  38. <?php if( $page = get_page_by_title('About') ) { echo "<a href='" . get_permalink($page->ID) . "'>About</a>"; } else { ?>
  39. About
  40. <?php } ?>
  41. </h3>
  42. <p><?php bloginfo('description'); ?></p>
  43. <?php }
  44. register_sidebar_widget('DePo Square Status', 'depo_square_status_widget');
  45. function depo_square_status_widget() {
  46. global $depo_post_types; ?>
  47. <?php if(get_option( $depo_post_types['status']['id'] )) : ?>
  48. <h3><a href="<?php echo get_category_link(get_option( $depo_post_types['status']['id'] )); ?>">Status</a></h3>
  49. <?php
  50. $depo_status_query = new WP_Query("posts_per_page=1&cat=".get_option( $depo_post_types['status']['id'] ));
  51. while ($depo_status_query->have_posts()) : $depo_status_query->the_post(); ?>
  52. <?php the_content(); ?>
  53. <?php
  54. endwhile;
  55. else :
  56. ?>
  57. <?php if( is_user_logged_in() ) :?>
  58. <h3>Status</h3>
  59. <p><a href="<?php bloginfo('wpurl'); ?>/wp-admin/themes.php?page=depo-square">Setup your post type categories</a> to have your latest status message appear here.</p>
  60. <?php endif;?>
  61. <?php endif;?>
  62. <?php }
  63. function depo_square_flickr_widget() {
  64. if(class_exists('Widget_DePoFlickr')) {
  65. $args = array('before_title' => '<h3>', 'after_title' => '</h3>', 'title' => 'Flickr');
  66. $flickr = new Widget_DePoFlickr;
  67. @$flickr->widget($args);
  68. }
  69. }
  70. $depo_post_types = array(
  71. 'post' =>
  72. array(
  73. 'id' => 'type-post',
  74. 'proper_name' => 'Articles'
  75. ),
  76. 'status' =>
  77. array(
  78. 'id' => 'type-status',
  79. 'proper_name' => 'Statuses'
  80. ),
  81. 'quote' =>
  82. array(
  83. 'id' => 'type-quote',
  84. 'proper_name' => 'Quotes'
  85. ),
  86. 'links' =>
  87. array(
  88. 'id' => 'type-link',
  89. 'proper_name' => 'Links'
  90. ),
  91. 'photo' =>
  92. array(
  93. 'id' => 'type-photo',
  94. 'proper_name' => 'Photos'
  95. )
  96. );
  97. function depo_post_category_html () {
  98. $type = depo_post_type();
  99. $type = $type['id'];
  100. echo (!$type or $type == 'type-post') ?
  101. "<img src='".get_bloginfo('template_directory')."/i/type-post.png' alt='Post' />"
  102. :
  103. "<img src='".get_bloginfo('template_directory')."/i/$type.png' alt='$type[proper_name]' />";
  104. }
  105. function depo_post_type() {
  106. global $depo_post_types;
  107. $custom = false;
  108. foreach( $depo_post_types as $key => $option ) {
  109. if( in_category(get_option( $option['id'] )) ) {
  110. $custom = $option;
  111. }
  112. }
  113. if(!$custom)
  114. return $depo_post_types['post'];
  115. return $custom;
  116. }
  117. function depo_post_category () {
  118. $type = depo_post_type();
  119. $type = $type['id'];
  120. return (!$type or $type == 'type-post') ?
  121. "type-post"
  122. :
  123. $type;
  124. }
  125. // type-photo functions
  126. function replace_empty_tag($m) {
  127. $no_replace = array('embed'); // expand as required
  128. if ( in_array( strtolower($m[1]), $no_replace ) )
  129. return $m[0]; // return the original untouched
  130. return '';
  131. }
  132. // remove image tag from post_content for display
  133. function image_above($entry) {
  134. // don't scrape the image for the feed
  135. if (is_feed()) { return $entry; }
  136. $entry = str_replace('[/wp_caption]','', $entry);
  137. $entry = str_replace('[/caption]','', $entry);
  138. //remove image tag
  139. $image = preg_replace('/<img [^>]*src=(\"|\').+?(\1)[^>]*\/*>/','', $entry);
  140. //remove any empty tags left by the scrape.
  141. $entry = str_replace('<p> </p>', '', $entry);
  142. $entry = preg_replace_callback( '|<([a-z]+)[^>]*>\s*</\1>|i', 'replace_empty_tag', $entry );
  143. $entry = preg_replace_callback( '|<([a-z]+)[^>]*>\s*</\1>|i', 'replace_empty_tag', $entry );
  144. $entry = preg_replace_callback( '|<([a-z]+)[^>]*>\s*</\1>|i', 'replace_empty_tag', $entry );
  145. return $image.$entry;
  146. }
  147. //admin interface
  148. if( is_admin() ) {
  149. add_action('admin_menu', 'deposquare_add_page');
  150. function deposquare_add_page() {
  151. add_theme_page(__('Theme Options'), __('Theme Options'), 'edit_theme_options', 'theme_options', 'deposquare_do_page');
  152. }
  153. function deposquare_do_page() {
  154. global $depo_post_types;
  155. if( esc_attr( $_POST['action'] ) == 'update' ) {
  156. foreach( $depo_post_types as $key => $option ) {
  157. if( esc_attr( $_POST[ $option['id'] ] ) ) update_option( $option['id'], esc_attr( $_POST[ $option['id'] ] ) );
  158. }
  159. }
  160. foreach( $depo_post_types as $key => $option ) {
  161. register_setting( 'deposquareops', $option['id'], 'intval' );
  162. }
  163. ?>
  164. <div class="wrap">
  165. <h2><?php _e('DePo Square Theme Options'); ?></h2>
  166. <form method="post">
  167. <?php settings_fields( 'deposquareops' ); ?>
  168. <?php
  169. $defaults = array(
  170. 'show_option_all' => '', 'show_option_none' => '',
  171. 'orderby' => 'id', 'order' => 'ASC',
  172. 'show_last_update' => 0, 'show_count' => 0,
  173. 'hide_empty' => 1, 'child_of' => 0,
  174. 'exclude' => '', 'echo' => 1,
  175. 'selected' => 0, 'hierarchical' => 0,
  176. 'name' => 'cat', 'class' => 'postform',
  177. 'depth' => 0, 'tab_index' => 0
  178. );
  179. $args = array('hide_empty' => 0, 'name' => 'category_parent', 'orderby' => 'name', 'selected' => $category->parent, 'hierarchical' => true, 'show_option_none' => __('None'));
  180. $r = wp_parse_args( $args, $defaults );
  181. extract( $r );
  182. $categories = get_categories($args);
  183. ?>
  184. <table class="form-table">
  185. <tr valign="top">
  186. <th scope="row">Category Mappings</th>
  187. </tr>
  188. <tr>
  189. <td>
  190. <table border="0" cellspacing="5" cellpadding="5">
  191. <tr><th><strong>Type of Post</strong></th> <th><strong>Category to Map</strong></th></tr>
  192. <?php foreach( $depo_post_types as $key => $option ) {
  193. if($key != 'post') {
  194. ?>
  195. <tr><td><?php _e( $option['proper_name'] ); ?></td><td>
  196. <?php $value = get_option( $option['id'] ); ?>
  197. <select name="<?php echo $option['id'] ?>" id="<?php echo $option['id'] ?>" size="1">
  198. <?php /*foreach($categories as $catkey => $data) { ?>
  199. <option <?php if( $value == $data->cat_ID) echo ' selected="selected"'; ?>
  200. value="<?php echo $data->cat_ID; ?>">
  201. <?php if( $data->parent > 0 ) { $pad .= '&nbsp;&nbsp;&nbsp;'; } else { $pad = ''; } ?>
  202. <?php echo $pad.$data->category_nicename; ?>
  203. </option>
  204. <?php } */?>
  205. <?php
  206. $output = '';
  207. $output .= walk_category_dropdown_tree( $categories, $r['depth'], $r );
  208. if($value > 0) $output = preg_replace('/(value="'.$value.'")/', '$1'.' selected="selected"', $output);
  209. echo $output;
  210. ?>
  211. </select>
  212. <?php $value = 0; ?>
  213. </td></tr>
  214. <?php } } ?>
  215. </table>
  216. </td>
  217. </tr>
  218. </table>
  219. <p class="submit">
  220. <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
  221. </p>
  222. </form>
  223. </div>
  224. <?php }
  225. }
  226. function old_fetch_rss_summary( $a, $b ) { return fetch_rss( $a, $b ); }
  227. register_widget('Widget_DePoFlickr');
  228. class Widget_DePoFlickr extends WP_Widget {
  229. function Widget_DePoFlickr() {
  230. $widget_ops = array('classname' => 'depo_widget_flickr', 'description' => __( "For DePo Square: Display your flickr photos.") );
  231. $this->WP_Widget('depo-square-flickr', __('DePo Square Flickr'), $widget_ops);
  232. }
  233. function widget( $args, $instance ) {
  234. global $current_blog;
  235. require_once(ABSPATH . WPINC . '/rss.php');
  236. extract( $args );
  237. $flickr_rss_url = esc_url_raw( $instance['flickr_rss_url'] );
  238. if ( empty($flickr_rss_url) ) $flickr_rss_url = __('http://feeds.feedburner.com/flickr_interestingness');
  239. if( empty($title) ) $title = apply_filters('widget_title', $instance['title']);
  240. if ( empty($title) ) $title = __( 'Flickr' );
  241. if ( empty($items) || $items < 1 || $items > 10 ) $items = 8;
  242. if( !$photos = @wp_cache_get('widget-depo-square-flickr') ) {
  243. $flickr_photos = old_fetch_rss_summary( $flickr_rss_url, array( 'link', 'title', 'media:thumbnail', 'description' ) );
  244. if( is_array( $flickr_photos->items ) ) {
  245. $photos = '';
  246. $items = array_slice( $flickr_photos->items, 0, $items );
  247. while( list( $key, $photo ) = each( $items ) ) {
  248. $href = esc_url( $photo['link'] );
  249. $itemtitle = esc_attr( $photo['title'] );
  250. if ( isset( $photo['media:thumbnail'] ) ) {
  251. $src = str_replace( "_s.jpg", "_t.jpg", esc_url( $photo['media:thumbnail']['url'] ) );
  252. } else { // Sometimes the image url is in the description
  253. $src = preg_match( '/src="(.*?)"/i', $photo['description'], $p );
  254. $src = $p[1];
  255. $src = str_replace( '_m.jpg', '_t.jpg', $src );
  256. $src = esc_url( $src );
  257. }
  258. if(empty($src)) $src = $photo['enclosure'];
  259. $photos .= "<li><a href='$href'><img alt='$itemtitle' title='$itemtitle' src='$src' /></a></li>";
  260. }
  261. $flickr_home = esc_url( $flickr_photos->channel[ 'link' ] );
  262. $flickr_more_title = esc_attr( $flickr_photos->channel[ 'title' ] );
  263. @wp_cache_add( 'widget-depo-square-flickr', $photos, 'widget', $expire );
  264. }
  265. }
  266. echo $before_title.'<a href="'.$flickr_home.'">'.$title.'</a>'.$after_title;
  267. echo '<ul class="widget_flickr_depo">'.$photos.'</ul>';
  268. if(function_exists('stats_extra') ) stats_extra( 'widget', 'depo-square-flickr' );
  269. }
  270. function update( $new_instance, $old_instance ) {
  271. $instance = $old_instance;
  272. $instance['flickr_rss_url'] = strip_tags(stripslashes($new_instance['flickr_rss_url']));
  273. $instance['title'] = strip_tags(stripslashes($new_instance['title']));
  274. wp_cache_delete( 'widget-depo-square-flickr' , 'widget' );
  275. return $instance;
  276. }
  277. function form( $instance ) {
  278. //Defaults
  279. $instance = wp_parse_args( (array) $instance, array('flickr_rss_url' => '', 'title' => '') );
  280. $flickr_rss_url = esc_attr($instance['flickr_rss_url']);
  281. $title = esc_attr($instance['title']);
  282. echo '<p><label for="' . $this->get_field_id('title') . '">' . __('Title:') . '
  283. <input class="widefat" id="' . $this->get_field_id('title') . '" name="' . $this->get_field_name('title') . '" type="text" value="' . $title . '" />
  284. </label></p>
  285. <p><label for="' . $this->get_field_id('flickr_rss_url') . '">' . __('RSS URL:') . ' *
  286. <input class="widefat" id="' . $this->get_field_id('flickr_rss_url') . '" name="' . $this->get_field_name('flickr_rss_url') . '" type="text" value="' . $flickr_rss_url . '" />
  287. </label></p>
  288. <p>
  289. * Your RSS feed can be found on your Flickr homepage. Scroll down to the bottom of the page until you see the <em>Feed</em> link and copy that into the box above.
  290. </p>
  291. <p>Leave the Flickr RSS URL blank to display <a href="http://www.flickr.com/explore/interesting">interesting</a> Flickr photos.</p>
  292. ';
  293. }
  294. }