/** * Don't let the customer on the login page if they are already authenticated * @Developer brandon * @Date Oct 12, 2010 */ public function new_one() { if (customer::logged_in()) { url::redirect(url::site()); } parent::new_one(); }
public function _update($user) { if ($user->guest || $user->id != user::active()->id) { access::forbidden(); } $form = user::get_edit_form($user); $valid = $form->validate(); if ($valid) { $user->full_name = $form->edit_user->full_name->value; if ($form->edit_user->password->value) { $user->password = $form->edit_user->password->value; } $user->email = $form->edit_user->email->value; $user->url = $form->edit_user->url->value; if ($form->edit_user->locale) { $desired_locale = $form->edit_user->locale->value; $user->locale = $desired_locale == "none" ? null : $desired_locale; } $user->save(); message::success(t("User information updated.")); print json_encode(array("result" => "success", "resource" => url::site("users/{$user->id}"))); } else { print json_encode(array("result" => "error", "form" => $form->__toString())); } }
public function action_accessDenied() { $image = url::site('static/img/accessDenied.gif'); $this->session = Session::instance(); $email = $this->session->get('account_email'); if ($email) { $email = " <b>({$email})</b>"; } else { $email = ""; } $this->request->response = <<<HEREDOC <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>Access Denied</title> </head> <body> <div style="text-align: center"> <h1>Access Denied</h1> <img src="{$image}" alt="accessDenied" /> <p>Your login is not permitted in this section.</p> <p>Let the admin know what your email{$email} address is.</p> </div> </body> </html> HEREDOC; }
/** * Create HTML link anchors. * * @param string URL or URI string * @param string link text * @param array HTML anchor attributes * @param string non-default protocol, eg: https * @return string */ public static function anchor($uri, $title = NULL, $attributes = NULL, $protocol = NULL) { if ($uri === '') { $site_url = url::base(FALSE); } elseif (strpos($uri, '://') === FALSE AND strpos($uri, '#') !== 0) { $site_url = url::site($uri, $protocol); } else { if (html::$windowed_urls === TRUE AND empty($attributes['target'])) { $attributes['target'] = '_blank'; } $site_url = $uri; } return // Parsed URL '<a href="'.html::specialchars($site_url, FALSE).'"' // Attributes empty? Use an empty string .(is_array($attributes) ? html::attributes($attributes) : '').'>' // Title empty? Use the parsed URL .(($title === NULL) ? $site_url : $title).'</a>'; }
static function admin_menu($menu, $theme) { $menu->get("content_menu") ->append(Menu::factory("link") ->id("comments") ->label(t("Comments")) ->url(url::site("admin/comments"))); }
static function admin($menu, $theme) { $menu->get("settings_menu")->append(Menu::factory("link")->id("akismet")->label(t("Akismet"))->url(url::site("admin/akismet"))); if (module::get_var("akismet", "api_key")) { $menu->get("statistics_menu")->append(Menu::factory("link")->id("akismet")->label(t("Akismet"))->url(url::site("admin/akismet/stats"))); } }
static function thumb_top($theme, $child) { if (access::can("edit", $child)) { $edit_link = url::site("quick/pane/{$child->id}?page_type=album"); return "<div class=\"gQuick\" href=\"{$edit_link}\">"; } }
public static function page_data($e) { $pid = $e->pid; $cid = $e->container; $dd = $e->as_array(); $data = array(); $fields = array('copy', 'title', 'date_added', 'date_modified', 'meta_keywords', 'meta_description'); foreach ($fields as $field) { if (isset($dd[$field])) { $data[$field] = $dd[$field]; } } $data['url'] = url::site('page/' . $dd['name'] . '.html'); $data['plugins'] = array(); $plugins = Container::instance($cid)->get_blocks_flat($pid); foreach ($plugins as $k => $v) { $d = $v->data(); if (empty($d)) { continue; } $data['plugins'][$v->get_name()] = $d; } // var_dump( $data ); exit; return $data; }
/** * Méthode : renvois vers la home page avec un message d'erreur */ protected function redirection($txt = false, $javascript = FALSE) { if ($javascript) { echo '<script>redirect( \'' . url::site() . '?msg=' . urlencode($txt) . '\' );</script>'; } return url::redirect('?msg=' . urlencode($txt)); }
static function get($block_id, $theme) { $block = ""; switch ($block_id) { case "pages_xtra_block": // Create a new block with a list of all Pages and their links. // Query the database for all existing pages. // If at least one page exists, display the sidebar block. $query = ORM::factory("px_static_page"); $pages = $query->order_by("title", "ASC")->find_all(); if (count($pages) > 0) { // Loop through each page and generate an HTML list of their links and titles. $content = "<ul id=\"g-pages-list\">"; foreach ($pages as $one_page) { $content .= "<li style=\"clear: both;\"><a href=\"" . url::site("pages_xtra/show/" . $one_page->name) . "\">" . t($one_page->title) . "</a></li>"; } $content .= "</ul>"; // Make a new sidebar block. $block = new Block(); $block->css_id = "g-pages"; $block->title = t("Pages"); $block->content = new View("pages_xtra_sidebar.html"); $block->content->links = $content; } break; } return $block; }
public function _update($user) { if ($user->guest || $user->id != user::active()->id) { access::forbidden(); } $form = user::get_edit_form($user); $valid = $form->validate(); if ($valid) { $user->full_name = $form->edit_user->full_name->value; if ($form->edit_user->password->value) { $user->password = $form->edit_user->password->value; } $user->email = $form->edit_user->email->value; $user->url = $form->edit_user->url->value; if ($form->edit_user->locale) { $desired_locale = $form->edit_user->locale->value; $new_locale = $desired_locale == "none" ? null : $desired_locale; if ($new_locale != $user->locale) { // Delete the session based locale preference setcookie("g_locale", "", time() - 24 * 3600, "/"); } $user->locale = $new_locale; } $user->save(); module::event("user_edit_form_completed", $user, $form); message::success(t("User information updated.")); print json_encode(array("result" => "success", "resource" => url::site("users/{$user->id}"))); } else { print json_encode(array("result" => "error", "form" => $form->__toString())); } }
/** * adds the shopping basket administration controls to the admin menu */ static function admin_menu($menu, $theme) { $menu->add_after("users_groups", $basket_menu = Menu::factory("submenu")->id("basket_menu")->label(t("Basket"))); $basket_menu->append(Menu::factory("link")->id("configure")->label(t("Configure"))->url(url::site("admin/configure"))); $basket_menu->append(Menu::factory("link")->id("product_line")->label(t("Product Lines"))->url(url::site("admin/product_lines"))); $basket_menu->append(Menu::factory("link")->id("postage_bands")->label(t("Postage Bands"))->url(url::site("admin/postage_bands"))); }
/** * Creates a feed from the given parameters. * * @param array feed information * @param array items to add to the feed * @return string */ public static function create($info, $items, $format = 'rss2') { $info += array('title' => 'Generated Feed', 'link' => '', 'generator' => 'KohanaPHP'); $feed = '<?xml version="1.0"?><rss version="2.0"><channel></channel></rss>'; $feed = simplexml_load_string($feed); foreach ($info as $name => $value) { if (($name === 'pubDate' or $name === 'lastBuildDate') and (is_int($value) or ctype_digit($value))) { // Convert timestamps to RFC 822 formatted dates $value = date(DATE_RFC822, $value); } elseif (($name === 'link' or $name === 'docs') and strpos($value, '://') === FALSE) { // Convert URIs to URLs $value = url::site($value, 'http'); } // Add the info to the channel $feed->channel->addChild($name, $value); } foreach ($items as $item) { // Add the item to the channel $row = $feed->channel->addChild('item'); foreach ($item as $name => $value) { if ($name === 'pubDate' and (is_int($value) or ctype_digit($value))) { // Convert timestamps to RFC 822 formatted dates $value = date(DATE_RFC822, $value); } elseif (($name === 'link' or $name === 'guid') and strpos($value, '://') === FALSE) { // Convert URIs to URLs $value = url::site($value, 'http'); } // Add the info to the row $row->addChild($name, $value); } } return $feed->asXML(); }
public function _update($user) { if ($user->guest || $user->id != user::active()->id) { access::forbidden(); } $form = user::get_edit_form($user); $form->edit_user->password->rules("-required"); if ($form->validate()) { if ($form->edit_user->password->value && $form->edit_user->password->value != $form->edit_user->password2->value) { $form->edit_user->password2->add_error("mistyped", 1); print json_encode(array("result" => "error", "form" => $form->__toString())); } else { // @todo: allow the user to change their name $user->full_name = $form->edit_user->full_name->value; if ($form->edit_user->password->value) { $user->password = $form->edit_user->password->value; } $user->email = $form->edit_user->email->value; $user->url = $form->edit_user->url->value; $user->save(); print json_encode(array("result" => "success", "resource" => url::site("users/{$user->id}"))); } } else { print json_encode(array("result" => "error", "form" => $form->__toString())); } }
/** * This adds the buttons for the case of a tag. If you want to disable * either the A4 or LTR part, do so here *and* above for albums. */ static function tag_menu($menu, $theme) { $proofsheetA4Link = url::site("proofsheet/makepdf/a4/tag/{$theme->tag()->id}"); $menu->append(Menu::factory("link")->id("proofsheetA4")->label(t("A4 Proof Sheet"))->url($proofsheetA4Link)->css_id("g-proofsheet-a4-link")); $proofsheetLTRLink = url::site("proofsheet/makepdf/ltr/tag/{$theme->tag()->id}"); $menu->append(Menu::factory("link")->id("proofsheetLTR")->label(t("LTR Proof Sheet"))->url($proofsheetLTRLink)->css_id("g-proofsheet-ltr-link")); }
static function user_menu($menu, $theme) { $user = identity::active_user(); if ($user->guest) { $menu->append(Menu::factory("dialog")->id("user_menu_register")->css_id("g-register-menu")->url(url::site("register"))->label(t("Register"))); } }
/** * @see REST_Controller::_update($resource) */ public function _update($photo) { access::verify_csrf(); access::required("view", $photo); access::required("edit", $photo); $form = photo::get_edit_form($photo); if ($valid = $form->validate()) { if ($form->edit_photo->filename->value != $photo->name) { // Make sure that there's not a conflict if (Database::instance()->from("items")->where("parent_id", $photo->parent_id)->where("id <>", $photo->id)->where("name", $form->edit_photo->filename->value)->count_records()) { $form->edit_photo->filename->add_error("conflict", 1); $valid = false; } } } if ($valid) { $photo->title = $form->edit_photo->title->value; $photo->description = $form->edit_photo->description->value; $photo->rename($form->edit_photo->filename->value); $photo->save(); module::event("photo_edit_form_completed", $photo, $form); log::success("content", "Updated photo", "<a href=\"photos/{$photo->id}\">view</a>"); message::success(t("Saved photo %photo_title", array("photo_title" => p::clean($photo->title)))); print json_encode(array("result" => "success", "location" => url::site("photos/{$photo->id}"))); } else { print json_encode(array("result" => "error", "form" => $form->__toString())); } }
static function site_menu($menu, $theme) { $item = $theme->item(); if ($can_add = $item && access::can("add", $item)) { $menu->get("add_menu")->append(Menu::factory("dialog")->id("embed_add")->label(t("Embed Video"))->url(url::site("form/add/embedded_videos/{$item->id}"))); } }
public function generate_url() { if ($this->id == 0) { return '/gallery/'; } return url::site('/gallery/view/' . $this->id); }
static function site_menu($menu, $theme) { $item = $theme->item(); if ($item && $item->is_album() && access::can("edit", $item)) { $menu->get("options_menu")->append(Menu::factory("link")->id("captionator")->label(t("Caption album"))->css_id("g-menu-captionator-link")->url(url::site("captionator/dialog/{$item->id}"))); } }
public function __get($prop) { if ('url' == $prop) { return url::site("tags/{$this->name}"); } return parent::__get($prop); }
/** * Generates an opening HTML form tag. * * @param string form action attribute * @param array extra attributes * @param array hidden fields to be created immediately after the form tag * @return string */ public static function open($action = NULL, $attr = array(), $hidden = NULL) { // Make sure that the method is always set empty($attr['method']) and $attr['method'] = 'post'; if ($attr['method'] !== 'post' and $attr['method'] !== 'get') { // If the method is invalid, use post $attr['method'] = 'post'; } if ($action === NULL) { // Use the current URL as the default action $action = url::site(Router::$complete_uri); } elseif (strpos($action, '://') === FALSE) { // Make the action URI into a URL $action = url::site($action); } // Set action $attr['action'] = $action; // Only show the CSRF field when form method is POST $hidden_field = $attr['method'] === 'post' ? form::hidden('form_auth_token', csrf::token()) . "\n" : ''; // Form opening tag $form = '<form' . form::attributes($attr) . '>' . "\n" . $hidden_field; // Add hidden fields immediate after opening tag empty($hidden) or $form .= form::hidden($hidden); return $form; }
public static function setting($id, $key = '') { static $modules; if (!is_array($modules)) { $modules = (include SYSROOT . DS . 'modules.php'); } //设置空的module $module = $modules[strtolower($id)]; if (!isset($module)) { $module = array('id' => $id, 'name' => $id, 'path' => $id, 'url' => $id, 'type' => 'system', 'status' => '0', 'publishtime' => '0', 'installtime' => '0', 'updatetime' => '0'); } //修正module的路径 if (empty($module['path'])) { $module['path'] = $module['id']; } switch (strtolower($module['type'])) { case 'core': case 'system': $module['root'] = SYSROOT . DS . 'modules' . DS . $module['path']; $module['url'] = url::system() . '/modules/' . $module['path']; break; case 'site': $module['root'] = SITEROOT . DS . 'modules' . DS . $module['path']; $module['url'] = url::site() . '/modules/' . $module['path']; break; default: $module['root'] = realpath($module['path']); $module['url'] = url::abs($module['path']); break; } if (empty($key)) { return $module; } return $module[strtolower($key)]; }
function action_tryAuth() { $type = $_POST['type']; if (isset($_GET['openid_mode']) && $_GET['openid_mode'] == 'cancel') { $this->request->redirect('auth/login'); return; } $openid = new LightOpenID(); $openid->returnUrl = url::site('auth/finishAuth', TRUE); $openid->required = array('namePerson/friendly', 'contact/email', 'namePerson/first', 'namePerson/last', 'namePerson'); if ($type == 'google') { $openid->identity = 'https://www.google.com/accounts/o8/id'; $url = $openid->authUrl(TRUE); } else { if ($type == 'yahoo') { $openid->identity = 'https://me.yahoo.com'; } else { /* FIXME - flash error message - no type provided*/ $this->request->required('auth/login'); } } if (!isset($url)) { $url = $openid->authUrl(); } $this->request->redirect($url); }
static function movie_menu($menu, $theme) { // Display embedlinks toolbar icon, if the corresponding setting is enabled. if (module::get_var("embedlinks", "ToolbarLinks") == true) { $menu->append(Menu::factory("link")->id("embedlinks")->label(t("Link to this page"))->url(url::site("embedlinks/showlinks/" . $theme->item()->id))->css_class("g-dialog-link")->css_id("g-embedlinks-link")); } }
/** * Sends an email alert * * @param Validation_Core $post * @param Alert_Model $alert * @return bool */ public static function _send_email_alert($post, $alert) { if (!$post instanceof Validation_Core and !$alert instanceof Alert_Model) { throw new Kohana_Exception('Invalid parameter types'); } // Email Alerts, Confirmation Code $alert_email = $post->alert_email; $alert_code = text::random('alnum', 20); $settings = kohana::config('settings'); $to = $alert_email; $from = array(); $from[] = $settings['alerts_email'] ? $settings['alerts_email'] : $settings['site_email']; $from[] = $settings['site_name']; $subject = $settings['site_name'] . " " . Kohana::lang('alerts.verification_email_subject'); $message = Kohana::lang('alerts.confirm_request') . url::site() . 'alerts/verify?c=' . $alert_code . "&e=" . $alert_email; if (email::send($to, $from, $subject, $message, TRUE) == 1) { $alert->alert_type = self::EMAIL_ALERT; $alert->alert_recipient = $alert_email; $alert->alert_code = $alert_code; if (isset($_SESSION['auth_user'])) { $alert->user_id = $_SESSION['auth_user']->id; } $alert->save(); self::_add_categories($alert, $post); return TRUE; } return FALSE; }
static function photo_menu($menu, $theme) { if (module::get_var("ecard", "location") == "top") { $item = $theme->item(); $menu->append(Menu::factory("link")->id("ecard")->label(t("Send as eCard"))->url(url::site("ecard/form_send/{$item->id}"))->css_class("g-dialog-link ui-icon-ecard")->css_id("g-send-ecard")); } }
static function album_menu($menu, $theme) { if (access::can("view_full", $theme->item)) { $downloadLink = url::site("downloadalbum/zip/{$theme->item->id}"); $menu->append(Menu::factory("link")->id("downloadalbum")->label(t("Download Album"))->url($downloadLink)->css_id("g-download-album-link")); } }
/** * @return string An error message suitable for inclusion in the task log */ static function check_index() { list($remaining) = search::stats(); if ($remaining) { site_status::warning(t('Your search index needs to be updated. <a href="%url" class="g-dialog-link">Fix this now</a>', array("url" => html::mark_clean(url::site("admin/maintenance/start/search_task::update_index?csrf=__CSRF__")))), "search_index_out_of_date"); } }
/** * Sends an email alert */ public static function _send_email_alert($post) { // Email Alerts, Confirmation Code $alert_email = $post->alert_email; $alert_lon = $post->alert_lon; $alert_lat = $post->alert_lat; $alert_radius = $post->alert_radius; $alert_code = text::random('alnum', 20); $settings = kohana::config('settings'); $to = $alert_email; $from = array(); $from[] = $settings['alerts_email'] ? $settings['alerts_email'] : $settings['site_email']; $from[] = $settings['site_name']; $subject = $settings['site_name'] . " " . Kohana::lang('alerts.verification_email_subject'); $message = Kohana::lang('alerts.confirm_request') . url::site() . 'alerts/verify?c=' . $alert_code . "&e=" . $alert_email; if (email::send($to, $from, $subject, $message, TRUE) == 1) { $alert = ORM::factory('alert'); $alert->alert_type = self::EMAIL_ALERT; $alert->alert_recipient = $alert_email; $alert->alert_code = $alert_code; $alert->alert_lon = $alert_lon; $alert->alert_lat = $alert_lat; $alert->alert_radius = $alert_radius; if (isset($_SESSION['auth_user'])) { $alert->user_id = $_SESSION['auth_user']->id; } $alert->save(); self::_add_categories($alert, $post); return TRUE; } return FALSE; }