/** * @brief 업데이트 실행 **/ function moduleUpdate() { $oDB =& DB::getInstance(); // 2009. 02. 11 menu 테이블에 site_srl 추가 if (!$oDB->isColumnExists('layouts', 'site_srl')) { $oDB->addColumn('layouts', 'site_srl', 'number', 11, 0, true); } // 2009. 02. 26 faceOff에 맞춰 기존 레이아웃 편집본을 이동 $oLayoutModel =& getModel('layout'); $files = FileHandler::readDir('./files/cache/layout'); for ($i = 0, $c = count($files); $i < $c; $i++) { $filename = $files[$i]; if (!preg_match('/([0-9]+)\\.html/i', $filename, $match)) { continue; } $layout_srl = $match[1]; if (!$layout_srl) { continue; } $path = $oLayoutModel->getUserLayoutPath($layout_srl); if (!is_dir($path)) { FileHandler::makeDir($path); } FileHandler::copyFile('./files/cache/layout/' . $filename, $path . 'layout.html'); @unlink('./files/cache/layout/' . $filename); } return new Object(0, 'success_updated'); }
public function testFileMethods() { $mock = dirname(__FILE__) . '/mock.txt'; $mock2 = dirname(__FILE__) . '/mock2.txt'; touch($mock); // copy file $this->assertTrue(is_readable($mock)); FileHandler::copyFile($mock, $mock2); $this->assertTrue(is_readable($mock2)); // remove file $this->assertTrue(FileHandler::removeFile($mock2)); $this->assertFalse(is_readable($mock2)); $this->assertFalse(FileHandler::removeFile($mock2)); // rename file $this->assertTrue(FileHandler::rename($mock, $mock2)); $this->assertFalse(is_readable($mock)); $this->assertTrue(is_readable($mock2)); $this->assertFalse(FileHandler::rename($mock, $mock2)); // move file $this->assertTrue(FileHandler::rename($mock2, $mock)); $this->assertTrue(is_readable($mock)); $this->assertFalse(is_readable($mock2)); $this->assertTrue(touch($mock2) && is_readable($mock2)); $this->assertTrue(FileHandler::moveFile($mock, $mock2)); $this->assertFalse(is_readable($mock)); $this->assertTrue(is_readable($mock2)); // remove file $this->assertFalse(FileHandler::removeFile($mock)); $this->assertTrue(FileHandler::removeFile($mock2)); $this->assertFalse(is_readable($mock)); $this->assertFalse(is_readable($mock2)); }
function pluginInstall($args) { // mkdir FileHandler::makeDir(sprintf(_XE_PATH_ . "files/epay/%s/log", $args->plugin_srl)); // copy files FileHandler::copyFile(_XE_PATH_ . 'modules/epay/plugins/payplus6/.htaccess', sprintf(_XE_PATH_ . "files/epay/%s/.htaccess", $args->plugin_srl)); FileHandler::copyFile(_XE_PATH_ . 'modules/epay/plugins/payplus6/readme.txt', sprintf(_XE_PATH_ . "files/epay/%s/readme.txt", $args->plugin_srl)); }
/** * Save image to disk * * @author Dan Dragan (dev@xpressengine.org) * @param $image ProductImage * @return boolean */ public function saveImage(ProductImage &$image) { try { $path = sprintf('./files/attach/images/shop/%d/product-images/%d/', $image->module_srl, $image->product_srl); $filename = sprintf('%s%s', $path, $image->filename); FileHandler::copyFile($image->source_filename, $filename); } catch (Exception $e) { return new Object(-1, $e->getMessage()); } return TRUE; }
/** * Execute update * @return Object */ function moduleUpdate() { $oDB =& DB::getInstance(); // 2009. 02. 11 Add site_srl to menu table if (!$oDB->isColumnExists('layouts', 'site_srl')) { $oDB->addColumn('layouts', 'site_srl', 'number', 11, 0, true); } // 2009. 02. 26 Move the previous layout for faceoff $oLayoutModel = getModel('layout'); $files = FileHandler::readDir('./files/cache/layout'); for ($i = 0, $c = count($files); $i < $c; $i++) { $filename = $files[$i]; if (!preg_match('/([0-9]+)\\.html/i', $filename, $match)) { continue; } $layout_srl = $match[1]; if (!$layout_srl) { continue; } $path = $oLayoutModel->getUserLayoutPath($layout_srl); if (!is_dir($path)) { FileHandler::makeDir($path); } FileHandler::copyFile('./files/cache/layout/' . $filename, $path . 'layout.html'); @unlink('./files/cache/layout/' . $filename); } if (!$oDB->isColumnExists('layouts', 'layout_type')) { $oDB->addColumn('layouts', 'layout_type', 'char', 1, 'P', true); } $args = new stdClass(); $args->layout = '.'; $output = executeQueryArray('layout.getLayoutDotList', $args); if ($output->data && count($output->data) > 0) { foreach ($output->data as $layout) { $layout_path = explode('.', $layout->layout); if (count($layout_path) != 2) { continue; } if (is_dir(sprintf(_XE_PATH_ . 'themes/%s/layouts/%s', $layout_path[0], $layout_path[1]))) { $args->layout = implode('|@|', $layout_path); $args->layout_srl = $layout->layout_srl; $output = executeQuery('layout.updateLayout', $args); Rhymix\Framework\Cache::delete('layout:' . $args->layout_srl); } } } return new Object(0, 'success_updated'); }
function procSeoAdminSaveSetting() { $oModuleController = getController('module'); $vars = Context::getRequestVars(); $config = $this->getConfig(); if ($vars->setting_section == 'general') { // 기본 설정 $config->use_optimize_title = $vars->use_optimize_title; $config->site_name = $vars->site_name; $config->site_slogan = $vars->site_slogan; $config->site_description = $vars->site_description; $config->site_keywords = $vars->site_keywords; if ($vars->site_image) { $path = _XE_PATH_ . 'files/attach/site_image/'; $ext = strtolower(array_pop(explode('.', $vars->site_image['name']))); $timestamp = time(); $filename = "site_image.{$timestamp}.{$ext}"; FileHandler::copyFile($vars->site_image['tmp_name'], $path . $filename); $config->site_image = $filename; } } elseif ($vars->setting_section == 'analytics') { // analytics // Google $config->ga_id = trim($vars->ga_id); $config->ga_except_admin = $vars->ga_except_admin; // Naver $config->na_id = trim($vars->na_id); $config->na_except_admin = $vars->na_except_admin; } elseif ($vars->setting_section == 'miscellaneous') { // miscellaneous // Facebook $config->fb_app_id = trim($vars->fb_app_id); $config->fb_admins = trim($vars->fb_admins); } $config->site_image_url = NULL; $oModuleController->updateModuleConfig('seo', $config); $this->setMessage('success_updated'); if (Context::get('success_return_url')) { $this->setRedirectUrl(Context::get('success_return_url')); } }
/** * Add products info to export folder * @author Dan Dragan (dev@xpressengine.org) * * @param array $products * * @return boolean */ public function addProductsToExportFolder($products) { $buff = ''; //table header for products csv foreach ($products[0] as $key => $value) { if (!in_array($key, array('member_srl', 'module_srl', 'regdate', 'last_update', 'primary_image', 'repo', 'associated_products', 'cache'))) { if ($key == 'product_srl') { $buff = $buff . 'id,'; } else { $buff = $buff . $key . ","; } } } $buff = $buff . "configurable_attributes\r\n"; //table values for products csv foreach ($products as $product) { // add images to temp folder foreach ($product->images as $image) { $path = sprintf('./files/attach/images/shop/%d/product-images/%d/', $image->module_srl, $image->product_srl); $filename = sprintf('%s%s', $path, $image->filename); $export_filename = sprintf('./files/attach/shop/export-import/images/%s', $image->product_srl . $image->filename); FileHandler::copyFile($filename, $export_filename); } foreach ($product as $key => $value) { if (!in_array($key, array('member_srl', 'module_srl', 'regdate', 'last_update', 'primary_image', 'primary_image_filename', 'repo', 'categories', 'attributes', 'images', 'associated_products', 'configurable_attributes', 'cache'))) { $buff = $buff . str_replace(",", ";;", $value) . ","; } if ($key == 'primary_image_filename') { if (isset($product->primary_image_filename)) { $buff = $buff . $product->product_srl . $value . ","; } else { $buff = $buff . ","; } } $product_categories = ''; if ($key == 'categories') { foreach ($value as $category) { if ($product_categories == '') { $product_categories = $category; } else { $product_categories = $product_categories . '|' . $category; } } $buff = $buff . $product_categories . ","; } $product_attributes = ''; if ($key == 'attributes') { foreach ($value as $attribute_srl => $attribute_value) { if ($product_attributes == '') { $product_attributes = $attribute_srl . '=' . $attribute_value; } else { $product_attributes = $product_attributes . '|' . $attribute_srl . '=' . $attribute_value; } } $buff = $buff . $product_attributes . ","; } $images = ''; if ($key == 'images') { foreach ($value as $image) { if ($image->filename) { if ($images == '') { $images = $product->product_srl . $image->filename; } else { $images = $images . '|' . $product->product_srl . $image->filename; } } } $buff = $buff . $images . ","; } if ($key == 'configurable_attributes') { $configurable_attributes = ''; foreach ($value as $attribute_srl => $attribute_value) { if ($configurable_attributes == '') { $configurable_attributes = $attribute_srl; } else { $configurable_attributes = $configurable_attributes . '+' . $attribute_srl; } } } } $buff = $buff . $configurable_attributes . "\r\n"; } $product_csv_filename = 'products.csv'; $product_csv_path = sprintf('./files/attach/shop/export-import/%s', $product_csv_filename); FileHandler::writeFile($product_csv_path, $buff); return TRUE; }
function saveIcon($icon, $iconname) { $mobicon_size = array('57', '114'); $target_file = $icon['tmp_name']; $type = $icon['type']; $target_filename = _XE_PATH_ . 'files/attach/xeicon/' . $iconname; list($width, $height, $type_no, $attrs) = @getimagesize($target_file); if ($iconname == 'favicon.ico' && preg_match('/^.*(icon).*$/', $type)) { $fitHeight = $fitWidth = '16'; } else { if ($iconname == 'mobicon.png' && preg_match('/^.*(png).*$/', $type) && in_array($height, $mobicon_size) && in_array($width, $mobicon_size)) { $fitHeight = $fitWidth = $height; } else { return false; } } //FileHandler::createImageFile($target_file, $target_filename, $fitHeight, $fitWidth, $ext); FileHandler::copyFile($target_file, $target_filename); }
/** * Save category image to disc * * @param int $module_srl Module's srl * @param string $original_filename Original filename of the uploaded file * @param string $tmp_name Uploaded file's content * * @return string */ public function saveCategoryImage($module_srl, $original_filename, $tmp_name) { $tmp_arr = explode('.', $original_filename); $extension = $tmp_arr[count($tmp_arr) - 1]; $path = sprintf($this->category_images_folder, $module_srl); $filename = sprintf('%s%s.%s', $path, uniqid('product-category-'), $extension); FileHandler::copyFile($tmp_name, $filename); return $filename; }
/** * Layout file copy * @param $sourceLayoutSrl origin layout number * @param $targetLayoutSrl origin layout number * @return void */ function _copyLayoutFile($sourceLayoutSrl, $targetLayoutSrl) { $oLayoutModel = getModel('layout'); $sourceLayoutPath = FileHandler::getRealPath($oLayoutModel->getUserLayoutPath($sourceLayoutSrl)); $targetLayoutPath = FileHandler::getRealPath($oLayoutModel->getUserLayoutPath($targetLayoutSrl)); $sourceImagePath = $oLayoutModel->getUserLayoutImagePath($sourceLayoutSrl); $targetImagePath = $oLayoutModel->getUserLayoutImagePath($targetLayoutSrl); FileHandler::makeDir($targetImagePath); $sourceFileList = $oLayoutModel->getUserLayoutFileList($sourceLayoutSrl); foreach ($sourceFileList as $key => $file) { if (is_readable($sourceLayoutPath . $file)) { FileHandler::copyFile($sourceLayoutPath . $file, $targetLayoutPath . $file); if ($file == 'layout.html' || $file == 'layout.css') { $this->_changeFilepathInSource($targetLayoutPath . $file, $sourceImagePath, $targetImagePath); } } } }
/** * Copy directory * * @param array $file_list File list to copy * @return Object */ function _copyDir(&$file_list) { $output = $this->_connect(); if (!$output->toBool()) { return $output; } $target_dir = $this->target_path; if (is_array($file_list)) { foreach ($file_list as $k => $file) { $org_file = $file; if ($this->package->path == ".") { $file = substr($file, 3); } $path = FileHandler::getRealPath("./" . $this->target_path . "/" . $file); $path_list = explode('/', dirname($this->target_path . "/" . $file)); $real_path = "./"; for ($i = 0; $i < count($path_list); $i++) { if ($path_list == "") { continue; } $real_path .= $path_list[$i] . "/"; if (!file_exists(FileHandler::getRealPath($real_path))) { FileHandler::makeDir($real_path); } } FileHandler::copyFile(FileHandler::getRealPath($this->download_path . "/" . $org_file), FileHandler::getRealPath("./" . $target_dir . '/' . $file)); } } $this->_close(); return new Object(); }
/** * When copy a menu, button copied also. * @param $args menuItemInfo with button values */ private function _copyButton($insertedMenuItemSrl, $insertedMenuSrl, &$menuItemInfo) { $copied_info = array("normal_btn" => "", "hover_btn" => "", "active_btn" => ""); //normal_btn if ($menuItemInfo->normal_btn) { $originFile = FileHandler::getRealPath($menuItemInfo->normal_btn); $targetFile = $this->_changeMenuItemSrlInButtonPath($menuItemInfo->normal_btn, $insertedMenuSrl, $insertedMenuItemSrl, 'normal'); FileHandler::copyFile($originFile, $targetFile); $copied_info['normal_btn'] = $targetFile; } //hover_btn if ($menuItemInfo->hover_btn) { $originFile = FileHandler::getRealPath($menuItemInfo->hover_btn); $targetFile = $this->_changeMenuItemSrlInButtonPath($menuItemInfo->hover_btn, $insertedMenuSrl, $insertedMenuItemSrl, 'hover'); FileHandler::copyFile($originFile, $targetFile); $copied_info['hover_btn'] = $targetFile; } //active_btn if ($menuItemInfo->active_btn) { $originFile = FileHandler::getRealPath($menuItemInfo->active_btn); $targetFile = $this->_changeMenuItemSrlInButtonPath($menuItemInfo->active_btn, $insertedMenuSrl, $insertedMenuItemSrl, 'active'); FileHandler::copyFile($originFile, $targetFile); $copied_info['active_btn'] = $targetFile; } return $copied_info; }
/** * @brief 설정한 언어 파일 찾기 **/ function loadLangSelected() { static $lang_selected = null; if (is_null($lang_selected)) { $orig_lang_file = _XE_PATH_ . 'common/lang/lang.info'; $selected_lang_file = _XE_PATH_ . 'files/config/lang_selected.info'; if (!file_exists($selected_lang_file) || !filesize($selected_lang_file)) { $old_selected_lang_file = _XE_PATH_ . 'files/cache/lang_selected.info'; if (file_exists($old_selected_lang_file)) { FileHandler::copyFile($old_selected_lang_file, $selected_lang_file); FileHandler::removeFile($old_selected_lang_file); } } if (!file_exists($selected_lang_file) || !filesize($selected_lang_file)) { $buff = FileHandler::readFile($orig_lang_file); FileHandler::writeFile($selected_lang_file, $buff); $lang_selected = Context::loadLangSupported(); } else { $langs = file($selected_lang_file); foreach ($langs as $val) { list($lang_prefix, $lang_text) = explode(',', $val); $lang_text = trim($lang_text); $lang_selected[$lang_prefix] = $lang_text; } } } return $lang_selected; }
private function _saveFaviconTemp($icon, $iconname) { $site_info = Context::get('site_module_info'); $virtual_site = ''; if ($site_info->site_srl) { $virtual_site = $site_info->site_srl . '/'; } $original_filename = $icon['tmp_name']; $type = $icon['type']; $relative_filename = 'files/attach/xeicon/' . $virtual_site . 'tmp/' . $iconname; $target_filename = RX_BASEDIR . $relative_filename; list($width, $height, $type_no, $attrs) = @getimagesize($original_filename); if ($iconname == 'favicon.ico') { if (!preg_match('/^.*(x-icon|\\.icon)$/i', $type)) { Context::set('msg', '*.ico ' . Context::getLang('msg_possible_only_file')); return; } } elseif ($iconname == 'mobicon.png') { if (!preg_match('/^.*(png).*$/', $type)) { Context::set('msg', '*.png ' . Context::getLang('msg_possible_only_file')); return; } if (!($height == '57' && $width == '57' || $height == '114' && $width == '114')) { Context::set('msg', Context::getLang('msg_invalid_format') . ' (size : 57x57, 114x114)'); return; } } else { Context::set('msg', Context::getLang('msg_invalid_format')); return; } $fitHeight = $fitWidth = $height; FileHandler::copyFile($original_filename, $target_filename); return $relative_filename; }
/** * user layout ini * @param int $layout_srl * @return string */ function getUserLayoutIni($layout_srl) { $src = $this->getUserLayoutPath($layout_srl) . 'layout.ini'; if ($this->useUserLayoutTemp == 'temp') { $temp = $this->getUserLayoutTempIni($layout_srl); if (!file_exists(FileHandler::getRealPath($temp))) { FileHandler::copyFile($src, $temp); } return $temp; } return $src; }
function procMaterialInsert() { $var = Context::getRequestVars(); if (!$var->auth || !$var->type) { return new Object(-1, 'msg_not_permitted'); } $oMaterialModel =& getModel('material'); $member_srl = $oMaterialModel->getMemberSrlByAuth($var->auth); if (!$member_srl) { return new Object(-1, 'msg_invalid_request'); } if ($var->type == 'img') { if ($var->image) { $path = sprintf('files/cache/material/tmp/%s/', getNumberingPath($member_srl)); $filename = basename($var->image); $file = $path . $filename; FileHandler::makeDir($path); FileHandler::getRemoteFile($var->image, $file); if (file_exists($file)) { $material_srl = getNextSequence(); $ext = substr(strrchr($filename, '.'), 1); $ext = array_shift(explode('?', $ext)); // insert file module $file_info = array(); $file_info['tmp_name'] = $file; $file_info['name'] = sprintf("%s.%s", $material_srl, $ext); $oFileController =& getController('file'); $output = $oFileController->insertFile($file_info, $member_srl, $material_srl, 0, true); if (!$output->toBool()) { return $output; } //set File valid $oFileController->setFilesValid($output->get('upload_target_srl')); // delete temp file FileHandler::removeFile($filename); $uploaded_filename = $output->get('uploaded_filename'); $_filename = sprintf("%s%s.%%s.%s", preg_replace("/\\/[^\\/]*\$/", "/", $uploaded_filename), $material_srl, $ext); $s_filename = sprintf($_filename, 'S'); list($w, $h) = @getimagesize($uploaded_filename); if ($w > $this->thum['S']['width'] || $h > $this->thum['S']['height']) { FileHandler::createImageFile($uploaded_filename, $s_filename, $this->thum['S']['width'], $h, '', 'ratio'); } else { FileHandler::copyFile($uploaded_filename, $s_filename); } // replace image src $var->content = str_replace($var->image, $uploaded_filename, $var->content); } else { $var->image = null; } } else { return new Object(-1, 'msg_not_select_image'); } } // there is no file or copy failed if ($var->type == 'img' && !$var->image) { return new Object(-1, 'msg_fail_image_save'); } $args->material_srl = $material_srl ? $material_srl : getNextSequence(); $args->member_srl = $member_srl; $args->type = $var->type; $args->content = $var->content; $output = executeQuery('material.insertMaterial', $args); return $output; }
private function saveIconTmp($icon, $iconname) { $target_file = $icon['tmp_name']; $type = $icon['type']; $relative_filename = 'files/attach/xeicon/tmp/' . $iconname; $target_filename = _XE_PATH_ . $relative_filename; list($width, $height, $type_no, $attrs) = @getimagesize($target_file); if ($iconname == 'favicon.ico') { if (!preg_match('/^.*(x-icon|\\.icon)$/i', $type)) { Context::set('msg', '*.ico ' . Context::getLang('msg_possible_only_file')); return; } } else { if ($iconname == 'mobicon.png') { if (!preg_match('/^.*(png).*$/', $type)) { Context::set('msg', '*.png ' . Context::getLang('msg_possible_only_file')); return; } if (!($height == '57' && $width == '57' || $height == '114' && $width == '114')) { Context::set('msg', Context::getLang('msg_invalid_format') . ' (size : 57x57, 114x114)'); return; } } else { Context::set('msg', Context::getLang('msg_invalid_format')); return; } } $fitHeight = $fitWidth = $height; //FileHandler::createImageFile($target_file, $target_filename, $fitHeight, $fitWidth, $ext); FileHandler::copyFile($target_file, $target_filename); return $relative_filename; }