Ejemplo n.º 1
1
 /**
  * @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;
 }
Ejemplo n.º 2
0
 /**
  * @param string $request
  * @throws SPException
  * @return void
  */
 public function validate($request = 'post')
 {
     $this->loadFields(Sobi::Section());
     foreach ($this->fields as $field) {
         /* @var $field SPField */
         if ($field->enabled('form', !$this->id)) {
             try {
                 $field->validate($this, $request);
             } catch (SPException $x) {
                 $exception = new SPException($x->getMessage());
                 $exception->setData(array('field' => $field->get('nid')));
                 throw $exception;
             }
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * @param string $out - output type
  * @param array $functions - array with PHP function to register
  * @throws SPException
  * @return mixed|string
  */
 public function display($out = 'html', $functions = array())
 {
     $class = SPLoader::loadClass('helpers.template');
     $methods = get_class_methods($class);
     if (count($methods)) {
         foreach ($methods as $method) {
             $functions[] = $class . '::' . $method;
         }
     }
     /* standard function registered via the core ini file */
     $stdFunctions = SPLoader::loadIniFile('etc.template_functions');
     if (count($stdFunctions)) {
         foreach ($stdFunctions as $class => $fns) {
             if (strstr($class, '.')) {
                 $class = SPLoader::loadClass($class, false, 'sp-root');
             }
             if (count($fns)) {
                 foreach ($fns as $method => $state) {
                     if ($state) {
                         $functions[] = $class == 'functions' ? $method : $class . '::' . $method;
                     }
                 }
             }
         }
     }
     Sobi::Trigger('TemplateEngine', 'RegisterFunctions', array(&$functions));
     $this->createXML();
     if (SPRequest::cmd('xml') && Sobi::Cfg('debug.xml_raw', false) && (!Sobi::Cfg('debug.xml_ip', null) || Sobi::Cfg('debug.xml_ip') == SPRequest::ip('REMOTE_ADDR', 0, 'SERVER'))) {
         SPFactory::mainframe()->cleanBuffer();
         echo $this->_xml->saveXML();
         exit;
     } elseif (SPRequest::cmd('xml')) {
         Sobi::Error('Debug', 'You have no permission to access this site', SPC::ERROR, 403, __LINE__, __FILE__);
     }
     $template = SPLoader::loadTemplate($this->_tpl, 'xsl');
     if (!$template) {
         $template = SPLoader::loadTemplate($this->_tpl, 'xslt');
     }
     if (Sobi::Cfg('cache.xml_enabled')) {
         SPFactory::cache()->addView($this->_xml, $template, $this->_cacheData);
     }
     if ($template) {
         try {
             if (!($style = DOMDocument::load($template))) {
                 Sobi::Error('template', SPLang::e('CANNOT_PARSE_TEMPLATE_FILE', $template), SPC::ERROR, 500, __LINE__, __FILE__);
             }
         } catch (DOMException $x) {
             Sobi::Error('template', SPLang::e('CANNOT_LOAD_TEMPLATE_FILE', $template, $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
         }
         Sobi::Trigger('TemplateEngine', 'LoadStyle', array(&$style));
         $processor = new XSLTProcessor();
         $processor->setParameter('block', 'xmlns', 'http://www.w3.org/1999/xhtml');
         $processor->registerPHPFunctions($functions);
         SPException::catchErrors(SPC::WARNING);
         try {
             $processor->importStylesheet($style);
         } catch (SPException $x) {
             Sobi::Error('template', SPLang::e('CANNOT_PARSE_TEMPLATE_FILE', $template) . $x->getMessage(), SPC::ERROR, 500, __LINE__, __FILE__);
         }
         SPException::catchErrors(0);
         if ($out == 'html') {
             $doc = $processor->transformToDoc($this->_xml);
             $doc->formatOutput = true;
             return $this->cleanOut($doc->saveXML());
         } else {
             $doc = $processor->transformToDoc($this->_xml);
             $doc->formatOutput = true;
             return $doc->saveXML();
         }
     } else {
         throw new SPException(SPLang::e('CANNOT_LOAD_TEMPLATE_FILE_AT', SPLoader::loadTemplate($this->_tpl, 'xsl', false)));
     }
 }
Ejemplo n.º 4
0
 /**
  * This function catch errors and throws an exception instead
  * It is going to be used to handle errors from function which does not throws exceptions
  * @param $type - type of the error to catch
  */
 public static function catchErrors($type = E_ALL)
 {
     self::$_trigger = $type;
 }