示例#1
0
 public function getFirstMedia()
 {
     if ($this->_invoker->contains($this->_options['mediaAlias'])) {
         return $this->_invoker->reference($this->_options['mediaAlias'])->getFirst();
     }
     return dmDb::query('DmMedia m, m.Folder f, m.' . $this->getGalleryRelClass() . ' rel')->where('rel.dm_record_id = ?', $this->_invoker->get('id'))->orderBy('rel.position ASC')->select('m.*, f.*')->fetchOne();
 }
 /**
  * @see sfTask
  */
 protected function execute($arguments = array(), $options = array())
 {
     throw new dmException('deprecated');
     $this->withDatabase();
     $page = dmDb::table('DmPage')->findOneByIdWithI18n($arguments['id'], $arguments['culture']);
     if (!$page instanceof DmPage) {
         throw new dmException('No page with id = ' . $arguments['id']);
     }
     $this->getContext()->setPage($page);
     $area = dmDb::query('DmArea a, a.Zones z, z.Widgets w')->select('a.id, z.id, w.module, w.action, w.value')->where('a.type = ? AND a.dm_page_view_id = ?', array('content', $page->get('PageView')->get('id')))->orderBy('z.position asc, w.position asc')->fetchArray();
     $widgetTypeManager = $dmContext->get('widget_type_manager');
     $html = '';
     foreach ($area[0]['Zones'] as $zone) {
         foreach ($zone['Widgets'] as $widget) {
             if (!in_array($widget['module'] . '.' . $widget['action'], self::$skipWidgets)) {
                 $widget['css_class'] = null;
                 $widgetViewClass = $widgetTypeManager->getWidgetType($widget['module'], $widget['action'])->getViewClass();
                 $widgetView = new $widgetViewClass($widget);
                 try {
                     $html .= $widgetView->toIndexableString();
                 } catch (Exception $e) {
                     $this->log($e->getMessage());
                 }
             }
         }
     }
     $indexableText = dmSearchIndex::cleanText($html);
     die($indexableText);
 }
 /**
  * Update changed documentation pages in database
  */
 protected function updateDatabase($branch)
 {
     $types = dmDb::query('Doc d')->select('d.type')->distinct()->fetchFlat();
     $cultures = sfConfig::get('dm_i18n_cultures');
     $originalCulture = sfDoctrineRecord::getDefaultCulture();
     foreach ($types as $type) {
         foreach ($cultures as $culture) {
             sfDoctrineRecord::setDefaultCulture($culture);
             $dir = dmOs::join($this->repo->getDir(), $type, $culture);
             $files = sfFinder::type('file')->name('/^\\d{2}\\s-\\s.+\\.markdown$/')->in($dir);
             foreach ($files as $file) {
                 $docName = preg_replace('/^\\d{2}\\s-\\s(.+)\\.markdown$/', '$1', basename($file));
                 $docRecord = dmDb::query('DocPage dp')->withI18n()->innerJoin('dp.Doc doc')->innerJoin('doc.Branch branch')->where('branch.number = ?', $branch)->andWhere('doc.type = ?', $type)->andWhere('dpTranslation.name = ?', $docName)->fetchOne();
                 if ($docRecord) {
                     $docText = file_get_contents($file);
                     if ($docRecord->text != $docText) {
                         $docRecord->text = $docText;
                         $docRecord->save();
                     }
                 }
             }
         }
     }
     sfDoctrineRecord::setDefaultCulture($originalCulture);
 }
 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');
         }
     }
 }
 public function getGroupNames()
 {
     $groups = dmDb::query('DmSetting s')->select('s.group_name')->groupBy('s.group_name')->fetchPDO();
     foreach ($groups as $index => $group) {
         $groups[$index] = $group[0];
     }
     return $groups;
 }
示例#6
0
 public function executeTest()
 {
     $widget = dmDb::query('DmWidget q')->withI18n()->where('q.id = ?', 272)->fetchOne();
     $widgetValue = $widget->value;
     $widget = $widget->toArray();
     $widget['value'] = $widgetValue;
     $this->html = $this->getService('page_helper')->renderWidget($widget);
 }
示例#7
0
 public function getUser()
 {
     $userId = $this->get('user_id');
     if (!isset(self::$usersCache[$userId])) {
         self::$usersCache[$userId] = $userId ? dmDb::query('DmUser u')->where('u.id = ?', $userId)->fetchRecord() : null;
     }
     return self::$usersCache[$userId];
 }
