Пример #1
0
 public static function getMetaInfo($file, $type)
 {
     $meta = array();
     if (!file_exists($file) || !is_readable($file)) {
         return $meta;
     }
     $meta['creation'] = DateTimeObj::get('c', filemtime($file));
     if (General::in_iarray($type, fieldUpload::$imageMimeTypes) && ($array = @getimagesize($file))) {
         $meta['width'] = $array[0];
         $meta['height'] = $array[1];
     }
     return $meta;
 }
 /**
  * This function is called immediately from the Frontend class passing the current
  * URL for generation. Generate will resolve the URL to the specific page in the Symphony
  * and then execute all events and datasources registered to this page so that it can
  * be rendered. A number of delegates are fired during stages of execution for extensions
  * to hook into.
  *
  * @uses FrontendDevKitResolve
  * @uses FrontendOutputPreGenerate
  * @uses FrontendPreRenderHeaders
  * @uses FrontendOutputPostGenerate
  * @see __buildPage()
  * @param string $page
  * The URL of the current page that is being Rendered as returned by getCurrentPage
  * @return string
  * The page source after the XSLT has transformed this page's XML. This would be
  * exactly the same as the 'view-source' from your browser
  */
 public function generate($page)
 {
     $full_generate = true;
     $devkit = null;
     $output = null;
     if ($this->is_logged_in) {
         /**
          * Allows a devkit object to be specified, and stop continued execution:
          *
          * @delegate FrontendDevKitResolve
          * @param string $context
          * '/frontend/'
          * @param boolean $full_generate
          *  Whether this page will be completely generated (ie. invoke the XSLT transform)
          *  or not, by default this is true. Passed by reference
          * @param mixed $devkit
          *  Allows a devkit to register to this page
          */
         Symphony::ExtensionManager()->notifyMembers('FrontendDevKitResolve', '/frontend/', array('full_generate' => &$full_generate, 'devkit' => &$devkit));
     }
     Symphony::Profiler()->sample('Page creation process started');
     $this->_page = $page;
     $this->__buildPage();
     if ($full_generate) {
         /**
          * Immediately before generating the page. Provided with the page object, XML and XSLT
          * @delegate FrontendOutputPreGenerate
          * @param string $context
          * '/frontend/'
          * @param FrontendPage $page
          *  This FrontendPage object, by reference
          * @param string $xml
          *  This pages XML, including the Parameters, Datasource and Event XML, by reference
          * @param string $xsl
          *  This pages XSLT
          */
         Symphony::ExtensionManager()->notifyMembers('FrontendOutputPreGenerate', '/frontend/', array('page' => &$this, 'xml' => &$this->_xml, 'xsl' => $this->_xsl));
         if (is_null($devkit)) {
             if (General::in_iarray('XML', $this->_pageData['type'])) {
                 $this->addHeaderToPage('Content-Type', 'text/xml; charset=utf-8');
             } else {
                 if (General::in_iarray('JSON', $this->_pageData['type'])) {
                     $this->addHeaderToPage('Content-Type', 'application/json; charset=utf-8');
                 } else {
                     $this->addHeaderToPage('Content-Type', 'text/html; charset=utf-8');
                 }
             }
             if (in_array('404', $this->_pageData['type'])) {
                 $this->addHeaderToPage('Status', '404 Not Found', 404);
             } elseif (in_array('403', $this->_pageData['type'])) {
                 $this->addHeaderToPage('Status', '403 Forbidden', 403);
             }
         }
         /**
          * This is just prior to the page headers being rendered, and is suitable for changing them
          * @delegate FrontendPreRenderHeaders
          * @param string $context
          * '/frontend/'
          */
         Symphony::ExtensionManager()->notifyMembers('FrontendPreRenderHeaders', '/frontend/');
         $output = parent::generate();
         /**
          * Immediately after generating the page. Provided with string containing page source
          * @delegate FrontendOutputPostGenerate
          * @param string $context
          * '/frontend/'
          * @param string $output
          *  The generated output of this page, ie. a string of HTML, passed by reference
          */
         Symphony::ExtensionManager()->notifyMembers('FrontendOutputPostGenerate', '/frontend/', array('output' => &$output));
         Symphony::Profiler()->sample('XSLT Transformation', PROFILE_LAP);
         if (is_null($devkit) && !$output) {
             $errstr = NULL;
             while (list($key, $val) = $this->Proc->getError()) {
                 $errstr .= 'Line: ' . $val['line'] . ' - ' . $val['message'] . PHP_EOL;
             }
             GenericExceptionHandler::$enabled = true;
             throw new SymphonyErrorPage(trim($errstr), NULL, 'xslt', array('proc' => clone $this->Proc));
         }
         Symphony::Profiler()->sample('Page creation complete');
     }
     if (!is_null($devkit)) {
         $devkit->prepare($this, $this->_pageData, $this->_xml, $this->_param, $output);
         return $devkit->build();
     }
     // Display the Event Results in the page source if the user is logged
     // into Symphony, the page is not JSON and if it is enabled in the
     // configuration.
     if ($this->is_logged_in && !General::in_iarray('JSON', $this->_pageData['type']) && Symphony::Configuration()->get('display_event_xml_in_source', 'public') == 'yes') {
         $output .= PHP_EOL . '<!-- ' . PHP_EOL . $this->_events_xml->generate(true) . ' -->';
     }
     return $output;
 }
