Example #1
0
 public function getCollection()
 {
     if ($this->collection) {
         return $this->collection;
     }
     $c = new Dase_DBO_Collection($this->db);
     $c->load($this->collection_id);
     $this->collection = $c;
     return $c;
 }
Example #2
0
 function ingest($db, $r, $fetch_enclosures = false)
 {
     $user = $r->getUser();
     $coll_ascii_id = $this->getAsciiId();
     $count = $this->getItemCount();
     $collection_name = $this->getTitle();
     $ascii_id = $this->getAsciiId();
     $c = new Dase_DBO_Collection($db);
     $c->collection_name = $collection_name;
     if (Dase_DBO_Collection::get($db, $ascii_id) || $c->findOne()) {
         //$r->renderError(409,'collection already exists');
         Dase_Log::info(LOG_FILE, 'collection exists ' . $c->collection_name);
         return;
     }
     $c->ascii_id = $ascii_id;
     $c->is_public = 0;
     $c->created = date(DATE_ATOM);
     $c->updated = date(DATE_ATOM);
     if ($c->insert()) {
         $cache = $r->getCache();
         $cache->expire('app_data');
         Dase_Log::info(LOG_FILE, 'created collection ' . $c->collection_name);
         $coll_media_dir = MEDIA_DIR . '/' . $ascii_id;
         if (file_exists($coll_media_dir)) {
             //$r->renderError(409,'collection media archive exists');
             Dase_Log::info(LOG_FILE, 'collection media archive exists');
         } else {
             if (mkdir("{$coll_media_dir}")) {
                 chmod("{$coll_media_dir}", 0775);
                 foreach (Dase_Media::$sizes as $size => $access_level) {
                     mkdir("{$coll_media_dir}/{$size}");
                     Dase_Log::info(LOG_FILE, 'created directory ' . $coll_media_dir . '/' . $size);
                     chmod("{$coll_media_dir}/{$size}", 0775);
                 }
                 //todo: compat only!
                 symlink($coll_media_dir, $coll_media_dir . '_collection');
             }
         }
         foreach ($this->getEntries() as $entry) {
             if ('item' == $entry->getEntryType()) {
                 $r->set('collection_ascii_id', $c->ascii_id);
                 $entry->insert($db, $r, $fetch_enclosures);
             }
         }
     }
 }
Example #3
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 #4
0
 function testDatabaseSelect()
 {
     $c = new Dase_Config(BASE_PATH);
     $c->load('inc/config.php');
     $c->load('inc/local_config.php');
     $db = new Dase_DB($c);
     $c = Dase_DBO_Collection::get($db, 'test');
     $this->assertTrue('Test Collection' == $c->collection_name);
 }
Example #5
0
 protected function setup($r)
 {
     $this->collection = Dase_DBO_Collection::get($this->db, $r->get('collection_ascii_id'));
     if (!$this->collection) {
         $r->renderError(404);
     }
     $this->user = $r->getUser();
     if (!$this->user->can('admin', $this->collection)) {
         $r->renderError(401);
     }
     //so proper menu item highlights
     $r->set('tab', $r->resource);
 }
Example #6
0
 public static function initGlobalData($db, $config)
 {
     $cache = Dase_Cache::get($config);
     //refreshed once per hour -- expunge when necessary!
     $serialized_app_data = $cache->getData('app_data', 3600);
     if (!$serialized_app_data) {
         $c = new Dase_DBO_Collection($db);
         $colls = array();
         $acl = array();
         foreach ($c->find() as $coll) {
             $colls[$coll->ascii_id] = $coll->collection_name;
             $acl[$coll->ascii_id] = $coll->visibility;
             //compat
             $acl[$coll->ascii_id . '_collection'] = $coll->visibility;
         }
         $app_data['collections'] = $colls;
         $app_data['media_acl'] = $acl;
         $cache->setData('app_data', serialize($app_data));
     } else {
         $app_data = unserialize($serialized_app_data);
     }
     return $app_data;
 }
Example #7
0
 public function setup($r)
 {
     if ($r->has('collection_ascii_id')) {
         $this->collection = Dase_DBO_Collection::get($this->db, $r->get('collection_ascii_id'));
     }
     if ($r->has('att_ascii_id') && $r->has('collection_ascii_id')) {
         $this->attribute = Dase_DBO_Attribute::get($this->db, $r->get('collection_ascii_id'), $r->get('att_ascii_id'));
     }
     if ($r->has('att_ascii_id') && !$r->has('collection_ascii_id')) {
         $this->attribute = Dase_DBO_Attribute::getAdmin($this->db, 'admin_' . $r->get('att_ascii_id'));
     }
     if (!$this->attribute) {
         $r->renderError('404');
     }
 }
