static function get($block_id, $theme)
 {
     $block = "";
     if (!$theme->item()) {
         return;
     }
     switch ($block_id) {
         case "embed_links_dialog":
             // Display dialog buttons in the sidebar.
             $block = new Block();
             $block->css_id = "g-embed-links-sidebar";
             $block->title = t("Link To This Page");
             $block->content = new View("embedlinks_sidebar.html");
             break;
         case "embed_links_album":
             // If the current item is an album and if "In Page" links are enabled then
             //  display links to the current album in the theme sidebar.
             if ($theme->item()->is_album() && module::get_var("embedlinks", "InPageLinks")) {
                 $block = new Block();
                 $block->css_id = "g-embed-links-album-sidebar";
                 $block->title = t("Links");
                 $block->content = new View("embedlinks_album_block.html");
             }
             break;
     }
     return $block;
 }
 public function print_proxy($site_key, $file_id)
 {
     // This function retrieves the full-sized image for fotomoto.
     //   As this function by-passes normal Gallery security, a private
     //   site-key is used to try and prevent people other then fotomoto
     //   from finding the URL.
     // If the site key doesn't match, display a 404 error.
     if ($site_key != module::get_var("fotomotorw", "fotomoto_private_key")) {
         throw new Kohana_404_Exception();
     }
     // Load the photo from the provided id.  If the id# is invalid, display a 404 error.
     $item = ORM::factory("item", $file_id);
     if (!$item->loaded()) {
         throw new Kohana_404_Exception();
     }
     // If the image file doesn't exist for some reason, display a 404 error.
     if (!file_exists($item->file_path())) {
         throw new Kohana_404_Exception();
     }
     // Display the image.
     header("Content-Type: {$item->mime_type}");
     Kohana::close_buffers(false);
     $fd = fopen($item->file_path(), "rb");
     fpassthru($fd);
     fclose($fd);
 }
Example #3
0
 public function index()
 {
     $view = new Admin_View("admin.html");
     $view->page_title = t("Users and groups");
     $view->page_type = "collection";
     $view->page_subtype = "admin_users";
     $view->content = new View("admin_users.html");
     // @todo: add this as a config option
     $page_size = module::get_var("user", "page_size", 10);
     $page = Input::instance()->get("page", "1");
     $builder = db::build();
     $user_count = $builder->from("users")->count_records();
     // Pagination info
     $view->page = $page;
     $view->page_size = $page_size;
     $view->children_count = $user_count;
     $view->max_pages = ceil($view->children_count / $view->page_size);
     $view->content->pager = new Pagination();
     $view->content->pager->initialize(array("query_string" => "page", "total_items" => $user_count, "items_per_page" => $page_size, "style" => "classic"));
     // Make sure that the page references a valid offset
     if ($page < 1) {
         url::redirect(url::merge(array("page" => 1)));
     } else {
         if ($page > $view->content->pager->total_pages) {
             url::redirect(url::merge(array("page" => $view->content->pager->total_pages)));
         }
     }
     // Join our users against the items table so that we can get a count of their items
     // in the same query.
     $view->content->users = ORM::factory("user")->order_by("users.name", "ASC")->find_all($page_size, $view->content->pager->sql_offset);
     $view->content->groups = ORM::factory("group")->order_by("name", "ASC")->find_all();
     print $view;
 }
Example #4
0
 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"));
     }
 }
