Example #1
0
 protected function configureDoctrineCache(Doctrine_Manager $manager)
 {
     if (sfConfig::get('dm_orm_cache_enabled', true) && dmAPCCache::isEnabled()) {
         $driver = new Doctrine_Cache_Apc(array('prefix' => dmProject::getNormalizedRootDir() . '/doctrine/'));
         $manager->setAttribute(Doctrine_Core::ATTR_QUERY_CACHE, $driver);
     }
 }
 protected function generateLayoutTemplates()
 {
     $this->logSection('diem', 'generate layout templates');
     $filesystem = $this->get('filesystem');
     foreach (dmDb::query('DmLayout l')->fetchRecords() as $layout) {
         $template = $layout->get('template');
         $templateFile = dmProject::rootify('apps/front/modules/dmFront/templates/' . $template . 'Success.php');
         if (!file_exists($templateFile)) {
             if ($filesystem->mkdir(dirname($templateFile))) {
                 $filesystem->copy(dmOs::join(sfConfig::get('dm_front_dir'), 'modules/dmFront/templates/pageSuccess.php'), $templateFile);
                 $filesystem->chmod($templateFile, 0777);
             } else {
                 $this->logBlock('Can NOT create layout template ' . $template, 'ERROR');
             }
         }
     }
     $layoutFile = dmProject::rootify('apps/front/modules/dmFront/templates/layout.php');
     if (!file_exists($layoutFile)) {
         if ($filesystem->mkdir(dirname($layoutFile))) {
             $filesystem->copy(dmOs::join(sfConfig::get('dm_front_dir'), 'modules/dmFront/templates/layout.php'), $layoutFile);
             $filesystem->chmod($layoutFile, 0777);
         } else {
             $this->logBlock('Can NOT create layout ' . $layoutFile, 'ERROR');
         }
     }
 }
 protected function addFiles()
 {
     $controllers = $this->addChild('Controllers')->ulClass('level1')->liClass('type');
     $templates = $this->addChild('Templates')->ulClass('level1')->liClass('type');
     $moduleDirs = sfFinder::type('dir')->maxDepth(0)->in(sfConfig::get('sf_app_module_dir'));
     natcasesort($moduleDirs);
     foreach ($moduleDirs as $moduleDir) {
         if (count($found = sfFinder::type('file')->in($moduleDir . '/actions'))) {
             $moduleControllers = $controllers->addChild(basename($moduleDir))->ulClass('level2');
             natcasesort($found);
             foreach ($found as $path) {
                 $moduleControllers->addChild(basename($path), '#' . dmProject::unRootify($path));
             }
         }
         if (count($found = sfFinder::type('file')->in($moduleDir . '/templates'))) {
             $moduleTemplates = $templates->addChild(basename($moduleDir))->ulClass('level2');
             natcasesort($found);
             foreach ($found as $path) {
                 $moduleTemplates->addChild(str_replace($moduleDir . '/templates/', '', $path), '#' . dmProject::unRootify($path));
             }
         }
     }
     $stylesheets = $this->addChild('Stylesheets')->ulClass('level1')->liClass('type')->addChild($this->user->getTheme()->getName())->ulClass('level2');
     $cssDir = $this->user->getTheme()->getFullPath('css');
     $cssFiles = sfFinder::type('file')->name('*.css')->in($cssDir);
     natcasesort($cssFiles);
     foreach ($cssFiles as $cssFile) {
         if (dmProject::isInProject($cssFile)) {
             $stylesheets->addChild(str_replace($cssDir . '/', '', $cssFile), '#' . dmProject::unRootify($cssFile));
         }
     }
     return $this;
 }
Example #4
0
 public static function getDmModels()
 {
     if (null === self::$dmModels) {
         $baseFiles = glob(dmOs::join(sfConfig::get('sf_lib_dir'), 'model/doctrine/dmCorePlugin/base/Base*.class.php'));
         self::$dmModels = self::getModelsFromBaseFiles($baseFiles);
     }
     return self::$dmModels;
 }
