Example #1
0
 /**
  * Generates the SWF file
  */
 public function swf()
 {
     $swfFile = new \System\IO\File(PATH_MODULES . self::SWF_FILE);
     $renderer = new \System\Output\Renderer\DataRenderer();
     $renderer->render($swfFile->getContents());
     $surface = \System\Output\RenderSurface::getSurface('\\System\\Output\\BufferSurface');
     $surface->addHeader('Content-Type: application/x-shockwave-flash');
     $surface->setRenderer($renderer);
     $this->setRenderSurface($surface);
 }
Example #2
0
 /**
  * Adds a JS file to be loaded upon clientside rendering. Leave the localpath empty for remote files
  * @param \SimpleXMLElement The XML root
  * @param string The (full)path to the local JS file
  * @param string The (full)path to the remote file
  * @param int The \System\Web\BasePage\Page\InclusionLocation for inclusion location
  */
 public function addJSFile(\SimpleXMLElement $xml, $localFile, $remoteFile, $location = \System\Web\BasePage\Page\InclusionLocation::LOCATION_HEAD)
 {
     if (!isset($xml->jsfiles)) {
         $xml->addChild('jsfiles');
     }
     $jsFiles = $xml->jsfiles;
     $jsFile = $jsFiles->addChild('jsfile');
     if ($localFile) {
         $file = new \System\IO\File($localFile);
         if (MINIFY_ENABLE && mb_strpos($file->getFilename(), self::JS_MIN_EXTENSION) === false && mb_strpos($file->getFilename(), self::JS_MIN_PACKED) === false) {
             $localMinFile = $file->getPath() . basename($file->getFilename(), self::JS_EXTENSION) . self::JS_MIN_EXTENSION;
             if (!file_exists($localMinFile)) {
                 $file = \System\IO\File::writeContents($localMinFile, \System\Web\Minify\JS\Minify::minify($file->getContents()));
             } else {
                 $file = new \System\IO\File($localMinFile);
             }
             $remoteFile = str_ireplace(self::JS_EXTENSION, self::JS_MIN_EXTENSION, $remoteFile);
         }
         $jsFile->addChild('filesize', $file->getFileSizeInBytes());
     }
     $jsFile->addChild('name', $remoteFile);
     $jsFile->addChild('location', $location);
 }
Example #3
0
 /**
  * Loads the XML file from disk and parses it to an XML structure. This structure is then returned.
  * This function is used internally to parse the given DynamicBaseObj XML descriptors and should not
  * be called directly, as it serves no further purpose.
  * @param string The XML file to load
  * @return \SimpleXMLElement The XML tree
  */
 public static final function parseXml($xmlFile)
 {
     try {
         if (!($xml = \simplexml_load_file($xmlFile))) {
             throw new \Exception('XML file does not exist, or could not be loaded: ' . $xmlFile);
         } else {
             /*
             check for xml inheritance. we currently support adding of parent fields, conditions and virtuals only
             we apply this recursively, to allow inheritance trees
             */
             if (isset($xml['extends'])) {
                 $fileName = (string) $xml['extends'];
                 $currentFilePath = new \System\IO\File($xmlFile);
                 $parentFile = $currentFilePath->getPath() . $fileName;
                 $parentXml = self::parseXml($parentFile);
                 //we only add some field types in the parent xml to our current loaded xml
                 foreach ($parentXml->children() as $item) {
                     switch ($item->getName()) {
                         case 'fields':
                             foreach ($item->children() as $field) {
                                 $result = $xml->xpath('fields/' . $field->getName());
                                 if (is_array($result) && count($result) == 0) {
                                     if (!isset($xml->fields)) {
                                         $xml->addChild('fields');
                                     }
                                     \System\XML\XML::appendToXML($xml->fields, $field);
                                 }
                             }
                             break;
                         case 'virtuals':
                             foreach ($item->children() as $virtual) {
                                 $result = $xml->xpath('virtuals/' . $virtual->getName());
                                 if (is_array($result) && count($result) == 0) {
                                     if (!isset($xml->virtuals)) {
                                         $xml->addChild('virtuals');
                                     }
                                     \System\XML\XML::appendToXML($xml->virtuals, $virtual);
                                 }
                             }
                             break;
                         case 'conditions':
                             foreach ($item->children() as $condition) {
                                 //conditions follow a different structure and work on the name attribute
                                 $result = $xml->xpath('conditions/condition[@name="' . $condition['name'] . '"]');
                                 if (is_array($result) && count($result) == 0) {
                                     if (!isset($xml->conditions)) {
                                         $xml->addChild('conditions');
                                     }
                                     \System\XML\XML::appendToXML($xml->conditions, $condition);
                                 }
                             }
                             break;
                         default:
                             //we ignore other items
                     }
                 }
             }
             return $xml;
         }
     } catch (Exception $e) {
         throw new \System\Error\Exception\ObjectLoaderSourceException($e->getMessage());
     }
 }