Example #5
0
 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("blocks_dashboard_sidebar", "blocks_dashboard_center") as $key) {
         $blocks = array();
         foreach (unserialize(module::get_var("gallery", $key)) as $rnd => $value) {
             $blocks[++$i] = $value;
         }
         module::set_var("gallery", $key, serialize($blocks));
     }
     $db = Database::instance();
     $db->query("TRUNCATE {sessions}");
     $db->query("TRUNCATE {logs}");
     $db->query("DELETE FROM {vars} WHERE `module_name` = 'core' AND `name` = '_cache'");
     $db->update("users", array("password" => ""), array("id" => 1));
     $db->update("users", array("password" => ""), array("id" => 2));
     $dbconfig = Kohana::config('database.default');
     $conn = $dbconfig["connection"];
     $pass = $conn["pass"] ? "-p{$conn['pass']}" : "";
     $sql_file = DOCROOT . "installer/install.sql";
     if (!is_writable($sql_file)) {
         print "{$sql_file} is not writeable";
         return;
     }
     $command = "mysqldump --compact --skip-extended-insert --add-drop-table -h{$conn['host']} " . "-u{$conn['user']} {$pass} {$conn['database']} > {$sql_file}";
     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);
         }
         $buf .= $line;
     }
     $fd = fopen($sql_file, "wb");
     fwrite($fd, $buf);
     fclose($fd);
 }
Example #6
0
 private function _get_admin_form()
 {
     $form = new Forge("admin/star/save", "", "post", array("id" => "g-star-admin-form"));
     $form->dropdown("show")->label(t("Default to showing..."))->options(array(0 => "All", 1 => "Starred"))->selected(module::get_var("star", "show"));
     $form->submit("save")->value(t("Save"));
     return $form;
 }
Example #7
0
 public function setup()
 {
     self::$installed_locales = locales::installed();
     self::$default_locale = module::get_var("gallery", "default_locale");
     locales::update_installed(array_keys(locales::available()));
     module::set_var("gallery", "default_locale", "no_NO");
 }
Example #8
0
 public function index()
 {
     // Far from perfection, but at least require view permission for the root album
     $album = ORM::factory("item", 1);
     access::required("view", $album);
     print tag::cloud(module::get_var("tag", "tag_cloud_size", 30));
 }
 static function head($theme)
 {
     $v = $theme->css("photoannotation.css");
     if ($theme->page_subtype == "photo") {
         $v .= $theme->script("jquery.annotate.min.js");
         $noborder = module::get_var("photoannotation", "noborder", false);
         $noclickablehover = module::get_var("photoannotation", "noclickablehover", false);
         $nohover = module::get_var("photoannotation", "nohover", false);
         $bordercolor = "#" . module::get_var("photoannotation", "bordercolor", "000000");
         $v .= "<style type=\"text/css\">\n";
         $v .= ".photoannotation-del-button {\n\n              border:1px solid " . $bordercolor . " !important;\n\n              }\n";
         $v .= ".photoannotation-edit-button {\n\n              border:1px solid " . $bordercolor . " !important;\n\n              }";
         if ($noborder) {
             $border_thickness = "2px";
         } else {
             $border_thickness = "1px";
         }
         if (!$noborder || !$noclickablehover || !$nohover) {
             if (!$noborder) {
                 $v .= ".image-annotate-area {\n\n                border: 1px solid " . $bordercolor . ";\n\n                }\n";
                 $v .= ".image-annotate-area div {\n\n                  border: 1px solid #FFFFFF;\n\n                  }\n";
             }
             if (!$noclickablehover) {
                 $clickablehovercolor = "#" . module::get_var("photoannotation", "clickablehovercolor", "00AD00");
                 $v .= ".image-annotate-area-editable-hover div {\n\n                  border: " . $border_thickness . " solid " . $clickablehovercolor . " !important;\n\n                  }\n";
             }
             if (!$nohover) {
                 $hovercolor = "#" . module::get_var("photoannotation", "hovercolor", "990000");
                 $v .= ".image-annotate-area-hover div {\n\n                  border: " . $border_thickness . " solid " . $hovercolor . " !important;\n\n                  }\n";
             }
         }
         $v .= "</style>\n";
         return $v;
     }
 }
 public function update()
 {
     //Get the ordered list of modules
     $modulerawlist = explode("&", trim($_POST['modulelist'], "&"));
     //Make sure that gallery and user modules are first in the list
     $current_weight = 2;
     $identity_provider = module::get_var("gallery", "identity_provider");
     foreach ($modulerawlist as $row) {
         $currentry = explode("=", $row);
         $currentry = explode(":", $currentry[1]);
         if ($currentry[0] == "gallery") {
             $modulelist[0] = $row;
         } elseif ($currentry[0] == $identity_provider) {
             $modulelist[1] = $row;
         } else {
             $modulelist[$current_weight] = $row;
             $current_weight++;
         }
     }
     ksort($modulelist);
     //Write the correct weight values
     $current_weight = 0;
     foreach ($modulelist as $row) {
         $current_weight++;
         $currentry = explode("=", $row);
         $currentry = explode(":", $currentry[1]);
         db::build()->update("modules")->set("weight", $current_weight)->where("id", "=", $currentry[1])->execute();
     }
     message::success(t("Your settings have been saved."));
     url::redirect("admin/moduleorder");
     print $this->_get_view();
 }
