public static function getDmConfiguration() { $moduleManager = dmContext::getInstance()->getModuleManager(); // homepage first $config = array('homepage' => array('class' => 'sfRoute', 'url' => '/', 'params' => array('module' => 'dmAdmin', 'action' => 'index'))); // media library special route if ($dmMediaLibraryModule = $moduleManager->getModuleOrNull('dmMediaLibrary')) { $baseUrl = implode('/', array(dmString::slugify($dmMediaLibraryModule->getSpace()->getType()->getPublicName()), dmString::slugify($dmMediaLibraryModule->getSpace()->getPublicName()), dmString::slugify($dmMediaLibraryModule->getPlural()))); $config['dm_media_library_path'] = array('class' => 'sfRoute', 'url' => $baseUrl . '/path/:path', 'params' => array('module' => 'dmMediaLibrary', 'action' => 'path', 'path' => ''), 'requirements' => array('path' => '.*')); } // module routes foreach ($moduleManager->getModules() as $module) { if (!$module->hasAdmin()) { continue; } $baseUrl = implode('/', array(dmString::slugify($module->getSpace()->getType()->getPublicName()), dmString::slugify($module->getSpace()->getPublicName()), dmString::slugify($module->getPlural()))); $config[$module->getUnderscore()] = array('class' => 'sfRoute', 'url' => $baseUrl . '/:action/*', 'params' => array('module' => $module->getSfName(), 'action' => 'index')); } // static routes $config['default'] = array('class' => 'sfRoute', 'url' => '/+/:module/:action/*'); $config['signin'] = array('class' => 'sfRoute', 'url' => '/security/signin', 'params' => array('module' => 'dmUserAdmin', 'action' => 'signin')); $config['signout'] = array('class' => 'sfRoute', 'url' => '/security/signout', 'params' => array('module' => 'dmUserAdmin', 'action' => 'signout')); $config['dm_module_type'] = array('class' => 'sfRoute', 'url' => '/:moduleTypeName', 'params' => array('module' => 'dmAdmin', 'action' => 'moduleType')); $config['dm_module_space'] = array('class' => 'sfRoute', 'url' => '/:moduleTypeName/:moduleSpaceName', 'params' => array('module' => 'dmAdmin', 'action' => 'moduleSpace')); return $config; }
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; }
protected function loadTemplate(DmMailTemplate $template, array $vars) { $culture = $this->serviceContainer->getService('user')->getCulture(); $fileName = dmOs::join(sfConfig::get('sf_cache_dir'), 'mail_templates', sprintf('%s-%s-%s.php', dmString::slugify($template->get('name')), $culture, dmString::slugify($template->get('updated_at')))); if (!file_exists($fileName)) { $this->buildTemplate($template, $fileName, $vars); } return $fileName; }
protected function getModuleTypeBySlug($slug) { foreach ($this->context->getModuleManager()->getTypes() as $type) { if (dmString::slugify($type->getPublicName()) == $slug) { return $type; } } return null; }
protected function configureFromData($data) { if (!$this->getOption('file_name')) { $this->setOption('file_name', dmString::slugify(dmConfig::get('site_name')) . '-' . dmString::random(8)); } if (!$this->getOption('file_size')) { $this->setOption('file_size', strlen($data)); } }
public function checkSlug($validator, $values) { if (!empty($values['slug'])) { $values['slug'] = dmString::slugify($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; }
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; }
public function _doHeaders_callback_atx($matches) { $level = strlen($matches[1]); $attr = $this->_doHeaders_attr($id =& $matches[3]); $text = $this->runSpanGamut($matches[2]); if ($this->options['auto_header_id'] && false === strpos($attr, 'id="')) { $id = ''; if (1 !== $level && !empty($this->headerIdStack[$level - 1])) { $id = $this->headerIdStack[$level - 1] . ':'; } $id .= dmString::slugify($text); if (!empty($id)) { $attr = ' id="' . $id . '"'; if ($level < 6) { $this->headerIdStack[$level] = $id; } } } $block = "<h{$level}{$attr}>" . $text . "</h{$level}>"; return "\n" . $this->hashBlock($block) . "\n\n"; }
public function execute($configFiles) { $config = array(); $behaviors = array(); foreach ($configFiles as $file) { $tmp = $this->parseYaml($file); if (!isset($tmp['dmBehaviors'])) { continue; } foreach ($tmp['dmBehaviors'] as $key => $value) { $sectionKey = dmString::slugify($value['section']); if (!isset($config[$sectionKey])) { $config[$sectionKey] = array('section_name' => $value['section'], 'behaviors' => array()); } $config[$sectionKey]['behaviors'][$key] = array('name' => isset($value['name']) ? $value['name'] : dmString::humanize($key), 'icon' => isset($value['icon']) ? $value['icon'] : '/dmCorePlugin/images/16/gear.png', 'form' => isset($value['form']) ? $value['form'] : 'dm' . dmString::camelize($key) . 'BehaviorForm', 'view' => isset($value['view']) ? $value['view'] : 'dm' . dmString::camelize($key) . 'BehaviorView', 'cache' => isset($value['cache']) ? (bool) $value['cache'] : true); $behaviors[$key] = $config[$sectionKey]['behaviors'][$key]; } } $retval = sprintf("<?php\n" . "// auto-generated by %s\n" . "// date: %s\nsfConfig::set('dm_behaviors_menu_items', \n%s\n);\n sfConfig::set('dm_behaviors', \n%s\n); \n ?>", __CLASS__, date('Y/m/d H:i:s'), var_export($config, true), var_export($behaviors, true)); return $retval; }
protected function doUpdateObject($values) { $parent = dmDb::table('DmPage')->find($values['parent_id']); if (!$parent instanceof DmPage) { throw new dmException('Create page with unknown parent ' . $values['parent_id']); } parent::doUpdateObject($values); $this->object->module = $parent->module; $action = dmString::modulize(str_replace('-', '_', dmString::slugify($values['name']))); if (dmDb::query('DmPage p')->where('p.module = ? AND p.action = ?', array($this->object->module, $action))->exists()) { $iterator = 2; while (dmDb::query('DmPage p')->where('p.module = ? AND p.action = ?', array($this->object->module, $action . $iterator))->exists()) { $iterator++; } $action .= $iterator; } $this->object->action = $action; $this->object->title = $this->object->name; $this->object->Node->insertAsLastChildOf($parent); $this->object->PageView->Layout = dmDb::table('DmLayout')->find($values['dm_layout_id']); $this->object->PageView->save(); $this->object->save(); }
public function compilePatterns(array $patterns, array $replacements, $parentSlug) { $values = array(); foreach ($patterns as $field => $pattern) { if ($field === 'slug') { $slugReplacements = array(); foreach ($replacements as $key => $replacement) { $slugReplacements[$key] = dmString::slugify($replacement); } $value = strtr($pattern, $slugReplacements); // add parent slug if ($pattern[0] !== '/') { $value = $parentSlug . '/' . $value; } $value = trim($value, '/'); if (false !== strpos($value, '//')) { $value = preg_replace('|(/{2,})|', '/', $value); } } elseif ($field === 'title') { $value = ucfirst(strtr($pattern, $replacements)); } else { $value = strtr($pattern, $replacements); $value = strip_tags($value); } $values[$field] = $this->truncateValueForField(trim($value), $field); } return $values; }
protected function renderLiOpenTag() { $classes = array(); $id = $this->getOption('show_id') ? dmString::slugify($this->getRoot()->getName() . '-' . $this->getName()) : null; $link = $this->getLink(); if ($this->isFirst()) { $classes[] = 'first'; } if ($this->isLast()) { $classes[] = 'last'; } if ($this->getOption('li_class')) { $classes[] = $this->getOption('li_class'); } if ($link && $link->isCurrent()) { $classes[] = $link->getOption('current_class'); } elseif ($link && $link->isParent()) { $classes[] = $link->getOption('parent_class'); } return '<li' . ($id ? ' id="' . $id . '"' : '') . (!empty($classes) ? ' class="' . implode(' ', $classes) . '"' : '') . '>'; }
<?php require_once dirname(__FILE__) . '/helper/dmUnitTestHelper.php'; $helper = new dmUnitTestHelper(); $helper->boot(); $t = new lime_test(53); $t->comment('iconv available : ' . function_exists('iconv')); $t->is(dmString::slugify(" phrâse avèc dés accënts "), $expected = "phrase-avec-des-accents", $expected); $t->is(dmString::slugify("fonctionnalité"), $expected = "fonctionnalite", $expected); $hexTests = array(array('ffffff', 'FFFFFF'), array('#ffffff', 'FFFFFF'), array('#0Cd4fe', '0CD4FE'), array('aaa', null), array('fffff', null), array('fffxff', null)); foreach ($hexTests as $hexTest) { $t->is(dmString::hexColor($hexTest[0]), $hexTest[1], 'dmString::hexColor(' . $hexTest[0] . ') = ' . (null === $hexTest[1] ? 'NULL' : $hexTest[1])); } $t->is(dmString::lcfirst('TEST'), 'tEST', 'lcfirst test'); $t->is(dmString::lcfirst('another test'), 'another test', 'lcfirst test'); // ::retrieveOptFromString() $t->diag('::retrieveOptFromString()'); // Empty string $t->diag(' ::retrieveOptFromString() empty string'); $string = ''; $opt = array('aa' => 'bb'); $originalOpt = $opt; $t->is_deeply(dmString::retrieveOptFromString($string, $opt), null, '::retrieveOptFromString() with an empty string returns null'); $t->is_deeply($opt, $originalOpt, '::retrieveOptFromString() with an empty string does not modify opt'); $t->is_deeply($string, '', '::retrieveOptFromString() with an empty string does not modify string'); // Non-empty string $t->diag(' ::retrieveOptFromString() non-empty string'); $string = 'x=y'; $opt = array('aa' => 'bb'); dmString::retrieveOptFromString($string, $opt); $t->is_deeply($opt, array('aa' => 'bb', 'x' => 'y'), '::retrieveOptFromString() merges the options');
/** * Physically creates asset * * @param string $asset_path path to the asset original file * @param bool $move do move or just copy ? */ public function create(sfValidatedFile $file) { $this->file = $this->getAvailableFileName(dmString::slugify(dmOs::getFileWithoutExtension($file->getOriginalName())) . dmOs::getFileExtension($file->getOriginalName(), true)); $this->clearCache(); $file->save($this->getFullPath()); $this->refreshFromFile(); return $this; }
$helper->updatePageTreeWatcher($t); } catch (Exception $e) { $t->skip('Not supported on this server: ' . $e->getMessage(), $nbTests); return; } $t->ok(true, sprintf('Seo updated in %01.2f s', $timer->getElapsedTime())); foreach (dmDb::table('dmTestPost')->findAll() as $post) { if (!($page = $post->getDmPage())) { $t->skip('Post ' . $post . ' has no page', 6); continue; } $page->refresh(true); $categ = $page->getNode()->getParent()->getRecord(); $domain = $page->getNode()->getParent()->getNode()->getParent()->getRecord(); $t->is($post->isActive, $page->isActive, 'is_active field synchronized to ' . ($post->isActive ? 'TRUE' : 'FALSE')); $slug = 'dm-test-domains/' . $domain->id . '-' . dmString::slugify($domain->title) . '/' . $categ->id . '-' . dmString::slugify($categ->name) . '/' . dmString::slugify($post->title) . '-' . $post->id; $slug = dmSeoSynchronizer::truncateValueForField($slug, 'slug'); $t->is($page->slug, $slug, 'slug : ' . $slug); $name = 'Post : ' . trim($post->title); $name = dmSeoSynchronizer::truncateValueForField($name, 'name'); $t->is($page->name, $name, 'name : ' . $name); $title = ucfirst(trim($post->title) . ' | ' . trim($categ->name)); $title = dmSeoSynchronizer::truncateValueForField($title, 'title'); $t->is($page->title, $title, 'title : ' . $title); $h1 = trim($post->title); $h1 = dmSeoSynchronizer::truncateValueForField($h1, 'h1'); $t->is($page->h1, $h1, 'h1 : ' . $h1); $description = dmSeoSynchronizer::truncateValueForField(dmMarkdown::brutalToText($post->body), 'description'); $t->is($page->description, $description ? $description : null, 'description : ' . $description); } $t->comment('Add inactive domain');
protected function createPage($module, $action, $name = null, $slug = null) { $name = $name ? $name : $module . '.' . $action; $slug = $slug ? $slug : dmString::slugify($name); return dmDb::create('DmPage', array('module' => $module, 'action' => $action, 'name' => $name, 'slug' => $slug)); }
public function getModuleSpaceUrl(dmModuleSpace $space) { return '@dm_module_space?moduleTypeName=' . dmString::slugify($space->getType()->getPublicName()) . '&moduleSpaceName=' . dmString::slugify($space->getPublicName()); }
use_stylesheet('admin.configPanel'); use_javascript('lib.ui-tabs'); use_javascript('core.tabForm'); use_javascript('admin.configPanel'); echo _open('div.dm_config_panel.mt10'); echo _open('ul'); foreach ($groups as $group) { echo _tag('li', sprintf('<a href="#%s">%s</a>', 'dm_setting_group_' . dmString::slugify($group), __(dmString::humanize($group)))); } echo _close('ul'); echo $form->open('.dm_form.list'); foreach ($settings as $group => $groupSettings) { if ('internal' == $group) { continue; } echo _open('div#dm_setting_group_' . dmString::slugify($group)); echo _tag('h2', __(dmString::humanize($group))); echo _open('ul.dm_setting_group.clearfix'); $it = 0; foreach ($groupSettings as $setting) { $settingName = $setting->get('name'); if (!($it % 2)) { echo _close('ul') . _open('ul.dm_setting_group.clearfix'); } ++$it; echo _tag('li.dm_form_element.clearfix.setting_' . $setting->type, $form[$settingName]->label()->field()->error() . _tag('div.dm_help_wrap', escape(__($form[$settingName]->getHelp())))); } echo _close('ul'); echo _close('div'); } echo $form->renderSubmitTag(__('Save modifications'));
<?php require_once dirname(__FILE__) . '/helper/dmUnitTestHelper.php'; $helper = new dmUnitTestHelper(); $helper->boot(); $t = new lime_test(59); $t->comment('iconv available : ' . function_exists('iconv')); $t->is(dmString::slugify(" phrâse avèc dés accënts "), $expected = "phrase-avec-des-accents", $expected); $t->is(dmString::slugify("fonctionnalité"), $expected = "fonctionnalite", $expected); $t->is(dmString::urlize(" phrâse avèc dés accënts "), $expected = "phrase-avec-des-accents", $expected); $t->is(dmString::urlize("fonctionnalité"), $expected = "fonctionnalite", $expected); $t->is(dmString::slugify("an-url.htm"), $expected = "an-url-htm", $expected); $t->is(dmString::slugify("an-url.html"), $expected = "an-url-html", $expected); $t->is(dmString::urlize("an-url.htm"), $expected = "an-url.htm", $expected); $t->is(dmString::urlize("an-url.html"), $expected = "an-url.html", $expected); $hexTests = array(array('ffffff', 'FFFFFF'), array('#ffffff', 'FFFFFF'), array('#0Cd4fe', '0CD4FE'), array('aaa', null), array('fffff', null), array('fffxff', null)); foreach ($hexTests as $hexTest) { $t->is(dmString::hexColor($hexTest[0]), $hexTest[1], 'dmString::hexColor(' . $hexTest[0] . ') = ' . (null === $hexTest[1] ? 'NULL' : $hexTest[1])); } $t->is(dmString::lcfirst('TEST'), 'tEST', 'lcfirst test'); $t->is(dmString::lcfirst('another test'), 'another test', 'lcfirst test'); // ::retrieveOptFromString() $t->diag('::retrieveOptFromString()'); // Empty string $t->diag(' ::retrieveOptFromString() empty string'); $string = ''; $opt = array('aa' => 'bb'); $originalOpt = $opt; $t->is_deeply(dmString::retrieveOptFromString($string, $opt), null, '::retrieveOptFromString() with an empty string returns null'); $t->is_deeply($opt, $originalOpt, '::retrieveOptFromString() with an empty string does not modify opt'); $t->is_deeply($string, '', '::retrieveOptFromString() with an empty string does not modify string');
public function getAnchor() { return 'download-branch-' . dmString::slugify($this->get('number')); }
protected function updateListPages() { $projectModules = $this->moduleManager->getProjectModules(); foreach ($projectModules as $key => $module) { if (!$module->hasListPage()) { unset($projectModules[$key]); } } $projectModuleKeys = array_keys($projectModules); $_listPages = dmDb::pdo('SELECT p.id, p.module FROM dm_page p WHERE p.action = ?', array('list'))->fetchAll(PDO::FETCH_ASSOC); $listPages = array(); foreach ($_listPages as $_listPage) { $listPages[$_listPage['module']] = $_listPage['id']; } foreach ($projectModules as $moduleKey => $module) { /* * Only root modules, which have no parent, need a list page */ if (!isset($listPages[$moduleKey])) { if (isset($listPages[strtolower($moduleKey)])) { // fix page module dmDb::table('DmPage')->createQuery()->update('DmPage')->where('id = ?', $listPages[strtolower($moduleKey)])->set('module', "'" . $moduleKey . "'")->execute(); } else { // create page dmDb::create('DmPage', array('module' => $moduleKey, 'action' => 'list', 'name' => $module->getPlural(), 'title' => $module->getPlural(), 'slug' => dmString::slugify($module->getPlural()), 'description' => $module->getPlural()))->getNode()->insertAsLastChildOf(dmDb::table('DmPage')->getTree()->fetchRoot()); } } } }
<?php use_helper('Date'); use_stylesheet('lib.ui-tabs'); use_javascript('lib.ui-tabs'); use_javascript('admin.sitemap'); echo _open('div.dm_sitemap.mt10'); echo sprintf('%s%s%s', sprintf('<form style="text-align: center" method="post" class="dm_sitemap_generate_form" action="%s">', _link('@dm_sitemap?action=generate')->getHref()), sprintf('<input type="submit" value="%s" />', __('Generate sitemap')), '</form>'); echo _open('div.dm_sitemap_tabs.mt10'); echo _open('ul'); foreach ($sitemap->getFiles() as $file) { echo _tag('li', _tag('a href=#dm_sitemap_' . dmString::slugify(basename($file)), basename($file))); } echo _close('ul'); foreach ($sitemap->getFiles() as $file) { echo _open('div#dm_sitemap_' . dmString::slugify(basename($file))); if (file_exists($file)) { echo _tag('div.clearfix.mb10', definition_list(array('Position' => _link($sitemap->getWebPath($file)), 'Urls' => $sitemap->countUrls($file), 'Size' => $sitemap->getFileSize($file), 'Updated at' => format_date($sitemap->getUpdatedAt($file))), '.clearfix.dm_little_dl.fleft.mr20')); echo _tag('pre', array('style' => 'background: #fff; padding: 10px; border: 1px solid #ddd; max-height: 350px; overflow-y: auto;'), htmlentities(file_get_contents($file), ENT_QUOTES, 'UTF-8')); } else { echo sprintf('<input type="submit" class="dm_sitemap_generate" value="%s" />', __('Generate sitemap')); } if (!is_writable($file)) { echo _tag('p.error', __('File %1% is not writable', array('%1%' => dmProject::unrootify($file)))); } echo _close('div'); } echo _close('div'); if (isset($phpCli)) { echo _open('div.dm_box.big.search_engine'); echo _tag('h1.title', __('Set up a cron to update the sitemap'));