本文整理汇总了PHP中user::active方法的典型用法代码示例。如果您正苦于以下问题:PHP user::active方法的具体用法?PHP user::active怎么用?PHP user::active使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类user
的用法示例。
在下文中一共展示了user::active方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: upgrade
public function upgrade()
{
if (php_sapi_name() == "cli") {
// @todo this may screw up some module installers, but we don't have a better answer at
// this time.
$_SERVER["HTTP_HOST"] = "example.com";
} else {
if (!user::active()->admin && !Session::instance()->get("can_upgrade", false)) {
access::forbidden();
}
}
// Upgrade gallery and user first
module::install("gallery");
module::install("user");
// Then upgrade the rest
foreach (module::available() as $id => $module) {
if ($id == "gallery") {
continue;
}
if ($module->active && $module->code_version != $module->version) {
module::install($id);
}
}
if (php_sapi_name() == "cli") {
print "Upgrade complete\n";
} else {
url::redirect("upgrader?done=1");
}
}
示例2: add_albums_and_photos
function add_albums_and_photos($count, $desired_type = null)
{
srand(time());
$parents = ORM::factory("item")->where("type", "album")->find_all()->as_array();
$owner_id = user::active()->id;
$test_images = glob(MODPATH . "gallery/tests/images/*.[Jj][Pp][Gg]");
batch::start();
$album_count = $photo_count = 0;
for ($i = 0; $i < $count; $i++) {
set_time_limit(30);
$parent = $parents[array_rand($parents)];
$parent->reload();
$type = $desired_type;
if (!$type) {
$type = rand(0, 10) ? "photo" : "album";
}
if ($type == "album") {
$thumb_size = module::get_var("gallery", "thumb_size");
$parents[] = album::create($parent, "rnd_" . rand(), "Rnd {$i}", "random album {$i}", $owner_id)->save();
$album_count++;
} else {
$photo_index = rand(0, count($test_images) - 1);
photo::create($parent, $test_images[$photo_index], basename($test_images[$photo_index]), "rnd_" . rand(), "sample thumb", $owner_id);
$photo_count++;
}
}
batch::stop();
if ($photo_count > 0) {
log::success("content", "(scaffold) Added {$photo_count} photos");
}
if ($album_count > 0) {
log::success("content", "(scaffold) Added {$album_count} albums");
}
url::redirect("scaffold");
}
示例3: site
static function site($menu, $theme)
{
if (file_exists(APPPATH . "controllers/welcome.php")) {
$menu->append(Menu::factory("link")->id("browse")->label("Scaffold")->url(url::site("welcome")));
}
$menu->append(Menu::factory("link")->id("home")->label(t("Home"))->url(url::site("albums/1")));
$item = $theme->item();
if ($item && access::can("edit", $item)) {
$menu->append($options_menu = Menu::factory("submenu")->id("options_menu")->label(t("Options"))->append(Menu::factory("dialog")->id("edit_item")->label($item->type == "album" ? t("Edit album") : t("Edit photo"))->url(url::site("form/edit/{$item->type}s/{$item->id}"))));
// @todo Move album options menu to the album quick edit pane
// @todo Create resized item quick edit pane menu
if ($item->type == "album") {
$options_menu->append(Menu::factory("dialog")->id("add_item")->label(t("Add a photo"))->url(url::site("form/add/albums/{$item->id}?type=photo")))->append(Menu::factory("dialog")->id("add_album")->label(t("Add an album"))->url(url::site("form/add/albums/{$item->id}?type=album")))->append(Menu::factory("dialog")->id("edit_permissions")->label(t("Edit permissions"))->url(url::site("permissions/browse/{$item->id}")));
}
}
if (user::active()->admin) {
$menu->append($admin_menu = Menu::factory("submenu")->id("admin_menu")->label(t("Admin")));
self::admin($admin_menu, $theme);
foreach (module::installed() as $module) {
if ($module->name == "core") {
continue;
}
$class = "{$module->name}_menu";
if (method_exists($class, "admin")) {
call_user_func_array(array($class, "admin"), array(&$admin_menu, $this));
}
}
}
}
示例4: emailid
public function emailid($user_id)
{
// Display a form that a vistor can use to contact a registered user.
// If this page is disabled, show a 404 error.
if (module::get_var("contactowner", "contact_user_link") != true) {
kohana::show_404();
}
// Locate the record for the user specified by $user_id,
// use this to determine the user's name.
$userDetails = ORM::factory("user")->where("id", $user_id)->find_all();
// Make a new form with a couple of text boxes.
$form = new Forge("contactowner/sendemail", "", "post", array("id" => "gContactOwnerSendForm"));
$sendmail_fields = $form->group("contactOwner");
$sendmail_fields->input("email_to")->label(t("To:"))->value($userDetails[0]->name);
$sendmail_fields->input("email_from")->label(t("From:"))->value(user::active()->email);
$sendmail_fields->input("email_subject")->label(t("Subject:"))->value("");
$sendmail_fields->textarea("email_body")->label(t("Message:"))->value("");
$sendmail_fields->hidden("email_to_id")->value($user_id);
// Add a save button to the form.
$sendmail_fields->submit("SendMessage")->value(t("Send"));
// Set up and display the actual page.
$template = new Theme_View("page.html", "Contact");
$template->content = new View("contactowner_emailform.html");
$template->content->sendmail_form = $form;
print $template;
}
示例5: __construct
/**
* Attempts to load a view and pre-load view data.
*
* @throws Kohana_Exception if the requested view cannot be found
* @param string $name view name
* @param string $page_type page type: album, photo, tags, etc
* @param string $theme_name view name
* @return void
*/
public function __construct($name, $page_type)
{
$theme_name = module::get_var("gallery", "active_site_theme");
if (!file_exists("themes/{$theme_name}")) {
module::set_var("gallery", "active_site_theme", "default");
theme::load_themes();
Kohana::log("error", "Unable to locate theme '{$theme_name}', switching to default theme.");
}
parent::__construct($name);
$this->theme_name = module::get_var("gallery", "active_site_theme");
if (user::active()->admin) {
$this->theme_name = Input::instance()->get("theme", $this->theme_name);
}
$this->item = null;
$this->tag = null;
$this->set_global("theme", $this);
$this->set_global("user", user::active());
$this->set_global("page_type", $page_type);
$this->set_global("page_title", null);
if ($page_type == "album") {
$this->set_global("thumb_proportion", $this->thumb_proportion());
}
$maintenance_mode = Kohana::config("core.maintenance_mode", false, false);
if ($maintenance_mode) {
message::warning(t("This site is currently in maintenance mode"));
}
}
示例6: _form_edit
public function _form_edit($user)
{
if ($user->guest || $user->id != user::active()->id) {
access::forbidden();
}
print user::get_edit_form($user);
}
示例7: search
static function search($q, $limit, $offset) {
$db = Database::instance();
$q = $db->escape_str($q);
if (!user::active()->admin) {
foreach (user::group_ids() as $id) {
$fields[] = "`view_$id` = " . access::ALLOW;
}
$access_sql = "AND (" . join(" AND ", $fields) . ")";
} else {
$access_sql = "";
}
// Count the total number of rows. We can't do this with our regular query because of the
// limit statement. It's possible that if we get rid of the limit (but keep the offset) on
// the 2nd query and combine the two, it might be faster than making 2 separate queries.
$count_query = "SELECT COUNT(*) AS c " .
"FROM {items} JOIN {search_records} ON ({items}.`id` = {search_records}.`item_id`) " .
"WHERE MATCH({search_records}.`data`) AGAINST ('$q' IN BOOLEAN MODE) " .
$access_sql;
$count = $db->query($count_query)->current()->c;
$query = "SELECT {items}.*, MATCH({search_records}.`data`) AGAINST ('$q') AS `score` " .
"FROM {items} JOIN {search_records} ON ({items}.`id` = {search_records}.`item_id`) " .
"WHERE MATCH({search_records}.`data`) AGAINST ('$q' IN BOOLEAN MODE) " .
$access_sql .
"ORDER BY `score` DESC " .
"LIMIT $limit OFFSET $offset";
return array($count, new ORM_Iterator(ORM::factory("item"), $db->query($query)));
}
示例8: _create
/**
* Add a new comment to the collection.
* @see REST_Controller::_create($resource)
*/
public function _create($comment)
{
$item = ORM::factory("item", $this->input->post("item_id"));
access::required("view", $item);
$form = comment::get_add_form($item);
$valid = $form->validate();
if ($valid) {
if (user::active()->guest && !$form->add_comment->inputs["name"]->value) {
$form->add_comment->inputs["name"]->add_error("missing", 1);
$valid = false;
}
if (!$form->add_comment->text->value) {
$form->add_comment->text->add_error("missing", 1);
$valid = false;
}
}
if ($valid) {
$comment = comment::create($item, user::active(), $form->add_comment->text->value, $form->add_comment->inputs["name"]->value, $form->add_comment->email->value, $form->add_comment->url->value);
$active = user::active();
if ($active->guest) {
$form->add_comment->inputs["name"]->value("");
$form->add_comment->email->value("");
$form->add_comment->url->value("");
} else {
$form->add_comment->inputs["name"]->value($active->full_name);
$form->add_comment->email->value($active->email);
$form->add_comment->url->value($active->url);
}
$form->add_comment->text->value("");
print json_encode(array("result" => "success", "resource" => $comment->state == "published" ? url::site("comments/{$comment->id}") : null, "form" => $form->__toString()));
} else {
print json_encode(array("result" => "error", "form" => $form->__toString()));
}
}
示例9: __construct
public function __construct($theme = null)
{
if (!user::active()->admin) {
throw new Exception("@todo UNAUTHORIZED", 401);
}
parent::__construct();
}
示例10: viewable
/**
* Add a set of restrictions to any following queries to restrict access only to items
* viewable by the active user.
* @chainable
*/
public function viewable()
{
if (is_null($this->view_restrictions)) {
if (user::active()->admin) {
$this->view_restrictions = array();
} else {
foreach (user::group_ids() as $id) {
// Separate the first restriction from the rest to make it easier for us to formulate
// our where clause below
if (empty($this->view_restrictions)) {
$this->view_restrictions[0] = "view_{$id}";
} else {
$this->view_restrictions[1]["view_{$id}"] = access::ALLOW;
}
}
}
}
switch (count($this->view_restrictions)) {
case 0:
break;
case 1:
$this->where($this->view_restrictions[0], access::ALLOW);
break;
default:
$this->open_paren();
$this->where($this->view_restrictions[0], access::ALLOW);
$this->orwhere($this->view_restrictions[1]);
$this->close_paren();
break;
}
return $this;
}
示例11: change
function change($command, $group_id, $perm_id, $item_id)
{
access::verify_csrf();
$group = ORM::factory("group", $group_id);
$perm = ORM::factory("permission", $perm_id);
$item = ORM::factory("item", $item_id);
access::required("view", $item);
access::required("edit", $item);
if ($group->loaded && $perm->loaded && $item->loaded) {
switch ($command) {
case "allow":
access::allow($group, $perm->name, $item);
break;
case "deny":
access::deny($group, $perm->name, $item);
break;
case "reset":
access::reset($group, $perm->name, $item);
break;
}
// If the active user just took away their own edit permissions, give it back.
if ($perm->name == "edit") {
if (!access::user_can(user::active(), "edit", $item)) {
access::allow($group, $perm->name, $item);
}
}
}
}
示例12: header_top
static function header_top($theme)
{
if ($theme->page_type != "login") {
$view = new View("login.html");
$view->user = user::active();
return $view->render();
}
}
示例13: is_admin
function is_admin()
{
if (user::active()->admin) {
print json_encode(array("result" => "success", "csrf" => access::csrf_token()));
return;
}
print json_encode(array("result" => "failure"));
}
示例14: site_menu
static function site_menu($menu, $theme)
{
$item = $theme->item();
$paths = unserialize(module::get_var("server_add", "authorized_paths"));
if ($item && user::active()->admin && $item->is_album() && !empty($paths) && is_writable($item->is_album() ? $item->file_path() : $item->parent()->file_path())) {
$menu->get("add_menu")->append(Menu::factory("dialog")->id("server_add")->label(t("Server add"))->url(url::site("server_add/browse/{$item->id}")));
}
}
示例15: form_edit
public function form_edit($id)
{
$user = user::lookup($id);
if ($user->guest || $user->id != user::active()->id) {
access::forbidden();
}
print $this->_get_edit_form($user);
}