Пример #1
0
 public function before()
 {
     $redirect = false;
     $this->template = new View('kwalbum/template');
     $this->url = URL::base(true, 'http') . 'kwalbum';
     // get location from URL
     if ($this->request->param('location')) {
         $this->location = urldecode($this->request->param('location'));
         Model_Kwalbum_Item::append_where('location', $this->location);
     } elseif (!empty($_GET['location'])) {
         $this->location = $_GET['location'];
         Model_Kwalbum_Item::append_where('location', $this->location);
         $redirect = true;
     }
     // date
     if (!empty($_GET['date'])) {
         $date = explode('-', $_GET['date']);
         $year = (int) @$date[0];
         $month = (int) @$date[1];
         $day = (int) @$date[2];
         if (!empty($_GET['date2'])) {
             $date2 = explode('-', $_GET['date2']);
             $year2 = (int) @$date2[0];
             $month2 = (int) @$date2[1];
             $day2 = (int) @$date2[2];
         } else {
             $year2 = 0;
             $month2 = 0;
             $day2 = 0;
         }
         $redirect = true;
     } else {
         $year = (int) $this->request->param('year');
         $month = (int) $this->request->param('month');
         $day = (int) $this->request->param('day');
         $year2 = (int) $this->request->param('year2');
         $month2 = (int) $this->request->param('month2');
         $day2 = (int) $this->request->param('day2');
     }
     if ($year) {
         // date filtering requires at least a start year
         $end_year_is_set = $year2 > 1700;
         $year = $year > 1700 ? $year : date('Y');
         // validate year
         $year2 = $end_year_is_set ? $year2 : $year;
         // default end year to start year
         $month = ($month > 0 and $month < 13) ? $month : 0;
         // validate month
         if ($month2 < 1 or $month2 > 12) {
             // default end month to start month or last month
             $month2 = (!$end_year_is_set and $month) ? $month : 12;
         }
         $month = $month ?: 1;
         // default start month to first month
         $last_day = date('t', strtotime("{$year}-{$month}-1"));
         $last_day2 = date('t', strtotime("{$year2}-{$month2}-1"));
         $day = ($day > 0 and $day < $last_day) ? $day : 0;
         // validate day
         if ($day2 < 1 or $day2 > $last_day2) {
             // default end day to start day or last day
             $day2 = (!$end_year_is_set and $day) ? $day : $last_day2;
         }
         $day = $day ?: 1;
         // default start day to first day
         $this->date = new DateTime("{$year}-{$month}-{$day}");
         $this->date2 = new DateTime("{$year2}-{$month2}-{$day2}");
         Model_Kwalbum_Item::append_where('date', array($this->date, $this->date2));
     }
     // tags
     $this->tags = explode(',', urldecode($this->request->param('tags')));
     if ($this->tags[0] != '') {
         Model_Kwalbum_Item::append_where('tags', $this->tags);
     } elseif (!empty($_GET['tags'])) {
         $this->tags = explode(',', $_GET['tags']);
         Model_Kwalbum_Item::append_where('tags', $this->tags);
         $redirect = true;
     } else {
         $this->tags = null;
     }
     // people names
     $this->people = explode(',', urldecode($this->request->param('people')));
     if ($this->people[0] != '') {
         Model_Kwalbum_Item::append_where('people', $this->people);
     } elseif (!empty($_GET['people'])) {
         $this->people = explode(',', $_GET['people']);
         Model_Kwalbum_Item::append_where('people', $this->people);
         $redirect = true;
     } else {
         $this->people = null;
     }
     // created timestamp
     if ($this->request->param('created_date')) {
         $this->create_dt = urldecode($this->request->param('created_date'));
         if ($this->request->param('created_time')) {
             $this->create_dt .= ' ' . urldecode($this->request->param('created_time'));
             Model_Kwalbum_Item::append_where('create_dt', $this->create_dt);
         } else {
             Model_Kwalbum_Item::append_where('create_date', $this->create_dt);
         }
     } elseif (!empty($_GET['created_date'])) {
         $this->create_dt = $_GET['created_date'];
         if ($_GET['created_time']) {
             $this->create_dt .= ' ' . $_GET['created_time'];
             Model_Kwalbum_Item::append_where('create_dt', $this->create_dt);
             $redirect = true;
         } else {
             Model_Kwalbum_Item::append_where('create_date', $this->create_dt);
         }
     } else {
         $this->create_dt = null;
     }
     // Set up user if logged in
     $this->user = Model::factory('Kwalbum_User');
     $this->user->load_from_cookie($this->request->action());
     // item id
     if (0 < $this->request->param('id')) {
         $this->item = Model::factory('kwalbum_item')->load((int) $this->request->param('id'));
         $this->item->hide_if_needed($this->user);
         $this->template->set_global('item', $this->item);
     }
     $this->params = ($year ? $year . '/' : null) . ($month ? $month . '/' : null) . ($day ? $day . '/' : null);
     if ($year2) {
         $this->params .= 'to/' . $year2 . '/' . ($month2 ? $month2 . '/' : null) . ($day2 ? $day2 . '/' : null);
     }
     $this->params .= ($this->location ? $this->location . '/' : null) . ($this->tags ? 'tags/' . implode(',', $this->tags) . '/' : null) . ($this->people ? 'people/' . implode(',', $this->people) . '/' : null) . ($this->create_dt ? 'created/' . implode('/', explode(' ', $this->create_dt)) . '/' : null);
     if ($this->request->action() != 'media' and $this->request->controller() != 'install') {
         $this->in_edit_mode = !empty($_SESSION['kwalbum_edit']);
         $this->total_items = Model_Kwalbum_Item::get_total_items();
         $this->total_pages = Model_Kwalbum_Item::get_page_number($this->total_items, $this->in_edit_mode);
         $this->item_index = 0;
         $page_number = (int) $this->request->param('page');
         if ($page_number < 1 or $page_number > $this->total_pages) {
             $page_number = 1;
         }
         if ($this->item) {
             $this->item_index = Model_Kwalbum_Item::get_index($this->item->id, $this->item->sort_date);
             $page_number = Model_Kwalbum_Item::get_page_number($this->item_index);
             $this->next_item = $this->item->getNextItem();
             if ($this->next_item->id) {
                 $this->next_item->hide_if_needed($this->user);
             }
             $this->previous_item = $this->item->getPreviousItem();
             if ($this->previous_item->id) {
                 $this->previous_item->hide_if_needed($this->user);
             }
             $this->template->set_global('previous_item', $this->previous_item);
             $this->template->set_global('next_item', $this->next_item);
         }
         if ($redirect) {
             header('Location: ' . $this->url . '/' . $this->params);
         }
         $this->page_number = $page_number;
         $this->template->set_global('location', $this->location);
         $this->template->set_global('date', $this->date);
         $this->template->set_global('date2', $this->date2);
         $this->template->set_global('tags', $this->tags);
         $this->template->set_global('people', $this->people);
         $this->template->set_global('create_dt', $this->create_dt);
         $this->template->set_global('kwalbum_url_params', $this->params);
         $this->template->set_global('total_items', $this->total_items);
         $this->template->set_global('total_pages', $this->total_pages);
         $this->template->set_global('item_index', $this->item_index);
         $this->template->set_global('page_number', $this->page_number);
         $this->template->set_global('in_edit_mode', $this->in_edit_mode);
         $this->template->set_global('head', html::script($this->url . '/media/ajax/toggle.edit.js'));
     }
     $this->template->set_global('kwalbum_url', $this->url);
     $this->template->set_global('user', $this->user);
 }
