PluginProbe
ManageWP Worker / 3.9.0
ManageWP Worker v3.9.0
4.9.38 4.9.37 4.9.36 4.9.35 4.9.34 3.8.7 3.8.8 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.18 3.9.19 3.9.2 3.9.20 3.9.21 3.9.22 3.9.23 3.9.24 All 73 releases
worker / plugins / search / search.php

search.php in ManageWP Worker 3.9.0, at plugins/search/search.php

130 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*************************************************************
3 *
4 * stats.class.php
5 *
6 * Various searches on worker
7 *
8 *
9 * Copyright (c) 2011 Prelovac Media
10 * www.prelovac.com
11 **************************************************************/
12
13 mmb_add_action('search_posts_by_term', 'search_posts_by_term');
14
15 function search_posts_by_term($params = false){
16
17 global $wpdb, $current_user;
18
19 $search_type = trim($params['search_type']);
20 $search_term = strtolower(trim($params['search_term']));
21 switch ($search_type){
22 case 'page_post':
23 $num_posts = 10;
24 $num_content_char = 30;
25
26 $term_orig = trim($params['search_term']);
27
28 $term_base= addslashes(trim($params['search_term']));
29
30 $query = "SELECT *
31 FROM $wpdb->posts
32 WHERE $wpdb->posts.post_status = 'publish'
33 AND ($wpdb->posts.post_title LIKE '%$term_base%'
34 OR $wpdb->posts.post_content LIKE '%$term_base%')
35 ORDER BY $wpdb->posts.post_modified DESC
36 LIMIT 0, $num_posts
37 ";
38
39 $posts_array = $wpdb->get_results($query);
40
41 $ret_posts = array();
42
43 foreach($posts_array as $post){
44 //highlight searched term
45
46 if (substr_count(strtolower($post->post_title), strtolower($term_orig))){
47 $str_position_start = strpos(strtolower($post->post_title), strtolower($term_orig));
48
49 $post->post_title = substr($post->post_title, 0, $str_position_start).'<b>'.
50 substr($post->post_title, $str_position_start, strlen($term_orig)).'</b>'.
51 substr($post->post_title, $str_position_start + strlen($term_orig));
52
53 }
54 $post->post_content = html_entity_decode($post->post_content);
55
56 $post->post_content = strip_tags($post->post_content);
57
58
59
60 if (substr_count(strtolower($post->post_content), strtolower($term_orig))){
61 $str_position_start = strpos(strtolower($post->post_content), strtolower($term_orig));
62
63 $start = $str_position_start > $num_content_char ? $str_position_start - $num_content_char: 0;
64 $first_len = $str_position_start > $num_content_char? $num_content_char : $str_position_start;
65
66 $start_substring = $start>0 ? '...' : '';
67 $post->post_content = $start_substring . substr($post->post_content, $start, $first_len).'<b>'.
68 substr($post->post_content, $str_position_start, strlen($term_orig)).'</b>'.
69 substr($post->post_content, $str_position_start + strlen($term_orig), $num_content_char) . '...';
70
71
72 }else{
73 $post->post_content = substr($post->post_content,0, 50). '...';
74 }
75
76 $ret_posts[] = array(
77 'ID' => $post->ID
78 ,'post_permalink' => get_permalink($post->ID)
79 ,'post_date' => $post->post_date
80 ,'post_title' => $post->post_title
81 ,'post_content' => $post->post_content
82 ,'post_modified' => $post->post_modified
83 ,'comment_count' => $post->comment_count
84
85
86 );
87 }
88 mmb_response($ret_posts, true);
89 break;
90
91 case 'plugin':
92 $plugins = get_option('active_plugins');
93
94 if(!function_exists('get_plugin_data'))
95 include_once( ABSPATH.'/wp-admin/includes/plugin.php');
96
97 $have_plugin = array();
98 foreach ($plugins as $plugin) {
99 $pl = WP_PLUGIN_DIR . '/' . $plugin ;
100 $pl_extended = get_plugin_data($pl);
101 $pl_name = $pl_extended['Name'];
102 if(strpos(strtolower($pl_name), $search_term)>-1){
103
104 $have_plugin[] = $pl_name;
105 }
106 }
107 if($have_plugin){
108 mmb_response($have_plugin, true);
109 }else{
110 mmb_response('Not found', false);
111 }
112 break;
113 case 'theme':
114 $theme = strtolower(get_option('stylesheet'));
115 $tm = ABSPATH . 'wp-content/themes/'. $theme . '/style.css' ;
116 $tm_extended = get_theme_data($tm);
117 $tm_name = $tm_extended['Name'];
118 $have_theme = array();
119 if(strpos(strtolower($tm_name), $search_term)>-1){
120 $have_theme[] = $tm_name;
121 mmb_response($have_theme, true);
122 }else{
123 mmb_response('Not found', false);
124 }
125 break;
126 default: mmb_response('Not found', false);
127 }
128 }
129
130 ?>