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;
 }
예제 #2
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);
 }
예제 #3
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);
 }
예제 #4
0
  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;
  }
 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 . '"'));
 }
예제 #6
0
  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;
  }
예제 #7
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'));
 }
 /**
  * @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();
 }
예제 #9
0
파일: dmCoreUser.php 프로젝트: jdart/diem
 /**
  * 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;
 }
예제 #10
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') : '');
 }
 public function getWidgetValues()
 {
     $values = parent::getWidgetValues();
     if (dmArray::get($values, 'removeMedia')) {
         $values['mediaId'] = null;
     }
     unset($values['removeMedia']);
     return $values;
 }
예제 #12
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);
 }
예제 #13
0
 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());
 }
예제 #14
0
  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);
  }
예제 #15
0
파일: dmLorem.php 프로젝트: theolymp/diem
 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);
 }
예제 #16
0
 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;
 }
예제 #17
0
 public function field($attributes = array())
 {
     $attributes = dmString::toArray($attributes);
     $parentAttributes = $this->parent->getWidget()->offsetGet($this->name)->getAttributes();
     $attributes['class'] = array_merge((array) dmArray::get($parentAttributes, 'class'), dmArray::get($attributes, 'class', array()));
     if ($this->isRequired) {
         $attributes['class'][] = 'required';
     }
     if ($this->error) {
         $attributes['class'][] = 'has_error';
     }
     $attributes['class'] = dmArray::toHtmlCssClasses($attributes['class']);
     $this->htmlBuffer .= parent::render(array_merge($parentAttributes, $attributes));
     return $this;
 }
예제 #18
0
 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();
         }
     }
 }
예제 #19
0
파일: dmAdminUser.php 프로젝트: rafix/diem
 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;
 }
예제 #20
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;
 }
예제 #21
0
 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;
 }
예제 #22
0
 public function get($app = null, $env = null, $culture = null)
 {
     $app = null === $app ? sfConfig::get('sf_app') : $app;
     $env = null === $env ? sfConfig::get('sf_environment') : $env;
     $culture = null === $culture ? $this->culture : $culture;
     if ($config = dmConfig::get('base_urls')) {
         $knownAppUrls = json_decode($config, true);
     } else {
         $knownAppUrls = array();
     }
     $appUrlKey = implode('-', array($app, $env, $culture));
     if (!($appUrl = dmArray::get($knownAppUrls, $appUrlKey))) {
         if (!($script = $this->guessBootScriptFromWebDir($app, $env))) {
             throw new dmException(sprintf('Diem can not guess %s app url', $app));
         }
         $appUrl = $this->requestContext['absolute_url_root'] . '/' . $script;
     }
     return $appUrl;
 }
예제 #23
0
 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;
 }
예제 #24
0
 protected function filterViewVars(array $vars = array())
 {
     $vars = parent::filterViewVars($vars);
     if (!empty($vars['mediaId']) || $this->isRequiredVar('mediaId')) {
         $media = dmDb::table('DmMedia')->findOneByIdWithFolder($vars['mediaId']);
         if (!$media instanceof DmMedia) {
             throw new dmException('No DmMedia found for media id : ' . $vars['mediaId']);
         }
         $mediaTag = $this->getHelper()->media($media);
         if (!empty($vars['width']) || !empty($vars['height'])) {
             $mediaTag->size(dmArray::get($vars, 'width'), dmArray::get($vars, 'height'));
         }
     } else {
         $media = null;
         $mediaTag = null;
     }
     $vars['media'] = $media;
     $vars['mediaTag'] = $mediaTag;
     return $vars;
 }
 /**
  * @see sfTask
  */
 protected function execute($arguments = array(), $options = array())
 {
     $this->logSection('Diem Extended', 'Generate admin modules');
     $modules = $this->get('module_manager')->getModules();
     $existingModules = array();
     foreach ($modules as $moduleKey => $module) {
         if ($pluginName = $module->getPluginName()) {
             if ($module->isOverridden()) {
                 continue;
             }
             $module->setOption('generate_dir', dmOs::join($this->configuration->getPluginConfiguration($pluginName)->getRootDir(), 'modules', $module->getSfName()));
         } else {
             $module->setOption('generate_dir', dmOs::join(sfConfig::get('sf_apps_dir'), 'admin/modules', $module->getSfName()));
         }
         if (is_dir($module->getOption('generate_dir'))) {
             $existingModules[] = $moduleKey;
         }
     }
     $moduleToClear = dmArray::get($options, 'clear');
     foreach ($modules as $moduleKey => $module) {
         if ($moduleToClear && $moduleKey !== $moduleToClear) {
             //        $this->log('Skip '.$moduleKey);
             continue;
         }
         if (!$module->hasModel() || !$module->hasAdmin()) {
             //        $this->log('Skip module without model or no admin '.$moduleKey);
             continue;
         }
         if (in_array($moduleKey, $existingModules) && !$moduleToClear) {
             //        $this->log('Skip existing module '.$moduleKey);
             continue;
         }
         //      $this->log('Will generate '.$moduleKey.' admin module');
         $task = new dmAdminDoctrineGenerateModuleTask($this->dispatcher, $this->formatter);
         $task->setCommandApplication($this->commandApplication);
         $task->setConfiguration($this->configuration);
         $task->run(array('admin', $module->getKey(), $module->getModel()), array('theme' => 'dmAdmin', 'env' => $options['env'], 'route-prefix' => $module->getUnderscore(), 'with-doctrine-route' => true, 'generate-in-cache' => true, 'non-verbose-templates' => true, 'singular' => $moduleKey, 'plural' => $moduleKey . 's', 'from-admin-generate' => 'true'));
     }
     $this->get('cache_manager')->clearAll();
 }
 public function getWidgetValues()
 {
     $values = parent::getWidgetValues();
     if ($media = dmDb::table('DmMedia')->findOneByIdWithFolder($values['mediaId'])) {
         if ($media->isImage()) {
             if (empty($values['width'])) {
                 if ($values['widget_width']) {
                     $values['width'] = $values['widget_width'];
                     $values['height'] = (int) ($media->getHeight() * ($values['widget_width'] / $media->getWidth()));
                 } else {
                     $values['width'] = $media->getWidth();
                 }
             } elseif (empty($values['height'])) {
                 $values['height'] = (int) ($media->getHeight() * ($values['width'] / $media->getWidth()));
             }
         }
     }
     unset($values['widget_width']);
     $values['background'] = dmArray::get($values, 'background', $this->getFirstDefault('background'), true);
     $values['method'] = dmArray::get($values, 'method', $this->getFirstDefault('method'), true);
     return $values;
 }
 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), 'pager' => '#mediaPager' . $this->widget['id'])));
     foreach ($vars['medias'] as $media) {
         $html .= $helper->tag('li.element', $media['link'] ? $helper->link($media['link'])->text($media['tag']) : $media['tag']);
     }
     $html .= '</ol>';
     // add media numbers
     if (isset($vars['show_pager']) && $vars['show_pager']) {
         $html .= $helper->open('div#mediaPager' . $this->widget['id'] . '.pager');
         $html .= $helper->close('div');
     }
     if ($this->isCachable()) {
         $this->setCache($html);
     }
     return $html;
 }