Example #11
0
 static function update_installed($locales)
 {
     // Ensure that the default is included...
     $default = module::get_var("gallery", "default_locale");
     $locales = array_merge($locales, array($default));
     module::set_var("gallery", "installed_locales", join("|", $locales));
 }
Example #12
0
 public function __construct()
 {
     $this->m_trackerUrl = module::get_var("piwik", "installation_url", null);
     $this->m_tokenAuth = module::get_var("piwik", "token_auth", null);
     if (empty($this->m_trackerUrl) || empty($this->m_tokenAuth)) {
         $this->m_errorMessage = t("Incomplete connection settings. Cannot connect to the Piwik server");
         $this->m_bInit = false;
         return;
     }
     //TODO add an option to choice here
     /* Make encrypted http connections */
     $this->m_trackerUrl = substr_replace($this->m_trackerUrl, "https", 0, 4);
     /* Build basic REST connection string */
     if (substr($this->m_trackerUrl, -1) != "/") {
         $this->m_trackerUrl .= "/";
     }
     $this->m_trackerUrl .= "index.php?module=API&format=php&token_auth=" . $this->m_tokenAuth;
     /* Populate the sites list. This is cached once, here. */
     $aIdList = $this->getAllSiteId();
     if (!is_array($aIdList)) {
         $this->m_bInit = false;
         return;
     }
     foreach ($aIdList as $id) {
         $idSite = $this->getSiteFromId($id);
         if ($idSite === false) {
             $this->m_bInit = false;
             $this->m_aSites = array();
             return;
         }
         $this->m_aSites[$id] = $idSite;
     }
     $this->m_bInit = true;
 }