Example #8
0
 public function getList($r)
 {
     $t = new Dase_Template($r, true);
     $c = Dase_DBO_Collection::get($this->db, $r->get('coll_ascii'));
     if (!$c) {
         $r->renderError('404');
     }
     if ('public' != $c->visibility) {
         $r->renderError('401');
     }
     $url = 'https://dase.laits.utexas.edu/collection/' . $c->ascii_id . '/items.json';
     $json = file_get_contents($url);
     $php_data = json_decode($json, true);
     $t->assign('c', $c);
     $t->assign('items', $php_data['items']);
     $r->renderResponse($t->fetch('index.tpl'));
 }
Example #9
0
 protected function setup($r)
 {
     $this->collection = Dase_DBO_Collection::get($this->db, $r->get('collection_ascii_id'));
     if (!$this->collection) {
         $r->renderError(404);
     }
     if ('html' == $r->format && 'service' != $r->resource && 'ping' != $r->resource) {
         $this->user = $r->getUser();
         if (!$this->user->can('read', $this->collection)) {
             $r->renderError(401);
         }
     }
     /* todo: i guess anyone can read?
     		if ('atom' == $r->format) {
     			$this->user = $r->getUser('http');
     			if (!$this->user->can('read',$this->collection)) {
     			$r->renderError(401);
     			}
     		}
     		 */
 }
Example #10
0
 public function postToLogin($r)
 {
     //this is the default, uber-simple login
     //which should be overidden by a module
     //all valid users need to be superusers
     $username = strtolower($r->get('username'));
     $pass = $r->get('password');
     $superusers = $r->getSuperusers();
     //todo: this is why params are not saved -- super ONLY
     if (isset($superusers[$username]) && $superusers[$username] == $pass) {
         $user = new Dase_DBO_DaseUser($this->db);
         $user->retrieveByEid($username);
         $user->initCart();
         $r->setCookie('collections', Dase_Json::get(Dase_DBO_Collection::getLookupArray($this->db)));
         $r->setCookie('eid', $username);
         $r->setCookie('max', $user->max_items);
         $r->setCookie('display', $user->display);
         $r->renderRedirect(urldecode($r->get('target')));
     } else {
         //I could probably just display here instead of redirect
         $params['msg'] = 'incorrect username/password';
         $r->renderRedirect("login/form", $params);
     }
 }
Example #11
0
 public function getCollection()
 {
     //avoids another db lookup
     if ($this->collection) {
         return $this->collection;
     }
     $c = new Dase_DBO_Collection($this->db);
     $c->load($this->collection_id);
     $this->collection = $c;
     return $c;
 }
Example #12
0
 public function getTools($r)
 {
     $tpl = new Dase_Template($r);
     $colls = new Dase_DBO_Collection($this->db);
     $colls->orderBy('collection_name');
     $tpl->assign('collections', $colls->find());
     $r->renderResponse($tpl->fetch('admin/tools.tpl'));
 }
Example #13
0
 function getCollection()
 {
     $coll = new Dase_DBO_Collection($this->db);
     $coll->load($this->getItem()->collection_id);
     return $coll;
 }
Example #14
0
 /** for now, PUT of a collection entry can only add, NOT delete item_types & attributes */
 function update($db, $r)
 {
     $coll = $this->getAsciiId();
     foreach ($this->getAttributes() as $att) {
         Dase_DBO_Attribute::findOrCreate($db, $coll, $att['term']);
     }
     foreach ($this->getItemTypes() as $type) {
         Dase_DBO_ItemType::findOrCreate($db, $coll, $type['term']);
     }
     $coll = Dase_DBO_Collection::get($db, $coll);
     $coll->updateVisibility($this->getVisibility());
     $r->renderResponse('updated collection');
 }
Example #15
0
 function addLinks($db, $r)
 {
     $eid = $r->getUser()->eid;
     $sernum = $this->getSerialNumber();
     $c = Dase_DBO_Collection::get($db, $r->get('collection_ascii_id'));
     if (!$c) {
         return;
     }
     $item = Dase_DBO_Item::get($db, $c->ascii_id, $sernum);
     if (!$item) {
         return;
     }
     $item->updated = date(DATE_ATOM);
     $item->update();
     foreach ($this->getMetadataLinks() as $att => $keyval) {
         foreach ($keyval['values'] as $v) {
             if (trim($v['text'])) {
                 //check that it's proper collection
                 if ($c->ascii_id = $v['coll']) {
                     $val = $item->setValueLink($att, $v['text'], $v['url'], $v['mod']);
                 }
             }
         }
     }
     $item->buildSearchIndex();
     return $item;
 }
