public function exitEditor() { //eDebug($this->params,true); switch ($this->params['exitType']) { case 'saveAsCopy': $oldimage = new expFile($this->params['fid']); $copyname = expFile::resolveDuplicateFilename($oldimage->path); copy(BASE . $this->cacheDir . "/" . $this->params['cpi'], $oldimage->directory . $copyname); //copy the edited file over to the files dir $newFile = new expFile(array("filename" => $copyname)); //construct a new expFile $newFile->directory = $oldimage->directory; $newFile->title = $oldimage->title; $newFile->shared = $oldimage->shared; $newFile->mimetype = $oldimage->mimetype; $newFile->posted = time(); $newFile->filesize = filesize(BASE . $this->cacheDir . "/" . $this->params['cpi']); $resized = getimagesize(BASE . $this->cacheDir . "/" . $this->params['cpi']); $newFile->image_width = $resized[0]; $newFile->image_height = $resized[1]; $newFile->alt = $oldimage->alt; $newFile->is_image = $oldimage->is_image; $newFile->save(); //Save it to the database break; case 'saveAsIs': //eDebug($this->params,true); $oldimage = new expFile($this->params['fid']); $resized = getimagesize(BASE . $this->cacheDir . "/" . $this->params['cpi']); $oldimage->image_width = $resized[0]; $oldimage->image_height = $resized[1]; $oldimage->save(); copy(BASE . $this->cacheDir . "/" . $this->params['cpi'], $oldimage->directory . $oldimage->filename); //copy the edited file over to the files dir break; default: # code... break; } // proper file types to look for $types = array(".jpg", ".gif", ".png"); //Pixidou images directory, the editor's cache $cachedir = BASE . $this->cacheDir; if (is_dir($cachedir) && is_readable($cachedir)) { $dh = opendir($cachedir); while (($tmpfile = readdir($dh)) !== false) { if (in_array(substr($tmpfile, -4, 4), $types)) { $filename = $cachedir . $tmpfile; unlink($filename); } } } redirect_to(array("controller" => 'file', "action" => 'picker', "ajax_action" => 1, "update" => $this->params['update'], "fck" => $this->params['fck'])); }
/** * @param array $params * @return bool */ public function update($params = array()) { // if not user id then we should not be doing anything here if (empty($params['user_id'])) { return false; } $this->user_id = $params['user_id']; // check for a previous avatar otherwise set the default $this->image = $params['current_avatar']; if (empty($this->image)) { $this->image = URL_FULL . 'framework/modules/users/assets/images/avatar_not_found.jpg'; } if (!empty($_FILES['avatar']['tmp_name'])) { // if the user uploaded a new avatar lets save it! $info = expFile::getImageInfo($_FILES['avatar']['tmp_name']); if ($info['is_image']) { // figure out the mime type and set the file extension and name $extinfo = explode('/', $info['mime']); $extension = $extinfo[1]; $avatar_name = $this->user_id . '.' . $extension; // save the file to the filesystem $file = expFile::fileUpload('avatar', true, false, $avatar_name, 'files/avatars/'); //save the file to the database $this->image = $file->url; $this->use_gravatar = false; // if we uploaded a file, we don't want to use gravatar } } elseif (!empty($params['use_gravatar'])) { // if the user chose gravatar, create the link and save it! $this->use_gravatar = $params['use_gravatar']; $emailMD5 = md5(strtolower(trim(user::getEmailById($params['user_id'])))); $this->image = "http://www.gravatar.com/avatar/" . $emailMD5 . ".jpg"; } parent::update(); }
/** * cleans out all the cache folders * @return bool */ function upgrade() { // work our way through all the tmp files and remove them $files = array(BASE . 'tmp/css', BASE . 'tmp/minify', BASE . 'tmp/pixidou', BASE . 'tmp/rsscache', BASE . 'tmp/views_c', BASE . 'tmp/cache', BASE . 'tmp/img_cache', BASE . 'tmp/extensionuploads'); // delete the files. $removed = 0; $errors = 0; foreach ($files as $file) { if (file_exists($file)) { $files = expFile::removeFilesInDirectory($file); $removed += count($files['removed']); $errors += count($files['not_removed']); } } return gt("All Caches were cleared.") . "<br>" . $errors . " " . gt("files could not be removed."); }
$config = $_POST['sc']; foreach ($config as $key => $value) { expSettings::change($key, addslashes($value)); } } else { // Initialize /conf/config $config = $_POST['sc']; $values = array('c' => $config, 'opts' => array(), 'configname' => 'Default', 'activate' => 1); expSettings::saveConfiguration($values); } } if (isset($_POST['install_sample'])) { $eql = BASE . $_POST['install_sample'] . ".eql"; if (file_exists($eql)) { $errors = array(); expFile::restoreDatabase($db, $eql, $errors, 0); $files = BASE . $_POST['install_sample'] . ".tar.gz"; // only install if there was an eql file if (file_exists($files)) { include_once BASE . 'external/Tar.php'; $tar = new Archive_Tar($files); // $dest_dir = BASE.'files/'; // @mkdir($dest_dir); // if (file_exists($dest_dir)) { $return = $tar->extract(BASE); // } } } // if (count($errors)) { // echo gt('Errors were encountered populating the site database.').'<br /><br />'; // foreach ($errors as $e) echo $e . '<br />';
# Copyright (c) 2004-2011 OIC Group, Inc. # Written and Designed by James Hunt # # This file is part of Exponent # # Exponent is free software; you can redistribute # it and/or modify it under the terms of the GNU # General Public License as published by the Free # Software Foundation; either version 2 of the # License, or (at your option) any later version. # # GPL: http://www.gnu.org/licenses/gpl.txt # ################################################## /** @define "BASE" "../../../../.." */ if (!defined('EXPONENT')) { exit(''); } $errors = null; $continue = URL_FULL . 'index.php?section=' . SITE_DEFAULT_SECTION; expSession::clearAllUsersSessionCache(); $template = new template('importer', '_eql_results', $loc); //GREP:UPLOADCHECK if (!expFile::restoreDatabase($db, $_FILES['file']['tmp_name'], $errors)) { $template->assign('success', 0); $template->assign('errors', $errors); } else { $template->assign('success', 1); $template->assign('continue', $continue); } $template->output();
/** * download a file attached to item */ function downloadfile() { global $db; if (!isset($this->config['allowdownloads']) || $this->config['allowdownloads'] == true) { //if ($db->selectObject('content_expFiles', 'content_type="'.$this->baseclassname.'" AND expfiles_id='.$this->params['id']) != null) { expFile::download($this->params['id']); //} } else { flash('error', gt('Downloads have not been enabled for this file')); expHistory::back(); } }
public static function removeSmartyCache() { expFile::removeFilesInDirectory(BASE . 'tmp/cache'); // alt location for cache return expFile::removeFilesInDirectory(BASE . 'tmp/views_c'); }
# This file is part of Exponent # # Exponent is free software; you can redistribute # it and/or modify it under the terms of the GNU # General Public License as published by the Free # Software Foundation; either version 2 of the # License, or (at your option) any later version. # # GPL: http://www.gnu.org/licenses/gpl.txt # ################################################## /** @define "BASE" "../../../../.." */ if (!defined('EXPONENT')) { exit(''); } $dest_dir = $_POST['dest_dir']; $files = array(); foreach (array_keys($_POST['mods']) as $file) { $files[$file] = expFile::canCreate(BASE . 'files/' . $file); // if (class_exists($mod)) { // $files[$mod][0] = call_user_func(array($mod,'name')); // } // foreach (array_keys(expFile::listFlat($dest_dir.'/files',1,null,array(),$dest_dir.'/files/')) as $file) { // $files[$mod][1][$file] = expFile::canCreate(BASE.'files/'.$file); // } } expSession::set('dest_dir', $dest_dir); expSession::set('files_data', $files); $template = new template('importer', '_files_verifyFiles'); $template->assign('files_data', $files); $template->output();
function moveFile($original_name, $formvalues) { $dir = 'files/uploads'; $filename = expFile::fixName(time() . '_' . $formvalues[$original_name]['name']); $dest = $dir . '/' . $filename; //Check to see if the directory exists. If not, create the directory structure. if (!file_exists(BASE . $dir)) { expFile::makeDirectory($dir); } // Move the temporary uploaded file into the destination directory, and change the name. expFile::moveUploadedFile($formvalues[$original_name]['tmp_name'], BASE . $dest); return $dest; }
//Get the post data for future massaging $post = $_POST; //Check to make sure the user filled out the required input. if (!is_numeric($_POST["rowstart"])) { unset($post['rowstart']); $post['_formError'] = gt('The starting row must be a number.'); expSession::set("last_POST", $post); header("Location: " . $_SERVER['HTTP_REFERER']); exit('Redirecting...'); } //Get the temp directory to put the uploaded file $directory = "framework/modules-1/importer/importers/usercsv/tmp"; //Get the file save it to the temp directory if ($_FILES["upload"]["error"] == UPLOAD_ERR_OK) { // $file = file::update("upload",$directory,null,time()."_".$_FILES['upload']['name']); $file = expFile::fileUpload("upload", false, false, time() . "_" . $_FILES['upload']['name'], $directory); //FIXME quick hack to remove file model if ($file == null) { switch ($_FILES["upload"]["error"]) { case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE: $post['_formError'] = gt('The file you attempted to upload is too large. Contact your system administrator if this is a problem.'); break; case UPLOAD_ERR_PARTIAL: $post['_formError'] = gt('The file was only partially uploaded.'); break; case UPLOAD_ERR_NO_FILE: $post['_formError'] = gt('No file was uploaded.'); break; default: $post['_formError'] = gt('A strange internal error has occurred. Please contact the Exponent Developers.');
# # Exponent is free software; you can redistribute # it and/or modify it under the terms of the GNU # General Public License as published by the Free # Software Foundation; either version 2 of the # License, or (at your option) any later version. # # GPL: http://www.gnu.org/licenses/gpl.txt # ################################################## /** @define "BASE" "../../../../.." */ if (!defined('EXPONENT')) { exit(''); } $dest_dir = expSession::get('dest_dir'); $files = expSession::get('files_data'); if (!file_exists(BASE . 'files')) { mkdir(BASE . 'files', 0777); } $filecount = 0; foreach (array_keys($files) as $file) { expFile::copyDirectoryStructure($dest_dir . '/files/' . $file, BASE . 'files/' . $file); copy($dest_dir . '/files/' . $file, BASE . 'files/' . $file); $filecount += 1; } expSession::un_set('dest_dir'); expSession::un_set('files_data'); expFile::removeDirectory($dest_dir); $template = new template('importer', '_files_final'); $template->assign('file_count', $filecount); $template->output();
public function export() { // gather all the data $banners = $this->banner->find('all'); $out = '"Banner ID","Banner Title","Banner URL","Company Name","Impression Limit","Click Limit","Impressions","Clicks"' . "\n"; foreach ($banners as $l) { $out .= '"' . $l->id . '","' . $l->title . '","' . $l->url . '","' . $l->company->title . '","' . $l->impression_limit . '","' . $l->click_limit . '","' . $l->impressions . '","' . $l->clicks . '"' . "\n"; } // open the file $dir = BASE . 'tmp'; $filename = 'banner_export' . date("m-d-Y") . '.csv'; $fh = fopen($dir . '/' . $filename, 'w'); // Put all values from $out to export.csv. fputs($fh, $out); fclose($fh); // push the file to the user $export = new expFile(array('directory' => $dir, 'filename' => $filename)); expFile::download($export); }
echo gt('Unable to create temporary directory to extract files archive.'); } else { $return = $tar->extract($dest_dir); if (!$return) { echo '<br />' . gt('Error extracting TAR archive') . '<br />'; } else { if (!file_exists($dest_dir . '/files') || !is_dir($dest_dir . '/files')) { echo '<br />' . gt('Invalid archive format') . '<br />'; } else { // Show the form for specifying which mod types to 'extract' $mods = array(); // Stores the mod classname, the files list, and the module's real name $dh = opendir($dest_dir . '/files'); while (($file = readdir($dh)) !== false) { if ($file[0] != '.' && is_dir($dest_dir . '/files/' . $file)) { $mods[$file] = array('', array_keys(expFile::listFlat($dest_dir . '/files/' . $file, 1, null, array(), $dest_dir . '/files/'))); // if (class_exists($file)) { // $mods[$file][0] = call_user_func(array($file,'name')); // $file is the class name of the module // } } elseif ($file != '.' && $file != '..') { $mods[$file] = array('', $file); } } $template = new template('importer', '_files_selectModList'); $template->assign('dest_dir', $dest_dir); $template->assign('file_data', $mods); $template->output(); } } } }
public function install_extension_finish() { $sessid = session_id(); if (!file_exists(BASE . "tmp/extensionuploads/{$sessid}") || !is_dir(BASE . "tmp/extensionuploads/{$sessid}")) { // $template = new template('administrationmodule','_upload_finalSummary',$loc); // $template->assign('nofiles',1); $nofiles = 1; } else { $success = array(); foreach (array_keys(expFile::listFlat(BASE . "tmp/extensionuploads/{$sessid}", true, null, array(), BASE . "tmp/extensionuploads/{$sessid}")) as $file) { if ($file != '/archive.tar' && $file != '/archive.tar.gz' && $file != 'archive.tar.bz2' && $file != '/archive.zip') { expFile::makeDirectory(dirname($file)); $success[$file] = copy(BASE . "tmp/extensionuploads/{$sessid}" . $file, BASE . substr($file, 1)); if (basename($file) == 'views_c') { chmod(BASE . substr($file, 1), 0777); } } } $del_return = expFile::removeDirectory(BASE . "tmp/extensionuploads/{$sessid}"); //FIXME shouldn't use echo echo $del_return; // ob_start(); // include(BASE . 'framework/modules-1/administrationmodule/actions/installtables.php'); // ob_end_clean(); self::install_dbtables(); // $template = new template('administrationmodule','_upload_finalSummary',$loc); // $template->assign('nofiles',0); $nofiles = 0; // $template->assign('success',$success); // $template->assign('redirect',expHistory::getLastNotEditable()); } // $template->output(); assign_to_template(array('nofiles' => $nofiles, 'success' => $success, 'redirect' => expHistory::getLastNotEditable())); }
# # Exponent is free software; you can redistribute # it and/or modify it under the terms of the GNU # General Public License as published by the Free # Software Foundation; either version 2 of the # License, or (at your option) any later version. # # GPL: http://www.gnu.org/licenses/gpl.txt # ################################################## /** @define "BASE" "../../../../.." */ if (!defined('EXPONENT')) { exit(''); } $template = new template("importer", "_usercsv_form_start"); if (expFile::canCreate(BASE . "framework/modules-1/importer/importers/usercsv/tmp/test") != SYS_FILES_SUCCESS) { $template->assign("error", "The modules/importer/importers/usercsv/tmp directory is not writable. Please contact your administrator."); $template->output(); } else { //Setup the mete data (hidden values) $form = new form(); $form->meta("module", "importer"); $form->meta("action", "page"); $form->meta("page", "mapper"); $form->meta("importer", "usercsv"); //Setup the arrays with the name/value pairs for the dropdown menus $delimiterArray = array(',' => gt('Comma'), ';' => gt('Semicolon'), ':' => gt('Colon'), ' ' => gt('Space')); //Register the dropdown menus $form->register("delimiter", gt('Delimiter Character'), new dropdowncontrol(",", $delimiterArray)); $form->register("upload", gt('CSV File to Upload'), new uploadcontrol()); $form->register("rowstart", gt('Row to Begin at'), new textcontrol("1", 1, 0, 6));
flash('error', gt("Error opening eql file for writing") . " " . $path); } else { $eqlfile = expFile::dumpDatabase($db, array_keys($_POST['tables'])); if (fwrite($eql, $eqlfile) === FALSE) { flash('error', gt("Error writing to eql file") . " " . $path); } fclose($eql); flash('message', gt("Sample database (eql file) saved to") . " '" . DISPLAY_THEME . "' " . gt("theme")); expHistory::back(); } } else { // This code was lifted from phpMyAdmin, but this is Open Source, right? // 'application/octet-stream' is the registered IANA type but // MSIE and Opera seems to prefer 'application/octetstream' $mime_type = EXPONENT_USER_BROWSER == 'IE' || EXPONENT_USER_BROWSER == 'OPERA' ? 'application/octetstream' : 'application/octet-stream'; header('Content-Type: ' . $mime_type); header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // IE need specific headers if (EXPONENT_USER_BROWSER == 'IE') { header('Content-Disposition: inline; filename="' . $filename . '"'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); } else { header('Content-Disposition: attachment; filename="' . $filename . '"'); header('Pragma: no-cache'); } echo expFile::dumpDatabase($db, array_keys($_POST['tables'])); exit(''); // Exit, since we are exporting } }
/** * File UPLOAD that also inserts File info into database. * * File UPLOAD is a straight forward uploader and processor. It can accept * filename and destination directory overrides as well. It has an additional * pair of flags that allow for an upload NOT to be inserted into the database * (default to INSERT) and if it previous file, with the same name, should be * overwritten (default to NO overwrite) * * @static * @access public * * @uses class|method|global|variable description * @requires class_name * * @PHPUnit Not Defined|Implement|Completed * * @param string $_postName The name of the _FILE upload array * @param bool|string $_force Force the uploaded to overwrite existing file of same name * @param bool|string $_save Save file info to database, defaults to TRUE * @param string $_destFile Override the uploaded file name * @param string $_destDir Override the default FILE UPLOAD location * * @return object $_objFile expFile Object * @return object $errMsg Error message if something failed@throws void * * @TODO Have file upload overwrite make sure not to duplicate its record in the DB * */ public static function fileUpload($_postName = null, $_force = false, $_save = true, $_destFile = null, $_destDir = null) { // Make sure something was sent first off... if (!isset($_SERVER['CONTENT_TYPE']) || strpos($_SERVER['CONTENT_TYPE'], 'multipart/form-data') !== 0) { return 'bad upload form'; } //check for errors switch ($_FILES[$_postName]['error']) { case UPLOAD_ERR_OK: // Everything looks good. Continue with the update. break; case UPLOAD_ERR_INI_SIZE: // case images: // This is a tricky one to catch. If the file is too large for // POST, then the script won't even run. // But if its between post_max_size and upload_max_filesize, // we will get here. return 'file_too_large'; case UPLOAD_ERR_FORM_SIZE: return 'file_exceeds_form_MAX_FILE_SIZ'; case UPLOAD_ERR_PARTIAL: return 'partial_file'; case UPLOAD_ERR_NO_FILE: return 'no_file_uploaded'; case UPLOAD_ERR_NO_TMP_DIR: return 'missing_tmp_folder'; case UPLOAD_ERR_CANT_WRITE: return 'failed_write_to_disk'; case UPLOAD_ERR_EXTENSION: return 'upload_stopped_by_extension'; default: return 'unknown'; break; } // If $_destDir is not defined, use the default Files directory // $_destDir = ( $_destDir == null ) ? UPLOAD_DIRECTORY : $_destDir; $_destDir = $_destDir == null ? UPLOAD_DIRECTORY_RELATIVE : $_destDir; // If $_destFile is defined, use that name as an override for the // uploaded file name $_destFile = $_destFile == null ? self::fixFileName($_FILES[$_postName]['name']) : $_destFile; // Fix the filename, so that we don't have funky characters screwing // with our attempt to create the destination file. // $_destFile = self::fixFileName( $_FILES[$_postName]['name']); // eDebug($_destFile,1); // Build destination fille path for future use $_destFullPath = BASE . $_destDir . $_destFile; //if the file exists and we don't want to overwrite it, create a new one if (file_exists($_destFullPath) && $_force == false) { $_destFile = self::resolveDuplicateFilename($_destFullPath); $_destFullPath = $_destDir . $_destFile; } //Check to see if the directory exists. If not, create the directory structure. // if (!file_exists(BASE . $_destDir)) { // self::makeDirectory(BASE . $_destDir); // } // Move the temporary uploaded file into the destination directory, // and change the name. move_uploaded_file($_FILES[$_postName]['tmp_name'], $_destFullPath); if (file_exists($_destFullPath)) { $__oldumask = umask(0); chmod($_destFullPath, FILE_DEFAULT_MODE); umask($__oldumask); // Checking if ($__oldumask != umask()) { flash('error', gt('An error occurred while setting file permissions') . ': ' . $_destFullPath); } } else { return 'could not move'; } // At this point, we are good to go. // Create a new expFile Object for further processing $_fileParams = array('filename' => $_destFile, 'directory' => $_destDir); $_objFile = new expFile($_fileParams); // Insert new File Record if ($_save === true) { $_objFile->save(); } return $_objFile; }
public function editShare() { global $user; $file = new expFile($this->params['id']); if (!isset($this->params['newValue'])) { $this->params['newValue'] = 0; } if ($user->id == $file->poster || $user->is_acting_admin == 1) { $file->shared = $this->params['newValue']; $file->save(); $ar = new expAjaxReply(200, gt('This file is now shared.'), $file); } else { $ar = new expAjaxReply(300, gt("You didn't create this file, so it's not yours to share.")); } $ar->send(); echo json_encode($file); }