本文整理汇总了PHP中Visitor::current方法的典型用法代码示例。如果您正苦于以下问题:PHP Visitor::current方法的具体用法?PHP Visitor::current怎么用?PHP Visitor::current使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Visitor
的用法示例。
在下文中一共展示了Visitor::current方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: extend_nav
public function extend_nav($navs)
{
if (Visitor::current()->group->can("toggle_extensions")) {
$navs["extend_manager"] = array("title" => __("Extension Manager", "extension_manager"));
}
return $navs;
}
示例2: settings_nav
static function settings_nav($navs)
{
if (Visitor::current()->group->can("change_settings")) {
$navs["obscura_settings"] = array("title" => __("Obscura", "obscura"));
}
return $navs;
}
示例3: route_submit
/**
* Function: submit
* Submits a post to the blog owner.
*/
public function route_submit()
{
if (!Visitor::current()->group->can("submit_article")) {
show_403(__("Access Denied"), __("You do not have sufficient privileges to submit articles."));
}
if (!empty($_POST)) {
if (!isset($_POST['hash']) or $_POST['hash'] != Config::current()->secure_hashkey) {
show_403(__("Access Denied"), __("Invalid security key."));
}
if (empty($_POST['body'])) {
Flash::notice(__("Post body can't be empty!"), redirect("/"));
}
if (!isset($_POST['draft'])) {
$_POST['draft'] = "true";
}
$_POST['body'] = "{$_POST['body']}\n\n\n{$_POST['name']}\n{$_POST['email']}\n";
$post = Feathers::$instances[$_POST['feather']]->submit();
if (!in_array(false, $post)) {
Flash::notice(__("Thank you for your submission. ", "submission"), "/");
}
}
if (Theme::current()->file_exists("forms/post/submit")) {
MainController::current()->display("forms/post/submit", array("feather" => $feather), __("Submit a Text Post"));
} else {
require "pages/submit.php";
}
}
示例4: settings_nav
public function settings_nav($navs)
{
if (Visitor::current()->group->can("change_settings")) {
$navs["friendfeedr_settings"] = array("title" => __("FriendFeed", "friendfeedr"));
}
return $navs;
}
示例5: write
/**
* Function: write
* Writes their session to the database, or updates it if it already exists.
*
* Parameters:
* $id - Session ID.
* $data - Data to write.
*/
static function write($id, $data)
{
if (empty($data) or $data == self::$data) {
return;
}
$sql = SQL::current();
if ($sql->count("sessions", array("id" => $id))) {
$sql->update("sessions", array("id" => $id), array("data" => $data, "user_id" => Visitor::current()->id, "updated_at" => datetime()));
} else {
$sql->insert("sessions", array("id" => $id, "data" => $data, "user_id" => Visitor::current()->id, "created_at" => datetime()));
}
}
示例6: __construct
/**
* Function: __construct
* See Also:
* <Model::grab>
*/
public function __construct($req = null, $user_id = null)
{
$this->action = isset($req["action"]) ? $req["action"] == "unlike" ? "unlike" : "like" : null;
# user info
$this->user_id = isset($user_id) ? $user_id : Visitor::current()->id;
$this->user_name = null;
# post info
$this->total_count = 0;
$this->post_id = isset($req["post_id"]) ? (int) fix($req["post_id"]) : null;
# inits
$this->cookieInit();
}
示例7: add
/**
* Function: add
* Adds a page to the database.
*
* Calls the @add_page@ trigger with the new <Page>.
*
* Parameters:
* $title - The Title for the new page.
* $body - The Body for the new page.
* $body - The <User> or <User.id> of the page's author.
* $parent_id - The ID of the new page's parent page (0 for none).
* $show_in_list - Whether or not to show it in the pages list.
* $list_order - The order of the page in the list.
* $clean - The clean URL.
* $url - The unique URL.
* $created_at - The new page's "created" timestamp.
* $updated_at - The new page's "last updated" timestamp.
*
* Returns:
* The newly created <Page>.
*
* See Also:
* <update>
*/
static function add($title, $body, $user = null, $parent_id = 0, $show_in_list = true, $list_order = 0, $clean = "", $url = "", $created_at = null, $updated_at = "0000-00-00 00:00:00")
{
$user_id = $user instanceof User ? $user->id : $user;
$sql = SQL::current();
$visitor = Visitor::current();
$trigger = Trigger::current();
$new_values = array("title" => $title, "body" => $body, "user_id" => oneof($user_id, $visitor->id), "parent_id" => oneof($parent_id, 0), "show_in_list" => oneof($show_in_list, true), "list_order" => oneof($list_order, 0), "clean" => oneof($clean, sanitize($title)), "url" => oneof($url, self::check_url($clean)), "created_at" => oneof($created_at, datetime()), "updated_at" => oneof($updated_at, "0000-00-00 00:00:00"));
$trigger->filter($new_values, "before_add_page");
$sql->insert("pages", $new_values);
$page = new self($sql->latest());
$trigger->call("add_page", $page);
return $page;
}
示例8: __construct
public function __construct($url, $config)
{
$this->user = logged_in() ? Visitor::current()->login : "guest";
$this->path = INCLUDES_DIR . "/caches/" . sanitize($this->user);
$this->caches = INCLUDES_DIR . "/caches";
$this->url = $url;
$this->file = $this->path . "/" . md5($this->url) . ".html";
# If the cache directory is not writable, disable this module and cancel execution.
if (!is_writable($this->caches)) {
cancel_module("cacher");
}
# Remove all expired files.
$this->remove_expired();
}
示例9: __construct
public function __construct($url, $config)
{
$raw_hosts = (array) $config->cache_memcached_hosts;
$this->user = logged_in() ? Visitor::current()->login : "guest";
$this->memcache = new Memcache();
$this->url = $url;
$this->config = $config;
$disable_module = true;
foreach ($raw_hosts as $raw) {
$raw = trim($raw);
if ($raw == '') {
continue;
}
$stack = explode(':', $raw);
$host = false;
$port = 11211;
if (count($stack) == 9 or count($stack) == 2) {
# ipv6 with port is 9, ipv4 with port is 2
$port = array_pop($stack);
}
if (count($stack) == 1) {
$host = $stack[0];
}
if (count($stack) == 8) {
# ipv6 is 8 entries
$host = implode(':', $stack);
}
if ($host === false and count($stack) > 0) {
# probably a uri for other transit
$host = implode(':', $stack);
$port = 0;
# other transit requires a port of 0
}
if ($host === false) {
error_log("Memcached error: {$raw} is an invalid host address");
} else {
$this->memcache->addServer($host, $port);
$disable_module = false;
}
}
//$disable_module = true;
if ($disable_module) {
cancel_module("cacher");
}
}
示例10: admin_theme_editor
public function admin_theme_editor($admin)
{
if (!Visitor::current()->group->can("change_settings")) {
show_403(__("Access Denied"), __("You do not have sufficient privileges to change settings."));
}
if (empty($_POST)) {
return $admin->display("theme_editor", array("editor" => self::admin_context($admin->context)), __("Theme Editor", "theme_editor"));
}
if (!isset($_POST['hash']) or $_POST['hash'] != Config::current()->secure_hashkey) {
show_403(__("Access Denied"), __("Invalid security key."));
}
if (isset($_POST['file']) and isset($_POST['newcontent'])) {
$done = file_put_contents($_POST['file'], $_POST['newcontent']);
if (!empty($done)) {
Flash::notice(__("File Updated"), "/admin/?action=theme_editor&file=" . $_POST['cur_file']);
}
}
}
示例11: display
/**
* Function: display
* Display the page.
*
* If "posts" is in the context and the visitor requested a feed, they will be served.
*
* Parameters:
* $file - The theme file to display.
* $context - The context for the file.
* $title - The title for the page.
*/
public function display($file, $context = array(), $title = "")
{
if (is_array($file)) {
for ($i = 0; $i < count($file); $i++) {
$check = ($file[$i][0] == "/" or preg_match("/[a-zA-Z]:\\\\/", $file[$i])) ? $file[$i] : THEME_DIR . "/" . $file[$i];
if (file_exists($check . ".twig") or $i + 1 == count($file)) {
return $this->display($file[$i], $context, $title);
}
}
}
$this->displayed = true;
$route = Route::current();
$trigger = Trigger::current();
# Serve feeds.
if ($this->feed) {
if ($trigger->exists($route->action . "_feed")) {
return $trigger->call($route->action . "_feed", $context);
}
if (isset($context["posts"])) {
return $this->feed($context["posts"]);
}
}
$this->context = array_merge($context, $this->context);
$visitor = Visitor::current();
$config = Config::current();
$theme = Theme::current();
$theme->title = $title;
$this->context["theme"] = $theme;
$this->context["flash"] = Flash::current();
$this->context["trigger"] = $trigger;
$this->context["modules"] = Modules::$instances;
$this->context["feathers"] = Feathers::$instances;
$this->context["title"] = $title;
$this->context["site"] = $config;
$this->context["visitor"] = $visitor;
$this->context["route"] = Route::current();
$this->context["hide_admin"] = isset($_COOKIE["hide_admin"]);
$this->context["version"] = CHYRP_VERSION;
$this->context["now"] = time();
$this->context["debug"] = DEBUG;
$this->context["POST"] = $_POST;
$this->context["GET"] = $_GET;
$this->context["sql_queries"] =& SQL::current()->queries;
$this->context["visitor"]->logged_in = logged_in();
$this->context["enabled_modules"] = array();
foreach ($config->enabled_modules as $module) {
$this->context["enabled_modules"][$module] = true;
}
$context["enabled_feathers"] = array();
foreach ($config->enabled_feathers as $feather) {
$this->context["enabled_feathers"][$feather] = true;
}
$this->context["sql_debug"] =& SQL::current()->debug;
$trigger->filter($this->context, array("main_context", "main_context_" . str_replace("/", "_", $file)));
$file = ($file[0] == "/" or preg_match("/[a-zA-Z]:\\\\/", $file)) ? $file : THEME_DIR . "/" . $file;
if (!file_exists($file . ".twig")) {
error(__("Template Missing"), _f("Couldn't load template: <code>%s</code>", array($file . ".twig")));
}
try {
return $this->twig->getTemplate($file . ".twig")->display($this->context);
} catch (Exception $e) {
$prettify = preg_replace("/([^:]+): (.+)/", "\\1: <code>\\2</code>", $e->getMessage());
$trace = debug_backtrace();
$twig = array("file" => $e->filename, "line" => $e->lineno);
array_unshift($trace, $twig);
error(__("Error"), $prettify, $trace);
}
}
示例12: keywords
/**
* Function: keywords
* Handle keyword-searching.
*
* Parameters:
* $query - The query to parse.
* $plain - WHERE syntax to search for non-keyword queries.
* $table - If specified, the keywords will be checked against this table's columns for validity.
*
* Returns:
* An array containing the "WHERE" queries and the corresponding parameters.
*/
function keywords($query, $plain, $table = null)
{
if (!trim($query)) {
return array(array(), array());
}
$search = array();
$matches = array();
$where = array();
$params = array();
if ($table) {
$columns = SQL::current()->select($table)->fetch();
}
$queries = explode(" ", $query);
foreach ($queries as $query) {
if (!preg_match("/([a-z0-9_]+):(.+)/", $query)) {
$search[] = $query;
} else {
$matches[] = $query;
}
}
$times = array("year", "month", "day", "hour", "minute", "second");
foreach ($matches as $match) {
list($test, $equals, ) = explode(":", $match);
if ($equals[0] == '"') {
if (substr($equals, -1) != '"') {
foreach ($search as $index => $part) {
$equals .= " " . $part;
unset($search[$index]);
if (substr($part, -1) == '"') {
break;
}
}
}
$equals = ltrim(trim($equals, '"'), '"');
}
if (in_array($test, $times)) {
if ($equals == "today") {
$where["created_at like"] = date("%Y-m-d %");
} elseif ($equals == "yesterday") {
$where["created_at like"] = date("%Y-m-d %", now("-1 day"));
} elseif ($equals == "tomorrow") {
error(__("Error"), "Unfortunately our flux capacitor is currently having issues. Try again yesterday.");
} else {
$where[strtoupper($test) . "(created_at)"] = $equals;
}
} elseif ($test == "author") {
$user = new User(array("login" => $equals));
if ($user->no_results and $equals == "me") {
$where["user_id"] = Visitor::current()->id;
} else {
$where["user_id"] = $user->id;
}
} elseif ($test == "group") {
$group = new Group(array("name" => $equals));
$test = "group_id";
$equals = $group->no_results ? 0 : $group->id;
} else {
$where[$test] = $equals;
}
}
if ($table) {
foreach ($where as $col => $val) {
if (!isset($columns[$col])) {
if ($table == "posts") {
$where["post_attributes.name"] = $col;
$where["post_attributes.value like"] = "%" . $val . "%";
}
unset($where[$col]);
}
}
}
if (!empty($search)) {
$where[] = $plain;
$params[":query"] = "%" . join(" ", $search) . "%";
}
$keywords = array($where, $params);
Trigger::current()->filter($keywords, "keyword_search", $query, $plain);
return $keywords;
}
示例13: admin_manage_tags
public function admin_manage_tags($admin)
{
$sql = SQL::current();
$tags = array();
$names = array();
foreach ($sql->select("post_attributes", "*", array("name" => "tags"))->fetchAll() as $tag) {
$post_tags = YAML::load($tag["value"]);
$tags = array_merge($tags, $post_tags);
foreach ($post_tags as $name => $clean) {
$names[] = $name;
}
}
$popularity = array_count_values($names);
$cloud = array();
if (!empty($popularity)) {
$max_qty = max($popularity);
$min_qty = min($popularity);
$spread = $max_qty - $min_qty;
if ($spread == 0) {
$spread = 1;
}
$step = 75 / $spread;
foreach ($popularity as $tag => $count) {
$cloud[] = array("size" => 100 + ($count - $min_qty) * $step, "popularity" => $count, "name" => $tag, "title" => sprintf(_p("%s post tagged with "%s"", "%s posts tagged with "%s"", $count, "tags"), $count, $tag), "clean" => $tags[$tag], "url" => url("tag/" . $tags[$tag]));
}
if (!Post::any_editable() and !Post::any_deletable()) {
return $admin->display("manage_tags", array("tag_cloud" => $cloud));
}
}
fallback($_GET['query'], "");
list($where, $params) = keywords($_GET['query'], "post_attributes.value LIKE :query OR url LIKE :query");
$visitor = Visitor::current();
if (!$visitor->group->can("view_draft", "edit_draft", "edit_post", "delete_draft", "delete_post")) {
$where["user_id"] = $visitor->id;
}
$results = Post::find(array("placeholders" => true, "where" => $where, "params" => $params));
$ids = array();
foreach ($results[0] as $result) {
$ids[] = $result["id"];
}
if (!empty($ids)) {
$posts = new Paginator(Post::find(array("placeholders" => true, "drafts" => true, "where" => array("id" => $ids))), 25);
} else {
$posts = new Paginator(array());
}
$admin->display("manage_tags", array("tag_cloud" => $cloud, "posts" => $posts));
}
示例14: admin_clear_cache
public function admin_clear_cache()
{
if (!Visitor::current()->group->can("change_settings")) {
show_403(__("Access Denied"), __("You do not have sufficient privileges to change settings."));
}
$this->regenerate();
Flash::notice(__("Cache cleared.", "cacher"), "/admin/?action=cache_settings");
}
示例15: admin_destroy_aggregate
public function admin_destroy_aggregate($admin)
{
if (empty($_POST['id'])) {
error(__("No ID Specified"), __("An ID is required to delete an aggregate.", "aggregator"));
}
if ($_POST['destroy'] == "bollocks") {
redirect("/admin/?action=manage_aggregates");
}
if (!isset($_POST['hash']) or $_POST['hash'] != Config::current()->secure_hashkey) {
show_403(__("Access Denied"), __("Invalid security key."));
}
if (!Visitor::current()->group->can("delete_aggregate")) {
show_403(__("Access Denied"), __("You do not have sufficient privileges to delete this aggregate.", "aggregator"));
}
$name = $_POST['id'];
if ($_POST["delete_posts"]) {
$this->delete_posts($name);
$notice = __("Aggregate and its posts deleted.", "aggregator");
} else {
$notice = __("Aggregate deleted.", "aggregator");
}
$config = Config::current();
unset($config->aggregates[$name]);
$config->set("aggregates", $config->aggregates);
Flash::notice($notice, "/admin/?action=manage_aggregates");
}