Example #1
0
 /**
  * this method will be called
  * w/ an http delete to '/login' *or* '/login/{eid}'
  *
  */
 public function deleteLogin($r)
 {
     $r->clearCookies();
     //	$r->renderRedirect('login/form');
     $logout_url = $r->app_root . '/logini/form';
     $json = Dase_Json::get(array('location' => $logout_url));
     $r->response_mime_type = 'application/json';
     $r->renderResponse($json);
 }
Example #2
0
 /**
  * this method will be called
  * w/ an http delete to '/login' *or* '/login/{eid}'
  *
  */
 public function deleteLogin($r)
 {
     $r->clearCookies();
     //$return_to = $r->app_root . '/login';
     //$logout_url = 'http://www.google.com/accounts/Logout?continue='.$return_to;
     $logout_url = 'http://www.google.com/accounts/Logout';
     $r->response_mime_type = 'application/json';
     $json = Dase_Json::get(array('location' => $logout_url));
     $r->renderResponse($json);
 }
Example #3
0
 public function getListJson($r)
 {
     $items = new Dase_DBO_Item($this->db);
     $items->orderBy('updated DESC');
     $set = array();
     foreach ($items->find() as $item) {
         $item = clone $item;
         $set[] = $item->asArray($r);
     }
     $r->renderResponse(Dase_Json::get($set));
 }
Example #4
0
 /**
  * this method will be called
  * w/ an http delete to '/login' *or* '/login/{eid}'
  *
  */
 public function deleteLogin($r)
 {
     setcookie('DOC', '', time() - 86400, '/', '.utexas.edu');
     setcookie('FC', '', time() - 86400, '/', '.utexas.edu');
     setcookie('SC', '', time() - 86400, '/', '.utexas.edu');
     setcookie('TF', '', time() - 86400, '/', '.utexas.edu');
     $r->clearCookies();
     $logout_url = $r->app_root . '/login/form';
     $json = Dase_Json::get(array('location' => $logout_url));
     $r->response_mime_type = 'application/json';
     $r->renderResponse($json);
 }
Example #5
0
 public function asJson()
 {
     $set = array();
     $set['name'] = $this->name;
     $set['timestamp'] = $this->timestamp;
     $set['uniq_id'] = $this->uniq_id;
     $set['items'] = array();
     foreach ($this->getItems() as $item) {
         $set['items'][] = $item->text;
     }
     return Dase_Json::get($set);
 }
Example #6
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;
 }
Example #7
0
 public function getManagerJson($r)
 {
     $coll = $r->get('collection_ascii_id');
     $eid = $r->get('eid');
     $cm = Dase_DBO_CollectionManager::get($this->db, $coll, $eid);
     $result = array();
     if ($cm) {
         $result['eid'] = $eid;
         $result['collection_ascii_id'] = $coll;
         $result['auth_level'] = $cm->auth_level;
         $r->renderResponse(Dase_Json::get($result));
     } else {
         $r->renderError(404);
     }
 }
Example #8
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'));
 }
Example #9
0
 /** implicit 1000 limit */
 public function getAttributeValuesJson($r)
 {
     $attr = Dase_DBO_Attribute::get($this->db, $r->get('collection_ascii_id'), $r->get('att_ascii_id'));
     if (!$attr) {
         $r->renderError('404');
     }
     if (0 == $attr->collection_id) {
         //since it is admin att we need to be able to limit to items in this coll
         $values_array = $attr->getDisplayValues($this->collection->ascii_id, $r->get('limit'));
     } else {
         $values_array = $attr->getDisplayValues(null, $r->get('limit'));
     }
     $result['att_name'] = $attr->attribute_name;
     $result['att_ascii'] = $attr->ascii_id;
     $result['coll'] = $r->get('collection_ascii_id');
     $result['values'] = $values_array;
     $json_result = Dase_Json::get($result);
     if ($r->get('callback')) {
         $r->renderResponse($r->get('callback') . '(' . $json_result . ');');
     } else {
         $r->renderResponse($json_result);
     }
 }
Example #10
0
 public function get()
 {
     $url = $this->getUrl();
     $res = Dase_Http::get($url);
     return Dase_Json::toPhp($res[1]);
 }
