示例#1
0
 public function day($display_year, $display_user, $display_month, $display_day)
 {
     // Display all images for the specified day.
     // Figure out the total number of photos to display.
     if ($display_user == "-1") {
         $day_count = ORM::factory("item")->viewable()->where("type !=", "album")->where("captured >=", mktime(0, 0, 0, $display_month, $display_day, $display_year))->where("captured <", mktime(0, 0, 0, $display_month, $display_day + 1, $display_year))->find_all()->count();
     } else {
         $day_count = ORM::factory("item")->viewable()->where("owner_id", $display_user)->where("type !=", "album")->where("captured >=", mktime(0, 0, 0, $display_month, $display_day, $display_year))->where("captured <", mktime(0, 0, 0, $display_month, $display_day + 1, $display_year))->find_all()->count();
     }
     // Figure out paging stuff.
     $page_size = module::get_var("gallery", "page_size", 9);
     $page = $this->input->get("page", "1");
     $offset = ($page - 1) * $page_size;
     $max_pages = ceil($day_count / $page_size);
     // Make sure that the page references a valid offset
     if ($page < 1 || $day_count && $page > ceil($day_count / $page_size)) {
         Kohana::show_404();
     }
     // Set up the page.
     $template = new Theme_View("page.html", "other", "CalendarDayView");
     $template->page_title = t("Gallery :: Calendar");
     $template->set_global("page_size", $page_size);
     // Figure out which photos go on this page.
     if ($display_user == "-1") {
         $template->set_global("children", ORM::factory("item")->viewable()->where("type !=", "album")->where("captured >=", mktime(0, 0, 0, $display_month, $display_day, $display_year))->where("captured <", mktime(0, 0, 0, $display_month, $display_day + 1, $display_year))->orderby("captured", "ASC")->find_all($page_size, $offset));
     } else {
         $template->set_global("children", ORM::factory("item")->viewable()->where("owner_id", $display_user)->where("type !=", "album")->where("captured >=", mktime(0, 0, 0, $display_month, $display_day, $display_year))->where("captured <", mktime(0, 0, 0, $display_month, $display_day + 1, $display_year))->orderby("captured", "ASC")->find_all($page_size, $offset));
     }
     // Finish setting up and then display the page.
     $template->set_global("children_count", $day_count);
     $template->content = new View("dynamic.html");
     $template->content->title = t("Photos From ") . date("d F Y", mktime(0, 0, 0, $display_month, $display_day, $display_year));
     print $template;
 }
 /**
  * show map
  *
  * @param string $id 
  * @return void
  * @author Andy Bennett
  */
 public function index($id = 1)
 {
     $db = new Database();
     $m = ORM::factory('imagemap', $id);
     if (!$m->loaded) {
         Kohana::show_404('Imagemap ' . $id, 'common/error_404');
         return;
     }
     Assets::instance()->add_javascript('/cache/js/photonotes');
     Assets::instance()->add_css('/cache/css/photonotes');
     Assets::instance()->add_css('/cache/css/photonotes_client');
     $pages_array = strstr(APPPATH, 'backend_') === FALSE ? array() : imagemap_helper::get_pages();
     $pages = json_encode($pages_array);
     // Build the Image object
     $image = array();
     $image['img'] = $m->upload->id . $m->upload->file_ext;
     $image['alt'] = $m->title;
     // Load the view as an object
     $view = new View('imagemap');
     // Add variable data to the view
     $view->image = $image;
     $view->notes = $m->imagenotes;
     $view->admin = true;
     //APPENV == 'backend';  		// Are the image maps editable?
     $view->id = $id;
     // Needed for reporting changes back to the backend via ajax
     $view->pages = $pages;
     // Send the array of pages through to the view
     // Render the View
     $view->render(TRUE);
 }
示例#3
0
 public function tags($id)
 {
     $tag = ORM::factory("tag", $id);
     if (!$tag->loaded) {
         return Kohana::show_404();
     }
     $page = $this->input->get("page", 1);
     if ($page < 1) {
         url::redirect("media_rss/tags/{$tag->id}");
     }
     $children = $tag->items(self::$page_size, ($page - 1) * self::$page_size, "photo");
     $max_pages = ceil($tag->count / self::$page_size);
     if ($page > $max_pages) {
         url::redirect("media_rss/tags/{$tag->id}?page={$max_pages}");
     }
     $view = new View("feed.mrss");
     $view->title = $tag->name;
     $view->link = url::abs_site("tags/{$tag->id}");
     $view->description = t("Photos related to %tag_name", array("tag_name" => $tag->name));
     $view->feed_link = url::abs_site("media_rss/tags/{$tag->id}");
     $view->children = $children;
     if ($page > 1) {
         $previous_page = $page - 1;
         $view->previous_page_link = url::site("media_rss/tags/{$tag->id}?page={$previous_page}");
     }
     if ($page < $max_pages) {
         $next_page = $page + 1;
         $view->next_page_link = url::site("media_rss/tags/{$tag->id}?page={$next_page}");
     }
     // @todo do we want to add an upload date to the items table?
     $view->pub_date = date("D, d M Y H:i:s T");
     rest::http_content_type(rest::RSS);
     print $view;
 }
