/**
  * Create an instance of PHPTAL and initialize it correctly.
  *
  * @return     PHPTAL The PHPTAL instance.
  *
  * @author     David Zülke <*****@*****.**>
  * @since      1.0.2
  */
 protected function createEngineInstance()
 {
     $phptalPhpCodeDestination = AgaviConfig::get('core.cache_dir') . DIRECTORY_SEPARATOR . AgaviPhptalRenderer::COMPILE_DIR . DIRECTORY_SEPARATOR . AgaviPhptalRenderer::COMPILE_SUBDIR . DIRECTORY_SEPARATOR;
     // we keep this for < 1.2
     if (!defined('PHPTAL_PHP_CODE_DESTINATION')) {
         define('PHPTAL_PHP_CODE_DESTINATION', $phptalPhpCodeDestination);
     }
     AgaviToolkit::mkdir($phptalPhpCodeDestination, fileperms(AgaviConfig::get('core.cache_dir')), true);
     if (!class_exists('PHPTAL')) {
         require 'PHPTAL.php';
     }
     $phptal = new PHPTAL();
     if (version_compare(PHPTAL_VERSION, '1.2', 'ge')) {
         $phptal->setPhpCodeDestination($phptalPhpCodeDestination);
     }
     return $phptal;
 }
Ejemplo n.º 2
0
 /**
  * Initialize this Translator.
  *
  * @param      AgaviContext The current application context.
  * @param      array        An associative array of initialization parameters
  *
  * @author     Dominik del Bondio <*****@*****.**>
  * @since      0.11.0
  */
 public function initialize(AgaviContext $context, array $parameters = array())
 {
     parent::initialize($context);
     if (isset($parameters['text_domains']) && is_array($parameters['text_domains'])) {
         foreach ($parameters['text_domains'] as $domain => $path) {
             $this->domainPaths[$domain] = $path;
         }
     }
     if (isset($parameters['text_domain_pattern'])) {
         $this->domainPathPattern = $parameters['text_domain_pattern'];
     }
     if (isset($parameters['store_calls'])) {
         $this->storeTranslationCalls = true;
         $this->translationCallStoreDir = $parameters['store_calls'];
         AgaviToolkit::mkdir($parameters['store_calls'], 0777, true);
     }
 }
Ejemplo n.º 3
0
 /**
  * Create an instance of PHPTAL and initialize it correctly.
  *
  * @return     PHPTAL The PHPTAL instance.
  *
  * @author     David Zülke <*****@*****.**>
  * @since      1.0.2
  */
 protected function createEngineInstance()
 {
     $phptalPhpCodeDestination = AgaviConfig::get('core.cache_dir') . DIRECTORY_SEPARATOR . AgaviPhptalRenderer::COMPILE_DIR . DIRECTORY_SEPARATOR . AgaviPhptalRenderer::COMPILE_SUBDIR . DIRECTORY_SEPARATOR;
     // we keep this for < 1.2
     if (!defined('PHPTAL_PHP_CODE_DESTINATION')) {
         define('PHPTAL_PHP_CODE_DESTINATION', $phptalPhpCodeDestination);
     }
     AgaviToolkit::mkdir($phptalPhpCodeDestination, fileperms(AgaviConfig::get('core.cache_dir')), true);
     if (!class_exists('PHPTAL')) {
         require 'PHPTAL.php';
     }
     $phptal = new PHPTAL();
     if (version_compare(PHPTAL_VERSION, '1.2', 'ge')) {
         $phptal->setPhpCodeDestination($phptalPhpCodeDestination);
     } else {
         trigger_error('Support for PHPTAL versions older than 1.2 is deprecated and will be removed in Agavi 1.2.', E_USER_DEPRECATED);
     }
     if ($this->hasParameter('encoding')) {
         $phptal->setEncoding($this->getParameter('encoding'));
     }
     return $phptal;
 }