Example #5
0
 public static function getDmModels()
 {
     if (null === self::$dmModels) {
         $baseFiles = sfFinder::type('file')->name('/Base\\w+.class.php/i')->maxDepth(0)->in(dmOs::join(sfConfig::get("sf_lib_dir"), "model/doctrine/dmCorePlugin/base"));
         self::$dmModels = self::getModelsFromBaseFiles($baseFiles);
     }
     return self::$dmModels;
 }
Example #6
0
 public function initialize(array $options)
 {
     parent::initialize($options);
     if ('/' !== $this->options['file'][0]) {
         $this->options['file'] = dmProject::rootify($this->options['file']);
     }
     $this->nbFields = count($this->fields);
 }
Example #7
0
 public function __construct($options = array())
 {
     if (isset($options['cache_dir'])) {
         $name = substr($options['cache_dir'], strlen(sfConfig::get('sf_cache_dir')) + 1);
     } elseif (isset($options['prefix'])) {
         $name = dmProject::unRootify($options['prefix']);
     } else {
         throw new dmException('You must provide a cache_dir or a prefix');
     }
     $this->initialize(array('prefix' => dmProject::getNormalizedRootDir() . '/' . $name));
 }
Example #8
0
 public function create()
 {
     foreach ($this->getFullPaths() as $fullPath) {
         @$this->filesystem->mkdir($fullPath);
         if (!is_dir($fullPath)) {
             throw new dmException(sprintf('%s can not be created. Please check %s permissions', dmProject::unRootify($fullPath), dmProject::unRootify(dirname($fullPath))));
         }
     }
     $this->filesystem->touch($this->getFullPath('css/markdown.css'));
     $this->dispatcher->notify(new sfEvent($this, 'dm.theme.created', array()));
 }
 /**
  * Executes the filter chain.
  *
  * @param sfFilterChain $filterChain
  */
 public function execute($filterChain)
 {
     $cookieName = sfConfig::get('dm_security_remember_cookie_name', 'dm_remember_' . dmProject::getHash());
     if ($this->isFirstCall() && $this->user->isAnonymous() && ($cookie = $this->request->getCookie($cookieName))) {
         $q = Doctrine_Core::getTable('DmRememberKey')->createQuery('r')->innerJoin('r.User u')->where('r.remember_key = ?', $cookie);
         if ($q->count()) {
             $this->user->signIn($q->fetchOne()->get('User'));
         }
     }
     $filterChain->execute();
 }
