Ejemplo n.º 1
0
 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();
 }
Ejemplo n.º 2
0
 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();
 }
Ejemplo n.º 3
0
 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);
 }
Ejemplo n.º 4
0
 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();
 }
Ejemplo n.º 5
0
 public function getRecentUploadsAtom($r)
 {
     //todo: implement http authorization!
     $items = new Dase_DBO_Item($this->db);
     $items->created_by_eid = $this->user->eid;
     $items->collection_id = Dase_DBO_Collection::get($this->db, $r->get('collection_ascii_id'))->id;
     $items->orderBy('created DESC');
     if ($r->has('limit')) {
         $limit = $r->get('limit');
     } else {
         $limit = 50;
     }
     $items->setLimit($limit);
     $feed = new Dase_Atom_Feed();
     $feed->setTitle('Recent Uploads by ' . $this->user->eid);
     $feed->setId($r->app_root . 'user/' . $this->user->eid . '/' . $r->get('collection_ascii_id') . '/recent');
     $feed->setFeedType('items');
     $feed->setUpdated(date(DATE_ATOM));
     $feed->addAuthor();
     foreach ($items->find() as $item) {
         $item = clone $item;
         $item->injectAtomEntryData($feed->addEntry('item'), $r->app_root);
     }
     $r->renderResponse($feed->asXml());
 }
Ejemplo n.º 6
0
 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;
 }
Ejemplo n.º 7
0
 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();
 }
Ejemplo n.º 8
0
 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;
 }
Ejemplo n.º 9
0
 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();
 }
Ejemplo n.º 10
0
 public function getItemsMarkedToBeDeletedAtom($r)
 {
     $feed = new Dase_Atom_Feed();
     $feed->setTitle($this->collection->collection_name . ' items to be deleted');
     $feed->setId(Dase_Atom::getNewId());
     $items = new Dase_DBO_Item($this->db);
     $items->collection_id = $this->collection->id;
     $items->status = 'delete';
     foreach ($items->find() as $item) {
         $item = clone $item;
         $entry = $feed->addEntry();
         $entry->addLink($r->app_root . '/item/' . $this->collection->ascii_id . '/' . $item->serial_number, "http://daseproject.org/relation/search-item");
         $item->injectAtomEntryData($entry, $r->app_root);
     }
     $r->renderResponse($feed->asXml());
 }
Ejemplo n.º 11
0
 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();
 }