Example #4
0
 /**
  * Gets all the files in the current directory, with exclusion of
  * .svn, .htaccess, .htpasswd etc.
  * Does not iterate to deeper levels.
  * @param \System\Collection\Vector extensions to include in the search.
  * @return \System\Collection\Vector A Vector with File objects.
  */
 public final function getFiles(\System\Collection\Vector $extensions = null)
 {
     $list = new \System\Collection\Vector();
     //list all the files
     $handle = opendir($this->path);
     while (($file = readdir($handle)) !== false) {
         //get the full path
         $filePath = self::getPath($this->path . self::getSeparator() . $file);
         //no current or upper folders should be considered and the target should exist.
         if ($file != '.' && $file != '..' && mb_substr($file, 0, 1) != '.' && file_exists($filePath) && !is_dir($filePath)) {
             $file = new \System\IO\File($filePath);
             if ($extensions != null) {
                 if ($extensions->contains($file->getExtension())) {
                     $list[] = $file;
                 }
             } else {
                 $list[] = $file;
             }
         }
     }
     closedir($handle);
     return $list;
 }
 /**
  * Deletes a file from the filesystem. Listens to EVENT_DELETE_FILE and requires a 'host', 'port', 'username', 'password' and 'file' field.
  * @param OnInteractionEvent The event to listen to
  */
 public static final function deleteFile(\System\System\Interaction\Event\OnInteractionEvent $event)
 {
     $msg = $event->getMessage();
     if ($msg->getType() == \System\System\Interaction\MessageType::TYPE_SYSTEM && $msg->getMessage() == SystemInteractionEventEvent::EVENT_DELETE_FILE) {
         $params = $msg->getParams();
         if (isset($params['file']) && isset($params['host']) && isset($params['username']) && isset($params['password']) && isset($params['port'])) {
             //test if the file exists
             $file = new \System\IO\File($params['file']);
             if (!function_exists('ssh2_connect') || !function_exists('ssh2_auth_password') || !function_exists('ssh2_sftp')) {
                 throw new \System\Error\Exception\SystemException('The required module, SSH2, is not loaded in PHP');
             }
             $connection = ssh2_connect($params['host'], $params['port']);
             if ($connection && ssh2_auth_password($connection, $params['username'], $params['password'])) {
                 $sftp = ssh2_sftp($connection);
                 $result = ssh2_sftp_unlink($sftp, getcwd() . '/' . $params['file']);
                 $response = new \System\System\Interaction\Response($msg, 'File delete ' . $file->getFilename() . ': ' . ($result ? 'success' : 'fail'));
                 $event->addResponse($response);
             }
         }
     }
 }
Example #6
0
 /**
  * Invalidates a static block. This makes sure the block must be regenerated.
  * @param \System\Db\Database The database to use
  * @param string The unique key, given at the creation of the StaticBlock
  */
 public static final function invalidate(\System\Db\Database $db, $key)
 {
     $filename = '';
     if (\System\Cache\LUTCache\LUTCache::retrieve($db, $key, $filename) == \System\Cache\LUTCache\Status::CACHE_HIT) {
         $fullFile = self::getWritablePath($filename) . $filename;
         if (file_exists($fullFile)) {
             $file = new \System\IO\File($fullFile);
             $file->delete();
         }
     }
     \System\Cache\LUTCache\LUTCache::invalidate($db, $key);
 }