Ejemplo n.º 4
0
 /**
  * Grab a cleaned up dwoo instance.
  *
  * @return     Dwoo A Dwoo instance.
  */
 protected function getEngine()
 {
     if ($this->dwoo) {
         return $this->dwoo;
     }
     // this triggers Agavi autoload
     if (!class_exists('Dwoo')) {
         if (file_exists(dirname(__FILE__) . '/../../../dwooAutoload.php')) {
             // file was dropped with the entire dwoo package
             require dirname(__FILE__) . '/../../../dwooAutoload.php';
         } else {
             // assume the dwoo package is in the include path
             require 'dwooAutoload.php';
         }
     }
     $parentMode = fileperms(AgaviConfig::get('core.cache_dir'));
     $compileDir = AgaviConfig::get('core.cache_dir') . DIRECTORY_SEPARATOR . self::COMPILE_DIR . DIRECTORY_SEPARATOR . self::COMPILE_SUBDIR;
     AgaviToolkit::mkdir($compileDir, $parentMode, true);
     $cacheDir = AgaviConfig::get('core.cache_dir') . DIRECTORY_SEPARATOR . self::CACHE_DIR;
     AgaviToolkit::mkdir($cacheDir, $parentMode, true);
     $this->dwoo = new Dwoo_Core($compileDir, $cacheDir);
     if (!empty($this->plugin_dir)) {
         foreach ((array) $this->plugin_dir as $dir) {
             $this->dwoo->getLoader()->addDirectory($dir);
         }
     }
     $this->dwoo->setDefaultCompilerFactory('file', array($this, 'compilerFactory'));
     return $this->dwoo;
 }
 private function getCacheFilename()
 {
     $file = "squish_" . md5($this->route);
     $cached = $this->cache_dir . '/' . $file;
     if (!file_exists($this->cache_dir)) {
         AgaviToolkit::mkdir($this->cache_dir);
     }
     return $cached;
 }
 /**
  * Grab a cleaned up ezctemplate instance.
  *
  * @return     ezcTemplate A ezcTemplate instance.
  *
  * @author     Felix Weis <*****@*****.**>
  * @since      0.11.0
  */
 protected function getEngine()
 {
     // ezcTemplate already initialized, only clear the assigns and retun the engine
     if ($this->ezcTemplate) {
         $this->ezcTemplate->send = new ezcTemplateVariableCollection();
         return $this->ezcTemplate;
     }
     $this->ezcTemplate = $this->createEngineInstance();
     // initialize ezcTemplate
     $parentMode = fileperms(AgaviConfig::get('core.cache_dir'));
     $compileDir = AgaviConfig::get('core.cache_dir') . DIRECTORY_SEPARATOR . self::COMPILE_DIR . DIRECTORY_SEPARATOR . self::COMPILE_SUBDIR;
     AgaviToolkit::mkdir($compileDir, $parentMode, true);
     // templatePath unnessesary because Agavi will always supply the absolute ressource path
     $config = new ezcTemplateConfiguration();
     $config->templatePath = "";
     $config->compilePath = $compileDir;
     // set the ezcTemplateOutputContext (standard is ezcTemplateXhtmlContext)
     if ($this->hasParameter('context')) {
         $contextClass = $this->getParameter('context');
         $config->context = new $contextClass();
     }
     // add some usefull Agavi Functions/Blocks as Extension
     $config->addExtension('AgaviEzctemplateCustomBlocks');
     $config->addExtension('AgaviEzctemplateCustomFunctions');
     foreach ($this->getParameter('extensions', array()) as $extension) {
         $config->addExtension($extension);
     }
     $this->ezcTemplate->configuration = $config;
     return $this->ezcTemplate;
 }
 /**
  * Grab a cleaned up smarty instance.
  *
  * @return     Smarty A Smarty instance.
  *
  * @author     David Zülke <*****@*****.**>
  * @author     TANAKA Koichi <*****@*****.**>
  * @since      0.9.0
  */
 protected function getEngine()
 {
     if ($this->smarty) {
         $this->smarty->clear_all_assign();
         $this->smarty->clear_config();
         return $this->smarty;
     }
     $this->smarty = $this->createEngineInstance();
     $this->smarty->clear_all_assign();
     $this->smarty->clear_config();
     $this->smarty->config_dir = AgaviConfig::get('core.config_dir');
     $parentMode = fileperms(AgaviConfig::get('core.cache_dir'));
     $compileDir = AgaviConfig::get('core.cache_dir') . DIRECTORY_SEPARATOR . self::COMPILE_DIR . DIRECTORY_SEPARATOR . self::COMPILE_SUBDIR;
     AgaviToolkit::mkdir($compileDir, $parentMode, true);
     $this->smarty->compile_dir = $compileDir;
     $cacheDir = AgaviConfig::get('core.cache_dir') . DIRECTORY_SEPARATOR . self::CACHE_DIR;
     AgaviToolkit::mkdir($cacheDir, $parentMode, true);
     $this->smarty->cache_dir = $cacheDir;
     if (AgaviConfig::get('core.debug', false)) {
         $this->smarty->debugging = true;
     }
     foreach ((array) $this->getParameter('smarty_variables') as $key => $value) {
         $this->smarty->{$key} = $value;
     }
     return $this->smarty;
 }