Пример #2
0
 /**
  * recursive function to find items to be used as markers on a map
  *
  * @param float $left
  * @param float $right
  * @param float $top
  * @param float $bottom
  * @param string $where
  * @param ArrayOfArray $data
  * @param int $limit
  * @param int $depth
  * @return void
  */
 public static function getMarkers($left, $right, $top, $bottom, &$where, &$data, $limit, $depth = 0)
 {
     $where_query = $where . " AND latitude IS NOT NULL AND latitude != 0" . " AND latitude >= '{$bottom}' AND latitude <= '{$top}'" . ($left > $right ? " AND (longitude >= '{$left}' OR longitude <= '{$right}')" : " AND longitude >= '{$left}' AND longitude <= '{$right}'");
     $query = "SELECT count(*) FROM kwalbum_items {$where_query}";
     $result = DB::query(Database::SELECT, $query)->execute();
     $count = (int) $result[0]['count(*)'];
     if (0 == $count) {
         return;
     }
     if (0 < $depth and $limit < $count) {
         $depth--;
         $centerLat = ($left + $right) / 2;
         $centerLon = ($top + $bottom) / 2;
         Model_Kwalbum_Item::getMarkers($left, $centerLat, $top, $centerLon, $where, $data, $limit, $depth);
         Model_Kwalbum_Item::getMarkers($centerLat, $right, $top, $centerLon, $where, $data, $limit, $depth);
         Model_Kwalbum_Item::getMarkers($left, $centerLat, $centerLon, $bottom, $where, $data, $limit, $depth);
         Model_Kwalbum_Item::getMarkers($centerLat, $right, $centerLon, $bottom, $where, $data, $limit, $depth);
     } elseif ($limit >= $count) {
         $query = 'SELECT id, latitude as lat, longitude as lon, count(*) as count, visible_dt as date, description' . ' FROM kwalbum_items' . $where_query . ' GROUP BY latitude, longitude' . ' ORDER BY latitude' . ' LIMIT ' . $limit;
         $result = DB::query(Database::SELECT, $query)->execute();
         foreach ($result as $row) {
             $row['group'] = false;
             $data[] = $row;
         }
     } else {
         $query = 'SELECT AVG(latitude) as lat, AVG(longitude) as lon' . ' FROM kwalbum_items' . $where_query . ' LIMIT 1';
         $result = DB::query(Database::SELECT, $query)->execute();
         $row = $result[0];
         $row['group'] = true;
         $row['count'] = $count;
         $data[] = $row;
     }
 }