Example #10
0
 protected function getAllTables()
 {
     if (null === $this->tables) {
         $this->tables = dmProject::getAllModels();
         foreach ($this->tables as $table) {
             if (dmDb::table($table)->hasI18n()) {
                 new $table();
                 $this->tables[] = dmDb::table($table)->getI18nTable();
             }
         }
     }
     return $this->tables;
 }
 /**
  * @see sfTask
  */
 protected function execute($arguments = array(), $options = array())
 {
     $this->withDatabase();
     $this->logSection('Diem Extended', 'Upgrade ' . dmProject::getKey());
     foreach ($this->changes as $change) {
         $upgradeMethod = 'upgradeTo' . ucfirst($change);
         try {
             $this->{$upgradeMethod}();
         } catch (Exception $e) {
             $this->logBlock('Can not upgrade to change ' . $change . ' : ' . $e->getMessage(), 'ERROR');
         }
     }
 }
 /**
  * @see sfTask
  */
 protected function execute($arguments = array(), $options = array())
 {
     $filesystem = $this->get('filesystem');
     $uploadDir = dmOs::join(sfConfig::get('sf_web_dir'), 'uploads');
     if (!$filesystem->mkdir($uploadDir)) {
         throw new dmException(dmProject::unRootify($uploadDir) . ' is not writable');
     }
     $cacheDir = dmOs::join(sfConfig::get('sf_cache_dir'), 'open_package', dmProject::getKey());
     if (!$filesystem->mkdir($cacheDir)) {
         throw new dmException(dmProject::unRootify($cacheDir) . ' is not writable');
     }
     $filesystem->deleteDirContent($cacheDir);
     if (file_exists(dmOs::join($uploadDir, dmProject::getKey() . '.tgz'))) {
         $filesystem->unlink(dmOs::join($uploadDir, dmProject::getKey() . '.tgz'));
     }
     $this->log('Building the package, please wait...');
     $finder = sfFinder::type('all')->prune(array('.thumbs'))->discard(array('.thumbs'));
     foreach (array('apps', 'config', 'lib', 'plugins', 'public_html', 'test') as $dir) {
         $filesystem->mirror(dmOs::join(sfConfig::get('sf_root_dir'), $dir), dmOs::join($cacheDir, $dir), $finder);
     }
     $filesystem->copy(dmOs::join(sfConfig::get('sf_root_dir'), 'symfony'), dmOs::join($cacheDir, 'symfony'));
     foreach (array('cache', 'data') as $dir) {
         $filesystem->mkdir(dmOs::join($cacheDir, $dir));
     }
     if (file_exists(dmOs::join(sfConfig::get('sf_data_dir'), 'mysql'))) {
         $filesystem->mirror(dmOs::join(sfConfig::get('sf_data_dir'), 'mysql'), dmOs::join($cacheDir, 'data/mysql'), sfFinder::type('all'));
     }
     $databasesFile = dmOs::join($cacheDir, 'config/databases.yml');
     $databasesConfig = sfYaml::load($databasesFile);
     foreach ($databasesConfig as $namespace => $nsConfig) {
         foreach ($nsConfig as $dbName => $config) {
             $dsn = $databasesConfig[$namespace][$dbName]['param']['dsn'];
             $databasesConfig[$namespace][$dbName]['param']['dsn'] = preg_replace('#//(.+)\\:(.*)@#', '//#DB_USER#:#DB_PASSWORD#@', $dsn);
             foreach (array('username', 'password') as $key) {
                 if (isset($databasesConfig[$namespace][$dbName]['param'][$key])) {
                     unset($databasesConfig[$namespace][$dbName]['param'][$key]);
                 }
             }
         }
         file_put_contents($databasesFile, sfYaml::dump($databasesConfig, 5));
     }
     $filesystem->unlink(dmOs::join($cacheDir, 'test/functional'));
     $command = 'cd ' . dirname($cacheDir) . '; tar -czf ' . dmProject::getKey() . '.tgz ' . dmProject::getKey();
     $this->logSection('Compression', $command);
     if (!$filesystem->exec($command)) {
         throw new dmException($filesystem->getLastExec('output'));
     }
     rename(dmOs::join(dirname($cacheDir), dmProject::getKey() . '.tgz'), dmOs::join($uploadDir, dmProject::getKey() . '.tgz'));
     $filesystem->unlink($cacheDir);
     $this->logBlock('Done !', 'INFO');
 }
Example #13
0
 protected function checkCliFile()
 {
     $file = $this->getCliFileFullPath();
     if (!file_exists($file) || file_get_contents($file) != $this->getCliFileContent()) {
         $this->filesystem->mkdir(dirname($file));
         file_put_contents($file, $this->getCliFileContent());
     }
     if (!is_executable($file)) {
         chmod($file, 0777);
     }
     if (!is_executable($file) && '/' === DIRECTORY_SEPARATOR) {
         throw new dmException('Can not make ' . dmProject::unRootify($file) . ' executable');
     }
 }
Example #14
0
 public function checkFolder($validator, $values)
 {
     if (!empty($values['file'])) {
         if (!($folder = dmDb::table('DmMediaFolder')->find($values['dm_media_folder_id']))) {
             throw new dmException('media has no folder');
         }
         if (!is_writable($folder->fullPath)) {
             $error = new sfValidatorError($validator, dmProject::unRootify($folder->fullPath) . ' is not writable');
             // throw an error bound to the file field
             throw new sfValidatorErrorSchema($validator, array('file' => $error));
         }
     }
     return $values;
 }
Example #15
0
 public function executeIndex(sfWebRequest $request)
 {
     $this->commands = implode(' ', $this->getCommands());
     $this->uname = php_uname();
     $filesystem = $this->context->getFilesystem();
     if ($filesystem->exec('whoami')) {
         $this->whoami = $filesystem->getLastExec('output');
     } else {
         $this->whoami = 'unknown_user';
     }
     $this->pwd = getcwd();
     $this->prompt = $this->whoami . '@' . php_uname('n') . ':' . '~/' . dmProject::unRootify($this->pwd) . '$ ';
     $this->getUser()->setAttribute('dm_console_prompt', $this->prompt);
     $this->form = $this->getCommandForm();
 }
