Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/worker
File: functions.php
<?php
[0] Fix | Delete
[1] Fix | Delete
function mwp_autoload($class)
[2] Fix | Delete
{
[3] Fix | Delete
if (substr($class, 0, 8) === 'Symfony_'
[4] Fix | Delete
|| substr($class, 0, 8) === 'Monolog_'
[5] Fix | Delete
|| substr($class, 0, 5) === 'Gelf_'
[6] Fix | Delete
|| substr($class, 0, 4) === 'MWP_'
[7] Fix | Delete
|| substr($class, 0, 4) === 'MMB_'
[8] Fix | Delete
) {
[9] Fix | Delete
$file = dirname(__FILE__).'/src/'.str_replace('_', '/', $class).'.php';
[10] Fix | Delete
if (file_exists($file)) {
[11] Fix | Delete
include_once $file;
[12] Fix | Delete
}
[13] Fix | Delete
}
[14] Fix | Delete
}
[15] Fix | Delete
[16] Fix | Delete
/**
[17] Fix | Delete
* @return Monolog_Psr_LoggerInterface
[18] Fix | Delete
*/
[19] Fix | Delete
function mwp_logger()
[20] Fix | Delete
{
[21] Fix | Delete
return mwp_container()->getLogger();
[22] Fix | Delete
}
[23] Fix | Delete
[24] Fix | Delete
/**
[25] Fix | Delete
* @return MWP_WordPress_Context
[26] Fix | Delete
*/
[27] Fix | Delete
function mwp_context()
[28] Fix | Delete
{
[29] Fix | Delete
return mwp_container()->getWordPressContext();
[30] Fix | Delete
}
[31] Fix | Delete
[32] Fix | Delete
function mwp_worker_configuration()
[33] Fix | Delete
{
[34] Fix | Delete
return mwp_container()->getConfiguration();
[35] Fix | Delete
}
[36] Fix | Delete
[37] Fix | Delete
function mwp_format_memory_limit($limit)
[38] Fix | Delete
{
[39] Fix | Delete
if ((string)(int)$limit === (string)$limit) {
[40] Fix | Delete
// The number is numeric.
[41] Fix | Delete
return mwp_format_bytes($limit);
[42] Fix | Delete
}
[43] Fix | Delete
[44] Fix | Delete
$units = strtolower(substr($limit, -1));
[45] Fix | Delete
[46] Fix | Delete
if (!in_array($units, array('b', 'k', 'm', 'g'))) {
[47] Fix | Delete
// Invalid size unit.
[48] Fix | Delete
return $limit;
[49] Fix | Delete
}
[50] Fix | Delete
[51] Fix | Delete
$number = substr($limit, 0, -1);
[52] Fix | Delete
[53] Fix | Delete
if ((string)(int)$number !== $number) {
[54] Fix | Delete
// The number isn't numeric.
[55] Fix | Delete
return $number;
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
switch ($units) {
[59] Fix | Delete
case 'g':
[60] Fix | Delete
return $number.' GB';
[61] Fix | Delete
case 'm':
[62] Fix | Delete
return $number.' MB';
[63] Fix | Delete
case 'k':
[64] Fix | Delete
return $number.' KB';
[65] Fix | Delete
case 'b':
[66] Fix | Delete
default:
[67] Fix | Delete
return $number.' B';
[68] Fix | Delete
}
[69] Fix | Delete
}
[70] Fix | Delete
[71] Fix | Delete
function mwp_format_bytes($bytes)
[72] Fix | Delete
{
[73] Fix | Delete
$bytes = (int)$bytes;
[74] Fix | Delete
[75] Fix | Delete
if ($bytes > 1024 * 1024 * 1024) {
[76] Fix | Delete
return round($bytes / 1024 / 1024 / 1024, 2).' GB';
[77] Fix | Delete
} elseif ($bytes > 1024 * 1024) {
[78] Fix | Delete
return round($bytes / 1024 / 1024, 2).' MB';
[79] Fix | Delete
} elseif ($bytes > 1024) {
[80] Fix | Delete
return round($bytes / 1024, 2).' KB';
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
return $bytes.' B';
[84] Fix | Delete
}
[85] Fix | Delete
[86] Fix | Delete
function cleanup_delete_worker($params = array())
[87] Fix | Delete
{
[88] Fix | Delete
$revision_params = get_option('mmb_stats_filter');
[89] Fix | Delete
$revision_limit = isset($revision_params['plugins']['cleanup']['revisions']) ? str_replace('r_', '', $revision_params['plugins']['cleanup']['revisions']) : 5;
[90] Fix | Delete
[91] Fix | Delete
$params_array = explode('_', $params['actions']);
[92] Fix | Delete
$return_array = array();
[93] Fix | Delete
[94] Fix | Delete
foreach ($params_array as $param) {
[95] Fix | Delete
switch ($param) {
[96] Fix | Delete
case 'revision':
[97] Fix | Delete
if (mmb_delete_all_revisions($revision_limit)) {
[98] Fix | Delete
$return_array['revision'] = 'OK';
[99] Fix | Delete
} else {
[100] Fix | Delete
$return_array['revision_error'] = 'OK, nothing to do';
[101] Fix | Delete
}
[102] Fix | Delete
break;
[103] Fix | Delete
case 'overhead':
[104] Fix | Delete
if (mmb_handle_overhead(true)) {
[105] Fix | Delete
$return_array['overhead'] = 'OK';
[106] Fix | Delete
} else {
[107] Fix | Delete
$return_array['overhead_error'] = 'OK, nothing to do';
[108] Fix | Delete
}
[109] Fix | Delete
break;
[110] Fix | Delete
case 'comment':
[111] Fix | Delete
if (mmb_delete_spam_comments()) {
[112] Fix | Delete
$return_array['comment'] = 'OK';
[113] Fix | Delete
} else {
[114] Fix | Delete
$return_array['comment_error'] = 'OK, nothing to do';
[115] Fix | Delete
}
[116] Fix | Delete
break;
[117] Fix | Delete
default:
[118] Fix | Delete
break;
[119] Fix | Delete
}
[120] Fix | Delete
}
[121] Fix | Delete
[122] Fix | Delete
unset($params);
[123] Fix | Delete
[124] Fix | Delete
mmb_response($return_array, true);
[125] Fix | Delete
}
[126] Fix | Delete
[127] Fix | Delete
function mmb_num_revisions($leaveRevsPerPost)
[128] Fix | Delete
{
[129] Fix | Delete
global $wpdb;
[130] Fix | Delete
[131] Fix | Delete
$query = "SELECT SUM(t.cnt) FROM (SELECT COUNT(ID) - {$leaveRevsPerPost} as cnt FROM {$wpdb->posts} WHERE post_type = 'revision' AND post_parent != 0 GROUP BY post_parent HAVING COUNT(ID) > {$leaveRevsPerPost}) as t";
[132] Fix | Delete
[133] Fix | Delete
return $wpdb->get_var($query);
[134] Fix | Delete
}
[135] Fix | Delete
[136] Fix | Delete
function mmb_delete_all_revisions($filter)
[137] Fix | Delete
{
[138] Fix | Delete
global $wpdb;
[139] Fix | Delete
[140] Fix | Delete
$num_rev = isset($filter['num_to_keep']) ? (int)str_replace("r_", "", $filter['num_to_keep']) : 5;
[141] Fix | Delete
[142] Fix | Delete
$allRevisions = $wpdb->get_results("SELECT post_parent FROM {$wpdb->posts} WHERE post_type = 'revision' AND post_parent != 0 GROUP BY post_parent HAVING COUNT(ID) > {$num_rev}");
[143] Fix | Delete
[144] Fix | Delete
if (!is_array($allRevisions)) {
[145] Fix | Delete
return false;
[146] Fix | Delete
}
[147] Fix | Delete
[148] Fix | Delete
foreach ($allRevisions as $revision) {
[149] Fix | Delete
$toKeep = $wpdb->get_results("SELECT ID FROM {$wpdb->posts} WHERE post_type = 'revision' AND post_parent = '{$revision->post_parent}' ORDER BY post_date DESC LIMIT ".$num_rev);
[150] Fix | Delete
[151] Fix | Delete
$keepArray = array();
[152] Fix | Delete
foreach ($toKeep as $keep) {
[153] Fix | Delete
$keepArray[] = $keep->ID;
[154] Fix | Delete
}
[155] Fix | Delete
[156] Fix | Delete
if (empty($keepArray)) {
[157] Fix | Delete
continue;
[158] Fix | Delete
}
[159] Fix | Delete
[160] Fix | Delete
$keepQuery = implode(', ', $keepArray);
[161] Fix | Delete
$wpdb->query("DELETE FROM {$wpdb->posts} WHERE post_type = 'revision' AND post_parent = '{$revision->post_parent}' AND ID NOT IN ({$keepQuery})");
[162] Fix | Delete
}
[163] Fix | Delete
[164] Fix | Delete
return true;
[165] Fix | Delete
}
[166] Fix | Delete
[167] Fix | Delete
function mmb_handle_overhead($clear = false)
[168] Fix | Delete
{
[169] Fix | Delete
/** @var wpdb $wpdb */
[170] Fix | Delete
global $wpdb;
[171] Fix | Delete
$query = 'SHOW TABLE STATUS';
[172] Fix | Delete
$tables = $wpdb->get_results($query, ARRAY_A);
[173] Fix | Delete
$tableOverhead = 0;
[174] Fix | Delete
$tablesToOptimize = array();
[175] Fix | Delete
[176] Fix | Delete
foreach ($tables as $table) {
[177] Fix | Delete
if (!isset($table['Engine']) || $table['Engine'] !== 'MyISAM' || $table['Data_free'] == 0) {
[178] Fix | Delete
continue;
[179] Fix | Delete
}
[180] Fix | Delete
[181] Fix | Delete
if ($wpdb->base_prefix === $wpdb->prefix && !preg_match('/^'.preg_quote($wpdb->prefix).'/Ui', $table['Name'])) {
[182] Fix | Delete
continue;
[183] Fix | Delete
}
[184] Fix | Delete
[185] Fix | Delete
if ($wpdb->base_prefix !== $wpdb->prefix && !preg_match('/^'.preg_quote($wpdb->prefix).'\d+_/Ui', $table['Name'])) {
[186] Fix | Delete
continue;
[187] Fix | Delete
}
[188] Fix | Delete
[189] Fix | Delete
$tableOverhead += $table['Data_free'] / 1024;
[190] Fix | Delete
$tablesToOptimize[] = $table['Name'];
[191] Fix | Delete
}
[192] Fix | Delete
[193] Fix | Delete
if (!$clear) { // we should only return the overhead
[194] Fix | Delete
return round($tableOverhead, 3);
[195] Fix | Delete
}
[196] Fix | Delete
[197] Fix | Delete
$optimize = true;
[198] Fix | Delete
[199] Fix | Delete
foreach ($tablesToOptimize as $tableToOptimize) {
[200] Fix | Delete
$query = 'OPTIMIZE TABLE '.$tableToOptimize;
[201] Fix | Delete
$optimize = ((bool)$wpdb->query($query)) && $optimize;
[202] Fix | Delete
}
[203] Fix | Delete
[204] Fix | Delete
return $optimize;
[205] Fix | Delete
}
[206] Fix | Delete
[207] Fix | Delete
function mmb_num_spam_comments()
[208] Fix | Delete
{
[209] Fix | Delete
global $wpdb;
[210] Fix | Delete
$sql = "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = 'spam'";
[211] Fix | Delete
$num_spams = $wpdb->get_var($sql);
[212] Fix | Delete
[213] Fix | Delete
return $num_spams;
[214] Fix | Delete
}
[215] Fix | Delete
[216] Fix | Delete
function mmb_delete_spam_comments()
[217] Fix | Delete
{
[218] Fix | Delete
global $wpdb;
[219] Fix | Delete
$spam = 1;
[220] Fix | Delete
$total = 0;
[221] Fix | Delete
while (!empty($spam)) {
[222] Fix | Delete
$getCommentsQuery = "SELECT * FROM $wpdb->comments WHERE comment_approved = 'spam' LIMIT 1000";
[223] Fix | Delete
$spam = $wpdb->get_results($getCommentsQuery);
[224] Fix | Delete
[225] Fix | Delete
if (empty($spam)) {
[226] Fix | Delete
break;
[227] Fix | Delete
}
[228] Fix | Delete
[229] Fix | Delete
$commentIds = array();
[230] Fix | Delete
foreach ($spam as $comment) {
[231] Fix | Delete
$commentIds[] = $comment->comment_ID;
[232] Fix | Delete
[233] Fix | Delete
// Avoid queries to comments by caching the comment.
[234] Fix | Delete
// Plugins which hook to 'delete_comment' might call get_comment($id), which in turn returns the cached version.
[235] Fix | Delete
wp_cache_add($comment->comment_ID, $comment, 'comment');
[236] Fix | Delete
do_action('delete_comment', $comment->comment_ID);
[237] Fix | Delete
wp_cache_delete($comment->comment_ID, 'comment');
[238] Fix | Delete
}
[239] Fix | Delete
[240] Fix | Delete
$commentIdsList = implode(', ', array_map('intval', $commentIds));
[241] Fix | Delete
$wpdb->query("DELETE FROM {$wpdb->comments} WHERE comment_ID IN ($commentIdsList)");
[242] Fix | Delete
$wpdb->query("DELETE FROM {$wpdb->commentmeta} WHERE comment_id IN ($commentIdsList)");
[243] Fix | Delete
[244] Fix | Delete
$total += count($spam);
[245] Fix | Delete
if (!empty($spam)) {
[246] Fix | Delete
usleep(10000);
[247] Fix | Delete
}
[248] Fix | Delete
}
[249] Fix | Delete
[250] Fix | Delete
return $total;
[251] Fix | Delete
}
[252] Fix | Delete
[253] Fix | Delete
function mwp_is_nio_shell_available()
[254] Fix | Delete
{
[255] Fix | Delete
static $check;
[256] Fix | Delete
if (isset($check)) {
[257] Fix | Delete
return $check;
[258] Fix | Delete
}
[259] Fix | Delete
try {
[260] Fix | Delete
$process = new Symfony_Process_Process("cd .", dirname(__FILE__), array(), null, 1);
[261] Fix | Delete
$process->run();
[262] Fix | Delete
$check = $process->isSuccessful();
[263] Fix | Delete
} catch (Exception $e) {
[264] Fix | Delete
$check = false;
[265] Fix | Delete
}
[266] Fix | Delete
[267] Fix | Delete
return $check;
[268] Fix | Delete
}
[269] Fix | Delete
[270] Fix | Delete
function mwp_is_shell_available()
[271] Fix | Delete
{
[272] Fix | Delete
if (mwp_container()->getParameter('disable_shell')) {
[273] Fix | Delete
return false;
[274] Fix | Delete
}
[275] Fix | Delete
[276] Fix | Delete
if (mwp_is_safe_mode()) {
[277] Fix | Delete
return false;
[278] Fix | Delete
}
[279] Fix | Delete
if (!function_exists('proc_open') || !function_exists('escapeshellarg')) {
[280] Fix | Delete
return false;
[281] Fix | Delete
}
[282] Fix | Delete
[283] Fix | Delete
$neededFunction = array('proc_get_status', 'proc_open');
[284] Fix | Delete
$disabledFunction = mwp_get_disabled_functions();
[285] Fix | Delete
[286] Fix | Delete
if (count(array_diff($neededFunction, $disabledFunction)) != count($neededFunction)) {
[287] Fix | Delete
return false;
[288] Fix | Delete
}
[289] Fix | Delete
[290] Fix | Delete
if (!mwp_is_nio_shell_available()) {
[291] Fix | Delete
return false;
[292] Fix | Delete
}
[293] Fix | Delete
[294] Fix | Delete
return true;
[295] Fix | Delete
}
[296] Fix | Delete
[297] Fix | Delete
function mwp_get_disabled_functions()
[298] Fix | Delete
{
[299] Fix | Delete
$list = array_merge(explode(',', ini_get('disable_functions')), explode(',', ini_get('suhosin.executor.func.blacklist')));
[300] Fix | Delete
$list = array_map('trim', $list);
[301] Fix | Delete
$list = array_map('strtolower', $list);
[302] Fix | Delete
$list = array_filter($list);
[303] Fix | Delete
[304] Fix | Delete
return $list;
[305] Fix | Delete
}
[306] Fix | Delete
[307] Fix | Delete
function mwp_is_safe_mode()
[308] Fix | Delete
{
[309] Fix | Delete
$value = ini_get("safe_mode");
[310] Fix | Delete
if ((int)$value === 0 || strtolower($value) === "off") {
[311] Fix | Delete
return false;
[312] Fix | Delete
}
[313] Fix | Delete
[314] Fix | Delete
return true;
[315] Fix | Delete
}
[316] Fix | Delete
[317] Fix | Delete
function mmb_response($response = false, $success = true)
[318] Fix | Delete
{
[319] Fix | Delete
if (!$success) {
[320] Fix | Delete
if (!is_scalar($response)) {
[321] Fix | Delete
$response = json_encode($response);
[322] Fix | Delete
}
[323] Fix | Delete
throw new MWP_Worker_Exception(MWP_Worker_Exception::GENERAL_ERROR, $response);
[324] Fix | Delete
}
[325] Fix | Delete
[326] Fix | Delete
throw new MWP_Worker_ActionResponse($response);
[327] Fix | Delete
}
[328] Fix | Delete
[329] Fix | Delete
function mmb_remove_site($params)
[330] Fix | Delete
{
[331] Fix | Delete
mwp_core()->deactivate(false, false);
[332] Fix | Delete
mwp_remove_current_key();
[333] Fix | Delete
[334] Fix | Delete
mmb_response(
[335] Fix | Delete
array(
[336] Fix | Delete
'removed_data' => 'Site removed successfully. <br /><br /><b>ManageWP Worker plugin was not deactivated.</b>',
[337] Fix | Delete
),
[338] Fix | Delete
true
[339] Fix | Delete
);
[340] Fix | Delete
}
[341] Fix | Delete
[342] Fix | Delete
function mwp_get_stats(array $params)
[343] Fix | Delete
{
[344] Fix | Delete
mwp_context()->requireWpRewrite();
[345] Fix | Delete
mwp_context()->requireTaxonomies();
[346] Fix | Delete
mwp_context()->requirePostTypes();
[347] Fix | Delete
mwp_context()->requireTheme();
[348] Fix | Delete
[349] Fix | Delete
mwp_logger()->debug('Starting get_stats after everything was required');
[350] Fix | Delete
[351] Fix | Delete
$return = mwp_core()->get_stats_instance()->get_stats($params);
[352] Fix | Delete
mmb_response($return);
[353] Fix | Delete
}
[354] Fix | Delete
[355] Fix | Delete
function mmb_update_worker_plugin($params)
[356] Fix | Delete
{
[357] Fix | Delete
if (!empty($params['version'])) {
[358] Fix | Delete
$recoveryKit = new MwpRecoveryKit();
[359] Fix | Delete
update_option('mwp_incremental_update_active', time());
[360] Fix | Delete
try {
[361] Fix | Delete
$files = $recoveryKit->recover($params['version']);
[362] Fix | Delete
} catch (Exception $e) {
[363] Fix | Delete
update_option('mwp_incremental_update_active', '');
[364] Fix | Delete
throw $e;
[365] Fix | Delete
}
[366] Fix | Delete
update_option('mwp_incremental_update_active', '');
[367] Fix | Delete
mmb_response(array('files' => $files, 'success' => 'ManageWP Worker plugin successfully updated'), true);
[368] Fix | Delete
} else {
[369] Fix | Delete
mmb_response(mwp_core()->update_worker_plugin($params), true);
[370] Fix | Delete
}
[371] Fix | Delete
}
[372] Fix | Delete
[373] Fix | Delete
function mmb_install_addon($params)
[374] Fix | Delete
{
[375] Fix | Delete
mwp_context()->requireTheme();
[376] Fix | Delete
mwp_load_required_components();
[377] Fix | Delete
$return = mwp_core()->get_installer_instance()->install_remote_file($params);
[378] Fix | Delete
mmb_response($return, true);
[379] Fix | Delete
}
[380] Fix | Delete
[381] Fix | Delete
function mmb_do_upgrade($params)
[382] Fix | Delete
{
[383] Fix | Delete
mwp_context()->requireTheme();
[384] Fix | Delete
$return = mwp_core()->get_installer_instance()->do_upgrade($params);
[385] Fix | Delete
mmb_response($return, true);
[386] Fix | Delete
}
[387] Fix | Delete
[388] Fix | Delete
function mmb_bulk_action_comments($params)
[389] Fix | Delete
{
[390] Fix | Delete
$return = mwp_core()->get_comment_instance()->bulk_action_comments($params);
[391] Fix | Delete
if (is_array($return) && array_key_exists('error', $return)) {
[392] Fix | Delete
mmb_response($return['error'], false);
[393] Fix | Delete
} else {
[394] Fix | Delete
mmb_response($return, true);
[395] Fix | Delete
}
[396] Fix | Delete
}
[397] Fix | Delete
[398] Fix | Delete
function mmb_add_user($params)
[399] Fix | Delete
{
[400] Fix | Delete
$return = mwp_core()->get_user_instance()->add_user($params);
[401] Fix | Delete
if (is_array($return) && array_key_exists('error', $return)) {
[402] Fix | Delete
mmb_response($return['error'], false);
[403] Fix | Delete
} else {
[404] Fix | Delete
mmb_response($return, true);
[405] Fix | Delete
}
[406] Fix | Delete
}
[407] Fix | Delete
[408] Fix | Delete
function mmb_edit_users($params)
[409] Fix | Delete
{
[410] Fix | Delete
$users = mwp_core()->get_user_instance()->edit_users($params);
[411] Fix | Delete
$response = 'User updated.';
[412] Fix | Delete
$check_error = false;
[413] Fix | Delete
foreach ($users as $username => $user) {
[414] Fix | Delete
$check_error = is_array($user) && array_key_exists('error', $user);
[415] Fix | Delete
if ($check_error) {
[416] Fix | Delete
$response = $username.': '.$user['error'];
[417] Fix | Delete
}
[418] Fix | Delete
}
[419] Fix | Delete
mmb_response($response, !$check_error);
[420] Fix | Delete
}
[421] Fix | Delete
[422] Fix | Delete
function mmb_iframe_plugins_fix($update_actions)
[423] Fix | Delete
{
[424] Fix | Delete
foreach ($update_actions as $key => $action) {
[425] Fix | Delete
$update_actions[$key] = str_replace('target="_parent"', '', $action);
[426] Fix | Delete
}
[427] Fix | Delete
[428] Fix | Delete
return $update_actions;
[429] Fix | Delete
}
[430] Fix | Delete
[431] Fix | Delete
function mmb_execute_php_code($params)
[432] Fix | Delete
{
[433] Fix | Delete
ob_start();
[434] Fix | Delete
$errorHandler = new MWP_Debug_EvalErrorHandler();
[435] Fix | Delete
set_error_handler(array($errorHandler, 'handleError'));
[436] Fix | Delete
[437] Fix | Delete
if (!empty($params['code64'])) {
[438] Fix | Delete
$params['code'] = base64_decode(substr($params['code64'], 2));
[439] Fix | Delete
}
[440] Fix | Delete
[441] Fix | Delete
$returnValue = eval($params['code']); // This code handles the "Execute PHP Snippet" functionality on ManageWP and is not a security issue.
[442] Fix | Delete
$errors = $errorHandler->getErrorMessages();
[443] Fix | Delete
restore_error_handler();
[444] Fix | Delete
$return = array('output' => ob_get_clean(), 'returnValue' => $returnValue);
[445] Fix | Delete
[446] Fix | Delete
if (count($errors)) {
[447] Fix | Delete
$return['errorLog'] = $errors;
[448] Fix | Delete
}
[449] Fix | Delete
[450] Fix | Delete
$lastError = error_get_last();
[451] Fix | Delete
$fatalError = null;
[452] Fix | Delete
[453] Fix | Delete
if (($lastError !== null)
[454] Fix | Delete
&& ($lastError['type'] & (E_PARSE | E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR))
[455] Fix | Delete
&& (strpos($lastError['file'], __FILE__) !== false)
[456] Fix | Delete
&& (strpos($lastError['file'], 'eval()') !== false)
[457] Fix | Delete
) {
[458] Fix | Delete
$return['fatalError'] = $lastError;
[459] Fix | Delete
}
[460] Fix | Delete
[461] Fix | Delete
mmb_response($return, true);
[462] Fix | Delete
}
[463] Fix | Delete
[464] Fix | Delete
function mmb_upload_file_action($params)
[465] Fix | Delete
{
[466] Fix | Delete
$transactions = getUploadMessages();
[467] Fix | Delete
[468] Fix | Delete
if (!file_exists($params['file_path'])) {
[469] Fix | Delete
mmb_response(array('message' => $transactions['path_not_exist'], 'ok' => false), true);
[470] Fix | Delete
}
[471] Fix | Delete
[472] Fix | Delete
if (!is_writable($params['file_path'])) {
[473] Fix | Delete
mmb_response(array('message' => $transactions['permissions_denied'], 'ok' => false), true);
[474] Fix | Delete
}
[475] Fix | Delete
[476] Fix | Delete
$pathName = $params['file_path'];
[477] Fix | Delete
if (substr($pathName, -1) !== '/') {
[478] Fix | Delete
$pathName = $pathName.'/';
[479] Fix | Delete
}
[480] Fix | Delete
$filePath = $pathName.$params['file_name'];
[481] Fix | Delete
[482] Fix | Delete
if (file_exists($filePath) && !$params['overwrite']) {
[483] Fix | Delete
mmb_response(array('message' => $transactions['file_exist'], 'ok' => false), true);
[484] Fix | Delete
}
[485] Fix | Delete
[486] Fix | Delete
$file = fopen($filePath, 'w');
[487] Fix | Delete
if (!fwrite($file, base64_decode($params['content']))) {
[488] Fix | Delete
mmb_response(array('message' => $transactions['upload_failed'], 'ok' => false), true);
[489] Fix | Delete
}
[490] Fix | Delete
[491] Fix | Delete
fclose($file);
[492] Fix | Delete
$isWritable = is_writable($filePath);
[493] Fix | Delete
$result = array(
[494] Fix | Delete
'pathName' => $filePath,
[495] Fix | Delete
'fileName' => basename($filePath),
[496] Fix | Delete
'date' => filemtime($filePath),
[497] Fix | Delete
'permissions' => substr(sprintf('%o', fileperms($filePath)), -4),
[498] Fix | Delete
'fileType' => pathinfo($filePath, PATHINFO_EXTENSION),
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function