Example #13
0
 public function children()
 {
     $path = $this->input->get("path");
     $tree = new View("server_add_tree.html");
     $tree->files = array();
     $tree->parents = array();
     // Make a tree with the parents back up to the authorized path, and all the children under the
     // current path.
     if (server_add::is_valid_path($path)) {
         $tree->parents[] = $path;
         while (server_add::is_valid_path(dirname($tree->parents[0]))) {
             array_unshift($tree->parents, dirname($tree->parents[0]));
         }
         foreach (glob("{$path}/*") as $file) {
             if (!is_readable($file)) {
                 continue;
             }
             if (!is_dir($file)) {
                 $ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
                 if (!in_array($ext, array("gif", "jpeg", "jpg", "png", "flv", "mp4"))) {
                     continue;
                 }
             }
             $tree->files[] = $file;
         }
     } else {
         // Missing or invalid path; print out the list of authorized path
         $paths = unserialize(module::get_var("server_add", "authorized_paths"));
         foreach (array_keys($paths) as $path) {
             $tree->files[] = $path;
         }
     }
     print $tree;
 }
 /**
  * Rotate an image.  Valid options are degrees
  *
  * @param string     $input_file
  * @param string     $output_file
  * @param array      $options
  */
 static function rotate($input_file, $output_file, $options)
 {
     graphics::init_toolkit();
     module::event("graphics_rotate", $input_file, $output_file, $options);
     // BEGIN mod to original function
     $image_info = getimagesize($input_file);
     // [0]=w, [1]=h, [2]=type (1=GIF, 2=JPG, 3=PNG)
     if (module::get_var("image_optimizer", "rotate_jpg") || $image_info[2] == 2) {
         // rotate_jpg enabled, the file is a jpg.  get args
         $path = module::get_var("image_optimizer", "path_jpg");
         $exec_args = " -rotate ";
         $exec_args .= $options["degrees"] > 0 ? $options["degrees"] : $options["degrees"] + 360;
         $exec_args .= " -copy all -optimize -outfile ";
         // run it - from input_file to tmp_file
         $tmp_file = image_optimizer::make_temp_name($output_file);
         exec(escapeshellcmd($path) . $exec_args . escapeshellarg($tmp_file) . " " . escapeshellarg($input_file), $exec_output, $exec_status);
         if ($exec_status || !filesize($tmp_file)) {
             // either a blank/nonexistant file or an error - log an error and pass to normal function
             Kohana_Log::add("error", "image_optimizer rotation failed on " . $output_file);
             unlink($tmp_file);
         } else {
             // worked - move temp to output
             rename($tmp_file, $output_file);
             $status = true;
         }
     }
     if (!$status) {
         // we got here if we weren't supposed to use jpegtran or if jpegtran failed
         // END mod to original function
         Image::factory($input_file)->quality(module::get_var("gallery", "image_quality"))->rotate($options["degrees"])->save($output_file);
         // BEGIN mod to original function
     }
     // END mod to original function
     module::event("graphics_rotate_completed", $input_file, $output_file, $options);
 }
Example #15
0
 static function required($perm_name, $item)
 {
     // Original code from the required function in modules/gallery/helpers/access.php.
     if (!access::can($perm_name, $item)) {
         if ($perm_name == "view") {
             // Treat as if the item didn't exist, don't leak any information.
             throw new Kohana_404_Exception();
         } else {
             access::forbidden();
         }
         // Begin rWatcher modifications.
         //   Throw a 404 error when a user attempts to access a protected item,
         //   unless the password has been provided, or the user is the item's owner.
     } elseif (module::get_var("albumpassword", "hideonly") == false) {
         $item_protected = ORM::factory("albumpassword_idcache")->where("item_id", "=", $item->id)->order_by("cache_id")->find_all();
         if (count($item_protected) > 0) {
             $existing_password = ORM::factory("items_albumpassword")->where("id", "=", $item_protected[0]->password_id)->find();
             if ($existing_password->loaded()) {
                 if (cookie::get("g3_albumpassword") != $existing_password->password && identity::active_user()->id != $item->owner_id && !identity::active_user()->admin) {
                     throw new Kohana_404_Exception();
                 }
             }
         }
     }
 }
