Khalequzzaman

functions.php file of mobilepress plugin

Nov 26th, 2015
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.80 KB | None | 0 0
  1. <?php
  2. function string_limit_words($string, $word_limit)
  3. {
  4. $words = explode(' ', $string, ($word_limit + 1));
  5. if(count($words) > $word_limit)
  6. array_pop($words);
  7. return implode(' ', $words);
  8. }
  9. ?>
  10. <?php
  11. /*******************************************************************
  12. * @Author: Khalequzzaman
  13. ********************************************************************/
  14. /* Function that Rounds To The Nearest Value.
  15. Needed for the pagenavi() function */
  16. function round_num($num, $to_nearest) {
  17. /*Round fractions down (http://php.net/manual/en/function.floor.php)*/
  18. return floor($num/$to_nearest)*$to_nearest;
  19. }
  20. /* Function that performs a Boxed Style Numbered Pagination (also called Page Navigation).
  21. Function is largely based on Version 2.4 of the WP-PageNavi plugin */
  22. function pagenavi($before = '', $after = '') {
  23. global $wpdb, $wp_query;
  24. $pagenavi_options = array();
  25. $pagenavi_options['pages_text'] = ('Page %CURRENT_PAGE% of %TOTAL_PAGES%');
  26. $pagenavi_options['current_text'] = '%PAGE_NUMBER%';
  27. $pagenavi_options['page_text'] = '%PAGE_NUMBER%';
  28. $pagenavi_options['first_text'] = ('First');
  29. $pagenavi_options['last_text'] = ('Last');
  30. $pagenavi_options['next_text'] = '&#187;';
  31. $pagenavi_options['prev_text'] = 'Prev.';
  32. $pagenavi_options['dotright_text'] = '...';
  33. $pagenavi_options['dotleft_text'] = '...';
  34. $pagenavi_options['num_pages'] = 5; //continuous block of page numbers
  35. $pagenavi_options['always_show'] = 0;
  36. $pagenavi_options['num_larger_page_numbers'] = 0;
  37. $pagenavi_options['larger_page_numbers_multiple'] = 5;
  38. //If NOT a single Post is being displayed
  39. /*http://codex.wordpress.org/Function_Reference/is_single)*/
  40. if (!is_single()) {
  41. $request = $wp_query->request;
  42. //intval — Get the integer value of a variable
  43. /*http://php.net/manual/en/function.intval.php*/
  44. $posts_per_page = intval(get_query_var('posts_per_page'));
  45. //Retrieve variable in the WP_Query class.
  46. /*http://codex.wordpress.org/Function_Reference/get_query_var*/
  47. $paged = intval(get_query_var('paged'));
  48. $numposts = $wp_query->found_posts;
  49. $max_page = $wp_query->max_num_pages;
  50. //empty — Determine whether a variable is empty
  51. /*http://php.net/manual/en/function.empty.php*/
  52. if(empty($paged) || $paged == 0) {
  53. $paged = 1;
  54. }
  55. $pages_to_show = intval($pagenavi_options['num_pages']);
  56. $larger_page_to_show = intval($pagenavi_options['num_larger_page_numbers']);
  57. $larger_page_multiple = intval($pagenavi_options['larger_page_numbers_multiple']);
  58. $pages_to_show_minus_1 = $pages_to_show - 1;
  59. $half_page_start = floor($pages_to_show_minus_1/2);
  60. //ceil — Round fractions up (http://us2.php.net/manual/en/function.ceil.php)
  61. $half_page_end = ceil($pages_to_show_minus_1/2);
  62. $start_page = $paged - $half_page_start;
  63. if($start_page <= 0) {
  64. $start_page = 1;
  65. }
  66. $end_page = $paged + $half_page_end;
  67. if(($end_page - $start_page) != $pages_to_show_minus_1) {
  68. $end_page = $start_page + $pages_to_show_minus_1;
  69. }
  70. if($end_page > $max_page) {
  71. $start_page = $max_page - $pages_to_show_minus_1;
  72. $end_page = $max_page;
  73. }
  74. if($start_page <= 0) {
  75. $start_page = 1;
  76. }
  77. $larger_per_page = $larger_page_to_show*$larger_page_multiple;
  78. //round_num() custom function - Rounds To The Nearest Value.
  79. $larger_start_page_start = (round_num($start_page, 10) + $larger_page_multiple) - $larger_per_page;
  80. $larger_start_page_end = round_num($start_page, 10) + $larger_page_multiple;
  81. $larger_end_page_start = round_num($end_page, 10) + $larger_page_multiple;
  82. $larger_end_page_end = round_num($end_page, 10) + ($larger_per_page);
  83. if($larger_start_page_end - $larger_page_multiple == $start_page) {
  84. $larger_start_page_start = $larger_start_page_start - $larger_page_multiple;
  85. $larger_start_page_end = $larger_start_page_end - $larger_page_multiple;
  86. }
  87. if($larger_start_page_start <= 0) {
  88. $larger_start_page_start = $larger_page_multiple;
  89. }
  90. if($larger_start_page_end > $max_page) {
  91. $larger_start_page_end = $max_page;
  92. }
  93. if($larger_end_page_end > $max_page) {
  94. $larger_end_page_end = $max_page;
  95. }
  96. if($max_page > 1 || intval($pagenavi_options['always_show']) == 1) {
  97. /*http://php.net/manual/en/function.str-replace.php */
  98. /*number_format_i18n(): Converts integer number to format based on locale (wp-includes/functions.php*/
  99. $pages_text = str_replace("%CURRENT_PAGE%", number_format_i18n($paged), $pagenavi_options['pages_text']);
  100. $pages_text = str_replace("%TOTAL_PAGES%", number_format_i18n($max_page), $pages_text);
  101. echo $before.'<div id="pagination-links">'."\n";
  102. if(!empty($pages_text)) {
  103. echo '<span class="pages">'.$pages_text.'</span>';
  104. }
  105. //Displays a link to the previous post which exists in chronological order from the current post.
  106. /*http://codex.wordpress.org/Function_Reference/previous_post_link*/
  107. previous_posts_link($pagenavi_options['prev_text']);
  108.  
  109. if ($start_page >= 2 && $pages_to_show < $max_page) {
  110. $first_page_text = str_replace("%TOTAL_PAGES%", number_format_i18n($max_page), $pagenavi_options['first_text']);
  111. //esc_url(): Encodes < > & " ' (less than, greater than, ampersand, double quote, single quote).
  112. /*http://codex.wordpress.org/Data_Validation*/
  113. //get_pagenum_link():(wp-includes/link-template.php)-Retrieve get links for page numbers.
  114. echo '<a href="'.esc_url(get_pagenum_link()).'" class="first" title="'.$first_page_text.'">1</a>';
  115. if(!empty($pagenavi_options['dotleft_text'])) {
  116. echo '<span class="expand">'.$pagenavi_options['dotleft_text'].'</span>';
  117. }
  118. }
  119. if($larger_page_to_show > 0 && $larger_start_page_start > 0 && $larger_start_page_end <= $max_page) {
  120. for($i = $larger_start_page_start; $i < $larger_start_page_end; $i+=$larger_page_multiple) {
  121. $page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $pagenavi_options['page_text']);
  122. echo '<a href="'.esc_url(get_pagenum_link($i)).'" class="single_page" title="'.$page_text.'">'.$page_text.'</a>';
  123. }
  124. }
  125. for($i = $start_page; $i <= $end_page; $i++) {
  126. if($i == $paged) {
  127. $current_page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $pagenavi_options['current_text']);
  128. echo '<span class="current">'.$current_page_text.'</span>';
  129. } else {
  130. $page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $pagenavi_options['page_text']);
  131. echo '<a href="'.esc_url(get_pagenum_link($i)).'" class="single_page" title="'.$page_text.'">'.$page_text.'</a>';
  132. }
  133. }
  134. if ($end_page < $max_page) {
  135. if(!empty($pagenavi_options['dotright_text'])) {
  136. echo '<span class="expand">'.$pagenavi_options['dotright_text'].'</span>';
  137. }
  138. $last_page_text = str_replace("%TOTAL_PAGES%", number_format_i18n($max_page), $pagenavi_options['last_text']);
  139. echo '<a href="'.esc_url(get_pagenum_link($max_page)).'" class="last" title="'.$last_page_text.'">'.$max_page.'</a>';
  140. }
  141. next_posts_link($pagenavi_options['next_text'], $max_page);
  142. if($larger_page_to_show > 0 && $larger_end_page_start < $max_page) {
  143. for($i = $larger_end_page_start; $i <= $larger_end_page_end; $i+=$larger_page_multiple) {
  144. $page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $pagenavi_options['page_text']);
  145. echo '<a href="'.esc_url(get_pagenum_link($i)).'" class="single_page" title="'.$page_text.'">'.$page_text.'</a>';
  146. }
  147. }
  148. echo '</div>'.$after."\n";
  149. }
  150. }
  151. }
  152. ?>
  153. <?php
  154. /*******************************************************************
  155. * @Author: Khalequzzaman
  156. ********************************************************************/function auto_copyright($year = 'auto'){ ?>
  157. <?php if(intval($year) == 'auto'){ $year = date('Y'); } ?>
  158. <?php if(intval($year) == date('Y')){ echo intval($year); } ?>
  159. <?php if(intval($year) < date('Y')){ echo intval($year) . ' - ' . date('Y'); } ?>
  160. <?php if(intval($year) > date('Y')){ echo date('Y'); } ?>
  161. <?php } ?>
  162. <?php
  163. function mytheme_comment($comment, $args, $depth) {
  164. $GLOBALS['comment'] = $comment; ?>
  165.  
  166. <div class="comment"> <div class="comment-header"> <?php printf(__('<h5 class="title">%s</h5>'), get_comment_author_link()) ?><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>"><?php printf(__('%1$s at %2$s'), get_comment_date(), get_comment_time()) ?></a><?php edit_comment_link(__('(Edit)'),' ','') ?></div>
  167.  
  168. <div class="comment-content"><?php if ($comment->comment_approved == '0') : ?>
  169. <em><?php _e('Your comment is awaiting moderation.') ?></em>
  170. <br />
  171. <?php endif; ?>
  172.  
  173.  
  174.  
  175. <?php comment_text() ?>
  176.  
  177. <div class="reply">
  178. <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
  179. </div>
  180. </div></div>
  181. <?php
  182. }
  183. ?>
Advertisement
Add Comment
Please, Sign In to add comment