Example #11
0
 public function postToCreateAdmin($r)
 {
     $resp = array();
     $superusers = $r->superusers;
     $u = clone $r->getUser('none');
     $u->eid = array_shift(array_keys($superusers));
     if ($u->findOne()) {
         $resp['msg'] = "Admin user \"{$u->eid}\" already exists";
         $resp['ok'] = 1;
         $r->renderResponse(Dase_Json::get($resp));
     }
     $u->name = $u->eid;
     if ($u->insert()) {
         $resp['msg'] = "Admin user \"{$u->eid}\" created. (See local_config.php for password)";
         $resp['ok'] = 1;
     } else {
         $resp['msg'] = "There was a problem creating admin user \"{$u->eid}\".";
         $resp['ok'] = 0;
     }
     $r->renderResponse(Dase_Json::get($resp));
 }
Example #12
0
 public function getAttributeDefinedValuesJson($r)
 {
     $att = Dase_DBO_Attribute::get($this->db, $this->collection->ascii_id, $r->get('att_ascii_id'));
     $response = array();
     $def_value_array = $att->getDefinedValues();
     $response['count'] = count($def_value_array);
     $response['input'] = $att->html_input_type;
     $response['defined'] = $def_value_array;
     $r->response_mime_type = 'application/json';
     $r->renderResponse(Dase_Json::get($response));
 }
Example #13
0
 public function getCartJson()
 {
     return Dase_Json::get($this->getCartArray());
 }
Example #14
0
 public function asJson($r)
 {
     return Dase_Json::get($this->asArray($r));
 }
Example #15
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');
 }
Example #16
0
 function asJson()
 {
     //todo: all the opensearch methods
     $feed_array = array('id' => $this->getId(), 'title' => $this->getTitle(), 'subtitle' => $this->getSubtitle(), 'updated' => $this->getUpdated(), 'feedtype' => $this->getFeedtype(), 'rights' => $this->getRights(), 'category' => $this->getCategories(), 'link' => $this->getLinks());
     foreach ($this->getEntries() as $entry) {
         $feed_array['entries'][] = $entry->asArray();
     }
     return Dase_Json::get($feed_array);
 }
Example #17
0
 function asJson()
 {
     return Dase_Json::get($this->asArray());
 }
Example #18
0
 public function getAdminAttributeTalliesJson($r)
 {
     $prefix = $this->db->table_prefix;
     $c = $this->collection;
     $dbh = $this->db->getDbh();
     $sql = "\n\t\t\tSELECT id, ascii_id\n\t\t\tFROM {$prefix}attribute a\n\t\t\tWHERE a.collection_id = 0\n\t\t\t";
     $sth1 = $dbh->prepare($sql);
     $sth1->execute();
     $sql = "\n\t\t\tSELECT count(DISTINCT value_text) \n\t\t\tFROM {$prefix}value v, {$prefix}item i\n\t\t\tWHERE v.attribute_id = ?\n\t\t\tAND v.item_id = i.id\n\t\t\tAND i.collection_id = ? \n\t\t\t";
     $sth2 = $dbh->prepare($sql);
     $tallies = array();
     while ($row = $sth1->fetch()) {
         $sth2->execute(array($row['id'], $c->id));
         $tallies[$row['ascii_id']] = $sth2->fetchColumn();
     }
     $result['tallies'] = $tallies;
     $result['is_admin'] = 1;
     $r->renderResponse(Dase_Json::get($result));
 }
Example #19
0
 public function getSearchJson($r)
 {
     $result = CFSearch::search($this->db, $r->get('q'));
     $r->renderResponse(Dase_Json::get($result));
 }
Example #20
0
        $record['record_title'] = $entry->getTitle();
        $record['serial_number'] = $entry->getSerialNumber();
        $record['enclosure'] = $entry->getEnclosure();
        foreach ($entry->getMetadata() as $ascii => $meta) {
            if (!isset($att_count[$ascii])) {
                $att_count[$ascii] = 1;
            } else {
                $att_count[$ascii]++;
            }
            $record[$ascii] = $meta;
            foreach ($meta['values'] as $v) {
                $search_set .= " {$v}";
            }
        }
        $search[$record['serial_number']] = $search_set;
        $records['searches'][] = $search;
        $records['items'][$record['serial_number']] = $record;
    } else {
        $attribute['title'] = $entry->getTitle();
        $attribute['ascii_id'] = $entry->getAsciiId();
        $attributes[] = $attribute;
    }
}
foreach ($attributes as $a) {
    if (isset($att_count[$a['ascii_id']])) {
        $a['count'] = $att_count[$a['ascii_id']];
        $records['attributes'][] = $a;
    }
}
print Dase_Json::get($records);
Example #21
0
File: DBO.php Project: hillct/lists
 public function asJson()
 {
     Dase_Json::get($this->asArray());
 }