Example #16
0
 public function execute()
 {
     require_once dmOs::join(sfConfig::get('dm_core_dir'), 'lib/vendor/Zend/Reflection/File.php');
     require_once dmOs::join(sfConfig::get('dm_core_dir'), 'lib/vendor/Zend/CodeGenerator/Php/File.php');
     require_once dmOs::join(sfConfig::get('dm_core_dir'), 'lib/vendor/dmZend/CodeGenerator/Php/Class.php');
     $file = dmOs::join($this->moduleDir, 'actions/actions.class.php');
     if (!$this->filesystem->mkdir(dirname($file))) {
         $this->logError('can not create directory ' . dmProject::unrootify(dirname($file)));
     }
     $className = $this->module->getKey() . 'Actions';
     if (file_exists($file)) {
         if ($this->shouldSkip($file)) {
             $this->log('skip ' . dmProject::unrootify($file));
             return true;
         }
         include_once $file;
         $this->class = dmZendCodeGeneratorPhpClass::fromReflection(new Zend_Reflection_Class($className));
         foreach ($this->class->getMethods() as $method) {
             $method->setIndentation($this->indentation);
         }
     } else {
         $this->class = $this->buildClass($className);
     }
     $this->class->setIndentation($this->indentation);
     if ($this->module->hasModel()) {
         foreach ($this->module->getComponents() as $component) {
             if ($component->getType() == 'form') {
                 $methodName = 'execute' . dmString::camelize($component->getKey()) . 'Widget';
                 if (!$this->class->getMethod($methodName)) {
                     $this->class->setMethod($this->buildFormMethod($methodName, $component));
                 }
             }
         }
     }
     if ($code = $this->class->generate()) {
         $return = file_put_contents($file, "<?php\n" . $code);
         $this->filesystem->chmod($file, 0777);
     } else {
         $return = true;
     }
     if (!$return) {
         $this->logError('can not write to ' . dmProject::unrootify($file));
     }
     return $return;
 }
Example #17
0
 public function executeSave(dmWebRequest $request)
 {
     $file = dmProject::rootify($request->getParameter('file'));
     $this->forward404Unless(file_exists($file), $file . ' does not exists');
     try {
         @$this->getService('file_backup')->save($file);
     } catch (dmException $e) {
         return $this->renderJson(array('type' => 'error', 'message' => 'backup failed : ' . $e->getMessage()));
     }
     @file_put_contents($file, $request->getParameter('code'));
     if (dmOs::getFileExtension($file, false) == 'css') {
         $return = array('type' => 'css', 'path' => $this->getHelper()->getStylesheetWebPath(dmOs::getFileWithoutExtension($file)));
     } else {
         $this->getService('cache_cleaner')->clearTemplate();
         $return = array('type' => 'php', 'widgets' => $this->getWidgetInnersForFile($file));
     }
     $return['message'] = $this->getI18n()->__('Your modifications have been saved');
     return $this->renderJson($return);
 }
 public function execute()
 {
     $dir = dmOs::join($this->moduleDir, 'templates');
     if (!$this->filesystem->mkdir($dir)) {
         $this->logError('can not create directory ' . $dir);
     }
     $success = true;
     foreach ($this->module->getComponents() as $component) {
         $file = dmOs::join($dir, '_' . $component->getKey() . '.php');
         if (file_exists($file)) {
             continue;
         }
         touch($file);
         $code = $this->getActionTemplate($component);
         $fileSuccess = file_put_contents($file, $code);
         $this->filesystem->chmod($file, 0777);
         if (!$fileSuccess) {
             $this->logError('can not write to ' . dmProject::unrootify($file));
         }
         $success &= $fileSuccess;
     }
     return $success;
 }
