Exemple #1
0
 public function configure(array $options = array())
 {
     $options['default'] = null;
     foreach ($options['list'] as $themeName => $themeConfig) {
         // enabled options defaults to true
         if (null === dmArray::get($themeConfig, 'enabled')) {
             $options['list'][$themeName]['enabled'] = true;
         }
         // first enabled theme is the default theme
         if (null === $options['default'] && $options['list'][$themeName]['enabled']) {
             $options['default'] = $themeName;
         }
         // path is renamed to dir BC 5.0_BETA6
         if (isset($options['list'][$themeName]['path'])) {
             $options['list'][$themeName]['dir'] = $options['list'][$themeName]['path'];
             unset($options['list'][$themeName]['path']);
         }
         // theme key is the theme name
         $options['list'][$themeName]['name'] = $themeName;
     }
     if (null === $options['default']) {
         throw new dmException('No theme is enabled!');
     }
     return parent::configure($options);
 }
 protected function getUrls()
 {
     $urls = array('/');
     $routing = $this->context->getRouting();
     foreach ($this->context->getModuleManager()->getModules() as $module) {
         if (!$routing->hasRouteName($module->getUnderscore())) {
             continue;
         }
         $moduleUrl = $routing->generate($module->getUnderscore());
         $urls[] = $moduleUrl;
         if ($module->hasModel() && $module->getTable()->hasField('id')) {
             $records = $module->getTable()->createQuery('t')->select('t.id, RANDOM() AS rand')->orderBy('rand')->limit(2)->fetchArray();
             foreach ($records as $record) {
                 $urls[] = $moduleUrl . '/edit/pk/' . $record['id'];
             }
         }
     }
     foreach ($this->context->getModuleManager()->getTypes() as $type) {
         $urls[] = $this->context->getController()->genUrl($routing->getModuleTypeUrl($type));
         foreach ($type->getSpaces() as $space) {
             $urls[] = $this->context->getController()->genUrl($routing->getModuleSpaceUrl($space));
         }
     }
     $uriPrefixLength = strlen(dmArray::get(dmArray::get($routing->getOptions(), 'context'), 'prefix'));
     foreach ($urls as $index => $url) {
         $urls[$index] = substr($url, $uriPrefixLength);
     }
     return $urls;
 }
 public function executeSaveFile(dmWebRequest $request)
 {
     // modify existing media
     if ($mediaId = dmArray::get($request->getParameter('dm_admin_media_form'), 'id')) {
         $this->forward404Unless($media = dmDb::table('DmMedia')->find($mediaId));
         $form = new DmAdminMediaForm($media);
     } else {
         $media = null;
         $this->forward404Unless($folder = dmDb::table('DmMediaFolder')->find($request->getParameter('folder_id')));
         if (!$folder->isWritable()) {
             $this->getUser()->logAlert($this->getI18n()->__('Folder %1% is not writable', array('%1%' => $folder->fullPath)));
         }
         $form = new DmAdminMediaForm();
         $form->setDefault('dm_media_folder_id', $folder->id);
     }
     if ($request->isMethod('post') && $form->bindAndValid($request)) {
         $redirect = $form->getValue('file') || $media->dm_media_folder_id != $form->getValue('dm_media_folder_id');
         $media = $form->save();
         if ($redirect) {
             $this->getUser()->setFlash('dm_media_open', $media->id, false);
             return $this->renderText($this->getRouting()->getMediaUrl(dmDb::table('DmMediaFolder')->find($media->dm_media_folder_id)));
         }
     }
     $action = $media ? 'dmMediaLibrary/saveFile' : 'dmMediaLibrary/saveFile?folder_id=' . $folder->id;
     return $this->renderText($form->render('.dm_form.list.little action="' . $action . '"'));
 }
  public function getWidgetValues()
  {
    $values = parent::getWidgetValues();

    $values['items'] = array();

    foreach(dmArray::get($values, 'link', array()) as $index => $link)
    {
      $values['items'][] = array(
        'link'     => $values['link'][$index],
        'text'     => $values['text'][$index],
        'secure'   => (int) !empty($values['secure'][$index]),
        'nofollow' => (int) !empty($values['nofollow'][$index]),
        'depth'    => $values['depth'][$index]
      );
    }

    unset(
      $values['link'],
      $values['text'],
      $values['secure'],
      $values['nofollow'],
      $values['depth']
    );

    return $values;
  }
