/** * Attach behavior. * Set owner and init behavior * * <code> * public function init(){ * $this->image = new \Ub\Helper\Image\Object() * $this->image->owner_field = 'image_data'; * $this->attachBehavior('image', $this->image); * } * </code> * @param string $name * @param Behavior $behavior * @return $this */ public function attachBehavior($name, Behavior $behavior) { $behavior->setOwner($this); $behavior->init(); $this->behaviors[$name] = $behavior; return $this; }
function deprecated_find_page_by_slug($slug, &$parent, $all = false) { global $__CMS_CONN__; $page_class = 'Page'; $parent_id = $parent ? $parent->id : 0; $sql = 'SELECT page.*, author.name AS author, updater.name AS updater ' . 'FROM ' . TABLE_PREFIX . 'page AS page ' . 'LEFT JOIN ' . TABLE_PREFIX . 'user AS author ON author.id = page.created_by_id ' . 'LEFT JOIN ' . TABLE_PREFIX . 'user AS updater ON updater.id = page.updated_by_id '; if ($all) { $sql .= 'WHERE slug = ? AND parent_id = ? AND (status_id=' . Page::STATUS_PREVIEW . ' OR status_id=' . Page::STATUS_PUBLISHED . ' OR status_id=' . Page::STATUS_HIDDEN . ')'; } else { $sql .= 'WHERE slug = ? AND parent_id = ? AND (status_id=' . Page::STATUS_PUBLISHED . ' OR status_id=' . Page::STATUS_HIDDEN . ')'; } $stmt = $__CMS_CONN__->prepare($sql); $stmt->execute(array($slug, $parent_id)); if ($page = $stmt->fetchObject()) { // hook to be able to redefine the page class with behavior if (!empty($parent->behavior_id)) { // will return Page by default (if not found!) $page_class = Behavior::loadPageHack($parent->behavior_id); } // create the object page $page = new $page_class($page, $parent); return $page; } else { return false; } }
public function __construct(&$page, $params) { /* Execute this behaviour only if page equals the current page. */ if (url_match($page->getUri())) { if ($child = $page->children(array('limit' => 1))) { header('Location: ' . $child->url()); die; } } else { // find called page foreach ($params as $slug) { $page = Page::findBySlug($slug, $page); } // if found if ($page instanceof Page) { // check for behavior if ($page->behavior_id != '') { // add a instance of the behavior with the name of the behavior $page->{$page->behavior_id} = Behavior::load($page->behavior_id, $page, $params); } } else { // not found page_not_found($_SERVER['REQUEST_URI']); } } }
/** * Инициализация */ protected function Init() { parent::Init(); if (!$this->getParam('validate_field')) { $this->aParams['validate_field'] = $this->getParam('form_field'); } }
public function getParameter($sName) { $sParam = parent::getParameter($sName); if ($sName === 'tag_instance_model' && $sParam === '') { $sParam = parent::getParameter('tag_model') . 'Instance'; } return $sParam; }
public function getParameter($sName) { $sParam = parent::getParameter($sName); if ($sName === 'mode' && $sParam === '') { $sParam = parent::getParameter('role_key') ? 'by_role' : 'allow'; } if ($sName === 'owner_allowed' && $sParam === '') { $sParam = $this->getParameter('mode') === 'by_role' ? 'by_role' : 'false'; } if ($sName === 'role_key' && $sParam === '') { $sParam = $this->getTable()->getCommonName(); } return $sParam; }
public function testBehaviorRun() { $config = ['behavior' => ['tags' => ['test' => ['before' => ['\\Codelint\\Laravel\\Behavior\\TestBehavior'], 'after' => ['\\Codelint\\Laravel\\Behavior\\ExceptionBehavior'], 'no_exception' => ['@\\Codelint\\Laravel\\Behavior\\ExceptionBehavior', '\\Codelint\\Laravel\\Behavior\\TestBehavior']]]]]; Behavior::setConfig($config); Behavior::tag('test.before', $config); $this->assertEquals([], $config['behavior']['tags']['test']['before']); try { Behavior::tag('test.after', $config); $this->assertFalse(true, 'there is except a exception occur, but not'); } catch (BehaviorException $e) { } $config['exception.before'] = false; Behavior::tag('test.no_exception', $config); $this->assertTrue($config['exception.before']); }
<?php /* * First Child - Frog CMS behaviour * * Copyright (c) 2009 Mika Tuupola * * Licensed under the MIT license: * http://www.opensource.org/licenses/mit-license.php * * Project home: * http://www.appelsiini.net/ */ Plugin::setInfos(array('id' => 'first_child', 'title' => 'First Child', 'description' => 'Redirects page to its first child.', 'version' => '0.1.2', 'license' => 'MIT', 'author' => 'Mika Tuupola', 'update_url' => 'http://www.appelsiini.net/download/frog-plugins.xml', 'website' => 'http://www.appelsiini.net/')); Behavior::add('Redirect_to_first_child', 'first_child/first_child.php');
public function __construct($name) { parent::__construct($name, 0, false, true); }
private static function findBySql($sql, $values = null) { $class_name = get_called_class(); Record::logQuery($sql); // Prepare and execute $stmt = Record::getConnection()->prepare($sql); if (!$stmt->execute($values)) { return false; } $page_class = 'Page'; $objects = array(); while ($page = $stmt->fetchObject('Page')) { $parent = $page->parent(); if (!empty($parent->behavior_id)) { // will return Page by default (if not found!) $page_class = Behavior::loadPageHack($parent->behavior_id); } // create the object page $page = new $page_class($page, $parent); $page->part = self::get_parts($page->id); $objects[] = $page; } return $objects; }
/** * Load the JavaScript behavior. * * @param string $group The pane identifier. * @param array $params Array of options. * @return void */ protected static function behavior($group, $params = array()) { static $loaded = array(); if (!array_key_exists((string) $group, $loaded)) { $options = array(); $opt['onActive'] = isset($params['onActive']) ? $params['onActive'] : null; $opt['onBackground'] = isset($params['onBackground']) ? $params['onBackground'] : null; $opt['display'] = isset($params['startOffset']) ? (int) $params['startOffset'] : null; $opt['useStorage'] = isset($params['useCookie']) && $params['useCookie'] ? 'true' : 'false'; $opt['titleSelector'] = "'dt.tabs'"; $opt['descriptionSelector'] = "'dd.tabs'"; foreach ($opt as $k => $v) { if ($v) { $options[] = $k . ': ' . $v; } } $options = '{' . implode(',', $options) . '}'; Behavior::framework(true); \App::get('document')->addScriptDeclaration('jQuery(document).ready(function($){ $("dl#' . $group . '.tabs").tabs(); });'); Asset::script('system/jquery.tabs.js', false, true); $loaded[(string) $group] = true; } }
/** * Implements __construct(). */ public function __construct() { return parent::__construct('background_motion'); }
protected function loadBehavior($behavior, $options = array()) { $behavior = Inflector::camelize($behavior); Behavior::load($behavior); return $this->{$behavior} = new $behavior($this, $options); }
/** * Implements __construct(). */ public function __construct() { return parent::__construct('background_parallax'); }
* ru_login_page() Use this on the page you want to have for logging in eg mysite.com/login * ru_confirm_page() This is the page a user clicks through to validate their account * ru_auth_required_page() Users who are not authorised to view the requested page will be redirected here * ru_reset_page() Will allow a user to have an email sent to them with a lnk to reset their password * ru_logout() A page to logout a user and return them to the hompage */ Plugin::setInfos(array('id' => 'registered_users', 'title' => 'Registered Users', 'description' => 'Allows you to manage new user registrations on your site.', 'version' => '1.0-dev', 'author' => 'Martijn van der Kleijn', 'require_wolf_version' => '0.7.7')); // Only when the plugin is enabled if (Plugin::isEnabled('registered_users')) { Plugin::addController('registered_users', 'Registered Users', 'admin_edit', true); Observer::observe('view_page_edit_plugins', 'registered_users_access_page_checkbox'); Observer::observe('page_add_after_save', 'registered_users_add_page_permissions'); Observer::observe('page_edit_after_save', 'registered_users_edit_page_permissions'); Observer::observe('page_delete', 'registered_users_delete_page_permissions'); Observer::observe('page_found', 'registered_users_page_found'); Behavior::add('login_page', ''); include 'classes/RegisteredUser.php'; include 'classes/RUCommon.php'; include 'observers/RUObservers.php'; // @todo Switch this stupid stuff to use routes function ru_login_page() { $registered_users_class = new RegisteredUser(); $loginpage = $registered_users_class->login_page(); echo $loginpage; } function ru_register_page() { $registered_users_class = new RegisteredUser(); $registerpage = $registered_users_class->registration_page(); echo $registerpage;
/** * Load the JavaScript behavior. * * @param string $group The pane identifier. * @param array $params Array of options. * @return void */ protected static function behavior($group, $params = array()) { static $loaded = array(); if (!array_key_exists($group, $loaded)) { $loaded[$group] = true; $display = isset($params['startOffset']) && isset($params['startTransition']) && $params['startTransition'] ? (int) $params['startOffset'] : null; $show = isset($params['startOffset']) && !(isset($params['startTransition']) && $params['startTransition']) ? (int) $params['startOffset'] : null; $opt = array(); $opt['heightStyle'] = "'content'"; /*$opt['onActive'] = "function(toggler, i) {toggler.addClass('pane-toggler-down');" . "toggler.removeClass('pane-toggler');i.addClass('pane-down');i.removeClass('pane-hide');Cookie.write('jpanesliders_" . $group . "',$('div#" . $group . ".pane-sliders > .panel > h3').indexOf(toggler));}"; $opt['onBackground'] = "function(toggler, i) {toggler.addClass('pane-toggler');" . "toggler.removeClass('pane-toggler-down');i.addClass('pane-hide');i.removeClass('pane-down');if($('div#" . $group . ".pane-sliders > .panel > h3').length==$('div#" . $group . ".pane-sliders > .panel > h3.pane-toggler').length) Cookie.write('jpanesliders_" . $group . "',-1);}"; $opt['duration'] = (isset($params['duration'])) ? (int) $params['duration'] : 300; $opt['display'] = (isset($params['useCookie']) && $params['useCookie']) ? JRequest::getInt('jpanesliders_' . $group, $display, 'cookie') : $display; $opt['show'] = (isset($params['useCookie']) && $params['useCookie']) ? JRequest::getInt('jpanesliders_' . $group, $show, 'cookie') : $show; $opt['opacity'] = (isset($params['opacityTransition']) && ($params['opacityTransition'])) ? 'true' : 'false'; $opt['alwaysHide'] = (isset($params['allowAllClose']) && (!$params['allowAllClose'])) ? 'false' : 'true';*/ $options = array(); foreach ($opt as $k => $v) { if ($v) { $options[] = $k . ': ' . $v; } } $options = '{' . implode(',', $options) . '}'; Behavior::framework(true); \App::get('document')->addScriptDeclaration("jQuery(document).ready(function(\$){\n\t\t\t\t\t\$('div#" . $group . "').accordion(" . $options . ");\n\t\t\t\t});"); } }
* Alternate Mirror site <http://www.tbeckett.net/articles/plugins/tagger.xhtml> * Copyright (C) 2008 - 2011 Andrew Smith <*****@*****.**> * Copyright (C) 2008 - 2011 Tyler Beckett <*****@*****.**> * * Dual licensed under the MIT (license/mit-license.txt) * and GPL (license/gpl-license.txt) licenses. */ // Root location where Tagger plugin lives. define('TAGGER_URL', URI_PUBLIC . 'wolf/plugins/tagger'); define('TAGGER_ROOT', dirname(__FILE__) . '/'); // Tagger Version define('TAGGER_VERSION', '1.4.4'); define('TAGGER_NAME', __('Tagger')); Plugin::setInfos(array('id' => 'tagger', 'title' => TAGGER_NAME, 'description' => __('Add tags to any page and organize your website.'), 'version' => TAGGER_VERSION, 'license' => 'MIT', 'author' => 'Andrew Smith ' . __('and') . ' Tyler Beckett', 'website' => 'http://www.tbeckett.net/articles/plugins/tagger.xhtml', 'update_url' => 'http://www.tbeckett.net/wpv.xhtml', 'require_wolf_version' => '0.7.3')); Plugin::addController('tagger', TAGGER_NAME); Behavior::add('tagger', 'tagger/tagger.php'); // Setting error display depending on debug mode or not error_reporting(DEBUG ? E_ALL | E_STRICT : 0); /** * Tagger Tag Cloud, Count and List new Object * * @since 1.4.0 */ class Tags { public function __construct($option = array()) { return self::render($option); } /** * Gets the url where pages are displayed based on tag selected
public static function findBySlugAndParentId($slug, $parent_id = 0, $class = __CLASS__) { /* TODO: Behaviour pagehack seems kludgish. */ $parent = Page::findById($parent_id); if ($parent && $parent->behaviorId()) { $class = Behavior::loadPageHack($parent->behaviorId()); } $params['where'] = sprintf("slug=%s AND parent_id=%d", self::connection()->quote($slug), $parent_id); $sql = Record::buildSql($params, $class); // print_r(self::connection()->query($sql, PDO::FETCH_CLASS, $class)->fetch()); return self::connection()->query($sql, PDO::FETCH_CLASS, $class)->fetch(); }
/* * Wolf CMS - Content Management Simplified. <http://www.wolfcms.org> * Copyright (C) 2009-2010 Martijn van der Kleijn <*****@*****.**> * Copyright (C) 2008 Philippe Archambault <*****@*****.**> * * This file is part of Wolf CMS. Wolf CMS is licensed under the GNU GPLv3 license. * Please see license.txt for the full license text. */ /* Security measure */ if (!defined('IN_CMS')) { exit; } /** * The Archive plugin provides an Archive pagetype behaving similar to a blog or news archive. * * @package Plugins * @subpackage archive * * @author Philippe Archambault <*****@*****.**> * @copyright Philippe Archambault, 2008 * @license http://www.gnu.org/licenses/gpl.html GPLv3 license */ Plugin::setInfos(array('id' => 'archive', 'title' => __('Archive'), 'description' => __('Provides an Archive pagetype behaving similar to a blog or news archive.'), 'version' => '1.1.0', 'website' => 'http://www.wolfcms.org/', 'update_url' => 'http://www.wolfcms.org/plugin-versions.xml')); // Add the plugin's tab and controller Plugin::addController('archive', '', 'admin_view', false); Behavior::add('archive', 'archive/archive.php'); Behavior::add('archive_day_index', 'archive/archive.php'); Behavior::add('archive_month_index', 'archive/archive.php'); Behavior::add('archive_year_index', 'archive/archive.php');
/** * Runs checks and stores a page. * * @param string $action What kind of action this is: add or edit. * @param mixed $id Page to edit if any. */ private function _store($action, $id = false) { // Sanity checks if ($action == 'edit' && !$id) { throw new Exception('Trying to edit page when $id is false.'); } use_helper('Validate'); $data = $_POST['page']; $data['is_protected'] = !empty($data['is_protected']) ? 1 : 0; Flash::set('post_data', (object) $data); $pagesetting = array(); //For homepage info & about page info okstmtcc if ($id == 1 || $id == 4) { $upload = $_POST['upload']; $pagesetting = $_POST['pagesetting']; //Flash::set('post_settingdata', (object) $pagesetting); } // Add pre-save checks here $errors = false; $error_fields = false; // CSRF checks if (isset($_POST['csrf_token'])) { $csrf_token = $_POST['csrf_token']; $csrf_id = ''; if ($action === 'edit') { $csrf_id = '/' . $id; } if (!SecureToken::validateToken($csrf_token, BASE_URL . 'page/' . $action . $csrf_id)) { $errors[] = __('Invalid CSRF token found!'); } } else { $errors[] = __('No CSRF token found!'); } $data['title'] = trim($data['title']); if (empty($data['title'])) { $error_fields[] = __('Page Title'); } /** homepage setting check okstmtcc **/ if ($id == 1) { /** homepage page title **/ if (empty($pagesetting['homepage_discover_title'])) { $error_fields[] = __('Homepage Title'); } if (empty($pagesetting['homepage_discover_teaser'])) { $error_fields[] = __('Homepage Teaser'); } /** highlight 1 **/ // if (empty($pagesetting['highlight_title'])){ // $error_fields[] = __('Highlight 1´s Title'); // } // if (empty($pagesetting['highlight_text1'])){ // $error_fields[] = __('Highlight 1´s Text 1'); // } // if (empty($pagesetting['highlight_url'])){ // $error_fields[] = __('Highlight 1´s Read More URL'); // } // $pagesetting_ori = PageSetting::init(); // if (isset($_FILES)) { // if(empty($_FILES['upload_highlight_image']['name'])){ // $pagesetting['highlight_image'] = $pagesetting_ori->highlight_image; // } else { // $pagesetting['highlight_image'] = $_FILES['upload_highlight_image']['name']; // } // } else { // $pagesetting['highlight_image'] = $pagesetting_ori->highlight_image; // } // if (empty($pagesetting['highlight_image'])){ // $error_fields[] = __('Highlight 1´s Image'); // } // /** highlight 2 **/ // if (empty($pagesetting['highlight2_title'])){ // $error_fields[] = __('Highlight 2´s Title'); // } // if (empty($pagesetting['highlight2_text1'])){ // $error_fields[] = __('Highlight 2´s Text 1'); // } // if (empty($pagesetting['highlight2_url'])){ // $error_fields[] = __('Highlight 2´s Read More URL'); // } // if (isset($_FILES)) { // if(empty($_FILES['upload_highlight2_image']['name'])){ // $pagesetting['highlight2_image'] = $pagesetting_ori->highlight2_image; // } else { // $pagesetting['highlight2_image'] = $_FILES['upload_highlight2_image']['name']; // } // } else { // $pagesetting['highlight2_image'] = $pagesetting_ori->highlight2_image; // } // if (empty($pagesetting['highlight2_image'])){ // $error_fields[] = __('Highlight 2´s Image'); // } // if (isset($_FILES)) { // if(empty($_FILES['upload_newdev_image']['name'])){ // $pagesetting['newdev_image'] = $pagesetting_ori->newdev_image; // } else { // $pagesetting['newdev_image'] = $_FILES['upload_newdev_image']['name']; // } // } else { // $pagesetting['newdev_image'] = $pagesetting_ori->newdev_image; // } // if (empty($pagesetting['newdev_image'])){ // $error_fields[] = __('New Development Image'); // } } /** homepage setting check okstmtcc **/ $data['slug'] = !empty($data['slug']) ? trim($data['slug']) : ''; if (empty($data['slug']) && $id != '1') { $error_fields[] = __('Slug'); } else { if ($data['slug'] == ADMIN_DIR) { $errors[] = __('You cannot have a slug named :slug!', array(':slug' => ADMIN_DIR)); } if (!Validate::slug($data['slug']) && (!empty($data['slug']) && $id == '1')) { $errors[] = __('Illegal value for :fieldname field!', array(':fieldname' => 'slug')); } } // Check all numerical fields for a page $fields = array('parent_id', 'layout_id', 'needs_login'); foreach ($fields as $field) { if (!Validate::digit($data[$field])) { $errors[] = __('Illegal value for :fieldname field!', array(':fieldname' => $field)); } } // Check all date fields for a page $fields = array('created_on', 'published_on', 'valid_until'); foreach ($fields as $field) { if (isset($data[$field])) { $data[$field] = trim($data[$field]); if (!empty($data[$field]) && !(bool) preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/D', (string) $data[$field])) { $errors[] = __('Illegal value for :fieldname field!', array(':fieldname' => $field)); } } } // Check all time fields for a page $fields = array('created_on_time', 'published_on_time', 'valid_until_time'); foreach ($fields as $field) { if (isset($data[$field])) { $data[$field] = trim($data[$field]); if (!empty($data[$field]) && !(bool) preg_match('/^[0-9]{2}:[0-9]{2}:[0-9]{2}$/D', (string) $data[$field])) { $errors[] = __('Illegal value for :fieldname field!', array(':fieldname' => $field)); } } } // Check alphanumerical fields $fields = array('keywords', 'description'); foreach ($fields as $field) { use_helper('Kses'); $data[$field] = kses(trim($data[$field]), array()); /* if (!empty($data[$field]) && !Validate::alpha_comma($data[$field])) { $errors[] = __('Illegal value for :fieldname field!', array(':fieldname' => $field)); } * */ } // Check behaviour_id field if (!empty($data['behaviour_id']) && !Validate::slug($data['behaviour_id'])) { $errors[] = __('Illegal value for :fieldname field!', array(':fieldname' => 'behaviour_id')); } // Make sure the title doesn't contain HTML if (Setting::get('allow_html_title') == 'off') { use_helper('Kses'); $data['title'] = kses(trim($data['title']), array()); } // Create the page object to be manipulated and populate data if ($action == 'add') { $page = new Page($data); } else { $page = Record::findByIdFrom('Page', $id); $page->setFromData($data); } // Upon errors, rebuild original page and return to screen with errors if (false !== $errors || $error_fields !== false) { $tags = $_POST['page_tag']; // Rebuild time fields if (isset($page->created_on) && isset($page->created_on_time)) { $page->created_on = $page->created_on . ' ' . $page->created_on_time; } if (isset($page->published_on) && isset($page->published_on_time)) { $page->published_on = $page->published_on . ' ' . $page->published_on_time; } if (isset($page->valid_until)) { $page->valid_until = $page->valid_until . ' ' . $page->valid_until_time; } // Rebuild parts $part = ''; if (!empty($_POST['part'])) { $part = $_POST['part']; $tmp = false; foreach ($part as $key => $val) { $tmp[$key] = (object) $val; } $part = $tmp; } // Set the errors to be displayed. $err_msg = $errors != false ? implode('<br/>', $errors) : ''; $err_msg .= $error_fields != false ? '<br />Please specify these fields: ' . implode(', ', $error_fields) : ''; Flash::setNow('error', $err_msg); //$settingdata = 'aaa'; // display things ... $this->setLayout('backend'); $pagesettingobj = new stdClass(); foreach ($pagesetting as $name => $value) { $pagesettingobj->{$name} = $value; } $this->display('page/edit', array('action' => $action, 'csrf_token' => SecureToken::generateToken(BASE_URL . 'page/' . $action), 'page' => (object) $page, 'pagesetting' => $pagesettingobj, 'tags' => $tags, 'filters' => Filter::findAll(), 'behaviors' => Behavior::findAll(), 'page_parts' => $part, 'layouts' => Record::findAllFrom('Layout'))); } // Notify if ($action == 'add') { Observer::notify('page_add_before_save', $page); } else { Observer::notify('page_edit_before_save', $page); } // Time to actually save the page // @todo rebuild this so parts are already set before save? // @todo determine lazy init impact $page->newwindow = !empty($data['newwindow']) ? '1' : '0'; if ($page->save()) { // Get data for parts of this page $data_parts = $_POST['part']; Flash::set('post_parts_data', (object) $data_parts); if ($action == 'edit') { $old_parts = PagePart::findByPageId($id); // check if all old page part are passed in POST // if not ... we need to delete it! foreach ($old_parts as $old_part) { $not_in = true; foreach ($data_parts as $part_id => $data) { $data['name'] = trim($data['name']); if ($old_part->name == $data['name']) { $not_in = false; // this will not really create a new page part because // the id of the part is passed in $data $part = new PagePart($data); $part->page_id = $id; Observer::notify('part_edit_before_save', $part); $part->save(); Observer::notify('part_edit_after_save', $part); unset($data_parts[$part_id]); break; } } if ($not_in) { $old_part->delete(); } } } // add the new parts foreach ($data_parts as $data) { $data['name'] = trim($data['name']); $part = new PagePart($data); $part->page_id = $page->id; Observer::notify('part_add_before_save', $part); $part->save(); Observer::notify('part_add_after_save', $part); } // save tags $page->saveTags($_POST['page_tag']['tags']); // save homepage banner info okstmtcc if ($id == 1) { // upload home banner image 1, 2 if (isset($_FILES) && !empty($_FILES['upload_banner_image1']['name'])) { //okstmtcc 20150827 Replace image filename spaces $_FILES['upload_banner_image1']['name'] = str_replace(array(" ", "(", ")"), array("_", "", ""), $_FILES['upload_banner_image1']['name']); $file = $this->upload_file($_FILES['upload_banner_image1']['name'], FILES_DIR . '/pagesetting/images/', $_FILES['upload_banner_image1']['tmp_name'], $overwrite); if ($file === false) { Flash::set('error', __('Home banner could not be uploaded!')); redirect(get_url('page/edit/1')); } else { $pagesetting['banner_image1'] = $file; } } if (isset($_FILES) && !empty($_FILES['upload_banner_image2']['name'])) { //okstmtcc 20150827 Replace image filename spaces $_FILES['upload_banner_image2']['name'] = str_replace(array(" ", "(", ")"), array("_", "", ""), $_FILES['upload_banner_image2']['name']); $file = $this->upload_file($_FILES['upload_banner_image2']['name'], FILES_DIR . '/pagesetting/images/', $_FILES['upload_banner_image2']['tmp_name'], $overwrite); if ($file === false) { Flash::set('error', __('Home banner could not be uploaded!')); redirect(get_url('page/edit/1')); } else { $pagesetting['banner_image2'] = $file; } } PageSetting::saveFromData($pagesetting); } // save homepage banner info okstmtcc // save about banner info okstmtcc if ($id == 4) { // upload about page image 1 if (isset($_FILES) && !empty($_FILES['upload_about_image1']['name'])) { //okstmtcc 20150827 Replace image filename spaces $_FILES['upload_about_image1']['name'] = str_replace(array(" ", "(", ")"), array("_", "", ""), $_FILES['upload_about_image1']['name']); $file = $this->upload_file($_FILES['upload_about_image1']['name'], FILES_DIR . '/pagesetting/images/', $_FILES['upload_about_image1']['tmp_name'], $overwrite); if ($file === false) { Flash::set('error', __('Home banner could not be uploaded!')); redirect(get_url('page/edit/1')); } else { $pagesetting['about_image1'] = $file; } } PageSetting::saveFromData($pagesetting); } // save about banner info okstmtcc Flash::set('success', __('Page has been saved.')); } else { Flash::set('error', __('Page has not been saved!')); $url = 'page/'; $url .= $action == 'edit' ? 'edit/' . $id : 'add/'; redirect(get_url($url)); } if ($action == 'add') { Observer::notify('page_add_after_save', $page); } else { Observer::notify('page_edit_after_save', $page); } // save and quit or save and continue editing ? if (isset($_POST['commit'])) { redirect(get_url('page')); } else { redirect(get_url('page/edit/' . $page->id)); } }
<?php defined('SYSPATH') or die('No direct access allowed.'); Observer::observe(array('page_add_after_save', 'page_edit_after_save'), function ($page) { if (!empty($page->behavior_id)) { $data = Request::current()->post('behavior'); ORM::factory('Page_Behavior_Setting')->find_by_page($page)->set_page($page)->set('data', $data)->save(); } else { $model = ORM::factory('Page_Behavior_Setting')->find_by_page($page); if ($model->loaded()) { $model->delete(); } } }); Observer::observe('modules::after_load', function () { Behavior::init(); }); Observer::observe(array('controller_before_page_edit', 'controller_before_page_add'), function () { Assets::js('controller.behavior', ADMIN_RESOURCES . 'js/controller/behavior.js', 'global'); });
/** * * @param string $field * @param string $value * @param Model_Page_Front $parent * @param boolean $include_hidden * @return boolean|\Model_Page_Front */ public static function findByField($field, $value, $parent = NULL, $include_hidden = TRUE) { $page_cache_id = self::_get_cache_id(array($field, $value), $parent); if (isset(self::$_pages_cache[$page_cache_id])) { return self::$_pages_cache[$page_cache_id]; } $page_class = get_called_class(); $page = DB::select('page.*')->from(array('pages', 'page'))->where('page.' . $field, '=', $value)->where('status_id', 'in', self::get_statuses($include_hidden))->limit(1); if (Config::get('page', 'check_date') == Config::YES) { $page->where('published_on', '<=', DB::expr('NOW()')); } $parent_id = $parent instanceof Model_Page_Front ? $parent->id : NULL; if ($parent_id !== NULL) { $page->where('parent_id', '=', $parent_id); } $page = $page->cache_tags(array('pages'))->cached((int) Config::get('cache', 'front_page'))->as_object()->execute()->current(); if (!$page) { return FALSE; } if ($page->parent_id and $parent === NULL) { $parent = self::findById($page->parent_id); } // hook to be able to redefine the page class with behavior if ($parent instanceof Model_Page_Front and !empty($parent->behavior_id)) { // will return Page by default (if not found!) $page_class = Behavior::load_page($parent->behavior_id); } // create the object page $page = new $page_class($page, $parent); self::$_pages_cache[$page_cache_id] = $page; return $page; }
/** * Runs checks and stores a page. * * @param string $action What kind of action this is: add or edit. * @param mixed $id Page to edit if any. */ private function _store($action, $id = false) { // Sanity checks if ($action == 'edit' && !$id) { throw new Exception('Trying to edit page when $id is false.'); } use_helper('Validate'); $data = $_POST['page']; $data['is_protected'] = !empty($data['is_protected']) ? 1 : 0; Flash::set('post_data', (object) $data); // Add pre-save checks here $errors = false; // CSRF checks if (isset($_POST['csrf_token'])) { $csrf_token = $_POST['csrf_token']; if (!SecureToken::validateToken($csrf_token, BASE_URL . 'page/' . $action)) { $errors[] = __('Invalid CSRF token found!'); } } else { $errors[] = __('No CSRF token found!'); } $data['title'] = trim($data['title']); if (empty($data['title'])) { $errors[] = __('You have to specify a title!'); } $data['slug'] = trim($data['slug']); if (empty($data['slug']) && $id != '1') { $errors[] = __('You have to specify a slug!'); } else { if ($data['slug'] == ADMIN_DIR) { $errors[] = __('You cannot have a slug named :slug!', array(':slug' => ADMIN_DIR)); } if (!Validate::slug($data['slug']) && (!empty($data['slug']) && $id == '1')) { $errors[] = __('Illegal value for :fieldname field!', array(':fieldname' => 'slug')); } } // Check all numerical fields for a page $fields = array('parent_id', 'layout_id', 'needs_login'); foreach ($fields as $field) { if (!Validate::digit($data[$field])) { $errors[] = __('Illegal value for :fieldname field!', array(':fieldname' => $field)); } } // Check all date fields for a page $fields = array('created_on', 'published_on', 'valid_until'); foreach ($fields as $field) { if (isset($data[$field])) { $data[$field] = trim($data[$field]); if (!empty($data[$field]) && !(bool) preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/D', (string) $data[$field])) { $errors[] = __('Illegal value for :fieldname field!', array(':fieldname' => $field)); } } } // Check all time fields for a page $fields = array('created_on_time', 'published_on_time', 'valid_until_time'); foreach ($fields as $field) { if (isset($data[$field])) { $data[$field] = trim($data[$field]); if (!empty($data[$field]) && !(bool) preg_match('/^[0-9]{2}:[0-9]{2}:[0-9]{2}$/D', (string) $data[$field])) { $errors[] = __('Illegal value for :fieldname field!', array(':fieldname' => $field)); } } } // Check alphanumerical fields $fields = array('keywords', 'description'); foreach ($fields as $field) { use_helper('Kses'); $data[$field] = kses(trim($data[$field]), array()); /* if (!empty($data[$field]) && !Validate::alpha_comma($data[$field])) { $errors[] = __('Illegal value for :fieldname field!', array(':fieldname' => $field)); } * */ } // Check behaviour_id field if (!empty($data['behaviour_id']) && !Validate::slug($data['behaviour_id'])) { $errors[] = __('Illegal value for :fieldname field!', array(':fieldname' => 'behaviour_id')); } // Make sure the title doesn't contain HTML if (Setting::get('allow_html_title') == 'off') { use_helper('Kses'); $data['title'] = kses(trim($data['title']), array()); } // Create the page object to be manipulated and populate data if ($action == 'add') { $page = new Page($data); } else { $page = Record::findByIdFrom('Page', $id); $page->setFromData($data); } // Upon errors, rebuild original page and return to screen with errors if (false !== $errors) { $tags = $_POST['page_tag']; // Rebuild time fields if (isset($page->created_on)) { $page->created_on = $page->created_on . ' ' . $page->created_on_time; } if (isset($page->published_on)) { $page->published_on = $page->published_on . ' ' . $page->published_on_time; } if (isset($page->valid_until)) { $page->valid_until = $page->valid_until . ' ' . $page->valid_until_time; } // Rebuild parts $part = $_POST['part']; if (!empty($part)) { $tmp = false; foreach ($part as $key => $val) { $tmp[$key] = (object) $val; } $part = $tmp; } // Set the errors to be displayed. Flash::setNow('error', implode('<br/>', $errors)); // display things ... $this->setLayout('backend'); $this->display('page/edit', array('action' => $action, 'csrf_token' => SecureToken::generateToken(BASE_URL . 'page/' . $action), 'page' => (object) $page, 'tags' => $tags, 'filters' => Filter::findAll(), 'behaviors' => Behavior::findAll(), 'page_parts' => (object) $part, 'layouts' => Record::findAllFrom('Layout'))); } // Notify if ($action == 'add') { Observer::notify('page_add_before_save', $page); } else { Observer::notify('page_edit_before_save', $page); } // Time to actually save the page // @todo rebuild this so parts are already set before save? // @todo determine lazy init impact if ($page->save()) { // Get data for parts of this page $data_parts = $_POST['part']; Flash::set('post_parts_data', (object) $data_parts); if ($action == 'edit') { $old_parts = PagePart::findByPageId($id); // check if all old page part are passed in POST // if not ... we need to delete it! foreach ($old_parts as $old_part) { $not_in = true; foreach ($data_parts as $part_id => $data) { $data['name'] = trim($data['name']); if ($old_part->name == $data['name']) { $not_in = false; // this will not really create a new page part because // the id of the part is passed in $data $part = new PagePart($data); $part->page_id = $id; Observer::notify('part_edit_before_save', $part); $part->save(); Observer::notify('part_edit_after_save', $part); unset($data_parts[$part_id]); break; } } if ($not_in) { $old_part->delete(); } } } // add the new parts foreach ($data_parts as $data) { $data['name'] = trim($data['name']); $part = new PagePart($data); $part->page_id = $page->id; Observer::notify('part_add_before_save', $part); $part->save(); Observer::notify('part_add_after_save', $part); } // save tags $page->saveTags($_POST['page_tag']['tags']); Flash::set('success', __('Page has been saved!')); } else { Flash::set('error', __('Page has not been saved!')); $url = 'page/'; $url .= $action == 'edit' ? 'edit/' . $id : 'add/'; redirect(get_url($url)); } if ($action == 'add') { Observer::notify('page_add_after_save', $page); } else { Observer::notify('page_edit_after_save', $page); } // save and quit or save and continue editing ? if (isset($_POST['commit'])) { redirect(get_url('page')); } else { redirect(get_url('page/edit/' . $page->id)); } }
private static function registerBehaviour() { Behavior::add('calendar', CALENDAR_ID . '/behaviour.php'); }
<?php /* * Email Template - Frog CMS behaviour * * Copyright (c) 2008-2009 Mika Tuupola * * Licensed under the MIT license: * http://www.opensource.org/licenses/mit-license.php * * Project home: * http://www.appelsiini.net/ */ Plugin::setInfos(array('id' => 'email_template', 'title' => 'Email template', 'description' => 'Provides mailer backend to your forms.', 'version' => '0.2.1', 'author' => 'Mika Tuupola', 'license' => 'MIT', 'update_url' => 'http://www.appelsiini.net/download/frog-plugins.xml', 'website' => 'http://www.appelsiini.net/')); Behavior::add('Email_template', 'email_template/email_template.php');
public static function findByUri($uri, $all = false) { // echo "findByUri: ".$uri; global $__CMS_CONN__; $uri = trim($uri, '/'); $has_behavior = false; // adding the home root $urls = array_merge(array(''), Dispatcher::splitUrl($uri)); $url = ''; $page = new stdClass(); $page->id = 0; $parent = false; foreach ($urls as $page_slug) { $url = ltrim($url . '/' . $page_slug, '/'); if ($page = Page::findBySlug($page_slug, $parent, $all)) { // check for behavior if ($page->behavior_id != '') { // add a instance of the behavior with the name of the behavior $params = Dispatcher::splitUrl(substr($uri, strlen($url))); $page->{$page->behavior_id} = Behavior::load($page->behavior_id, $page, $params); return $page; } } else { break; } $parent = $page; } // foreach //echo "<br/> return: ".(( ! $page && $has_behavior) ? $parent->id: $page->id)."<br/>"; return !$page && $has_behavior ? $parent : $page; }
public function testParameters() { $b = new Behavior(); $this->assertEquals($b->getParameters(), array(), 'Behavior parameters is an empty array by default'); $b->addParameter(array('name' => 'foo', 'value' => 'bar')); $this->assertEquals($b->getParameters(), array('foo' => 'bar'), 'addParameter() sets a parameter from an associative array'); $b->addParameter(array('name' => 'foo2', 'value' => 'bar2')); $this->assertEquals($b->getParameters(), array('foo' => 'bar', 'foo2' => 'bar2'), 'addParameter() adds a parameter from an associative array'); $b->addParameter(array('name' => 'foo', 'value' => 'bar3')); $this->assertEquals($b->getParameters(), array('foo' => 'bar3', 'foo2' => 'bar2'), 'addParameter() changes a parameter from an associative array'); $this->assertEquals($b->getParameter('foo'), 'bar3', 'getParameter() retrieves a parameter value by name'); $b->setParameters(array('foo3' => 'bar3', 'foo4' => 'bar4')); $this->assertEquals($b->getParameters(), array('foo3' => 'bar3', 'foo4' => 'bar4'), 'setParameters() changes the whole parameter array'); }
<?php $plugin_id = "page_versions"; $controller_name = 'PageVersionsController'; Plugin::setInfos(array('id' => $plugin_id, 'title' => 'Page Versions', 'description' => 'Stores all the previous versions of a page', 'version' => '0.1', 'author' => 'Jules Piccotti', 'website' => 'http://fresh.jules.it/page_versions')); Plugin::addController($plugin_id, __('Page Versions'), null, false); Plugin::addJavascript($plugin_id, "page_versions.js"); Behavior::add('version', 'page_versions/page_versions.php'); Behavior::add('current_version', 'page_versions/page_versions.php'); Observer::observe('page_add_after_save', $controller_name . '::callback_page_updated'); Observer::observe('page_edit_after_save', $controller_name . '::callback_page_updated'); Observer::observe('page_before_execute_find', $controller_name . '::callback_filter_out_versions'); //Observer::observe('pages_tree_item_found', $controller_name.'::callback_tree_item_found');
/** * Provides Page not found page types. * * @package Plugins * @subpackage page-not-found * * @author Philippe Archambault <*****@*****.**> * @copyright Philippe Archambault, 2008 * @license http://www.gnu.org/licenses/gpl.html GPLv3 license */ /* Security measure */ if (!defined('IN_CMS')) { exit; } Plugin::setInfos(array('id' => 'page_not_found', 'title' => __('Page not found'), 'description' => __('Provides Page not found page types.'), 'version' => '1.0.0', 'website' => 'http://www.wolfcms.org/', 'update_url' => 'http://www.wolfcms.org/plugin-versions.xml')); Behavior::add('page_not_found', ''); Observer::observe('page_not_found', 'behavior_page_not_found'); /** * Presents browser with a custom 404 page. */ function behavior_page_not_found($url) { $page = Page::findByBehaviour('page_not_found'); if (is_a($page, 'Page')) { header("HTTP/1.0 404 Not Found"); header("Status: 404 Not Found"); $page->_executeLayout(); exit; // need to exit otherwise true error page will be sent } }
public function edit($id = null) { if (is_null($id)) { redirect(get_url('page')); } $page = Page::findById($id); if (!$page) { Flash::set('error', __('Page not found!')); redirect(get_url('page')); } // check for protected page and editor user if (!AuthUser::hasPermission('administrator') && !AuthUser::hasPermission('developer') && $page->is_protected) { Flash::set('error', __('You do not have permission to access the requested page!')); redirect(get_url('page')); } // check if trying to save if (get_request_method() == 'POST') { return $this->_edit($id); } // find all page_part of this pages $page_parts = PagePart::findByPageId($id); if (empty($page_parts)) { $page_parts = array(new PagePart()); } $tag_array = array(); foreach ($page->tags() as $tag) { $tag_array[] = $tag->name(); } // display things ... $this->setLayout('backend'); $this->display('page/edit', array('action' => 'edit', 'page' => $page, 'tags' => $tag_array, 'filters' => Filter::findAll(), 'behaviors' => Behavior::findAll(), 'page_parts' => $page_parts, 'layouts' => Layout::find(array('order' => 'position')))); }