Ejemplo n.º 8
0
 public function testMkdir()
 {
     $this->assertTrue(AgaviToolkit::mkdir('_testing_path'));
     rmdir('_testing_path');
 }
 /**
  * Move the uploaded file.
  *
  * @param      string The destination filename.
  * @param      int    The mode of the destination file, defaults to 0664.
  * @param      bool   Whether or not subdirs should be created if necessary.
  * @param      int    The mode to use when creating subdirs, defaults to 0775.
  *
  * @return     bool True, if the operation was successful, false otherwise.
  *
  * @throws     AgaviFileException If chmod or mkdir calls failed.
  *
  * @author     David Zülke <*****@*****.**>
  * @since      0.11.0
  */
 public function move($dest, $fileMode = 0664, $create = true, $dirMode = 0775)
 {
     if ($this->hasError()) {
         return false;
     } elseif (!$this->isMovable()) {
         return false;
     }
     // get our directory path from the destination filename
     $directory = dirname($dest);
     if (!is_readable($directory)) {
         if ($create && !AgaviToolkit::mkdir($directory, $dirMode, true)) {
             // failed to create the directory
             $error = 'Failed to create file upload directory "%s"';
             $error = sprintf($error, $directory);
             throw new AgaviFileException($error);
         }
     } elseif (!is_dir($directory)) {
         // the directory path exists but it's not a directory
         $error = 'File upload path "%s" exists, but is not a directory';
         $error = sprintf($error, $directory);
         throw new AgaviFileException($error);
     } elseif (!is_writable($directory)) {
         // the directory isn't writable
         $error = 'File upload path "%s" is not writable';
         $error = sprintf($error, $directory);
         throw new AgaviFileException($error);
     }
     if ($this->is_uploaded_file) {
         $moved = @move_uploaded_file($this->tmp_name, $dest);
     } else {
         if (is_writable($dest)) {
             unlink($dest);
         }
         $moved = @rename($this->tmp_name, $dest);
     }
     if ($moved) {
         $this->moved = true;
         // chmod our file
         if (!@chmod($dest, $fileMode)) {
             throw new AgaviFileException('Failed to chmod uploaded file after moving');
         }
     } else {
         // moving the file failed
         throw new AgaviFileException('Failed to move uploaded file');
     }
     return true;
 }
