Ejemplo n.º 1
0
 /** {@inheritdoc} */
 public function toTwig()
 {
     $content = $this->content;
     if ($this->allowTemplateSyntax) {
         $tpl = Curry_Twig_Template::loadTemplateString($content);
         $content = $tpl->render(array());
     }
     return array('content' => $content);
 }
Ejemplo n.º 2
0
 /** {@inheritdoc} */
 public function toTwig()
 {
     $flashvars = array();
     foreach ($this->flashvars as $flashvar) {
         $flashvars[$flashvar['name']] = $flashvar['value'];
     }
     if ($this->module) {
         $moduleTemplate = $this->template ? Curry_Twig_Template::loadTemplate($this->template) : null;
         $flashvars[$this->moduleFlashvar] = $this->module->showFront($moduleTemplate);
     }
     if (in_array("get", $this->addToFlashvars)) {
         Curry_Array::extend($flashvars, $_GET);
     }
     if (in_array("post", $this->addToFlashvars)) {
         Curry_Array::extend($flashvars, $_POST);
     }
     if (in_array("cookie", $this->addToFlashvars)) {
         Curry_Array::extend($flashvars, $_COOKIE);
     }
     $options = array();
     $options['expressInstall'] = $this->expressInstall;
     $options['target'] = $this->target;
     $options['attributes'] = count($this->attributes) ? $this->attributes : null;
     $options['params'] = count($this->params) ? $this->params : null;
     $options['flashvars'] = count($flashvars) ? $flashvars : null;
     $options['alternativeContent'] = $this->alternativeContent;
     $flashContent = Curry_Flash::embed($this->method, $this->flash, $this->width, $this->height, $this->version, $options);
     return array('Source' => $this->flash, 'Target' => $this->target, 'AlternativeContent' => $this->alternativeContent, 'Html' => $flashContent['html'], 'Script' => $flashContent['script']);
 }
Ejemplo n.º 3
0
 /**
  * Clear cache.
  * 
  * @todo Clear templates.
  */
 public function showClearCache()
 {
     $this->addMainMenu();
     Curry_Core::$cache->clean(Zend_Cache::CLEANING_MODE_ALL);
     Curry_Twig_Template::getSharedEnvironment()->clearCacheFiles();
     if (extension_loaded('apc')) {
         @apc_clear_cache();
     }
     $this->addMessage('Cache cleaned', self::MSG_SUCCESS);
 }
Ejemplo n.º 4
0
 /**
  * Wrap module with inline admin controls.
  *
  * @param string $content
  * @param Curry_PageModuleWrapper $pageModuleWrapper
  * @return string
  */
 protected function adminModule($content, Curry_PageModuleWrapper $pageModuleWrapper)
 {
     $user = User::getUser();
     $pageId = $pageModuleWrapper->getPageRevision()->getPageId();
     $page = $pageModuleWrapper->getPageRevision()->getPage();
     $pageModuleId = $pageModuleWrapper->getPageModuleId();
     $commands = array();
     $templatePermission = $user->hasAccess('Curry_Backend_Template');
     $contentPermission = $user->hasPagePermission($page, PageAccessPeer::PERM_CONTENT);
     $modulePermission = $user->hasPagePermission($page, PageAccessPeer::PERM_MODULES);
     $createPermission = $user->hasPagePermission($page, PageAccessPeer::PERM_CREATE_MODULE);
     if (!$user->hasModuleAccess($pageModuleWrapper)) {
         return $content;
     }
     if ($contentPermission || $modulePermission) {
         $url = url('admin.php', array('module' => 'Curry_Backend_Page', 'view' => 'Module', 'page_id' => $pageId, 'page_module_id' => $pageModuleId));
         if ($user->hasPagePermission($page, PageAccessPeer::PERM_CONTENT)) {
             $commands['edit'] = array('Name' => 'Edit', 'Url' => $url, 'Class' => 'iframe');
         }
     }
     if ($pageModuleWrapper->getTemplate() && $templatePermission) {
         $url = url('admin.php', array('module' => 'Curry_Backend_Template', 'view' => 'Edit', 'file' => $pageModuleWrapper->getTemplate()));
         $commands['template'] = array('Name' => 'Edit template', 'Url' => $url, 'Class' => 'iframe');
     }
     if ($modulePermission) {
         $url = url('admin.php', array('module' => 'Curry_Backend_Page', 'view' => 'ModuleProperties', 'page_id' => $pageId, 'page_module_id' => $pageModuleId));
         $commands['properties'] = array('Name' => 'Properties', 'Url' => $url, 'Class' => 'iframe');
     }
     if ($createPermission && ($contentPermission && !$pageModuleWrapper->isInherited() || $modulePermission)) {
         $url = url('admin.php', array('module' => 'Curry_Backend_Page', 'view' => 'DeleteModule', 'page_id' => $pageId, 'page_module_id' => $pageModuleId));
         $commands['delete'] = array('Name' => 'Delete', 'Url' => $url, 'Class' => 'iframe');
     }
     $module = $pageModuleWrapper->createObject();
     $module->setPageGenerator($this);
     $commands = $module->getInlineCommands($commands);
     if (!count($commands)) {
         return $content;
     }
     $tpl = Curry_Twig_Template::loadTemplateString(Curry_InlineAdmin::getAdminModuleTpl());
     return $tpl->render(array('Id' => $pageModuleId, 'Name' => $pageModuleWrapper->getName(), 'ClassName' => $pageModuleWrapper->getClassName(), 'Content' => $content, 'commands' => $commands));
 }