Exemple #5
0
 public function configure(array $data)
 {
     $isXhr = $data['context']->getRequest()->isXmlHttpRequest();
     $uri = $this->cleanUri(dmArray::get($data['server'], 'PATH_INFO', $data['server']['REQUEST_URI']));
     $milliseconds = (microtime(true) - dm::getStartTime()) * 1000;
     $this->data = array('time' => (string) $data['server']['REQUEST_TIME'], 'uri' => dmString::truncate($uri, 500), 'code' => (string) $data['context']->getResponse()->getStatusCode(), 'app' => (string) sfConfig::get('sf_app'), 'env' => (string) sfConfig::get('sf_environment'), 'ip' => (string) $data['server']['REMOTE_ADDR'], 'user_id' => (string) $data['context']->getUser()->getUserId(), 'user_agent' => dmString::truncate($isXhr ? '' : isset($data['server']['HTTP_USER_AGENT']) ? $data['server']['HTTP_USER_AGENT'] : '', 500), 'xhr' => (int) $isXhr, 'mem' => (string) memory_get_peak_usage(true), 'timer' => (string) sprintf('%.0f', $milliseconds), 'cache' => sfConfig::get('dm_internal_page_cached'));
 }
Exemple #6
0
 public function executeCommand(sfWebRequest $request)
 {
     $command = trim($request->getParameter("dm_command"));
     if (substr($command, 0, 2) == "sf") {
         $command = substr($command, 3);
         $exec = sprintf('%s "%s" %s --color', sfToolkit::getPhpCli(), dmProject::getRootDir() . '/symfony', $command);
     } else {
         $options = substr(trim($command), 0, 2) == 'll' || substr(trim($command), 0, 2) == 'ls' ? '--color' : '';
         $parts = explode(" ", $command);
         $parts[0] = dmArray::get($this->getAliases(), $parts[0], $parts[0]);
         $command = implode(" ", $parts);
         $parts = explode(" ", $command);
         $command = dmArray::get($this->getAliases(), $command, $command);
         if (!in_array($parts[0], $this->getCommands())) {
             return $this->renderText(sprintf("%s<li>This command is not available. You can do: <strong>%s</strong></li>", $this->renderCommand($command), implode(' ', $this->getCommands())));
         }
         $exec = sprintf("%s {$options}", $command);
     }
     ob_start();
     passthru($exec . ' 2>&1', $return);
     $raw = dmAnsiColorFormatHtmlRenderer::render(ob_get_clean());
     $arr = explode("\n", $raw);
     $res = $this->renderCommand($command);
     foreach ($arr as $a) {
         $res .= "<li class='dm_result_command'><pre>" . $a . "</pre></li>";
     }
     return $this->renderText($res);
 }
  protected function filterViewVars(array $vars = array())
  {
    $vars = parent::filterViewVars($vars);

    $menuClass = dmArray::get($vars, 'menuClass');

    $vars['menu'] = $this->getService('menu', $menuClass ? $menuClass : null)
    ->ulClass($vars['ulClass']);

    foreach($vars['items'] as $index => $item)
    {
      $menuItem = $vars['menu']
      ->addChild($index.'-'.dmString::slugify($item['text']), $item['link'])
      ->label($item['text'])
      ->secure(!empty($item['secure']))
      ->liClass($vars['liClass'])
      ->addRecursiveChildren(dmArray::get($item, 'depth', 0));

      if(!empty($item['nofollow']) && $menuItem->getLink())
      {
        $menuItem->getLink()->set('rel', 'nofollow');
      }
    }

    unset($vars['items'], $vars['ulClass'], $vars['liClass']);

    return $vars;
  }
