Пример #1
0
 /**
  * Get the content templates widget and validator
  *
  * @param sfForm $form 
  * @return array $widgetAndValidator
  */
 public static function getTemplateWidgetAndValidator(sfForm $form)
 {
     if ($form instanceof sfSympalContentForm) {
         $type = $form->getObject()->getType()->getName();
     } else {
         if ($form instanceof sfSympalContentTypeForm) {
             $type = $form->getObject()->getName();
         } else {
             return false;
         }
     }
     $templates = sfSympalConfiguration::getActive()->getContentTemplates($type);
     $options = array('' => '');
     foreach ($templates as $name => $template) {
         $options[$name] = sfInflector::humanize($name);
     }
     $widget = new sfWidgetFormChoice(array('choices' => $options));
     $validator = new sfValidatorChoice(array('choices' => array_keys($options), 'required' => false));
     return array('widget' => $widget, 'validator' => $validator);
 }
 /**
  * Listens to the sympal.load_admin_menu to configure the admin menu
  */
 public function setupAdminMenu(sfEvent $event)
 {
     $menu = $event->getSubject();
     // Setup the Content menu
     $manageContent = $menu->getChild('content');
     $manageContent->setLabel('Content');
     $manageContent->addChild('Search', '@sympal_admin_search');
     $contentTypes = Doctrine_Core::getTable('sfSympalContentType')->getAllContentTypes();
     foreach ($contentTypes as $contentType) {
         $manageContent->addChild($contentType->getLabel(), '@sympal_content_list_type?type=' . $contentType->getId())->setCredentials(array('ManageContent'));
     }
     $manageContent->addChild('Slots', '@sympal_content_slots')->setCredentials(array('ManageSlots'));
     $manageContent->addChild('XML Sitemap', '@sympal_sitemap')->setCredentials(array('ViewXmlSitemap'));
     // Setup the Site Administration menu
     $siteAdministration = $menu->getChild('site_administration');
     $siteAdministration->setLabel('Site Administration');
     $siteAdministration->addChild('404 Redirects', '@sympal_redirects')->setCredentials(array('ManageRedirects'));
     $siteAdministration->addChild('Edit Site', '@sympal_sites_edit?id=' . sfSympalContext::getInstance()->getService('site_manager')->getSite()->getId())->setCredentials(array('ManageSites'));
     // Add to the Administration menu
     $administration = $menu->getChild('administration');
     $administration->addChild('Content Types', '@sympal_content_types')->setCredentials(array('ManageContentTypes'));
     $administration->addChild('Sites', '@sympal_sites')->setCredentials(array('ManageSites'));
     // Add a Content menu if applicable
     $content = $this->_sympalContext->getService('site_manager')->getCurrentContent();
     if ($content) {
         $contentEditor = $menu->getChild($content->getType()->slug);
         $contentEditor->setLabel(sprintf(__('%s Actions'), $content->getType()->getLabel()));
         // If in the admin, put a link to view the content
         if (sfSympalConfiguration::getActive()->isAdminModule()) {
             $contentEditor->addChild(sprintf(__('View %s'), $content->getType()->getLabel()), $content->getRoute());
         }
         $contentEditor->addChild(sprintf(__('Create New %s'), $content->getType()->getLabel()), '@sympal_content_create_type?type=' . $content['Type']['slug'])->setCredentials('ManageContent');
         $contentEditor->addChild(sprintf(__('Edit %s'), $content->getType()->getLabel()), $content->getEditRoute())->setCredentials('ManageContent');
         $contentEditor->addChild(__('Edit Content Type'), '@sympal_content_types_edit?id=' . $content->getType()->getId())->setCredentials('ManageMenus');
         // Add a menu item entry
         $menuItem = $this->_sympalContext->getService('menu_manager')->getCurrentMenuItem();
         if ($menuItem && $menuItem->exists()) {
             $contentEditor->addChild(__('Edit Menu Item'), '@sympal_content_menu_item?id=' . $content->getId())->setCredentials('ManageMenus');
         } else {
             $contentEditor->addChild(__('Add to Menu'), '@sympal_content_menu_item?id=' . $content->getId())->setCredentials('ManageMenus');
         }
         // Add publish/unpublish icons
         $user = sfContext::getInstance()->getUser();
         if ($user->hasCredential('PublishContent')) {
             if ($content->getIsPublished()) {
                 $contentEditor->addChild(__('Unpublish'), '@sympal_unpublish_content?id=' . $content->id, 'title=' . __('Published on %date%', array('%date%' => format_date($content->getDatePublished(), 'g'))) . '. ' . __('Click to unpublish content.'));
             } elseif ($content->getIsPublishInTheFuture()) {
                 $contentEditor->addChild(__('Unpublish'), '@sympal_unpublish_content?id=' . $content->id, 'title=' . __('Will publish on %date%', array('%date%' => format_date($content->getDatePublished(), 'g'))) . '. ' . __('Click to unpublish content.'));
             } else {
                 $contentEditor->addChild(__('Publish'), '@sympal_publish_content?id=' . $content->id, 'title=' . __('Has not been published yet. ' . __('Click to publish content.')));
             }
         }
         if (sfSympalConfig::isI18nEnabled()) {
             foreach (sfSympalConfig::getLanguageCodes() as $code) {
                 if (sfContext::getInstance()->getUser()->getEditCulture() != $code) {
                     $contentEditor->addChild(sprintf(__('Edit in %s'), format_language($code)), '@sympal_change_edit_language?language=' . $code, 'title=' . sprintf(__('Edit %s version'), format_language($code)));
                 }
             }
         }
     }
 }
