/** * Installs a Item(Plugin||theme) from a given local file into a local directory * * @param string $filename Name of the local file * @param mixed array details of the File * @param string $destination the directory to install in (Minus ABSPATH) * @return boolean false on failure, mixed array on success */ function installItemFromZip($filename, $fileinfo = array(), $destination = '') { require_once 'wp-update-filesystem.php'; global $wp_filesystem; if (!$wp_filesystem || !is_object($wp_filesystem)) { WP_Filesystem(); } if (!is_object($wp_filesystem)) { return array('Errors' => array(__('Filesystem options not set correctly'))); } $fs =& $wp_filesystem; //Just for simplicity require_once 'pclzip.lib.php'; $messages = array(); if (!$filename) { return false; } /* NOTE: If this uses too much memory, it might be possible to just extract each file as needed rather than extracting entire archive into memory */ $archive = new PclZip($filename); //Check to see if its a Valid archive if (false == ($archiveFiles = $archive->extract(PCLZIP_OPT_EXTRACT_AS_STRING))) { return array('Errors' => array(__('Incompatible Archive'))); } else { $messages[] = __('Valid Archive Selected'); } if (0 == count($archiveFiles)) { return array('Errors' => array(__('Empty Archive'))); } //First of all, Does the zip file contain a base folder? $base = $fs->get_base_dir() . $destination; $messages[] = sprintf(__("Base Directory: <strong>%s</strong>"), $base); $fs->setDefaultPermissions($fs->getchmod($base)); //Check if the destination directory exists, If not, create it. $path = explode('/', $base); $tmppath = ''; for ($j = 0; $j < count($path) - 1; $j++) { $tmppath .= $path[$j] . '/'; if (!$fs->is_dir($tmppath)) { $messages[] = __('<strong>Creating folder</strong>: ') . $tmppath . succeeded($fs->mkdir($tmppath)); } } if (count($archiveFiles) > 1) { //Multiple files, they'll need to be in a folder $baseFolderName = false; foreach ((array) $archiveFiles as $thisFileInfo) { //If no Slash then it needs to be put in a folder if (false === strpos($thisFileInfo['filename'], '/')) { $messages[] = sprintf(__('Installing to Subdirectory: <strong>%s</strong>'), basename($fileinfo['name'], '.zip')); $base .= basename($fileinfo['name'], '.zip'); if ($fs->is_dir($base)) { return array('Errors' => array(sprintf(__('Folder Exists! Install cannot continue to installing to %s'), $base))); } $messages[] = __('<strong>Creating folder</strong>: ') . basename($fileinfo['name'], '.zip') . succeeded($fs->mkdir($base)); break; //We've created any folders we need, we can now break out of this loop. } } } //Inflate the files and Create Directory Structure foreach ($archiveFiles as $archiveFile) { $path = explode('/', $archiveFile['filename']); $tmppath = ''; //Loop through each of the items and check the folder exists. for ($j = 0; $j < count($path) - 1; $j++) { $tmppath .= $path[$j] . '/'; if (!$fs->is_dir($base . $tmppath)) { $messages[] = __('<strong>Creating folder</strong>: ') . $tmppath . succeeded($fs->mkdir($base . $tmppath)); } } //end for //We've made sure the folders are there, So lets extract the file now: if (!$archiveFile['folder']) { $messages[] = __('<strong>Inflating File</strong>: ') . $archiveFile['filename'] . succeeded($fs->put_contents($base . $archiveFile['filename'], $archiveFile['content'])); } } return $messages; }
$tmppath .= $path[$j] . '/'; if (!$wp_filesystem->is_dir($tmppath)) { $messages[] = __('<strong>Creating folder</strong>: ') . $tmppath . succeeded($wp_filesystem->mkdir($tmppath)); } } foreach ((array) $diff as $filename => $fileInfo) { switch ($fileInfo['status']) { case 'deleted': $messages[] = __('<strong>Deleteing file</strong>: ') . $filename . succeeded($wp_filesystem->delete(ABSPATH . $destination . '/' . $filename, true)); break; case 'changed': $messages[] = __('<strong>Deleteing file</strong>: ') . $filename . succeeded($wp_filesystem->delete(ABSPATH . $destination . '/' . $filename, true)); //No Break, We delete the file, then treat it as a new file. //No Break, We delete the file, then treat it as a new file. case 'new': $messages[] = __('<strong>Installing file</strong>: ') . $filename . succeeded($wp_filesystem->copy(ABSPATH . $source . '/' . $filename, ABSPATH . $destination . '/' . $filename)); break; default: case 'same': //Leave unchanged files alone. break; } } echo implode("<br>", $messages); $folder = ABSPATH . 'wp-content/wpupdate/' . $_POST['upgrade_source']; $wp_filesystem->delete($folder, true); } else { ?> <h2><?php _e('Currently installed:'); ?>
statsceremony($myManager); break; case 'statsceremonycustomers': statsceremonycustomers($myManager); break; case 'statculturecustomers': statculturecustomers($myManager); break; case 'updateVisitor': updateVisitor($myManager); break; case 'removeOperation': removeOperation($myManager); break; case 'succeeded': succeeded($myManager); break; default: break; } } catch (PDOException $e) { echo MiscUtils::encode($e->getMessage()); } $myManager->commit_t(); function login($myManager) { $args = json_decode(MiscUtils::decryptParam('a', '[]')); $orm = classToOrm('pz_user'); $result = $orm->find($myManager, NULL, NULL, NULL, NULL, "d.account = '{$args->account}' AND d.password = '******'", NULL); if (count($result->data) == 1) { $user = $result->data[0];