Пример #1
0
function iwp_mmb_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 '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) {
                iwp_mmb_response($have_plugin, true);
            } else {
                iwp_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;
                iwp_mmb_response($have_theme, true);
            } else {
                iwp_mmb_response('Not found', false);
            }
            break;
        default:
            iwp_mmb_response('Not found', false);
    }
}
Пример #2
0
function iwp_mmb_cleanup_delete_client($params = array())
{
    global $iwp_mmb_core;
    $revision_params = get_option('iwp_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 (iwp_mmb_delete_all_revisions($revision_filter['revisions'])) {
                    $return_array['revision'] = 'OK';
                } else {
                    $return_array['revision_error'] = 'Failed, please try again';
                }
                break;
            case 'overhead':
                if (iwp_mmb_handle_overhead(true)) {
                    $return_array['overhead'] = 'OK';
                } else {
                    $return_array['overhead_error'] = 'Failed, please try again';
                }
                break;
            case 'comment':
                if (iwp_mmb_delete_spam_comments()) {
                    $return_array['comment'] = 'OK';
                } else {
                    $return_array['comment_error'] = 'Failed, please try again';
                }
                break;
            default:
                break;
        }
    }
    unset($params);
    iwp_mmb_response($return_array, true);
}
Пример #3
0
 function statusLog($historyID = '', $statusArray = array(), $params = array())
 {
     global $wpdb, $insertID;
     $this->wpdb_reconnect();
     if (empty($historyID)) {
         $insert = $wpdb->insert($wpdb->base_prefix . 'iwp_backup_status', array('stage' => $statusArray['stage'], 'status' => $statusArray['status'], 'action' => $params['args']['action'], 'type' => $params['args']['type'], 'category' => $params['args']['what'], 'historyID' => $params['args']['parentHID'], 'finalStatus' => 'pending', 'startTime' => microtime(true), 'endTime' => '', 'statusMsg' => $statusArray['statusMsg'], 'requestParams' => serialize($params), 'taskName' => $params['task_name']), array('%s', '%s', '%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%s', '%s', '%s'));
         if ($insert) {
             $insertID = $wpdb->insert_id;
         }
     } else {
         if (isset($statusArray['responseParams']) || isset($statusArray['task_result'])) {
             $update = $wpdb->update($wpdb->base_prefix . 'iwp_backup_status', array('responseParams' => $this->maybe_serialize_compress($statusArray['responseParams']), 'stage' => $statusArray['stage'], 'status' => $statusArray['status'], 'statusMsg' => $statusArray['statusMsg'], 'taskResults' => isset($statusArray['task_result']) ? serialize($statusArray['task_result']) : serialize(array())), array('historyID' => $historyID), array('%s', '%s', '%s', '%s', '%s'), array('%d'));
         } else {
             //$responseParams = $this -> getRequiredData($historyID,"responseParams");
             $update = $wpdb->update($wpdb->base_prefix . 'iwp_backup_status', array('stage' => $statusArray['stage'], 'status' => $statusArray['status'], 'statusMsg' => $statusArray['statusMsg']), array('historyID' => $historyID), array('%s', '%s', '%s'), array('%d'));
         }
     }
     if (isset($update) && $update === false || isset($insert) && $insert === false) {
         //return array('error'=> $statusArray['statusMsg']);
         iwp_mmb_response(array('error' => 'MySQL Error: ' . $wpdb->last_error, 'error_code' => 'mysql_error_status_log'), false);
     }
     if (isset($statusArray['sendResponse']) && $statusArray['sendResponse'] == true || $statusArray['status'] == 'completed') {
         $returnParams = array();
         $returnParams['parentHID'] = $historyID;
         $returnParams['backupRowID'] = $insertID;
         $returnParams['stage'] = $statusArray['stage'];
         $returnParams['status'] = $statusArray['status'];
         $returnParams['nextFunc'] = isset($statusArray['nextFunc']) ? $statusArray['nextFunc'] : '';
         return array('success' => $returnParams);
     } else {
         if ($statusArray['status'] == 'error') {
             refresh_iwp_files_db();
             //truncating the file list table on error
             $returnParams = array();
             $returnParams['parentHID'] = $historyID;
             $returnParams['backupRowID'] = $insertID;
             $returnParams['stage'] = $statusArray['stage'];
             $returnParams['status'] = $statusArray['status'];
             $returnParams['statusMsg'] = $statusArray['statusMsg'];
             return array('error' => $statusArray['statusMsg'], 'error_code' => $statusArray['statusCode']);
         }
     }
 }
Пример #4
0
 function iwp_mmb_backup_test_site($params)
 {
     global $iwp_mmb_core, $iwp_mmb_plugin_dir;
     $return = array();
     $iwp_mmb_core->get_backup_instance();
     $return = $iwp_mmb_core->backup_instance->check_backup_compat($params);
     if (is_array($return) && array_key_exists('error', $return)) {
         iwp_mmb_response($return, false);
     } else {
         iwp_mmb_response($return, true);
     }
 }
