Exemplo n.º 1
0
 public static function processArg()
 {
     $sws = array('-v' => false, '-h' => false, '-ini' => false, '-D' => 2);
     $params = array('ini' => false);
     list($switches, $parameters) = \Jelix\BuildTools\Cli\Params::getOptionsAndParams($_SERVER['argv'], $sws, $params);
     if (isset($parameters['ini'])) {
         Environment::addIni($parameters['ini']);
     }
     if (isset($switches['-D'])) {
         foreach ($switches['-D'] as $var) {
             if (preg_match("/^(\\w+)=(.*)\$/", $var, $m)) {
                 Environment::set($m[1], $m[2]);
             } else {
                 throw new Exception('bad syntax for -D option  :' . $var . "\n");
             }
         }
     }
     if (isset($switches['-v'])) {
         Environment::set('VERBOSE_MODE', true);
     }
     if (isset($switches['-h'])) {
         echo Environment::help();
         exit(0);
     }
     if (isset($switches['-ini'])) {
         echo Environment::getIniContent();
         exit(0);
     }
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  *
  * @throws \Icicle\File\Exception\FileException
  * @throws \Icicle\Exception\InvalidArgumentError
  */
 public function run(Environment $environment)
 {
     if ('f' === $this->operation[0]) {
         if ('fopen' === $this->operation) {
             $file = new File($this->args[0], $this->args[1]);
             $id = $file->getId();
             $environment->set($this->makeId($id), $file);
             return [$id, $file->stat()['size'], $file->inAppendMode()];
         }
         if (null === $this->id) {
             throw new FileException('No file ID provided.');
         }
         if (!$environment->exists($this->id)) {
             throw new FileException('No file handle with the given ID has been opened on the worker.');
         }
         if (!($file = $environment->get($this->id)) instanceof File) {
             throw new FileException('File storage found in inconsistent state.');
         }
         switch ($this->operation) {
             case 'fread':
             case 'fwrite':
             case 'fseek':
             case 'fstat':
             case 'ftruncate':
                 return [$file, substr($this->operation, 1)](...$this->args);
             case 'fclose':
                 $environment->delete($this->id);
                 return true;
             default:
                 throw new InvalidArgumentError('Invalid operation.');
         }
     }
     switch ($this->operation) {
         case 'stat':
         case 'unlink':
         case 'rename':
         case 'copy':
         case 'link':
         case 'symlink':
         case 'readlink':
         case 'isfile':
         case 'isdir':
         case 'mkdir':
         case 'lsdir':
         case 'rmdir':
         case 'chmod':
         case 'chown':
         case 'chgrp':
             return [$this, $this->operation](...$this->args);
         default:
             throw new InvalidArgumentError('Invalid operation.');
     }
 }
Exemplo n.º 3
0
 public function testWriteAndRead()
 {
     Environment::write('title', 'this is development', 'development');
     $this->assertEquals(Environment::read('title', 'development'), 'this is development');
     Environment::write('title', 'this is production', 'production');
     $this->assertEquals(Environment::read('title', 'production'), 'this is production');
     Environment::set('development');
     $this->assertEquals(Environment::read('title'), 'this is development');
     Environment::set('production');
     $this->assertEquals(Environment::read('title'), 'this is production');
     Environment::write(array('hello' => 'Hello World', 'bye' => 'Bye bye'), 'development');
     $this->assertEquals(Environment::read('bye', 'development'), 'Bye bye');
     Environment::write(array('debug' => 3, 'App.encoding' => 'UTF-8', 'Security.salt' => 'hjkh34k5j3kKjg23kH23452873fd9sdfsd9f8shd90f'), 'development');
     Environment::write(array('debug' => 0, 'App.encoding' => 'UTF-8', 'Security.salt' => '67783jd9HKkjkhhkferwQhhPbkjb987987bJKhjvdskhJK'), 'production');
     Environment::set('development');
     $this->assertEquals(Configure::read('Security.salt'), 'hjkh34k5j3kKjg23kH23452873fd9sdfsd9f8shd90f');
     Environment::set('production');
     $this->assertEquals(Configure::read('Security.salt'), '67783jd9HKkjkhhkferwQhhPbkjb987987bJKhjvdskhJK');
 }
Exemplo n.º 4
0
 /**
  * Generate an XML files and save them to the root directory
  *
  * @param array $arrFeed
  */
 protected function generateFiles($arrFeed)
 {
     $arrArchives = deserialize($arrFeed['archives']);
     if (!is_array($arrArchives) || empty($arrArchives)) {
         return;
     }
     $strType = $arrFeed['format'] == 'atom' ? 'generateAtom' : 'generateRss';
     $strLink = $arrFeed['feedBase'] ?: \Environment::get('base');
     $strFile = $arrFeed['feedName'];
     $objFeed = new \Feed($strFile);
     $objFeed->link = $strLink;
     $objFeed->title = $arrFeed['title'];
     $objFeed->description = $arrFeed['description'];
     $objFeed->language = $arrFeed['language'];
     $objFeed->published = $arrFeed['tstamp'];
     // Get the items
     if ($arrFeed['maxItems'] > 0) {
         $objArticle = \NewsModel::findPublishedByPids($arrArchives, null, $arrFeed['maxItems']);
     } else {
         $objArticle = \NewsModel::findPublishedByPids($arrArchives);
     }
     // Parse the items
     if ($objArticle !== null) {
         $arrUrls = array();
         while ($objArticle->next()) {
             /** @var \PageModel $objPage */
             $objPage = $objArticle->getRelated('pid');
             $jumpTo = $objPage->jumpTo;
             // No jumpTo page set (see #4784)
             if (!$jumpTo) {
                 continue;
             }
             // Get the jumpTo URL
             if (!isset($arrUrls[$jumpTo])) {
                 $objParent = \PageModel::findWithDetails($jumpTo);
                 // A jumpTo page is set but does no longer exist (see #5781)
                 if ($objParent === null) {
                     $arrUrls[$jumpTo] = false;
                 } else {
                     $arrUrls[$jumpTo] = $objParent->getFrontendUrl(\Config::get('useAutoItem') && !\Config::get('disableAlias') ? '/%s' : '/items/%s');
                 }
             }
             // Skip the event if it requires a jumpTo URL but there is none
             if ($arrUrls[$jumpTo] === false && $objArticle->source == 'default') {
                 continue;
             }
             $strUrl = $arrUrls[$jumpTo];
             $objItem = new \FeedItem();
             $objItem->title = $objArticle->headline;
             $objItem->link = $this->getLink($objArticle, $strUrl, $strLink);
             $objItem->published = $objArticle->date;
             $objItem->author = $objArticle->authorName;
             // Prepare the description
             if ($arrFeed['source'] == 'source_text') {
                 $strDescription = '';
                 $objElement = \ContentModel::findPublishedByPidAndTable($objArticle->id, 'tl_news');
                 if ($objElement !== null) {
                     // Overwrite the request (see #7756)
                     $strRequest = \Environment::get('request');
                     \Environment::set('request', $objItem->link);
                     while ($objElement->next()) {
                         $strDescription .= $this->getContentElement($objElement->current());
                     }
                     \Environment::set('request', $strRequest);
                 }
             } else {
                 $strDescription = $objArticle->teaser;
             }
             $strDescription = $this->replaceInsertTags($strDescription, false);
             $objItem->description = $this->convertRelativeUrls($strDescription, $strLink);
             // Add the article image as enclosure
             if ($objArticle->addImage) {
                 $objFile = \FilesModel::findByUuid($objArticle->singleSRC);
                 if ($objFile !== null) {
                     $objItem->addEnclosure($objFile->path, $strLink);
                 }
             }
             // Enclosures
             if ($objArticle->addEnclosure) {
                 $arrEnclosure = deserialize($objArticle->enclosure, true);
                 if (is_array($arrEnclosure)) {
                     $objFile = \FilesModel::findMultipleByUuids($arrEnclosure);
                     if ($objFile !== null) {
                         while ($objFile->next()) {
                             $objItem->addEnclosure($objFile->path, $strLink);
                         }
                     }
                 }
             }
             $objFeed->addItem($objItem);
         }
     }
     // Create the file
     \File::putContent('share/' . $strFile . '.xml', $this->replaceInsertTags($objFeed->{$strType}(), false));
 }
Exemplo n.º 5
0
 /**
  * Generate an XML files and save them to the root directory
  * @param array
  */
 protected function generateFiles($arrFeed)
 {
     $arrArchives = deserialize($arrFeed['archives']);
     if (!is_array($arrArchives) || empty($arrArchives)) {
         return;
     }
     $strType = $arrFeed['format'] == 'atom' ? 'generateAtom' : 'generateRss';
     $strLink = $arrFeed['feedBase'] ?: \Environment::get('base');
     $strFile = $arrFeed['feedName'];
     $objFeed = new \Feed($strFile);
     $objFeed->link = $strLink;
     $objFeed->title = $arrFeed['title'];
     $objFeed->description = $arrFeed['description'];
     $objFeed->language = $arrFeed['language'];
     $objFeed->published = $arrFeed['tstamp'];
     $arrCategories = deserialize($arrFeed['categories']);
     // Filter by categories
     if (is_array($arrCategories) && !empty($arrCategories)) {
         $GLOBALS['NEWS_FILTER_CATEGORIES'] = true;
         $GLOBALS['NEWS_FILTER_DEFAULT'] = $arrCategories;
     } else {
         $GLOBALS['NEWS_FILTER_CATEGORIES'] = false;
     }
     // Get the items
     if ($arrFeed['maxItems'] > 0) {
         $objArticle = \NewsModel::findPublishedByPids($arrArchives, null, $arrFeed['maxItems']);
     } else {
         $objArticle = \NewsModel::findPublishedByPids($arrArchives);
     }
     // Parse the items
     if ($objArticle !== null) {
         $arrUrls = array();
         while ($objArticle->next()) {
             $jumpTo = $objArticle->getRelated('pid')->jumpTo;
             // No jumpTo page set (see #4784)
             if (!$jumpTo) {
                 continue;
             }
             // Get the jumpTo URL
             if (!isset($arrUrls[$jumpTo])) {
                 $objParent = \PageModel::findWithDetails($jumpTo);
                 // A jumpTo page is set but does no longer exist (see #5781)
                 if ($objParent === null) {
                     $arrUrls[$jumpTo] = false;
                 } else {
                     $arrUrls[$jumpTo] = $objParent->getAbsoluteUrl(\Config::get('useAutoItem') && !\Config::get('disableAlias') ? '/%s' : '/items/%s');
                 }
             }
             // Skip the event if it requires a jumpTo URL but there is none
             if ($arrUrls[$jumpTo] === false && $objArticle->source == 'default') {
                 continue;
             }
             // Get the categories
             if ($arrFeed['categories_show']) {
                 $arrCategories = array();
                 if (($objCategories = NewsCategoryModel::findPublishedByIds(deserialize($objArticle->categories, true))) !== null) {
                     $arrCategories = $objCategories->fetchEach('title');
                 }
             }
             $strUrl = $arrUrls[$jumpTo];
             $objItem = new \FeedItem();
             // Add the categories to the title
             if ($arrFeed['categories_show'] == 'title') {
                 $objItem->title = sprintf('[%s] %s', implode(', ', $arrCategories), $objArticle->headline);
             } else {
                 $objItem->title = $objArticle->headline;
             }
             $objItem->link = $this->getLink($objArticle, $strUrl);
             $objItem->published = $objArticle->date;
             $objItem->author = $objArticle->authorName;
             // Prepare the description
             if ($arrFeed['source'] == 'source_text') {
                 $strDescription = '';
                 $objElement = \ContentModel::findPublishedByPidAndTable($objArticle->id, 'tl_news');
                 if ($objElement !== null) {
                     // Overwrite the request (see #7756)
                     $strRequest = \Environment::get('request');
                     \Environment::set('request', $objItem->link);
                     while ($objElement->next()) {
                         $strDescription .= $this->getContentElement($objElement->current());
                     }
                     \Environment::set('request', $strRequest);
                 }
             } else {
                 $strDescription = $objArticle->teaser;
             }
             // Add the categories to the description
             if ($arrFeed['categories_show'] == 'text_before' || $arrFeed['categories_show'] == 'text_after') {
                 $strCategories = '<p>' . $GLOBALS['TL_LANG']['MSC']['newsCategories'] . ' ' . implode(', ', $arrCategories) . '</p>';
                 if ($arrFeed['categories_show'] == 'text_before') {
                     $strDescription = $strCategories . $strDescription;
                 } else {
                     $strDescription .= $strCategories;
                 }
             }
             $strDescription = $this->replaceInsertTags($strDescription, false);
             $objItem->description = $this->convertRelativeUrls($strDescription, $strLink);
             // Add the article image as enclosure
             if ($objArticle->addImage) {
                 $objFile = \FilesModel::findByUuid($objArticle->singleSRC);
                 if ($objFile !== null) {
                     $objItem->addEnclosure($objFile->path, $strLink);
                 }
             }
             // Enclosures
             if ($objArticle->addEnclosure) {
                 $arrEnclosure = deserialize($objArticle->enclosure, true);
                 if (is_array($arrEnclosure)) {
                     $objFile = \FilesModel::findMultipleByUuids($arrEnclosure);
                     if ($objFile !== null) {
                         while ($objFile->next()) {
                             $objItem->addEnclosure($objFile->path, $strLink);
                         }
                     }
                 }
             }
             $objFeed->addItem($objItem);
         }
     }
     // Create the file
     \File::putContent('share/' . $strFile . '.xml', $this->replaceInsertTags($objFeed->{$strType}(), false));
 }
Exemplo n.º 6
0
<?php

Environment::set('database', ['default' => ['type' => 'mysql', 'host' => 'localhost', 'user' => 'root', 'pass' => 'root', 'name' => 'test']]);
Exemplo n.º 7
0
 /**
  * Generate an XML file and save it to the root directory
  *
  * @param array $arrFeed
  */
 protected function generateFiles($arrFeed)
 {
     $arrCalendars = deserialize($arrFeed['calendars']);
     if (!is_array($arrCalendars) || empty($arrCalendars)) {
         return;
     }
     $strType = $arrFeed['format'] == 'atom' ? 'generateAtom' : 'generateRss';
     $strLink = $arrFeed['feedBase'] ?: \Environment::get('base');
     $strFile = $arrFeed['feedName'];
     $objFeed = new \Feed($strFile);
     $objFeed->link = $strLink;
     $objFeed->title = $arrFeed['title'];
     $objFeed->description = $arrFeed['description'];
     $objFeed->language = $arrFeed['language'];
     $objFeed->published = $arrFeed['tstamp'];
     $arrUrls = array();
     $this->arrEvents = array();
     $time = time();
     // Get the upcoming events
     $objArticle = \CalendarEventsModel::findUpcomingByPids($arrCalendars, $arrFeed['maxItems']);
     // Parse the items
     if ($objArticle !== null) {
         while ($objArticle->next()) {
             $jumpTo = $objArticle->getRelated('pid')->jumpTo;
             // No jumpTo page set (see #4784)
             if (!$jumpTo) {
                 continue;
             }
             // Get the jumpTo URL
             if (!isset($arrUrls[$jumpTo])) {
                 $objParent = \PageModel::findWithDetails($jumpTo);
                 // A jumpTo page is set but does no longer exist (see #5781)
                 if ($objParent === null) {
                     $arrUrls[$jumpTo] = false;
                 } else {
                     $arrUrls[$jumpTo] = $this->generateFrontendUrl($objParent->row(), \Config::get('useAutoItem') && !\Config::get('disableAlias') ? '/%s' : '/events/%s', $objParent->language);
                 }
             }
             // Skip the event if it requires a jumpTo URL but there is none
             if ($arrUrls[$jumpTo] === false && $objArticle->source == 'default') {
                 continue;
             }
             $strUrl = $arrUrls[$jumpTo];
             $this->addEvent($objArticle, $objArticle->startTime, $objArticle->endTime, $strUrl, $strLink);
             // Recurring events
             if ($objArticle->recurring) {
                 $arrRepeat = deserialize($objArticle->repeatEach);
                 if ($arrRepeat['value'] < 1) {
                     continue;
                 }
                 $count = 0;
                 $intStartTime = $objArticle->startTime;
                 $intEndTime = $objArticle->endTime;
                 $strtotime = '+ ' . $arrRepeat['value'] . ' ' . $arrRepeat['unit'];
                 // Do not include more than 20 recurrences
                 while ($count++ < 20) {
                     if ($objArticle->recurrences > 0 && $count >= $objArticle->recurrences) {
                         break;
                     }
                     $intStartTime = strtotime($strtotime, $intStartTime);
                     $intEndTime = strtotime($strtotime, $intEndTime);
                     if ($intStartTime >= $time) {
                         $this->addEvent($objArticle, $intStartTime, $intEndTime, $strUrl, $strLink);
                     }
                 }
             }
         }
     }
     $count = 0;
     ksort($this->arrEvents);
     // Add the feed items
     foreach ($this->arrEvents as $days) {
         foreach ($days as $events) {
             foreach ($events as $event) {
                 if ($arrFeed['maxItems'] > 0 && $count++ >= $arrFeed['maxItems']) {
                     break 3;
                 }
                 $objItem = new \FeedItem();
                 $objItem->title = $event['title'];
                 $objItem->link = $event['link'];
                 $objItem->published = $event['tstamp'];
                 $objItem->begin = $event['begin'];
                 $objItem->end = $event['end'];
                 $objItem->author = $event['authorName'];
                 // Prepare the description
                 if ($arrFeed['source'] == 'source_text') {
                     $strDescription = '';
                     $objElement = \ContentModel::findPublishedByPidAndTable($event['id'], 'tl_calendar_events');
                     if ($objElement !== null) {
                         // Overwrite the request (see #7756)
                         $strRequest = \Environment::get('request');
                         \Environment::set('request', $objItem->link);
                         while ($objElement->next()) {
                             $strDescription .= $this->getContentElement($objElement->current());
                         }
                         \Environment::set('request', $strRequest);
                     }
                 } else {
                     $strDescription = $event['teaser'];
                 }
                 $strDescription = $this->replaceInsertTags($strDescription, false);
                 $objItem->description = $this->convertRelativeUrls($strDescription, $strLink);
                 if (is_array($event['enclosure'])) {
                     foreach ($event['enclosure'] as $enclosure) {
                         $objItem->addEnclosure($enclosure);
                     }
                 }
                 $objFeed->addItem($objItem);
             }
         }
     }
     // Create the file
     \File::putContent('share/' . $strFile . '.xml', $this->replaceInsertTags($objFeed->{$strType}(), false));
 }
Exemplo n.º 8
0
 /**
  * @expectedException \RuntimeException
  * @expectedExceptionMessage The parameter `not_protected` could not be set, because a protected parameter named `not_protected.protected` already exists.
  */
 public function testContainingProtectedParam()
 {
     $env = new Environment();
     $env->set('not_protected', []);
     $env->setAsProtected('not_protected.protected', 'value');
     // Ok
     $env->setAsProtected('protected', 'value');
     $env->setAsProtected('not', 'value');
     // Since `not_protected.protected` is a protected parameter, overwriting
     // the whole `not_protected` parameter is not allowed.
     $env->setAsProtected('not_protected', 'value');
 }
Exemplo n.º 9
0
<?php

// WebSeed Release
Environment::define('WebSeed.version', 1);
// Security string
Environment::define('WebSeed.session_string', 'webseed_security');
// Application
Environment::set('Application.controllers', __DIR__ . '/../app/controllers');
Environment::set('Application.models', __DIR__ . '/../app/models');
Environment::set('Application.views', __DIR__ . '/../app/views');
Environment::set('Application.database', 'default');
 /**
  * loadDataContainer hook
  *
  * - Saves the referrer in the session if it is a frontend URL
  * - Preselects the original template in the template editor
  *
  * @param  string $table The data container table name
  * @return void
  */
 public function loadDataContainerHook($table)
 {
     if (TL_MODE !== 'BE') {
         return;
     }
     if (defined('TL_REFERER_ID') && \Input::get('ref')) {
         $referrerSession = \Session::getInstance()->get('referer');
         if (!empty($referrerSession[\Input::get('ref')]['current'])) {
             $referrerSession[\Input::get('ref')]['current'] = preg_replace('(([&?])rsfhr=1(&|$))', '$1', $referrerSession[\Input::get('ref')]['current']);
             \Session::getInstance()->set('referer', $referrerSession);
         }
     }
     // Only handle requests from the frontend helper
     if (!\Input::get('rsfhr')) {
         return;
     }
     if ($table === 'tl_templates' && \Input::get('key') === 'new_tpl') {
         if (\Input::get('original') && !\Input::post('original')) {
             // Preselect the original template
             \Input::setPost('original', \Input::get('original'));
         }
         if (\Input::get('target') && !\Input::post('target')) {
             // Preselect the target template folder
             \Input::setPost('target', \Input::get('target'));
         }
     }
     $base = \Environment::get('path');
     if (version_compare(VERSION, '4.0', '>=')) {
         $base .= \System::getContainer()->get('router')->generate('contao_backend');
     } else {
         $base .= '/contao';
     }
     $referrer = parse_url(\Environment::get('httpReferer'));
     $referrer = $referrer['path'] . ($referrer['query'] ? '?' . $referrer['query'] : '');
     // Stop if the referrer is a backend URL
     if (substr($referrer, 0, strlen($base)) === $base && in_array(substr($referrer, strlen($base), 1), array(false, '/', '?'), true)) {
         return;
     }
     // Fix empty referrers
     if (empty($referrer)) {
         $referrer = '/';
     }
     // Make homepage possible as referrer
     if ($referrer === \Environment::get('path') . '/') {
         $referrer .= '?';
     }
     $assetsDir = version_compare(VERSION, '4.0', '>=') ? 'bundles/rocksolidfrontendhelper' : 'system/modules/rocksolid-frontend-helper/assets';
     $referrer = \Environment::get('path') . '/' . $assetsDir . '/html/referrer.html?referrer=' . rawurlencode($referrer);
     // set the frontend URL as referrer
     $referrerSession = \Session::getInstance()->get('referer');
     if (defined('TL_REFERER_ID') && !\Input::get('ref')) {
         $referrer = substr($referrer, strlen(TL_PATH) + 1);
         $tlRefererId = substr(md5(TL_START - 1), 0, 8);
         $referrerSession[$tlRefererId]['current'] = $referrer;
         \Input::setGet('ref', $tlRefererId);
         $requestUri = \Environment::get('requestUri');
         $requestUri .= (strpos($requestUri, '?') === false ? '?' : '&') . 'ref=' . $tlRefererId;
         \Environment::set('requestUri', $requestUri);
         if (version_compare(VERSION, '4.0', '>=')) {
             \System::getContainer()->get('request_stack')->getCurrentRequest()->query->set('ref', $tlRefererId);
         }
     } else {
         if (!defined('TL_REFERER_ID')) {
             $referrerSession['current'] = $referrer;
         }
     }
     \Session::getInstance()->set('referer', $referrerSession);
 }