Ejemplo n.º 10
0
 /**
  * Grab a cleaned up smarty instance.
  *
  * @return     Smarty A Smarty instance.
  *
  * @author     David Zülke <*****@*****.**>
  * @author     TANAKA Koichi <*****@*****.**>
  * @since      0.9.0
  */
 protected function getEngine()
 {
     if ($this->smarty) {
         if ($this->isSmarty2) {
             $this->smarty->clear_all_assign();
             $this->smarty->clear_config();
         }
         return $this->smarty;
     }
     $this->smarty = $this->createEngineInstance();
     $this->isSmarty2 = !defined("Smarty::SMARTY_VERSION") || !preg_match('#^Smarty.?3#', Smarty::SMARTY_VERSION, $matches);
     if ($this->isSmarty2) {
         $this->smarty->config_dir = AgaviConfig::get('core.config_dir');
     } else {
         $this->smarty->setConfigDir(AgaviConfig::get('core.config_dir'));
     }
     $parentMode = fileperms(AgaviConfig::get('core.cache_dir'));
     $compileDir = AgaviConfig::get('core.cache_dir') . DIRECTORY_SEPARATOR . self::COMPILE_DIR . DIRECTORY_SEPARATOR . self::COMPILE_SUBDIR;
     AgaviToolkit::mkdir($compileDir, $parentMode, true);
     if ($this->isSmarty2) {
         $this->smarty->compile_dir = $compileDir;
     } else {
         $this->smarty->setCompileDir($compileDir);
     }
     $cacheDir = AgaviConfig::get('core.cache_dir') . DIRECTORY_SEPARATOR . self::CACHE_DIR;
     AgaviToolkit::mkdir($cacheDir, $parentMode, true);
     if ($this->isSmarty2) {
         $this->smarty->cache_dir = $cacheDir;
     } else {
         $this->smarty->setCacheDir($cacheDir);
     }
     if (AgaviConfig::get('core.debug', false)) {
         $this->smarty->debugging = true;
     }
     foreach ((array) $this->getParameter('smarty_variables') as $key => $value) {
         $this->smarty->{$key} = $value;
     }
     return $this->smarty;
 }
 /**
  * Write a cache file.
  *
  * @param      string An absolute filesystem path to a configuration file.
  * @param      string An absolute filesystem path to the cache file that
  *                    will be written.
  * @param      string Data to be written to the cache file.
  * @param      bool   Should we append the data?
  *
  * @throws     <b>AgaviCacheException</b> If the cache file cannot be written.
  *
  * @author     Sean Kerr <*****@*****.**>
  * @since      0.9.0
  */
 public static function writeCacheFile($config, $cache, $data, $append = false)
 {
     $perms = fileperms(AgaviConfig::get('core.cache_dir')) ^ 0x4000;
     $cacheDir = AgaviConfig::get('core.cache_dir') . DIRECTORY_SEPARATOR . self::CACHE_SUBDIR;
     AgaviToolkit::mkdir($cacheDir, $perms);
     if ($append && is_readable($cache)) {
         $data = file_get_contents($cache) . $data;
     }
     $tmpName = tempnam($cacheDir, basename($cache));
     if (@file_put_contents($tmpName, $data) !== false) {
         // that worked, but that doesn't mean we're safe yet
         // first, we cannot know if the destination directory really was writeable, as tempnam() falls back to the system temp dir
         // second, with php < 5.2.6 on win32 renaming to an already existing file doesn't work, but copy does
         // so we simply assume that when rename() fails that we are on win32 and try to use copy() followed by unlink()
         // if that also fails, we know something's odd
         if (@rename($tmpName, $cache) || @copy($tmpName, $cache) && unlink($tmpName)) {
             // alright, it did work after all. chmod() and bail out.
             chmod($cache, $perms);
             return;
         }
     }
     // still here?
     // that means we could not write the cache file
     $error = 'Failed to write cache file "%s" generated from ' . 'configuration file "%s".';
     $error .= "\n\n";
     $error .= 'Please make sure you have set correct write permissions for directory "%s".';
     $error = sprintf($error, $cache, $config, AgaviConfig::get('core.cache_dir'));
     throw new AgaviCacheException($error);
 }