Пример #3
0
<?php

/**
 * Unit test for the sfSympalConfiguration class
 * 
 * @package     
 * @subpackage  
 * @author      Ryan Weaver <*****@*****.**>
 * @since       2010-02-06
 * @version     svn:$Id$ $Author$
 */
$app = 'sympal';
require_once dirname(__FILE__) . '/../../bootstrap/unit.php';
$t = new lime_test(18);
$sympalPluginConfiguration = sfContext::getInstance()->getConfiguration()->getPluginConfiguration('sfSympalPlugin');
$sympalConfiguration = sfSympalConfiguration::getActive();
$contentTemplates = $sympalConfiguration->getContentTemplates('sfSympalPage');
$t->is(isset($contentTemplates['default_view']), true, '->getContentTemplates() returns default_view for sfSympalPage');
$t->is(isset($contentTemplates['register']), true, '->getContentTemplates() returns register for sfSympalPage');
$plugins = $sympalConfiguration->getPlugins();
$t->is(is_array($plugins), true, '->getPlugins() returns array');
$t->is(in_array('sfSympalBlogPlugin', $plugins), true, '->getPlugins() includes sfSympalBlogPlugin');
$pluginPaths = $sympalConfiguration->getPluginPaths();
$t->is(is_array($pluginPaths), true, '->getPluginPaths() returns array');
$t->is(isset($pluginPaths['sfSympalBlogPlugin']), true, '->getPluginPaths() includes sfSympalBlogPlugin');
$t->is($pluginPaths['sfSympalBlogPlugin'], sfConfig::get('sf_plugins_dir') . '/sfSympalBlogPlugin', '->getPluginPaths() returns correct path as value of array');
$corePlugins = array('sfDoctrineGuardPlugin', 'sfFormExtraPlugin', 'sfTaskExtraPlugin', 'sfFeed2Plugin', 'sfWebBrowserPlugin', 'sfImageTransformPlugin', 'sfInlineObjectPlugin', 'sfThemePlugin', 'sfContentFilterPlugin', 'sfSympalMenuPlugin', 'sfSympalPluginManagerPlugin', 'sfSympalPagesPlugin', 'sfSympalContentListPlugin', 'sfSympalDataGridPlugin', 'sfSympalUserPlugin', 'sfSympalInstallPlugin', 'sfSympalUpgradePlugin', 'sfSympalRenderingPlugin', 'sfSympalAdminPlugin', 'sfSympalEditorPlugin', 'sfSympalAssetsPlugin', 'sfSympalSearchPlugin', 'sfSympalMinifyPlugin', 'sfSympalFormPlugin');
$t->is($sympalConfiguration->getCorePlugins(), $corePlugins, '->getCorePlugins() returns the correct array');
$installedPlugins = array_values($sympalConfiguration->getDownloadedPlugins());
sort($installedPlugins);
// sort the plugins - don't depend on file system to return with consistent order
Пример #4
0
 public function clearCache()
 {
     if ($cache = sfSympalConfiguration::getActive()->getCache()) {
         return $cache->remove($this->_cacheKey);
     }
 }
 public function getTemplateToRenderWith()
 {
     if (!($template = $this->getTemplate())) {
         $template = $this->getType()->getTemplate();
     }
     $templates = sfSympalConfiguration::getActive()->getContentTemplates($this->getType()->getSlug());
     if (isset($templates[$template])) {
         $template = $templates[$template]['template'];
     }
     $template = $template ? $template : sfSympalConfig::get($this->getType()->getSlug(), 'default_content_template', sfSympalConfig::get('default_content_template'));
     return $template;
 }
 public function loadEditor(sfEvent $event)
 {
     $user = sfContext::getInstance()->getUser();
     $this->configuration->loadHelpers(array('Asset', 'Partial', 'I18N'));
     $menu = $event->getSubject();
     $content = $event['content'];
     $menuItem = $event['menuItem'];
     $sympalConfiguration = sfSympalConfiguration::getActive();
     $user = sfContext::getInstance()->getUser();
     $request = sfContext::getInstance()->getRequest();
     $contentEditor = $menu->getChild($content->getType()->getLabel() . ' Actions');
     if ($sympalConfiguration->isAdminModule()) {
         $contentEditor->addChild(image_tag('/sf/sf_admin/images/list.png') . ' ' . __('View ' . $content->getType()->getLabel()), $content->getRoute());
     }
     $contentEditor->addChild(image_tag('/sf/sf_admin/images/add.png') . ' ' . __('Create New ' . $content->getType()->getLabel()), '@sympal_content_create_type?type=' . $content['Type']['slug'])->setCredentials('ManageContent');
     $contentEditor->addChild(image_tag('/sf/sf_admin/images/edit.png') . ' ' . __('Edit ' . $content->getType()->getLabel()), $content->getEditRoute())->setCredentials('ManageContent');
     $contentEditor->addChild(image_tag('/sf/sf_admin/images/edit.png') . ' ' . __('Edit Content Type'), '@sympal_content_types_edit?id=' . $content->getType()->getId())->setCredentials('ManageMenus');
     if ($menuItem && $menuItem->exists()) {
         $contentEditor->addChild(image_tag('/sf/sf_admin/images/edit.png') . ' ' . __('Edit Menu Item'), '@sympal_content_menu_item?id=' . $content->getId())->setCredentials('ManageMenus');
     } else {
         $contentEditor->addChild(image_tag('/sf/sf_admin/images/add.png') . ' ' . __('Add to Menu'), '@sympal_content_menu_item?id=' . $content->getId())->setCredentials('ManageMenus');
     }
     if (sfSympalConfig::isI18nEnabled()) {
         foreach (sfSympalConfig::getLanguageCodes() as $code) {
             if (sfContext::getInstance()->getUser()->getEditCulture() != $code) {
                 $contentEditor->addChild(image_tag('/sfSympalPlugin/images/flags/' . strtolower($code) . '.png') . ' Edit ' . format_language($code), '@sympal_change_edit_language?language=' . $code, 'title=Switch to ' . format_language($code));
             }
         }
     }
 }
 protected function _getCache()
 {
     return sfSympalConfig::get('menu_cache', 'enabled', true) ? sfSympalConfiguration::getActive()->getCache() : false;
 }
 public function shouldLoadEditor()
 {
     $format = sfContext::getInstance()->getRequest()->getRequestFormat();
     $format = $format ? $format : 'html';
     return sfContext::getInstance()->getUser()->isEditMode() && $format == 'html' && (!sfSympalConfig::get('page_cache', 'enabled') && sfSympalConfig::get('inline_editing', 'enabled') && sfSympalContext::getInstance()->getCurrentContent()) || sfSympalConfiguration::getActive()->isAdminModule() && sfSympalContext::getInstance()->getCurrentContent();
 }
 public function loadEditor(sfEvent $event)
 {
     $user = sfContext::getInstance()->getUser();
     $this->configuration->loadHelpers(array('Asset', 'Partial', 'I18N'));
     $menu = $event->getSubject();
     $content = $event['content'];
     $menuItem = $event['menuItem'];
     $sympalConfiguration = sfSympalConfiguration::getActive();
     $user = sfContext::getInstance()->getUser();
     $request = sfContext::getInstance()->getRequest();
     $contentEditor = $menu->getChild($content->getType()->getLabel() . ' Actions');
     if ($sympalConfiguration->isAdminModule()) {
         $contentEditor->addChild(__('View ') . $content->getType()->getLabel(), $content->getRoute());
     }
     $contentEditor->addChild(__('Create New ') . $content->getType()->getLabel(), '@sympal_content_create_type?type=' . $content['Type']['slug'])->setCredentials('ManageContent');
     $contentEditor->addChild(__('Edit ') . $content->getType()->getLabel(), $content->getEditRoute())->setCredentials('ManageContent');
     $contentEditor->addChild(__('Edit Content Type'), '@sympal_content_types_edit?id=' . $content->getType()->getId())->setCredentials('ManageMenus');
     if ($menuItem && $menuItem->exists()) {
         $contentEditor->addChild(__('Edit Menu Item'), '@sympal_content_menu_item?id=' . $content->getId())->setCredentials('ManageMenus');
     } else {
         $contentEditor->addChild(__('Add to Menu'), '@sympal_content_menu_item?id=' . $content->getId())->setCredentials('ManageMenus');
     }
     if (sfSympalConfig::isI18nEnabled()) {
         foreach (sfSympalConfig::getLanguageCodes() as $code) {
             if (sfContext::getInstance()->getUser()->getEditCulture() != $code) {
                 $contentEditor->addChild(__('Edit ') . format_language($code), '@sympal_change_edit_language?language=' . $code, 'title=' . __('Switch to ') . '' . format_language($code));
             }
         }
     }
     if ($user->hasCredential('PublishContent')) {
         if ($content->getIsPublished()) {
             $contentEditor->addChild(__('Unpublish'), '@sympal_unpublish_content?id=' . $content['id'], 'title=' . __('Published on %date%', array('%date%' => format_date($content->getDatePublished(), 'g'))) . '. ' . __('Click to unpublish content.'));
         } elseif ($content->getIsPublishInTheFuture()) {
             $contentEditor->addChild(__('Unpublish'), '@sympal_unpublish_content?id=' . $content['id'], 'title=' . __('Will publish on %date%', array('%date%' => format_date($content->getDatePublished(), 'g'))) . '. ' . __('Click to unpublish content.'));
         } else {
             $contentEditor->addChild(__('Publish'), '@sympal_publish_content?id=' . $content['id'], 'title=' . __('Has not been published yet. ' . __('Click to publish content.')));
         }
     }
 }