예제 #28
0
 public function executeIndex(dmWebRequest $request)
 {
     if ($this->getUser()->can('google_analytics')) {
         $this->form = new dmGoogleAnalyticsForm();
         $this->form->setGapi($this->getService('gapi'));
         if ($request->isMethod('post')) {
             dmConfig::set('ga_key', dmArray::get($request->getParameter($this->form->getName()), 'key'));
             if ($this->form->bindAndValid($request)) {
                 $this->form->save();
                 return $this->redirect('@dm_google_analytics');
             }
         }
     }
     $this->gapiConnected = false;
     if (dmConfig::get('ga_token')) {
         try {
             $this->getService('gapi')->authenticate(null, null, dmConfig::get('ga_token'));
             $this->gapiConnected = true;
         } catch (dmGapiException $e) {
             // bad token
         }
     }
 }
 protected function tryToSortWithForeignColumn(Doctrine_Query $query, array $sort)
 {
     $table = $this->getDmModule()->getTable();
     if ('integer' === dmArray::get($table->getColumnDefinition($sort[0]), 'type')) {
         if ($table->isI18nColumn($sort[0])) {
             $query->addOrderBy(sprintf('%s.%s %s', $query->getJoinAliasForRelationAlias($table->getComponentName(), 'Translation'), $sort[0], $sort[1]));
             // Success, skip default sorting by local column
             return;
         } elseif ($relation = $table->getRelationHolder()->getLocalByColumnName($sort[0])) {
             if ($relation instanceof Doctrine_Relation_LocalKey && ($foreignTable = $relation->getTable()) instanceof dmDoctrineTable) {
                 if (($foreignColumn = $foreignTable->getIdentifierColumnName()) != 'id') {
                     if (!($joinAlias = $query->getJoinAliasForRelationAlias($table->getComponentName(), $relation->getAlias()))) {
                         $query->leftJoin(sprintf('%s.%s %s', $query->getRootAlias(), $relation->getAlias(), $relation->getAlias()));
                         $joinAlias = $relation->getAlias();
                         if ($foreignTable->isI18nColumn($foreignColumn)) {
                             $query->leftJoin(sprintf('%s.%s %s', $joinAlias, 'Translation', $joinAlias . 'Translation'));
                         }
                     }
                     if ($foreignTable->isI18nColumn($foreignColumn)) {
                         $query->addOrderBy(sprintf('%s.%s %s', $joinAlias . 'Translation', $foreignColumn, $sort[1]));
                     } else {
                         $query->addOrderBy(sprintf('%s.%s %s', $joinAlias, $foreignColumn, $sort[1]));
                     }
                     // Success, skip default sorting by local column
                     return;
                 }
             }
         }
     } elseif ($table->isI18nColumn($sort[0])) {
         $query->addOrderBy(sprintf('%s.%s %s', $query->getJoinAliasForRelationAlias($table->getComponentName(), 'Translation'), $sort[0], $sort[1]));
         // Success, skip default sorting by local column
         return;
     }
     if ($table->hasField($sort[0])) {
         $query->addOrderBy($sort[0] . ' ' . $sort[1]);
     }
 }
 public function renderArea($name, $options = array())
 {
     $options = dmString::toArray($options);
     //Set id of page we need
     $this->global_area_id = dmArray::get($options, 'global_area', null);
     unset($options['global_area']);
     $tagName = $this->getAreaTypeTagName($name);
     $area = $this->getArea($name);
     list($prefix, $type) = explode('.', $name);
     $options['class'] = array_merge(dmArray::get($options, 'class', array()), array('dm_area', 'dm_' . $prefix . '_' . $type, 'dm_area_' . $area['id'], $prefix == 'layout' ? 'dm_layout_shared' : '', $this->behaviorsManager->isAreaAttachable() ? 'dm_behaviors_attachable' : ''));
     $options['id'] = dmArray::get($options, 'id', 'dm_area_' . $area['id']);
     $html = '';
     /*
      * Add a content id for accessibility purpose ( access link )
      */
     if ('content' === $type) {
         $html .= '<div id="dm_content">';
     }
     $html .= $this->helper->open($tagName, $options);
     if ($this->behaviorsManager->isAreaAttachable()) {
         $html .= '<a class="dm dm_area_edit' . ($this->user->can('behavior_add') ? ' dm_behaviors_droppable' : '') . '">' . ('content' === $type ? $this->i18n->__('Content') : $this->i18n->__('Layout')) . '</a>';
         if ($this->user->can('behavior_edit') || $this->user->can('behavior_delete')) {
             $html .= '<a class="dm dm_edit_behaviors_icon dm_edit_behaviors_area_icon s16_gear s16" title="' . $this->i18n->__('Edit behaviors') . '"></a>';
         }
     }
     $html .= '<div class="dm_zones clearfix">';
     $html .= $this->renderAreaInner($area);
     $html .= '</div>';
     $html .= sprintf('</%s>', $tagName);
     /*
      * Add a content id for accessibility purpose ( access links )
      */
     if ('content' === $type) {
         $html .= '</div>';
     }
     return $html;
 }