Example #1
0
 public function choose($toolkit_id)
 {
     access::verify_csrf();
     if ($toolkit_id != module::get_var("gallery", "graphics_toolkit")) {
         $tk = graphics::detect_toolkits();
         module::set_var("gallery", "graphics_toolkit", $toolkit_id);
         module::set_var("gallery", "graphics_toolkit_path", $tk->{$toolkit_id}->dir);
         site_status::clear("missing_graphics_toolkit");
         $msg = t("Changed graphics toolkit to: %toolkit", array("toolkit" => $tk->{$toolkit_id}->name));
         message::success($msg);
         log::success("graphics", $msg);
     }
     url::redirect("admin/graphics");
 }
Example #2
0
 public function choose($toolkit)
 {
     access::verify_csrf();
     if ($toolkit != module::get_var("gallery", "graphics_toolkit")) {
         module::set_var("gallery", "graphics_toolkit", $toolkit);
         $toolkit_info = graphics::detect_toolkits();
         if ($toolkit == "graphicsmagick" || $toolkit == "imagemagick") {
             module::set_var("gallery", "graphics_toolkit_path", $toolkit_info[$toolkit]);
         }
         site_status::clear("missing_graphics_toolkit");
         message::success(t("Updated Graphics Toolkit"));
         log::success("graphics", t("Changed graphics toolkit to: %toolkit", array("toolkit" => $toolkit)));
     }
     url::redirect("admin/graphics");
 }