Example #19
0
 /**
  * Backup a file
  * return boolean success
  */
 public function save($file)
 {
     if (!$this->isEnabled()) {
         return true;
     }
     if (!dmProject::isInProject($file)) {
         $file = dmOs::join(dmProject::getRootDir(), $file);
     }
     if (!is_readable($file)) {
         throw new dmException('Can no read ' . $file);
     }
     $relFile = dmProject::unRootify($file);
     $backupPath = dmOs::join($this->getDir(), dirname($relFile));
     if (!$this->filesystem->mkdir($backupPath)) {
         throw new dmException('Can not create backup dir ' . $backupPath);
     }
     $backupFile = dmOs::join($backupPath, basename($relFile) . '.' . date('Y-m-d_H-i-s'));
     if (!$this->filesystem->touch($backupFile, 0777)) {
         throw new dmException('Can not copy ' . $file . ' to ' . $backupFile);
     }
     file_put_contents($backupFile, file_get_contents($file));
     $this->filesystem->chmod($file, 0777);
     return true;
 }
 protected function getUnchangedModels()
 {
     return array_diff(dmProject::getAllModels(), $this->getChangedModels());
 }
Example #21
0
<?php

require_once realpath(dirname(__FILE__) . '/../../..') . '/unit/helper/dmModuleUnitTestHelper.php';
$helper = new dmModuleUnitTestHelper();
$helper->boot();
$t = new lime_test(10);
$models = dmProject::getModels();
$dmModels = dmProject::getDmModels();
$allModels = dmProject::getAllModels();
$t->is_deeply($models, $expected = array('DmTestCateg', 'DmTestComment', 'DmTestDomainCateg', 'DmTestDomain', 'DmTestFruit', 'DmTestPost', 'DmTestPostTag', 'DmTestTag', 'DmTestUser', 'DmContact', 'DmTag'), 'dmProject::getModels() -> ' . implode(', ', $expected));
$t->is_deeply(array_intersect($models, $allModels), $models, 'dmProject::getAllModels() contain all project models');
$t->is_deeply(array_intersect($dmModels, $allModels), $dmModels, 'dmProject::getAllModels() contain all Diem models');
$t->is_deeply(array_intersect($models, $dmModels), array(), 'dmProject::getDmModels() contain no project models');
$t->is_deeply(array_intersect($dmModels, $models), array(), 'dmProject::getModels() contain no Diem models');
$t->is(count($dmModels), $expected = 17, 'Diem has ' . $expected . ' models');
$t->is(dmProject::getKey(), 'project', 'project key is "project"');
$t->ok(dmProject::appExists('front'), 'project has a front app');
$t->ok(dmProject::appExists('admin'), 'project has a admin app');
$t->ok(!dmProject::appExists('bluk'), 'project has no bluk app');
Example #22
0
 protected function validatePath($path, $restrictedPaths, $verb = 'use')
 {
     if (!dmProject::isInProject($path)) {
         throw new dmCodeEditorException(sprintf('Can not %s %s because it is outside of the project', $verb, $path));
     }
     $path = dmProject::unRootify($path);
     foreach ($restrictedPaths as $restrictedPath) {
         if (preg_match('#^' . $restrictedPath . '$#', $path)) {
             throw new dmCodeEditorException(sprintf('You are not allowed to %s %s', $verb, $path));
         }
     }
 }
Example #23
0
 public function getFullPath()
 {
     return dmProject::rootify($this->getOption('dir'));
 }
Example #24
0
 public function deleteDirContent($dir, $throwExceptions = false)
 {
     if (!dmProject::isInProject($dir)) {
         throw new dmException(sprintf('Try to delete %s, which is outside symfony project', $dir));
     }
     $success = true;
     if (!($dh = @opendir($dir))) {
         if ($throwExceptions) {
             throw new dmException("Can not open {$dir} folder");
         } else {
             $success = false;
         }
     }
     while (false !== ($obj = @readdir($dh))) {
         if ($obj == '.' || $obj == '..') {
             continue;
         }
         if (is_dir($dir . '/' . $obj)) {
             $success &= $this->deleteDir($dir . '/' . $obj, $throwExceptions);
         } else {
             if (!@unlink($dir . '/' . $obj)) {
                 if ($throwExceptions) {
                     throw new dmException("Can not delete file {$dir}/{$obj}");
                 } else {
                     $success = false;
                 }
             }
         }
     }
     @closedir($dh);
     return $success;
 }
