function asAtom($app_root) { $item = $this->getItem(); $tag = $this->getTag(); $feed = new Dase_Atom_Feed(); if (is_numeric($item->updated)) { $updated = date(DATE_ATOM, $item->updated); } else { $updated = $item->updated; } $feed->setUpdated($updated); $feed->setTitle($item->getTitle()); $feed->setId($app_root . '/tag/item/' . $tag->id . '/' . $this->id); $feed->setGenerator('DASe', 'http://daseproject.org', '1.0'); $feed->addAuthor($tag->eid); //$feed->addCategory($tag->type,"http://daseproject.org/category/tag_type",$tag->type); $feed->addCategory('set', "http://daseproject.org/category/tag_type"); //$feed->addLink($tag->getUrl($app_root),"http://daseproject.org/relation/feed-link"); $feed->addLink($tag->getUrl($app_root), "up"); $tag_item_id_array = $tag->getTagItemIds(); $position = array_search($this->id, $tag_item_id_array) + 1; $feed->addCategory($position, "http://daseproject.org/category/position"); if (1 == $position) { $prev_id = array_pop($tag_item_id_array); array_push($tag_item_id_array, $prev_id); //because array_pop shortened array } else { $prev_id = $tag_item_id_array[$position - 2]; } if (isset($tag_item_id_array[$position])) { $next_id = $tag_item_id_array[$position]; } else { $next_id = $tag_item_id_array[0]; } //overloading opensearch elements here $feed->setOpensearchTotalResults($tag->item_count); $feed->setOpensearchQuery($tag->name); //$feed->addLink($tag->getLink().'/'.$prev_id,"previous"); //$feed->addLink($tag->getLink().'/'.$next_id,"next"); $feed->addLink($app_root . '/tag/item/' . $tag->id . '/' . $this->id . '.atom', "self"); $feed->addLink($app_root . '/tag/item/' . $tag->id . '/' . $prev_id, "previous"); $feed->addLink($app_root . '/tag/item/' . $tag->id . '/' . $next_id, "next"); $feed->setFeedType('tagitem'); //tag name goes in subtitle, so doesn't need to be in category $feed->setSubtitle($tag->name . ' ' . $position . ' of ' . count($tag_item_id_array)); //regenerated!!! (should cache) $entry = $item->injectAtomEntryData($feed->addEntry(), $app_root); //very strange to use summary for annotation (?) $entry->setSummary($this->annotation); return $feed->asXml(); }
public function getAnswer($r) { $ident = $r->get('identifier'); $search_result = Dase_Atom_Feed::retrieve($r->app_root . '/search.atom?c=dase_help&q=@identifier:"' . $ident . '"&limit=100'); foreach ($search_result->entries as $e) { $meta = $e->getMetadata('answer'); $r->renderResponse($meta['text']); } $r->renderError(401); }
function __get($var) { //allows smarty to invoke function as if getter $classname = get_class($this); $method = 'get' . ucfirst($var); if (method_exists($classname, $method)) { return $this->{$method}(); } else { return parent::__get($var); } }
public static function retrieve($url, $user = '', $pwd = '') { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //do not need to verify certificate //from http://blog.taragana.com/index.php/archive/how-to-use-curl-in-php-for-authentication-and-ssl-communication/ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //this will NOT work in safemode curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); if ($user && $pwd) { curl_setopt($ch, CURLOPT_USERPWD, "{$user}:{$pwd}"); } $xml = curl_exec($ch); curl_close($ch); //beware tight coupling to dase error text!!! if (0 === strpos($xml, 'DASe Error')) { return false; } //for debugging if (isset($_GET['showfeed'])) { print $xml; exit; } $dom = new DOMDocument('1.0', 'utf-8'); if (!$xml) { print "an error has occurred"; exit; } //error entry if (!@$dom->loadXML($xml)) { $entry = new Dase_Atom_Feed(); $entry->setTitle($xml); print $entry->asXml(); exit; return $entry; } return self::_init($dom); }
public static function listAsAtom($db, $app_root) { $cm = new Dase_DBO_CollectionManager($db); $cms = $cm->find(); $feed = new Dase_Atom_Feed(); $feed->setTitle('DASe Collection Managers'); $feed->setId($app_root . '/admin/managers'); //fix to be latest update $feed->setUpdated(date(DATE_ATOM)); $feed->addAuthor(); $feed->addLink($app_root . '/admin/managers.atom', 'self'); $feed->addCategory($app_root, "http://daseproject.org/category/base_url"); foreach ($cms as $manager) { $entry = $feed->addEntry(); $manager->injectAtomEntryData($entry, $app_root); } return $feed->asXml(); }
static function listAsAtom($db, $app_root, $public_only = false) { $c = new Dase_DBO_Collection($db); $c->orderBy('collection_name'); if ($public_only) { $c->is_public = 1; } $cs = $c->find(); $feed = new Dase_Atom_Feed(); $feed->setTitle('DASe Collections'); $feed->setId($app_root); $feed->setFeedType('collection_list'); $feed->setUpdated(date(DATE_ATOM)); $feed->addAuthor('DASe (Digital Archive Services)', 'http://daseproject.org'); $feed->addLink($app_root . '/collections.atom', 'self'); $feed->addCategory($app_root, "http://daseproject.org/category/base_url"); foreach ($cs as $coll) { $coll->injectAtomEntryData($feed->addEntry(), $app_root); } return $feed->asXml(); }
public function postToCreateSample($r) { $resp = array(); $url = "http://daseproject.org/collection/sample.atom"; $feed = Dase_Atom_Feed::retrieve($url); $coll_ascii_id = $feed->getAsciiId(); $feed->ingest($r, true); $cm = new Dase_DBO_CollectionManager($this->db); $cm->dase_user_eid = $u->eid; $cm->collection_ascii_id = $coll_ascii_id; $cm->auth_level = 'superuser'; $cm->created = date(DATE_ATOM); $cm->insert(); $login_url = APP_ROOT . '/login/form'; }
function _smarty_dase_atom_feed_sortby(Dase_Atom_Feed $feed, $att) { return $feed->sortBy($att); }
public function getSearch($r) { $r->checkCache(); $tpl = new Dase_Template($r); //default slidehow max of 100 $json_url = $r->app_root . '/' . $r->url . '&format=json&max=100'; $tpl->assign('json_url', $json_url); $feed_url = $r->app_root . '/' . $r->url . '&format=atom'; $tpl->assign('feed_url', $feed_url); $feed = Dase_Atom_Feed::retrieve($feed_url); //single hit goes directly to item $count = $feed->getCount(); if (1 == $count) { //todo use preg_replace and guarentee only one replacement $url = str_replace('search?', 'search/item?', $r->url); $r->renderRedirect($r->app_root . '/' . $url . '&num=1'); } if (0 == $count) { $coll = $r->get('collection_ascii_id'); if (!$coll) { //won't go back to collection page unless //just one collection is being searched $coll_array = $r->get('c', true); if (1 == count($coll_array)) { $coll = $coll_array[0]; } } if ($coll) { $params['msg'] = 'no items found'; $params['failed_query'] = $feed->getQuery(); $r->renderRedirect($r->app_root . '/collection/' . $coll, $params); } else { $params['msg'] = 'no items found'; $params['failed_query'] = $feed->getQuery(); $r->renderRedirect($r->app_root . '/collections', $params); } } $end = $this->start + $this->max; if ($end > $count) { $end = $count; } $tpl->assign('start', $this->start); $tpl->assign('end', $end); $tpl->assign('sort', $r->get('sort')); $tpl->assign('items', $feed); if ('list' == $r->get('display')) { $tpl->assign('display', 'list'); } else { $tpl->assign('display', 'grid'); } $r->renderResponse($tpl->fetch('item_set/search.tpl')); }
public function getCart($r) { $u = $this->user; $tag = new Dase_DBO_Tag($this->db); $tag->dase_user_id = $u->id; $tag->type = 'cart'; if ($tag->findOne()) { $t = new Dase_Template($r); $json_url = $r->app_root . '/tag/' . $tag->id . '.json'; $t->assign('json_url', $json_url); $t->assign('items', Dase_Atom_Feed::retrieve($r->app_root . '/tag/' . $tag->id . '.atom', $u->eid, $u->getHttpPassword())); $t->assign('is_admin', 1); if ('list' == $u->display) { $t->assign('display', 'list'); } if ($u->can('admin', $tag) && 'hide' != $u->controls_status) { $t->assign('bulkedit', 1); } $r->renderResponse($t->fetch('item_set/tag.tpl')); } else { $r->renderError(404); } }
function asAtom($app_root, $authorized_links = false) { $this->user || $this->getUser(); $feed = new Dase_Atom_Feed(); $feed->setTitle($this->name); if ($this->description) { $feed->setSubtitle($this->description); } $feed->setId($app_root . '/tag/' . $this->user->eid . '/' . $this->ascii_id); $feed->setUpdated($this->updated); $feed->addAuthor($this->user->eid); $feed->setFeedType('tag'); $feed->addLink($app_root . '/tag/' . $this->user->eid . '/' . $this->ascii_id . '.atom', 'self'); $feed->addLink($app_root . '/tag/' . $this->user->eid . '/' . $this->ascii_id, 'alternate'); $feed->addLink($app_root . '/tag/' . $this->user->eid . '/' . $this->ascii_id . '/list', 'alternate', 'text/html', '', 'list'); $feed->addLink($app_root . '/tag/' . $this->user->eid . '/' . $this->ascii_id . '/grid', 'alternate', 'text/html', '', 'grid'); $feed->addLink($app_root . '/tag/' . $this->user->eid . '/' . $this->ascii_id . '.json', 'alternate', 'application/json', '', 'slideshow'); $feed->addCategory($this->type, "http://daseproject.org/category/tag_type", $this->type); if ($this->is_public) { $pub = "public"; } else { $pub = "private"; } $feed->addCategory($pub, "http://daseproject.org/category/visibility"); $feed->addCategory($this->background, "http://daseproject.org/category/background"); /* TO DO categories: admin_coll_id, updated, created, master_item, etc */ $setnum = 0; $collections_array = array(); foreach ($this->getTagItems() as $tag_item) { $tag_item->persist(true); $item_unique = $tag_item->p_collection_ascii_id . '/' . $tag_item->p_serial_number; //lets us determine if tag includes items in only one collection $collections_array[$tag_item->p_collection_ascii_id] = 1; if ($authorized_links) { //fresh, not from cache $item = $tag_item->getItem(); $entry = $feed->addEntry(); $entry = $item->injectAtomEntryData($entry, $app_root, true); } else { $entry = $feed->addItemEntryByItemUnique($this->db, $item_unique, $app_root); } if ($entry) { $setnum++; $entry->addCategory($setnum, 'http://daseproject.org/category/position'); $entry->addCategory($tag_item->id, 'http://daseproject.org/category/tag_item_id'); $entry->addLink($app_root . '/tag/' . $this->user->eid . '/' . $this->ascii_id . '/' . $tag_item->id, "http://daseproject.org/relation/search-item"); $entry->addLink($app_root . '/tag/' . $this->user->eid . '/' . $this->ascii_id . '/' . $tag_item->id . '/annotation', "http://daseproject.org/relation/edit-annotation"); if ($tag_item->annotation) { $entry->setSummary($tag_item->annotation); } } else { //remove tag_item $log_text = "SMOKING GUN Ann Johns mystery: tried removing {$item_unique} from set {$this->eid}/{$this->ascii_id}"; Dase_Log::info(LOG_FILE, $log_text); //$tag_item->delete();; //$this->resortTagItems(); //$this->updateItemCount(); } } if (1 == count($collections_array)) { $coll = array_pop(array_keys($collections_array)); $feed->addCategory($coll, "http://daseproject.org/category/collection"); } return $feed->asXml(); }
public function getSearch($r) { $tpl = new Dase_Template($r); $courses = Dase_Atom_Categories::load(file_get_contents($r->app_root . '/sets/utexas/courses.cats')); $tpl->assign('courses', $courses); $feed = Dase_Atom_Feed::retrieve($r->app_root . '/tags/search.atom?q=' . $r->get('q')); $tpl->assign('sets', $feed); $tpl->assign('q', $r->get('q')); $r->renderResponse($tpl->fetch('tags/list.tpl')); }
public function getItem($r) { $user = $r->getUser(); if (!$user->can('read', $this->item)) { $r->renderError(401, 'user cannot read this item'); } //a bit inefficient since the setup item get is unecessary, assuming atom feed error reporting $t = new Dase_Template($r); $feed = Dase_Atom_Feed::retrieve($r->app_root . '/item/' . $r->get('collection_ascii_id') . '/' . $r->get('serial_number') . '.atom?type=feed', $user->eid, $user->getHttpPassword()); if ($user->can('write', $this->item)) { $t->assign('is_admin', 1); } $t->assign('item', $feed); $r->renderResponse($t->fetch('item/display.tpl')); }
<?php include 'config.php'; $feed = Dase_Atom_Feed::load('gfromr.atom'); $records = array(); $attributes = array(); $att_count = array(); foreach ($feed->entries as $entry) { $record = array(); $attribute = array(); $etype = $entry->getEntryType(); $search_set = ''; $search = array(); if ('item' == $etype) { $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;
public function getCollection($r) { $tpl = new Dase_Template($r); $tpl->assign('collection', Dase_Atom_Feed::retrieve($r->app_root . '/collection/' . $r->get('collection_ascii_id') . '.atom')); $r->renderResponse($tpl->fetch('collection/browse.tpl')); }
function getTagsAsAtom($app_root) { $feed = new Dase_Atom_Feed(); $feed->setTitle($this->eid . ' sets'); $feed->setId($app_root . '/user/' . $this->eid . '/sets'); $feed->setFeedType('sets'); $feed->setUpdated(date(DATE_ATOM)); $feed->addAuthor(); $tags = new Dase_DBO_Tag($this->db); $tags->dase_user_id = $this->id; $tags->orderBy('updated DESC'); $tag_count_lookup = $this->getTagCountLookup(); foreach ($tags->find() as $tag) { if ($tag->ascii_id) { //compat: make sure tag has ascii_id if (isset($tag_count_lookup[$tag->id])) { $count = $tag_count_lookup[$tag->id]; } else { $count = 0; } $entry = $tag->injectAtomEntryData($feed->addEntry('set'), $this, $app_root); $entry->addCategory($count, "http://daseproject.org/category/item_count"); } } return $feed->asXml(); }
public function atomError($code, $msg = '') { $feed = new Dase_Atom_Feed(); if (isset(self::$codes[$code])) { $message = $code . ' ' . self::$codes[$code]; } $feed->setTitle($message . ' ' . $msg); $feed->addAuthor(); $feed->addCategory('error', 'http://daseproject.org/category/error'); echo $feed->asXml(); exit; }
function injectAtomFeedData(Dase_Atom_Feed $feed, $app_root) { if (!$this->id) { return false; } $c = $this->getCollection(); if (is_numeric($this->updated)) { $updated = date(DATE_ATOM, $this->updated); } else { $updated = $this->updated; } $feed->setUpdated($updated); $feed->setTitle($this->getTitle()); $feed->setId('tag:daseproject.org,2008:' . Dase_Util::getUniqueName()); $feed->addLink($app_root . '/item/' . $this->p_collection_ascii_id . '/' . $this->serial_number . '.atom', 'self'); $feed->addAuthor(); return $feed; }
public function getAttributesFeed($collection_ascii_id, $app_root) { $feed = new Dase_Atom_Feed(); $feed->setTitle($this->name . ' Attributes'); $feed->setId($app_root . '/item_type/' . $collection_ascii_id . '/' . $this->ascii_id . '/attributes'); $feed->setUpdated(date(DATE_ATOM)); foreach ($this->getAttributes() as $att) { $entry = $feed->addEntry('attribute'); $att->injectAtomEntryData($entry, $collection_ascii_id, $app_root); } return $feed->asXml(); }
public function getTagItem($r) { $u = $r->getUser(); $tag_ascii_id = $r->get('tag_ascii_id'); $tag_item_id = $r->get('tag_item_id'); $t = new Dase_Template($r); //$t->assign('item',Dase_Atom_Feed::retrieve($r->app_root.'/tag/'.$u->eid.'/'.$tag_ascii_id.'/'.$tag_item_id.'?format=atom',$u->eid,$u->getHttpPassword())); $t->assign('item', Dase_Atom_Feed::retrieve($r->app_root . '/tag/item/' . $this->tag->id . '/' . $tag_item_id . '?format=atom', $u->eid, $u->getHttpPassword())); $r->renderResponse($t->fetch('item/display.tpl')); }