Exemple #8
0
 protected function createPageTranslations($pageId)
 {
     $cultures = $this->getOption('cultures');
     $translationTable = dmDb::table('DmPageTranslation');
     $existingCultures = $translationTable->createQuery('t')->where('t.id = ? ', $pageId)->andWhereIn('t.lang', $cultures)->select('t.lang')->fetchFlat();
     // can not generate translations from nothing
     if (empty($existingCultures)) {
         return;
     }
     // calculate missing cultures for this page
     $missingCultures = array_diff($cultures, $existingCultures);
     // all translations exist
     if (empty($missingCultures)) {
         return;
     }
     if (in_array(sfConfig::get('sf_default_culture'), $existingCultures)) {
         $mainCulture = sfConfig::get('sf_default_culture');
     } elseif (in_array(myDoctrineRecord::getDefaultCulture(), $existingCultures)) {
         $mainCulture = myDoctrineRecord::getDefaultCulture();
     } else {
         $mainCulture = dmArray::first($existingCultures);
     }
     $mainTranslationArray = $translationTable->createQuery('t')->select('t.slug, t.name, t.title, t.h1, t.description, t.keywords, t.is_active')->where('t.id = ?', $pageId)->andWhere('t.lang = ?', $mainCulture)->limit(1)->fetchOne(array(), Doctrine_Core::HYDRATE_ARRAY);
     $missingTranslations = new myDoctrineCollection(dmDb::table('DmPageTranslation'));
     if ($this->getOption('activate_new_translations')) {
         $isActive = $mainTranslationArray['is_active'];
     } else {
         $isActive = false;
     }
     foreach ($missingCultures as $culture) {
         $missingTranslations->add($translationTable->create(array_merge($mainTranslationArray, array('lang' => $culture, 'is_active' => $isActive))));
     }
     $missingTranslations->save();
 }
 /**
  * @see sfTask
  */
 protected function execute($arguments = array(), $options = array())
 {
     $this->logSection('Diem Extended', 'Setup ' . dmProject::getKey());
     $this->dispatcher->notify(new sfEvent($this, 'dm.setup.before', array('clear-db' => $options['clear-db'])));
     // don't use cache:clear task because it changes current app & environment
     @sfToolkit::clearDirectory(sfConfig::get('sf_cache_dir'));
     if (!file_exists(dmOs::join(sfConfig::get('sf_root_dir'), 'lib', 'model', 'doctrine', 'myDoctrineRecord.php'))) {
         $this->getContext()->get('filesystem')->copy(dmOs::join(sfConfig::get('dm_core_dir'), 'data', 'skeleton', 'lib', 'model', 'doctrine', 'myDoctrineRecord.php'), dmOs::join(sfConfig::get('sf_root_dir'), 'lib', 'model', 'doctrine', 'myDoctrineRecord.php'));
     }
     if (!file_exists(dmOs::join(sfConfig::get('sf_root_dir'), 'lib', 'model', 'doctrine', 'myDoctrineQuery.php'))) {
         $this->getContext()->get('filesystem')->copy(dmOs::join(sfConfig::get('dm_core_dir'), 'data', 'skeleton', 'lib', 'model', 'doctrine', 'myDoctrineQuery.php'), dmOs::join(sfConfig::get('sf_root_dir'), 'lib', 'model', 'doctrine', 'myDoctrineQuery.php'));
     }
     if (!file_exists(dmOs::join(sfConfig::get('sf_root_dir'), 'lib', 'model', 'doctrine', 'myDoctrineTable.php'))) {
         $this->getContext()->get('filesystem')->copy(dmOs::join(sfConfig::get('dm_core_dir'), 'data', 'skeleton', 'lib', 'model', 'doctrine', 'myDoctrineTable.php'), dmOs::join(sfConfig::get('sf_root_dir'), 'lib', 'model', 'doctrine', 'myDoctrineTable.php'));
     }
     $this->runTask('doctrine:build', array(), array('model' => true));
     if ($options['clear-db'] || $options['clear-tables'] || $this->isProjectLocked()) {
         $this->reloadAutoload();
         if ($options['clear-db']) {
             $this->runTask('doctrine:drop-db', array(), array('env' => $options['env'], 'no-confirmation' => dmArray::get($options, 'no-confirmation', false)));
         } else {
             $this->runTask('dm:drop-tables', array(), array('env' => $options['env']));
         }
         if ($options['clear-db'] && ($ret = $this->runTask('doctrine:build-db', array(), array('env' => $options['env'])))) {
             return $ret;
         }
         $this->runTask('doctrine:build-sql', array(), array('env' => $options['env']));
         $this->runTask('doctrine:insert-sql', array(), array('env' => $options['env']));
     } else {
         $this->runTask('dm:upgrade', array(), array('env' => $options['env']));
     }
     $this->reloadAutoload();
     $this->withDatabase();
     $this->runTask('dm:clear-cache', array(), array('env' => $options['env']));
     $this->getContext()->reloadModuleManager();
     $this->runTask('doctrine:build-forms', array(), array('generator-class' => 'dmDoctrineFormGenerator'));
     $this->runTask('doctrine:build-filters', array(), array('generator-class' => 'dmDoctrineFormFilterGenerator'));
     $this->runTask('dm:publish-assets');
     $this->runTask('dm:clear-cache', array(), array('env' => $options['env']));
     $this->reloadAutoload();
     $this->getContext()->reloadModuleManager();
     $this->runTask('dmAdmin:generate', array(), array('env' => $options['env']));
     if (!$options['dont-load-data']) {
         $this->runTask('dm:data', array(), array('load-doctrine-data' => $options['load-doctrine-data'], 'env' => $options['env']));
     }
     $this->logSection('Diem Extended', 'generate front modules');
     if (!($return = $this->context->get('filesystem')->sf('dmFront:generate --env=' . dmArray::get($options, 'env', 'dev')))) {
         $this->logBlock(array('Can\'t run dmFront:generate: ' . $this->context->get('filesystem')->getLastExec('output'), 'Please run "php symfony dmFront:generate" manually to generate front templates'), 'ERROR');
     }
     $this->runTask('dm:permissions');
     // fix db file permissions
     if ('Sqlite' === Doctrine_Manager::connection()->getDriverName()) {
         $this->filesystem->chmod(sfConfig::get('sf_data_dir'), 0777, 00);
     }
     $this->runTask('dm:clear-cache', array(), array('env' => $options['env']));
     $this->dispatcher->notify(new sfEvent($this, 'dm.setup.after', array('clear-db' => $options['clear-db'])));
     $this->logBlock('Setup successful', 'INFO_LARGE');
     $this->unlockProject();
 }
 protected function getOptionsForSelect($value, $choices)
 {
     $choices = dmArray::valueToKey($value ? $value : $choices);
     $html = parent::getOptionsForSelect($choices, $choices);
     // fcbkcomplete wants a class selected
     $html = str_replace('selected="selected"', 'class="selected"', $html);
     return $html;
 }
 public function label($label = null, $attributes = array())
 {
     $attributes = dmString::toArray($attributes);
     $attributes['class'] = dmArray::toHtmlCssClasses(empty($attributes['class']) ? array('label') : array_merge((array) $attributes['class'], array('label')));
     $label = null === $label ? $this->parent->getWidget()->getLabel($this->name) : $label;
     $this->htmlBuffer .= parent::renderLabel($label, $attributes);
     return $this;
 }