示例#8
0
 public function executeShow()
 {
     $query = $this->getShowQuery('b');
     $this->branch = $this->getRecord($query);
     $this->tuto = dmDb::query('DocPage p')->withI18n()->leftJoin('p.Doc d')->where('d.type = ?', 'tuto')->orderBy('p.position ASC')->fetchOne();
     $this->howTo = dmDb::query('Doc d')->withI18n()->where('d.type = ?', 'howto')->fetchOne();
     $this->openSourceProjects = dmDb::query('DocPage p')->withI18n()->where('pTranslation.name = ?', 'Open source projects')->fetchOne();
 }
 protected function createAdminUser()
 {
     dmDb::query('DmUser u')->delete()->where('u.username = ?', 'admin')->execute();
     $user = dmDb::table('DmUser')->create(array('username' => 'admin', 'email' => '*****@*****.**', 'is_active' => true, 'is_super_admin' => false));
     $user->setPassword('admin');
     $user->addGroupByName('demo');
     $user->save();
 }
示例#10
0
 /**
  * How many pages use this layout?
  */
 public function getNbPages()
 {
     $nb = 0;
     foreach ($this->get('PageViews') as $pageView) {
         $nb += dmDb::query('DmPage p')->where('p.module = ?', $pageView->module)->andWhere('p.action = ?', $pageView->action)->count();
     }
     return $nb;
 }
示例#11
0
文件: dmMail.php 项目: jdart/diem
 /**
  * Set a template to the mail
  *
  * @param mixed $templateName the template name, or a DmMailTemplateInstance
  * @return dmMail $this
  */
 public function setTemplate($templateName)
 {
     if ($templateName instanceof DmMailTemplate) {
         $this->template = $templateName;
     } elseif (!($this->template = dmDb::query('DmMailTemplate t')->where('t.name = ?', $templateName)->fetchRecord())) {
         $this->template = dmDb::create('DmMailTemplate', array('name' => $templateName));
     }
     return $this;
 }
 protected function getParentChoices()
 {
     $_parentChoices = dmDb::query('DmMediaFolder f')->where('f.lft < ? OR f.rgt > ?', array($this->folder->lft, $this->folder->rgt))->orderBy('f.lft')->select('f.id, f.level, f.rel_path')->fetchPDO();
     $parentChoices = array();
     foreach ($_parentChoices as $values) {
         $name = basename($values[2]) ? basename($values[2]) : 'root';
         $parentChoices[$values[0]] = str_repeat('&nbsp;&nbsp;', $values[1]) . '-&nbsp;' . $name;
     }
     return $parentChoices;
 }
示例#13
0
 public function executeGetAttributes(sfWebRequest $request)
 {
     $bm = $this->getService('behaviors_manager');
     $user = $this->getService('user');
     $this->forward404Unless($zone = dmDb::query('DmZone z')->where('z.id = ?', $request->getParameter('zone_id'))->select('z.width as width, z.css_class as css_class')->limit(1)->fetchPDO());
     if ($bm->isZoneAttachable() && ($user->can('behavior_add') || $user->can('behavior_edit') || $user->can('behavior_delete') || $user->can('behavior_sort'))) {
         $zone[0][1] = $zone[0][1] . '.dm_behaviors_attachable';
     }
     return $this->renderJson($zone[0]);
 }
示例#14
0
 protected function getFolderChoices()
 {
     $_folderChoices = dmDb::query('DmMediaFolder f')->orderBy('f.lft')->select('f.id, f.level, f.rel_path')->fetchPDO();
     $folderChoices = array();
     foreach ($_folderChoices as $values) {
         $name = basename($values[2]) ? basename($values[2]) : 'root';
         $folderChoices[$values[0]] = str_repeat('&nbsp;&nbsp;', $values[1]) . '-&nbsp;' . $name;
     }
     return $folderChoices;
 }
示例#15
0
 public function executeMyAccount()
 {
     if ($this->user = $this->getUser()->getDmUser()) {
         $this->plugins = dmDb::query('Plugin p')->where('p.created_by = ?', $this->user->id)->andWhere('p.is_active = ?', true)->orderByPosition()->fetchRecords();
         $this->preloadPages($this->plugins);
     } else {
         $this->form = $this->forms['DmSigninFront'] = new DmSigninFrontForm();
         unset($this->form['remember_me']);
     }
 }