function error_404()
{
    if (Kohana::$instance == NULL) {
        Kohana::$instance = new Errors_Controller();
    }
    Kohana::show_404(null, 'common/error_404');
}
示例#5
0
 public function show($movie)
 {
     if (!is_object($movie)) {
         // show() must be public because we route to it in url::parse_url(), so make
         // sure that we're actually receiving an object
         Kohana::show_404();
     }
     access::required("view", $movie);
     $where = array(array("type", "!=", "album"));
     $position = $movie->parent()->get_position($movie, $where);
     if ($position > 1) {
         list($previous_item, $ignore, $next_item) = $movie->parent()->children(3, $position - 2, $where);
     } else {
         $previous_item = null;
         list($next_item) = $movie->parent()->viewable()->children(1, $position, $where);
     }
     $template = new Theme_View("page.html", "item", "movie");
     $template->set_global("item", $movie);
     $template->set_global("children", array());
     $template->set_global("children_count", 0);
     $template->set_global("parents", $movie->parents());
     $template->set_global("next_item", $next_item);
     $template->set_global("previous_item", $previous_item);
     $template->set_global("sibling_count", $movie->parent()->viewable()->children_count($where));
     $template->set_global("position", $position);
     $template->content = new View("movie.html");
     $movie->view_count++;
     $movie->save();
     print $template;
 }
示例#6
0
文件: rss.php 项目: Okat/gallery3
 public function feed($module_id, $feed_id, $id = null)
 {
     $page = $this->input->get("page", 1);
     if ($page < 1) {
         url::redirect(url::merge(array("page" => 1)));
     }
     // Configurable page size between 1 and 100, default 20
     $page_size = max(1, min(100, $this->input->get("page_size", self::$page_size)));
     // Run the appropriate feed callback
     if (module::is_active($module_id)) {
         $class_name = "{$module_id}_rss";
         if (method_exists($class_name, "feed")) {
             $feed = call_user_func(array($class_name, "feed"), $feed_id, ($page - 1) * $page_size, $page_size, $id);
         }
     }
     if (empty($feed)) {
         Kohana::show_404();
     }
     if ($feed->max_pages && $page > $feed->max_pages) {
         url::redirect(url::merge(array("page" => $feed->max_pages)));
     }
     $view = new View(empty($feed->view) ? "feed.mrss" : $feed->view);
     unset($feed->view);
     $view->feed = $feed;
     $view->pub_date = date("D, d M Y H:i:s T");
     $feed->uri = url::abs_site(Router::$current_uri);
     if ($page > 1) {
         $feed->previous_page_uri = url::abs_site(url::merge(array("page" => $page - 1)));
     }
     if ($page < $feed->max_pages) {
         $feed->next_page_uri = url::abs_site(url::merge(array("page" => $page + 1)));
     }
     rest::http_content_type(rest::RSS);
     print $view;
 }
示例#7
0
 /**
  *  @see REST_Controller::_show($resource)
  */
 public function _show($album)
 {
     access::required("view", $album);
     $page_size = module::get_var("core", "page_size", 9);
     $show = $this->input->get("show");
     if ($show) {
         $index = $album->get_position($show);
         $page = ceil($index / $page_size);
         if ($page == 1) {
             url::redirect("albums/{$album->id}");
         } else {
             url::redirect("albums/{$album->id}?page={$page}");
         }
     }
     $page = $this->input->get("page", "1");
     $children_count = $album->viewable()->children_count();
     $offset = ($page - 1) * $page_size;
     // Make sure that the page references a valid offset
     if ($page < 1 || $page > max(ceil($children_count / $page_size), 1)) {
         Kohana::show_404();
     }
     $template = new Theme_View("page.html", "album");
     $template->set_global("page_size", $page_size);
     $template->set_global("item", $album);
     $template->set_global("children", $album->viewable()->children($page_size, $offset));
     $template->set_global("children_count", $children_count);
     $template->set_global("parents", $album->parents());
     $template->content = new View("album.html");
     $album->view_count++;
     $album->save();
     print $template;
 }