Пример #5
0
 /**
  * Gets an instance of stats class
  *
  */
 function get_backup_instance($mechanism = '')
 {
     require_once $GLOBALS['iwp_mmb_plugin_dir'] . "/backup.class.singlecall.php";
     require_once $GLOBALS['iwp_mmb_plugin_dir'] . "/backup.class.multicall.php";
     //$mechanism = 'multiCall';
     if (!isset($this->backup_instance)) {
         if ($mechanism == 'singleCall' || $mechanism == '') {
             $this->backup_instance = new IWP_MMB_Backup_Singlecall();
         } elseif ($mechanism == 'multiCall') {
             $this->backup_instance = new IWP_MMB_Backup_Multicall();
         } else {
             iwp_mmb_response(array('error' => 'mechanism not found'), true);
             //return false;
         }
     }
     return $this->backup_instance;
 }
Пример #6
0
 function statusLog($historyID = '', $statusArray = array(), $params = array())
 {
     global $wpdb, $insertID;
     if (empty($historyID)) {
         $insert = $wpdb->insert($wpdb->base_prefix . 'iwp_backup_status', array('stage' => $statusArray['stage'], 'status' => $statusArray['status'], 'action' => $params['args']['action'], 'type' => $params['args']['type'], 'category' => $params['args']['what'], 'historyID' => $GLOBALS['IWP_CLIENT_HISTORY_ID'], 'finalStatus' => 'pending', 'startTime' => microtime(true), 'endTime' => '', 'statusMsg' => $statusArray['statusMsg'], 'requestParams' => serialize($params), 'taskName' => $params['task_name']), array('%s', '%s', '%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%s', '%s', '%s'));
         if ($insert) {
             $insertID = $wpdb->insert_id;
         }
     } else {
         if (isset($statusArray['responseParams'])) {
             $update = $wpdb->update($wpdb->base_prefix . 'iwp_backup_status', array('responseParams' => serialize($statusArray['responseParams']), 'stage' => $statusArray['stage'], 'status' => $statusArray['status'], 'statusMsg' => $statusArray['statusMsg'], 'taskResults' => serialize($statusArray['task_result'])), array('historyID' => $historyID), array('%s', '%s', '%s', '%s', '%s'), array('%d'));
         } else {
             $update = $wpdb->update($wpdb->base_prefix . 'iwp_backup_status', array('stage' => $statusArray['stage'], 'status' => $statusArray['status'], 'statusMsg' => $statusArray['statusMsg'], 'taskResults' => serialize($statusArray['task_result'])), array('historyID' => $historyID), array('%s', '%s', '%s', '%s'), array('%d'));
         }
     }
     if (isset($update) && !$update || isset($insert) && !$insert) {
         //return array('error'=> $statusArray['statusMsg']);
         iwp_mmb_response(array('error' => 'MySQL Error: ' . $wpdb->last_error, 'error_code' => 'status_log_my_sql_error'), false);
     }
     if (isset($statusArray['sendResponse']) && $statusArray['sendResponse'] == true || $statusArray['status'] == 'completed') {
         $returnParams = array();
         $returnParams['parentHID'] = $historyID;
         $returnParams['backupID'] = $insertID;
         $returnParams['stage'] = $statusArray['stage'];
         $returnParams['status'] = $statusArray['status'];
         $returnParams['nextFunc'] = $statusArray['nextFunc'];
         return array('success' => $returnParams);
     } else {
         if ($statusArray['status'] == 'error') {
             $returnParams = array();
             $returnParams['parentHID'] = $historyID;
             $returnParams['backupID'] = $insertID;
             $returnParams['stage'] = $statusArray['stage'];
             $returnParams['status'] = $statusArray['status'];
             $returnParams['statusMsg'] = $statusArray['statusMsg'];
             return array('error' => $returnParams);
         }
     }
 }
Пример #7
0
 function iwp_mmb_shutdown()
 {
     $isError = false;
     if ($error = error_get_last()) {
         switch ($error['type']) {
             /*case E_PARSE:*/
             case E_ERROR:
             case E_CORE_ERROR:
             case E_COMPILE_ERROR:
             case E_USER_ERROR:
                 $isError = true;
                 break;
         }
     }
     if ($isError) {
         $response = '<span style="font-weight:700;">PHP Fatal error occured:</span> ' . $error['message'] . ' in ' . $error['file'] . ' on line ' . $error['line'] . '.';
         if (stripos($error['message'], 'allowed memory size') !== false) {
             $response .= '<br>Try <a href="http://infinitewp.com/knowledge-base/increase-memory-limit/?utm_source=application&utm_medium=userapp&utm_campaign=kb" target="_blank">increasing the PHP memory limit</a> for this WP site.';
         }
         if (!$GLOBALS['IWP_RESPONSE_SENT']) {
             iwp_mmb_response($response, false);
         }
     }
 }