示例#16
0
 /**
  * Set a template to the mail
  *
  * @param mixed $templateName the template name, or a DmMailTemplateInstance
  * @return dmMail $this
  */
 public function setTemplate($templateName)
 {
     if ($templateName instanceof DmMailTemplate) {
         $this->template = $templateName;
     } elseif (!($this->template = dmDb::query('DmMailTemplate t')->leftJoin('t.Decorator d')->where('t.name = ?', $templateName)->fetchRecord())) {
         $this->template = dmDb::table('DmMailTemplate')->createDefault($templateName);
     }
     $this->decorator = $this->template->getDecorator();
     return $this;
 }
示例#17
0
 protected function useDmRedirect($slug)
 {
     if ($dmRedirect = dmDb::query('DmRedirect r')->where('r.source = ?', $slug)->fetchRecord()) {
         if ($page = dmDb::table('DmPage')->findOneBySource($dmRedirect->dest)) {
             $redirectionUrl = $this->serviceContainer->getService('helper')->link($page)->getHref();
         } else {
             $redirectionUrl = $dmRedirect->dest;
         }
         return $redirectionUrl;
     }
 }
 /**
  * Try to guess default values
  * from last updated behavior
  * @return array default values
  */
 protected function getDefaultsFromLastUpdated(array $fields = array())
 {
     if ($this->dmBehavior->getDmBehaviorValue() != '') {
         return array_merge($this->dmBehavior->getDmBehaviorValue(), array('dm_behavior_enabled' => $this->dmBehavior->getDmBehaviorEnabled()));
     }
     $lastBehaviorValue = dmDb::query('DmBehavior b')->withI18n()->where('b.dm_behavior_key = ?', array($this->dmBehavior->getDmBehaviorKey()))->orderBy('b.updated_at desc')->limit(1)->select('b.id, bTranslation.dm_behavior_value as value')->fetchOneArray();
     if (!$lastBehaviorValue) {
         return array();
     }
     return json_decode((string) $lastBehaviorValue['value'], true);
 }
 protected function migrateUnchangedModels()
 {
     throw new dmException('hey, no !');
     foreach (dmProject::getAllModels() as $model) {
         $this->log('Empty ' . $model);
         dmDb::query($model)->delete()->execute();
     }
     $this->copyModels('DmMediaFolder DmLayout DmPage DmPermission DmGroup DmUser');
     $this->copyModels('DmGroupPermission DmuserPermission DmUserGroup DmRememberKey');
     $this->copyModels('DmMedia DmPageView');
     $this->copyModels('DmArea DmZone DmWidget');
     $this->copyModels('Article Comment Site Branch Version Plugin PluginComment PluginBranch');
 }
示例#20
0
 public function checkSlug($validator, $values)
 {
     if (!empty($values['slug'])) {
         $values['slug'] = dmString::urlize($values['slug'], true);
         $existingPageName = dmDb::query('DmPageTranslation t')->where('t.lang = ? AND t.slug = ?', array($this->object->lang, $values['slug']))->select('t.name')->fetchValue();
         if ($existingPageName) {
             $error = new sfValidatorError($validator, dm::getI18n()->__('The page "%1%" uses this slug', array('%1%' => $existingPageName)));
             // throw an error bound to the password field
             throw new sfValidatorErrorSchema($validator, array('slug' => $error));
         }
     }
     return $values;
 }
示例#21
0
 public function createAllPagesTranslations()
 {
     $cultures = $this->getOption('cultures');
     $pageIds = dmDb::table('DmPage')->createQuery('p')->select('p.id')->fetchFlat();
     $existingTranslations = array_flip(dmDb::query('DmPageTranslation p')->select('CONCAT(p.id, p.lang)')->fetchFlat());
     foreach ($pageIds as $pageId) {
         foreach ($cultures as $culture) {
             if (!isset($existingTranslations[$pageId . $culture])) {
                 $this->createPageTranslations($pageId);
             }
         }
     }
 }
示例#22
0
 public function checkModuleAction($validator, $values)
 {
     if (!empty($values['module']) && !empty($values['action'])) {
         foreach (array('module', 'action') as $key) {
             $values[$key] = dmString::modulize(str_replace('-', '_', dmString::slugify(dmString::underscore($values[$key]))));
         }
         $existingPage = dmDb::query('DmPage p')->where('p.module = ? AND p.action = ? and p.record_id = ? AND p.id != ?', array($values['module'], $values['action'], $this->object->record_id, $this->object->id))->fetchRecord();
         if ($existingPage) {
             $error = new sfValidatorError($validator, $this->getI18n()->__('The page "%1%" uses this module.action', array('%1%' => $existingPage->name)));
             // throw an error bound to the password field
             throw new sfValidatorErrorSchema($validator, array('action' => $error));
         }
     }
     return $values;
 }