Example #16
0
 /**
  * Return the path to an executable version of the named binary, or null.
  * The paths are traversed in the following order:
  *   1. $priority_path (if specified)
  *   2. Gallery's own bin directory (DOCROOT . "bin")
  *   3. PATH environment variable
  *   4. extra_binary_paths Gallery variable (if specified)
  * In addition, if the file is found inside Gallery's bin directory but
  * it's not executable, we try to change its permissions to 0755.
  *
  * @param  string $binary
  * @param  string $priority_path (optional)
  * @return string path to binary if found; null if not found
  */
 static function find_binary($binary, $priority_path = null)
 {
     $bin_path = DOCROOT . "bin";
     if ($priority_path) {
         $paths = array($priority_path, $bin_path);
     } else {
         $paths = array($bin_path);
     }
     $paths = array_merge($paths, explode(":", getenv("PATH")), explode(":", module::get_var("gallery", "extra_binary_paths")));
     foreach ($paths as $path) {
         $path = rtrim($path, "/");
         $candidate = "{$path}/{$binary}";
         // @suppress errors below to avoid open_basedir issues
         if (@file_exists($candidate)) {
             if (!@is_executable($candidate) && substr_compare($bin_path, $candidate, 0, strlen($bin_path)) == 0) {
                 // Binary isn't executable but is in Gallery's bin directory - try fixing permissions.
                 @chmod($candidate, 0755);
             }
             if (@is_executable($candidate)) {
                 return $candidate;
             }
         }
     }
     return null;
 }
 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"));
     }
 }
 static function get($block_id, $theme)
 {
     $block = "";
     switch ($block_id) {
         case "embed_links_dialog":
             // If displaying links in a dialog box is enabled then
             //   insert buttons into the bottom of the side bar
             //   to open up the dialog window.
             if (module::get_var("embedlinks", "DialogLinks") && $theme->item()) {
                 $block = new Block();
                 $block->css_id = "g-embed-links-sidebar";
                 $block->title = t("Link To This Page");
                 $block->content = new View("embedlinks_sidebar.html");
             }
             break;
         case "embed_links_album":
             // If the current item is an album and if "In Page" links are enabled then
             //  display links to the current album in the theme sidebar.
             if ($theme->item()->is_album() && module::get_var("embedlinks", "InPageLinks")) {
                 $block = new Block();
                 $block->css_id = "g-embed-links-album-sidebar";
                 $block->title = t("Links");
                 $block->content = new View("embedlinks_album_block.html");
             }
             break;
     }
     return $block;
 }
Example #19
0
 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;
 }
Example #20
0
 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;
     }
 }
Example #21
0
 public function show($tag_id)
 {
     $tag = ORM::factory("tag", $tag_id);
     $page_size = module::get_var("gallery", "page_size", 9);
     $page = (int) Input::instance()->get("page", "1");
     $children_count = $tag->items_count();
     $offset = ($page - 1) * $page_size;
     $max_pages = max(ceil($children_count / $page_size), 1);
     // Make sure that the page references a valid offset
     if ($page < 1) {
         url::redirect($album->abs_url());
     } else {
         if ($page > $max_pages) {
             url::redirect($album->abs_url("page={$max_pages}"));
         }
     }
     $template = new Theme_View("page.html", "collection", "tag");
     $template->set_global("page", $page);
     $template->set_global("max_pages", $max_pages);
     $template->set_global("page_size", $page_size);
     $template->set_global("tag", $tag);
     $template->set_global("children", $tag->items($page_size, $offset));
     $template->set_global("children_count", $children_count);
     $template->content = new View("dynamic.html");
     $template->content->title = $tag->name;
     print $template;
 }
Example #22
0
 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", "");
 }
Example #23
0
 static function upgrade($version)
 {
     $db = Database::instance();
     if ($version == 1) {
         $db->query("ALTER TABLE {comments} CHANGE `state` `state` varchar(15) default 'unpublished'");
         module::set_version("comment", $version = 2);
     }
     if ($version == 2) {
         module::set_var("comment", "access_permissions", "everybody");
         module::set_version("comment", $version = 3);
     }
     if ($version == 3) {
         // 40 bytes for server_remote_addr is enough to swallow the longest
         // representation of an IPv6 addy.
         //
         // 255 bytes for server_remote_host is enough to swallow the longest
         // legit DNS entry, with a few bytes to spare.
         $db->query("ALTER TABLE {comments} CHANGE `server_remote_addr` `server_remote_addr` varchar(40)");
         $db->query("ALTER TABLE {comments} CHANGE `server_remote_host` `server_remote_host` varchar(255)");
         module::set_version("comment", $version = 4);
     }
     if ($version == 4) {
         module::set_var("comment", "rss_visible", "all");
         module::set_version("comment", $version = 5);
     }
     // In version 5 we accidentally set the installer variable to rss_available when it should
     // have been rss_visible.  Migrate it over now, if necessary.
     if ($version == 5) {
         if (!module::get_var("comment", "rss_visible")) {
             module::set_var("comment", "rss_visible", module::get_var("comment", "rss_available"));
         }
         module::clear_var("comment", "rss_available");
         module::set_version("comment", $version = 6);
     }
 }
