Esempio n. 1
0
 public function install()
 {
     $id = $this->xGetString('id');
     $name = $this->xGetString('name');
     if (SPLoader::dirPath('usr.templates.' . $id) && !SPRequest::bool('force')) {
         throw new SPException(SPLang::e('TEMPLATE_INST_DUPLICATE', $name) . ' ' . Sobi::Txt('FORCE_TPL_UPDATE', Sobi::Url(array('task' => 'extensions.install', 'force' => 1, 'root' => basename($this->root) . '/' . basename($this->xmlFile)))));
     }
     $requirements = $this->xGetChilds('requirements/*');
     if ($requirements && $requirements instanceof DOMNodeList) {
         SPFactory::Instance('services.installers.requirements')->check($requirements);
     }
     $language = $this->xGetChilds('language/file');
     $folder = @$this->xGetChilds('language/@folder')->item(0)->nodeValue;
     if ($language && $language instanceof DOMNodeList && $language->length) {
         $langFiles = array();
         foreach ($language as $file) {
             $adm = false;
             if ($file->attributes->getNamedItem('admin')) {
                 $adm = $file->attributes->getNamedItem('admin')->nodeValue == 'true' ? true : false;
             }
             $langFiles[$file->attributes->getNamedItem('lang')->nodeValue][] = array('path' => Sobi::FixPath("{$this->root}/{$folder}/" . trim($file->nodeValue)), 'name' => $file->nodeValue, 'adm' => $adm);
         }
         SPFactory::CmsHelper()->installLang($langFiles, false, true);
     }
     $path = SPLoader::dirPath('usr.templates.' . $id, 'front', false);
     if (SPRequest::bool('force')) {
         /** @var $from SPDirectory */
         $from = SPFactory::Instance('base.fs.directory', $this->root);
         $from->moveFiles($path);
     } else {
         if (!SPFs::move($this->root, $path)) {
             throw new SPException(SPLang::e('CANNOT_MOVE_DIRECTORY', $this->root, $path));
         }
     }
     if (!SPRequest::bool('force')) {
         $section = $this->xGetChilds('install');
         if ($section instanceof DOMNodeList && $section->length) {
             $this->section($id);
         }
     }
     //05 Oct 2015 Kishore
     $exec = $this->xGetString('exec');
     if ($exec && SPFs::exists($path . DS . $exec)) {
         include_once "{$path}/{$exec}";
     }
     /** @var $dir SPDirectory */
     $dir =& SPFactory::Instance('base.fs.directory', $path);
     $zip = array_keys($dir->searchFile('.zip', false));
     if (count($zip)) {
         foreach ($zip as $file) {
             SPFs::delete($file);
         }
     }
     Sobi::Trigger('After', 'InstallTemplate', array($id));
     $dir =& SPFactory::Instance('base.fs.directory', SPLoader::dirPath('tmp.install'));
     $dir->deleteFiles();
     return Sobi::Txt('TP.TEMPLATE_HAS_BEEN_INSTALLED', array('template' => $name));
 }
Esempio n. 2
0
 /**
  * Move files from directory to given path
  * @param string $target - target path
  * @return array
  */
 public function moveFiles($target)
 {
     $this->iterator();
     $log = array();
     foreach ($this->_dirIterator as $child) {
         if (!$child->isDot() && !SPFs::exists(Sobi::FixPath($target . DS . $child->getFileName()))) {
             if (SPFs::move($child->getPathname(), Sobi::FixPath($target . DS . $child->getFileName()))) {
                 $log[] = Sobi::FixPath($target . DS . $child->getFileName());
             }
         }
     }
     return $log;
 }
Esempio n. 3
0
 public function install()
 {
     $id = $this->xGetString('id');
     $name = $this->xGetString('name');
     if (SPLoader::dirPath('usr.templates.' . $id) && !SPRequest::bool('force')) {
         throw new SPException(SPLang::e('TEMPLATE_INST_DUPLICATE', $name) . ' ' . Sobi::Txt('FORCE_TPL_UPDATE', Sobi::Url(array('task' => 'extensions.install', 'force' => 1, 'root' => basename($this->root) . '/' . basename($this->xmlFile)))));
     }
     $requirements = $this->xGetChilds('requirements/*');
     if ($requirements && $requirements instanceof DOMNodeList) {
         SPFactory::Instance('services.installers.requirements')->check($requirements);
     }
     $path = SPLoader::dirPath('usr.templates.' . $id, 'front', false);
     if (SPRequest::bool('force')) {
         /** @var $from SPDirectory */
         $from = SPFactory::Instance('base.fs.directory', $this->root);
         $from->moveFiles($path);
     } else {
         if (!SPFs::move($this->root, $path)) {
             throw new SPException(SPLang::e('CANNOT_MOVE_DIRECTORY', $this->root, $path));
         }
     }
     if (!SPRequest::bool('force')) {
         $section = $this->xGetChilds('install');
         if ($section instanceof DOMNodeList && $section->length) {
             $this->section($id);
         }
     }
     $exec = $this->xGetString('exec');
     if ($exec && SPFs::exists($this->root . DS . $exec)) {
         include_once "{$this->root}/{$exec}";
     }
     /** @var $dir SPDirectory */
     $dir =& SPFactory::Instance('base.fs.directory', $path);
     $zip = array_keys($dir->searchFile('.zip', false));
     if (count($zip)) {
         foreach ($zip as $file) {
             SPFs::delete($file);
         }
     }
     Sobi::Trigger('After', 'InstallTemplate', array($id));
     $dir =& SPFactory::Instance('base.fs.directory', SPLoader::dirPath('tmp.install'));
     $dir->deleteFiles();
     return Sobi::Txt('TP.TEMPLATE_HAS_BEEN_INSTALLED', array('template' => $name));
 }
Esempio n. 4
0
 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;
 }
Esempio n. 5
0
 /**
  * @param $name
  * @return bool
  */
 public function rename($name)
 {
     $filename = SPFs::getFileName($this->_filename);
     $new = str_replace($filename, $name, $this->_filename);
     if (SPFs::move($this->_filename, $new)) {
         $this->_filename = $new;
         return true;
     } else {
         return false;
     }
 }
Esempio n. 6
0
 /**
  * Install language file
  * @param string $lang
  * @param bool $force
  * @param bool $move
  * @return array
  */
 public static function installLang($lang, $force = true, $move = false)
 {
     $log = array();
     if (count($lang)) {
         foreach ($lang as $language => $files) {
             $language = str_replace('_', '-', $language);
             if (count($files)) {
                 foreach ($files as $file) {
                     $target = $file['adm'] ? implode('/', array(JPATH_ADMINISTRATOR, 'language', $language)) : implode('/', array(SOBI_ROOT, 'language', $language));
                     if ($force || SPFs::exists($target)) {
                         $iFile = $target . '/' . trim($file['name']);
                         $log[] = $iFile;
                         $move ? SPFs::move(Sobi::FixPath($file['path']), $iFile) : SPFs::copy(Sobi::FixPath($file['path']), $iFile);
                     }
                 }
             }
         }
     }
     return $log;
 }