/** * Returns the config form and checks the file permissions * * @return sfSympalConfigForm */ protected function _getForm() { $this->checkFilePermissions(); $class = sfSympalConfig::get('config_form_class', null, 'sfSympalConfigForm'); $this->form = new $class(); return $this->form; }
public function executeIndex() { $response = $this->getResponse(); $response->addJavascript(sfSympalConfig::getAssetPath('/sfSympalPlugin/js/shortcuts.js')); $response->addJavascript(sfSympalConfig::getAssetPath('/sfSympalAdminPlugin/js/shortcuts.js')); if (sfSympalConfig::get('check_for_upgrades_on_dashboard', null, false)) { $this->upgrade = new sfSympalUpgradeFromWeb($this->getContext()->getConfiguration(), $this->getContext()->getEventDispatcher(), new sfFormatter()); $this->hasNewVersion = $this->upgrade->hasNewVersion(); } else { $this->hasNewVersion = false; } $this->dashboardRight = new sfSympalMenu('Sympal Dashboard Right'); $numUsers = Doctrine_Core::getTable('sfGuardUser')->count(); $this->dashboardRight->addChild(sprintf('<label>Users</label> %s', $numUsers), '@sympal_users'); $numSites = Doctrine_Core::getTable('sfSympalSite')->count(); $this->dashboardRight->addChild(sprintf('<label>Sites</label> %s', $numSites), '@sympal_sites'); $numContentTypes = Doctrine_Core::getTable('sfSympalContentType')->count(); $this->dashboardRight->addChild(sprintf('<label>Content Types</label> %s', $numContentTypes), '@sympal_content_types'); $contentTypes = Doctrine::getTable('sfSympalContentType')->getAllContentTypes(); foreach ($contentTypes as $contentType) { $numPublishedContent = Doctrine_Core::getTable('sfSympalContent')->createQuery('c')->where('c.date_published < NOW()')->andWhere('c.content_type_id = ?', $contentType->getId())->count(); $this->dashboardRight->addChild(sprintf('<label>Published %s Content</label> %s', $contentType->getLabel(), $numPublishedContent), '@sympal_content_list_type?type=' . $contentType->getId() . '&published=1'); $numUnPublishedContent = Doctrine_Core::getTable('sfSympalContent')->createQuery('c')->where('c.date_published >= NOW() OR c.date_published IS NULL')->andWhere('c.content_type_id = ?', $contentType->getId())->count(); $this->dashboardRight->addChild(sprintf('<label>Un-Published %s Content</label> %s', $contentType->getLabel(), $numUnPublishedContent), '@sympal_content_list_type?type=' . $contentType->getId() . '&published=0'); } sfApplicationConfiguration::getActive()->getEventDispatcher()->notify(new sfEvent($this->dashboardRight, 'sympal.load_dashboard_right')); }
/** * Searches through the content and extracts out any matches. The return * value is a formatted array of what needs to be replaced * * Returned syntax will look like this: * array( * 'link' => array( * 3 => array('options' => array(), 'replace' => '[link:3]'), * 5 => array('options' => array('option' => 'value'), 'replace' => '[link:5 option=value]'), * ), asset => array( * 10 => array('options' => array(), 'replace' => '[asset:10]'), * ), * ) * * @return array */ private function _parseSyntaxes($content) { // create the replacement string (e.g. link|asset|myObject) $replacementString = implode('|', array_keys(sfSympalConfig::get('content_syntax_types'))); preg_match_all("/\\[({$replacementString}):(.*?)\\]/", $content, $matches); if (isset($matches[0]) && $matches[0]) { $replacements = array(); $types = $matches[1]; $bodies = $matches[2]; foreach ($types as $type) { $replacements[$type] = array(); } /* * body matches (e.g. "3" or "5 option=value") */ foreach ($bodies as $key => $body) { // use the key to find the corresponding type $typeKey = $types[$key]; $e = explode(' ', $body); $slug = $e[0]; $replacements[$typeKey][$slug] = array('options' => _parse_attributes(substr($body, strlen($e[0]))), 'replace' => $matches[0][$key]); } return $replacements; } else { return false; } }
/** * Include a content slot in your template. * * This replaces get_sympal_content_slot() and is intended to be easier * to use. This also taps into the app.yml config for its options * * @param string $name The name of the slot * @param array $options An array of options for this slot * * Available options include * * content An sfSympalContent instance to render the slot for * * type The rendering type to use for this slot (e.g. Markdown) * * default_value A default value to give this slot the first time it's created * * edit_mode How to edit this slot (popup (default), inline) */ function _get_sympal_content_slot($name, $options = array()) { if (isset($options['content'])) { $content = $options['content']; unset($options['content']); } else { $content = sfSympalContext::getInstance()->getCurrentContent(); } // mark this content record as having content slots $content->setEditableSlotsExistOnPage(true); // merge the default config for this slot into the given config $slotOptions = sfSympalConfig::get($content->Type->slug, 'content_slots', array()); if (isset($slotOptions[$name])) { $options = array_merge($slotOptions[$name], $options); } // retrieve the slot if ($name instanceof sfSympalContentSlot) { $slot = $name; $name = $name->getName(); } else { $slot = $content->getOrCreateSlot($name, $options); unset($options['default_value']); } $slot->setContentRenderedFor($content); /** * Either render the raw value or the editor for the slot */ if (sfSympalContext::getInstance()->shouldLoadFrontendEditor()) { use_helper('SympalContentSlotEditor'); return get_sympal_content_slot_editor($content, $slot, $options); } else { return $slot->render(); } }
/** * Returns the anchor tag to a comment's website * * @param string $url The url of the website to link to * @param string $label The text to include inside the link * @param array $options An array of link options * @return string */ function link_to_sympal_comment_website($comment, $options = array()) { if (sfSympalConfig::get('sfSympalCommentsPlugin', 'websites_no_follow')) { $options['rel'] = 'nofollow'; } return link_to($comment['author_name'], $comment['website'], $options); }
public function executeCreate_asset(sfWebRequest $request) { $form = new sfSympalAssetUploadForm(); $upload = $request->getParameter($form->getName()); $form->setUploadDirectory($upload['directory']); $form->bind($upload, $request->getFiles($form->getName())); if ($form->isValid()) { $postFile = $form->getValue('file'); $fileName = $postFile->getOriginalName(); $name = Doctrine_Inflector::urlize(sfSympalAssetToolkit::getNameFromFile($fileName)); $extension = pathinfo($fileName, PATHINFO_EXTENSION); $fullName = $extension ? $name . '.' . $extension : $name; $destinationDirectory = sfConfig::get('sf_web_dir') . '/' . sfSympalConfig::get('assets', 'root_dir') . $upload['directory']; $this->getUser()->setFlash('notice', 'File uploaded successfully.'); $postFile->save($destinationDirectory . '/' . $fullName); $assetObject = sfSympalAssetToolkit::createAssetObject($upload['directory'] . '/' . $fullName); if (!($asset = $assetObject->getDoctrineAsset())) { $asset = new sfSympalAsset(); } $asset->path = $assetObject->getRelativePathDirectory(); $asset->name = $assetObject->getName(); $asset->save(); } else { $this->getUser()->setFlash('error', 'Could not upload file.'); } if ($this->isAjax) { $this->redirect('@sympal_assets_select?is_ajax=' . $this->isAjax . '&dir=' . $upload['directory']); } else { $this->redirect('@sympal_assets?is_ajax=' . $this->isAjax . '&dir=' . $upload['directory']); } }
public function buildDataGrid(sfWebRequest $request) { if ($this->table_method) { $typeTable = Doctrine_Core::getTable($this->ContentType->name); $method = $this->table_method; $q = $typeTable->{$method}($this, $request); if ($q instanceof sfSympalDataGrid) { $dataGrid = $q; } else { if ($q instanceof sfDoctrinePager || $q instanceof Doctrine_Query_Abstract) { $dataGrid = sfSympalDataGrid::create($q); } else { throw new sfException(sprintf('ContentList table_method must return an instance of sfSympalDataGrid, sfDoctrinePager or Doctrine_Query_Abstract. An instance of "%s" was returned.', get_class($q))); } } } else { $pager = new sfDoctrinePager('sfSympalContent'); $pager->setQuery($this->_buildQuery($request)); $dataGrid = sfSympalDataGrid::create($pager)->addColumn('c.title', 'renderer=sympal_data_grid/default_title')->addColumn('c.date_published')->addColumn('u.username', 'label=Created By'); } if ($this->sort_column) { $dataGrid->setDefaultSort($this->sort_column, $this->sort_order); } $dataGrid->setMaxPerPage($this->rows_per_page > 0 ? $this->rows_per_page : sfSympalConfig::get('rows_per_page', null, 10)); $dataGridRequestInfo = $request->getParameter($dataGrid->getId()); return $dataGrid; }
/** * Check if Sympal is installed and redirect to installer if not. * Do some other install checks as well. * * @return void */ private function _checkInstalled() { $request = $this->_symfonyContext->getRequest(); // Prepare the symfony application if it has not been prepared yet if (!$this->_symfonyContext->getUser() instanceof sfSympalUser) { chdir(sfConfig::get('sf_root_dir')); $task = new sfSympalEnableForAppTask($this->_dispatcher, new sfFormatter()); $task->run(array($this->_invoker->getProjectConfiguration()->getApplication()), array()); $this->_symfonyContext->getController()->redirect('@homepage'); } /* * Redirect to install module if... * * not in test environment * * sympal has not been installed * * module is not already sympal_install */ if (sfConfig::get('sf_environment') != 'test' && !sfSympalConfig::get('installed') && $request->getParameter('module') != 'sympal_install') { $this->_symfonyContext->getController()->redirect('@sympal_install'); } /* * Redirect to homepage if no site record exists so we can prompt the * user to create a site record for this application. * * This check is only ran in dev mode */ if (sfConfig::get('sf_environment') == 'dev' && !$this->_sympalContext->getSite() && $this->_symfonyContext->getRequest()->getPathInfo() != '/') { $this->_symfonyContext->getController()->redirect('@homepage'); } }
public function run(sfEvent $event, $content) { // The following were removed, but should probably be there //$request->isXmlHttpRequest() //$controller->getRenderMode() != sfView::RENDER_CLIENT || $response = $event->getSubject(); if (strpos($response->getContentType(), 'html') === false || $response->getStatusCode() == 304 || in_array($response->getStatusCode(), array(302, 301)) || $response->isHeaderOnly()) { return $content; } if ($code = sfSympalConfig::get('google_analytics_code')) { $js = <<<EOF <script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); \tdocument.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); </script> <script type="text/javascript"> try { \tvar pageTracker = _gat._getTracker("{$code}"); \tpageTracker._trackPageview(); } catch(err) {}</script> EOF; return str_replace('</body>', $js . '</body>', $content); } else { return $content; } }
/** * Instantiate the sfSympalCache instance and prime the cache for this Sympal * project * * @see sfSympalConfiguration * @see sfSympalPluginConfiguration * @param sfSympalConfiguration $sympalConfiguration */ public function __construct(sfSympalConfiguration $sympalConfiguration) { $this->_sympalConfiguration = $sympalConfiguration; $this->_projectConfiguration = $sympalConfiguration->getProjectConfiguration(); $this->_cacheDriver = call_user_func_array(sfSympalConfig::get('get_cache_driver_callback'), array($this)); $this->primeCache(); }
/** * Handles the form submit for a given slot. This could come from two sources: * 1) Inline, frontend editing. (ajax request) * 2) Admin, non-inline editing (non-ajax request) */ public function executeSlot_save(sfWebRequest $request) { $this->contentSlot = $this->setupContentSlot($request); $this->form = $this->contentSlot->getEditForm(); $this->form->bind($request->getParameter($this->form->getName())); if ($this->form->isValid()) { $this->form->save(); $this->getUser()->setFlash('saved', __('Slot saved'), false); // if we close editor on save, just return the flash js and the editor close js if ($request->isXmlHttpRequest() && sfSympalConfig::get('inline_editing', 'close_editor_on_save', false)) { $this->getContext()->getConfiguration()->loadHelpers('SympalContentSlotEditor'); $this->renderText(trigger_flash_from_user($this->getUser())); $this->renderText(sprintf(' <script type="text/javascript"> $(document).ready(function() { $("#sympal_slot_wrapper_%s").sympalSlot("closeEditor"); }); </script> ', $this->contentSlot->id)); return sfView::NONE; } } else { $this->getUser()->setFlash('error', __('There was an error saving your slot'), false); } // we need to route the response appropriately based on ajax/non-ajax if ($request->isXmlHttpRequest()) { // ajax, just re-show the form $this->renderPartial('sympal_edit_slot/slot_editor_form'); } else { // handle non-ajax, which come from sympal_content/edit_slots // this is a bit of a hack, we redirect even on errors, which is technically a fail $this->redirect('@sympal_content_edit_slots?id=' . $this->contentSlot->getContentRenderedFor()->id); } return sfView::NONE; }
public function loadEditorAssets() { if (!$this->_editorAssetsLoaded) { $this->configuration->loadHelpers('SympalContentSlotEditor'); sfSympalToolkit::useJQuery(array('ui')); $response = sfContext::getInstance()->getResponse(); // Load jquery tools/plugins that the inline editor requires $response->addJavascript(sfSympalConfig::getAssetPath('/sfSympalPlugin/js/jQuery.cookie.js')); $response->addJavascript(sfSympalConfig::getAssetPath('/sfSympalPlugin/js/jQuery.elastic.js')); $response->addJavascript(sfSympalConfig::getAssetPath('/sfSympalPlugin/js/jquery.Jcrop.min.js')); // Load markitup markdown editor if (sfSympalConfig::get('enable_markdown_editor')) { $response->addJavascript(sfSympalConfig::getAssetPath('/sfSympalPlugin/markitup/jquery.markitup.js')); $response->addJavascript(sfSympalConfig::getAssetPath('/sfSympalPlugin/markitup/sets/markdown/set.js')); $response->addStylesheet(sfSympalConfig::getAssetPath('/sfSympalPlugin/markitup/skins/markitup/style.css')); $response->addStylesheet(sfSympalConfig::getAssetPath('/sfSympalPlugin/markitup/sets/markdown/style.css')); } // Load tinymce $response->addJavascript(sfSympalConfig::getAssetPath('/sfSympalPlugin/tiny_mce/tiny_mce.js')); // Load the sympal editor js and css $response->addJavascript(sfSympalConfig::getAssetPath('/sfSympalEditorPlugin/js/editor.js')); $response->addStylesheet(sfSympalConfig::getAssetPath('/sfSympalEditorPlugin/css/editor.css')); // Fancybox $response->addJavascript(sfSympalConfig::getAssetPath('/sfSympalPlugin/fancybox/jquery.fancybox.js')); $response->addStylesheet(sfSympalConfig::getAssetPath('/sfSympalPlugin/fancybox/jquery.fancybox.css')); // Shortcuts $response->addJavascript(sfSympalConfig::getAssetPath('/sfSympalPlugin/js/shortcuts.js')); $this->_editorAssetsLoaded = true; } }
/** * Renders an edit form for a slot * * @param sfSympalContent $content The content on which the slot should be rendered * @param sfSympalContentSlot $slot The slot to render in a form * @param array $options An options array. Available options include: * * edit_mode * */ function get_sympal_content_slot_editor($content, $slot, $options = array()) { $slot->setContentRenderedFor($content); // merge in some global default slot options $options = array_merge(array('edit_mode' => sfSympalConfig::get('inline_editing', 'default_edit_mode'), 'view_url' => url_for('sympal_content_slot_view', array('id' => $slot->id, 'content_id' => $slot->getContentRenderedFor()->id))), $options); // merge the default config for this slot into the given config $slotOptions = sfSympalConfig::get($slot->getContentRenderedFor()->Type->slug, 'content_slots', array()); if (isset($slotOptions[$slot->name])) { $options = array_merge($slotOptions[$slot->name], $options); } /* * Finally, override the "type" option, it should be set to whatever's * in the database, regardless of what the original slot options were */ $options['type'] = $slot->type; /* * Give the slot a default value if it's blank. * * @todo Move this somewhere where it can be specified on a type-by-type * basis (e.g., if we had an "image" content slot, it might say * "Click to choose image" */ $renderedValue = $slot->render(); if (!$renderedValue) { $renderedValue = __('[Hover over and click edit to change.]'); } $inlineContent = sprintf('<a href="%s" class="sympal_slot_button">' . __('Edit') . '</a>', url_for('sympal_content_slot_form', array('id' => $slot->id, 'content_id' => $slot->getContentRenderedFor()->id))); $inlineContent .= sprintf('<span class="sympal_slot_content">%s</span>', $renderedValue); return sprintf('<span class="sympal_slot_wrapper %s" id="sympal_slot_wrapper_%s">%s</span>', htmlentities(json_encode($options)), $slot->id, $inlineContent); }
public function getEmbed($options = array()) { $url = $this->getUrl(); $width = isset($options['width']) ? $options['width'] : sfSympalConfig::get('default_video_width', null, 400); $height = isset($options['height']) ? $options['height'] : sfSympalConfig::get('default_video_height', null, 400); $extension = $this->getExtension(); $id = $this->getDoctrineAsset()->getId(); if ($extension == 'swf') { return sprintf('<object width="%s" height="%s"> <param name="movie" value="%s"> <embed src="%s" width="%s" height="%s"> </embed> </object>', $width, $height, $url, $url, $width, $height); } else { if ($extension == 'flv') { sympal_use_jquery(); sympal_use_javascript('/sfSympalPlugin/js/flowplayer.min.js'); return sprintf('<a href="%s" style="display:block;width:%spx;height:%spx;" id="asset_%s"></a> <script language="JavaScript"> flowplayer("asset_%s", "%s"); </script>', $url, $width, $height, $id, $id, _compute_public_path('/sfSympalPlugin/js/flowplayer.swf', 'swf', 'swf')); } else { return $this->getLink($options); } } }
public function getPathAsString() { $children = array(); foreach ($this->_children as $child) { $children[] = $child->renderLabel(); } return implode(sfSympalConfig::get('breadcrumbs_separator', null, ' / '), $children); }
/** * Check if Sympal is not online and act accordingly * * @return void */ private function _checkOnlineConfiguration() { if (sfSympalConfig::get('offline', 'enabled', false) && !$this->_checkedOnline) { $this->_checkedOnline = true; $this->_invoker->getSymfonyContext()->getController()->forward(sfSympalConfig::get('offline', 'module'), sfSympalConfig::get('offline', 'action')); throw new sfStopException(); } }
public function getActionToRenderWith() { if ($actionName = $this->_get('action')) { return $actionName; } else { return sfSympalConfig::get($this->getSlug(), 'default_rendering_action', sfSympalConfig::get('default_rendering_action', null, 'index')); } }
public function upgrade() { $result = parent::upgrade(); $versionHistory = sfSympalConfig::get('upgrade_version_history', null, array()); $versionHistory[] = $this->_version . '__' . $this->_number; sfSympalConfig::writeSetting('upgrade_version_history', $versionHistory); return $result; }
public function loadAdminMenu(sfEvent $event) { $menu = $event->getSubject(); if (sfSympalConfig::get('sfSympalCommentsPlugin', 'installed', false) && sfSympalConfig::get('sfSympalCommentsPlugin', 'enabled')) { $commentTable = Doctrine::getTable('sfSympalComment')->getNumPending(); $menu->getChild('Content')->addChild('Comments (' . $commentTable . ')', '@sympal_comments'); } }
public function copyOriginal() { $dir = $this->getPathDirectory() . '/' . sfSympalConfig::get('assets', 'originals_dir'); if (!is_dir($dir)) { mkdir($dir, 0777, true); } copy($this->getPath(), $dir . '/' . $this->getName()); }
public function getPluginInstallMenu() { $menu = $this->createQuery('m')->select('m.*')->innerJoin('m.Site s WITH s.slug = ?', sfConfig::get('sf_app'))->where('m.slug = ?', sfSympalConfig::get('default_install_content_type_menu', null, 'primary'))->fetchOne(); if (!$menu) { $menu = Doctrine_Core::getTable('sfSympalMenuItem')->findFirstMenu(); } return $menu; }
/** * Function validates if the current user has the rights to be posting * comments. * * @throws sfException */ protected function authComments() { if (sfSympalConfig::get('sfSympalCommentsPlugin', 'requires_auth') && !$this->getUser()->isAuthenticated()) { throw new sfException('Comments require that you are authenticated!'); } if (!sfSympalConfig::get('sfSympalCommentsPlugin', 'enabled')) { throw new sfException('Commenting is disabled'); } }
/** * Check if we are inside an admin module * * @return boolean */ public function isAdminModule() { if (!($sympalContext = $this->getSympalContext())) { return false; } $module = $sympalContext->getSymfonyContext()->getRequest()->getParameter('module'); $adminModules = sfSympalConfig::get('admin_modules'); return array_key_exists($module, $adminModules); }
/** * Render the date published for a content record * * @param sfSympalContent $content * @param string $slot * @return string $datePublished */ function render_content_date_published(sfSympalContent $content, $slot) { if ($content->date_published) { sfSympalToolkit::loadHelpers('Date'); return format_datetime($content->date_published, sfSympalConfig::get('date_published_format')); } else { return '0000-00-00'; } }
public function hasRecaptcha() { // No recaptcha in test environment if (sfConfig::get('sf_environment') === 'test') { return false; } $forms = sfSympalConfig::get('recaptcha_forms', null, array()); $class = get_class($this->getSubject()); return in_array($class, $forms) || array_key_exists($class, $forms) ? true : false; }
public function executeIndex() { $response = $this->getResponse(); $response->addJavascript(sfSympalConfig::getAssetPath('/sfSympalPlugin/js/shortcuts.js')); $response->addJavascript(sfSympalConfig::getAssetPath('/sfSympalAdminPlugin/js/shortcuts.js')); if (sfSympalConfig::get('check_for_upgrades_on_dashboard', null, false)) { $this->upgrade = new sfSympalUpgradeFromWeb($this->getContext()->getConfiguration(), $this->getContext()->getEventDispatcher(), new sfFormatter()); $this->hasNewVersion = $this->upgrade->hasNewVersion(); } else { $this->hasNewVersion = false; } }
/** * Converts some fields to rich date fields */ protected function setupRichDateFields(sfForm $form) { $richDateForms = sfSympalConfig::get('form', 'rich_date_forms', array()); $formClass = get_class($form); $fields = isset($richDateForms[$formClass]) ? $richDateForms[$formClass] : array(); foreach ($fields as $name) { $widget = $form[$name]->getWidget(); if ($widget instanceof sfWidgetFormDateTime || $widget instanceof sfWidgetFormDate) { sfSympalFormToolkit::changeDateWidget($name, $form); } } }
/** * The main index, list action, which adds the following: * * Adds a is_published filter based on a "published" parameter * * Specifies the content type based off of a user attribute or request parameter */ public function executeIndex(sfWebRequest $request) { if ($request->hasParameter('published')) { $filters = $this->getFilters(); $filters['is_published'] = $request->getParameter('published'); $this->setFilters($filters); $this->redirect('@sympal_content'); } $type = $this->getUser()->getAttribute('content_type_id', sfSympalConfig::get('default_admin_list_content_type', null, 'sfSympalPage')); $this->contentType = $this->_getContentType($type, $request); $this->getResponse()->setTitle('Sympal Admin / ' . $this->contentType->getLabel()); parent::executeIndex($request); }
public function retrieveBlogMonth($month, $year) { $start = date('Y-m-d', strtotime($month . '/01/' . $year)); $end = date('Y-m-d', strtotime($start . ' +1 month')); $end = date('Y-m-d', strtotime($end . ' -1 day')); $dates = array($start, $end); Doctrine::getTable('sfSympalBlogPost'); $q = Doctrine::getTable('sfSympalContent')->createQuery('e')->innerJoin('e.sfSympalBlogPost p')->innerJoin('e.Type t2')->where('e.date_published > ? AND e.date_published < ?', $dates); $pager = new sfDoctrinePager('sfSympalContent', sfSympalConfig::get('rows_per_page')); $pager->setQuery($q); $pager->init(); return $pager; }
public function __construct($username = null, $password = null, $cacheDir = null) { if (!$username) { $username = sfSympalConfig::get('plugin_api', 'username'); } if (!$password) { $password = sfSympalConfig::get('plugin_api', 'password'); } if (!$cacheDir) { $cacheDir = sfConfig::get('sf_cache_dir') . '/sympal/plugins_api'; } parent::__construct($username, $password, $cacheDir); }