/** * @param string $to - path where the archive should be extracted to * @return bool */ public function extract($to) { $r = false; $ext = SPFs::getExt($this->_filename); switch ($ext) { case 'zip': $zip = new ZipArchive(); if ($zip->open($this->_filename) === true) { SPException::catchErrors(SPC::WARNING); try { $zip->extractTo($to); $zip->close(); $r = true; } catch (SPException $x) { $t = Sobi::FixPath(Sobi::Cfg('fs.temp') . DS . md5(microtime())); SPFs::mkdir($t, 0777); $dir = SPFactory::Instance('base.fs.directory', $t); if ($zip->extractTo($t)) { $zip->close(); $dir->moveFiles($to); $r = true; } SPFs::delete($dir->getPathname()); } SPException::catchErrors(0); } break; } return $r; }
/** * */ public function exif($sections = 0, $array = true) { if (function_exists('exif_read_data') && $this->_filename) { if (in_array(strtolower(SPFs::getExt($this->_filename)), array('jpg', 'jpeg', 'tiff'))) { $this->exif = exif_read_data($this->_filename, $sections, $array); } return $this->exif; } else { return false; } }
protected function iconChooser() { if (!Sobi::Can('category.edit')) { Sobi::Error('category', 'You have no permission to access this site', SPC::ERROR, 403, __LINE__, __FILE__); } $folder = SPRequest::cmd('iconFolder', null); $callback = SPRequest::cmd('callback', 'SPSelectIcon'); $dir = $folder ? Sobi::Cfg('images.category_icons') . str_replace('.', '/', $folder) . '/' : Sobi::Cfg('images.category_icons'); $files = array(); $dirs = array(); if ($folder) { $up = explode('.', $folder); unset($up[count($up) - 1]); $dirs[] = array('name' => Sobi::Txt('FOLEDR_UP'), 'count' => count(scandir($dir . '..')) - 2, 'url' => Sobi::Url(array('task' => 'category.icon', 'out' => 'html', 'iconFolder' => count($up) ? implode('.', $up) : null))); } $ext = array('png', 'jpg', 'jpeg', 'gif'); if (is_dir($dir) && ($dh = opendir($dir))) { while (($file = readdir($dh)) !== false) { if (filetype($dir . $file) == 'file' && in_array(strtolower(SPFs::getExt($file)), $ext)) { $files[] = array('name' => $folder ? str_replace('.', '/', $folder) . '/' . $file : $file, 'path' => str_replace('\\', '/', str_replace(SOBI_ROOT, Sobi::Cfg('live_site'), str_replace('//', '/', $dir . $file)))); } elseif (filetype($dir . $file) == 'dir' && !($file == '.' || $file == '..')) { $dirs[] = array('name' => $file, 'count' => count(scandir($dir . $file)) - 2, 'path' => str_replace('\\', '/', str_replace(SOBI_ROOT, Sobi::Cfg('live_site'), str_replace('//', '/', $dir . $file))), 'url' => Sobi::Url(array('task' => 'category.icon', 'out' => 'html', 'iconFolder' => $folder ? $folder . '.' . $file : $file))); } } closedir($dh); } sort($files); sort($dirs); $view = SPFactory::View('category'); $view->setTemplate('category.icon'); $view->assign($this->_task, 'task'); $view->assign($callback, 'callback'); $view->assign($files, 'files'); $view->assign(Sobi::Cfg('images.folder_ico'), 'folder'); $view->assign($dirs, 'directories'); $view->icon(); }
/** * */ private function mimeFromExt() { $ext = SPFs::getExt($this->_path); if (!count(self::$_exts)) { self::$_exts = SPLoader::loadIniFile('etc.mime', false); } if (!isset(self::$_exts[$ext])) { Sobi::Error('FileInfo', SPLang::e('Cannot determine the right file type from extension'), SPC::WARNING, 0); } else { $this->_mime = self::$_exts[$ext]; } }
/** * */ public function ProxyUpload() { $ident = SPRequest::cmd('ident', null, 'post'); $data = SPRequest::file($ident, 'tmp_name'); $secret = md5(Sobi::Cfg('secret')); if ($data) { $properties = SPRequest::file($ident); $orgFileName = $properties['name']; $extension = SPFs::getExt($orgFileName); $orgFileName = str_replace('.' . $extension, '.' . strtolower($extension), $orgFileName); if ($properties['size'] > $this->maxSize) { $this->message(array('type' => 'error', 'text' => SPLang::e('FIELD_IMG_TOO_LARGE', $this->name, $properties['size'], $this->maxSize), 'id' => '')); } $dirNameHash = md5($orgFileName . time() . $secret); $dirName = SPLoader::dirPath("tmp.files.{$secret}.{$dirNameHash}", 'front', false); SPFs::mkdir($dirName); $path = $dirName . $orgFileName; /** @var $file SPImage */ $orgImage = SPFactory::Instance('base.fs.image'); if (!$orgImage->upload($data, $path)) { $this->message(array('type' => 'error', 'text' => SPLang::e('CANNOT_UPLOAD_FILE'), 'id' => '')); } if (Sobi::Cfg('image_field.fix_rotation', true)) { if ($orgImage->fixRotation()) { $orgImage->save(); } } if ($this->crop) { $croppedImage = clone $orgImage; list($originalWidth, $originalHeight) = getimagesize($path); $aspectRatio = $this->resizeWidth / $this->resizeHeight; $width = $aspectRatio * $originalHeight > $originalWidth ? $originalWidth : $aspectRatio * $originalHeight; $height = $originalWidth / $aspectRatio > $originalHeight ? $originalHeight : $originalWidth / $aspectRatio; try { $croppedImage->crop($width, $height); $croppedImage->saveAs($dirName . 'cropped_' . $orgFileName); $ico = SPFactory::Instance('base.fs.image', $dirName . 'cropped_' . $orgFileName); } catch (SPException $x) { $this->message(array('type' => 'error', 'text' => SPLang::e('FIELD_IMG_CANNOT_CROP', $x->getMessage()), 'id' => '')); } } else { $ico = clone $orgImage; } $image = clone $orgImage; try { $previewSize = explode(':', Sobi::Cfg('image.preview_size', '500:500')); $image->resample($previewSize[0], $previewSize[1], false); $image->saveAs($dirName . 'resized_' . $orgFileName); } catch (SPException $x) { $image->delete(); $this->message(array('type' => 'error', 'text' => SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage()), 'id' => '')); } try { $icoSize = explode(':', Sobi::Cfg('image.ico_size', '80:80')); $ico->resample($icoSize[0], $icoSize[1], false); $ico->saveAs($dirName . 'icon_' . $orgFileName); } catch (SPException $x) { $ico->delete(); $this->message(array('type' => 'error', 'text' => SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage()), 'id' => '')); } $path = $orgImage->getPathname(); $type = $this->check($path); $properties['tmp_name'] = $path; SPFs::write(SPLoader::dirPath("tmp.files.{$secret}", 'front', false) . '/' . $orgFileName . '.var', SPConfig::serialize($properties)); $response = array('type' => 'success', 'text' => $this->crop ? Sobi::Txt('IMAGE_UPLOADED_CROP', $properties['name'], $type) : Sobi::Txt('FILE_UPLOADED', $properties['name']), 'id' => 'directory://' . $dirNameHash, 'data' => array('name' => $properties['name'], 'type' => $properties['type'], 'size' => $properties['size'], 'original' => $dirNameHash . '/' . $properties['name'], 'icon' => $dirNameHash . '/' . 'icon_' . $orgFileName, 'crop' => $this->crop, 'height' => $this->resizeHeight, 'width' => $this->resizeWidth)); } else { $response = array('type' => 'error', 'text' => SPLang::e('CANNOT_UPLOAD_FILE_NO_DATA'), 'id' => ''); } $this->message($response); }
private function editFile() { if (Sobi::Section() && Sobi::Cfg('section.template') == SPC::DEFAULT_TEMPLATE) { SPFactory::message()->warning(Sobi::Txt('TP.DEFAULT_WARN', 'https://www.sigsiu.net/help_screen/template.info'), false)->setSystemMessage(); } $file = SPRequest::cmd('file'); $file = $this->file($file); $ext = SPFs::getExt($file); $fileContent = SPFs::read($file); $path = str_replace('\\', '/', SOBI_PATH); if (strstr($file, $path)) { $filename = str_replace($path . '/usr/templates/', null, $file); } else { $filename = str_replace(SOBI_ROOT, null, $file); } $menu = $this->createMenu(); if (Sobi::Section()) { $menu->setOpen('AMN.APPS_SECTION_TPL'); } else { $menu->setOpen('GB.CFG.GLOBAL_TEMPLATES'); } /** @var $view SPAdmTemplateView */ $view = SPFactory::View('template', true)->assign($fileContent, 'file_content')->assign($filename, 'file_name')->assign($ext, 'file_ext')->assign($menu, 'menu')->assign($this->_task, 'task')->assign(Sobi::Section(), 'sid')->addHidden(SPRequest::cmd('file'), 'fileName')->addHidden($filename, 'filePath')->determineTemplate('template', 'edit'); Sobi::Trigger('Edit', $this->name(), array(&$file, &$view)); $view->display(); }
public function save(&$attr) { static $lang = null; static $defLang = null; if (!$lang) { $lang = Sobi::Lang(); $defLang = Sobi::DefLang(); } $file = SPRequest::file('spfieldsopts', 'tmp_name'); if ($file) { $data = parse_ini_file($file, true); } elseif (is_string($attr['options'])) { $data = parse_ini_string($attr['options'], true); } else { $data = null; } $options = $this->parseOptsFile($data); if (!count($options) && count($attr['options'])) { $p = 0; $hold = array(); foreach ($attr['options'] as $o) { if (is_numeric($o['id'])) { $o['id'] = $this->nid . '_' . $o['id']; } if (isset($o['id'])) { $i = 0; $oid = $o['id']; while (isset($hold[$oid])) { $oid = $o['id'] . '_' . ++$i; } $options[] = array('id' => $oid, 'name' => $o['name'], 'parent' => null, 'position' => ++$p); $hold[$oid] = $oid; } } } if (count($options)) { unset($attr['options']); $optionsArr = array(); $labelsArr = array(); $optsIds = array(); $defLabelsArr = array(); $duplicates = false; foreach ($options as $i => $option) { /* check for doubles */ foreach ($options as $pos => $opt) { if ($i == $pos) { continue; } if ($option['id'] == $opt['id']) { $option['id'] = $option['id'] . '_' . substr((string) microtime(), 2, 8) . rand(1, 100); $duplicates = true; } } $optionsArr[] = array('fid' => $this->id, 'optValue' => $option['id'], 'optPos' => $option['position'], 'optParent' => $option['parent']); $defLabelsArr[] = array('sKey' => $option['id'], 'sValue' => $option['name'], 'language' => $defLang, 'oType' => 'field_option', 'fid' => $this->id); $labelsArr[] = array('sKey' => $option['id'], 'sValue' => $option['name'], 'language' => $lang, 'oType' => 'field_option', 'fid' => $this->id); $optsIds[] = $option['id']; } if ($duplicates) { SPFactory::message()->warning('FIELD_WARN_DUPLICATE_OPT_ID'); } $db = SPFactory::db(); /* try to delete the existing labels */ try { $db->delete('spdb_field_option', array('fid' => $this->id)); $db->delete('spdb_language', array('oType' => 'field_option', 'fid' => $this->id, '!sKey' => $optsIds)); } catch (SPException $x) { Sobi::Error($this->name(), SPLang::e('CANNOT_STORE_FIELD_OPTIONS_DB_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__); } /* insert new values */ try { $db->insertArray('spdb_field_option', $optionsArr); $db->insertArray('spdb_language', $labelsArr, true); if ($defLang != $lang) { $db->insertArray('spdb_language', $defLabelsArr, false, true); } } catch (SPException $x) { Sobi::Error($this->name(), SPLang::e('CANNOT_DELETE_SELECTED_OPTIONS', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__); } } if (!isset($attr['params'])) { $attr['params'] = array(); } $myAttr = $this->getAttr(); $properties = array(); if (count($myAttr)) { foreach ($myAttr as $property) { $properties[$property] = isset($attr[$property]) ? $attr[$property] : null; } } $this->sets['field.options'] = SPFactory::Instance('types.array')->toINIString($data); /** handle upload of new definition file */ $XMLFile = SPRequest::file('select-list-dependency', 'tmp_name'); if ($XMLFile && file_exists($XMLFile)) { $XMLFileName = SPRequest::file('select-list-dependency', 'name'); if (SPFs::getExt($XMLFileName) == 'zip') { $arch = SPFactory::Instance('base.fs.archive'); $name = str_replace('.zip', null, $XMLFileName); $path = SPLoader::dirPath('tmp.install.' . $name, 'front', false); $c = 0; while (SPFs::exists($path)) { $path = SPLoader::dirPath('tmp.install.' . $name . '_' . ++$c, 'front', false); } $arch->upload($XMLFile, $path . '/' . $XMLFileName); $arch->extract($path); $files = scandir($path); if (count($files)) { foreach ($files as $defFile) { switch (SPFs::getExt($defFile)) { case 'xml': $properties['dependencyDefinition'] = $defFile; SPFs::move($path . '/' . $defFile, SOBI_PATH . '/etc/fields/select-list/' . $defFile); break; case 'ini': $defLang = explode('.', $defFile); $defLang = $defLang[0]; if (file_exists(SOBI_ROOT . '/language/' . $defLang)) { SPFs::move($path . '/' . $defFile, SOBI_ROOT . '/language/' . $defLang . '/' . $defFile); } break; } } } } elseif (SPFs::getExt($XMLFileName) == 'xml') { if (SPFs::upload($XMLFile, SOBI_PATH . '/etc/fields/select-list/' . $XMLFileName)) { $properties['dependencyDefinition'] = $XMLFileName; } } } /** if we use it - let's transform the XML file */ if ($properties['dependency'] && $properties['dependencyDefinition']) { $this->parseDependencyDefinition($properties['dependencyDefinition']); } $attr['params'] = $properties; }
/** * @param $dir SPDirectoryIterator * @param $nodes string * @param $current int * @param $count * @param bool $package * @return void */ private function travelTpl($dir, &$nodes, $current, &$count, $package = false) { $ls = Sobi::FixPath(Sobi::Cfg('img_folder_live') . '/tree'); static $root = null; if (!$root) { $root = new SPFile(SOBI_PATH); } $exceptions = array('config.xml', 'config.json'); foreach ($dir as $file) { $task = null; $fileName = $file->getFilename(); if (in_array($fileName, $exceptions)) { continue; } if ($file->isDot()) { continue; } $count++; if ($file->isDir()) { if ($current == 0 || $package) { if (strstr($file->getPathname(), $root->getPathname())) { $filePath = str_replace($root->getPathname() . '/usr/templates/', null, $file->getPathname()); } else { $filePath = 'cms:' . str_replace(SOBI_ROOT . '/', null, $file->getPathname()); } $filePath = str_replace('/', '.', $filePath); $insertTask = Sobi::Url(array('task' => 'template.info', 'template' => $filePath)); $nodes .= "spTpl.add( {$count}, {$current},'{$fileName}','', '', '', '{$ls}/imgfolder.gif', '{$ls}/imgfolder.gif' );\n"; if (!Sobi::Section()) { $count2 = $count * -100; $fileName = Sobi::Txt('TP.INFO'); $nodes .= "spTpl.add( {$count2}, {$count},'{$fileName}','{$insertTask}', '', '', '{$ls}/info.png' );\n"; if (file_exists($file->getPathname() . "/config.xml")) { $fileName = Sobi::Txt('TP.SETTINGS'); $count2--; $insertTask = Sobi::Url(array('task' => 'template.settings', 'template' => $filePath)); $nodes .= "spTpl.add( {$count2}, {$count},'{$fileName}','{$insertTask}', '', '', '{$ls}/settings.png' );\n"; } } } else { $nodes .= "spTpl.add( {$count}, {$current},'{$fileName}','');\n"; } $this->travelTpl(new SPDirectoryIterator($file->getPathname()), $nodes, $count, $count); } else { $ext = SPFs::getExt($fileName); if (in_array($ext, array('htaccess', 'zip')) || $fileName == 'index.html') { continue; } switch (strtolower($ext)) { case 'php': $ico = $ls . '/php.png'; break; case 'xml': $ico = $ls . '/xml.png'; break; case 'xsl': $ico = $ls . '/xsl.png'; break; case 'css': $ico = $ls . '/css.png'; break; case 'jpg': case 'jpeg': case 'png': case 'bmp': case 'gif': $ico = $ls . '/img.png'; $task = 'javascript:void(0);'; break; case 'ini': $ico = $ls . '/ini.png'; break; case 'less': $ico = $ls . '/less.png'; break; case 'js': $ico = $ls . '/js.png'; break; default: $ico = $ls . '/page.gif'; } if (!$task) { if (strstr($file->getPathname(), $root->getPathname())) { $filePath = str_replace($root->getPathname() . '/usr/templates/', null, $file->getPathname()); } else { $filePath = 'cms:' . str_replace(SOBI_ROOT . DS, null, $file->getPathname()); } $filePath = str_replace('/', '.', $filePath); if (Sobi::Section()) { $task = Sobi::Url(array('task' => 'template.edit', 'file' => $filePath, 'sid' => Sobi::Section())); } else { $task = Sobi::Url(array('task' => 'template.edit', 'file' => $filePath)); } } $nodes .= "spTpl.add( {$count}, {$current},'{$fileName}','{$task}', '', '', '{$ico}' );\n"; } } }
private function install($file = null) { $arch = SPFactory::Instance('base.fs.archive'); $ajax = strlen(SPRequest::cmd('ident', null, 'post')); if (!$file && SPRequest::string('root')) { $file = str_replace('.xml', null, SPRequest::string('root')); $file = SPLoader::path('tmp.install.' . $file, 'front', true, 'xml'); } if (!$file) { $ident = SPRequest::cmd('ident', null, 'post'); $data = SPRequest::file($ident); $name = str_replace(array('.' . SPFs::getExt($data['name']), '.'), null, $data['name']); $path = SPLoader::dirPath('tmp.install.' . $name, 'front', false); $c = 0; while (SPFs::exists($path)) { $path = SPLoader::dirPath('tmp.install.' . $name . '_' . ++$c, 'front', false); } /* * temp directory - will be removed later but it needs to be writable for apache and Joomla! fs (FTP mode) */ try { if (Sobi::Cfg('ftp_mode')) { SPFs::mkdir($path, 0777); } else { SPFs::mkdir($path); } } catch (SPException $x) { return $this->ajaxResponse($ajax, $x->getMessage(), false, SPC::ERROR_MSG); } $file = $path . '/' . $data['name']; try { $arch->upload($data['tmp_name'], $file); } catch (SPException $x) { return $this->ajaxResponse($ajax, $x->getMessage(), false, SPC::ERROR_MSG); } } elseif (SPRequest::string('root') && $file) { $path = dirname($file); } else { $arch->setFile($file); $name = str_replace(array('.' . SPFs::getExt($file), '.'), null, basename($file)); $path = SPLoader::dirPath('tmp.install.' . $name, 'front', false); $c = 0; while (SPFs::exists($path)) { $path = SPLoader::dirPath('tmp.install.' . $name . '_' . ++$c, 'front', false); } /* * temp directory - will be removed later but it needs to writable for apache and Joomla! fs (FTP mode) */ try { if (Sobi::Cfg('ftp_mode')) { SPFs::mkdir($path, 0777); } else { SPFs::mkdir($path); } } catch (SPException $x) { return $this->ajaxResponse($ajax, $x->getMessage(), false, SPC::ERROR_MSG); } } if ($path) { if (!SPRequest::string('root')) { if (!$arch->extract($path)) { return $this->ajaxResponse($ajax, SPLang::e('CANNOT_EXTRACT_ARCHIVE', basename($file), $path), false, SPC::ERROR_MSG); } } $dir =& SPFactory::Instance('base.fs.directory', $path); $xml = array_keys($dir->searchFile('.xml', false, 2)); if (!count($xml)) { return $this->ajaxResponse($ajax, SPLang::e('NO_INSTALL_FILE_IN_PACKAGE'), false, SPC::ERROR_MSG); } $definition = $this->searchInstallFile($xml); if (!$definition) { if (SPFactory::CmsHelper()->installerFile($xml)) { try { $message = SPFactory::CmsHelper()->install($xml, $path); return $this->ajaxResponse($ajax, $message['msg'], $ajax, $message['msgtype']); } catch (SPException $x) { return $this->ajaxResponse($ajax, $x->getMessage(), $ajax, SPC::ERROR_MSG); } } else { return $this->ajaxResponse($ajax, SPLang::e('NO_INSTALL_FILE_IN_PACKAGE'), false, SPC::ERROR_MSG); } } /** @var $installer SPInstaller */ $installer =& SPFactory::Instance('services.installers.' . trim(strtolower($definition->documentElement->tagName)), $xml[0], trim($definition->documentElement->tagName)); try { $installer->validate(); $msg = $installer->install(); return $this->ajaxResponse($ajax, $msg, true, SPC::SUCCESS_MSG); } catch (SPException $x) { return $this->ajaxResponse($ajax, $x->getMessage(), false, SPC::ERROR_MSG); } } else { return $this->ajaxResponse($ajax, SPLang::e('NO_FILE_HAS_BEEN_UPLOADED'), false, SPC::ERROR_MSG); } }
protected function cleanDir($dir, $ext, $force = false) { if ($dir) { $js = scandir($dir); if (count($js)) { foreach ($js as $file) { if ($file != '.' && $file != '..' && is_file(Sobi::FixPath("{$dir}/{$file}")) && (SPFs::getExt($file) == $ext || $ext == -1) && ($force || time() - filemtime(Sobi::FixPath("{$dir}/{$file}")) > 60 * 60 * 24 * 7)) { SPFs::delete(Sobi::FixPath("{$dir}/{$file}")); } } } } }