예제 #1
0
 public function action_view($supplychain_id)
 {
     if (!is_numeric($supplychain_id)) {
         $supplychain_id = $this->_match_alias($supplychain_id);
     }
     $supplychain = ORM::factory('supplychain', $supplychain_id);
     $sc = $supplychain->kitchen_sink($supplychain_id);
     if ($supplychain->loaded()) {
         $current_user_id = Auth::instance()->logged_in() ? (int) Auth::instance()->get_user()->id : 0;
         $owner_id = (int) $supplychain->user_id;
         if ($supplychain->user_can($current_user_id, Sourcemap::READ)) {
             $this->layout->supplychain_id = $supplychain_id;
             // pass supplychain metadeta to template
             $this->template->supplychain_id = $supplychain_id;
             $this->template->supplychain_date = date('F j, Y', $sc->created);
             $this->template->supplychain_name = isset($sc->attributes->title) ? $sc->attributes->title : (isset($sc->attributes->name) ? $sc->attributes->name : "");
             $this->template->supplychain_owner = isset($sc->owner->name) ? $sc->owner->name : "";
             $this->template->supplychain_ownerid = isset($sc->owner->id) ? $sc->owner->id : "";
             $this->template->supplychain_avatar = isset($sc->owner->avatar) ? $sc->owner->avatar : "";
             $this->template->supplychain_desc = isset($sc->attributes->description) ? $sc->attributes->description : "";
             $this->template->supplychain_taxonomy = isset($sc->taxonomy) ? $sc->taxonomy : array();
             $this->template->supplychain_weight = isset($sc->attributes->{'sm:ui:weight'}) ? "checked" : "";
             $this->template->supplychain_co2e = isset($sc->attributes->{"sm:ui:co2e"}) ? "checked" : "";
             $this->template->supplychain_water = isset($sc->attributes->{"sm:ui:water"}) ? "checked" : "";
             $this->template->supplychain_tileset = isset($sc->attributes->{"sm:ui:tileset"}) ? $sc->attributes->{"sm:ui:tileset"} : "";
             $this->layout->page_title = $this->template->supplychain_name;
             $this->template->can_edit = (bool) $supplychain->user_can($current_user_id, Sourcemap::WRITE);
             $this->layout->scripts = array('map-view');
             $this->layout->styles = array('sites/default/assets/styles/reset.css', 'assets/styles/base.less', 'assets/styles/general.less');
             // comments
             $c = $supplychain->comments->find_all();
             $comment_data = array();
             foreach ($c as $i => $comment) {
                 $arr = $comment->as_array();
                 $arr['username'] = $comment->user->username;
                 $arr['avatar'] = Gravatar::avatar($comment->user->email, 32);
                 $comment_data[] = (object) $arr;
             }
             $this->template->comments = $comment_data;
             $this->template->can_comment = (bool) $current_user_id;
             // qrcode url
             $shortener = new Sourcemap_Bitly();
             $shortlink = $shortener->shorten(URL::site('view/' . $supplychain->id, true));
             $qrcode_query = URL::query(array('q' => $shortlink, 'sz' => 3));
             $scaled_qrcode_query = URL::query(array('q' => $shortlink, 'sz' => 16));
             $this->template->short_link = $shortlink;
             $this->template->qrcode_url = URL::site('services/qrencode', true) . $qrcode_query;
             $this->template->scaled_qrcode_url = URL::site('services/qrencode', true) . $scaled_qrcode_query;
         } else {
             Message::instance()->set('That map is private.');
             $this->request->redirect('browse');
         }
     } else {
         Message::instance()->set('That map could not be found.');
         $this->request->redirect('browse');
     }
 }
예제 #2
0
 public function action_get()
 {
     if (isset($_GET['url'])) {
         $this->response = Sourcemap_Bitly::shorten($_GET['url']);
         if (!$this->response) {
             return $this->_bad_request("Request failed.");
         }
     } else {
         return $this->_bad_request("Url required.");
     }
 }