Ejemplo n.º 5
0
 public function templateToString($template, BaseObject $obj)
 {
     $tpl = Curry_Twig_Template::loadTemplateString($template);
     return $tpl->render(Curry_Propel::toTwig($obj));
 }
Ejemplo n.º 6
0
 /**
  * Get the template object for this PageRevision.
  *
  * @return Curry_Twig_Template
  */
 public function getTemplateObject()
 {
     $rootTemplate = $this->getRootTemplate();
     if (!$rootTemplate) {
         throw new Exception("Page has no root template");
     }
     return Curry_Twig_Template::loadTemplate($rootTemplate);
 }
Ejemplo n.º 7
0
 /** {@inheritdoc} */
 public function showFront(Curry_Twig_Template $template = null)
 {
     $twig = $this->toTwig();
     return $template ? $template->render($twig) : $twig['content'];
 }
Ejemplo n.º 8
0
    /**
     * Main view.
     *
     * @return string
     */
    public function getFinder()
    {
        if (isPost() && isset($_REQUEST['action'])) {
            try {
                // call instance method
                $method = 'action' . $_REQUEST['action'];
                if (!method_exists($this, $method)) {
                    throw new Curry_Exception('Action does not exist.');
                }
                $contentType = isset($_GET['iframe']) ? 'text/html' : 'application/json';
                Curry_Application::returnJson($this->{$method}($_REQUEST), "", $contentType);
            } catch (Exception $e) {
                if (isAjax()) {
                    $this->returnJson(array('status' => 0, 'error' => $e->getMessage()));
                } else {
                    $this->addMessage($e->getMessage(), self::MSG_ERROR);
                }
            }
        }
        $template = Curry_Twig_Template::loadTemplateString(<<<TPL
{% spaceless %}
<div class="finder">
  {% if selection %}
  <input type="hidden" name="selection" value="{{selection}}" />
  {% endif %}
  <div class="finder-overlay"><p></p></div>
  <div class="wrapper">
  {% for path in paths %}
  <ul class="folder {{path.IsRoot?'root':''}}" data-finder='{"path":"{{path.Path}}","action":"{{path.UploadUrl}}"}'>
    {% for file in path.files %}
    <li class="{{file.IsSelected?'selected':(file.IsHighlighted?'highlighted':'')}} {{file.Icon}}"><a href="{{file.Url}}" class="navigate" data-finder='{"name":"{{file.Name}}","path":"{{file.Path}}"}'>{{file.Name}}</a></li>
    {% endfor %}
  </ul>
  {% endfor %}
  {% if fileInfo %}
  <ul class="fileinfo">
    {% for Key,Value in fileInfo %}
    <li class="fileinfo-{{Key|lower}}">{{Value|raw}}</li>
    {% endfor %}
  </ul>
  {% endif %}
  </div>
  <div class="btn-toolbar">
    <div class="btn-group">
      {% for action in actions %}
      <a href="{{action.Action}}" class="btn {{action.Class}}" data-finder='{{action.Data ? action.Data|json_encode : ''}}'>{{action.Label}}</a>
      {% endfor %}
    </div>
    <select></select>
    <div class="btn-group">
      <button class="btn cancel">Cancel</button>
      <button class="btn btn-primary select" {{selection?'':'disabled=""'}}>Select</button>
    </ul>
  </div>
</div>
{% endspaceless %}
TPL
);
        $vars = array();
        $selected = (array) $_GET['path'];
        if ($_GET['public'] == 'true') {
            $virtual = array();
            foreach ($selected as $s) {
                $virtual[] = self::publicToVirtual($s);
            }
            $selected = $virtual;
        }
        // Verify selection and show selection info
        if (count($selected)) {
            try {
                $vars['fileInfo'] = $this->getFileInfo($selected);
                $selection = array();
                foreach ($selected as $s) {
                    $physical = self::virtualToPhysical($s);
                    $public = self::virtualToPublic($s);
                    $selection[] = $public;
                    if (isset($_GET['type'])) {
                        if ($_GET['type'] == 'folder' && !is_dir($physical)) {
                            $selection = false;
                            break;
                        }
                        if ($_GET['type'] == 'file' && !is_file($physical)) {
                            $selection = false;
                            break;
                        }
                    }
                }
                if ($selection) {
                    $vars['selection'] = join(PATH_SEPARATOR, $selection);
                }
            } catch (Exception $e) {
                $selected = array();
            }
        }
        // Show actions
        if ($selected && $selected[0]) {
            $vars['actions'] = array(array('Label' => 'Download', 'Action' => (string) url('', array('module', 'view' => 'Download', 'path' => $selected))));
            if ($this->isPhysicalWritable(self::virtualToPhysical($selected[0]))) {
                $vars['actions'][] = array('Label' => 'Upload', 'Action' => (string) url('', array('module', 'view', 'path' => $selected[0], 'action' => 'Upload')), 'Class' => 'upload');
                $vars['actions'][] = array('Label' => 'Delete', 'Action' => (string) url('', array('module', 'view', 'path' => $selected, 'action' => 'Delete')), 'Class' => 'delete');
                $vars['actions'][] = array('Label' => 'Create directory', 'Action' => (string) url('', array('module', 'view', 'path' => $selected[0], 'action' => 'CreateDirectory')), 'Class' => 'create-directory');
                if (count($selected) == 1) {
                    $vars['actions'][] = array('Label' => 'Rename', 'Action' => (string) url('', array('module', 'view', 'path' => $selected[0], 'action' => 'Rename')), 'Class' => 'rename', 'Data' => array('name' => basename($selected[0])));
                }
            }
        }
        $vars['paths'] = self::getPaths($selected);
        $content = $template->render($vars);
        if (isAjax()) {
            $this->returnJson(array('content' => $content, 'maxUploadSize' => Curry_Util::computerReadableBytes(get_cfg_var('upload_max_filesize')), 'path' => $selected));
        } else {
            return $content;
        }
        return '';
    }