Example #16
0
<?php

include 'config.php';
$source = 'asian_studies';
$target = 'pkeane';
$c = Dase_DBO_Collection::get($db, $source);
foreach ($c->getItems() as $item) {
    $json_doc = $item->buildJson('http://dase.laits.utexas.edu');
    //print_r(json_decode($json_doc));
    $target_url = 'https://daseupload.laits.utexas.edu/collection/' . $target . '/ingester';
    print $target_url . "\n";
    $res = Dase_Http::post($target_url, $json_doc, 'pkeane', 'dupload', 'application/json');
    print_r($res);
}
Example #17
0
 static function getLookupArray($db)
 {
     $hash = array();
     $c = new Dase_DBO_Collection($db);
     foreach ($c->find() as $coll) {
         $iter = $coll->getIterator();
         foreach ($iter as $field => $value) {
             $coll_hash[$field] = $value;
         }
         $hash[$coll->id] = $coll_hash;
     }
     return $hash;
 }
<?php

include 'config.php';
$c = Dase_DBO_Collection::get($db, 'cola_images');
$c = Dase_DBO_Collection::get($db, 'pkeane');
foreach ($c->getItems() as $item) {
    $item = clone $item;
    foreach ($item->getValues() as $v) {
        $v = clone $v;
        if (strpos($v->value_text, " ©")) {
            print $v->value_text . "\n";
            $v->value_text = str_replace(" ©", ' copyright', $v->value_text);
            $v->update();
            //$item->buildSearchIndex();
        }
    }
}
$c->buildSearchIndex('');
Example #19
0
 public function postToCollection($r)
 {
     $c = Dase_DBO_Collection::get($this->db, $r->get('collection_ascii_id'));
     if (!$this->user->can('write', $c)) {
         $r->renderError(401, 'cannot post media to this collection');
     }
     //hand off to item handler
     try {
         $item_handler = new Dase_Handler_Item($this->db, $this->config);
         //allows us to dictate serial number
         $sernum = Dase_Util::makeSerialNumber($r->slug);
         $item_handler->item = $c->createNewItem($sernum, $this->user->eid);
         $item_handler->postToMedia($r);
     } catch (Exception $e) {
         $r->renderError(409, $e->getMessage());
     }
     //if something goes wrong and control returns here
     $r->renderError(500, 'error in post to collection');
 }
Example #20
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 #21
0
<?php

include 'config.php';
$coll = 'images_of_india';
$c = Dase_DBO_Collection::get($db, $coll);
print "{$c->collection_name} ({$c->item_count})\n\n";
foreach ($c->getItems() as $item) {
    print "deleting " . $item->serial_number . "\n";
    print $item->expunge();
}
<?php