Example #25
0
 public function getRememberCookieName()
 {
     return sfConfig::get('dm_security_remember_cookie_name', 'dm_remember_' . dmProject::getHash());
 }
Example #26
0
 protected function loadI18nTransUnit()
 {
     foreach ($this->i18n->getCultures() as $culture) {
         if ($culture == sfConfig::get('sf_default_culture', 'en')) {
             continue;
         }
         /*
          * English to $culture
          */
         $catalogue = dmDb::table('DmCatalogue')->retrieveBySourceTargetSpace(sfConfig::get('sf_default_culture', 'en'), $culture, 'dm');
         $dataFiles = $this->configuration->getConfigPaths('data/dm/i18n/en_' . $culture . '.yml');
         $table = dmDb::table('DmTransUnit');
         $existQuery = $table->createQuery('t')->select('t.id, t.source, t.target, t.created_at, t.updated_at')->where('t.dm_catalogue_id = ? AND t.source = ?');
         $catalogueId = $catalogue->get('id');
         $nbAdded = 0;
         $nbUpdated = 0;
         foreach ($dataFiles as $dataFile) {
             if (!is_array($data = sfYaml::load(file_get_contents($dataFile)))) {
                 continue;
             }
             $addedTranslations = new Doctrine_Collection($table);
             $line = 0;
             foreach ($data as $source => $target) {
                 ++$line;
                 if (!is_string($source) || !is_string($target)) {
                     $this->log('Error line ' . $line . ': ' . dmProject::unrootify($dataFile));
                 } else {
                     $existing = $existQuery->fetchOneArray(array($catalogueId, $source));
                     if (!empty($existing) && $existing['source'] === $source) {
                         if ($existing['target'] !== $target) {
                             //$this->log(sprintf('%s -> %s', $existing['target'], $target));
                             // don't overwrite user modified translations
                             if ($existing['created_at'] === $existing['updated_at']) {
                                 $table->createQuery()->update('DmTransUnit')->set('target', '?', array($target))->where('id = ?', $existing['id'])->execute();
                                 ++$nbUpdated;
                             }
                         }
                     } elseif (empty($existing)) {
                         $addedTranslations->add(dmDb::create('DmTransUnit', array('dm_catalogue_id' => $catalogue->get('id'), 'source' => $source, 'target' => $target)));
                         ++$nbAdded;
                     }
                 }
             }
             $addedTranslations->save();
         }
         if ($nbAdded) {
             $this->log(sprintf('%s: added %d translation(s)', $culture, $nbAdded));
         }
         if ($nbUpdated) {
             $this->log(sprintf('%s: updated %d translation(s)', $culture, $nbUpdated));
         }
     }
 }
Example #27
0
 /**
  * Move into another folder
  *
  * @param DmMediaFolder $folder
  */
 public function move(DmMediaFolder $folder)
 {
     if ($folder->id == $this->nodeParentId) {
         return $this;
     }
     if ($folder->getNode()->isDescendantOfOrEqualTo($this)) {
         throw new dmException('Can not move to a descendant');
     }
     if ($this->getNode()->isRoot()) {
         throw new dmException('The root folder cannot be moved');
     }
     if (!$this->isWritable()) {
         throw new dmException(sprintf('The folder %s is not writable.', dmProject::unRootify($this->fullPath)));
     }
     if (!$folder->isWritable()) {
         throw new dmException(sprintf('The folder %s is not writable.', dmProject::unRootify($folder->fullPath)));
     }
     if ($folder->hasSubFolder($this->name)) {
         throw new dmException(sprintf('The selected folder already contains a folder named "%s".', $this->name));
     }
     $oldRelPath = $this->get('rel_path');
     $newRelPath = $folder->get('rel_path') . '/' . $this->name;
     $fs = $this->getService('filesystem');
     $oldFullPath = $this->getFullPath();
     $newFullPath = dmOs::join($folder->getFullPath(), $this->name);
     if (!rename($oldFullPath, $newFullPath)) {
         throw new dmException('Can not move %s to %s', dmProject::unRootify($oldFullPath), dmProject::unRootify($newFullPath));
     }
     $this->set('rel_path', $newRelPath);
     $this->clearCache();
     $this->getNode()->moveAsFirstChildOf($folder);
     //update descendants
     if ($descendants = $this->getNode()->getDescendants()) {
         foreach ($descendants as $folder) {
             $folder->set('rel_path', dmString::str_replace_once($oldRelPath, $newRelPath, $folder->get('rel_path')));
             $folder->save();
         }
     }
     return $this;
 }