function error_404()
{
    if (Kohana::$instance == NULL) {
        Kohana::$instance = new Errors_Controller();
    }
    Kohana::log('error', 'Error 404 (steam.core.hooks): ' . URI::instance()->string());
    Kohana::show_404(null, 'common/error_404');
}
示例#9
0
 static function feed($feed_id, $offset, $limit, $id)
 {
     if ($feed_id == "tag") {
         $tag = ORM::factory("tag", $id);
         if (!$tag->loaded) {
             Kohana::show_404();
         }
         $feed->children = $tag->items($limit, $offset, "photo");
         $feed->max_pages = ceil($tag->count / $limit);
         $feed->title = $tag->name;
         $feed->description = t("Photos related to %tag_name", array("tag_name" => $tag->name));
         return $feed;
     }
 }
示例#10
0
 static function tags($offset, $limit, $id)
 {
     $tag = ORM::factory("tag", $id);
     if (!$tag->loaded) {
         return Kohana::show_404();
     }
     $feed = new stdClass();
     $feed->data["children"] = $tag->items($limit, $offset, "photo");
     $feed->max_pages = ceil($tag->count / $limit);
     $feed->data["title"] = $tag->name;
     $feed->data["link"] = url::abs_site("tags/{$tag->id}");
     $feed->data["description"] = t("Photos related to %tag_name", array("tag_name" => $tag->name));
     return $feed;
 }
示例#11
0
 public function print_proxy($type, $id)
 {
     // If its a request for the full size then make sure we are coming from an
     // authorized address
     if ($type == "full") {
         $remote_addr = ip2long($this->input->server("REMOTE_ADDR"));
         if ($remote_addr === false) {
             Kohana::show_404();
         }
         $config = Kohana::config("addthis");
         $authorized = false;
         foreach ($config["ranges"] as $ip_range) {
             $low = ip2long($ip_range["low"]);
             $high = ip2long($ip_range["high"]);
             $authorized = $low !== false && $high !== false && $low <= $remote_addr && $remote_addr <= $high;
             if ($authorized) {
                 break;
             }
         }
         if (!$authorized) {
             Kohana::show_404();
         }
     }
     $proxy = ORM::factory("addthis_proxy", array("uuid" => $id));
     if (!$proxy->loaded || !$proxy->item->loaded) {
         Kohana::show_404();
     }
     $file = $type == "full" ? $proxy->item->file_path() : $proxy->item->thumb_path();
     if (!file_exists($file)) {
         kohana::show_404();
     }
     // We don't need to save the session for this request
     Session::abort_save();
     if (!TEST_MODE) {
         // Dump out the image
         header("Content-Type: {$proxy->item}->mime_type");
         Kohana::close_buffers(false);
         $fd = fopen($file, "rb");
         fpassthru($fd);
         fclose($fd);
         // If the request was for the image and not the thumb, then delete the proxy.
         if ($type == "full") {
             $proxy->delete();
         }
     }
     $this->_clean_expired();
 }
示例#12
0
 function index()
 {
     if (PHP_SAPI != 'cli') {
         Kohana::show_404();
     }
     try {
         $this->_reset();
         // empty and reinstall the standard modules
         $this->_dump_database();
         // Dump the database
         $this->_dump_var();
         // Dump the var directory
     } catch (Exception $e) {
         print $e->getTraceAsString();
         return;
     }
     print "Successfully wrote install.sql and init_var.php\n";
 }
 public function index()
 {
     //Only accessible through CLI
     if (PHP_SAPI !== 'cli') {
         Kohana::show_404();
     }
     //Clear the output buffer in preperation for any user prompts
     ob_end_flush();
     //Default configuration settings
     $config = array('data_fixtures_path' => MODPATH . 'doctrine' . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR, 'models_path' => MODPATH . 'doctrine' . DIRECTORY_SEPARATOR . 'models' . DIRECTORY_SEPARATOR, 'migrations_path' => MODPATH . 'doctrine' . DIRECTORY_SEPARATOR . 'migrations' . DIRECTORY_SEPARATOR, 'sql_path' => MODPATH . 'doctrine' . DIRECTORY_SEPARATOR . 'schema' . DIRECTORY_SEPARATOR, 'yaml_schema_path' => MODPATH . 'doctrine' . DIRECTORY_SEPARATOR . 'schema' . DIRECTORY_SEPARATOR, 'generateTableClasses' => true);
     $cli = new Doctrine_Cli($config);
     //remove our routing path
     $args = $_SERVER['argv'];
     $call = array_shift($args);
     $route = array_shift($args);
     array_unshift($args, $call);
     $cli->run($args);
 }
