Ejemplo n.º 1
0
 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('');
     }
 }
Ejemplo n.º 2
0
 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);
     }
 }
Ejemplo n.º 3
0
 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);
 }
Ejemplo n.º 4
0
 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);
 }
Ejemplo n.º 5
0
 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;
 }
Ejemplo n.º 6
0
 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'));
 }
Ejemplo n.º 7
0
 public function fetch()
 {
     parent::fetch();
     if (!isset($this->parameters['q'])) {
         $this->parameters['q'] = '';
     }
     $search = ORM::factory('supplychain_search');
     // category filter
     $clause_category = false;
     if (isset($this->parameters['c'])) {
         $cat = $this->parameters['c'];
         $csql = 'select id from category where name ilike \'%\'||:catq||\'%\'';
         $query = DB::query(Database::SELECT, $csql);
         $query->param(':catq', $cat);
         $rows = $query->execute();
         $cat_ids = array();
         foreach ($rows as $i => $row) {
             $cat_ids[] = $row['id'];
             $children = Sourcemap_Taxonomy::load_children($row['id']);
             foreach ($children as $j => $child) {
                 if (!in_array($child->id, $cat_ids)) {
                     $cat_ids[] = $child->id;
                 }
             }
         }
         if ($cat_ids) {
             $search->and_where('category', 'in', $cat_ids);
         } else {
             // pass
         }
     }
     if (isset($this->parameters['q']) && $this->parameters['q']) {
         $qts = preg_split('/\\s+/', $this->parameters['q'], null, PREG_SPLIT_NO_EMPTY);
         $q = array();
         foreach ($qts as $i => $qt) {
             $q[] = $qt;
         }
         if ($q) {
             $search->and_where(DB::expr('to_tsvector(body)'), '@@', DB::expr('plainto_tsquery(\'english\',' . Database::instance()->quote(join(' ', $q)) . ')'));
         }
     }
     // by userid
     if (isset($this->parameters['user']) && (int) $this->parameters['user']) {
         $search->and_where('user_id', '=', $this->parameters['user']);
     }
     $search->reset(false);
     $ct = $search->count_all();
     // featured filter
     if (isset($this->parameters['featured']) && strtolower($this->parameters['featured']) == 'yes') {
         $search->and_where(DB::expr('featured'), 'and', DB::expr('TRUE'));
     }
     // recent filter
     if (isset($this->parameters['recent']) && strtolower($this->parameters['recent']) == 'yes') {
         $search->order_by('created', 'desc');
     }
     // most commented
     if (isset($this->parameters['comments']) && strtolower($this->parameters['comments']) == 'yes') {
         $search->order_by('comments', 'desc');
     }
     // most favorited
     if (isset($this->parameters['favorited']) && strtolower($this->parameters['favorited']) == 'yes') {
         $search->order_by('favorited', 'desc');
     }
     $search->limit($this->limit);
     $search->offset($this->offset);
     $raw = $search->find_all();
     $results = self::prep_rows($raw);
     $this->results->hits_tot = $ct;
     $this->results->results = $results;
     $this->results->limit = $this->limit;
     $this->results->offset = $this->offset;
     $this->results->hits_ret = count($results);
     $this->results->parameters = $this->parameters;
     return $this->results;
 }
Ejemplo n.º 8
0
 public static function cache_key(Sourcemap_Search $s)
 {
     return $s->get_cache_key();
 }
Ejemplo n.º 9
0
<?php

/* Copyright (C) Sourcemap 2011
 * This program is free software: you can redistribute it and/or modify it under the terms
 * of the GNU Affero General Public License as published by the Free Software Foundation,
 * either version 3 of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License along with this
 * program. If not, see <http://www.gnu.org/licenses/>.*/
$data = Sourcemap_Search::Find(array('l' => 4));
if ($data) {
    $results = $data->results;
    $i = 0;
    foreach ($results as $item) {
        ?>
            <div class="preview-badge">
            <a href="view/<?php 
        print $item->id;
        ?>
">
                <img class="preview-map small" src="/map/static/<?php 
        print $item->id;
        ?>
.t.png" alt="" />
            </a>
            </div>
            <h3 class="preview-title">