Exemple #12
0
 public function configure(array $data)
 {
     $userId = dmArray::get($data, 'user_id', $this->serviceContainer->getService('user')->getUserId());
     if (!$userId && dmConfig::isCli()) {
         $userId = 'task';
     }
     $this->data = array('time' => (string) $data['server']['REQUEST_TIME'], 'ip' => (string) $this->getCurrentRequestIp(), 'session_id' => (string) session_id(), 'user_id' => (string) $userId, 'action' => (string) $data['action'], 'type' => (string) $data['type'], 'subject' => dmString::truncate($data['subject'], 500), 'record' => isset($data['record']) ? get_class($data['record']) . ':' . $data['record']->get('id') : '');
 }
Exemple #13
0
 /**
  * Guess user's browser
  * @return dmBrowser browser object
  */
 public function getBrowser()
 {
     if (!$this->isBrowserConfigured) {
         $this->browser->configureFromUserAgent(dmArray::get($_SERVER, 'HTTP_USER_AGENT'));
         $this->isBrowserConfigured = true;
     }
     return $this->browser;
 }
 public function getWidgetValues()
 {
     $values = parent::getWidgetValues();
     if (dmArray::get($values, 'removeMedia')) {
         $values['mediaId'] = null;
     }
     unset($values['removeMedia']);
     return $values;
 }
