/** * Logs the current user out * * @return void */ public static function logout() { // trigger a hook Hook::run('auth', 'logout', 'call', null, Auth::getCurrentMember()); $app = \Slim\Slim::getInstance(); $app->deleteCookie('stat_auth_cookie'); }
/** @param className name of the class and the name of the file without the ".php" extension */ function load($className) { $excludePaths = array(); //go throught all possible paths until either finding the class or failing while (!class_exists($className, false)) { if ($path = $this->findClass($className, $excludePaths)) { require_once $path; } else { break; } } if (class_exists($className, false)) { //found the class, perhaps hooks Hook::run('classLoaded', $className); return array('found' => true); } return array('found' => false, 'searched' => $excludePaths); }
function init() { $this->request = Yii::app()->request; $AssetManager = Yii::app()->getAssetManager(); $AssetManager->setBasePath(base_path() . '/../public/_assets/'); $AssetManager->setBaseUrl(base_url() . '/_assets'); Yii::app()->theme = $this->theme; if (!$this->hash) { $this->hash = Yii::app()->params['hash']; } $this->securityManager = Yii::app()->securityManager; $this->securityManager->encryptionKey = $this->hash; //设置选中的菜单 Helper::set('activeMenu', $this->active); //多语言 if (true == Yii::app()->params['checkBrowsLanguage']) { $this->_check_language(); } //加载hook Hook::run('init[]'); }
?> _container"> <label id="<?php echo $input_id; ?> _label"><?php echo humanize($name); ?> <br> <?php echo $field_str; ?> </label> </div> <?php } //TODO Sort this out Hook::run('form', 'post', array($db_object)); ?> <input type="submit" value="<?php echo '<?php echo $action_name ?> <?php echo $action_subject ?>'; ?> " class=""/> </form> <?php } else { ?> No object <?php }
/** * Runs a hook for this add-on * * @param string $hook Hook to run * @param string $type Type of hook to run (cumulative|replace|call) * @param mixed $return Pass-through values * @param mixed $data Data to pass to hook method * @return mixed */ public function runHook($hook, $type=null, $return=null, $data=null) { return Hook::run($this->addon_name, $hook, $type, $return, $data); }
function afterSave() { parent::afterSave(); Hook::run('model.NodeField_afterSave', $this); }
/** * Raven form tag pair * * {{ raven:form }} {{ /raven:form }} * * @return string */ public function form() { /* |-------------------------------------------------------------------------- | Formset |-------------------------------------------------------------------------- | | Raven really needs a formset to make it useful and secure. We may even | write a form decorator in the future to generate forms from formsets. | */ $formset = $this->fetchParam('formset', false); $return = $this->fetchParam('return', URL::getCurrent()); $error_return = $this->fetchParam('error_return', URL::getCurrent()); $multipart = ($this->fetchParam('files', false)) ? "enctype='multipart/form-data'" : ''; $old_values = array(); // Fetch the content if in edit mode if ($edit = $this->fetchParam('edit')) { $old_values = Content::get($edit, false, false); // Throw exception if there's an invalid URL if (count($old_values) == 0) { throw new FatalException('Invalid URL for editing'); } $entry_hash = Helper::encrypt($edit); } // Merge old values $old_values = array_merge($this->flash->get('old_values', array()), $old_values); // Sanitize data before returning it for display // $old_values = array_map_deep($old_values, 'htmlspecialchars'); // Set old values to re-populate the form $data = array(); array_set($data, 'value', $old_values); array_set($data, 'old_values', $old_values); /* |-------------------------------------------------------------------------- | Form HTML |-------------------------------------------------------------------------- | | Raven writes a few hidden fields to the form to help processing data go | more smoothly. Form attributes are accepted as colon/piped options: | Example: attr="class:form|id:contact-form" | | Note: The content of the tag pair is inserted back into the template | */ $form_id = $this->fetchParam('id', true); $attributes_string = ''; if ($attr = $this->fetchParam('attr', false, null, false, false)) { $attributes_array = Helper::explodeOptions($attr, true); foreach ($attributes_array as $key => $value) { $attributes_string .= " {$key}='{$value}'"; } } $html = "<form method='post' {$multipart} {$attributes_string}>\n"; $html .= "<input type='hidden' name='hidden[raven]' value='{$form_id}' />\n"; $html .= "<input type='hidden' name='hidden[formset]' value='{$formset}' />\n"; $html .= "<input type='hidden' name='hidden[return]' value='{$return}' />\n"; $html .= "<input type='hidden' name='hidden[error_return]' value='{$error_return}' />\n"; if ($edit) { $html .= "<input type='hidden' name='hidden[edit]' value='{$entry_hash}' />\n"; } /* |-------------------------------------------------------------------------- | Hook: Form Begin |-------------------------------------------------------------------------- | | Occurs in the middle the form allowing additional fields to be added. | Has access to the current fieldset. Must return HTML. | */ $html .= Hook::run('raven', 'inside_form', 'cumulative', ''); /* |-------------------------------------------------------------------------- | Hook: Content Preparse |-------------------------------------------------------------------------- | | Allows the modification of the tag data inside the form. Also has access | to the current formset. | */ $html .= Hook::run('raven', 'content_preparse', 'replace', $this->content, $this->content); $html .= "</form>"; return Parse::template($html, $data, array('statamic_view', 'callback'), $this->context); }
public function post_update($id) { $object = self::getObject(get_class($this), $id); if (!$object instanceof DBObject) { Controller::whoops('Invalid Object Returned'); return $object; } if (!$object->checkOwnership('update')) { Backend::addError('Permission Denied'); return false; } if (!$object->array) { Backend::addError('The ' . $object->getMeta('name') . ' does not exist'); return false; } $result = true; //We need to check if the post data is valid in some way? $data = $object->fromRequest(); $data = Hook::run('table_update', 'pre', array($data, $object), array('toret' => $data)); if ($object->update($data) !== false) { $data = Hook::run('table_update', 'post', array($data, $object), array('toret' => $data)); $result = $object; Backend::addSuccess($object->getMeta('name') . ' Modified'); } else { if (Controller::$debug && !empty($object->error_msg)) { Backend::addError('Could not update ' . $object->getMeta('name') . ': ' . $object->error_msg); } else { Backend::addError('Could not update ' . $object->getMeta('name')); } $result = false; } Backend::add('values', $data); return $result; }
<?php ///////////////////////////////////////////////////////////////////////////////////////////////// // ROUTING HOOKS ///////////////////////////////////////////////////////////////////////////////////////////////// $app->map('/TRIGGER/:namespace/:hook', function ($namespace, $hook) use($app) { Hook::run($namespace, $hook); })->via('GET', 'POST', 'HEAD'); ///////////////////////////////////////////////////////////////////////////////////////////////// // Static Asset Pipeline ///////////////////////////////////////////////////////////////////////////////////////////////// $app->get('/assets/(:segments+)', function ($segments = array()) use($app) { $file_requested = implode($segments, '/'); $file = Theme::getPath() . $file_requested; # Routes only if the file doesn't already exist (e.g. /assets/whatever.ext) if (!File::exists($file_requested) && File::exists($file)) { $mime = File::resolveMime($file); header("Content-type: {$mime}"); readfile($file); exit; } }); ///////////////////////////////////////////////////////////////////////////////////////////////// // GLOBAL STATAMIC CONTENT ROUTING ///////////////////////////////////////////////////////////////////////////////////////////////// $app->map('/(:segments+)', function ($segments = array()) use($app) { $requesting_xml = false; $content_found = false; // segments foreach ($segments as $key => $seg) { $count = $key + 1;
/** * _render_layout * Renders the page * * @param string $_html HTML of the template to use * @param string $template_type Content type of the template * @return string */ public function _render_layout($_html, $template_type = 'html') { if (self::$_layout) { $this->data['layout_content'] = $_html; if ($template_type != 'html' or self::$_control_panel) { extract($this->data); ob_start(); require self::$_layout . ".php"; $html = ob_get_clean(); } else { if (!File::exists(self::$_layout . ".html")) { Log::fatal("Can't find the specified theme.", 'core', 'template'); return '<p style="text-align:center; font-size:28px; font-style:italic; padding-top:50px;">We can\'t find your theme files. Please check your settings.'; } $this->appendNewData($this->data); // Fetch layout and parse any front matter $layout = Parse::frontMatter(File::get(self::$_layout . '.html'), false); $html = Parse::template($layout['content'], Statamic_View::$_dataStore, array($this, 'callback')); $html = Lex\Parser::injectNoparse($html); } } else { $html = $_html; } // post-render hook $html = \Hook::run('_render', 'after', 'replace', $html, $html); return $html; }
public function post_confirm($salt) { $user = self::checkSalt($salt); $data = array('confirmed' => true); $data = Hook::run('user_confirm', 'pre', array($user, $data), array('toret' => $data)); if (!$data) { return false; } if ($user->update($data) === false) { return false; } Hook::run('user_confirm', 'post', array($user), array('toret' => true)); return true; }
static function endJson($content, $encode = true) { Hook::run('preHTTPMessageBody'); header('Content-type: application/json'); if ($encode) { echo json_encode($content); } else { echo $content; } exit; }
/** * Actually output the information */ function output($to_print = null) { if (Controller::$mode == Controller::MODE_REQUEST) { if (!headers_sent() && !Controller::$debug) { $content_type = $this->mime_type; if ($this->charset) { $content_type .= '; charset=' . $this->charset; } header('Content-Type: ' . $content_type); } } //Run the View first, so that the other hooks have the output to work on if (method_exists($this, 'hook_output')) { $to_print = $this->hook_output($to_print); } $to_print = Hook::run('output', 'pre', array($to_print), array('toret' => $to_print)); echo $to_print; //Run the View first, so that the other hooks have the output to work on if (method_exists($this, 'hook_post_output')) { $to_print = $this->hook_post_output($to_print); } $to_print = Hook::run('output', 'post', array($to_print), array('toret' => $to_print)); }
/** * _render_layout * Renders the page * * @param string $_html HTML of the template to use * @param string $template_type Content type of the template * @return string */ public function _render_layout($_html, $template_type = 'html') { if (self::$_layout != '') { $this->data['layout_content'] = $_html; $layout_path = Path::assemble(BASE_PATH, Config::getTemplatesPath(), self::$_layout); if ($template_type != 'html' or self::$_control_panel) { extract($this->data); ob_start(); require $layout_path . ".php"; $html = ob_get_clean(); } else { if (!File::exists($layout_path . ".html")) { Log::fatal("Can't find the specified theme.", 'core', 'template'); return '<p style="text-align:center; font-size:28px; font-style:italic; padding-top:50px;">We can\'t find your theme files. Please check your settings.'; } $this->mergeNewData($this->data); $html = Parse::template(File::get($layout_path . ".html"), Statamic_View::$_dataStore, array($this, 'callback')); $html = Lex\Parser::injectNoparse($html); } } else { $html = $_html; } // post-render hook $html = \Hook::run('_render', 'after', 'replace', $html, $html); return $html; }
$admin_app->get('/images', function () use($admin_app) { authenticateForRole('admin'); doStatamicVersionCheck($admin_app); $path = $admin_app->request()->get('path'); $image_list = glob($path . "*.{jpg,jpeg,gif,png}", GLOB_BRACE); $images = array(); if (count($image_list) > 0) { foreach ($image_list as $image) { $images[] = array('thumb' => '/' . $image, 'image' => '/' . $image); } } echo json_encode($images); })->name('images'); /* |-------------------------------------------------------------------------- | Hook: Add Routes |-------------------------------------------------------------------------- | | Allows add-ons to add their own hooks to the control panel. | */ Hook::run('control_panel', 'add_routes'); // GET: 404 // -------------------------------------------------------- $admin_app->notFound(function () use($admin_app) { authenticateForRole('admin'); doStatamicVersionCheck($admin_app); $admin_app->flash('error', Localization::fetch('admin_404')); $redirect_to = Config::get('_admin_404_page', $admin_app->urlFor('pages')); $admin_app->redirect($redirect_to); });
/** * Process a form submission * * @return void */ private function process() { /* |-------------------------------------------------------------------------- | Prep form and handler variables |-------------------------------------------------------------------------- | | We're going to assume success = true here to simplify code readability. | Checks already exist for require and validation so we simply flip the | switch there. | */ $success = true; $errors = array(); /* |-------------------------------------------------------------------------- | Hidden fields and $_POST hand off |-------------------------------------------------------------------------- | | We slide the hidden key out of the POST data and assign the rest to a | cleaner $submission variable. | */ $hidden = $_POST['hidden']; unset($_POST['hidden']); $submission = $_POST; /* |-------------------------------------------------------------------------- | Grab formset and collapse settings |-------------------------------------------------------------------------- | | Formset settings are merged on top of the default raven.yaml config file | to allow per-form overrides. | */ $formset_name = array_get($hidden, 'formset'); $formset = $formset_name . '.yaml'; if (File::exists('_config/add-ons/raven/formsets/' . $formset)) { $formset = Yaml::parse('_config/add-ons/raven/formsets/' . $formset); } elseif (File::exists('_config/formsets/' . $formset)) { $formset = Yaml::parse('_config/formsets/' . $formset); } else { $formset = array(); } if (!is_array($this->config)) { $this->log->warn('Could not find the config file.'); $this->config = array(); } $config = array_merge($this->config, $formset, array('formset' => $hidden['formset'])); /* |-------------------------------------------------------------------------- | Prep filters |-------------------------------------------------------------------------- | | We jump through some PHP hoops here to filter, sanitize and validate | our form inputs. | */ $allowed_fields = array_flip(array_get($formset, 'allowed', array())); $required_fields = array_flip(array_get($formset, 'required', array())); $validation_rules = isset($formset['validate']) ? $formset['validate'] : array(); $messages = isset($formset['messages']) ? $formset['messages'] : array(); $referrer = Request::getReferrer(); $return = array_get($hidden, 'return', $referrer); $error_return = array_get($hidden, 'error_return', $referrer); /* |-------------------------------------------------------------------------- | Allowed fields |-------------------------------------------------------------------------- | | It's best to only allow a set of predetermined fields to cut down on | spam and misuse. | */ if (count($allowed_fields) > 0) { $submission = array_intersect_key($submission, $allowed_fields); } /* |-------------------------------------------------------------------------- | Required fields |-------------------------------------------------------------------------- | | Requiring fields isn't required (ironic-five!), but if any are specified | and missing from the POST, we'll be squashing this submission right here | and sending back an array of missing fields. | */ if (count($required_fields) > 0) { $missing = array_flip(array_diff_key($required_fields, array_filter($submission))); if (count($missing) > 0) { foreach ($missing as $key => $field) { $errors['missing'][] = array('field' => $field); } $success = false; } } /* |-------------------------------------------------------------------------- | Validation |-------------------------------------------------------------------------- | | Run optional per-field validation. Any data failing the specified | validation rule will squash the submission and send back error messages | as specified in the formset. | */ $invalid = $this->validate($submission, $validation_rules); // Prepare a data array of fields and error messages use for template display if (count($invalid) > 0) { $errors['invalid'] = array(); foreach ($invalid as $field) { $errors['invalid'][] = array('field' => $field, 'message' => isset($messages[$field]) ? $messages[$field] : null); } $success = false; } /* |-------------------------------------------------------------------------- | Upload Files |-------------------------------------------------------------------------- | | Upload any files to their specified destination. | */ if (count($_FILES) > 0) { $files = array_intersect_key($_FILES, $allowed_fields); $upload_destination = array_get($config, 'upload_destination'); foreach ($files as $name => $file) { $submission[$name] = File::upload($file, $upload_destination); } } /* |-------------------------------------------------------------------------- | Hook: Pre Process |-------------------------------------------------------------------------- | | Allow pre-processing by other add-ons with the ability to kill the | success of the submission. Has access to the submission and config. | */ $success = Hook::run('raven', 'pre_process', 'replace', $success, compact('submission', 'config', 'success')); /* |-------------------------------------------------------------------------- | Form Identifier |-------------------------------------------------------------------------- | | In the event of multiple forms on a page, we'll be able to determine | which one was the one that had been triggered. | */ $this->flash->set('form_id', $hidden['raven']); /* |-------------------------------------------------------------------------- | Finalize & determine action |-------------------------------------------------------------------------- | | Send back the errors if validation or require fields are missing. | If successful, save to file (if enabled) and send notification | emails (if enabled). | */ if ($success) { // Akismet? $is_spam = false; if ($akismet = array_get($config, 'akismet') && array_get($config, 'akismet_api_key')) { $is_spam = $this->tasks->akismetCheck(array('permalink' => URL::makeFull(URL::getCurrent()), 'comment_type' => $formset_name, 'comment_author' => array_get($submission, array_get($akismet, 'author')), 'comment_author_email' => array_get($submission, array_get($akismet, 'email')), 'comment_author_url' => array_get($submission, array_get($akismet, 'url')), 'comment_content' => array_get($submission, array_get($akismet, 'content')))); } // Shall we save? if (array_get($config, 'submission_save_to_file', false) === true) { $file_prefix = Parse::template(array_get($config, 'file_prefix', ''), $submission); $file_suffix = Parse::template(array_get($config, 'file_suffix', ''), $submission); $file_prefix = $is_spam ? '_' . $file_prefix : $file_prefix; $this->save($submission, $config, $config['submission_save_path'], $is_spam); } // Shall we send? if (!$is_spam && array_get($config, 'send_notification_email', false) === true) { $this->send($submission, $config); } /* |-------------------------------------------------------------------------- | Hook: On Success |-------------------------------------------------------------------------- | | Allow events after the form as been processed. Has access to the | submission and config. | */ Hook::run('raven', 'on_success', null, null, array('submission' => $submission, 'config' => $config)); $this->flash->set('success', true); URL::redirect(URL::format($return)); } else { $this->flash->set('success', false); $this->flash->set('errors', $errors); $this->flash->set('old_values', $_POST); URL::redirect(URL::format($error_return)); } }
function runHook($hook_name, $params = NULL) { return Hook::run($hook_name, $params); }
$response = $app->response(); $response['Content-Type'] = 'application/xml'; } } /* |-------------------------------------------------------------------------- | Hook: Render Before |-------------------------------------------------------------------------- | | Allows actions to occur before the template is rendered and parsed. | For example, pre-process a POST or set global variables dynamically. | */ Hook::run('_render', 'before'); /* |-------------------------------------------------------------------------- | HTTP Caching |-------------------------------------------------------------------------- | | We'll always set the last modified header, but leave the | cache_expires option to people's discretion and configuration. | */ if (array_get($data, '_http_cache_expires', Config::get('http_cache_expires', false))) { $app->lastModified(Cache::getLastCacheUpdate()); $app->expires('+'.Config::get('http_cache_expires', '30 minutes')); }
public function get_display($id) { if (Backend::getDB('default')) { $id = Hook::run('table_display', 'pre', array($id), array('toret' => $id)); $result = Content::retrieve($id, 'dbobject'); if ($result instanceof DBObject && !empty($result->object)) { if (!$this->checkPermissions(array('subject_id' => $result->object->id, 'subject' => 'content'))) { Controller::whoops(array('title' => 'Permission Denied', 'message' => 'You do not have permission to display ' . $result->object->title)); $result = false; } } else { if ($result instanceof DBObject && $id == 'last') { $result->read(array('limit' => 1, 'conditions' => array('`active` = 1'), 'order' => '`added` DESC', 'mode' => 'object')); if (!$result->object) { $result = false; } } else { if (Permission::check('create', 'content')) { Backend::addNotice('The content does not exist, but you can create it now'); Controller::redirect('?q=content/create/' . $id); $result = false; } else { Controller::whoops(array('title' => 'Unknown Content', 'message' => 'The page you requested could not be found.')); $result = false; } } } if ($result && Controller::$debug) { Backend::addNotice('Content ID: ' . $result->object->id); } $object = Hook::run('table_display', 'post', array($result), array('toret' => $result)); return $result; } else { //DB less content $template_file = array($id . '.tpl.php', str_replace('/', '.', $id) . '.tpl.php'); if (Render::checkTemplateFile($template_file[0])) { Backend::addContent(Render::file($template_file[0])); } else { if (Render::checkTemplateFile($template_file[1])) { Backend::addContent(Render::file($template_file[1])); } else { Backend::addContent('Could not find file'); } } return true; } }
<span class="ss-icon">check</span> <?php echo Localization::fetch('save_publish'); ?> </a> </li> </ul> </div> <div class="section content"> <?php print Hook::run('control_panel', 'add_to_publish_form_header', 'cumulative'); ?> <?php print Hook::run('control_panel', 'add_to_publish_form', 'cumulative'); ?> <input type="hidden" name="page[full_slug]" value="<?php print $full_slug; ?> "> <input type="hidden" name="page[type]" value="<?php print $type; ?> " /> <input type="hidden" name="page[folder]" value="<?php print $folder; ?> " /> <input type="hidden" name="page[original_slug]" value="<?php
/** * Execute a hook point on all registered hooks * * @param string $point Method of registered hooks to execute * @param mixed $args Parameter(s) to pass to the hook */ public static function hook($point, &$args = NULL) { foreach (self::$_hooks as $hook => $points) { Hook::run($hook, $point, &$args); } }
?> <link rel="stylesheet" href="//fonts.googleapis.com/css?family=Raleway:400,700|Open+Sans:400italic,400,600" /> <?php } ?> <link rel="stylesheet" href="<?php echo Path::tidy(Config::getSiteRoot() . '/' . $app->config['theme_path']); ?> css/ascent.min.css"> <link rel="icon" href="<?php echo Path::tidy(Config::getSiteRoot() . '/' . $app->config['theme_path']); ?> img/favicon.png" sizes="16x16" type="img/png" /> <script type="text/javascript" src="<?php echo Path::tidy(Config::getSiteRoot() . '/' . $app->config['theme_path']); ?> js/ascent.min.js"></script> <?php echo Hook::run('control_panel', 'add_to_head', 'cumulative'); ?> </head> <body id="login"> <?php echo $_html; ?> <?php echo Hook::run('control_panel', 'add_to_foot', 'cumulative'); ?> </body> </html>
/** * This function get's called via register_shutdown_function when the script finishes or exit is called */ public static function finish() { if (self::$init) { Hook::run('finish', 'pre'); $_SESSION['error'] = Backend::getError(); $_SESSION['notice'] = Backend::getNotice(); $_SESSION['success'] = Backend::getSuccess(); if (!empty(self::$view)) { if (empty($_SESSION['previous_url']) || !is_array($_SESSION['previous_url'])) { $_SESSION['previous_url'] = array(); } if (array_key_exists('REQUEST_URI', $_SERVER)) { $_SESSION['previous_url'][self::$view->mode] = $_SERVER['REQUEST_URI']; } if (empty($_SESSION['previous_area']) || !is_array($_SESSION['previous_area'])) { $_SESSION['previous_area'] = array(); } $_SESSION['previous_area'][self::$view->mode] = self::$area; if (empty($_SESSION['previous_action']) || !is_array($_SESSION['previous_action'])) { $_SESSION['previous_action'] = array(); } $_SESSION['previous_action'][self::$view->mode] = self::$action; if (empty($_SESSION['previous_parameters']) || !is_array($_SESSION['previous_parameters'])) { $_SESSION['previous_parameters'] = array(); } $_SESSION['previous_parameters'][self::$view->mode] = self::$parameters; } //Check if we encountered a fatal error if ($last_error = error_get_last()) { if ($last_error['type'] === E_ERROR && SITE_STATE == 'production') { $id = send_email(ConfigValue::get('author.Email', ConfigValue::get('Email', 'info@' . SITE_DOMAIN)), 'Fatal PHP Error in ' . ConfigValue::get('Title', 'Application'), 'Error: ' . var_export($last_error, true) . PHP_EOL . 'Query: ' . self::$query_string . PHP_EOL . 'Payload: ' . var_export(self::$payload, true)); } } //Clean up self::$query_string = false; self::$query_vars = array(); self::$method = null; self::$payload = false; self::$area = 'home'; self::$action = 'index'; self::$parameters = array(); self::$salt = false; self::$view = false; self::$started = false; self::$init = false; self::$firephp = false; self::$whoopsed = false; Backend::shutdown(); Hook::run('finish', 'post'); while (ob_get_level() > self::$ob_level) { ob_end_flush(); } } self::$init = false; }