Ejemplo n.º 9
0
 /**
  * Get shared Twig environment.
  * 
  * This environment is automatically setup from the curry cms configuration.
  *
  * @return Twig_Environment
  */
 public static function getSharedEnvironment()
 {
     if (!self::$twig) {
         $loader = new Twig_Loader_Filesystem(Curry_Core::$config->curry->template->root);
         self::$twig = self::createTwigEnvironment($loader);
     }
     return self::$twig;
 }
Ejemplo n.º 10
0
 /**
  * Create new module form.
  *
  * @param PageRevision $pageRevision
  * @param string $moduleClass
  * @return Curry_Form
  */
 public static function getNewModuleForm($pageRevision, $moduleClass, $target)
 {
     $valid = array();
     $modules = array();
     foreach (ModuleQuery::create()->orderByTitle()->find() as $module) {
         $inTargets = in_array($target, $module->getTargets());
         if (!$target || ($module->getTargetsExclude() ? !$inTargets : $inTargets)) {
             $modules[$module->getModuleId()] = $module->getTitle();
             $valid[] = $module->getModuleId();
         }
     }
     $user = User::getUser();
     $modulePermission = $user->hasPagePermission($pageRevision->getPage(), PageAccessPeer::PERM_MODULES);
     if ($modulePermission) {
         $modules = array('Predefined' => $modules);
         foreach (Curry_Module::getModuleList() as $className) {
             $parts = explode("_", str_replace("_Module_", "_", $className));
             $package = array_shift($parts);
             $modules[$package][$className] = join(" / ", $parts);
             $valid[] = $className;
         }
     }
     if (!$moduleClass || !in_array($moduleClass, $valid)) {
         $form = new Curry_Form(array('action' => url('', $_GET), 'method' => 'post', 'class' => isAjax() ? 'dialog-form' : '', 'elements' => array('module_class' => array('select', array('label' => 'Type', 'multiOptions' => $modules, 'required' => true)), 'next' => array('submit', array('label' => 'Next')))));
         return $form;
     } else {
         // Fetch template targets
         $targets = array();
         try {
             $template = $pageRevision->getInheritedProperty('Template');
             if ($template) {
                 $template = Curry_Twig_Template::loadTemplate($template);
             }
             while ($template) {
                 $targets = array_merge($targets, $template->getPlaceholders());
                 $template = $template->getParent(array());
             }
         } catch (Exception $e) {
             trace_warning('Error in template: ' . $e->getMessage());
         }
         if (count($targets)) {
             $targets = array_combine(array_values($targets), array_values($targets));
         }
         // Check for predefined module creation
         if (ctype_digit($moduleClass)) {
             $module = ModuleQuery::create()->findPk($moduleClass);
             $form = new Curry_Form(array('action' => url('', $_GET), 'method' => 'post', 'class' => isAjax() ? 'dialog-form' : '', 'elements' => array('pid_newmodule' => array('hidden', array('value' => 1)), 'module_class' => array('hidden', array('value' => $moduleClass)), 'name' => array('text', array('label' => 'Name', 'required' => true, 'description' => 'A descriptive name of the module.', 'value' => $module->getName())))));
             if (!$target) {
                 // Show only acceptable targets...
                 $form->addElement('select', 'target', array('label' => 'Target', 'description' => 'Specifies what placeholder/variable in the page-template to attach this module to.', 'multiOptions' => $targets));
             } else {
                 $form->addElement('hidden', 'target', array('value' => $target));
                 $form->setCsrfCheck(false);
                 $_POST = $form->getValues();
             }
             $form->addElement('submit', 'add', array('label' => 'Add module'));
             return $form;
         }
         if (!class_exists($moduleClass)) {
             throw new Exception('Class \'' . $moduleClass . '\' could not be loaded, please check the path and classname.');
         }
         $defaultName = substr($moduleClass, strrpos($moduleClass, '_') + 1);
         $targets[''] = '[ Custom ]';
         asort($targets);
         $templates = array('' => "[ None ]", 'new' => "[ Create new ]") + Curry_Backend_Template::getTemplateSelect();
         $defaultTemplateName = 'Modules/' . $defaultName . '.html';
         $defaultTemplate = '';
         if ($moduleClass !== 'Curry_Module_Article' && call_user_func(array($moduleClass, 'hasTemplate'))) {
             $defaultTemplate = array_key_exists($defaultTemplateName, $templates) ? $defaultTemplateName : 'new';
         }
         $predefinedTemplates = call_user_func(array($moduleClass, 'getPredefinedTemplates'));
         $predefinedTemplates = count($predefinedTemplates) ? array_combine(array_keys($predefinedTemplates), array_keys($predefinedTemplates)) : array();
         $predefinedTemplates = array('' => '[ Empty ]') + $predefinedTemplates;
         $form = new Curry_Form(array('action' => url('', $_GET), 'method' => 'post', 'class' => isAjax() ? 'dialog-form' : '', 'elements' => array('pid_newmodule' => array('hidden'), 'module_class' => array('hidden', array('value' => $moduleClass)), 'module_class_display' => array('rawHtml', array('label' => 'Type', 'value' => '<input type="text" value="' . $moduleClass . '" disabled="disabled" />')), 'name' => array('text', array('label' => 'Name', 'required' => true, 'description' => 'A descriptive name of the module.', 'value' => $defaultName)), 'target' => array('select', array('label' => 'Target', 'description' => 'Specifies what placeholder/variable in the page-template to attach this module to.', 'value' => isset($_GET['target']) ? $_GET['target'] : null, 'multiOptions' => $targets, 'class' => 'trigger-change', 'onchange' => "\$('#target_name-label, #target_name-element').toggle(\$(this).val() == '');")), 'target_name' => array('text', array('label' => 'Target Name')), 'template' => array('select', array('class' => 'trigger-change', 'label' => 'Template', 'multiOptions' => $templates, 'value' => $defaultTemplate, 'onchange' => "\$('#template_name-label, #template_name-element, #predefined_template-label, #predefined_template-element').toggle(\$(this).val() == 'new');")), 'template_name' => array('text', array('label' => 'Name', 'value' => $defaultTemplateName)), 'predefined_template' => array('select', array('label' => 'Predefined template', 'multiOptions' => $predefinedTemplates)), 'content_visibility' => array('select', array('label' => 'Content Visibility', 'description' => 'Set the visibility of this module in the Content backend module.', 'multiOptions' => PageModulePeer::$contentVisiblityOptions, 'value' => PageModulePeer::CONTENT_VISIBILITY_ALWAYS, 'required' => true)), 'search_visibility' => array('checkbox', array('label' => 'Search Visibility', 'description' => 'If this module should be rendered when indexing pages.', 'value' => true, 'required' => true)))));
         $form->addDisplayGroup(array('position', 'content_visibility', 'search_visibility'), 'advanced', array('class' => 'advanced', 'legend' => 'Advanced'));
         $form->addElement('submit', 'add', array('label' => 'Add module'));
     }
     return $form;
 }
Ejemplo n.º 11
0
 /**
  * This function will be called when rendering a module. By default a
  * template is required, and it will be rendered using the results from
  * the toTwig() function.
  *
  * @param Curry_Twig_Template|null $template
  * @return string	The content generated by the module.
  */
 public function showFront(Curry_Twig_Template $template = null)
 {
     if (!$template) {
         throw new Exception('A template is required for this module (' . get_class($this) . ').');
     }
     return $template->render($this->toTwig());
 }