Example #3
0
 /**
  * This needs to be run once, after the initial install, to choose a graphics toolkit.
  */
 static function choose_default_toolkit()
 {
     // Detect a graphics toolkit
     $toolkits = graphics::detect_toolkits();
     foreach (array("imagemagick", "graphicsmagick", "gd") as $tk) {
         if ($toolkits[$tk]) {
             module::set_var("gallery", "graphics_toolkit", $tk);
             module::set_var("gallery", "graphics_toolkit_path", $tk == "gd" ? "" : $toolkits[$tk]);
             break;
         }
     }
     if (!module::get_var("gallery", "graphics_toolkit")) {
         site_status::warning(t("Graphics toolkit missing!  Please <a href=\"%url\">choose a toolkit</a>", array("url" => url::site("admin/graphics"))), "missing_graphics_toolkit");
     }
 }
 public function makepdf($page_type, $container_type, $id)
 {
     /**
      * This part is largely copied from downloadalbum,
      * but does have some additions (headertext/headerlink)
      */
     switch ($container_type) {
         case "album":
             $container = ORM::factory("item", $id);
             if (!$container->is_album()) {
                 throw new Kohana_Exception('container is not an album: ' . $container->relative_path());
             }
             $pdfname = empty($container->name) ? 'Gallery.pdf' : $container->name . '.pdf';
             $headerText = $container->title;
             $headerLink = $container->abs_url();
             break;
         case "tag":
             // @todo: if the module is not installed, it crash
             $container = ORM::factory("tag", $id);
             if (is_null($container->name)) {
                 throw new Kohana_Exception('container is not a tag: ' . $id);
             }
             $pdfname = $container->name . '.pdf';
             $headerText = $container->name;
             //$headerLink = $container->abs_url();
             $headerLink = url::abs_site("tag/{$container->id}/" . urlencode($container->name));
             break;
         default:
             throw new Kohana_Exception('unhandled container type: ' . $container_type);
     }
     $files = $this->getFilesList($container);
     /**
      * Configure PDF file.  These are all of the parameters that are used to
      * format the proof sheet.  If you'd like to tweak the formatting, here's
      * where to do it.
      */
     switch ($page_type) {
         case "ltr":
             // Setup for LTR 8.5" x 11" paper (215.9mm x 279.4mm)
             $cfg = array('pageW' => 215.9, 'pageH' => 279.4, 'imageNumW' => 5, 'imageNumH' => 5, 'imageSizeW' => 36, 'imageSizeH' => 36, 'marginL' => 10, 'marginR' => 10, 'marginT' => 21, 'marginB' => 20, 'headerSpace' => 2, 'footerSpace' => 2, 'captionSpace' => 1, 'headerFont' => array('name' => 'Arial', 'size' => 14, 'style' => 'B', 'posn' => 'L', 'r' => 0, 'g' => 0, 'b' => 0), 'footerFont' => array('name' => 'Arial', 'size' => 12, 'style' => 'B', 'posn' => 'R', 'r' => 0, 'g' => 0, 'b' => 0), 'captionFont' => array('name' => 'Arial', 'size' => 8, 'style' => 'U', 'posn' => 'C', 'r' => 0, 'g' => 0, 'b' => 255));
             break;
         case "a4":
             // Setup for A4 210mm x 297mm paper (8.27" x 11.69")
             $cfg = array('pageW' => 210, 'pageH' => 297, 'imageNumW' => 5, 'imageNumH' => 6, 'imageSizeW' => 36, 'imageSizeH' => 36, 'marginL' => 8, 'marginR' => 8, 'marginT' => 19, 'marginB' => 18, 'headerSpace' => 2, 'footerSpace' => 2, 'captionSpace' => 1, 'headerFont' => array('name' => 'Arial', 'size' => 14, 'style' => 'B', 'posn' => 'L', 'r' => 0, 'g' => 0, 'b' => 0), 'footerFont' => array('name' => 'Arial', 'size' => 12, 'style' => 'B', 'posn' => 'R', 'r' => 0, 'g' => 0, 'b' => 0), 'captionFont' => array('name' => 'Arial', 'size' => 8, 'style' => 'U', 'posn' => 'C', 'r' => 0, 'g' => 0, 'b' => 255));
             break;
         default:
             throw new Kohana_Exception('unhandled page type: ' . $page_type);
     }
     // Here are some other parameters that need defining
     $cfg['footerTextPage'] = 'Page ';
     // Note that this text isn't autofixed by translate module
     $cfg['footerTextSlash'] = ' / ';
     $cfg['headerLinkIconPath'] = MODPATH . 'proofsheet/images/ico-link.png';
     $cfgImageMissing['iconPath'] = MODPATH . 'proofsheet/images/image_missing.png';
     $cfgImageMissing['iconType'] = 'PNG';
     // PNG or JPG is most robust, GIF okay only if GD is installed
     $pt2mm = 25.4 / 72;
     // 25.4mm=1in=72pt
     // Derive a bunch more parameters.  These are all dependent on the above stuff.
     $cfg['headerH'] = $pt2mm * $cfg['headerFont']['size'];
     $cfg['footerH'] = $pt2mm * $cfg['footerFont']['size'];
     $cfg['captionH'] = $pt2mm * $cfg['captionFont']['size'];
     $cfg['imageSpaceW'] = ($cfg['pageW'] - $cfg['marginL'] - $cfg['marginR'] - $cfg['imageNumW'] * $cfg['imageSizeW']) / ($cfg['imageNumW'] - 1);
     $cfg['imageSpaceH'] = ($cfg['pageH'] - $cfg['marginT'] - $cfg['marginB'] - $cfg['imageNumH'] * $cfg['imageSizeH'] - $cfg['captionH'] - $cfg['captionSpace']) / ($cfg['imageNumH'] - 1);
     $linkInfo = getimagesize($cfg['headerLinkIconPath']);
     $cfg['headerLinkH'] = $cfg['headerH'];
     // I'm defining this to be the same as the text, but you can change it here.
     $cfg['headerLinkW'] = $linkInfo[0] / $linkInfo[1] * $cfg['headerLinkH'];
     $cfg['headerW'] = $cfg['pageW'] - $cfg['marginL'] - $cfg['marginR'] - $cfg['headerLinkW'] - $cfg['headerSpace'];
     $cfg['footerW'] = $cfg['pageW'] - $cfg['marginL'] - $cfg['marginR'];
     $cfg['captionW'] = $cfg['imageSizeW'];
     // I'm defining this to be the same as the image, but you can change it here.
     $cfg['headerX'] = $cfg['marginL'];
     $cfg['headerLinkX'] = $cfg['marginL'] + $cfg['headerW'];
     $cfg['footerX'] = $cfg['marginL'];
     $cfg['headerY'] = $cfg['marginT'] - $cfg['headerH'] - $cfg['headerSpace'];
     $cfg['headerLinkY'] = $cfg['marginT'] - $cfg['headerLinkH'] - $cfg['headerSpace'];
     $cfg['footerY'] = $cfg['pageH'] - $cfg['marginB'] + $cfg['footerSpace'];
     $cfg['imageNum'] = $cfg['imageNumW'] * $cfg['imageNumH'];
     $cfgImageMissing['iconInfo'] = getimagesize($cfgImageMissing['iconPath']);
     $cfgImageMissing['GDflag'] = graphics::detect_toolkits()->gd->installed;
     // FPDF uses GD to convert GIFs
     /**
      * Initialize and build PDF... the main routine.  Note that almost all of the
      * useful configuration parameters are already defined above.
      */
     // Initialize PDF, disable automatic margins and page breaks
     $pdf = new proofsheet_PDF('P', 'mm', array($cfg['pageW'], $cfg['pageH']));
     $pdf->SetMargins(0, 0);
     $pdf->SetAutoPageBreak(0);
     // Build the PDF
     $numpages = floor(count($files) / $cfg['imageNum']) + 1;
     $i = 0;
     foreach ($files as $f_path => $f_info) {
         // Initialize new pages, add header and footer
         if ($i % $cfg['imageNum'] == 0) {
             $pdf->AddPage();
             $pdf->printText($headerText, $cfg['headerFont'], $cfg['headerX'], $cfg['headerY'], $cfg['headerW'], $cfg['headerH']);
             $pdf->printImage($cfg['headerLinkIconPath'], $cfg['headerLinkX'], $cfg['headerLinkY'], $cfg['headerLinkW'], $cfg['headerLinkH'], $headerLink, $cfgImageMissing);
             $footerText = $cfg['footerTextPage'] . strval(floor($i / $cfg['imageNum']) + 1) . $cfg['footerTextSlash'] . strval($numpages);
             $pdf->printText($footerText, $cfg['footerFont'], $cfg['footerX'], $cfg['footerY'], $cfg['footerW'], $cfg['footerH']);
         }
         // Add thumbnail and caption
         $x = $cfg['marginL'] + ($cfg['imageSizeW'] + $cfg['imageSpaceW']) * ($i % $cfg['imageNumW']);
         $y = $cfg['marginT'] + ($cfg['imageSizeH'] + $cfg['imageSpaceH']) * (floor($i / $cfg['imageNumW']) % $cfg['imageNumH']);
         $pdf->printImage($f_path, $x, $y, $cfg['imageSizeW'], $cfg['imageSizeH'], null, $cfgImageMissing);
         $pdf->printText($f_info['name'], $cfg['captionFont'], $x, $y + $cfg['imageSizeH'] + $cfg['captionSpace'], $cfg['captionW'], $cfg['captionH'], $f_info['url']);
         // Increment index and loop
         $i++;
     }
     /**
      * Output the PDF file.  I wrote it in two versions (one should always be commented out).
      */
     // Using a method similar to downloadalbum
     $pdfstring = $pdf->Output('', 'S');
     $this->prepareOutput();
     $this->sendHeaders($pdfname, strlen($pdfstring));
     echo $pdfstring;
     // Using FPDF directly
     //$pdf->Output($pdfname,'I');
 }
 static function install()
 {
     $db = Database::instance();
     $version = 0;
     try {
         $version = module::get_version("core");
     } catch (Exception $e) {
         if ($e->getCode() != E_DATABASE_ERROR) {
             Kohana::log("error", $e);
             throw $e;
         }
     }
     if ($version == 0) {
         $db->query("CREATE TABLE `access_caches` (\n                   `id` int(9) NOT NULL auto_increment,\n                   `item_id` int(9),\n                   PRIMARY KEY (`id`))\n                 ENGINE=InnoDB DEFAULT CHARSET=utf8;");
         $db->query("CREATE TABLE `access_intents` (\n                   `id` int(9) NOT NULL auto_increment,\n                   `item_id` int(9),\n                   PRIMARY KEY (`id`))\n                 ENGINE=InnoDB DEFAULT CHARSET=utf8;");
         $db->query("CREATE TABLE `graphics_rules` (\n                   `id` int(9) NOT NULL auto_increment,\n                   `priority` int(9) NOT NULL,\n                   `module_name` varchar(64) NOT NULL,\n                   `target`  varchar(32) NOT NULL,\n                   `operation` varchar(64) NOT NULL,\n                   `args` varchar(255) default NULL,\n                   PRIMARY KEY (`id`))\n                 ENGINE=InnoDB DEFAULT CHARSET=utf8;");
         $db->query("CREATE TABLE `items` (\n                   `album_cover_item_id` int(9) default NULL,\n                   `created` int(9) default NULL,\n                   `description` varchar(255) default NULL,\n                   `height` int(9) default NULL,\n                   `id` int(9) NOT NULL auto_increment,\n                   `left` int(9) NOT NULL,\n                   `level` int(9) NOT NULL,\n                   `mime_type` varchar(64) default NULL,\n                   `name` varchar(255) default NULL,\n                   `owner_id` int(9) default NULL,\n                   `parent_id` int(9) NOT NULL,\n                   `resize_height` int(9) default NULL,\n                   `resize_width` int(9) default NULL,\n                   `resize_dirty` boolean default 1,\n                   `right` int(9) NOT NULL,\n                   `thumb_height` int(9) default NULL,\n                   `thumb_width` int(9) default NULL,\n                   `thumb_dirty` boolean default 1,\n                   `title` varchar(255) default NULL,\n                   `type` varchar(32) NOT NULL,\n                   `updated` int(9) default NULL,\n                   `view_count` int(9) default 0,\n                   `width` int(9) default NULL,\n                   PRIMARY KEY (`id`),\n                   KEY `parent_id` (`parent_id`),\n                   KEY `type` (`type`))\n                 ENGINE=InnoDB DEFAULT CHARSET=utf8;");
         $db->query("CREATE TABLE `logs` (\n                   `id` int(9) NOT NULL auto_increment,\n                   `category` varchar(64) default NULL,\n                   `html` varchar(255) default NULL,\n                   `message` text default NULL,\n                   `referer` varchar(255) default NULL,\n                   `severity` int(9) default 0,\n                   `timestamp` int(9) default 0,\n                   `url` varchar(255) default NULL,\n                   `user_id` int(9) default 0,\n                   PRIMARY KEY (`id`))\n                 ENGINE=InnoDB DEFAULT CHARSET=utf8;");
         $db->query("CREATE TABLE `messages` (\n                   `id` int(9) NOT NULL auto_increment,\n                   `key` varchar(255) default NULL,\n                   `value` varchar(255) default NULL,\n                   `severity` varchar(32) default NULL,\n                   PRIMARY KEY (`id`),\n                   UNIQUE KEY(`key`))\n                 ENGINE=InnoDB DEFAULT CHARSET=utf8;");
         $db->query("CREATE TABLE `modules` (\n                   `id` int(9) NOT NULL auto_increment,\n                   `name` varchar(64) default NULL,\n                   `version` int(9) default NULL,\n                   PRIMARY KEY (`id`),\n                   UNIQUE KEY(`name`))\n                 ENGINE=InnoDB DEFAULT CHARSET=utf8;");
         $db->query("CREATE TABLE `themes` (\n                   `id` int(9) NOT NULL auto_increment,\n                   `name` varchar(64) default NULL,\n                   `version` int(9) default NULL,\n                   PRIMARY KEY (`id`),\n                   UNIQUE KEY(`name`))\n                 ENGINE=InnoDB DEFAULT CHARSET=utf8;");
         $db->query("CREATE TABLE `permissions` (\n                   `id` int(9) NOT NULL auto_increment,\n                   `name` varchar(64) default NULL,\n                   `display_name` varchar(64) default NULL,\n                   PRIMARY KEY (`id`),\n                   UNIQUE KEY(`name`))\n                 ENGINE=InnoDB DEFAULT CHARSET=utf8;");
         $db->query("CREATE TABLE `incoming_translations` (\n                   `id` int(9) NOT NULL auto_increment,\n                   `key` binary(16) NOT NULL,\n                   `locale` char(10) NOT NULL,\n                   `message` text NOT NULL,\n                   `translation` text,\n                   `revision` int(9) DEFAULT NULL,\n                   PRIMARY KEY (`id`),\n                   UNIQUE KEY(`key`, `locale`),\n                   KEY `locale_key` (`locale`, `key`))\n                 ENGINE=InnoDB DEFAULT CHARSET=utf8;");
         $db->query("CREATE TABLE `sessions` (\n                  `session_id` varchar(127) NOT NULL,\n                  `last_activity` int(10) UNSIGNED NOT NULL,\n                  `data` text NOT NULL,\n                  PRIMARY KEY (`session_id`))\n                 ENGINE=InnoDB DEFAULT CHARSET=utf8;");
         $db->query("CREATE TABLE `tasks` (\n                  `callback` varchar(128) default NULL,\n                  `context` text NOT NULL,\n                  `done` boolean default 0,\n                  `id` int(9) NOT NULL auto_increment,\n                  `updated` int(9) default NULL,\n                  `name` varchar(128) default NULL,\n                  `percent_complete` int(9) default 0,\n                  `state` varchar(32) default NULL,\n                  `status` varchar(255) default NULL,\n                  PRIMARY KEY (`id`))\n                 ENGINE=InnoDB DEFAULT CHARSET=utf8;");
         $db->query("CREATE TABLE `vars` (\n                   `id` int(9) NOT NULL auto_increment,\n                   `module_name` varchar(64) NOT NULL,\n                   `name` varchar(64) NOT NULL,\n                   `value` text,\n                   PRIMARY KEY (`id`),\n                   UNIQUE KEY(`module_name`, `name`))\n                 ENGINE=InnoDB DEFAULT CHARSET=utf8;");
         foreach (array("albums", "resizes", "thumbs", "uploads", "modules") as $dir) {
             @mkdir(VARPATH . $dir);
         }
         access::register_permission("view", "View");
         access::register_permission("view_full", "View Full Size");
         access::register_permission("edit", "Edit");
         $root = ORM::factory("item");
         $root->type = 'album';
         $root->title = "Gallery";
         $root->description = "Welcome to your Gallery3";
         $root->left = 1;
         $root->right = 2;
         $root->parent_id = 0;
         $root->level = 1;
         $root->thumb_dirty = 1;
         $root->resize_dirty = 1;
         $root->save();
         access::add_item($root);
         module::set_var("core", "active_site_theme", "default");
         module::set_var("core", "active_admin_theme", "admin_default");
         module::set_var("core", "page_size", 9);
         module::set_var("core", "thumb_size", 200);
         module::set_var("core", "resize_size", 640);
         // Add rules for generating our thumbnails and resizes
         graphics::add_rule("core", "thumb", "resize", array("width" => 200, "height" => 200, "master" => Image::AUTO), 100);
         graphics::add_rule("core", "resize", "resize", array("width" => 640, "height" => 480, "master" => Image::AUTO), 100);
         // Detect a graphics toolkit
         $toolkits = graphics::detect_toolkits();
         foreach (array("imagemagick", "graphicsmagick", "gd") as $tk) {
             if ($toolkits[$tk]) {
                 module::set_var("core", "graphics_toolkit", $tk);
                 if ($tk != "gd") {
                     module::set_var("core", "graphics_toolkit_path", $toolkits[$tk]);
                 }
                 break;
             }
         }
         if (!module::get_var("core", "graphics_toolkit")) {
             site_status::warning(t("Graphics toolkit missing!  Please <a href=\"%url\">choose a toolkit</a>", array("url" => url::site("admin/graphics"))), "missing_graphics_toolkit");
         }
         // Instantiate default themes (site and admin)
         foreach (array("default", "admin_default") as $theme_name) {
             $theme_info = new ArrayObject(parse_ini_file(THEMEPATH . $theme_name . "/theme.info"), ArrayObject::ARRAY_AS_PROPS);
             $theme = ORM::factory("theme");
             $theme->name = $theme_name;
             $theme->version = $theme_info->version;
             $theme->save();
         }
         block_manager::add("dashboard_sidebar", "core", "block_adder");
         block_manager::add("dashboard_sidebar", "core", "stats");
         block_manager::add("dashboard_sidebar", "core", "platform_info");
         block_manager::add("dashboard_sidebar", "core", "project_news");
         block_manager::add("dashboard_center", "core", "welcome");
         block_manager::add("dashboard_center", "core", "photo_stream");
         block_manager::add("dashboard_center", "core", "log_entries");
         module::set_version("core", 1);
         module::set_var("core", "version", "3.0");
     }
 }