Example #22
0
 public function getRecentUploadsJson($r)
 {
     //todo: implement http authorization!
     $coll = $r->get('collection_ascii_id');
     $items = new Dase_DBO_Item($this->db);
     $items->created_by_eid = $this->user->eid;
     $items->collection_id = Dase_DBO_Collection::get($this->db, $coll)->id;
     $items->orderBy('created DESC');
     if ($r->has('limit')) {
         $limit = $r->get('limit');
     } else {
         $limit = 50;
     }
     $items->setLimit($limit);
     $recent = array();
     foreach ($items->find() as $item) {
         $item = clone $item;
         $recent['a' . $item->serial_number]['title'] = $item->getTitle();
         $recent['a' . $item->serial_number]['thumbnail_href'] = $item->getMediaUrl('thumbnail', $r->app_root);
         $recent['a' . $item->serial_number]['item_record_href'] = $item->getUrl($r->app_root);
     }
     $r->renderResponse(Dase_Json::get($recent));
 }
Example #23
0
 function asJson($app_root)
 {
     $coll_array = array();
     $coll_array['id'] = $app_root . '/collection/' . $this->ascii_id;
     foreach ($this as $k => $v) {
         $coll_array[$k] = $v;
     }
     $coll_array['links'] = array('alternate' => $app_root . '/collection/' . $this->ascii_id);
     $coll_array['title'] = $this->collection_name;
     return Dase_Json::get($coll_array);
 }
Example #24
0
 function asJson($app_root)
 {
     $collection_lookup = Dase_DBO_Collection::getLookupArray($this->db);
     $json_tag;
     $eid = $this->getUser()->eid;
     $json_tag['id'] = $this->getUrl($app_root);
     $json_tag['uri'] = $this->getUrl($app_root);
     $json_tag['links'] = array('self' => $this->getUrl($app_root));
     if ($this->created) {
         $json_tag['updated'] = $this->created;
     } else {
         $json_tag['updated'] = date(DATE_ATOM);
     }
     $json_tag['name'] = $this->name;
     $json_tag['description'] = $this->description;
     $json_tag['background'] = $this->background;
     $json_tag['is_public'] = $this->is_public;
     $json_tag['type'] = $this->type;
     $json_tag['eid'] = $eid;
     foreach ($this->getTagItems() as $tag_item) {
         $item = $tag_item->getItem();
         if (!$item) {
             Dase_Log::debug(LOG_FILE, 'tag_item missing item: ' . $tag_item->id);
             continue;
         }
         $json_item = array();
         $json_item['id'] = $app_root . '/tag/' . $eid . '/' . $this->ascii_id . '/' . $tag_item->id;
         $json_item['links'] = array();
         $json_item['links']['self'] = $app_root . '/tag/' . $eid . '/' . $this->ascii_id . '/' . $tag_item->id;
         $json_item['links']['related'] = $item->getUrl($app_root);
         $json_item['url'] = $app_root . '/tag/' . $eid . '/' . $this->ascii_id . '/' . $tag_item->id;
         $json_item['sort_order'] = $tag_item->sort_order;
         //make sure p_ values are always populated!
         $json_item['item_unique'] = $tag_item->p_collection_ascii_id . '/' . $tag_item->p_serial_number;
         $json_item['size'] = $tag_item->size;
         $json_item['updated'] = $tag_item->updated;
         $json_item['annotation'] = $tag_item->annotation;
         $json_item['title'] = $item->getTitle();
         $json_item['collection_name'] = $collection_lookup[$item->collection_id]['collection_name'];
         $json_item['media'] = array();
         foreach ($item->getMedia() as $m) {
             $json_item['media'][$m['size']] = $app_root . $m['url'];
         }
         $json_item['metadata'] = array();
         foreach ($item->getMetadata() as $meta) {
             $json_item['metadata'][$meta['attribute_name']] = $meta['value_text'];
         }
         $json_tag['items'][] = $json_item;
     }
     return Dase_Json::get($json_tag);
 }
