public function executeRate(sfWebRequest $request) { $this->forward404Unless($request->isMethod('POST')); list($class, $id) = dmString::decode($request->getParameter('hash')); $this->forward404Unless($table = dmDb::table($class)); $this->forward404Unless($record = $table->find($id)); $this->forward404Unless($table->hasTemplate('DmRatable')); $template = $table->getTemplate('DmRatable'); $options = $template->getOptions(); $value = (int) $request->getParameter('value'); $this->forward404Unless($value >= 0 && $value <= $options['max_rate']); $rate = array('rate' => $value); if ($options['user']) { $this->forward404Unless($this->getUser()->isAuthenticated()); $rate['dm_user_id'] = $this->getUser()->getUserId(); } else { $rate['session_id'] = session_id(); } if ($value) { $record->addRate($rate); $message = $this->getService('i18n')->__('Rating saved (%rate%)', array('%rate%' => $value)); } else { $record->cancelRate($rate); $message = $this->getService('i18n')->__('Rating removed'); } return $this->renderComponent('dmRatable', 'rating', array('record' => $record, 'message' => $message)); }
/** * Join media for this columnName or alias * return @dmDoctrineQuery $this */ public function withDmMedia($alias, $rootAlias = null) { $rootAlias = $rootAlias ? $rootAlias : $this->getRootAlias(); $mediaJoinAlias = $rootAlias . dmString::camelize($alias); $folderJoinAlias = $mediaJoinAlias . 'Folder'; return $this->leftJoin(sprintf('%s.%s %s, %s.%s %s', $rootAlias, $alias, $mediaJoinAlias, $mediaJoinAlias, 'Folder', $folderJoinAlias)); }
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 addWidget(DmZone $zone, $moduleAction) { list($module, $action) = explode('/', $moduleAction); $this->info('Add a ' . $moduleAction . ' widget')->get(sprintf('/index.php/+/dmWidget/add?to_dm_zone=%d&mod=' . $module . '&act=' . $action . '&dm_cpi=%d', $zone->id, $this->getPage()->id))->checks(array('module_action' => 'dmWidget/add', 'method' => 'get'))->has('.dm_widget.' . str_replace('dm_widget_', '', dmString::underscore($module)) . '.' . dmString::underscore($action)); $zone->refreshRelated('Widgets'); return $this; }
protected function renderText() { if (isset($this->options['text'])) { return $this->options['text']; } return dmString::escape($this->page->_getI18n('name')); }
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; }
public function checkBackground($validator, $values) { if ('fit' == $values['method'] && !dmString::hexColor($values['background'])) { throw new sfValidatorErrorSchema($validator, array('background' => new sfValidatorError($validator, 'This is not a valid hexadecimal color'))); } return $values; }
protected function useSearchIndex($slug) { if (!dmConfig::get('smart_404')) { return false; } try { $searchIndex = $this->serviceContainer->get('search_engine')->getCurrentIndex(); $queryString = str_replace('/', ' ', dmString::unSlugify($slug)); $query = Zend_Search_Lucene_Search_QueryParser::parse($queryString); $results = $searchIndex->search($query); $foundPage = null; foreach ($results as $result) { if ($result->getScore() > 0.5) { if ($foundPage = $result->getPage()) { break; } } else { break; } } if ($foundPage) { return $this->serviceContainer->getService('helper')->link($foundPage)->getHref(); } } catch (Exception $e) { $this->dispatcher->notify(new sfEvent($this, 'application.log', array('Can not use search index to find redirection for slug ' . $slug, sfLogger::ERR))); if (sfConfig::get('dm_debug')) { throw $e; } } }
public function background($v) { if (!($hexColor = dmString::hexColor($v))) { throw new dmException(sprintf('%s is not a valid hexadecimal color', $v)); } return $this->setOption('background', $hexColor); }
public function linkToHistory($object, $params) { if (!$object->getTable()->isVersionable()) { return ''; } return '<li class="sf_admin_action_history">' . link_to1(__($params['label']), $this->getRouteArrayForAction('history', $object), array('class' => 'sf_admin_action s16 s16_clock_history', 'title' => __($params['title'], array('%1%' => dmString::strtolower(__($this->getModule()->getName())))))) . '</li>'; }
function media_file_image_tag(DmMedia $file, $options = array()) { $options = array_merge(array( 'width' => $file->isImage() ? 128 : 64, 'height' => $file->isImage() ? 98 : 64 ), dmString::toArray($options, true)); if ($file->isImage()) { $image = _media($file); } else { if (file_exists( dmOs::join( sfConfig::get('sf_web_dir') . '/dmCorePlugin/images/media/' . dmOs::getFileExtension($file->getFile(), false) . '.png' ) )) { $image = _media('/dmCorePlugin/images/media/' . dmOs::getFileExtension($file->getFile(), false) . '.png'); } else { $image = _media('/dmCorePlugin/images/media/unknown.png'); } } return $image->size($options['width'], $options['height']); }
/** * Implementation of filterSet() to call set on Translation relationship to allow * access to I18n properties from the main object. * * @param Doctrine_Record $record * @param string $name Name of the property * @param string $value Value of the property * @return void */ public function filterSet(Doctrine_Record $record, $fieldName, $value) { $translation = $record->get('Translation'); $culture = myDoctrineRecord::getDefaultCulture(); if ($translation->contains($culture)) { $i18n = $record->get('Translation')->get($culture); } else { $i18n = $record->get('Translation')->get($culture); /* * If translation is new * populate it with i18n fallback */ if ($i18n->state() == Doctrine_Record::STATE_TDIRTY) { if ($fallback = $record->getI18nFallBack()) { $fallBackData = $fallback->toArray(); unset($fallBackData['id'], $fallBackData['lang']); $i18n->fromArray($fallBackData); } } } if (!ctype_lower($fieldName) && !$i18n->contains($fieldName)) { $underscoredFieldName = dmString::underscore($fieldName); if (strpos($underscoredFieldName, '_') !== false && $i18n->contains($underscoredFieldName)) { $fieldName = $underscoredFieldName; } } $i18n->set($fieldName, $value); return $value; }
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; }
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')); }
/** * Fill the field values with the page */ public function populate() { $boostValues = $this->getBoostValues(); // store the page id without indexing it $this->store('page_id', $this->page->get('id')); // index the page slug $this->index('slug', dmString::unSlugify($this->page->get('slug')), $boostValues['slug']); // index the page name $this->index('name', $this->page->get('name'), $boostValues['name']); // index the page title $this->index('title', $this->page->get('title'), $boostValues['title']); // index the page h1 $this->index('h1', $this->page->get('h1'), $boostValues['h1']); // index the page description $this->index('description', $this->page->get('description'), $boostValues['description']); // index keywords only if the project uses them if (sfConfig::get('dm_seo_use_keywords')) { $this->index('keywords', $this->page->get('keywords'), $boostValues['keywords']); } // process the page body only if its boost value is not null if ($boostValues['body']) { $this->index('content_index', $this->getPageContentForIndex(), $boostValues['body']); } // store page content to display it on search results $this->store('content', $this->getPageContentForStore()); }
protected function addPage(DmPage $page) { $pageMenu = $this->addChild('page-' . $page->get('id'), $page)->label(dmString::escape($page->get('name')))->secure($page->get('is_secure'))->credentials($page->get('credentials')); foreach ($page->get('__children') as $child) { !in_array($child->id, $this->hide) && $pageMenu->addPage($child); } }
public function listenToConfigUpdatedEvent(sfEvent $event) { $setting = $event['setting']; if ('internal' == dmString::strtolower($setting->groupName)) { return; } $this->log(array('server' => $_SERVER, 'action' => 'update', 'type' => 'config', 'subject' => sprintf('%s = %s ( %s )', $setting->name, dmString::truncate($setting->value, 80), $event['culture']))); }
public function linkToImportSentences($object, $params) { if ($this->module->getSecurityManager()->userHasCredentials('edit', $object)) { $title = __(isset($params['title']) ? $params['title'] : $params['label'], array('%1%' => dmString::strtolower(__($this->getModule()->getName()))), 'dm'); return '<li class="sf_admin_action_import_sentences">' . link_to1(__($params['label'], array(), $this->getI18nCatalogue()), $this->getRouteArrayForAction('importSentences', $object), array('class' => 's16 s16_save dm_import_link sf_admin_action', 'title' => $title)) . '</li>'; } return ''; }
public function label($label = null, $attributes = array()) { $attributes = dmString::toArray($attributes); $attributes['class'] = dmArray::toHtmlCssClasses(empty($attributes['class']) ? array('label') : array_merge((array) $attributes['class'], array('label'))); $label = null === $label ? $this->parent->getWidget()->getLabel($this->name) : $label; $this->htmlBuffer .= parent::renderLabel($label, $attributes); return $this; }
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; }
public function linkTo_preview($object, $params) { if ($this->module->getSecurityManager()->userHasCredentials('edit', $object)) { $title = __(isset($params['title']) ? $params['title'] : $params['label'], array('%1%' => dmString::strtolower(__($this->getModule()->getName()))), 'dm'); return '<li class="sf_admin_action_preview">' . link_to1(__($params['label'], array(), $this->getI18nCatalogue()), $this->getRouteArrayForAction('preview', $object), array('class' => 's16 s16_right_little dm_preview_link sf_admin_action', 'title' => $title, 'method' => 'get')) . '</li>'; } return ''; }
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') : ''); }
protected function clearApcSystemCache($siteUrl) { $this->log('Clear apc system cache'); $fileName = dmString::random(12) . '.php'; $file = sfConfig::get('sf_web_dir') . '/cache/' . $fileName; file_put_contents($file, '<?php apc_clear_cache();'); $this->getContext()->get('web_browser')->get(trim($siteUrl, '/') . '/cache/' . $fileName); unlink($file); }
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)); } }
protected function getModuleTypeBySlug($slug) { foreach ($this->context->getModuleManager()->getTypes() as $type) { if (dmString::slugify($type->getPublicName()) == $slug) { return $type; } } return null; }
/** * Sets a parameter (implements the ArrayAccess interface). * * @param string $name The parameter name * @param mixed $value The parameter value */ public function offsetSet($name, $value) { $name = dmString::camelize($name); if (!$value instanceof dmForm) { throw new InvalidArgumentException(sprintf('The object "%s" is not an instance of dmForm', get_class($value))); } $this->prepareFormForPage($value); $this->forms[$name] = $value; }
public function get($key) { if (method_exists($this, $method = 'get' . dmString::camelize($key))) { return $this->{$method}(); } if (isset($this->data[$key])) { return $this->data[$key]; } return null; }
public function checks(array $checks = array()) { $checks = array_merge($this->getDefaultChecks(), $checks); foreach ($checks as $check => $expected) { $method = 'is' . dmString::camelize($check); $this->{$method}($expected); } $this->test()->unlike($this->getResponse()->getContent(), '/\\[EXCEPTION\\]/', 'Response contains no [Exception]'); return $this; }
public function openFile($file) { $file = $this->decodePath($file); $this->validateOpenFile($file); if (!is_readable($file) || !is_file($file)) { throw new dmCodeEditorException($file . ' does not exist or is not readable'); } $mimeGroup = $this->mimeTypeResolver->getGroupByFilename($file); return array('full_path' => $file, 'path' => dmProject::unRootify($file), 'is_writable' => is_writable($file) && !$this->fileBackup->isFileBackup($file), 'is_image' => 'image' === $mimeGroup, 'code' => 'image' !== $mimeGroup ? dmString::unixify(file_get_contents($file)) : ''); }