Example #1
0
function cleanup_delete_worker($params = array())
{
    global $mmb_core;
    $revision_params = get_option('mmb_stats_filter');
    $revision_filter = isset($revision_params['plugins']['cleanup']) ? $revision_params['plugins']['cleanup'] : array();
    $params_array = explode('_', $params['actions']);
    $return_array = array();
    foreach ($params_array as $param) {
        switch ($param) {
            case 'revision':
                if (mmb_delete_all_revisions($revision_filter['revisions'])) {
                    $return_array['revision'] = 'OK';
                } else {
                    $return_array['revision_error'] = 'OK, nothing to do';
                }
                break;
            case 'overhead':
                if (mmb_handle_overhead(true)) {
                    $return_array['overhead'] = 'OK';
                } else {
                    $return_array['overhead_error'] = 'OK, nothing to do';
                }
                break;
            case 'comment':
                if (mmb_delete_spam_comments()) {
                    $return_array['comment'] = 'OK';
                } else {
                    $return_array['comment_error'] = 'OK, nothing to do';
                }
                break;
            default:
                break;
        }
    }
    unset($params);
    mmb_response($return_array, true);
}
Example #2
0
function search_posts_by_term($params = false)
{
    global $wpdb, $current_user;
    $search_type = trim($params['search_type']);
    $search_term = strtolower(trim($params['search_term']));
    switch ($search_type) {
        case 'page_post':
            $num_posts = 10;
            $num_content_char = 30;
            $term_orig = trim($params['search_term']);
            $term_base = addslashes(trim($params['search_term']));
            $query = "SELECT *\r\n\t\t    \t\t\t  FROM {$wpdb->posts} \r\n\t\t    \t\t\t  WHERE {$wpdb->posts}.post_status  = 'publish'\r\n\t\t    \t\t\t  AND ({$wpdb->posts}.post_title LIKE '%{$term_base}%'\r\n\t\t    \t\t\t  \t\tOR {$wpdb->posts}.post_content LIKE '%{$term_base}%')\r\n\t\t    \t\t\t  ORDER BY {$wpdb->posts}.post_modified DESC\r\n\t\t    \t\t\t  LIMIT 0, {$num_posts}\r\n\t\t    \t\t\t ";
            $posts_array = $wpdb->get_results($query);
            $ret_posts = array();
            foreach ($posts_array as $post) {
                //highlight searched term
                if (substr_count(strtolower($post->post_title), strtolower($term_orig))) {
                    $str_position_start = strpos(strtolower($post->post_title), strtolower($term_orig));
                    $post->post_title = substr($post->post_title, 0, $str_position_start) . '<b>' . substr($post->post_title, $str_position_start, strlen($term_orig)) . '</b>' . substr($post->post_title, $str_position_start + strlen($term_orig));
                }
                $post->post_content = html_entity_decode($post->post_content);
                $post->post_content = strip_tags($post->post_content);
                if (substr_count(strtolower($post->post_content), strtolower($term_orig))) {
                    $str_position_start = strpos(strtolower($post->post_content), strtolower($term_orig));
                    $start = $str_position_start > $num_content_char ? $str_position_start - $num_content_char : 0;
                    $first_len = $str_position_start > $num_content_char ? $num_content_char : $str_position_start;
                    $start_substring = $start > 0 ? '...' : '';
                    $post->post_content = $start_substring . substr($post->post_content, $start, $first_len) . '<b>' . substr($post->post_content, $str_position_start, strlen($term_orig)) . '</b>' . substr($post->post_content, $str_position_start + strlen($term_orig), $num_content_char) . '...';
                } else {
                    $post->post_content = substr($post->post_content, 0, 50) . '...';
                }
                $ret_posts[] = array('ID' => $post->ID, 'post_permalink' => get_permalink($post->ID), 'post_date' => $post->post_date, 'post_title' => $post->post_title, 'post_content' => $post->post_content, 'post_modified' => $post->post_modified, 'comment_count' => $post->comment_count);
            }
            mmb_response($ret_posts, true);
            break;
        case 'plugin':
            $plugins = get_option('active_plugins');
            if (!function_exists('get_plugin_data')) {
                include_once ABSPATH . '/wp-admin/includes/plugin.php';
            }
            $have_plugin = array();
            foreach ($plugins as $plugin) {
                $pl = WP_PLUGIN_DIR . '/' . $plugin;
                $pl_extended = get_plugin_data($pl);
                $pl_name = $pl_extended['Name'];
                if (strpos(strtolower($pl_name), $search_term) > -1) {
                    $have_plugin[] = $pl_name;
                }
            }
            if ($have_plugin) {
                mmb_response($have_plugin, true);
            } else {
                mmb_response('Not found', false);
            }
            break;
        case 'theme':
            $theme = strtolower(get_option('stylesheet'));
            $tm = ABSPATH . 'wp-content/themes/' . $theme . '/style.css';
            $tm_extended = get_theme_data($tm);
            $tm_name = $tm_extended['Name'];
            $have_theme = array();
            if (strpos(strtolower($tm_name), $search_term) > -1) {
                $have_theme[] = $tm_name;
                mmb_response($have_theme, true);
            } else {
                mmb_response('Not found', false);
            }
            break;
        default:
            mmb_response('Not found', false);
    }
}
Example #3
0
function mmb_change_comment_status($params)
{
    global $mmb_core;
    $mmb_core->get_comment_instance();
    $return = $mmb_core->comment_instance->change_status($params);
    if ($return) {
        $mmb_core->get_stats_instance();
        mmb_response($mmb_core->stats_instance->get_comments_stats($params), true);
    } else {
        mmb_response('Comment not updated', false);
    }
}
Example #4
0
 function mmb_plugin_actions()
 {
     global $mmb_actions, $mmb_core;
     if (!empty($mmb_actions)) {
         global $_mmb_plugin_actions;
         if (!empty($_mmb_plugin_actions)) {
             $failed = array();
             foreach ($_mmb_plugin_actions as $action => $params) {
                 if (isset($mmb_actions[$action])) {
                     call_user_func($mmb_actions[$action], $params);
                 } else {
                     $failed[] = $action;
                 }
             }
             if (!empty($failed)) {
                 $f = implode(', ', $failed);
                 $s = count($f) > 1 ? 'Actions "' . $f . '" do' : 'Action "' . $f . '" does';
                 mmb_response($s . ' not exist. Please update your Worker plugin.', false);
             }
         }
     }
     global $pagenow, $current_user, $mmode;
     if (!is_admin() && !in_array($pagenow, array('wp-login.php'))) {
         $mmode = get_option('mwp_maintenace_mode');
         if (!empty($mmode)) {
             if (isset($mmode['active']) && $mmode['active'] == true) {
                 if (isset($current_user->data) && !empty($current_user->data) && isset($mmode['hidecaps']) && !empty($mmode['hidecaps'])) {
                     $usercaps = array();
                     if (isset($current_user->caps) && !empty($current_user->caps)) {
                         $usercaps = $current_user->caps;
                     }
                     foreach ($mmode['hidecaps'] as $cap => $hide) {
                         if (!$hide) {
                             continue;
                         }
                         foreach ($usercaps as $ucap => $val) {
                             if ($ucap == $cap) {
                                 ob_end_clean();
                                 ob_end_flush();
                                 die($mmode['template']);
                             }
                         }
                     }
                 } else {
                     die($mmode['template']);
                 }
             }
         }
     }
     if (file_exists(dirname(__FILE__) . '/log')) {
         unlink(dirname(__FILE__) . '/log');
     }
 }