Example #24
0
 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;
     }
 }
Example #25
0
 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);
 }
Example #26
0
 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")));
     }
 }
Example #27
0
 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;
 }
Example #28
0
 function start($id)
 {
     access::verify_csrf();
     $paths = unserialize(module::get_var("server_add", "authorized_paths"));
     $input_files = $this->input->post("path");
     $files = array();
     $total_count = 0;
     foreach (array_keys($paths) as $valid_path) {
         $path_length = strlen($valid_path);
         foreach ($input_files as $key => $path) {
             if ($valid_path != $path && strpos($path, $valid_path) === 0) {
                 $relative_path = substr(dirname($path), $path_length);
                 $name = basename($path);
                 $files[$valid_path][] = array("path" => $relative_path, "parent_id" => $id, "name" => basename($path), "type" => is_dir($path) ? "album" : "file");
                 $total_count++;
                 unset($input_files[$key]);
             }
         }
     }
     if ($total_count == 0) {
         print json_encode(array("result" => "success", "url" => "", "task" => array("id" => -1, "done" => 1, "percent_complete" => 100, "status" => t("No Eligible files, import cancelled"))));
         return;
     }
     $task_def = Task_Definition::factory()->callback("server_add_task::add_from_server")->description(t("Add photos or movies from the local server"))->name(t("Add from server"));
     $task = task::create($task_def, array("item_id" => $id, "next_path" => 0, "files" => $files, "counter" => 0, "position" => 0, "total" => $total_count));
     batch::start();
     print json_encode(array("result" => "started", "url" => url::site("server_add/add_photo/{$task->id}?csrf=" . access::csrf_token()), "task" => array("id" => $task->id, "percent_complete" => $task->percent_complete, "status" => $task->status, "done" => $task->done)));
 }
Example #29
0
 private function _get_admin_form()
 {
     $form = new Forge("admin/hide/save", "", "post", array("id" => "g-hide-admin-form"));
     $form->dropdown("access_permissions")->label(t("Who can see hidden items?"))->options(hide::get_groups_as_dropdown_options())->selected(module::get_var("hide", "access_permissions"));
     $form->submit("save")->value(t("Save"));
     return $form;
 }
 static function get($block_id, $theme)
 {
     $block = "";
     switch ($block_id) {
         case "tagsinalbum":
             if ($theme->item && $theme->item->is_album()) {
                 $item = $theme->item;
                 // Create an ORM query for finding one instance of each tag
                 //  used by children in the current album.
                 $tags_model = ORM::factory("tag")->join("items_tags", "items_tags.tag_id", "tags.id")->join("items", "items.id", "items_tags.item_id", "LEFT")->where("items.parent_id", "=", $item->id)->order_by("tags.name", "ASC")->group_by("tags.id");
                 // Limit $all_tags to the first X tags if max_display_tags is set,
                 //  else populate it with all tags used by this album's children.
                 $all_tags = "";
                 if (module::get_var("tagsinalbum", "max_display_tags") > 0) {
                     $all_tags = $tags_model->find_all(module::get_var("tagsinalbum", "max_display_tags"));
                 } else {
                     $all_tags = $tags_model->find_all();
                 }
                 // If this album has children that are tagged, display those tags.
                 if (count($all_tags) > 0) {
                     $block = new Block();
                     $block->css_id = "g-tags-in-album-block";
                     $block->title = t("In this album");
                     $block->content = new View("tagsinalbum_sidebar.html");
                     $block->content->all_tags = $all_tags;
                 }
             }
             break;
     }
     return $block;
 }