本文整理汇总了PHP中module类的典型用法代码示例。如果您正苦于以下问题:PHP module类的具体用法?PHP module怎么用?PHP module使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了module类的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: save
function save($album_id)
{
access::verify_csrf();
$album = ORM::factory("item", $album_id);
access::required("edit", $album);
if (Input::instance()->post("save")) {
$titles = Input::instance()->post("title");
$descriptions = Input::instance()->post("description");
$filenames = Input::instance()->post("filename");
$internetaddresses = Input::instance()->post("internetaddress");
$tags = Input::instance()->post("tags");
$enable_tags = module::is_active("tag");
foreach (array_keys($titles) as $id) {
$item = ORM::factory("item", $id);
if ($item->loaded() && access::can("edit", $item)) {
$item->title = $titles[$id];
$item->description = $descriptions[$id];
$item->name = $filenames[$id];
$item->slug = $internetaddresses[$id];
$item->save();
if ($enable_tags) {
tag::clear_all($item);
foreach (explode(",", $tags[$id]) as $tag_name) {
if ($tag_name) {
tag::add($item, trim($tag_name));
}
}
tag::compact();
}
}
}
message::success(t("Captions saved"));
}
url::redirect($album->abs_url());
}
示例3: get
static function get($block_id, $theme)
{
$block = "";
switch ($block_id) {
case "random_image":
// The random_query approach is flawed and doesn't always return a
// result when there actually is one. Retry a *few* times.
// @todo Consider another fallback if further optimizations are necessary.
$image_count = module::get_var("image_block", "image_count");
$items = array();
for ($i = 0; $i < $image_count; $i++) {
$attempts = 0;
$item = null;
do {
$item = item::random_query()->where("type", "!=", "album")->find_all(1)->current();
} while (!$item && $attempts++ < 3);
if ($item) {
$items[] = $item;
}
}
if ($items) {
$block = new Block();
$block->css_id = "g-image-block";
$block->title = t2("Random image", "Random images", $image_count);
$block->content = new View("image_block_block.html");
$block->content->items = $items;
}
break;
}
return $block;
}
示例4: uninstall
static function uninstall()
{
// Delete the face mapping table before uninstalling.
$db = Database::instance();
$db->query("DROP TABLE IF EXISTS {picasa_faces};");
module::delete("picasa_faces");
}
示例5: _dump_database
private function _dump_database()
{
// We now have a clean install with just the packages that we want. Make sure that the
// database is clean too.
$i = 1;
foreach (array("dashboard_sidebar", "dashboard_center", "site_sidebar") as $key) {
$blocks = array();
foreach (unserialize(module::get_var("gallery", "blocks_{$key}")) as $rnd => $value) {
$blocks[++$i] = $value;
}
module::set_var("gallery", "blocks_{$key}", serialize($blocks));
}
Database::instance()->query("TRUNCATE {caches}");
Database::instance()->query("TRUNCATE {sessions}");
Database::instance()->query("TRUNCATE {logs}");
db::build()->update("users")->set(array("password" => ""))->where("id", "in", array(1, 2))->execute();
$dbconfig = Kohana::config('database.default');
$conn = $dbconfig["connection"];
$sql_file = DOCROOT . "installer/install.sql";
if (!is_writable($sql_file)) {
print "{$sql_file} is not writeable";
return;
}
$command = sprintf("mysqldump --compact --skip-extended-insert --add-drop-table %s %s %s %s > {$sql_file}", escapeshellarg("-h{$conn['host']}"), escapeshellarg("-u{$conn['user']}"), $conn['pass'] ? escapeshellarg("-p{$conn['pass']}") : "", escapeshellarg($conn['database']));
exec($command, $output, $status);
if ($status) {
print "<pre>";
print "{$command}\n";
print "Failed to dump database\n";
print implode("\n", $output);
return;
}
// Post-process the sql file
$buf = "";
$root = ORM::factory("item", 1);
$root_created_timestamp = $root->created;
$root_updated_timestamp = $root->updated;
$table_name = "";
foreach (file($sql_file) as $line) {
// Prefix tables
$line = preg_replace("/(CREATE TABLE|IF EXISTS|INSERT INTO) `{$dbconfig['table_prefix']}(\\w+)`/", "\\1 {\\2}", $line);
if (preg_match("/CREATE TABLE {(\\w+)}/", $line, $matches)) {
$table_name = $matches[1];
}
// Normalize dates
$line = preg_replace("/,{$root_created_timestamp},/", ",UNIX_TIMESTAMP(),", $line);
$line = preg_replace("/,{$root_updated_timestamp},/", ",UNIX_TIMESTAMP(),", $line);
// Remove ENGINE= specifications execpt for search records, it always needs to be MyISAM
if ($table_name != "search_records") {
$line = preg_replace("/ENGINE=\\S+ /", "", $line);
}
// Null out ids in the vars table since it's an auto_increment table and this will result in
// more stable values so we'll have less churn in install.sql.
$line = preg_replace("/^INSERT INTO {vars} VALUES \\(\\d+/", "INSERT INTO {vars} VALUES (NULL", $line);
$buf .= $line;
}
$fd = fopen($sql_file, "wb");
fwrite($fd, $buf);
fclose($fd);
}
示例6: photo_menu
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"));
}
}
示例7: _show
private function _show($album)
{
$page_size = module::get_var("gallery", "page_size", 9);
$page = Input::instance()->get("page", "1");
$album_defn = unserialize(module::get_var("dynamic", $album));
$children_count = $album_defn->limit;
if (empty($children_count)) {
$children_count = ORM::factory("item")->viewable()->where("type", "!=", "album")->count_all();
}
$offset = ($page - 1) * $page_size;
$max_pages = ceil($children_count / $page_size);
// Make sure that the page references a valid offset
if ($page < 1 || $children_count && $page > ceil($children_count / $page_size)) {
throw new Kohana_404_Exception();
}
$template = new Theme_View("page.html", "collection", "dynamic");
$template->set_global("page", $page);
$template->set_global("page_size", $page_size);
$template->set_global("max_pages", $max_pages);
$template->set_global("children", ORM::factory("item")->viewable()->where("type", "!=", "album")->order_by($album_defn->key_field, "DESC")->find_all($page_size, $offset));
$template->set_global("children_count", $children_count);
$template->content = new View("dynamic.html");
$template->content->title = t($album_defn->title);
print $template;
}
示例8: install
static function install()
{
$db = Database::instance();
$db->query("CREATE TABLE IF NOT EXISTS {item_links} (\n `id` int(9) NOT NULL auto_increment,\n `item_id` int(9) NOT NULL,\n `url` text default NULL,\n PRIMARY KEY (`id`),\n KEY(`item_id`, `id`))\n DEFAULT CHARSET=utf8;");
// Set the module's version number.
module::set_version("item_links", 1);
}
示例9: admin
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")));
}
}
示例10: googlemap
public function googlemap($fullsize)
{
// Display all tags with GPS coordinates on a google map.
// Generate a list of GPS coordinates.
$tagsGPS = ORM::factory("tags_gps")->find_all();
// Set up and display the actual page.
// If fullsize is true, allow the map to take up the entire browser window,
// if not, then display the map in the gallery theme.
if ($fullsize == true) {
$view = new View("tagsmap_googlemap.html");
$view->map_fullsize = true;
// Load in module preferences.
$view->tags_gps = $tagsGPS;
$view->google_map_key = module::get_var("tagsmap", "googlemap_api_key");
$view->google_map_latitude = module::get_var("tagsmap", "googlemap_latitude");
$view->google_map_longitude = module::get_var("tagsmap", "googlemap_longitude");
$view->google_map_zoom = module::get_var("tagsmap", "googlemap_zoom");
$view->google_map_type = module::get_var("tagsmap", "googlemap_type");
print $view;
} else {
$template = new Theme_View("page.html", "TagsMap");
$template->page_title = t("Gallery :: Map");
$template->content = new View("tagsmap_googlemap.html");
// Load in module preferences.
$template->content->tags_gps = $tagsGPS;
$template->content->google_map_key = module::get_var("tagsmap", "googlemap_api_key");
$template->content->google_map_latitude = module::get_var("tagsmap", "googlemap_latitude");
$template->content->google_map_longitude = module::get_var("tagsmap", "googlemap_longitude");
$template->content->google_map_zoom = module::get_var("tagsmap", "googlemap_zoom");
$template->content->google_map_type = module::get_var("tagsmap", "googlemap_type");
print $template;
}
}
示例11: _update
/**
* @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()));
}
}
示例12: uninstall
static function uninstall()
{
$db = Database::instance();
$sql = "SELECT `item_id` FROM {comments}";
module::event("item_related_update_batch", $sql);
$db->query("DROP TABLE IF EXISTS {comments};");
}
示例13: api_key
static function api_key($api_key = null)
{
if ($api_key !== null) {
module::set_var("gallery", "l10n_client_key", $api_key);
}
return module::get_var("gallery", "l10n_client_key", "");
}
示例14: create
/**
* Create a new album.
* @param integer $parent_id id of parent album
* @param string $name the name of this new album (it will become the directory name on disk)
* @param integer $title the title of the new album
* @param string $description (optional) the longer description of this album
* @return Item_Model
*/
static function create($parent, $name, $title, $description = null, $owner_id = null)
{
if (!$parent->loaded || !$parent->is_album()) {
throw new Exception("@todo INVALID_PARENT");
}
if (strpos($name, "/")) {
throw new Exception("@todo NAME_CANNOT_CONTAIN_SLASH");
}
// We don't allow trailing periods as a security measure
// ref: http://dev.kohanaphp.com/issues/684
if (rtrim($name, ".") != $name) {
throw new Exception("@todo NAME_CANNOT_END_IN_PERIOD");
}
$album = ORM::factory("item");
$album->type = "album";
$album->title = $title;
$album->description = $description;
$album->name = $name;
$album->owner_id = $owner_id;
$album->thumb_dirty = 1;
$album->resize_dirty = 1;
$album->rand_key = (double) mt_rand() / (double) mt_getrandmax();
$album->sort_column = "weight";
$album->sort_order = "ASC";
while (ORM::factory("item")->where("parent_id", $parent->id)->where("name", $album->name)->find()->id) {
$album->name = "{$name}-" . rand();
}
$album = $album->add_to_parent($parent);
mkdir($album->file_path());
mkdir(dirname($album->thumb_path()));
mkdir(dirname($album->resize_path()));
module::event("item_created", $album);
return $album;
}
示例15: save
public function save()
{
access::verify_csrf();
$form = theme::get_edit_form_admin();
if ($form->validate()) {
module::set_var("gallery", "page_size", $form->edit_theme->page_size->value);
$thumb_size = $form->edit_theme->thumb_size->value;
$thumb_dirty = false;
if (module::get_var("gallery", "thumb_size") != $thumb_size) {
graphics::remove_rule("gallery", "thumb", "gallery_graphics::resize");
graphics::add_rule("gallery", "thumb", "gallery_graphics::resize", array("width" => $thumb_size, "height" => $thumb_size, "master" => Image::AUTO), 100);
module::set_var("gallery", "thumb_size", $thumb_size);
}
$resize_size = $form->edit_theme->resize_size->value;
$resize_dirty = false;
if (module::get_var("gallery", "resize_size") != $resize_size) {
graphics::remove_rule("gallery", "resize", "gallery_graphics::resize");
graphics::add_rule("gallery", "resize", "gallery_graphics::resize", array("width" => $resize_size, "height" => $resize_size, "master" => Image::AUTO), 100);
module::set_var("gallery", "resize_size", $resize_size);
}
module::set_var("gallery", "header_text", $form->edit_theme->header_text->value);
module::set_var("gallery", "footer_text", $form->edit_theme->footer_text->value);
module::set_var("gallery", "show_credits", $form->edit_theme->show_credits->value);
message::success(t("Updated theme details"));
url::redirect("admin/theme_options");
} else {
$view = new Admin_View("admin.html");
$view->content = $form;
print $view;
}
}