PageRenderTime 31ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/Websites/remote/wp-content/themes/dynablue/functions.php

https://bitbucket.org/perchten/open-platform
PHP | 438 lines | 284 code | 75 blank | 79 comment | 49 complexity | 851bd406894d96f539c947cdafad6445 MD5 | raw file
  1. <?php
  2. if ( function_exists('register_sidebar') )
  3. {
  4. register_sidebar(array(
  5. 'before_widget' => '<li id="%1$s" class="widget %2$s">',
  6. 'after_widget' => '</li>',
  7. 'before_title' => '<h2 class="widgettitle">',
  8. 'after_title' => '</h2>',
  9. ));
  10. }
  11. define('FEATURED_SPEED', 5); // seconds
  12. define('FEATURED_POSTS', 5); // copunt
  13. /***********************************************************************/
  14. /* CUSTOM FIELDS */
  15. /*
  16. thumbnail = for top carusel
  17. */
  18. /***********************************************************************/
  19. function carousel_featured_posts($max_posts=5, $offset=0) {
  20. if(!function_exists('show_featured_posts'))
  21. return false;
  22. global $wpdb, $table_prefix;
  23. $table_name = $table_prefix."features";
  24. $sql = "SELECT * FROM $table_name ORDER BY date DESC LIMIT $offset, $max_posts";
  25. $posts = $wpdb->get_results($sql);
  26. $html = '';
  27. $coint_i = 0;
  28. foreach($posts as $post) {
  29. $coint_i++;
  30. $id = $post->id;
  31. $posts_table = $table_prefix.'posts';
  32. $sql_post = "SELECT * FROM $posts_table where id = $id";
  33. $rs_post = $wpdb->get_results($sql_post);
  34. $data = $rs_post[0];
  35. $post_title = stripslashes($data->post_title);
  36. $post_title = str_replace('"', '', $post_title);
  37. $post_content = stripslashes($data->post_content);
  38. $post_content = str_replace(']]>', ']]&gt;', $post_content);
  39. $post_content = strip_tags($post_content);
  40. $permalink = get_permalink($data->ID);
  41. $post_id = $data->ID;
  42. $html .= '<div class="board_item">
  43. <!-- board_item -->
  44. <p>';
  45. $thumbnail = get_post_meta($post_id, 'thumbnail', true);
  46. if( isset($thumbnail) && !empty($thumbnail) ):
  47. $html .= '<img src="'.$thumbnail.'" alt="'.$post_title.'" />';
  48. endif;
  49. $html .= '<strong><a href="'.$permalink.'">'.get_string_limit($post_title,50).'</a></strong> '.get_string_limit($post_content,200).'</p>
  50. <p class="more"><a href="'.$permalink.'">Readmore</a></p>
  51. <!-- /board_item -->
  52. </div>';
  53. }
  54. echo $html;
  55. return $coint_i;
  56. }
  57. function wp_list_pages2($args) {
  58. $defaults = array(
  59. 'depth' => 0, 'show_date' => '',
  60. 'date_format' => get_option('date_format'),
  61. 'child_of' => 0, 'exclude' => '',
  62. 'title_li' => __('Pages'), 'echo' => 1,
  63. 'authors' => '', 'sort_column' => 'menu_order, post_title',
  64. 'link_before' => '', 'link_after' => ''
  65. );
  66. $r = wp_parse_args( $args, $defaults );
  67. extract( $r, EXTR_SKIP );
  68. $output = '';
  69. $current_page = 0;
  70. // sanitize, mostly to keep spaces out
  71. $r['exclude'] = preg_replace('/[^0-9,]/', '', $r['exclude']);
  72. // Allow plugins to filter an array of excluded pages
  73. $r['exclude'] = implode(',', apply_filters('wp_list_pages_excludes', explode(',', $r['exclude'])));
  74. // Query pages.
  75. $r['hierarchical'] = 0;
  76. $pages = get_pages($r);
  77. if ( !empty($pages) ) {
  78. if ( $r['title_li'] )
  79. $output .= '<li class="pagenav">' . $r['title_li'] . '<ul>';
  80. global $wp_query;
  81. if ( is_page() || $wp_query->is_posts_page )
  82. $current_page = $wp_query->get_queried_object_id();
  83. $output .= walk_page_tree($pages, $r['depth'], $current_page, $r);
  84. if ( $r['title_li'] )
  85. $output .= '</ul></li>';
  86. }
  87. $output = apply_filters('wp_list_pages', $output);
  88. if ( $r['echo'] )
  89. echo $output;
  90. else
  91. return $output;
  92. }
  93. function get_string_limit($output, $max_char)
  94. {
  95. $output = str_replace(']]>', ']]&gt;', $output);
  96. $output = strip_tags($output);
  97. if ((strlen($output)>$max_char) && ($espacio = strpos($output, " ", $max_char )))
  98. {
  99. $output = substr($output, 0, $espacio).'...';
  100. return $output;
  101. }
  102. else
  103. {
  104. return $output;
  105. }
  106. }
  107. /* ======================== ADMIN ========================================= */
  108. // Hook for adding admin menus
  109. add_action('admin_menu', 'theme_ads_add_pages');
  110. // action function for above hook
  111. function theme_ads_add_pages() {
  112. // Add a new submenu under Options:
  113. //add_options_page('Theme Ads', 'Theme Ads', 8, 'theme_ads', 'theme_ads_options_page');
  114. add_menu_page('Theme Options', 'Theme Options', 8, 'functions.php', 'theme_main_options_page');
  115. add_submenu_page('functions.php', 'Main Settings', 'Main Settings', 8, 'functions.php', 'theme_main_options_page');
  116. }
  117. function theme_main_options_page() {
  118. $theme_ads_page_options = 'theme_twitter_id, theme_google_id';
  119. ?>
  120. <div class="wrap">
  121. <form method="post" action="options.php">
  122. <fieldset>
  123. <?php wp_nonce_field('update-options'); ?>
  124. <h2>Theme Main Options</h2>
  125. <br />
  126. <?php if ( $_REQUEST['updated'] ) echo '<div id="message" class="updated fade"><p><strong>Theme Main settings saved.</strong></p></div>'; ?>
  127. <h3>General</h3>
  128. <table>
  129. <tr>
  130. <td><label for="theme_twitter_id">Twitter ID</label></td>
  131. <td>:</td>
  132. <td><input type="text" name="theme_twitter_id" id="theme_twitter_id" value="<?php echo get_option('theme_twitter_id'); ?>" size="40" /></td>
  133. </tr>
  134. </table>
  135. <table>
  136. <tr>
  137. <td>
  138. <p class="submit">
  139. <input type="submit" name="Submit" value="<?php _e('Save Changes') ?>" />
  140. </p>
  141. </td>
  142. </tr>
  143. </table>
  144. </fieldset>
  145. <input type="hidden" name="action" value="update" />
  146. <input type="hidden" name="page_options" value="<? echo $theme_ads_page_options; ?>" />
  147. </form>
  148. </div>
  149. <?
  150. }
  151. function theme_twitter_show()
  152. {
  153. $id = trim(get_option('theme_twitter_id'));
  154. if(!empty($id))
  155. {
  156. ?>
  157. <script type="text/javascript" src="http://twitter.com/javascripts/blogger.js"></script>
  158. <script type="text/javascript" src="http://twitter.com/statuses/user_timeline/<?php echo $id; ?>.json?callback=twitterCallback2&count=1"></script>
  159. <?php
  160. }
  161. }
  162. function theme_twitter_link_show()
  163. {
  164. $id = trim(get_option('theme_twitter_id'));
  165. if(!empty($id))
  166. {
  167. return 'http://twitter.com/'.$id;
  168. }
  169. else
  170. {
  171. return '#';
  172. }
  173. }
  174. /* +++++++++++++++++++++++++++ ADMIN END ++++++++++++++++++++++++++++++++++++++++++++++++ */
  175. /**
  176. * HTML comment list class.
  177. *
  178. * @package WordPress
  179. * @uses Walker
  180. * @since unknown
  181. */
  182. class Walker_Comment2 extends Walker {
  183. /**
  184. * @see Walker::$tree_type
  185. * @since unknown
  186. * @var string
  187. */
  188. var $tree_type = 'comment';
  189. /**
  190. * @see Walker::$db_fields
  191. * @since unknown
  192. * @var array
  193. */
  194. var $db_fields = array ('parent' => 'comment_parent', 'id' => 'comment_ID');
  195. /**
  196. * @see Walker::start_lvl()
  197. * @since unknown
  198. *
  199. * @param string $output Passed by reference. Used to append additional content.
  200. * @param int $depth Depth of comment.
  201. * @param array $args Uses 'style' argument for type of HTML list.
  202. */
  203. function start_lvl(&$output, $depth, $args) {
  204. $GLOBALS['comment_depth'] = $depth + 1;
  205. echo "<div class='children '>\n";
  206. }
  207. /**
  208. * @see Walker::end_lvl()
  209. * @since unknown
  210. *
  211. * @param string $output Passed by reference. Used to append additional content.
  212. * @param int $depth Depth of comment.
  213. * @param array $args Will only append content if style argument value is 'ol' or 'ul'.
  214. */
  215. function end_lvl(&$output, $depth, $args) {
  216. $GLOBALS['comment_depth'] = $depth + 1;
  217. echo "</div>\n";
  218. }
  219. /**
  220. * @see Walker::start_el()
  221. * @since unknown
  222. *
  223. * @param string $output Passed by reference. Used to append additional content.
  224. * @param object $comment Comment data object.
  225. * @param int $depth Depth of comment in reference to parents.
  226. * @param array $args
  227. */
  228. function start_el(&$output, $comment, $depth, $args) {
  229. $depth++;
  230. $GLOBALS['comment_depth'] = $depth;
  231. if ( !empty($args['callback']) ) {
  232. call_user_func($args['callback'], $comment, $args, $depth);
  233. return;
  234. }
  235. $GLOBALS['comment'] = $comment;
  236. extract($args, EXTR_SKIP);
  237. $tag = 'div';
  238. $add_below = 'div-comment';
  239. ?>
  240. <<?php echo $tag ?> <?php comment_class(empty( $args['has_children'] ) ? '' : 'parent') ?> id="comment-<?php comment_ID() ?>">
  241. <div class="commentmet_data" id="div-comment-<?php comment_ID() ?>">
  242. <table cellpadding="0" cellspacing="0" width="100%">
  243. <tr>
  244. <td colspan="2">
  245. <div class="commentmetadata">
  246. <span><?php echo get_comment_author_link(); ?></span> said on <?php comment_time('d-m-Y') ?>
  247. </div>
  248. </td>
  249. </tr>
  250. <tr>
  251. <td width="102">
  252. <div class="commentmet_avatar">
  253. <?php if ($args['avatar_size'] != 0) echo get_avatar( $comment, 86 /*$args['avatar_size']*/ ); ?>
  254. </div>
  255. </td>
  256. <td width="83%">
  257. <div class="commentmet_text">
  258. <?php comment_text() ?>
  259. <div class="commentmet_replay"><?php comment_reply_link(array_merge( $args, array('add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth']))) ?></div>
  260. </div>
  261. </td>
  262. </tr>
  263. </table>
  264. </div>
  265. <?php
  266. }
  267. /**
  268. * @see Walker::end_el()
  269. * @since unknown
  270. *
  271. * @param string $output Passed by reference. Used to append additional content.
  272. * @param object $comment
  273. * @param int $depth Depth of comment.
  274. * @param array $args
  275. */
  276. function end_el(&$output, $comment, $depth, $args) {
  277. if ( !empty($args['end-callback']) ) {
  278. call_user_func($args['end-callback'], $comment, $args, $depth);
  279. return;
  280. }
  281. echo "</div>\n";
  282. }
  283. }
  284. /**
  285. * List comments
  286. *
  287. * Used in the comments.php template to list comments for a particular post
  288. *
  289. * @since 2.7.0
  290. * @uses Walker_Comment
  291. *
  292. * @param string|array $args Formatting options
  293. * @param array $comments Optional array of comment objects. Defaults to $wp_query->comments
  294. */
  295. function wp_list_comments2($args = array(), $comments = null ) {
  296. global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop;
  297. $in_comment_loop = true;
  298. $comment_alt = $comment_thread_alt = 0;
  299. $comment_depth = 1;
  300. $defaults = array('walker' => null, 'max_depth' => '', 'style' => 'div', 'callback' => null, 'end-callback' => null, 'type' => 'all',
  301. 'page' => '', 'per_page' => '', 'avatar_size' => 86, 'reverse_top_level' => null, 'reverse_children' => '');
  302. $r = wp_parse_args( $args, $defaults );
  303. // Figure out what comments we'll be looping through ($_comments)
  304. if ( null !== $comments ) {
  305. $comments = (array) $comments;
  306. if ( empty($comments) )
  307. return;
  308. if ( 'all' != $r['type'] ) {
  309. $comments_by_type = &separate_comments($comments);
  310. if ( empty($comments_by_type[$r['type']]) )
  311. return;
  312. $_comments = $comments_by_type[$r['type']];
  313. } else {
  314. $_comments = $comments;
  315. }
  316. } else {
  317. if ( empty($wp_query->comments) )
  318. return;
  319. if ( 'all' != $r['type'] ) {
  320. if ( empty($wp_query->comments_by_type) )
  321. $wp_query->comments_by_type = &separate_comments($wp_query->comments);
  322. if ( empty($wp_query->comments_by_type[$r['type']]) )
  323. return;
  324. $_comments = $wp_query->comments_by_type[$r['type']];
  325. } else {
  326. $_comments = $wp_query->comments;
  327. }
  328. }
  329. if ( '' === $r['per_page'] && get_option('page_comments') )
  330. $r['per_page'] = get_query_var('comments_per_page');
  331. if ( empty($r['per_page']) ) {
  332. $r['per_page'] = 0;
  333. $r['page'] = 0;
  334. }
  335. if ( '' === $r['max_depth'] ) {
  336. if ( get_option('thread_comments') )
  337. $r['max_depth'] = get_option('thread_comments_depth');
  338. else
  339. $r['max_depth'] = -1;
  340. }
  341. if ( '' === $r['page'] ) {
  342. if ( empty($overridden_cpage) ) {
  343. $r['page'] = get_query_var('cpage');
  344. } else {
  345. $threaded = ( -1 == $r['max_depth'] ) ? false : true;
  346. $r['page'] = ( 'newest' == get_option('default_comments_page') ) ? get_comment_pages_count($_comments, $r['per_page'], $threaded) : 1;
  347. set_query_var( 'cpage', $r['page'] );
  348. }
  349. }
  350. // Validation check
  351. $r['page'] = intval($r['page']);
  352. if ( 0 == $r['page'] && 0 != $r['per_page'] )
  353. $r['page'] = 1;
  354. if ( null === $r['reverse_top_level'] )
  355. $r['reverse_top_level'] = ( 'desc' == get_option('comment_order') ) ? TRUE : FALSE;
  356. extract( $r, EXTR_SKIP );
  357. if ( empty($walker) )
  358. $walker = new Walker_Comment2;
  359. $walker->paged_walk($_comments, $max_depth, $page, $per_page, $r);
  360. $wp_query->max_num_comment_pages = $walker->max_pages;
  361. $in_comment_loop = false;
  362. }
  363. ?>