public function delete_test() { $tag = tag::add(item::root(), "tag1")->reload(); $request->url = rest::url("tag_item", $tag, item::root()); tag_item_rest::delete($request); $this->assert_false($tag->reload()->has(item::root())); }
public function get_test() { $t1 = tag::add(item::root(), "t1"); $t2 = tag::add(item::root(), "t2"); $request = new stdClass(); $this->assert_equal_array(array("url" => rest::url("tags"), "members" => array(rest::url("tag", $t1), rest::url("tag", $t2))), tags_rest::get($request)); }
public function get_test() { $tag = tag::add(item::root(), "tag1")->reload(); $request = new stdClass(); $request->url = rest::url("tag", $tag); $this->assert_equal_array(array("url" => rest::url("tag", $tag), "entity" => $tag->as_array(), "relationships" => array("items" => array("url" => rest::url("tag_items", $tag), "members" => array(rest::url("tag_item", $tag, item::root()))))), tag_rest::get($request)); }
public function change() { access::verify_csrf(); $active_provider = module::get_var("gallery", "identity_provider", "user"); $providers = identity::providers(); $new_provider = Input::instance()->post("provider"); if ($new_provider != $active_provider) { module::deactivate($active_provider); // Switch authentication identity::reset(); module::set_var("gallery", "identity_provider", $new_provider); module::install($new_provider); module::activate($new_provider); module::event("identity_provider_changed", $active_provider, $new_provider); module::uninstall($active_provider); message::success(t("Changed to %description", array("description" => $providers->{$new_provider}))); try { Session::instance()->destroy(); } catch (Exception $e) { // We don't care if there was a problem destroying the session. } url::redirect(item::root()->abs_url()); } message::info(t("The selected provider \"%description\" is already active.", array("description" => $providers->{$new_provider}))); url::redirect("admin/identity"); }
public function index() { if (isset($_GET['cw'])) { setcookie('cw_agree', '1', time() + 60 * 60 * 24, '/'); url::redirect(item::root()->abs_url()); } }
public function create_comment_for_user_test() { $admin = identity::admin_user(); $comment = ORM::factory("comment"); $comment->item_id = item::root()->id; $comment->text = "text"; $comment->author_id = $admin->id; $comment->save(); $this->assert_equal($admin->full_name, $comment->author_name()); $this->assert_equal($admin->email, $comment->author_email()); $this->assert_equal($admin->url, $comment->author_url()); $this->assert_equal("text", $comment->text); $this->assert_equal(1, $comment->item_id); $this->assert_equal("REMOTE_ADDR", $comment->server_remote_addr); $this->assert_equal("HTTP_USER_AGENT", $comment->server_http_user_agent); $this->assert_equal("HTTP_ACCEPT", $comment->server_http_accept); $this->assert_equal("HTTP_ACCEPT_CHARSET", $comment->server_http_accept_charset); $this->assert_equal("HTTP_ACCEPT_ENCODING", $comment->server_http_accept_encoding); $this->assert_equal("HTTP_ACCEPT_LANGUAGE", $comment->server_http_accept_language); $this->assert_equal("HTTP_CONNECTION", $comment->server_http_connection); $this->assert_equal("HTTP_HOST", $comment->server_http_host); $this->assert_equal("HTTP_REFERER", $comment->server_http_referer); $this->assert_equal("HTTP_USER_AGENT", $comment->server_http_user_agent); $this->assert_equal("QUERY_STRING", $comment->server_query_string); $this->assert_equal("REMOTE_ADDR", $comment->server_remote_addr); $this->assert_equal("REMOTE_HOST", $comment->server_remote_host); $this->assert_equal("REMOTE_PORT", $comment->server_remote_port); $this->assert_true(!empty($comment->created)); }
static function site_menu($menu, $theme) { if ($theme->page_type != "login") { $menu->append(Menu::factory("link")->id("home")->label(t("Home"))->url(item::root()->url())); $item = $theme->item(); $can_edit = $item && access::can("edit", $item); $can_add = $item && access::can("add", $item); if ($can_add) { $menu->append($add_menu = Menu::factory("submenu")->id("add_menu")->label(t("Add"))); $add_menu->append(Menu::factory("dialog")->id("add_photos_item")->label(t("Add photos"))->url(url::site("simple_uploader/app/{$item->id}"))); if ($item->is_album()) { $add_menu->append(Menu::factory("dialog")->id("add_album_item")->label(t("Add an album"))->url(url::site("form/add/albums/{$item->id}?type=album"))); } } $menu->append($options_menu = Menu::factory("submenu")->id("options_menu")->label(t("Photo options"))); if ($item && ($can_edit || $can_add)) { if ($can_edit) { $options_menu->append(Menu::factory("dialog")->id("edit_item")->label($item->is_album() ? t("Edit album") : t("Edit photo"))->url(url::site("form/edit/{$item->type}s/{$item->id}"))); } if ($item->is_album()) { $options_menu->label(t("Album options")); if ($can_edit) { $options_menu->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"))); gallery::admin_menu($admin_menu, $theme); module::event("admin_menu", $admin_menu, $theme); } module::event("site_menu", $menu, $theme); } }
public function show($page_name) { // Display the page specified by $page_name, or a 404 error if it doesn't exist. // Run a database search to look up the page. $existing_page = ORM::factory("px_static_page")->where("name", "=", $page_name)->find_all(); // If it doesn't exist, display a 404 error. if (count($existing_page) == 0) { throw new Kohana_404_Exception(); } // Set up breadcrumbs. $breadcrumbs = array(); $root = item::root(); $breadcrumbs[] = Breadcrumb::instance($root->title, $root->url())->set_first(); $breadcrumbs[] = Breadcrumb::instance(t($existing_page[0]->title), url::site("pages_xtra/show/{$page_name}"))->set_last(); // Display the page. $template = new Theme_View("page.html", "other", "Pages"); $template->set_global(array("breadcrumbs" => $breadcrumbs)); // Call database variables into page header (off-page content). $site_title = module::get_var("pages_xtra", "site_title"); // Next line can be used as alternative to the following line // $template->page_title = t("Gallery :: ") . t($existing_page[0]->title); $template->page_title = t($existing_page[0]->title) . t(" :: {$site_title}"); $template->page_tags = $existing_page[0]->tags; $page_tags = trim(nl2br(html::purify($existing_page[0]->tags))); $template->page_description = $existing_page[0]->description; $page_description = trim(nl2br(html::purify($existing_page[0]->description))); // Set a new View and call database variables into page (on-page content). $template->content = new View("pages_xtra_display.html"); $template->content->title = $existing_page[0]->title; $template->content->body = $existing_page[0]->html_code; print $template; }
/** * Create an album for the newly created user and give him view and edit permissions. */ static function user_created($user) { // Create a group with the same name, if necessary $group_name = "auto: {$user->name}"; $group = identity::lookup_group_by_name($group_name); if (!$group) { $group = identity::create_group($group_name); identity::add_user_to_group($user, $group); } // Create an album for the user, if it doesn't exist $album = ORM::factory("item")->where("parent_id", "=", item::root()->id)->where("name", "=", $user->name)->find(); if (!$album->loaded()) { $album->type = "album"; $album->name = $user->name; $album->title = "{$user->name}'s album"; $album->parent_id = item::root()->id; $album->sort_column = "weight"; $album->sort_order = "asc"; $album->save(); access::allow($group, "view", item::root()); access::allow($group, "view_full", $album); access::allow($group, "edit", $album); access::allow($group, "add", $album); } }
static function feed($feed_id, $offset, $limit, $id) { $feed = new stdClass(); switch ($feed_id) { case "latest": $feed->items = ORM::factory("item")->viewable()->where("type", "<>", "album")->order_by("created", "DESC")->find_all($limit, $offset); $all_items = ORM::factory("item")->viewable()->where("type", "<>", "album")->order_by("created", "DESC"); $feed->max_pages = ceil($all_items->find_all()->count() / $limit); $feed->title = t("%site_title - Recent updates", array("site_title" => item::root()->title)); $feed->description = t("Recent updates"); return $feed; case "album": $item = ORM::factory("item", $id); access::required("view", $item); $feed->items = $item->viewable()->descendants($limit, $offset, array(array("type", "=", "photo"))); $feed->max_pages = ceil($item->viewable()->descendants_count(array(array("type", "=", "photo"))) / $limit); if ($item->id == item::root()->id) { $feed->title = html::purify($item->title); } else { $feed->title = t("%site_title - %item_title", array("site_title" => item::root()->title, "item_title" => $item->title)); } $feed->description = nl2br(html::purify($item->description)); return $feed; } }
/** * Redirect Gallery 2 urls to their appropriate matching Gallery 3 url. * * We use mod_rewrite to create this path, so Gallery2 urls like this: * /gallery2/v/Family/Wedding.jpg.html * /gallery2/main.php?g2_view=core.ShowItem&g2_itemId=1234 * * Show up here like this: * /g2/map?path=v/Family/Wedding.jpg.html * /g2/map?g2_view=core.ShowItem&g2_itemId=1931 */ public function map() { $input = Input::instance(); $path = $input->get("path"); $id = $input->get("g2_itemId"); if ($path && $path != 'index.php' && $path != 'main.php' || $id) { if ($id) { // Requests by id are either core.DownloadItem or core.ShowItem requests. Later versions of // Gallery 2 don't specify g2_view if it's the default (core.ShowItem). And in some cases // (bbcode, embedding) people are using the id style URLs although URL rewriting is enabled. $where = array(array("g2_id", "=", $id)); $view = $input->get("g2_view"); if ($view == "core.DownloadItem") { $where[] = array("resource_type", "IN", array("file", "resize", "thumbnail", "full")); } else { if ($view) { $where[] = array("g2_url", "like", "%g2_view={$view}%"); } } // else: Assuming that the first search hit is sufficiently good. } else { if ($path) { $where = array(array("g2_url", "IN", array($path, str_replace(" ", "+", $path)))); } else { throw new Kohana_404_Exception(); } } $g2_map = ORM::factory("g2_map")->merge_where($where)->find(); if (!$g2_map->loaded()) { throw new Kohana_404_Exception(); } $item = ORM::factory("item", $g2_map->g3_id); if (!$item->loaded()) { throw new Kohana_404_Exception(); } $resource_type = $g2_map->resource_type; } else { $item = item::root(); $resource_type = "album"; } access::required("view", $item); // Redirect the user to the new url switch ($resource_type) { case "thumbnail": url::redirect($item->thumb_url(true)); case "resize": url::redirect($item->resize_url(true)); case "file": case "full": url::redirect($item->file_url(true)); case "item": case "album": url::redirect($item->abs_url()); case "group": case "user": default: throw new Kohana_404_Exception(); } }
public function post_test() { access::allow(identity::everybody(), "edit", item::root()); $request = new stdClass(); $request->params = new stdClass(); $request->params->name = "test tag"; $this->assert_equal(array("url" => url::site("rest/tag/1")), tags_rest::post($request)); }
public function index() { access::verify_csrf(); auth::logout(); if ($continue_url = Input::instance()->get("continue_url")) { url::redirect($continue_url); } url::redirect(item::root()->abs_url()); }
public function index() { if (!user::active()->admin) { url::redirect(item::root()->abs_url()); } $v = new View("welcome_message.html"); $v->user = user::active(); print $v; }
public function auth_html() { access::verify_csrf(); list($valid, $form) = $this->_auth("login/auth_html"); if ($valid) { url::redirect(item::root()->abs_url()); } else { print $form; } }
static function site_menu($menu, $theme) { if (module::get_var("menu_links", "title") != null) { $menu->add_before("home", Menu::factory("link")->id("root")->label(module::get_var("menu_links", "title"))->url(module::get_var("menu_links", "url"))); } $menu->append(Menu::factory("link")->id("home")->css_id("g-menu-link-remove")->label(module::get_var("menu_links", "title2"))->url(item::root()->url())); if (module::get_var("menu_links", "title3") != null) { $menu->add_after("home", Menu::factory("link")->id("after_root")->label(module::get_var("menu_links", "title3"))->url(module::get_var("menu_links", "url3"))); } }
public function build_breadcrumbs_for_item_test() { $album = test::random_album(); $item = test::random_photo($album); $expected = array(); $expected[] = Breadcrumb::instance(item::root()->title, item::root()->url("show={$album->id}"))->set_first(); $expected[] = Breadcrumb::instance($album->title, $album->url("show={$item->id}")); $expected[] = Breadcrumb::instance($item->title, $item->url())->set_last(); $this->assert_equal($expected, Breadcrumb::array_from_item_parents($item)); }
static function initialize() { module::set_version("ldap", 1); $root = item::root(); foreach (IdentityProvider::instance()->groups() as $group) { module::event("group_created", $group); access::allow($group, "view", $root); access::allow($group, "view_full", $root); } }
function remind_me_later() { access::verify_csrf(); site_status::clear("upgrade_checker"); if ($referer = Input::instance()->server("HTTP_REFERER")) { url::redirect($referer); } else { url::redirect(item::root()->abs_url()); } }
static function install() { module::set_version("ldap", 1); $root = item::root(); $ldap_provider = new IdentityProvider("ldap"); foreach ($ldap_provider->groups() as $group) { module::event("group_created", $group); access::allow($group, "view", $root); access::allow($group, "view_full", $root); } }
static function get_display_context($item, $album_defn, $path) { $where = array(array("type", "!=", "album")); $position = dynamic::get_position($album_defn, $item, $where); if ($position > 1) { list($previous_item, $ignore, $next_item) = dynamic::items($album_defn->key_field, 3, $position - 2); } else { $previous_item = null; list($next_item) = dynamic::items($album_defn->key_field, 1, $position); } $root = item::root(); return array("position" => $position, "previous_item" => $previous_item, "next_item" => $next_item, "sibling_count" => dynamic::get_display_count($album_defn), "siblings_callback" => array("dynamic::items", array($album_defn->key_field)), "breadcrumbs" => array(Breadcrumb::instance($root->title, $root->url())->set_first(), Breadcrumb::instance($album_defn->title, url::site("dynamic/{$path}?show={$item->id}")), Breadcrumb::instance($item->title, $item->url())->set_last())); }
public function preview($type, $theme_name) { $view = new View("admin_themes_preview.html"); $view->info = theme::get_info($theme_name); $view->theme_name = t($theme_name); $view->type = $type; if ($type == "admin") { $view->url = url::site("admin?theme={$theme_name}"); } else { $view->url = item::root()->url("theme={$theme_name}"); } print $view; }
public function cant_move_parent_into_own_subtree_test() { $album1 = test::random_album(item::root()); $album2 = test::random_album($album1); $album3 = test::random_album($album2); try { $album1->parent_id = $album3->id; $album1->save(); $this->assert_true(false, "We should be unable to move an item inside its own hierarchy"); } catch (Exception $e) { // pass } }
public function index() { auth::logout(); if ($continue_url = Input::instance()->get("continue")) { $item = url::get_item_from_uri($continue_url); if (access::can("view", $item)) { // Don't use url::redirect() because it'll call url::site() and munge the continue url. header("Location: {$continue_url}"); } else { url::redirect(item::root()->abs_url()); } } }
public function post_fails_without_permissions_test() { access::deny(identity::everybody(), "edit", item::root()); identity::set_active_user(identity::guest()); try { $request->params->name = "test tag"; tags_rest::post($request); } catch (Exception $e) { $this->assert_equal(403, $e->getCode()); return; } $this->assert_true(false, "Shouldnt get here"); }
static function site_menu($menu, $theme) { if ($theme->page_type != "login") { $menu->append(Menu::factory("link")->id("home")->label(t("Home"))->url(item::root()->url())); $item = $theme->item(); if (!empty($item)) { $can_edit = $item && access::can("edit", $item); $can_add = $item && access::can("add", $item); if ($can_add) { $menu->append($add_menu = Menu::factory("submenu")->id("add_menu")->label(t("Add"))); $is_album_writable = is_writable($item->is_album() ? $item->file_path() : $item->parent()->file_path()); if ($is_album_writable) { $add_menu->append(Menu::factory("dialog")->id("add_photos_item")->label(t("Add photos"))->url(url::site("simple_uploader/app/{$item->id}"))); if ($item->is_album()) { $add_menu->append(Menu::factory("dialog")->id("add_album_item")->label(t("Add an album"))->url(url::site("form/add/albums/{$item->id}?type=album"))); } } else { message::warning(t("The album '%album_name' is not writable.", array("album_name" => $item->title))); } } switch ($item->type) { case "album": $option_text = t("Album options"); $edit_text = t("Edit album"); break; case "movie": $option_text = t("Movie options"); $edit_text = t("Edit movie"); break; default: $option_text = t("Photo options"); $edit_text = t("Edit photo"); } $menu->append($options_menu = Menu::factory("submenu")->id("options_menu")->label($option_text)); if ($item && ($can_edit || $can_add)) { if ($can_edit) { $options_menu->append(Menu::factory("dialog")->id("edit_item")->label($edit_text)->url(url::site("form/edit/{$item->type}s/{$item->id}"))); } if ($item->is_album()) { if ($can_edit) { $options_menu->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"))); module::event("admin_menu", $admin_menu, $theme); } } }
static function get($block_id) { $block = new Block(); switch ($block_id) { case "albumtree": $style = module::get_var("albumtree", "style", "select"); $block->css_id = "g-albumtree"; $block->title = t("Album Tree"); $block->content = new View("albumtree_block_{$style}.html"); $block->content->root = item::root(); break; } return $block; }
/** * Return an array of Breadcrumb instances build from the parents of a given item. * The first and last Breadcrumb instances will be marked first/last as appropriate. * Each breadcrumb will have a ?show= query parameter that refers to the id of the next * item in line. * * @return array Breadcrumb instances */ static function array_from_item_parents($item) { if ($item->id == item::root()->id) { return array(); } $bc = array_merge($item->parents()->as_array(), array($item)); for ($i = 0; $i < count($bc) - 1; $i++) { $bc[$i] = new Breadcrumb($bc[$i]->title, $bc[$i]->url("show={$bc[$i + 1]->id}")); } $bc[$i] = new Breadcrumb($item->title, $item->url()); $bc[0]->set_first(); end($bc)->set_last(); return $bc; }
public function preview($type, $theme_name) { $view = new View("admin_themes_preview.html"); $theme_name = preg_replace("/[^\\w]/", "", $theme_name); $view->info = new ArrayObject(parse_ini_file(THEMEPATH . "{$theme_name}/theme.info"), ArrayObject::ARRAY_AS_PROPS); $view->theme_name = $theme_name; $view->type = $type; if ($type == "admin") { $view->url = url::site("admin?theme={$theme_name}"); } else { $view->url = item::root()->url("theme={$theme_name}"); } print $view; }
public function auth_html() { access::verify_csrf(); list($valid, $form) = $this->_auth("login/auth_html"); if ($valid) { url::redirect(item::root()->abs_url()); } else { $view = new Theme_View("page.html", "other", "login"); $view->page_title = t("Log in to Gallery"); $view->content = new View("login_ajax.html"); $view->content->form = $form; print $view; } }