Exemple #15
0
 protected function renderPartial(array $vars)
 {
     if ($this->isCachable() && $this->context->getViewCacheManager()) {
         list($partialModule, $partialAction) = $this->getPartialModuleAction();
         $this->context->getViewCacheManager()->addCache($partialModule, '_' . $partialAction, array('withLayout' => false, 'lifeTime' => 86400, 'clientLifeTime' => 86400, 'contextual' => !$this->isStatic(), 'vary' => array(dmArray::get($this->widget, 'id'), $this->getService('user')->getUserId(), $this->getService('user')->getCulture())));
     }
     // add dm_widget to the component/partial vars
     $vars['dm_widget'] = $this->widget;
     return $this->doRenderPartial($vars);
 }
 protected function getResultsPager(array $vars)
 {
     $results = $this->getService('search_engine')->search($vars['query']);
     if (empty($results)) {
         return null;
     }
     $pager = new dmSearchPager($results, dmArray::get($vars, 'maxPerPage', 99999));
     $pager->setPage($this->getService('request')->getParameter('page', 1));
     $pager->init();
     return $this->getService('front_pager_view')->setPager($pager)->setOption('navigation_top', dmArray::get($vars, 'navTop'))->setOption('navigation_bottom', dmArray::get($vars, 'navBottom'))->setBaseHref($this->getService('request')->getUri());
 }
Exemple #17
0
 public function executeChangeMaxPerPage(sfWebRequest $request)
 {
     $this->forward404Unless($module = $this->context->getModuleManager()->getModuleBySfName($sfModule = $request->getParameter('dm_module')));
     if ($maxPerPage = $request->getParameter('max_per_page')) {
         $maxPerPages = sfConfig::get('dm_admin_max_per_page', array(10));
         $maxPerPage = in_array($maxPerPage, $maxPerPages) ? $maxPerPage : dmArray::first($maxPerPages);
         $this->getUser()->setAttribute($sfModule . '.max_per_page', $maxPerPage, 'admin_module');
         $this->getUser()->setAttribute($sfModule . '.page', 1, 'admin_module');
     }
     return $this->redirectBack();
 }
  public function renderBodyTag($options = array())
  {
    $options = dmString::toArray($options);

    $options['class'] = dmArray::toHtmlCssClasses(array_merge(dmArray::get($options, 'class', array()), array(
      'page_'.$this->page->get('module').'_'.$this->page->get('action'),
      $this->page->getPageView()->getLayout()->get('css_class')
    )));
    
    return parent::renderBodyTag($options);
  }