include 'config.php';
//this script replaces characters which are valid utf8
//but invalid in XML (there are just a few)
$ascii_id = 'cumbojd';
$c = Dase_DBO_Collection::get($db, $ascii_id);
foreach ($c->getItems() as $item) {
    $item = clone $item;
    print "working\n";
    $item->deleteDocs();
    $item->storeDoc();
    foreach ($item->getValues() as $value) {
        $str = $value->value_text;
        //		print $str."\n";
        if ($str != strip_invalid_xml_chars2($str)) {
            $value->value_text = strip_invalid_xml_chars2($str);
            $value->update();
            print "updated item {$item->serial_number}\n";
        }
    }
}
function strip_invalid_xml_chars2($in)
{
    $out = "";
    $length = strlen($in);
    for ($i = 0; $i < $length; $i++) {
        $current = ord($in[$i]);
        if ($current == 0x9 || $current == 0xa || $current == 0xd || $current >= 0x20 && $current <= 0xd7ff || $current >= 0xe000 && $current <= 0xfffd || $current >= 0x10000 && $current <= 0x10ffff) {
            $out .= chr($current);
        } else {
Example #23
0
<?php

include 'config.php';
$solr_url = 'quickdraw.laits.utexas.edu:8080/solr/update';
$limit = 0;
//$limit = 15;
if ($limit) {
    print "\nCurrently set to index most recent {$limit} items\n";
}
$cs = new Dase_DBO_Collection($db);
$cs->orderBy('id DESC');
foreach ($cs->find() as $c) {
    $c = clone $c;
    $colls[] = $c->ascii_id;
}
//can enter collections on command line
if (isset($argv[1])) {
    array_shift($argv);
    $colls = $argv;
}
$engine = new Dase_Solr($db, $config);
$i = 0;
foreach ($colls as $coll) {
    $c = Dase_DBO_Collection::get($db, $coll);
    if ($c) {
        foreach ($c->getItems($limit) as $item) {
            $i++;
            $item = clone $item;
            print $c->collection_name . ':' . $item->serial_number . ':' . $item->buildSearchIndex(false, false);
            print " {$i}\n";
            print " memory: " . memory_get_usage() . "\n";
<?php

include 'config.php';
$c = Dase_DBO_Collection::get($db, 'keanepj');
$i = 0;
foreach ($c->getItems() as $item) {
    $item = clone $item;
    $item->p_collection_ascii_id = $c->ascii_id;
    $item->collection_name = $c->collection_name;
    $item->p_remote_media_host = $c->remote_media_host;
    if ($item->update()) {
        $i++;
    }
}
print "updated {$i} items in {$c->collection_name}\n";
Example #25
0
<?php

include 'config.php';
$comms = new Dase_DBO_Comment($db);
foreach ($comms->find() as $c) {
    $item = new Dase_DBO_Item($db);
    $item->load($c->item_id);
    $item->comments_updated = $c->updated;
    $item->comments_count = $item->comment_count + 1;
    $item;
    $item->update();
}
$cs = new Dase_DBO_Collection($db);
$i = 0;
foreach ($cs->find() as $c) {
    print "\nworking on {$c->collection_name}\n\n";
    foreach ($c->getItems() as $item) {
        $i++;
        $item = clone $item;
        if (!$item->collection_name) {
            $item->collection_name = $c->collection_name;
            $type = $item->getItemType();
            $item->item_type_ascii_id = $type->ascii_id;
            $item->item_type_name = $type->name;
            $item->update();
        }
        print "\n{$i}";
    }
}
Example #26
0
 public function isBulkEditable($user)
 {
     $prefix = $this->db->table_prefix;
     $dbh = $this->db->getDbh();
     $sql = "\n\t\t\tSELECT p_collection_ascii_id \n\t\t\tFROM {$prefix}tag_item \n\t\t\twhere tag_id = ?\n\t\t\tGROUP BY p_collection_ascii_id\n\t\t\t";
     $st = $dbh->prepare($sql);
     $st->execute(array($this->id));
     $colls = $st->fetchAll();
     if (1 === count($colls) && $colls[0]['p_collection_ascii_id']) {
         $c = Dase_DBO_Collection::get($this->db, $colls[0]['p_collection_ascii_id']);
         if ($c && $user->can('write', $c)) {
             return true;
         }
     }
     return false;
 }
Example #27
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 #28
0
 public function getCollection()
 {
     //avoids another db lookup
     if ($this->_collection) {
         return $this->_collection;
     }
     $db = $this->db;
     $c = new Dase_DBO_Collection($db);
     $c->load($this->collection_id);
     if ($c) {
         $this->_collection = $c;
         return $c;
     } else {
         return false;
     }
 }
Example #29
0
<?php

include 'config.php';
//this script rebuilds search indexes
$coll_ascii_id = 'what_jane_saw';
$coll_ascii_id = 'cola_images';
$coll = new Dase_DBO_Collection($db);
$coll->orderBy('item_count ASC');
if ($coll_ascii_id) {
    $coll->ascii_id = $coll_ascii_id;
}
foreach ($coll->find() as $c) {
    $start = Dase_Util::getTime();
    print "working on " . $c->collection_name . "(" . $c->item_count . " items)\n";
    $c->buildSearchIndex('');
    $end = Dase_Util::getTime();
    $total = $end - $start;
    print $total . " seconds\n";
}
Example #30
0
 public function getCollections($app_root)
 {
     $cm = new Dase_DBO_CollectionManager($this->db);
     $cm->dase_user_eid = $this->eid;
     $special_colls = array();
     $user_colls = array();
     foreach ($cm->find() as $managed) {
         $special_colls[$managed->collection_ascii_id] = $managed->auth_level;
     }
     $coll = new Dase_DBO_Collection($this->db);
     $coll->orderBy('collection_name');
     foreach ($coll->find() as $c) {
         if (!$c->item_count) {
             $c->item_count = 0;
         }
         if (1 == $c->is_public || in_array($c->ascii_id, array_keys($special_colls))) {
             if (isset($special_colls[$c->ascii_id])) {
                 $auth_level = $special_colls[$c->ascii_id];
             } else {
                 $auth_level = '';
             }
             $user_colls[$c->ascii_id] = array('id' => $c->getUrl($app_root), 'collection_name' => $c->collection_name, 'ascii_id' => $c->ascii_id, 'is_public' => $c->is_public, 'item_count' => $c->item_count, 'auth_level' => $auth_level, 'links' => array('self' => $c->getUrl($app_root), 'media' => $c->getMediaUrl($app_root)));
         }
     }
     return $user_colls;
 }