/** {@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']); }
protected function getFileAccessList($query = null, $formOptions = array(), $listOptions = array()) { if (!$query) { $query = FilebrowserAccessQuery::create(); } $o = array('columnElements' => array('path' => array('filebrowser', array('filebrowserOptions' => array('local' => false), 'finderOptions' => array('type' => 'folder'), 'allowEmpty' => false, 'validators' => array(array('callback', false, array('callback' => array($this, 'validatePath')))))), 'write' => array('select', array('label' => 'Access', 'multiOptions' => array('' => 'Read', '1' => 'Read / Write'))))); Curry_Array::extend($o, $formOptions); $modelForm = new Curry_Form_ModelForm('FilebrowserAccess', $o); $modelForm->path->getValidator('callback')->setMessage("Invalid permissions to path '%value%'"); $form = new Curry_ModelView_Form($modelForm); $o = array('title' => 'File permissions', 'modelForm' => $form, 'columns' => array('write' => array('label' => 'Access', 'display' => '{{Write?"Read / Write":"Read"}}'))); Curry_Array::extend($o, $listOptions); $list = new Curry_ModelView_List($query, $o); return $list; }
public function setOptions(array $options) { if (isset($options['actions'])) { foreach ($options['actions'] as $name => $action) { $this->addAction($name, $action); } unset($options['actions']); } if (isset($options['columns'])) { foreach ($options['columns'] as $name => $column) { $this->addColumn($name, $column); } unset($options['columns']); } foreach ($options as $k => $v) { if (method_exists($this, 'set' . $k)) { $this->{'set' . $k}($v); } else { if (property_exists($this, $k)) { if (is_array($this->{$k})) { Curry_Array::extend($this->{$k}, $v); } else { $this->{$k} = $v; } } else { continue; } } unset($options[$k]); } Curry_Array::extend($this->options, $options); }
/** * Render a page and return content. * * @param array $vars * @param array $options * @return string */ public function render(array $vars = array(), array $options = array()) { $twig = Curry_Twig_Template::getSharedEnvironment(); // Todo: Rename curry to app? $appVars = Curry_Application::getInstance()->getGlobalVariables(); if (isset($vars['curry'])) { Curry_Array::extend($appVars, $vars['curry']); } $vars['curry'] = Curry_Array::extend($appVars, $this->getGlobals()); foreach ($vars as $k => $v) { $twig->addGlobal($k, $v); } $moduleContent = $this->generate($options); if (isset($options['pageModuleId'])) { $pageModuleId = $options['pageModuleId']; $pageModuleWrappers = $this->getPageModuleWrappers(); if (isset($pageModuleWrappers[$pageModuleId])) { $pageModuleWrapper = $pageModuleWrappers[$pageModuleId]; return $moduleContent[$pageModuleWrapper->getTarget()]; } else { throw new Exception('PageModule with id = ' . $pageModuleId . ' not found on page.'); } } $template = $this->getTemplateObject(); return $this->renderTemplate($template, $moduleContent); }
/** * Load configuration. * * @param string|array|null $config * @param bool $loadUserConfig * @return array */ private static function getConfig($config, $loadUserConfig = true) { $userConfig = array(); $configPath = null; $projectPath = null; if (is_string($config)) { // Load configuration from file $configPath = realpath($config); if (!$configPath) { throw new Exception('Configuration file not found: ' . $config); } $projectPath = Curry_Util::path(true, dirname($configPath), '..'); if ($loadUserConfig) { $userConfig = (require $configPath); } } else { if (is_array($config)) { // Configuration provided by array if ($loadUserConfig) { $userConfig = $config; } } else { if ($config === null || $config === false) { // Skip configuration } else { throw new Exception('Unknown configuration format.'); } } } // Attempt to find project path if (!$projectPath) { $projectPath = Curry_Util::path(true, getcwd(), '..', 'cms'); } if (!$projectPath) { $projectPath = Curry_Util::path(true, getcwd(), 'cms'); } // default config $config = array('curry' => array('name' => "untitled", 'baseUrl' => '/', 'adminEmail' => "*****@*****.**", 'divertOutMailToAdmin' => false, 'statistics' => false, 'applicationClass' => 'Curry_Application', 'defaultGeneratorClass' => 'Curry_PageGenerator_Html', 'forceDomain' => false, 'revisioning' => false, 'umask' => 02, 'liveEdit' => true, 'secret' => 'SECRET', 'errorNotification' => false, 'errorReporting' => E_ALL ^ E_NOTICE, 'generator' => 'Curry_PageGenerator_Html', 'internalEncoding' => 'utf-8', 'outputEncoding' => 'utf-8', 'basePath' => Curry_Util::path(true, dirname(__FILE__), '..', '..'), 'projectPath' => $projectPath, 'wwwPath' => getcwd(), 'configPath' => $configPath, 'cache' => array('method' => 'auto'), 'mail' => array('method' => 'sendmail'), 'log' => array('method' => 'none'), 'maintenance' => array('enabled' => false), 'defaultEditor' => 'tinyMCE', 'migrationVersion' => self::MIGRATION_VERSION, 'pageCache' => true, 'autoPublish' => false, 'developmentMode' => false, 'autoUpdateIndex' => false, 'password' => array('algorithm' => PASSWORD_BCRYPT, 'options' => array('cost' => 10)), 'debug' => array('moduleTimeLimit' => 0.5, 'moduleCpuLimit' => 0.25, 'moduleMemoryLimit' => 5 * 1024 * 1024, 'moduleSqlLimit' => 8))); if ($loadUserConfig) { Curry_Array::extend($config, $userConfig); } // Fix base url $config['curry']['baseUrl'] = url($config['curry']['baseUrl'])->getAbsolute(); if (!$config['curry']['projectPath']) { throw new Exception('Project path could not be found, please use a configuration file to specify the path'); } $secondaryConfig = array('curry' => array('vendorPath' => Curry_Util::path($config['curry']['basePath'], 'vendor'), 'tempPath' => self::getTempPath($config['curry']['projectPath']), 'trashPath' => Curry_Util::path($config['curry']['projectPath'], 'data', 'trash'), 'hooksPath' => Curry_Util::path($config['curry']['projectPath'], 'config', 'hooks.php'), 'autoBackup' => $config['curry']['developmentMode'] ? 0 : 86400, 'propel' => array('conf' => Curry_Util::path($config['curry']['projectPath'], 'config', 'propel.php'), 'projectClassPath' => Curry_Util::path($config['curry']['projectPath'], 'propel', 'build', 'classes')), 'template' => array('root' => Curry_Util::path($config['curry']['projectPath'], 'templates'), 'options' => array('debug' => (bool) $config['curry']['developmentMode'], 'cache' => Curry_Util::path($config['curry']['projectPath'], 'data', 'cache', 'templates'), 'base_template_class' => 'Curry_Twig_Template')), 'backend' => array('placeholderExclude' => array(), 'theme' => 'vindaloo', 'loginCookieExpire' => 31536000, 'loginTokenExpire' => 31536000), 'mail' => array('options' => array()), 'domainMapping' => array('enabled' => false, 'domains' => array()))); $config = Curry_Array::extend($secondaryConfig, $config); return $config; }
/** * Metadata form. * * @param PageRevision $pageRevision * @return Curry_Form */ public static function getMetadataForm(PageRevision $pageRevision) { $query = PageMetadataQuery::create()->joinWith('Metadata', Criteria::RIGHT_JOIN)->addJoinCondition('Metadata', 'PageMetadata.PageRevisionId = ?', $pageRevision->getPageRevisionId())->orderBy('Metadata.SortableRank'); $metadatas = $query->find(); $form = new Curry_Form(array('action' => url('', array("module", "view", "page_id")), 'method' => 'post', 'elements' => array('pid_metadata' => array('hidden')))); $typeOptions = array('textarea' => array('rows' => 6)); foreach ($metadatas as $pageMetadata) { $metadata = $pageMetadata->getMetadata(); $options = array('label' => $metadata->getDisplayName(), 'value' => $pageMetadata->getValue() !== null ? $pageMetadata->getValue() : $metadata->getDefaultValue()); if (isset($typeOptions[$metadata->getType()])) { Curry_Array::extend($options, $typeOptions[$metadata->getType()]); } $form->addElement($metadata->getType(), $metadata->getName(), $options); } $form->addElement('submit', 'save', array('label' => 'Save')); return $form; }