Пример #3
0
 /**
  * This function is called immediately from the Frontend class passing the current
  * URL for generation. Generate will resolve the URL to the specific page in the Symphony
  * and then execute all events and datasources registered to this page so that it can
  * be rendered. A number of delegates are fired during stages of execution for extensions
  * to hook into.
  *
  * @uses FrontendDevKitResolve
  * @uses FrontendOutputPreGenerate
  * @uses FrontendPreRenderHeaders
  * @uses FrontendOutputPostGenerate
  * @see __buildPage()
  * @param string $page
  * The URL of the current page that is being Rendered as returned by getCurrentPage
  * @return string
  * The page source after the XSLT has transformed this page's XML. This would be
  * exactly the same as the 'view-source' from your browser
  */
 public function generate($page = null)
 {
     $full_generate = true;
     $devkit = null;
     $output = null;
     $this->addHeaderToPage('Cache-Control', 'no-cache, must-revalidate, max-age=0');
     $this->addHeaderToPage('Expires', 'Mon, 12 Dec 1982 06:14:00 GMT');
     $this->addHeaderToPage('Last-Modified', gmdate('D, d M Y H:i:s') . ' GMT');
     $this->addHeaderToPage('Pragma', 'no-cache');
     if ($this->is_logged_in) {
         /**
          * Allows a devkit object to be specified, and stop continued execution:
          *
          * @delegate FrontendDevKitResolve
          * @param string $context
          * '/frontend/'
          * @param boolean $full_generate
          *  Whether this page will be completely generated (ie. invoke the XSLT transform)
          *  or not, by default this is true. Passed by reference
          * @param mixed $devkit
          *  Allows a devkit to register to this page
          */
         Symphony::ExtensionManager()->notifyMembers('FrontendDevKitResolve', '/frontend/', array('full_generate' => &$full_generate, 'devkit' => &$devkit));
     }
     Symphony::Profiler()->sample('Page creation process started');
     $this->_page = $page;
     $this->__buildPage();
     if ($full_generate) {
         /**
          * Immediately before generating the page. Provided with the page object, XML and XSLT
          * @delegate FrontendOutputPreGenerate
          * @param string $context
          * '/frontend/'
          * @param FrontendPage $page
          *  This FrontendPage object, by reference
          * @param string $xml
          *  This pages XML, including the Parameters, Datasource and Event XML, by reference
          * @param string $xsl
          *  This pages XSLT, by reference
          */
         Symphony::ExtensionManager()->notifyMembers('FrontendOutputPreGenerate', '/frontend/', array('page' => &$this, 'xml' => &$this->_xml, 'xsl' => &$this->_xsl));
         if (is_null($devkit)) {
             if (General::in_iarray('XML', $this->_pageData['type'])) {
                 $this->addHeaderToPage('Content-Type', 'text/xml; charset=utf-8');
             } else {
                 if (General::in_iarray('JSON', $this->_pageData['type'])) {
                     $this->addHeaderToPage('Content-Type', 'application/json; charset=utf-8');
                 } else {
                     $this->addHeaderToPage('Content-Type', 'text/html; charset=utf-8');
                 }
             }
             if (in_array('404', $this->_pageData['type'])) {
                 $this->setHttpStatus(self::HTTP_STATUS_NOT_FOUND);
             } else {
                 if (in_array('403', $this->_pageData['type'])) {
                     $this->setHttpStatus(self::HTTP_STATUS_FORBIDDEN);
                 }
             }
         }
         /**
          * This is just prior to the page headers being rendered, and is suitable for changing them
          * @delegate FrontendPreRenderHeaders
          * @param string $context
          * '/frontend/'
          */
         Symphony::ExtensionManager()->notifyMembers('FrontendPreRenderHeaders', '/frontend/');
         $backup_param = $this->_param;
         $this->_param['current-query-string'] = General::wrapInCDATA($this->_param['current-query-string']);
         $output = parent::generate();
         $this->_param = $backup_param;
         /**
          * Immediately after generating the page. Provided with string containing page source
          * @delegate FrontendOutputPostGenerate
          * @param string $context
          * '/frontend/'
          * @param string $output
          *  The generated output of this page, ie. a string of HTML, passed by reference
          */
         Symphony::ExtensionManager()->notifyMembers('FrontendOutputPostGenerate', '/frontend/', array('output' => &$output));
         Symphony::Profiler()->sample('XSLT Transformation', PROFILE_LAP);
         if (is_null($devkit) && !$output) {
             $errstr = NULL;
             while (list($key, $val) = $this->Proc->getError()) {
                 $errstr .= 'Line: ' . $val['line'] . ' - ' . $val['message'] . PHP_EOL;
             }
             Frontend::instance()->throwCustomError(trim($errstr), __('XSLT Processing Error'), Page::HTTP_STATUS_ERROR, 'xslt', array('proc' => clone $this->Proc));
         }
         Symphony::Profiler()->sample('Page creation complete');
     }
     if (!is_null($devkit)) {
         $devkit->prepare($this, $this->_pageData, $this->_xml, $this->_param, $output);
         return $devkit->build();
     }
     // Display the Event Results in the page source if the user is logged
     // into Symphony, the page is not JSON and if it is enabled in the
     // configuration.
     if ($this->is_logged_in && !General::in_iarray('JSON', $this->_pageData['type']) && Symphony::Configuration()->get('display_event_xml_in_source', 'public') == 'yes') {
         $output .= PHP_EOL . '<!-- ' . PHP_EOL . $this->_events_xml->generate(true) . ' -->';
     }
     return $output;
 }
Пример #4
0
 public static function getMetaInfo($file, $type)
 {
     $imageMimeTypes = array('image/gif', 'image/jpg', 'image/jpeg', 'image/png');
     $meta = array();
     $meta['creation'] = DateTimeObj::get('c', filemtime($file));
     if (General::in_iarray($type, $imageMimeTypes) && ($array = @getimagesize($file))) {
         $meta['width'] = $array[0];
         $meta['height'] = $array[1];
     }
     return $meta;
 }
 private static function __sniffMIMEType($file)
 {
     $ext = strtolower(General::getExtension($file));
     $imageMimeTypes = array('image/gif', 'image/jpg', 'image/jpeg', 'image/png');
     if (General::in_iarray("image/{$ext}", $imageMimeTypes)) {
         return "image/{$ext}";
     }
     return 'unknown';
 }
Пример #6
0
 protected static function isSvg($type)
 {
     return General::in_iarray($type, self::$svgMimeTypes);
 }