Exemple #19
0
 public static function getBigLorem($nbParagraphs = null)
 {
     $lorem = self::getLoremText();
     if (null === $nbParagraphs) {
         $nbParagraphs = 1;
     }
     $paragraphs = array();
     for ($it = 0; $it < $nbParagraphs; $it++) {
         $paragraphs[] = dmArray::get($lorem, array_rand($lorem));
     }
     return implode("\n", $paragraphs);
 }
 protected function getResultsPager(array $vars)
 {
     $this->index = $this->context->get('search_engine');
     if (count($results = $this->index->search($vars['query']))) {
         $pager = new dmSearchPager($results, dmArray::get($vars, 'maxPerPage', 99999));
         $pager->setPage($this->context->getRequest()->getParameter('page', 1));
         $pager->init();
     } else {
         $pager = null;
     }
     return $pager;
 }
 public function renderZone(array $zone)
 {
     $style = !$zone['width'] || $zone['width'] === '100%' ? '' : ' style="width: ' . $zone['width'] . ';"';
     $html = '<div id="dm_zone_' . $zone['id'] . '" class="' . dmArray::toHtmlCssClasses(array('dm_zone', $zone['css_class'])) . '"' . $style . '>';
     if ($this->user->can('zone_edit')) {
         $html .= '<a class="dm dm_zone_edit" title="' . $this->i18n->__('Edit this zone') . '"></a>';
     }
     $html .= '<div class="dm_widgets">';
     $html .= $this->renderZoneInner($zone);
     $html .= '</div>';
     $html .= '</div>';
     return $html;
 }
Exemple #22
0
 public function configure()
 {
     /*
      * Record id
      */
     $this->widgetSchema['recordId'] = new sfWidgetFormDoctrineChoice(array('model' => $this->dmModule->getModel(), 'add_empty' => $this->allowAutoRecordId() ? sprintf('(%s) %s', $this->__('contextual'), $this->getAutoRecord()->__toString()) : false));
     $this->widgetSchema['recordId']->setLabel($this->getDmModule()->getName());
     $this->validatorSchema['recordId'] = new sfValidatorDoctrineChoice(array('model' => $this->dmModule->getModel(), 'required' => !$this->allowAutoRecordId()));
     $this->setDefaults($this->getDefaultsFromLastUpdated());
     if (!$this->allowAutoRecordId() && !$this->getDefault('recordId')) {
         $this->setDefault('recordId', dmArray::first(array_keys($this->widgetSchema['recordId']->getChoices())));
     }
     parent::configure();
 }
 protected function renameSite()
 {
     $siteName = 'Diem demo';
     $this->log('Rename site to ' . $siteName);
     dmConfig::set('site_name', $siteName);
     foreach (dmDb::table('DmLayout')->findAll() as $layout) {
         $widget = $layout->getArea('top')->Zones[0]->Widgets[0];
         $values = $widget->values;
         if ('Diem' == dmArray::get($values, 'text')) {
             $values['text'] = 'Diem <em>demo</em>';
             $widget->values = $values;
             $widget->save();
         }
     }
 }
Exemple #24
0
 public function getWidgetType($moduleOrWidget, $action = null, $orNull = false)
 {
     if (is_array($moduleOrWidget) || $moduleOrWidget instanceof DmWidget) {
         list($module, $action) = array($moduleOrWidget['module'], $moduleOrWidget['action']);
     } else {
         $module = $moduleOrWidget;
     }
     $widgetType = dmArray::get(dmArray::get($this->getWidgetTypes(), $module, array()), $action);
     if (!$widgetType) {
         if ($orNull) {
             return null;
         }
         throw new dmException(sprintf("The %s/%s widget does not exist", $module, $action));
     }
     return $widgetType;
 }