示例#14
0
 public function _show($tag)
 {
     $page_size = module::get_var("core", "page_size", 9);
     $page = $this->input->get("page", "1");
     $children_count = $tag->items_count();
     $offset = ($page - 1) * $page_size;
     // Make sure that the page references a valid offset
     if ($page < 1 || $page > ceil($children_count / $page_size)) {
         Kohana::show_404();
     }
     $template = new Theme_View("page.html", "tag");
     $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("tag.html");
     print $template;
 }
示例#15
0
文件: tags.php 项目: krgeek/gallery3
 public function _show($tag)
 {
     $page_size = module::get_var("gallery", "page_size", 9);
     $page = $this->input->get("page", "1");
     $children_count = $tag->items_count();
     $offset = ($page - 1) * $page_size;
     // Make sure that the page references a valid offset
     if ($page < 1 || $children_count && $page > ceil($children_count / $page_size)) {
         Kohana::show_404();
     }
     $template = new Theme_View("page.html", "tag");
     $template->set_global("page_size", $page_size);
     $template->set_global("page_title", t("Browse Tag::%name", array("name" => $tag->name)));
     $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");
     print $template;
 }
示例#16
0
 /**
  * Print out a cached entry.
  * @param string   the combined entry type (either "javascript" or "css")
  * @param string   the key (typically an md5 sum)
  */
 private function _emit($type, $key)
 {
     $input = Input::instance();
     // Our data is immutable, so if they already have a copy then it needs no updating.
     if ($input->server("HTTP_IF_MODIFIED_SINCE")) {
         header('HTTP/1.0 304 Not Modified');
         header("Expires: Tue, 19 Jan 2038 00:00:00 GMT");
         header("Cache-Control: max-age=2678400");
         header('Pragma: public');
         return;
     }
     if (empty($key)) {
         Kohana::show_404();
     }
     // We don't need to save the session for this request
     Session::abort_save();
     $cache = Cache::instance();
     $use_gzip = function_exists("gzencode") && stripos($input->server("HTTP_ACCEPT_ENCODING"), "gzip") !== false && (int) ini_get("zlib.output_compression") === 0;
     if ($use_gzip && ($content = $cache->get("{$key}_gz"))) {
         header("Content-Encoding: gzip");
     } else {
         // Fall back to non-gzipped if we have to
         $content = $cache->get($key);
     }
     if (empty($content)) {
         Kohana::show_404();
     }
     // $type is either 'javascript' or 'css'
     if ($type == "javascript") {
         header("Content-Type: application/javascript; charset=UTF-8");
     } else {
         header("Content-Type: text/css; charset=UTF-8");
     }
     header("Expires: Tue, 19 Jan 2038 00:00:00 GMT");
     header("Cache-Control: max-age=2678400");
     header('Pragma: public');
     header("Last-Modified: " . gmdate("D, d M Y H:i:s T", time()));
     Kohana::close_buffers(false);
     print $content;
 }
