PageRenderTime 45ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/wptouch/themes/core/core-functions.php

https://bitbucket.org/crypticrod/sr_wp_code
PHP | 287 lines | 225 code | 50 blank | 12 comment | 43 complexity | 7657b8abbbdef153a778784371c7ce3d MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1, GPL-3.0, LGPL-2.0, AGPL-3.0
  1. <?php
  2. // WPtouch Core Header Functions
  3. function wptouch_core_header_enqueue() {
  4. $version = get_bloginfo('version');
  5. if ( !bnc_wptouch_is_exclusive() ) {
  6. wp_enqueue_script('jquery-form');
  7. wp_enqueue_script('wptouch-core', '' . compat_get_plugin_url( 'wptouch' ) . '/themes/core/core.js', array('jquery'), '1.9.x' );
  8. wp_head();
  9. } elseif ( bnc_wptouch_is_exclusive() ) {
  10. echo "<script src='" . site_url() . "/wp-includes/js/jquery/jquery.js?wptouch' type='text/javascript' charset='utf-8'></script>\n";
  11. echo "<script src='" . site_url() . "/wp-includes/js/jquery/jquery.form.js?wptouch' type='text/javascript' charset='utf-8'></script>\n";
  12. echo "<script src='" . compat_get_plugin_url( 'wptouch' ) . "/themes/core/core.js?wptouch' type='text/javascript' charset='utf-8'></script>\n";
  13. }
  14. do_action( 'wptouch_core_header_enqueue' );
  15. }
  16. function wptouch_core_header_home() {
  17. if (bnc_is_home_enabled()) {
  18. echo sprintf(__( "%sHome%s", "wptouch" ), '<li><a href="' . get_home_url('/') . '"><img src="' . bnc_get_title_image() . '" alt=""/>','</a></li>');
  19. }
  20. }
  21. function wptouch_core_header_pages() {
  22. $pages = bnc_wp_touch_get_pages();
  23. global $blog_id;
  24. foreach ($pages as $p) {
  25. if ( file_exists( compat_get_plugin_dir( 'wptouch' ) . '/images/icon-pool/' . $p['icon'] ) ) {
  26. $image = compat_get_plugin_url( 'wptouch' ) . '/images/icon-pool/' . $p['icon'];
  27. } else {
  28. $image = compat_get_upload_url() . '/wptouch/custom-icons/' . $p['icon'];
  29. }
  30. echo('<li><a href="' . get_permalink($p['ID']) . '"><img src="' . $image . '" alt="icon" />' . __($p['post_title']) . '</a></li>');
  31. }
  32. }
  33. function wptouch_core_header_rss() {
  34. if (bnc_is_rss_enabled()) {
  35. echo sprintf(__( "%sRSS Feed%s", "wptouch" ), '<li><a href="' . get_bloginfo('rss2_url') . '"><img src="' . compat_get_plugin_url( 'wptouch' ) . '/images/icon-pool/RSS.png" alt="" />','</a></li>');
  36. }
  37. }
  38. function wptouch_core_header_email() {
  39. if (bnc_is_email_enabled()) {
  40. echo sprintf(__( "%sE-Mail%s", "wptouch" ), '<li><a href="mailto:' . get_bloginfo('admin_email') . '"><img src="' . compat_get_plugin_url( 'wptouch' ) . '/images/icon-pool/Mail.png" alt="" />','</a></li>');
  41. }
  42. }
  43. function wptouch_core_header_check_use() {
  44. if (false && function_exists('bnc_is_iphone') && !bnc_is_iphone()) {
  45. echo '<div class="content post">';
  46. echo sprintf(__( "%sWarning%s", "wptouch" ), '<a href="#" class="h2">','</a>');
  47. echo '<div class="mainentry">';
  48. echo __( "Sorry, this theme is only meant for use on touch smartphones.", "wptouch" );
  49. echo '</div></div>';
  50. echo '' .get_footer() . '';
  51. echo '</body>';
  52. die;
  53. }
  54. }
  55. function wptouch_core_header_styles() {
  56. include('core-styles.php' );
  57. }
  58. function wptouch_agent($browser) {
  59. $useragent = $_SERVER['HTTP_USER_AGENT'];
  60. return stristr($useragent,$browser);
  61. }
  62. function wptouch_twitter_link() {
  63. echo '<li><a href="javascript:(function(){var%20f=false,t=true,a=f,b=f,u=\'\',w=window,d=document,g=w.open(),p,linkArr=d.getElementsByTagName(\'link\');for(var%20i=0;i%3ClinkArr.length&&!a;i++){var%20l=linkArr[i];for(var%20x=0;x%3Cl.attributes.length;x++){if(l.attributes[x].nodeName.toLowerCase()==\'rel\'){p=l.attributes[x].nodeValue.split(\'%20\');for(y=0;y%3Cp.length;y++){if(p[y]==\'short_url\'||p[y]==\'shorturl\'||p[y]==\'shortlink\'){a=t;}}}if(l.attributes[x].nodeName.toLowerCase()==\'rev\'&&l.attributes[x].nodeValue==\'canonical\'){a=t;}if(a){u=l.href;}}}if(a){go(u);}else{var%20h=d.getElementsByTagName(\'head\')[0]||d.documentElement,s=d.createElement(\'script\');s.src=\'http://api.bit.ly/shorten?callback=bxtShCb&longUrl=\'+encodeURIComponent(window.location.href)+\'&version=2.0.1&login=amoebe&apiKey=R_60a24cf53d0d1913c5708ea73fa69684\';s.charSet=\'utf-8\';h.appendChild(s);}bxtShCb=function(data){var%20rs,r;for(r%20in%20data.results){rs=data.results[r];break;}go(rs[\'shortUrl\']);};function%20go(u){return%20g.document.location.href=(\'http://mobile.twitter.com/home/?status=\'+encodeURIComponent(document.title+\'%20\'+u));}})();" id="otweet"></a></li>';
  64. }
  65. function wptouch_facebook_link() {
  66. echo "<li><a href=\"javascript:var%20d=document,f='http://www.facebook.com/share',l=d.location,e=encodeURIComponent,p='.php?src=bm&v=4&i=1297484757&u='+e(l.href)+'&t='+e(d.title);1;try{if%20(!/^(.*\.)?facebook\.[^.]*$/.test(l.host))throw(0);share_internal_bookmarklet(p)}catch(z)%20{a=function()%20{if%20(!window.open(f+'r'+p,'sharer','toolbar=0,status=0,resizable=1,width=626,height=436'))l.href=f+p};if%20(/Firefox/.test(navigator.userAgent))setTimeout(a,0);else{a()}}void(0)\" id=\"facebook\"></a></li>";
  67. }
  68. function wptouch_thumb_reflections() {
  69. if (wptouch_agent("iphone") != FALSE || wptouch_agent("ipod") != FALSE) {
  70. echo ".wptouch-post-thumb-wrap{ \n";
  71. echo "-webkit-box-reflect: below 1px -webkit-gradient(linear, left top, left bottom, from(transparent), color-stop(0.85, transparent), to(white));} \n";
  72. }
  73. }
  74. function wptouch_tags_link() {
  75. echo '<a href="#head-tags">' . __( "Tags", "wptouch" ) . '</a>';
  76. }
  77. function wptouch_cats_link() {
  78. echo '<a href="#head-cats">' . __( "Categories", "wptouch" ) . '</a>';
  79. }
  80. function bnc_get_ordered_cat_list( $num ) {
  81. global $wpdb;
  82. if ( wptouch_excluded_cats() ) {
  83. $excluded_cats = wptouch_excluded_cats();
  84. } else {
  85. $excluded_cats = 0;
  86. }
  87. echo '<ul>';
  88. $sql = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}term_taxonomy INNER JOIN {$wpdb->prefix}terms ON {$wpdb->prefix}term_taxonomy.term_id = {$wpdb->prefix}terms.term_id WHERE taxonomy = 'category' AND {$wpdb->prefix}term_taxonomy.term_id NOT IN ($excluded_cats) AND count >= 1 ORDER BY count DESC LIMIT 0, $num");
  89. if ( $sql ) {
  90. foreach ( $sql as $result ) {
  91. if ( $result ) {
  92. echo "<li><a href=\"" . get_category_link( $result->term_id ) . "\">" . $result->name . " <span>(" . $result->count . ")</span></a></li>";
  93. }
  94. }
  95. }
  96. echo '</ul>';
  97. }
  98. function wptouch_ordered_tag_list( $num ) {
  99. global $wpdb;
  100. if ( wptouch_excluded_tags() ) {
  101. $excluded_tags = wptouch_excluded_tags();
  102. } else {
  103. $excluded_tags = 0;
  104. }
  105. echo '<ul>';
  106. $sql = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}term_taxonomy INNER JOIN {$wpdb->prefix}terms ON {$wpdb->prefix}term_taxonomy.term_id = {$wpdb->prefix}terms.term_id WHERE taxonomy = 'post_tag' AND {$wpdb->prefix}term_taxonomy.term_id NOT IN ($excluded_tags) AND count >= 1 ORDER BY count DESC LIMIT 0, $num");
  107. if ( $sql ) {
  108. foreach ( $sql as $result ) {
  109. if ( $result ) {
  110. echo "<li><a href=\"" . get_tag_link( $result->term_id ) . "\">" . $result->name . " <span>(" . $result->count . ")</span></a></li>";
  111. }
  112. }
  113. }
  114. echo '</ul>';
  115. }
  116. // WPtouch Core Body Functions
  117. function wptouch_core_body_background() {
  118. $wptouch_settings = bnc_wptouch_get_settings();
  119. echo $wptouch_settings['style-background'];
  120. }
  121. function wptouch_core_body_sitetitle() {
  122. $str = bnc_get_header_title();
  123. echo stripslashes($str);
  124. }
  125. function wptouch_core_body_result_text() {
  126. global $is_ajax; if (!$is_ajax) {
  127. if (is_search()) {
  128. echo sprintf( __("Search results &rsaquo; %s", "wptouch"), get_search_query() );
  129. } if (is_category()) {
  130. echo sprintf( __("Categories &rsaquo; %s", "wptouch"), single_cat_title("", false));
  131. } elseif (is_tag()) {
  132. echo sprintf( __("Tags &rsaquo; %s", "wptouch"), single_tag_title("", false));
  133. } elseif (is_day()) {
  134. echo sprintf( __("Archives &rsaquo; %s", "wptouch"), get_the_time('F jS, Y'));
  135. } elseif (is_month()) {
  136. echo sprintf( __("Archives &rsaquo; %s", "wptouch"), get_the_time('F, Y'));
  137. } elseif (is_year()) {
  138. echo sprintf( __("Archives &rsaquo; %s", "wptouch"), get_the_time('Y'));
  139. }
  140. }
  141. }
  142. // WPtouch Core Footer Functions
  143. function wptouch_core_else_text() {
  144. global $is_ajax; if (($is_ajax) && !is_search()) {
  145. echo '' . __( "No more entries to display.", "wptouch" ) . '';
  146. } elseif (is_search() && ($is_ajax)) {
  147. echo '' . __( "No more search results to display.", "wptouch" ) . '';
  148. } elseif (is_search() && (!$is_ajax)) {
  149. echo '<div style="padding-bottom:127px">' . __( "No search results results found.", "wptouch" ) . '<br />' . __( "Try another query.", "wptouch" ) . '</div>';
  150. } else {
  151. echo '<div class="post">
  152. <h2>' . __( "404 Not Found", "wptouch" ) . '</h2>
  153. <p>' . __( "The page or post you were looking for is missing or has been removed.", "wptouch" ) . '</p>
  154. </div>';
  155. }
  156. }
  157. function wptouch_core_footer_switch_link() {
  158. echo '<script type="text/javascript">function switch_delayer() { window.location = "' . home_url() . '/?wptouch_view=normal&wptouch_redirect_nonce=' . wp_create_nonce( 'wptouch_redirect' ) . '&wptouch_redirect=' . urlencode( $_SERVER['REQUEST_URI'] ) .'"}</script>';
  159. echo '<a id="switch-link" href="javascript:return false;">';
  160. echo '<span class="on active">ON</span>';
  161. echo '<span class="off">OFF</span>';
  162. echo '</a>';
  163. }
  164. // WPtouch Standard Functions
  165. // Check if certain plugins are active
  166. function wptouch_is_plugin_active($plugin_filename) {
  167. $plugins = get_option('active_plugins');
  168. if( !is_array($plugins) ) settype($plugins,'array');
  169. return ( in_array($plugin_filename, $plugins) ) ;
  170. }
  171. //Filter out pingbacks and trackbacks
  172. add_filter('get_comments_number', 'comment_count', 0);
  173. function comment_count( $count ) {
  174. global $id;
  175. $comments = get_approved_comments($id);
  176. $comment_count = 0;
  177. foreach($comments as $comment){
  178. if($comment->comment_type == ""){
  179. $comment_count++;
  180. }
  181. }
  182. return $comment_count;
  183. }
  184. // Stop '0' comment counts in comment bubbles
  185. function wptouch_get_comment_count() {
  186. global $wpdb;
  187. global $post;
  188. $sql = $wpdb->prepare( "SELECT count(*) AS c FROM {$wpdb->comments} WHERE comment_type = '' AND comment_approved = 1 AND comment_post_ID = %d", $post->ID );
  189. $result = $wpdb->get_row( $sql );
  190. if ( $result ) {
  191. return $result->c;
  192. } else {
  193. return 0;
  194. }
  195. }
  196. // Add 'Delete | Spam' links in comments for logged in admins
  197. function wptouch_moderate_comment_link( $id ) {
  198. if ( current_user_can( 'edit_post' ) ) {
  199. echo '<a href="' . admin_url("comment.php?action=editcomment&c=$id") . '">' . __('edit') . '</a>';
  200. echo '<a href="' . admin_url("comment.php?action=cdc&c=$id") . '">' . __('del') . '</a>';
  201. echo '<a href="' . admin_url("comment.php?action=cdc&dt=spam&c=$id") . '">' . __('spam') . '</a>';
  202. }
  203. }
  204. function wptouch_thumbnail_size( $size ) {
  205. $size = 'thumbnail';
  206. return $size;
  207. }
  208. function wptouch_idevice_classes() {
  209. $iPhone = strstr( $_SERVER['HTTP_USER_AGENT'], 'iPhone' );
  210. $iPod = strstr( $_SERVER['HTTP_USER_AGENT'], 'iPod' );
  211. $iOS5 = strstr( $_SERVER['HTTP_USER_AGENT'], 'OS 5_0' );
  212. if ( $iPhone || $iPod ) {
  213. echo 'idevice';
  214. }
  215. if ( $iOS5 && wptouch_use_fixed_header() ) {
  216. echo ' ios5';
  217. }
  218. }
  219. // Remove the admin bar when logged in and looking at WPtouch
  220. if ( bnc_wptouch_is_mobile() && function_exists( 'show_admin_bar' ) ) {
  221. add_filter( 'show_admin_bar', '__return_false' );
  222. }
  223. // WPtouch Filters
  224. add_filter( 'post_thumbnail_size', 'wptouch_thumbnail_size' );
  225. remove_action('wp_head', 'gigpress_head');
  226. remove_filter('the_excerpt', 'do_shortcode');
  227. remove_filter('the_content', 'do_shortcode');
  228. remove_action( 'wp_default_scripts', array( 'JCP_UseGoogleLibraries', 'replace_default_scripts_action'), 1000);
  229. remove_filter('the_content', 'sociable_display_hook');
  230. remove_filter('the_excerpt', 'sociable_display_hook');
  231. remove_filter('the_content', 'whydowork_adsense_filter', 100);
  232. remove_filter('the_excerpt', 'whydowork_adsense_filter', 100);
  233. // Facebook Like button
  234. remove_filter('the_content', 'Add_Like_Button');
  235. //Sharebar Plugin
  236. remove_filter('the_content', 'sharebar_auto');
  237. remove_action('wp_head', 'sharebar_header');