Exemple #25
0
 public function getAppliedFiltersOnModule($module)
 {
     $appliedFilters = array();
     foreach ($this->getAttribute($module . '.filters', array(), 'admin_module') as $filter => $value) {
         if ($value) {
             if (is_array($value)) {
                 if (dmArray::get($value, 'text') || dmArray::get($value, 'is_empty') || dmArray::get($value, 'from') || dmArray::get($value, 'to')) {
                     $appliedFilters[] = $filter;
                 }
             } else {
                 $appliedFilters[] = $filter;
             }
         }
     }
     return $appliedFilters;
 }
 public function renderZone(array $zone)
 {
     $style = !$zone['width'] || $zone['width'] === '100%' ? '' : ' style="width: ' . $zone['width'] . ';"';
     $html = '<div id="dm_zone_' . $zone['id'] . '" class="' . dmArray::toHtmlCssClasses(array('dm_zone', 'dm_zone_' . $zone['id'], $zone['css_class'], $this->behaviorsManager->isZoneAttachable() ? 'dm_behaviors_attachable' : '')) . '"' . $style . '>';
     if ($this->user->can('zone_edit')) {
         $html .= '<a class="dm dm_zone_edit' . ($this->user->can('behavior_add') && $this->behaviorsManager->isZoneAttachable() ? ' dm_behaviors_droppable' : '') . '" title="' . $this->i18n->__('Edit this zone') . '"></a>';
     }
     if (($this->user->can('behavior_edit') || $this->user->can('behavior_delete')) && $this->behaviorsManager->isZoneAttachable()) {
         $html .= '<a class="dm dm_edit_behaviors_icon s16_gear s16" title="' . $this->i18n->__('Edit behaviors') . '"></a>';
     }
     $html .= '<div class="dm_widgets">';
     $html .= $this->renderZoneInner($zone);
     $html .= '</div>';
     $html .= '</div>';
     return $html;
 }
 protected function doRender()
 {
     if ($this->isCachable() && ($cache = $this->getCache())) {
         return $cache;
     }
     $vars = $this->getViewVars();
     $helper = $this->getHelper();
     $html = $helper->open('ol.dm_widget_content_gallery.list', array('json' => array('animation' => $vars['animation'], 'delay' => dmArray::get($vars, 'delay', 3))));
     foreach ($vars['medias'] as $media) {
         $html .= $helper->tag('li.element', $media['link'] ? $helper->link($media['link'])->text($media['tag']) : $media['tag']);
     }
     $html .= '</ol>';
     if ($this->isCachable()) {
         $this->setCache($html);
     }
     return $html;
 }
Exemple #28
0
 protected function findPageAndCultureForAnotherCulture($slug)
 {
     $i18n = $this->serviceContainer->getService('i18n');
     if (!$i18n->hasManyCultures()) {
         return false;
     }
     // search in all cultures
     $page = dmDb::query('DmPage p')->innerJoin('p.Translation t')->where('t.slug = ?', $slug)->fetchOne();
     if (!$page) {
         return false;
     }
     // use the default culture
     if ($page->get('Translation')->contains(sfConfig::get('sf_default_culture'))) {
         $culture = sfConfig::get('sf_default_culture');
     } else {
         $culture = dmArray::first(array_keys($page->get('Translation')->getData()));
     }
     return array($page, $culture);
 }
 protected function doRender()
 {
     if ($this->isCachable() && ($cache = $this->getCache())) {
         return $cache;
     }
     $vars = $this->getViewVars();
     if (!$vars['mediaTag']) {
         $html = '';
     } else {
         $html = $vars['mediaTag']->render();
     }
     if ($link = dmArray::get($vars, 'link')) {
         $html = $this->getHelper()->link($link)->text($html)->render();
     }
     if ($this->isCachable()) {
         $this->setCache($html);
     }
     return $html;
 }
 /**
  * @see sfProjectConfiguration
  */
 public function initConfiguration()
 {
     parent::initConfiguration();
     include $this->getConfigCache()->checkConfig('config/dm/config.yml');
     /*
      * Replace sf default culture by first culture in dm cultures configuration
      */
     sfConfig::set('sf_default_culture', dmArray::first(sfConfig::get('dm_i18n_cultures')));
     /*
      * Symfony 1.3 registers sfAutoloadAgain on dev env. This causes huge performance issues.
      */
     if ($this->isDebug()) {
         sfAutoloadAgain::getInstance()->unregister();
     }
     /*
      * Now that we have the project config, we can configure the doctrine cache
      */
     $this->configureDoctrineCache(Doctrine_Manager::getInstance());
 }