コード例 #1
0
ファイル: user.php プロジェクト: hkilter/OpenSupplyChains
 public function action_index($identifier = false)
 {
     // TODO: cache this crap
     if (!$identifier) {
         Message::instance()->set('No user specified.');
         return $this->request->redirect('');
     }
     if (is_numeric($identifier)) {
         // pass
         $user = ORM::factory('user', $identifier);
     } else {
         $user = ORM::factory('user')->where('username', '=', $identifier)->find();
     }
     if ($user->loaded()) {
         $user = (object) $user->as_array();
         unset($user->password);
         $user->avatar = Gravatar::avatar($user->email, 128);
         unset($user->email);
         $this->template->user = $user;
         $pg = isset($_GET['p']) && (int) $_GET['p'] ? $_GET['p'] : 1;
         $pg = max($pg, 1);
         $l = 10;
         $q = array('user' => $user->id, 'l' => $l, 'o' => ($pg - 1) * $l, 'p' => $pg, 'recent' => 'yes');
         $r = Sourcemap_Search::find($q);
         $this->template->search_result = $r;
         $p = Pagination::factory(array('current_page' => array('source' => 'query_string', 'key' => 'p'), 'total_items' => $r->hits_tot, 'items_per_page' => $r->limit, 'view' => 'pagination/basic'));
         $this->template->pager = $p;
         $this->template->supplychains = $r->results;
     } else {
         Message::instance()->set('That user doesn\'t exist.');
         return $this->request->redirect('');
     }
 }
コード例 #2
0
ファイル: search.php プロジェクト: hkilter/OpenSupplyChains
 public function action_get()
 {
     $t = Request::instance()->param('id', 'simple');
     // "id" == "type"
     try {
         $this->response = Sourcemap_Search::find($_GET, $t);
     } catch (Exception $e) {
         $this->_not_found('What are you trying to search?' . $e);
     }
 }
コード例 #3
0
ファイル: sitemap.php プロジェクト: hkilter/OpenSupplyChains
 public function action_index()
 {
     $cache_key = 'sourcemap-sitemap';
     $ttl = 60 * 60 * 24;
     if ($cached = Cache::instance()->get($cache_key)) {
         $xml = $cached;
     } else {
         // Sitemap instance.
         $sitemap = new Sitemap();
         // basics
         $urls = array('home' => array('', 0.9, 'daily', time()), 'register' => array('register/', 0.6, 'yearly'), 'browse' => array('browse/', 0.7, 'daily', time()), 'login' => array('auth/login', 0.5, 'yearly'), 'about' => array('info/', 0.7, 'monthly'), 'api' => array('info/api', 0.7, 'monthly'), 'contact' => array('info/contact', 0.8, 'monthly'));
         // categories
         $cats = Sourcemap_Taxonomy::arr();
         $nms = array();
         foreach ($cats as $i => $cat) {
             $slug = Sourcemap_Taxonomy::slugify($cat->name);
             $urls['browse-' . $cat->name] = array('browse/' . $slug . '/', 0.7);
         }
         // public maps
         $o = 0;
         $l = 100;
         while (($results = Sourcemap_Search::find(array('o' => $o, 'l' => $l))) && $results->hits_ret) {
             foreach ($results->results as $i => $r) {
                 $urls['sc-' . $r->id] = array('view/' . $r->id, 0.5, 'daily', $r->modified);
             }
             $o += $l;
         }
         $defaults = array(false, 0.5, 'daily', false);
         foreach ($urls as $k => $urld) {
             foreach ($defaults as $i => $d) {
                 if (!isset($urld[$i])) {
                     $urld[$i] = $d;
                 }
             }
             list($loc, $priority, $freq, $lastmod) = $urld;
             $new_url = new Sitemap_URL();
             $new_url->set_loc(URL::site($loc, true))->set_priority($priority)->set_change_frequency($freq);
             if ($lastmod) {
                 $new_url->set_last_mod($lastmod);
             }
             $sitemap->add($new_url);
         }
         $xml = $sitemap->render();
         Cache::instance()->set($cache_key, $xml, $ttl);
     }
     header('Content-Type: application/xml');
     $this->response = $xml;
     die($this->response);
 }