示例#23
0
 protected function preTransform($text)
 {
     $text = parent::preTransform($text);
     if (strpos($text, '[/code]')) {
         $text = preg_replace_callback('#\\[code\\s?(\\w*)\\]((?:\\n|.)*)\\n\\[/code\\]#uU', array($this, 'formatCode'), $text);
     }
     if (strpos($text, '%latest_diem_version%')) {
         $version = dmDb::pdo('SELECT v.number FROM version v INNER JOIN branch b ON v.branch_id = b.id AND b.number = ? WHERE v.is_active = ? ORDER BY v.position ASC LIMIT 1', array('5.0', true))->fetchColumn();
         $text = str_replace('%latest_diem_version%', $version, $text);
     }
     if (strpos($text, '%latest_diem_download_url%')) {
         $version = dmDb::query('Version v')->innerJoin('v.Branch b')->where('b.number = ?', '5.0')->andWhere('v.is_active = ?', true)->orderBy('v.position ASC')->fetchOne();
         $text = str_replace('%latest_diem_download_url%', $this->helper->link($version->downloadUrl)->getAbsoluteHref(), $text);
     }
     return $text;
 }
示例#24
0
 /**
  * Try to guess default values
  * from last updated widget with same module.action
  * @return array default values
  */
 protected function getDefaultsFromLastUpdated(array $fields = array())
 {
     if ($this->dmWidget->get('value')) {
         return array_merge($this->dmWidget->getValues(), array('cssClass' => $this->dmWidget->get('css_class')));
     }
     $lastWidgetValue = dmDb::query('DmWidget w')->withI18n(null, null, 'w')->where('w.module = ? AND w.action = ?', array($this->dmWidget->get('module'), $this->dmWidget->get('action')))->orderBy('w.updated_at desc')->limit(1)->select('w.id, wTranslation.value as value')->fetchOneArray();
     $defaults = $this->getFirstDefaults();
     if (!$lastWidgetValue) {
         return $defaults;
     }
     $values = json_decode((string) $lastWidgetValue['value'], true);
     foreach ($fields as $field) {
         $defaults[$field] = dmArray::get($values, $field, dmArray::get($defaults, $field));
     }
     return $defaults;
 }
示例#25
0
 public function getAreas($culture = null)
 {
     if (null === $this->areas) {
         if (!$this->page instanceof DmPage) {
             throw new dmException('Can not fetch page areas because no page have been set');
         }
         $culture = null === $culture ? $this->serviceContainer->getParameter('user.culture') : $culture;
         $fallBackCulture = sfConfig::get('sf_default_culture');
         $areas = dmDb::query('DmArea a')->leftJoin('a.Zones z')->leftJoin('z.Widgets w')->leftJoin('w.Translation wTranslation WITH wTranslation.lang = ? OR wTranslation.lang = ?', array($culture, $fallBackCulture))->select('a.dm_layout_id, a.type, z.width, z.css_class, w.module, w.action, wTranslation.value, w.css_class')->where('a.dm_layout_id = ?', $this->page->getPageView()->getLayout()->get('id'))->orWhere('a.dm_page_view_id = ?', $this->page->getPageView()->get('id'))->orderBy('z.position asc, w.position asc')->fetchArray();
         /*
          * WARNING strange code
          * This code is to simulate widget i18n fallback,
          * which can not be achived
          * normally when hydrating with an array
          */
         foreach ($areas as $areaIndex => $area) {
             foreach ($area['Zones'] as $zoneIndex => $zone) {
                 foreach ($zone['Widgets'] as $widgetIndex => $widget) {
                     $value = null;
                     // there is a translation for $culture
                     if (isset($widget['Translation'][$culture])) {
                         $value = $widget['Translation'][$culture]['value'];
                     } elseif (isset($widget['Translation'][$fallBackCulture])) {
                         $value = $widget['Translation'][$fallBackCulture]['value'];
                     }
                     // assign the value to the widget array
                     $areas[$areaIndex]['Zones'][$zoneIndex]['Widgets'][$widgetIndex]['value'] = $value;
                     // unset the useless Translation array
                     unset($areas[$areaIndex]['Zones'][$zoneIndex]['Widgets'][$widgetIndex]['Translation']);
                 }
             }
         }
         /*
          * End of strange code
          */
         /**
          * Give nice keys to the areas array
          */
         $this->areas = array();
         foreach ($areas as $area) {
             $prefix = $area['dm_layout_id'] ? 'layout' : 'page';
             $this->areas[$prefix . '.' . $area['type']] = $area;
         }
         unset($areas);
     }
     return $this->areas;
 }