Пример #3
0
 /**
  * Check filename, check/set filetype, save
  */
 public function save_existing_file()
 {
     $item = $this->_item;
     // TODO: get path
     // $item->path = ???
     // Do not add/save again if the file is already in the database
     if (!Model_Kwalbum_Item::check_unique_filename($item->path, $item->filename)) {
         return false;
     }
     $item->type = $this->get_filetype($item->filename);
     return $this->save();
 }
Пример #4
0
 public function action_admin()
 {
     $view = new View('kwalbum/browse/index');
     Model_Kwalbum_Item::append_where('hide_level', 5);
     $view->items = Model_Kwalbum_Item::get_thumbnails($this->page_number, $this->in_edit_mode);
     $this->template->content = $view;
     $this->template->title = 'browsing admin permissioned';
 }
Пример #5
0
 public function action_GetMapItems()
 {
     $zoom = (int) $_GET["z"];
     if ($zoom == 17) {
         $limit = 20;
     } else {
         $limit = 10;
     }
     $where = Model_Kwalbum_Item::get_where_query();
     if (!$where) {
         $where = ' WHERE 1=1 ';
     }
     $data = array();
     Model_Kwalbum_Item::getMarkers((double) $_GET["l"], (double) $_GET["r"], (double) $_GET["t"], (double) $_GET["b"], $where, $data, $limit, 1);
     echo "point\ttype\ttitle\tdescription";
     foreach ($data as $d) {
         echo "\n{$d['lon']},{$d['lat']}\t";
         if ($d['group']) {
             echo "g\t{$d['count']}\t{$zoom}";
         } else {
             echo "i\t{$d['id']}\t{$d['date']}";
         }
     }
 }