public function getLinks() { if ($this->context->isModuleAction('dmAdmin', 'index')) { return array(); } $module = $this->record ? $this->record->getDmModule() : $this->context->getModuleManager()->getModuleBySfName($this->context->getRequest()->getParameter('module')); $links = array(); $links['home'] = array(); if ($module) { $space = $module->getSpace(); $type = $space->getType(); $links['module_type'] = array('type' => $type); $links['module_space'] = array('space' => $space); $links['module'] = array('module' => $module); if ($this->record) { $links['object'] = array('object' => $this->record); } elseif (($action = $this->context->getActionName()) !== 'index') { $links['action'] = array('action' => dmString::humanize('create' === $action ? 'new' : $action)); } } /* * Allow listeners of dm.bread_crumb.filter_links event * to filter and modify the links list */ return $this->context->getEventDispatcher()->filter(new sfEvent($this, 'dm.bread_crumb.filter_links'), $links)->getReturnValue(); }
public function getWidgetTypes() { if (null === $this->widgetTypes) { $cache = $this->serviceContainer->getService('cache_manager')->getCache('dm/widget/' . sfConfig::get('sf_app') . sfConfig::get('sf_environment')); $this->widgetTypes = $cache->get('types'); if (empty($this->widgetTypes)) { $internalConfigFile = $this->serviceContainer->getService('config_cache')->checkConfig($this->getOption('config_file')); $internalConfig = (include $internalConfigFile); $this->widgetTypes = array(); $controller = $this->serviceContainer->getService('controller'); foreach ($internalConfig as $moduleKey => $actions) { $this->widgetTypes[$moduleKey] = array(); foreach ($actions as $actionKey => $action) { $fullKey = $moduleKey . dmString::camelize($actionKey); $name = dmArray::get($action, 'name', dmString::humanize($actionKey)); $widgetTypeConfig = array('full_key' => $moduleKey . ucfirst($actionKey), 'name' => $name, 'public_name' => dmArray::get($action, 'public_name', dmString::humanize($name)), 'form_class' => dmArray::get($action, 'form_class', $fullKey . 'Form'), 'view_class' => dmArray::get($action, 'view_class', $fullKey . 'View'), 'use_component' => $this->componentExists($moduleKey, $fullKey), 'cache' => dmArray::get($action, 'cache', false)); $this->widgetTypes[$moduleKey][$actionKey] = new dmWidgetType($moduleKey, $actionKey, $widgetTypeConfig); } } foreach ($this->serviceContainer->getService('module_manager')->getProjectModules() as $moduleKey => $module) { $this->widgetTypes[$moduleKey] = array(); foreach ($module->getComponents() as $componentKey => $component) { $baseClass = 'dmWidget' . dmString::camelize($component->getType()); $widgetTypeConfig = array('full_key' => $moduleKey . ucfirst($componentKey), 'name' => $component->getName(), 'public_name' => $module->getName() . ' ' . dmString::humanize($component->getName()), 'form_class' => $baseClass . 'Form', 'view_class' => $baseClass . 'View', 'use_component' => $this->componentExists($moduleKey, $componentKey), 'cache' => $component->isCachable()); $this->widgetTypes[$moduleKey][$componentKey] = new dmWidgetType($moduleKey, $componentKey, $widgetTypeConfig); } } $cache->set('types', $this->widgetTypes); } } return $this->widgetTypes; }
protected function generateHeader() { $fields = array(); foreach ($this->getFields() as $field => $fieldName) { $fields[] = $this->i18n->__(dmString::humanize($fieldName)); } return $fields; }
protected function generateHeader() { $fields = array(); foreach ($this->fields as $field => $fieldName) { $fields[] = dm::getI18n()->__(dmString::humanize($fieldName)); } return $fields; }
protected function getAvailableOrderFields() { $fields = array(); $allowedTypes = array('time', 'timestamp', 'date', 'enum', 'integer', 'string'); foreach ($this->dmModule->getTable()->getColumns() as $columnName => $column) { if (in_array($column['type'], $allowedTypes)) { $fields[$columnName] = $this->__(dmString::humanize($columnName)); } } return $fields; }
public function addWidgets() { $moduleManager = $this->serviceContainer->getService('module_manager'); foreach ($this->serviceContainer->get('widget_type_manager')->getWidgetTypes() as $space => $widgetTypes) { $spaceName = ($module = $moduleManager->getModuleOrNull($space)) ? $module->getName() : dmString::humanize(str_replace('dmWidget', '', $space)); $spaceMenu = $this->addChild($space)->label($this->getI18n()->__($spaceName))->ulClass('clearfix level2')->liClass('dm_droppable_widgets'); foreach ($widgetTypes as $key => $widgetType) { $spaceMenu->addChild($widgetType->getName())->label($this->getI18n()->__($widgetType->getName()))->setOption('widget_type', $widgetType); } if (!$spaceMenu->hasChildren()) { $this->removeChild($spaceMenu); } } return $this; }
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 loadSettings() { $array = array('site_name' => array('default_value' => dmString::humanize(dmProject::getKey()), 'description' => 'The site name', 'group_name' => 'site'), 'site_active' => array('type' => 'boolean', 'default_value' => 1, 'description' => 'Is the site ready for visitors ?', 'group_name' => 'site'), 'site_indexable' => array('type' => 'boolean', 'default_value' => 1, 'description' => 'Is the site ready for search engine crawlers ?', 'group_name' => 'site'), 'site_working_copy' => array('type' => 'boolean', 'default_value' => 1, 'description' => 'Is this site the current working copy ?', 'group_name' => 'site'), 'ga_key' => array('description' => 'The google analytics key without javascript stuff ( e.g. UA-9876614-1 )', 'group_name' => 'tracking', 'credentials' => 'google_analytics'), 'ga_token' => array('description' => 'Auth token gor Google Analytics, computed from password', 'group_name' => 'internal', 'credentials' => 'google_analytics'), 'gwt_key' => array('description' => 'The google webmaster tools filename without google and .html ( e.g. a913b555ba9b4f13 )', 'group_name' => 'tracking', 'credentials' => 'google_webmaster_tools'), 'xiti_code' => array('type' => 'textarea', 'description' => 'The xiti html code', 'group_name' => 'tracking', 'credentials' => 'xiti'), 'search_stop_words' => array('type' => 'textarea', 'description' => 'Words to exclude from searches (e.g. the, a, to )', 'group_name' => 'search engine', 'credentials' => 'search_engine'), 'base_urls' => array('type' => 'textarea', 'description' => 'Diem base urls for different applications/environments/cultures', 'group_name' => 'internal', 'credentials' => 'system'), 'image_resize_method' => array('type' => 'select', 'default_value' => 'center', 'description' => 'Default method when an image needs to be resized', 'params' => 'fit=Fit scale=Scale inflate=Inflate top=Top right=Right left=Left bottom=Bottom center=Center', 'group_name' => 'interface', 'credentials' => 'interface_settings'), 'image_resize_quality' => array('type' => 'number', 'default_value' => 95, 'description' => 'Jpeg default quality when generating thumbnails', 'group_name' => 'interface', 'credentials' => 'interface_settings'), 'link_external_blank' => array('type' => 'boolean', 'default_value' => 0, 'description' => 'Links to other domain get automatically a _blank target', 'group_name' => 'interface', 'credentials' => 'interface_settings'), 'link_current_span' => array('type' => 'boolean', 'default_value' => 1, 'description' => 'Links to current page are changed from <a> to <span>', 'group_name' => 'interface', 'credentials' => 'interface_settings'), 'link_use_page_title' => array('type' => 'boolean', 'default_value' => 1, 'description' => 'Add an automatic title on link based on the target page title', 'group_name' => 'interface', 'credentials' => 'interface_settings'), 'title_prefix' => array('default_value' => '', 'description' => 'Append something at the beginning of all pages title', 'group_name' => 'seo', 'credentials' => 'manual_metas'), 'title_suffix' => array('default_value' => ' | ' . dmString::humanize(dmProject::getKey()), 'description' => 'Append something at the end of all pages title', 'group_name' => 'seo', 'credentials' => 'manual_metas'), 'smart_404' => array('type' => 'boolean', 'default_value' => 1, 'description' => 'When a page is not found, user is redirect to a similar page. The internal search index is used to find the best page for requested url.', 'group_name' => 'seo', 'credentials' => 'url_redirection')); $existingSettings = dmDb::query('DmSetting s INDEXBY s.name')->withI18n()->fetchRecords(); foreach ($array as $name => $config) { if (!isset($existingSettings[$name])) { $setting = new DmSetting(); $setting->set('name', $name); $setting->fromArray($config); $setting->save(); } elseif (!$existingSettings[$name]->hasCurrentTranslation()) { /* * Try to find an existing config from another culture */ $existing = dmDb::query('DmSettingTranslation s')->where('s.id = ?', $existingSettings[$name]->id)->limit(1)->fetchArray(); if ($existing = dmArray::first($existing)) { $config = $existing; unset($config['id'], $config['lang']); } $existingSettings[$name]->fromArray($config)->getCurrentTranslation()->save(); } } dmConfig::load(false); }
protected function fixModuleConfig($moduleKey, $moduleConfig, $isInContent) { /* * Extract plural from name * name | plural */ if (!empty($moduleConfig['name'])) { if (strpos($moduleConfig['name'], '|')) { list($moduleConfig['name'], $moduleConfig['plural']) = explode('|', $moduleConfig['name']); } } else { $moduleConfig['name'] = dmString::humanize($moduleKey); } if (empty($moduleConfig['model'])) { $candidateModel = dmString::camelize($moduleKey); $model = class_exists('Base' . $candidateModel, true) ? Doctrine_Core::isValidModelClass($candidateModel) ? $candidateModel : false : false; } else { $model = $moduleConfig['model']; } // BC "actions" deprecated keyword becomes "components" if (isset($moduleConfig['actions'])) { $moduleConfig['components'] = $moduleConfig['actions']; unset($moduleConfig['actions']); } //security features $securityConfig = $this->fixSecurityConfig($moduleKey, $moduleConfig); $moduleOptions = array('name' => (string) trim($moduleConfig['name']), 'plural' => (string) trim(empty($moduleConfig['plural']) ? $model ? dmString::pluralize($moduleConfig['name']) : $moduleConfig['name'] : $moduleConfig['plural']), 'model' => $model, 'credentials' => isset($moduleConfig['credentials']) ? is_string($moduleConfig['credentials']) ? trim($moduleConfig['credentials']) : (is_array($moduleConfig['credentials']) ? $moduleConfig['credentials'] : '') : ((bool) $isInContent ? 'content' : null), 'underscore' => (string) dmString::underscore($moduleKey), 'is_project' => (bool) $isInContent || dmArray::get($moduleConfig, 'page', false) || count(dmArray::get($moduleConfig, 'components', array())), 'plugin' => $moduleConfig['plugin'], 'overridden' => dmArray::get($moduleConfig, 'overridden', false), 'has_admin' => (bool) dmArray::get($moduleConfig, 'admin', $model || !$isInContent), 'has_front' => (bool) dmArray::get($moduleConfig, 'front', true), 'components' => dmArray::get($moduleConfig, 'components', array()), 'has_security' => is_array($securityConfig), 'security' => $securityConfig, 'i18n_catalogue' => isset($moduleConfig['i18n_catalogue']) ? $moduleConfig['i18n_catalogue'] : sfConfig::get('dm_i18n_catalogue')); if ($moduleOptions['is_project']) { $moduleOptions = array_merge($moduleOptions, array('parent_key' => dmArray::get($moduleConfig, 'parent') ? dmString::modulize(trim(dmArray::get($moduleConfig, 'parent'))) : null, 'has_page' => (bool) dmArray::get($moduleConfig, 'page', false))); } // fix non array action filters foreach ($moduleOptions['components'] as $componentKey => $componentConfig) { if (is_array($componentConfig) && array_key_exists('filters', $componentConfig) && !is_array($componentConfig['filters'])) { $moduleOptions['components'][$componentKey]['filters'] = array($componentConfig['filters']); } } return $moduleOptions; }
/** * Returns HTML code for an action link. * * @param string $actionName The action name * @param array $params The parameters * @param boolean $pk_link Whether to add a primary key link or not * * @return string HTML code */ public function getLinkToAction($actionName, $params, $pk_link = false) { $action = isset($params['action']) ? $params['action'] : dmString::modulize($actionName); $url_params = $pk_link ? '?' . $this->getPrimaryKeyUrlParams() : '\''; return '[?php echo link_to(__(\'' . dmArray::get($params, 'label', dmString::humanize($actionName)) . '\', array(), \'' . $this->getI18nCatalogue() . '\'), \'' . $this->getModuleName() . '/' . $action . $url_params . ', ' . $this->asPhp($params['params']) . ') ?]'; }
/** * Returns an array containing the subclasses inheriting using column_aggregate, * using their declared discriminant. * * @return array the choices used by sfWidgetFormChoice and sfValidatorChoice */ public function getSubClassesChoices() { $choices = array(); $subClasses = $this->getTable()->getOption('subclasses'); if (!empty($subClasses)) { foreach ($subClasses as $subClass) { $subTableInheritanceMap = dmDb::table($subClass)->getOption('inheritanceMap'); if (!empty($subTableInheritanceMap)) { $columnName = array_keys($subTableInheritanceMap); $columnName = $columnName[0]; $discriminant = $subTableInheritanceMap[$columnName]; $choices[$discriminant] = ucfirst(dmString::humanize($discriminant)); } } } return $choices; }
protected function updateTemplate() { $template = $this->getTemplate(); $templateVars = array_keys($this->getValues()); natsort($templateVars); if ($template->get('vars') != implode(', ', $templateVars)) { $template->set('vars', implode(', ', $templateVars)); } if (!$template->get('body')) { $body = array(); foreach ($this->getValues() as $key => $value) { $body[] = dmString::humanize($key) . ' : ' . $this->wrap($key); } $template->set('body', implode("\n", $body)); } if ($template->isModified()) { $template->save(); } }
protected function getFormDisplay() { $fields = dmArray::valueToKey(array_diff($this->table->getAllColumnNames(), array_unique(array_merge($this->getFormExcludedFields(), $this->table->getPrimaryKeys(), array_keys((array) $this->table->getOption('inheritanceMap')))))); /* * Remove media fields not to see them in foreigns fields */ foreach ($this->table->getRelationHolder()->getLocalMedias() as $alias => $relation) { if (in_array($relation['local'], $fields)) { unset($fields[$relation['local']]); } } $sets = array(); $sets['NONE'] = array(); if (in_array($this->table->getIdentifierColumnName(), $fields)) { if ('embed' != sfConfig::get('dm_i18n_form') || !$this->table->hasI18n() || !$this->table->isI18nColumn($field)) { $sets['NONE'][] = $this->table->getIdentifierColumnName(); } unset($fields[$this->table->getIdentifierColumnName()]); } foreach ($this->getBooleanFields($fields) as $field) { if (in_array($field, $fields)) { $sets['NONE'][] = $field; unset($fields[$field]); } } foreach ($this->table->getRelationHolder()->getLocals() as $alias => $relation) { if ($relation->getClass() == 'DmMedia') { $sets[dmString::humanize($relation['local'])] = array($relation['local'] . '_form', $relation['local'] . '_view'); } else { $sets['NONE'][] = $relation->getLocalColumnName(); unset($fields[$relation->getLocalColumnName()]); } } foreach ($this->getTextFields($fields) as $field) { if (in_array($field, $fields)) { if ('embed' != sfConfig::get('dm_i18n_form') || !$this->table->hasI18n() || !$this->table->isI18nColumn($field)) { $sets[dmString::humanize($field)][] = $field; } unset($fields[$field]); } } foreach (array_merge($this->table->getRelationHolder()->getAssociations(), $this->table->getRelationHolder()->getForeigns()) as $alias => $relation) { if ($this->table->hasTemplate('DmGallery') && 'DmMedia' === $relation->getClass()) { continue; } if ($relation->getType() !== Doctrine_Relation::ONE && ($relationModule = $this->module->getManager()->getModuleByModel($relation->getClass()))) { $label = $relationModule->getPlural(); } else { continue; } $sets[$label][] = dmString::underscore($alias) . '_list'; } if ($this->table->hasTemplate('DmGallery')) { $sets['Gallery'][] = 'dm_gallery'; } if ('embed' == sfConfig::get('dm_i18n_form') && $this->table->hasI18n()) { $sets['Lang'] = array(); foreach (sfConfig::get('dm_i18n_cultures') as $culture) { $sets['Lang'][] = $culture; } } $sets['Others'] = array(); foreach ($fields as $field) { if ('embed' != sfConfig::get('dm_i18n_form') || !$this->table->hasI18n() || !$this->table->isI18nColumn($field)) { $sets['Others'][] = $field; } unset($fields[$field]); } return $this->removeEmptyValues($sets); }
protected function renderType(dmEventLogEntry $entry) { return '<strong>' . $this->i18n->__(dmString::humanize($entry->get('type'))) . '</strong>'; }
foreach ($revisions as $revision) { echo _tag('li.version_tab', _tag('a href=#revision_' . $revision->version, $revision->version)); } echo _close('ul'); $model = get_class($record); $revisionModel = get_class($revision); $fields = array_diff($revisions[0]->getTable()->getFieldNames(), array('id', 'version', 'lang')); $recordDiff = $sf_context->get('record_text_diff'); $table = _table(); $table->head(__('Field'), __('Difference'), __('Value')); $nbRevisions = count($revisions); foreach ($revisions as $index => $revision) { $recordDiff->compare(dmArray::get($revisions, $index + 1, new $revisionModel()), $revision); $diffs = $recordDiff->getHtmlDiffs($fields); $values = $recordDiff->getHtmlValues($fields); echo _open('div.revision.dm_data#revision_' . $revision->version); echo _open('div.revision_header'); echo _link($record)->text(__('Back to %1%', array('%1%' => $record->__toString())))->set('.s16.s16_arrow_left.back_to_record'); if ($index !== 0) { echo _link('+/dmAdminGenerator/revert')->textTitle(__('Revert to revision %1%', array('%1%' => $revision->version)))->set('.dm_medium_button.dm_js_confirm.revert_to_revision')->params(array('model' => $model, 'pk' => $record->getPrimaryKey(), 'version' => $revision->version)); } echo _tag('p.revision_title', __('Revision %number%', array('%number%' => $revision->version)) . (isset($values['updated_by']) ? ' - ' . $values['updated_by'] : '') . (isset($values['updated_at']) ? ' - ' . format_date($values['updated_at'], 'f') : '')); echo _close('div'); $table->clearBody(); foreach ($fields as $field) { $table->body(_tag('div', __(dmString::humanize($field))), _tag('div', $diffs[$field]), _tag('div', $values[$field])); } echo $table; echo _close('div'); } echo _close('div');
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')); echo '</form>';