示例#26
0
 public function executeGallery(dmWebRequest $request)
 {
     $this->record = $this->getGalleryRecord($request);
     $this->form = new DmMediaForm();
     $this->form->setDefault('dm_media_folder_id', $this->record->getDmMediaFolder()->get('id'));
     $this->form->setMimeTypeWhiteList('web_images');
     if ($request->isMethod('post') && $this->form->bindAndValid($request)) {
         $media = $this->form->save();
         $this->record->addMedia($media);
         $this->getUser()->logInfo('The item was updated successfully.');
         return $this->redirectBack();
     }
     $this->getService('bread_crumb')->setRecord($this->record);
     $this->context->getEventDispatcher()->connect('dm.bread_crumb.filter_links', array($this, 'listenToBreadCrumbFilterLinksEvent'));
     $this->galleryOptions = array('model' => get_class($this->record), 'pk' => $this->record->getPrimaryKey());
     $this->medias = dmDb::query('DmMedia m, m.Folder f, m.' . $this->record->getGalleryRelClass() . ' rel')->where('rel.dm_record_id = ?', $this->record->get('id'))->orderBy('rel.position ASC')->select('m.*, f.*, rel.id as dm_gallery_rel_id')->fetchRecords();
 }
示例#27
0
 public function executePreview()
 {
     $this->module = $this->autoSeo->getTargetDmModule();
     $pageId = dmDb::query('DmPage p')->select('p.id, RANDOM() as rand')->where('p.module = ? AND p.action = ?', array($this->module->getKey(), 'show'))->orderBy('rand')->limit(1)->fetchValue();
     if ($pageId && ($this->page = dmDb::table('DmPage')->findOneByIdWithI18n($pageId))) {
         try {
             $seoSynchronizer = $this->getService('seo_synchronizer');
             $seoSynchronizer->setCulture($this->getUser()->getCulture());
             $this->metas = $seoSynchronizer->compilePatterns($this->rules, $seoSynchronizer->getReplacementsForPatterns($this->module, $this->rules, $this->page->getRecord()), $this->page->getNode()->getParent()->get('slug'));
         } catch (Exception $e) {
             $this->getUser()->logError($e->getMessage(), false);
             if (sfConfig::get('dm_debug')) {
                 throw $e;
             }
         }
     }
 }
 public function saveSortOrder()
 {
     try {
         $behaviors = json_decode($this->getValue('behaviors'), true);
         DmBehaviorTable::getInstance()->getConnection()->beginTransaction();
         foreach ($behaviors as $behavior) {
             $tmp = dmDb::query('DmBehavior b')->where('id = ?', $behavior['dm_behavior_id'])->fetchOne();
             $tmp->setPosition($behavior['dm_behavior_sequence']);
             $tmp->save();
         }
         DmBehaviorTable::getInstance()->getConnection()->commit();
         return true;
     } catch (Exception $e) {
         DmBehaviorTable::getInstance()->getConnection()->rollback();
         return false;
     }
 }
示例#29
0
 protected function preloadHitPages(array $hits)
 {
     $pageIds = array();
     foreach ($hits as $hit) {
         $pageIds[] = $hit->getPageId();
     }
     $pages = dmDb::query('DmPage p INDEXBY p.id')->whereIn('p.id', $pageIds)->withI18n()->fetchRecords();
     foreach ($hits as $index => $hit) {
         if (empty($pages[$hit->getPageId()])) {
             unset($hits[$index]);
         } else {
             $hit->setPage($pages[$hit->getPageId()]);
         }
     }
     unset($pages);
     return $hits;
 }
示例#30
0
 public function executeExportSentences(dmWebRequest $request)
 {
     $catalogue = $this->getObjectOrForward404($request);
     $units = dmDb::query('DmTransUnit t')->select('t.source, t.target')->where('t.dm_catalogue_id = ?', $catalogue->getId())->fetchArray();
     $data = array();
     if (count($units) > 0) {
         foreach ($units as $unit) {
             $data[$unit['source']] = $unit['target'];
         }
     }
     $data = sfYaml::dump($data);
     $name = $catalogue->getName();
     if (($pos = strrpos($name, '.' . $catalogue->getTargetLang())) !== false) {
         $name = substr($name, 0, $pos);
     }
     $this->download($data, array('file_name' => sprintf('%s.%s_%s.yml', $name, $catalogue->getSourceLang(), $catalogue->getTargetLang()), 'mime_type' => 'application/octet-stream'));
 }