Example #28
0
 protected function getResizedMediaFullPath(array $attributes)
 {
     $media = $this->resource->getSource();
     if (!$media instanceof DmMedia) {
         throw new dmException('Can be used only if the source is a DmMedia instance');
     }
     if (empty($attributes['width'])) {
         $attributes['width'] = $media->getWidth();
     } elseif (empty($attributes['height'])) {
         $attributes['height'] = (int) ($media->getHeight() * ($attributes['width'] / $media->getWidth()));
     }
     $filter = dmArray::get($attributes, 'filter');
     $overlay = dmArray::get($attributes, 'overlay', array());
     /*
      * Nothing to change, return the original image
      */
     if ($attributes['width'] == $media->getWidth() && $attributes['height'] == $media->getHeight() && !$filter && !$overlay) {
         return $media->getFullPath();
     }
     if ($attributes['resize_method'] == 'fit') {
         $attributes['background'] = trim($attributes['background'], '#');
     }
     if (!in_array($attributes['resize_method'], $this->getAvailableMethods())) {
         throw new dmException(sprintf('%s is not a valid resize method. These are : %s', $attributes['resize_method'], implode(', ', $this->getAvailableMethods())));
     }
     if (!($thumbDir = dmArray::get(self::$verifiedThumbDirs, $media->get('dm_media_folder_id')))) {
         $thumbDir = dmOs::join($media->get('Folder')->getFullPath(), '.thumbs');
         if (!@$this->context->getFilesystem()->mkdir($thumbDir)) {
             throw new dmException('Thumbnails can not be created in ' . $media->get('Folder')->getFullPath());
         }
         self::$verifiedThumbDirs[$media->get('dm_media_folder_id')] = $thumbDir;
     }
     $pathInfo = pathinfo($media->get('file'));
     $thumbRelPath = $pathInfo['filename'] . '_' . substr(md5(implode('-', array($attributes['width'], $attributes['height'], $attributes['resize_method'] === 'fit' ? 'fit' . $attributes['background'] : $attributes['resize_method'], $filter, implode(' ', $overlay), isset($attributes['resize_quality']) ? $attributes['resize_quality'] : '', $media->getTimeHash()))), -6) . '.' . $pathInfo['extension'];
     $thumbPath = $thumbDir . '/' . $thumbRelPath;
     if (!file_exists($thumbPath)) {
         $image = $media->getImage();
         $image->setQuality($attributes['resize_quality']);
         $image->thumbnail($attributes['width'], $attributes['height'], $attributes['resize_method'], !empty($attributes['background']) ? '#' . $attributes['background'] : null);
         if ($filter) {
             $image->{$filter}();
         }
         if (!empty($overlay)) {
             $overlayPath = $overlay['image']->getServerFullPath();
             $type = $this->context->get('mime_type_resolver')->getByFilename($overlayPath);
             if ($type != 'image/png') {
                 throw new dmException('Only png images can be used as overlay.');
             }
             $image->overlay(new sfImage($overlayPath, $type), $overlay['position']);
         }
         $image->saveAs($thumbPath, $media->get('mime'));
         if (!file_exists($thumbPath)) {
             throw new dmException(dmProject::unRootify($thumbPath) . ' cannot be created');
         } else {
             $this->context->getFilesystem()->chmod($thumbPath, 0666);
         }
     }
     return $thumbPath;
 }