Пример #8
0
 function iwp_mmb_process_and_fetch_activities_log($params)
 {
     global $wpdb, $iwp_activities_log_post_type;
     $updated_key = 'updated';
     $backups_key = 'backups';
     $count_key = 'count';
     $name_key = 'name';
     $date_key = 'date';
     $time_key = 'time';
     $type_key = 'type';
     $from_key = 'from';
     $to_key = 'to';
     $translations_updated = 'translations-updated';
     if (!is_array($params['originalActions']) || !is_array($params['actions']) || !count($params['originalActions']) || !count($params['actions']) || empty($params['fromDate']) || empty($params['toDate'])) {
         iwp_mmb_response(array('error' => 'Invalid request', 'error_code' => 'invalid_request'), false);
     }
     $iwp_action = implode("','", $params['actions']);
     $query = "\n\t\t\tselect \n\t\t\t\tp.ID as post_id, \n\t\t\t\tp.post_date as date, \n\t\t\t\tpm.meta_value as actions \n\t\t\tfrom \n\t\t\t\t{$wpdb->prefix}posts as p \n\t\t\t\tleft join {$wpdb->prefix}postmeta as pm on pm.post_id = p.ID \n\t\t\twhere \n\t\t\t\tp.post_type = '" . $iwp_activities_log_post_type . "' \n\t\t\t\tand unix_timestamp(p.post_date)>='" . $params['fromDate'] . "' \n\t\t\t\tand unix_timestamp(p.post_date)<='" . $params['toDate'] . "' \n\t\t\t\tand pm.meta_key in ('" . $iwp_activities_log_post_type . "_actions') \n\t\t\t\tand pm.meta_value in ('" . $iwp_action . "')\n\t\t\torder by p.post_date asc\n\t\t";
     $activities_log_result = $wpdb->get_results($query, ARRAY_A);
     $return = array();
     $return['detailed'] = $params['detailed'];
     $return[$count_key] = array_map('iwp_make_values_as_zero', array_flip($params['actions']));
     foreach ($activities_log_result as $key => $activities_log) {
         $date = date('M d, y', strtotime($activities_log['date']));
         $time = date('g', strtotime($activities_log['date'])) . ':' . date('i', strtotime($activities_log['date'])) . ' ' . date('a', strtotime($activities_log['date']));
         $detailed_array = array($date_key => $date, $time_key => $time);
         $activities_log_details = get_post_meta($activities_log['post_id'], $iwp_activities_log_post_type . '_details', true);
         // The following lines are for CR New
         if ($activities_log['actions'] == $backups_key) {
             $return['detailed'][$activities_log['actions']]['details'][$return['detailed'][$activities_log['actions']][$count_key]] = $detailed_array;
             if ($activities_log_details['what'] == 'full') {
                 $backup_what_type = 'Files & DB';
             } else {
                 if ($activities_log_details['what'] == 'files') {
                     $backup_what_type = 'Files';
                 } else {
                     $backup_what_type = 'DB';
                 }
             }
             $return['detailed'][$activities_log['actions']]['details'][$return['detailed'][$activities_log['actions']][$count_key]][$type_key] = $backup_what_type;
             $return['detailed'][$activities_log['actions']][$count_key]++;
         } else {
             $return['detailed'][$updated_key][$count_key]++;
             $return['detailed'][$updated_key][$activities_log['actions']]['details'][$return['detailed'][$updated_key][$activities_log['actions']][$count_key]] = $detailed_array;
             if ($activities_log['actions'] != $translations_updated) {
                 $name = str_replace(array($translations_updated, 's-updated', 'core-updated'), array(''), $activities_log['actions']);
                 $what_updated = isset($activities_log_details['name']) ? $activities_log_details['name'] : 'Wordpress Core Updates';
                 $return['detailed'][$updated_key][$activities_log['actions']]['details'][$return['detailed'][$updated_key][$activities_log['actions']][$count_key]][$name . $name_key] = $what_updated;
                 $return['detailed'][$updated_key][$activities_log['actions']]['details'][$return['detailed'][$updated_key][$activities_log['actions']][$count_key]][$from_key] = $activities_log_details['old_version'];
                 $return['detailed'][$updated_key][$activities_log['actions']]['details'][$return['detailed'][$updated_key][$activities_log['actions']][$count_key]][$to_key] = $activities_log_details['updated_version'];
             }
             $return['detailed'][$updated_key][$activities_log['actions']][$count_key]++;
         }
         // The above lines are for CR New
         $return[$count_key][$activities_log['actions']]++;
         // This line is for CR Old
     }
     foreach ($return[$count_key] as $key => &$value) {
         if ($value == 0) {
             unset($return[$count_key][$key]);
         }
     }
     foreach ($return['detailed'] as $key => &$mainActionArray) {
         if (!$mainActionArray[$count_key]) {
             unset($return['detailed'][$key]);
         } else {
             if (!array_key_exists('details', $mainActionArray)) {
                 foreach ($mainActionArray as $key_inner => &$subActionsArray) {
                     if (!$subActionsArray[$count_key] && $key_inner != $count_key) {
                         unset($mainActionArray[$key_inner]);
                     }
                 }
             }
         }
     }
     iwp_mmb_response($return, true);
 }