Exemplo n.º 1
0
 public function isManager($collection_ascii_id)
 {
     $url = $this->config->getAppSetting('remote_url') . '/manager/' . $collection_ascii_id . '/' . $this->eid . '.json';
     $res = Dase_Http::get($url);
     if ('200' == $res[0]) {
         $data = Dase_Json::toPhp($res[1]);
         if (isset($data['auth_level'])) {
             return $data['auth_level'];
         }
     }
     return false;
 }
Exemplo n.º 2
0
 public function getCollections($r)
 {
     $user = $r->getUser();
     //if no collections, redirect to archive admin screen
     //will force login screen for non-superusers if no collections
     $c = new Dase_DBO_Collection($this->db);
     if (!$c->findCount() && $user && $user->is_superuser) {
         $r->renderRedirect('admin');
     }
     $tpl = new Dase_Template($r);
     //$feed = Dase_Atom_Feed::retrieve($r->app_root.'/collections.atom');
     //$tpl->assign('collections',$feed);
     $res = Dase_Http::get($r->app_root . '/collections.json');
     $collections = Dase_Json::toPhp($res[1]);
     $tpl->assign('collections', $collections);
     $r->renderResponse($tpl->fetch('collection/list.tpl'));
 }
Exemplo n.º 3
0
 /**
  * will ingest file if there is one
  */
 public function postToItems($r)
 {
     $this->user = $r->getUser('http');
     if (!$this->user->is_admin) {
         $r->renderError(401, 'no go unauthorized');
     }
     $content_type = $r->getContentType();
     if ('application/json' != $content_type) {
         //$r->renderError(415,'cannot accept '.$content_type);
         return $this->_processFile($r);
     }
     $json_data = Dase_Json::toPhp($r->getBody());
     if (!isset($json_data['title'])) {
         $r->renderError(415, 'incorrect json format');
     }
     //create new item
     $item = new Dase_DBO_Item($this->db);
     $item->title = $json_data['title'];
     if (isset($json_data['body'])) {
         $item->body = $json_data['body'];
     }
     if (isset($json_data['links']['file'])) {
         $file_url = $json_data['links']['file'];
         $ext = strtolower(pathinfo($file_url, PATHINFO_EXTENSION));
         $mime_type = Dase_Http_Request::$types[$ext];
         $base_dir = $this->config->getMediaDir();
         $basename = Dase_Util::dirify(pathinfo($file_url, PATHINFO_FILENAME));
         $newname = $this->_findNextUnique($base_dir, $basename, $ext);
         $new_path = $base_dir . '/' . $newname;
         //move file to new home
         file_put_contents($new_path, file_get_contents($file_url));
         chmod($new_path, 0775);
         $size = @getimagesize($new_path);
         $item->name = $newname;
         if (!$item->title) {
             $item->title = $item->name;
         }
         $item->file_url = 'file/' . $item->name;
         $item->filesize = filesize($new_path);
         $item->mime = $mime_type;
         $parts = explode('/', $mime_type);
         if (isset($parts[0]) && 'image' == $parts[0]) {
             $thumb_path = $base_dir . '/thumb/' . $newname;
             $thumb_path = str_replace('.' . $ext, '.jpg', $thumb_path);
             $command = CONVERT . " \"{$new_path}\" -format jpeg -resize '100x100 >' -colorspace RGB {$thumb_path}";
             $exec_output = array();
             $results = exec($command, $exec_output);
             if (!file_exists($thumb_path)) {
                 //Dase_Log::info(LOG_FILE,"failed to write $thumb_path");
             }
             chmod($thumb_path, 0775);
             $newname = str_replace('.' . $ext, '.jpg', $newname);
             $item->thumbnail_url = 'file/thumb/' . $newname;
         } else {
             $item->thumbnail_url = 'www/images/mime_icons/' . Dase_File::$types_map[$mime_type]['size'] . '.png';
         }
         if (isset($size[0]) && $size[0]) {
             $item->width = $size[0];
         }
         if (isset($size[1]) && $size[1]) {
             $item->height = $size[1];
         }
     } else {
         //meaning no file
         if (!$item->title) {
             $item->title = substr($item->body, 0, 20);
         }
         $item->name = $this->_findUniqueName(Dase_Util::dirify($item->title));
         $item->thumbnail_url = 'www/images/mime_icons/content.png';
     }
     $item->created_by = $this->user->eid;
     $item->created = date(DATE_ATOM);
     $item->updated_by = $this->user->eid;
     $item->updated = date(DATE_ATOM);
     $item->url = 'item/' . $item->name;
     if ($item->insert()) {
         $r->renderOk('added item');
     } else {
         $r->renderError(400);
     }
 }
Exemplo n.º 4
0
 public function get()
 {
     $url = $this->getUrl();
     $res = Dase_Http::get($url);
     return Dase_Json::toPhp($res[1]);
 }
Exemplo n.º 5
0
 public static function get($r, $name)
 {
     $url = $r->app_root . '/set/' . $name . '.json';
     return Dase_Json::toPhp(file_get_contents($url));
 }