Example #25
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);
     }
 }
Example #26
0
 public function getCommentsJson($app_root, $eid = '')
 {
     $db = $this->db;
     $comments = new Dase_DBO_Comment($db);
     $comments->item_id = $this->id;
     $comments->updated_by_eid = $eid;
     $comments->orderBy('updated DESC');
     $com = array();
     foreach ($comments->find() as $c_obj) {
         $c['id'] = $c_obj->id;
         //$c['updated'] = $c_obj->updated;
         $c['updated'] = date('D M j, Y \\a\\t g:ia', strtotime($c_obj->updated));
         $c['eid'] = $c_obj->updated_by_eid;
         $c['text'] = $c_obj->text;
         $c['url'] = $this->getUrl($app_root) . '/comments/' . $c_obj->id;
         $com[] = $c;
     }
     return Dase_Json::get($com);
 }
Example #27
0
 public function getAttributesJson($collection_ascii_id, $app_root)
 {
     $atts = array();
     foreach ($this->getAttributes() as $att) {
         $a = $att->asArray();
         $a['att_ascii_id'] = $att->ascii_id;
         $a['item_type_ascii'] = $this->ascii_id;
         //$a['attribute_name'] = $att->attribute_name;
         $a['href'] = $att->getUrl($collection_ascii_id, $app_root);
         $atts[] = $a;
     }
     return Dase_Json::get($atts);
 }
Example #28
0
 public function getExerciseJson($r)
 {
     $exercise = new Dase_DBO_Exercise($this->db);
     $exercise->load($r->get('id'));
     $exercise->getCreator();
     $exercise->getQuestions();
     $json = array();
     $json['exercise'] = array();
     $json['exercise']['title'] = $exercise->title;
     $json['exercise']['media_file'] = $exercise->media_file;
     $json['exercise']['creator_eid'] = $exercise->creator_eid;
     $json['exercise']['course'] = $exercise->course;
     $json['exercise']['notes'] = $exercise->notes;
     $json['exercise']['ascii_id'] = $exercise->ascii_id;
     $json['exercise']['is_published'] = $exercise->is_published;
     $json['exercise']['questions'] = array();
     foreach ($exercise->questions as $question) {
         $set = array();
         $set['text'] = $question->text;
         $set['lines'] = array();
         $so = 0;
         foreach ($question->lines as $line) {
             $so += 1;
             $aset = array();
             $aset['text'] = $line->text;
             $aset['sort_order'] = $so;
             $aset['is_correct'] = $line->is_correct;
             $set['lines'][] = $aset;
         }
         $json['exercise']['questions'][] = $set;
     }
     $r->renderResponse(Dase_Json::get($json));
 }
Example #29
0
 function asJson()
 {
     $json = array();
     $json['fixed'] = $this->getFixed();
     $json['scheme'] = $this->getScheme();
     $json['categories'] = $this->getCategories(false);
     return Dase_Json::get($json);
 }
Example #30
0
 public function getCommonKeyvalsJson($r)
 {
     $set = array();
     $common = array();
     foreach ($this->tag->getTagItems() as $ti) {
         $item = $ti->getItem();
         if ($item) {
             if (!isset($set[$item->serial_number])) {
                 $set[$item->serial_number] = array();
             }
             $meta = $item->getMetadata();
             foreach ($meta as $m) {
                 $set[$item->serial_number][$m['attribute_name'] . ' : ' . $m['value_text']] = array($m['ascii_id'], $m['value_text']);
             }
             $last = $set[$item->serial_number];
         }
     }
     //foreach keyval in the last item
     foreach ($last as $ascii_plus_val => $keyval) {
         $common[$ascii_plus_val] = $keyval;
         //iterate through all items checking for same keyval
         foreach ($set as $sernum => $metas) {
             if (!isset($metas[$ascii_plus_val])) {
                 unset($common[$ascii_plus_val]);
             }
         }
     }
     $r->renderResponse(Dase_Json::get($common));
 }