コード例 #4
0
ファイル: welcome.php プロジェクト: hkilter/OpenSupplyChains
 public function action_index()
 {
     $this->layout->scripts = array('sourcemap-core', 'sourcemap-welcome');
     $this->layout->styles = $this->default_styles;
     $this->layout->styles[] = 'sites/default/assets/styles/slider.less';
     $this->layout->page_title = 'Sourcemap: The Crowdsourced Directory of Product Supply Chains and Carbon Footprints';
     $recent = Sourcemap_Search::find(array('recent' => 'yes', 'l' => 4));
     $popular = Sourcemap_Search::find(array('comments' => 'yes', 'favorited' => 'yes', 'l' => 4));
     $featured = Sourcemap_Search::find(array('featured' => 'yes', 'l' => 4));
     $morefeatured = Sourcemap_Search::find(array('featured' => 'yes', 'l' => 2, 'o' => 0));
     $this->template->recent = $recent->results;
     $this->template->popular = $popular->results;
     $this->template->featured = $featured->results;
     $this->template->morefeatured = $morefeatured->results;
     $this->template->news = Blognews::fetch(4);
 }
コード例 #5
0
ファイル: search.php プロジェクト: hkilter/OpenSupplyChains
 public function action_index()
 {
     $this->layout->scripts = array('sourcemap-core');
     $defaults = array('q' => false, 'p' => 1, 'l' => 15);
     $params = $_GET;
     if (strtolower(Request::$method) == 'post') {
         $params = $_POST;
     }
     //$params = array_merge($defaults, $params);
     $search_params = $defaults;
     foreach ($search_params as $k => $v) {
         if (isset($params[$k])) {
             $search_params[$k] = $params[$k];
         }
     }
     $r = Sourcemap_Search::find($search_params);
     $this->template->search_result = $r;
     $this->layout->page_title = 'Search results for [' . $search_params['q'] . ']';
     $p = Pagination::factory(array('current_page' => array('source' => 'q', 'key' => 'p'), 'total_items' => $r->hits_tot, 'items_per_page' => $r->limit, 'view' => 'pagination/basic', 'url_params' => $search_params));
     $this->template->pager = $p;
 }
コード例 #6
0
ファイル: browse.php プロジェクト: hkilter/OpenSupplyChains
 public function action_index($category = false)
 {
     $this->layout->scripts = array('sourcemap-core');
     $this->layout->page_title = 'Browsing supply chains';
     $cats = Sourcemap_Taxonomy::arr();
     $nms = array();
     foreach ($cats as $i => $cat) {
         $nms[Sourcemap_Taxonomy::slugify($cat->name)] = $cat;
     }
     $this->template->taxonomy = Sourcemap_Taxonomy::load_tree();
     $defaults = array('q' => false, 'p' => 1, 'l' => 20);
     $params = $_GET;
     if (strtolower(Request::$method) == 'post') {
         $params = $_POST;
     }
     $params = array_merge($defaults, $params);
     $params['recent'] = 'yes';
     $params['l'] = 20;
     if ($category && isset($nms[$category])) {
         $slug = $category;
         $category = $nms[$category];
         $this->template->category = $category;
         $params['c'] = $category->name;
         $this->layout->page_title .= ' - ' . $category->title;
     } elseif ($category) {
         Message::instance()->set('"' . $category . '" is not a valid category slug.');
         return $this->request->redirect('browse');
     } else {
         $this->template->category = false;
     }
     $r = Sourcemap_Search::find($params);
     $p = Pagination::factory(array('current_page' => array('source' => 'query_string', 'key' => 'p'), 'total_items' => $r->hits_tot, 'items_per_page' => $r->limit, 'view' => 'pagination/basic'));
     $this->template->primary = $r;
     $this->template->pager = $p;
     $params['l'] = 1;
     $this->template->favorited = Sourcemap_Search_Simple::find($params + array('favorited' => 'yes'));
     $this->template->discussed = Sourcemap_Search_Simple::find($params + array('comments' => 'yes'));
     $this->template->interesting = Sourcemap_Search_Simple::find($params + array('favorited' => 'yes', 'comments' => 'yes'));
     $this->template->recent = Sourcemap_Search_Simple::find($params + array('recent' => 'yes'));
 }