Пример #10
0
 public static function getSympalConfiguration()
 {
     return sfSympalConfiguration::getActive();
 }
Пример #11
0
 /**
  * This gets the correct template to render with
  * 
  * The process is this:
  *   1) Look first on the content record itself for a template "name"
  *   2) Look next on the type record for a template "name"
  * 
  * We then retrieve the actual template (module/template) by looking
  * under the "content_templates" key of the current content template's
  * configuration for the template "name".
  * 
  * If all else fails, the "default_view" template name of the current
  * content type config will be used
  */
 public function getTemplateToRenderWith()
 {
     if (!($templateName = $this->getTemplate())) {
         $templateName = $this->getType()->getTemplate();
     }
     $templates = sfSympalConfiguration::getActive()->getContentTemplates($this->getType()->getName());
     if (isset($templates[$templateName])) {
         if (!is_array($templates[$templateName]) || !isset($templates[$templateName]['template'])) {
             throw new sfException(sprintf('Key "template" must be set under content_template "%s" in app.yml', $templateName));
         }
         $template = $templates[$templateName]['template'];
     } else {
         if (isset($templates['default_view'])) {
             if (!is_array($templates['default_view']) || !isset($templates['default_view']['template'])) {
                 throw new sfException('Key "template" must be set under content_template "default_view" in app.yml');
             }
             $template = $templates['default_view']['template'];
         } else {
             throw new sfException(sprintf('No "default_view" template specified for "%s" content type', $this->getType()->getName()));
         }
     }
     return $template;
 }