Exemplo n.º 6
0
 public function getExerciseEdit($r)
 {
     $t = new Dase_Template($r);
     $ex = new Dase_DBO_Exercise($this->db);
     if (!$ex->load($r->get('id'))) {
         $r->renderRedirect('home');
     }
     if ($this->user->eid != $ex->creator_eid) {
         $r->renderError(401, 'unauthorized');
     }
     // media
     $media_url = "https://dase.laits.utexas.edu/search.json?q=&collection_ascii_id=hdportal&max=999";
     $resp = Dase_Http::get($media_url);
     $data = Dase_Json::toPhp($resp[1]);
     $t->assign('feed', $data);
     // all categories
     $cset = array();
     $ex->getCreator();
     $ex->getLines();
     $ex->getSet();
     $t->assign('exercise', $ex);
     $t->assign('exercise_sets', Dase_DBO_ExerciseSet::getAll($this->db));
     $r->renderResponse($t->fetch('exercise_edit.tpl'));
 }
Exemplo n.º 7
0
 public function putItem($r)
 {
     $user = $r->getUser('http');
     if ($this->item && !$user->can('write', $this->item)) {
         $r->renderError(401, 'cannot update item');
     }
     if (!$this->item) {
         $collection = Dase_DBO_Collection::get($this->db, $r->get('collection_ascii_id'));
         if (!$user->can('write', $collection)) {
             $r->renderError(401, 'cannot update collection');
         }
     }
     //just in case, save a copy in 'deleted' media dir
     if ($this->item) {
         $this->item->saveCopy(MEDIA_DIR);
     }
     $content_type = $r->getContentType();
     if ('application/atom+xml;type=entry' == $content_type || 'application/atom+xml' == $content_type) {
         $raw_input = $r->getBody();
         $client_md5 = $r->getHeader('Content-MD5');
         //if Content-MD5 header isn't set, we just won't check
         if ($client_md5 && md5($raw_input) != $client_md5) {
             $r->renderError(412, 'md5 does not match');
         }
         try {
             $item_entry = Dase_Atom_Entry::load($raw_input, 'item');
         } catch (Exception $e) {
             Dase_Log::debug(LOG_FILE, 'item handler error: ' . $e->getMessage());
             $r->renderError(400, 'bad xml');
         }
         if ('item' != $item_entry->entrytype) {
             //$item_entry->setEntryType('item');
             $r->renderError(400, 'must be an item entry');
         }
         $item = $item_entry->update($this->db, $r);
         if ($item) {
             $r->renderOk('item has been updated');
         } else {
             $r->renderError(500, 'item not updated');
         }
     } elseif ('application/json' == $content_type) {
         if (!$this->item) {
             $this->item = $collection->createNewItem($r->get('serial_number'));
         }
         //todo: this only updates metadata, does nothing to media (prob OK)
         $item_data = Dase_Json::toPhp($r->getBody());
         if (isset($item_data['metadata']) && count($item_data['metadata'])) {
             $this->item->deleteValues();
             //todo WILL this mess up VRC module??
             //metadata
             if (isset($item_data['metadata_extended'])) {
                 foreach ($item_data['metadata_extended'] as $key => $vals) {
                     foreach ($vals['values'] as $val) {
                         $text = $val['text'];
                         if (isset($val['modifier'])) {
                             $mod = $val['modifier'];
                         } else {
                             $mod = '';
                         }
                         if (isset($val['url'])) {
                             $url = $val['url'];
                         } else {
                             $url = '';
                         }
                         $this->item->setValue($key, $text, $url, $mod);
                     }
                 }
             } else {
                 foreach ($item_data['metadata'] as $key => $vals) {
                     foreach ($vals as $val) {
                         $this->item->setValue($key, $val);
                     }
                 }
             }
             $this->item->buildSearchIndex();
             $r->renderOk('item has been updated');
         }
         $r->renderError(400, 'must be a json item');
     } else {
         $r->renderError(415, 'cannot accept ' . $content_type);
     }
     $r->renderError(500, 'something went wrong');
 }
Exemplo n.º 8
0
 private function _newJsonItem($r)
 {
     $user = $r->getUser('http');
     if (!$user->can('write', $this->collection)) {
         $r->renderError(401, 'no go unauthorized');
     }
     $json = $r->getBody();
     $client_md5 = $r->getHeader('Content-MD5');
     //if Content-MD5 header isn't set, we just won't check
     if ($client_md5 && md5($json) != $client_md5) {
         $r->renderError(412, 'md5 does not match');
     }
     $slug = $r->slug ? $r->slug : '';
     $sernum = Dase_Util::makeSerialNumber($slug);
     try {
         $item = $this->collection->createNewItem($sernum, $user->eid);
         $item_data = Dase_Json::toPhp($json);
         //item type
         if (isset($item_data['item_type'])) {
             $item->setItemType($item_data['item_type']);
         }
         $metadata = $item_data['metadata'];
         foreach ($metadata as $key => $vals) {
             foreach ($vals as $val) {
                 $item->setValue($key, $val);
             }
         }
         $item->buildSearchIndex();
         header("HTTP/1.1 201 Created");
         header("Content-Type: application/atom+xml;type=entry;charset='utf-8'");
         header("Location: " . $r->app_root . "/item/" . $r->get('collection_ascii_id') . "/" . $item->serial_number . '.atom');
         echo $item->asAtomEntry($r->app_root);
         exit;
     } catch (Dase_Exception $e) {
         $r->renderError(409, $e->getMessage());
     }
 }