示例#17
0
 private function _show($album)
 {
     $page_size = module::get_var("gallery", "page_size", 9);
     $page = $this->input->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)) {
         Kohana::show_404();
     }
     $template = new Theme_View("page.html", "dynamic");
     $template->set_global("page_size", $page_size);
     $template->set_global("children", ORM::factory("item")->viewable()->where("type !=", "album")->orderby($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;
 }
示例#18
0
 public function print_proxy($type, $id)
 {
     $proxy = ORM::factory("digibug_proxy", array("uuid" => $id));
     if (!$proxy->loaded || !$proxy->item->loaded) {
         Kohana::show_404();
     }
     $file = $type == "full" ? $proxy->item->file_path() : $proxy->item->thumb_path();
     if (!file_exists($file)) {
         kohana::show_404();
     }
     // We don't need to save the session for this request
     Session::abort_save();
     // Dump out the image
     header("Content-Type: {$proxy->item}->mime_type");
     Kohana::close_buffers(false);
     $fd = fopen($file, "rb");
     fpassthru($fd);
     fclose($fd);
     // If the request was for the image and not the thumb, then delete the proxy.
     if ($type == "full") {
         $proxy->delete();
     }
     $this->_clean_expired();
 }
示例#19
0
 /**
  * get the xml string for the form
  *
  * @return string
  * @author Andy Bennett
  */
 public function get_form_xml_string()
 {
     $path = 'forms/' . $this->data->name;
     // pull the form xml in as a simplexml object
     try {
         $xml_path = Kohana::find_file('xml', $path, TRUE, 'xml');
         $form_xml_string = file_get_contents($xml_path);
     } catch (Exception $e) {
         Kohana::show_404($path, 'common/error_404');
         // try {
         // 				// if the form doesn't exist, create one from the database
         // 				$xform_model = new Xform_Model;
         // 				$form_xml_string = $xform_model->get_form_xml( $this->data );
         //
         // 			} catch (Exception $e) {
         //
         //
         // 			}
     }
     return $form_xml_string;
 }
示例#20
0
 public function form_edit($resource_id)
 {
     if ($this->resource_type == null) {
         throw new Exception("@todo ERROR_MISSING_RESOURCE_TYPE");
     }
     // @todo this needs security checks
     $resource = ORM::factory($this->resource_type, $resource_id);
     if (!$resource->loaded) {
         return Kohana::show_404();
     }
     return $this->_form_edit($resource);
 }
示例#21
0
 /**
  * undocumented function
  *
  * @param string $page_req 
  * @return void
  * @author Andy Bennett
  */
 public function video($page_req = false)
 {
     $data = array();
     $model = ORM::factory($this->setup['model'], $page_req);
     if (!$model->loaded) {
         Kohana::show_404($page_req, 'common/error_404');
     }
     $path = DATAPATH . 'uploads/';
     $file = $model->upload->file_name;
     if (!file_exists($path . $file)) {
         Kohana::show_404($file, 'common/error_404');
     }
     if ($model->status == 0 and !User::instance()->is_admin()) {
         throw new Kohana_403_Exception($file, 'common/error_403');
     }
     if (!copy($path . $file, DOCROOT . 'cache/' . $file)) {
         Kohana::show_404($file, 'common/error_404');
     }
     $data['id'] = $page_req;
     $data['path'] = url::base() . 'cache/';
     $data['name'] = $file;
     $data['dimensions'] = array('height' => $model->upload->image_height, 'width' => $model->upload->image_width);
     $data['picture'] = url::base() . 'gallery/crop/' . $model->upload->image_width . '/' . $model->upload->image_height . '/' . $model->upload->id . '.jpg';
     Assets::instance()->add_css('/cache/css/ffmpeg');
     $c = View::factory('videoplayer', $data)->render();
     Display::instance()->display($c);
 }
示例#22
0
 /**
  * function to show page based on passed column name
  *
  * @param string $column 
  * @param string $page_req 
  * @return void
  * @author Andy Bennett
  */
 protected function show_view($model, $page_req)
 {
     if (!$model->loaded or !$model->status) {
         Kohana::show_404($page_req, 'common/error_404');
     }
     $data['row'] = $model;
     $data['controller'] = $this->setup['name'];
     // run the view event
     $r = array('view' => $this->setup['view'] . '_view', 'data' => $data);
     Event::run('steamcore.item_view_' . Restful::instance()->extension(), $r);
 }
示例#23
0
 /**
  * function to show page based on passed column name
  *
  * @param string $column 
  * @param string $page_req 
  * @return void
  * @author Andy Bennett
  */
 protected function show_view($model, $page_req)
 {
     if (!$model->loaded) {
         Kohana::show_404(null, 'common/error_404');
     }
     $data['row'] = $model;
     $data['controller'] = $this->setup['name'];
     // run the view event
     $r = array('view' => $this->setup['view'] . '_view', 'data' => $data);
     Event::run('steamcore.item_view', $r);
 }
示例#24
0
 public function month($display_year, $display_user, $display_month)
 {
     // Display all images for the specified month.
     // Figure out the total number of photos to display.
     $day_count = 0;
     if ($display_user == "-1") {
         $day_count = ORM::factory("item")->viewable()->where("type !=", "album")->where("captured >=", mktime(0, 0, 0, $display_month, 1, $display_year))->where("captured <", mktime(0, 0, 0, $display_month + 1, 1, $display_year))->find_all()->count();
     } else {
         $day_count = ORM::factory("item")->viewable()->where("owner_id", $display_user)->where("type !=", "album")->where("captured >=", mktime(0, 0, 0, $display_month, 1, $display_year))->where("captured <", mktime(0, 0, 0, $display_month + 1, 1, $display_year))->find_all()->count();
     }
     // Figure out paging stuff.
     $page_size = module::get_var("gallery", "page_size", 9);
     $page = (int) $this->input->get("page", "1");
     $offset = ($page - 1) * $page_size;
     $max_pages = max(ceil($day_count / $page_size), 1);
     // Make sure that the page references a valid offset
     if ($page < 1 || $page > $max_pages) {
         Kohana::show_404();
     }
     // Set up the page.
     $template = new Theme_View("page.html", "collection", "CalendarMonthView");
     $template->set_global("page", $page);
     $template->set_global("max_pages", $max_pages);
     $template->set_global("page_size", $page_size);
     $template->page_title = t("Gallery :: Calendar");
     // Figure out which photos go on this page.
     if ($display_user == "-1") {
         $template->set_global("children", ORM::factory("item")->viewable()->where("type !=", "album")->where("captured >=", mktime(0, 0, 0, $display_month, 1, $display_year))->where("captured <", mktime(0, 0, 0, $display_month + 1, 1, $display_year))->orderby("captured", "ASC")->find_all($page_size, $offset));
     } else {
         $template->set_global("children", ORM::factory("item")->viewable()->where("owner_id", $display_user)->where("type !=", "album")->where("captured >=", mktime(0, 0, 0, $display_month, 1, $display_year))->where("captured <", mktime(0, 0, 0, $display_month + 1, 1, $display_year))->orderby("captured", "ASC")->find_all($page_size, $offset));
     }
     // Set up breadcrumbs for this page.
     $calendar_breadcrumbs[0] = new Calendar_Breadcrumb($display_year, url::site("calendarview/calendar/" . $display_year . "/" . $display_user));
     $fake_item = new Calendar_Breadcrumb(t(date("F", mktime(0, 0, 0, $display_month, 1, $display_year))), "");
     $template->set_global("item", $fake_item);
     $template->set_global("parents", $calendar_breadcrumbs);
     // Finish setting up and then display the page.
     $template->set_global("children_count", $day_count);
     $template->content = new View("dynamic.html");
     $template->content->title = t("Photos From ") . t(date("F", mktime(0, 0, 0, $display_month, 1, $display_year))) . " " . date("Y", mktime(0, 0, 0, $display_month, 1, $display_year));
     print $template;
 }
 public function create()
 {
     Kohana::show_404();
 }
示例#26
0
 function Index()
 {
     if (!TEST_MODE) {
         print Kohana::show_404();
     }
     $original_config = DOCROOT . "var/database.php";
     $test_config = VARPATH . "database.php";
     if (!file_exists($original_config)) {
         print "Please copy kohana/config/database.php to {$original_config}.\n";
         return;
     } else {
         copy($original_config, $test_config);
         $db_config = Kohana::config('database');
         if (empty($db_config['unit_test'])) {
             $default = $db_config['default'];
             $conn = $default['connection'];
             Kohana::config_set('database.unit_test.benchmark', $default['benchmark']);
             Kohana::config_set('database.unit_test.persistent', $default['persistent']);
             Kohana::config_set('database.unit_test.connection.type', $conn['type']);
             Kohana::config_set('database.unit_test.connection.user', $conn['user']);
             Kohana::config_set('database.unit_test.connection.pass', $conn['pass']);
             Kohana::config_set('database.unit_test.connection.host', $conn['host']);
             Kohana::config_set('database.unit_test.connection.port', $conn['port']);
             Kohana::config_set('database.unit_test.connection.socket', $conn['socket']);
             Kohana::config_set('database.unit_test.connection.database', "{$conn['database']}_test");
             Kohana::config_set('database.unit_test.character_set', $default['character_set']);
             Kohana::config_set('database.unit_test.table_prefix', $default['table_prefix']);
             Kohana::config_set('database.unit_test.object', $default['object']);
             Kohana::config_set('database.unit_test.cache', $default['cache']);
             Kohana::config_set('database.unit_test.escape', $default['escape']);
             $db_config = Kohana::config('database');
         }
         if ($db_config['default']['connection']['database'] == $db_config['unit_test']['connection']['database']) {
             print "Don't use the default database for your unit tests or you'll lose all your data.\n";
             return;
         }
         try {
             $db = Database::instance('unit_test');
             $db->connect();
             // Make this the default database for the rest of this run
             Database::$instances = array('default' => $db);
         } catch (Exception $e) {
             print "{$e->getMessage()}\n";
             return;
         }
     }
     // Find all tests, excluding sample tests that come with the unit_test module.
     foreach (glob(MODPATH . "*/tests") as $path) {
         if ($path != MODPATH . "unit_test/tests") {
             $paths[] = $path;
         }
     }
     Kohana::config_set('unit_test.paths', $paths);
     // Clean out the database
     if ($tables = $db->list_tables()) {
         foreach ($db->list_tables() as $table) {
             $db->query("DROP TABLE {$table}");
         }
     }
     // Clean out the filesystem
     @system("rm -rf test/var");
     @mkdir('test/var/logs', 0777, true);
     // Reset our caches
     module::$modules = array();
     module::$active = array();
     module::$var_cache = array();
     $db->clear_cache();
     // Install all modules
     // Force gallery and user to be installed first to resolve dependencies.
     gallery_installer::install(true);
     module::load_modules();
     module::install("user");
     module::activate("user");
     $modules = array();
     foreach (glob(MODPATH . "*/helpers/*_installer.php") as $file) {
         $module_name = basename(dirname(dirname($file)));
         if (in_array($module_name, array("gallery", "user"))) {
             continue;
         }
         module::install($module_name);
         module::activate($module_name);
     }
     $filter = count($_SERVER["argv"]) > 2 ? $_SERVER["argv"][2] : null;
     print new Unit_Test($modules, $filter);
 }
示例#27
0
 /**
  * view blog post
  *
  * @param string $post 
  * @return string
  * @author Andy Bennett
  */
 public function view($post = null)
 {
     if (is_null($post)) {
         $post = URI::instance()->segment(3);
     }
     if ($post !== false) {
         $root = ORM::factory('blogpost')->where(array('id' => $post, 'status' => 1))->find();
         if (!$root->loaded) {
             Kohana::show_404(null, 'common/error_404');
         }
         $blog = ORM::factory('blog', $root->blog_id);
         $nodes = $root->descendants(true, 'ASC')->where('status', 1)->find_all();
         // Get all the user ids
         $user_ids = array();
         foreach ($nodes as $node) {
             $user_ids[] = $node->user_id;
         }
         $user_ids = array_unique($user_ids);
         $db = Database::instance();
         if (!empty($user_ids)) {
             $postcount_subq = "select user_id, count(*) as postcount from blogposts where lvl = 1 and user_id in (" . implode(',', $user_ids) . ") group by user_id";
             $replycount_subq = "select user_id, count(*) as replycount from blogposts where lvl > 1 and user_id in (" . implode(',', $user_ids) . ") group by user_id";
             $users_results = $db->query("SELECT post_q.user_id, postcount, replycount FROM ({$postcount_subq}) AS post_q, ({$replycount_subq}) AS reply_q WHERE post_q.user_id = reply_q.user_id");
         } else {
             $users_results = array();
         }
         $users = array();
         foreach ($users_results as $user) {
             $users[$user->user_id] = $user;
         }
         $nodes->rewind();
         if (!$nodes->count()) {
             Kohana::show_404(null, 'common/error_404');
         }
         $view_options = array('blog' => $blog, 'nodes' => $nodes, 'level_column' => $root->level_column, 'post_title' => $root->title, 'users' => $users);
         return View::factory('blog/post', $view_options)->render();
     } else {
         die("post id not specified");
         // url::redirect('/blog');
     }
 }
示例#28
0
 function Index()
 {
     if (!TEST_MODE) {
         print Kohana::show_404();
     }
     // Jump through some hoops to satisfy the way that we check for the site_domain in
     // config.php.  We structure this such that the code in config will leave us with a
     // site_domain of "." (for historical reasons)
     // @todo: for tests, we should force the site_domain to something like example.com
     $_SERVER["SCRIPT_FILENAME"] = "index.php";
     $_SERVER["SCRIPT_NAME"] = "./index.php";
     $original_config = DOCROOT . "var/database.php";
     $test_config = VARPATH . "database.php";
     if (!file_exists($original_config)) {
         print "Please copy kohana/config/database.php to {$original_config}.\n";
         return;
     } else {
         copy($original_config, $test_config);
         $db_config = Kohana::config('database');
         if (empty($db_config['unit_test'])) {
             $default = $db_config['default'];
             $conn = $default['connection'];
             Kohana::config_set('database.unit_test.benchmark', $default['benchmark']);
             Kohana::config_set('database.unit_test.persistent', $default['persistent']);
             Kohana::config_set('database.unit_test.connection.type', $conn['type']);
             Kohana::config_set('database.unit_test.connection.user', $conn['user']);
             Kohana::config_set('database.unit_test.connection.pass', $conn['pass']);
             Kohana::config_set('database.unit_test.connection.host', $conn['host']);
             Kohana::config_set('database.unit_test.connection.port', $conn['port']);
             Kohana::config_set('database.unit_test.connection.socket', $conn['socket']);
             Kohana::config_set('database.unit_test.connection.database', "{$conn['database']}_test");
             Kohana::config_set('database.unit_test.character_set', $default['character_set']);
             Kohana::config_set('database.unit_test.table_prefix', $default['table_prefix']);
             Kohana::config_set('database.unit_test.object', $default['object']);
             Kohana::config_set('database.unit_test.cache', $default['cache']);
             Kohana::config_set('database.unit_test.escape', $default['escape']);
             $db_config = Kohana::config('database');
         }
         if ($db_config['default']['connection']['database'] == $db_config['unit_test']['connection']['database']) {
             print "Don't use the default database for your unit tests or you'll lose all your data.\n";
             return;
         }
         try {
             $db = Database::instance('unit_test');
             $db->connect();
             // Make this the default database for the rest of this run
             Database::$instances = array('default' => $db);
         } catch (Exception $e) {
             print "{$e->getMessage()}\n";
             return;
         }
     }
     try {
         // Find all tests, excluding sample tests that come with the unit_test module.
         foreach (glob(MODPATH . "*/tests") as $path) {
             if ($path != MODPATH . "unit_test/tests") {
                 $paths[] = $path;
             }
         }
         Kohana::config_set('unit_test.paths', $paths);
         // Clean out the database
         if ($tables = $db->list_tables()) {
             foreach ($db->list_tables() as $table) {
                 $db->query("DROP TABLE {$table}");
             }
         }
         // Clean out the filesystem
         @system("rm -rf test/var");
         @mkdir('test/var/logs', 0777, true);
         // Reset our caches
         module::$modules = array();
         module::$active = array();
         module::$var_cache = array();
         $db->clear_cache();
         // Rest the cascading class path
         Kohana::config_set("core", Kohana::config_load("core"));
         // Install all modules
         // Force gallery and user to be installed first to resolve dependencies.
         gallery_installer::install(true);
         module::load_modules();
         module::install("user");
         module::activate("user");
         $modules = array();
         foreach (glob(MODPATH . "*/helpers/*_installer.php") as $file) {
             $module_name = basename(dirname(dirname($file)));
             if (in_array($module_name, array("gallery", "user"))) {
                 continue;
             }
             module::install($module_name);
             module::activate($module_name);
         }
         // Trigger late-binding install actions (defined in gallery_event::user_login)
         graphics::choose_default_toolkit();
         $filter = count($_SERVER["argv"]) > 2 ? $_SERVER["argv"][2] : null;
         print new Unit_Test($modules, $filter);
     } catch (Exception $e) {
         print "Exception: {$e->getMessage()}\n";
         print $e->getTraceAsString() . "\n";
     }
 }
示例#29
0
 public function show($album)
 {
     if (!is_object($album)) {
         // show() must be public because we route to it in url::parse_url(), so make
         // sure that we're actually receiving an object
         Kohana::show_404();
     }
     $page_size = module::get_var("gallery", "page_size", 9);
     if (!access::can("view", $album)) {
         if ($album->id == 1) {
             $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 = auth::get_login_form("login/auth_html");
             print $view;
             return;
         } else {
             access::forbidden();
         }
     }
     $input = Input::instance();
     $show = $input->get("show");
     if ($show) {
         $child = ORM::factory("item", $show);
         $index = $album->get_position($child);
         if ($index) {
             $page = ceil($index / $page_size);
             if ($page == 1) {
                 url::redirect($album->abs_url());
             } else {
                 url::redirect($album->abs_url("page={$page}"));
             }
         }
     }
     $page = $input->get("page", "1");
     $children_count = $album->viewable()->children_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", "album");
     $template->set_global("page", $page);
     $template->set_global("page_title", null);
     $template->set_global("max_pages", $max_pages);
     $template->set_global("page_size", $page_size);
     $template->set_global("item", $album);
     $template->set_global("children", $album->viewable()->children($page_size, $offset));
     $template->set_global("children_count", $children_count);
     $template->set_global("parents", $album->parents());
     $template->content = new View("album.html");
     // We can't use math in ORM or the query builder, so do this by hand.  It's important
     // that we do this with math, otherwise concurrent accesses will damage accuracy.
     db::query("UPDATE {items} SET `view_count` = `view_count` + 1 WHERE `id` = {$album->id}");
     print $template;
 }