Example #29
0
$t->isa_ok($currentIndex->getLuceneIndex(), 'Zend_Search_Lucene_Proxy', 'The current index is instanceof Zend_Search_Lucene_Proxy');
$t->ok(!file_exists(dmProject::rootify('segments.gen')), 'There is no segments.gen in project root dir');
dmConfig::set('search_stop_words', 'un le  les de,du , da, di ,do   ou ');
$t->is($currentIndex->getStopWords(), array('un', 'le', 'les', 'de', 'du', 'da', 'di', 'do', 'ou'), 'stop words retrieved from site instance : ' . implode(', ', $currentIndex->getStopWords()));
$t->diag('Cleaning text');
$html = '<ol><li><a class="link dm_parent" href="symfony">Accueil</a></li><li>></li><li><a class="link dm_parent" href="symfony/domaines">Domaines</a></li><li>></li><li><a class="link dm_parent" href="symfony/domaines/77-cursus-proin1i471j0u">cursus. Proin1i471j0u</a></li><li>></li><li><a class="link dm_parent" href="symfony/domaines/77-cursus-proin1i471j0u/104-trices-interdum-risus-duisgpcinqn1">trices interdum risus. Duisgpcinqn1</a></li><li>></li><li><span class="link dm_current">Info : t, auctor ornare, risus. Donec lo</span></li></ol><span class="link dm_current">Info : t, auctor ornare, risus. Donec lo</span><div class="info_tag list_by_info"><ul class="elements"><li class="element clearfix"><a class="link" href="symfony/domaines/77-cursus-proin1i471j0u/104-trices-interdum-risus-duisgpcinqn1/t-auctor-ornare-risus-donec-lo-79/t-donec">t. Donec</a></li><li class="element clearfix"><a class="link" href="symfony/domaines/77-cursus-proin1i471j0u/104-trices-interdum-risus-duisgpcinqn1/t-auctor-ornare-risus-donec-lo-79/em-ipsu">em ipsu</a></li></ul></div>';
$expected = 'accueil domaines cursus proin1i471j0u trices interdum risus duisgpcinqn1 info t auctor ornare risus donec lo info t auctor ornare risus donec lo t donec em ipsu';
$t->is($currentIndex->cleanText($html), $expected, 'cleaned text : ' . $expected);
$html = '<div>some content<a href="url">a link text  é àî</a>... end</div>';
$expected = 'some content a link text e ai end';
$t->is($currentIndex->cleanText($html), $expected, 'cleaned text : ' . $expected);
// for now this doesn't work on windows
if ('/' !== DIRECTORY_SEPARATOR) {
    return;
}
$t->diag('Populate all indices');
$t->ok($engine->populate(), 'Indices populated');
$t->is($user->getCulture(), sfConfig::get('sf_default_culture'), 'User\'s culture has not been changed');
$t->ok(!file_exists(dmProject::rootify('segments.gen')), 'There is no segments.gen in project root dir');
$t->diag('Optimize all indices');
$t->ok($engine->optimize(), 'Indices optimized');
$t->is($user->getCulture(), sfConfig::get('sf_default_culture'), 'User\'s culture has not been changed');
$t->ok(!file_exists(dmProject::rootify('segments.gen')), 'There is no segments.gen in project root dir');
$t->ok(file_exists(dmProject::rootify('cache/testIndex/' . $currentIndex->getName(), 'segments.gen')), 'There is segments.gen in cache index dir ' . dmProject::rootify('cache/testIndex/' . $currentIndex->getName(), 'segments.gen'));
$indexDescription = $engine->getCurrentIndex()->describe();
// not pages indexed with sqlite (?)
if (!$isSqlite) {
    $t->is($indexDescription['Documents'], $engine->getCurrentIndex()->getPagesQuery()->count(), 'All pages have been indexed : ' . $indexDescription['Documents']);
    $t->diag('Perform a search');
    $engine->search('Diem');
}
Example #30
0
 protected function write($filePath, $xml)
 {
     $file = dmOs::join($this->getOption('dir'), $filePath);
     if (!file_put_contents($file, $xml)) {
         throw new dmException('Can not save xml sitemap to ' . dmProject::unRootify($file));
     }
     @$this->filesystem->chmod($file, 0666);
 }