Exemplo n.º 1
0
 function insert($db, $r, $collection)
 {
     $att = new Dase_DBO_Attribute($db);
     $att->attribute_name = $this->getTitle();
     //think about using getAscii or Slug also
     $att->ascii_id = Dase_Util::dirify($att->attribute_name);
     if (!Dase_DBO_Attribute::get($db, $collection->ascii_id, $att->ascii_id)) {
         $att->collection_id = $collection->id;
         $att->updated = date(DATE_ATOM);
         $att->sort_order = 9999;
         $att->is_on_list_display = 1;
         $att->is_public = 1;
         $att->in_basic_search = 1;
         $att->html_input_type = $this->getHtmlInputType();
         $att->insert();
         $sort_order = 0;
         foreach ($this->getDefinedValues() as $dv) {
             $sort_order++;
             $att->addDefinedValue($dv, $sort_order);
         }
         foreach ($this->getItemTypes() as $type) {
             $att->addItemType($type);
         }
         $att->resort();
     } else {
         throw new Dase_Exception('attribute exists');
     }
     return $att;
 }
Exemplo n.º 2
0
 public static function getUniqueBaseIdent($db, $title, $collection_ascii_id)
 {
     $check_ident = Dase_Util::dirify($title);
     $mf = new Dase_DBO_MediaFile($db);
     $mf->p_serial_number = $check_ident;
     $mf->p_collection_ascii_id = $collection_ascii_id;
     if (!$mf->findOne()) {
         return $check_ident;
     } else {
         $check_ident = $check_ident . time();
         return Dase_DBO_MediaFile::getUniqueBaseIdent($db, $check_ident, $collection_ascii_id);
     }
 }
Exemplo n.º 3
0
 public static function findOrCreate($db, $collection_ascii_id, $ascii_id)
 {
     $type = new Dase_DBO_ItemType($db);
     $coll = Dase_DBO_Collection::get($db, $collection_ascii_id);
     if (!$coll) {
         throw new Exception('no such collection');
     }
     $type->collection_id = $coll->id;
     $type->ascii_id = Dase_Util::dirify($ascii_id);
     if (!$type->findOne()) {
         $type->name = ucwords(str_replace('_', ' ', $ascii_id));
         $type->insert();
     }
     return $type;
 }
Exemplo n.º 4
0
 protected function determineMethod($resource, $r)
 {
     if ('post' == $r->method) {
         $method = 'postTo';
     } else {
         $method = $r->method;
     }
     if ('html' == $r->format || 'get' != $r->method) {
         $format = '';
     } else {
         $format = ucfirst($r->format);
     }
     //camel case
     $resource = Dase_Util::camelize($resource);
     $handler_method = $method . $resource . $format;
     return $handler_method;
 }
Exemplo n.º 5
0
 function insert($db, $r, $collection)
 {
     //think about using Slug also
     $ascii_id = Dase_Util::dirify($this->getAsciiId());
     if (!$ascii_id) {
         $ascii_id = Dase_Util::dirify($this->getTitle());
     }
     if (!Dase_DBO_ItemType::get($db, $collection->ascii_id, $ascii_id)) {
         $type = new Dase_DBO_ItemType($db);
         $type->ascii_id = $ascii_id;
         $type->name = $this->getTitle();
         $type->collection_id = $collection->id;
         $type->description = $this->getSummary();
         $type->insert();
         return $type;
     } else {
         throw new Dase_Exception('item type exists');
     }
 }
Exemplo n.º 6
0
 public static function findOrCreateAdmin($db, $attribute_ascii_id)
 {
     $att = new Dase_DBO_Attribute($db);
     $att->collection_id = 0;
     $att->ascii_id = $attribute_ascii_id;
     if (!$att->findOne()) {
         $attribute_ascii_id = Dase_Util::dirify($attribute_ascii_id);
         $att->attribute_name = ucwords(str_replace('_', ' ', $attribute_ascii_id));
         $att->sort_order = 0;
         $att->in_basic_search = 0;
         $att->is_on_list_display = 0;
         $att->is_public = 0;
         $att->mapped_admin_att_id = 0;
         $att->updated = date(DATE_ATOM);
         $att->html_input_type = 'no_edit';
         $att->insert();
     }
     return $att;
 }
Exemplo n.º 7
0
 public function getDownloadAll($r)
 {
     $set = new Dase_DBO_ExerciseSet($this->db);
     $set->load($r->get('id'));
     //ZIP stuff
     $zip = new ZipArchive();
     $target_dir = "/tmp/humptydumpty_zip";
     if (!file_exists($target_dir)) {
         if (!mkdir($target_dir)) {
             $r->renderError(500);
         }
     }
     $filename = $target_dir . '/' . $set->ascii_id . ".zip";
     if (file_exists($filename)) {
         unlink($filename);
     }
     if ($zip->open($filename, ZIPARCHIVE::CREATE) !== TRUE) {
         $r->renderError(401, 'cannot create zip');
     }
     $exercises = $set->getExercises();
     $has_media = 0;
     foreach ($exercises as $ex) {
         if ($ex->media_file) {
             $ex_ascii = Dase_Util::dirify($ex->title);
             $fn = $target_dir . '/exercise-' . $ex_ascii;
             file_put_contents($fn, file_get_contents($ex->media_file));
             if (filesize($fn)) {
                 $zip->addFile($fn, $set->ascii_id . '/' . $ex_ascii . '.mp3');
                 $has_media = 1;
             }
         }
     }
     $zip->close();
     if (!$has_media) {
         $params['msg'] = $set->title . ' has no associated media';
         $r->renderRedirect('set/' . $set->id, $params);
     }
     //todo: need to set a cron job to garbage collect the set in media/tmp
     $r->serveFile($filename, 'application/zip', true);
 }
Exemplo n.º 8
0
 public function serveFile($path, $mime_type, $download = false)
 {
     if (!file_exists($path)) {
         header('Content-Type: image/jpeg');
         readfile(BASE_PATH . '/www/images/unavail.jpg');
         exit;
     }
     $filename = basename($path);
     //from php.net
     $headers = apache_request_headers();
     // Checking if the client is validating its cache and if it is current.
     if (isset($headers['If-Modified-Since']) && strtotime($headers['If-Modified-Since']) == filemtime($path)) {
         // Client's cache IS current, so we just respond '304 Not Modified'.
         header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($path)) . ' GMT', true, 304);
     } else {
         // Image not cached or cache outdated, we respond '200 OK' and output the image.
         header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($path)) . ' GMT', true, 200);
         header('Content-Length: ' . filesize($path));
         header('Content-Type: ' . $mime_type);
         if ($download) {
             header("Content-Disposition: attachment; filename={$filename}");
             //from http://us.php.net/fread
             $total = filesize($path);
             $blocksize = 2 << 20;
             //2M chunks
             $sent = 0;
             $handle = fopen($path, "r");
             // Now we need to loop through the file and echo out chunks of file data
             while ($sent < $total) {
                 echo fread($handle, $blocksize);
                 $sent += $blocksize;
             }
         } else {
             header("Content-Disposition: inline; filename={$filename}");
             //print file_get_contents($path);
             Dase_Util::readfileChunked($path);
         }
     }
     exit;
 }
Exemplo n.º 9
0
 public function postToCollections($r)
 {
     $user = $r->getUser('http');
     if (!$user->is_superuser) {
         $r->renderError(401, $user->eid . ' is not permitted to create a collection');
     }
     $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 ($client_md5 && md5($raw_input) != $client_md5) {
             //todo: fix this
             //$r->renderError(412,'md5 does not match');
         }
         try {
             $coll_entry = Dase_Atom_Entry::load($raw_input);
         } catch (Exception $e) {
             Dase_Log::debug(LOG_FILE, 'colls handler error: ' . $e->getMessage());
             $r->renderError(400, 'bad xml');
         }
         if ('collection' != $coll_entry->entrytype) {
             $r->renderError(400, 'must be a collection entry');
         }
         if ($r->slug) {
             $r->set('ascii_id', Dase_Util::dirify($r->slug));
         }
         $ascii_id = $coll_entry->create($this->db, $r);
         $user->expireDataCache($r->getCache());
         header("HTTP/1.1 201 Created");
         header("Content-Type: application/atom+xml;type=entry;charset='utf-8'");
         header("Location: " . $r->app_root . "/collection/" . $ascii_id . '.atom');
         echo Dase_DBO_Collection::get($this->db, $ascii_id)->asAtomEntry($r->app_root);
         exit;
     } else {
         $r->renderError(415, 'cannoot accept ' . $content_type);
     }
 }
Exemplo n.º 10
0
 public function insert($db, $r)
 {
     $user = $r->getUser();
     $atom_author = $this->getAuthorName();
     //should be exception??
     if (!$atom_author || $atom_author != $user->eid) {
         $r->renderError(401, 'users do not match');
     }
     $set = new Dase_DBO_Tag($db);
     $set->ascii_id = Dase_Util::dirify($this->getAsciiId());
     $set->eid = $user->eid;
     if ($set->findOne()) {
         $r->renderError(409, 'set with that name exists');
     }
     $set->dase_user_id = $user->id;
     $set->name = $this->getTitle();
     $set->is_public = 0;
     $set->item_count = 0;
     $set->type = 'set';
     $set->created = date(DATE_ATOM);
     $set->updated = date(DATE_ATOM);
     $set->insert();
     /*
     		foreach ($this->getCategories() as $category) {
     			$tag_cat = new Dase_DBO_TagCategory($db);
     			$tag_cat->tag_id = $set->id;
     			$tag_cat->category_id = 0;
     			$tag_cat->term = $category['term'];
     			$tag_cat->label = $category['label'];
     			$scheme = str_replace('http://daseproject.org/category/','',$category['scheme']);
     			$tag_cat->scheme = $scheme;
     			$tag_cat->insert();
     		}
     */
     return $set;
 }
Exemplo n.º 11
0
 public function postToSolr($item, $commit = true)
 {
     $start_check = Dase_Util::getTime();
     $start_get_doc = Dase_Util::getTime();
     $check_elapsed = round($start_get_doc - $start_check, 4);
     Dase_Log::debug(LOG_FILE, 'post to SOLR: ' . $this->solr_update_url . ' item ' . $item->getUnique());
     $solr_doc = $this->buildItemSolrDoc($item);
     //return $solr_doc;
     $start_index = Dase_Util::getTime();
     $get_doc_elapsed = round($start_index - $start_get_doc, 4);
     $resp = Dase_Http::post($this->solr_update_url, $solr_doc, null, null, 'text/xml');
     if ($commit) {
         Dase_Http::post($this->solr_update_url, '<commit/>', null, null, 'text/xml');
     }
     $end = Dase_Util::getTime();
     $index_elapsed = round($end - $start_index, 4);
     return $resp . ' check: ' . $check_elapsed . ' get_doc: ' . $get_doc_elapsed . ' index: ' . $index_elapsed;
 }
Exemplo n.º 12
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.º 13
0
 public static function makeSerialNumber($str)
 {
     if ($str) {
         //get just the last segment if it includes directory path
         $str = array_pop(explode('/', $str));
         $str = preg_replace('/[^a-zA-Z0-9_-]/', '_', trim($str));
         $str = trim(preg_replace('/__*/', '_', $str), '_');
         return Dase_Util::truncate($str, 50);
     } else {
         return null;
     }
 }
Exemplo n.º 14
0
 public function postToForm($r)
 {
     $this->user = $r->getUser();
     $set = new Dase_DBO_Itemset($this->db);
     $set->title = $r->get('title');
     if (!$set->title) {
         $set->title = dechex(time());
     }
     $set->name = $this->_findUniqueName(Dase_Util::dirify($set->title));
     $set->created_by = $this->user->eid;
     $set->created = date(DATE_ATOM);
     $set->insert();
     $r->renderRedirect('set/' . $set->name);
 }
Exemplo n.º 15
0
 public static function getNewId()
 {
     return 'tag:daseproject.org,' . date('Y') . ':' . Dase_Util::getUniqueName();
 }
Exemplo n.º 16
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;
 }
Exemplo n.º 17
0
if ($config->getAppSettings('force_https')) {
    if ('on' != $_SERVER['HTTPS']) {
        $secure_url = "https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
        header("Location:{$secure_url}");
    }
}
//imagemagick
define('CONVERT', $config->getAppSettings('convert'));
//log file
define('LOG_FILE', $config->getLogDir() . '/dase.log');
define('FAILED_SEARCH_LOG', $config->getLogDir() . '/failed_searches.log');
define('DEBUG_LOG', $config->getLogDir() . '/debug.log');
//log level
define('LOG_LEVEL', $config->getAppSettings('log_level'));
//media directory
define('MEDIA_DIR', $config->getMediaDir());
//db table prefix
define('TABLE_PREFIX', $config->getDb('table_prefix'));
//cache type
define('CACHE_TYPE', $config->getCacheType());
define('SMARTY_CACHE_DIR', $config->getCacheDir());
//max items diplayed per page
define('MAX_ITEMS', $config->getAppSettings('max_items'));
//main title
define('MAIN_TITLE', $config->getAppSettings('main_title'));
//custom page logo
define('PAGE_LOGO_LINK_TARGET', $config->getLocalSettings('page_logo_link_target'));
define('PAGE_LOGO_SRC', $config->getLocalSettings('page_logo_src'));
//timer
define('START_TIME', Dase_Util::getTime());
Exemplo n.º 18
0
 function makeSizes($item, $path_to_media, $rotate)
 {
     $collection = $item->getCollection();
     $image_properties = array('small' => array('geometry' => '640x480', 'max_height' => '480', 'size_tag' => '_640'), 'medium' => array('geometry' => '800x600', 'max_height' => '600', 'size_tag' => '_800'), 'large' => array('geometry' => '1024x768', 'max_height' => '768', 'size_tag' => '_1024'), 'full' => array('geometry' => '3600x2700', 'max_height' => '2700', 'size_tag' => '_3600'));
     $last_width = '';
     $last_height = '';
     $subdir = Dase_Util::getSubdir($item->serial_number);
     foreach ($image_properties as $size => $size_info) {
         $newimage = $path_to_media . '/' . $collection->ascii_id . '/' . $size . '/' . $subdir . '/' . $item->serial_number . $size_info['size_tag'] . '.jpg';
         $subdir_path = $path_to_media . '/' . $collection->ascii_id . '/' . $size . '/' . $subdir;
         if (!file_exists($subdir_path)) {
             mkdir($subdir_path);
         }
         $command = CONVERT . " \"{$this->filepath}\" -format jpeg -rotate {$rotate} -resize '{$size_info['geometry']} >' -colorspace RGB {$newimage}";
         $exec_output = array();
         $results = exec($command, $exec_output);
         if (!file_exists($newimage)) {
             Dase_Log::debug(LOG_FILE, "failed to write {$size} image");
             Dase_Log::debug(LOG_FILE, "UNSUCCESSFUL: {$command}");
         }
         $file_info = getimagesize($newimage);
         //create the media_file entry
         $media_file = new Dase_DBO_MediaFile($this->db);
         $media_file->item_id = $item->id;
         $media_file->filename = $item->serial_number . $size_info['size_tag'] . ".jpg";
         if ($file_info) {
             $media_file->width = $file_info[0];
             $media_file->height = $file_info[1];
         }
         if ($media_file->width <= $last_width && $media_file->height <= $last_height) {
             return;
         }
         $last_width = $media_file->width;
         $last_height = $media_file->height;
         $media_file->mime_type = 'image/jpeg';
         $media_file->size = $size;
         $media_file->md5 = md5_file($newimage);
         $media_file->updated = date(DATE_ATOM);
         $media_file->file_size = filesize($newimage);
         $media_file->p_collection_ascii_id = $collection->ascii_id;
         $media_file->p_serial_number = $item->serial_number;
         $media_file->insert();
         Dase_Log::info(LOG_FILE, "created {$media_file->size} {$media_file->filename}");
     }
     return;
 }
Exemplo n.º 19
0
 private function _filterPost($key)
 {
     $post = $this->_post;
     if (Dase_Util::getVersion() >= 520) {
         return trim(filter_input(INPUT_POST, $key, FILTER_SANITIZE_STRING));
     } else {
         if (isset($post[$key])) {
             if (is_array($post[$key])) {
                 $clean_array = array();
                 foreach ($post[$key] as $inp) {
                     $inp = strip_tags($inp);
                     $clean_array[] = $inp;
                 }
                 return $clean_array;
             } else {
                 return strip_tags($post[$key]);
             }
         }
     }
     return false;
 }
Exemplo n.º 20
0
<?php

include 'config.php';
$tag = new Dase_DBO_Tag($db);
foreach ($tag->findAll() as $t) {
    $lower = Dase_Util::dirify($t->ascii_id);
    if ($t->ascii_id != $lower) {
        print "PROBLEM! {$t->ascii_id}\n";
        $t->ascii_id = $lower;
        print $t;
        $t->update();
    } else {
        print "OK {$t->ascii_id}\n";
    }
}
Exemplo n.º 21
0
 public function postToSetForm($r)
 {
     $t = new Dase_Template($r);
     $set = new Dase_DBO_ExerciseSet($this->db);
     if ($r->get('title')) {
         $set->title = $r->get('title');
         $set->ascii_id = Dase_Util::dirify($set->title);
         $set->creator_eid = $this->user->eid;
         $set->insert();
     }
     $r->renderRedirect('admin/set_form');
 }
Exemplo n.º 22
0
 public static function create($db, $tag_name, $user)
 {
     if (!$tag_name) {
         return false;
     }
     $tag = new Dase_DBO_Tag($db);
     $tag->ascii_id = Dase_Util::dirify($tag_name);
     $tag->dase_user_id = $user->id;
     if ($tag->findOne()) {
         return false;
     } else {
         $tag->name = $tag_name;
         $tag->type = 'set';
         $tag->background = 'white';
         $tag->is_public = 0;
         $tag->item_count = 0;
         $tag->eid = $user->eid;
         $tag->created = date(DATE_ATOM);
         $tag->insert();
         return $tag;
     }
 }
Exemplo n.º 23
0
 function __destruct()
 {
     //see http://bugs.php.net/bug.php?id=34206
     // if strange 'failed to open stream' messages appear
     $now = Dase_Util::getTime();
     $elapsed = round($now - START_TIME, 4);
     Dase_Log::debug(LOG_FILE, 'finished request ' . $elapsed);
 }
Exemplo n.º 24
0
 public function addToCollection($item, $check_for_dups, $path_to_media)
 {
     $c = $item->getCollection();
     $metadata = $this->getMetadata();
     //prevents 2 files in same collection w/ same md5
     if ($check_for_dups) {
         $prefix = $this->db->table_prefix;
         $sql = "\n\t\t\t\tSELECT v.value_text\n\t\t\t\tFROM {$prefix}value v, {$prefix}item i, {$prefix}attribute a\n\t\t\t\tWHERE i.collection_id = ?\n\t\t\t\tAND a.ascii_id = ?\n\t\t\t\tAND v.attribute_id = a.id\n\t\t\t\tAND i.id = v.item_id\n\t\t\t\tAND v.value_text = ?\n\t\t\t\tLIMIT 1\n\t\t\t\t";
         $hash = $metadata['md5'];
         $dbh = $this->db->getDbh();
         $sth = $dbh->prepare($sql);
         $sth->execute(array($c->id, 'admin_checksum', $hash));
         $row = $sth->fetch();
         if ($row && $row['value_text']) {
             throw new Exception('duplicate file');
         }
     }
     $subdir = Dase_Util::getSubdir($item->serial_number);
     $subdir_path = $path_to_media . '/' . $c->ascii_id . '/' . $this->size . '/' . $subdir;
     if (!file_exists($subdir_path)) {
         mkdir($subdir_path);
     }
     $target = $path_to_media . '/' . $c->ascii_id . '/' . $this->size . '/' . $subdir . '/' . $item->serial_number . '.' . $this->ext;
     if (file_exists($target)) {
         //make a timestamped backup
         copy($target, $target . '.bak.' . time());
     }
     //should this be try-catch?
     if ($this->copyTo($target)) {
         $media_file = new Dase_DBO_MediaFile($this->db);
         $mediafile_meta = array('file_size', 'height', 'width', 'mime_type', 'updated', 'md5');
         foreach ($mediafile_meta as $term) {
             if (isset($metadata[$term])) {
                 $media_file->{$term} = $metadata[$term];
             }
         }
         $media_file->item_id = $item->id;
         $media_file->filename = $item->serial_number . '.' . $this->ext;
         $media_file->size = $this->size;
         $media_file->p_serial_number = $item->serial_number;
         $media_file->p_collection_ascii_id = $c->ascii_id;
         $media_file->insert();
         //will only insert item metadata when attribute name matches 'admin_'+att_name
         foreach ($metadata as $term => $text) {
             //catches UTF8 errors in exif/iptc data
             //actually, no it doesn't :(
             try {
                 $item->setValue('admin_' . $term, $text);
             } catch (Exception $e) {
                 Dase_Log::debug(LOG_FILE, "could not write admin {$term}: {$text} ERROR: " . $e->getMessage());
             }
         }
     }
     return $media_file;
 }
Exemplo n.º 25
0
 function insert($db, $r, $fetch_enclosure = false)
 {
     $user = $r->getUser('http');
     //allows service user to  override created_by_eid
     $author = $this->getAuthorName();
     if ($user->is_serviceuser && $author) {
         $created_by_eid = $author;
     } else {
         $created_by_eid = $user->eid;
     }
     $c = Dase_DBO_Collection::get($db, $r->get('collection_ascii_id'));
     if (!$c) {
         return;
     }
     $sn = Dase_Util::makeSerialNumber($r->slug);
     $item = $c->createNewItem($sn, $created_by_eid);
     foreach ($this->getMetadata() as $att => $keyval) {
         //creates atribute if it doesn't exist!
         Dase_DBO_Attribute::findOrCreate($db, $c->ascii_id, $att);
         foreach ($keyval['values'] as $v) {
             if (trim($v['text'])) {
                 $val = $item->setValue($att, $v['text'], null, $v['mod']);
             }
         }
     }
     foreach ($this->getMetadataLinks() as $att => $keyval) {
         Dase_DBO_Attribute::findOrCreate($db, $c->ascii_id, $att);
         foreach ($keyval['values'] as $v) {
             if (trim($v['text'])) {
                 //check that it's proper collection
                 if ($c->ascii_id = $v['coll']) {
                     //don't index just yet (the false param)
                     $val = $item->setValueLink($att, $v['text'], $v['url'], $v['mod'], false);
                 }
             }
         }
     }
     //item_type
     $item_type = $this->getItemType();
     if ($item_type['term']) {
         $item->setItemType($item_type['term']);
     }
     //content
     if ($this->getContent()) {
         $item->setContent($this->getContent(), $eid, $this->getContentType());
     }
     //$item->setValue('title',$this->getTitle());
     //$item->setValue('description',$this->getSummary());
     if ($fetch_enclosure) {
         $enc = $this->getEnclosure();
         if ($enc) {
             $upload_dir = MEDIA_DIR . '/' . $c->ascii_id . '/uploaded_files';
             if (!file_exists($upload_dir)) {
                 $r->renderError(401, 'missing upload directory');
             }
             $ext = Dase_File::$types_map[$enc['type']]['ext'];
             $new_file = $upload_dir . '/' . $item->serial_number . '.' . $ext;
             file_put_contents($new_file, file_get_contents($enc['href']));
             try {
                 $file = Dase_File::newFile($db, $new_file, $enc['mime_type']);
                 $media_file = $file->addToCollection($item, false, MEDIA_DIR);
             } catch (Exception $e) {
                 $r->renderError(500, 'could not ingest enclosure file (' . $e->getMessage() . ')');
             }
         }
     }
     //messy
     $item->expireCaches($r->getCache());
     $item->buildSearchIndex();
     return $item;
 }
Exemplo n.º 26
0
 public function postToContentForm($r)
 {
     $item = new Dase_DBO_Item($this->db);
     $item->body = $r->get('body');
     $item->title = $r->get('title');
     $file = $r->_files['uploaded_file'];
     if ($file && is_file($file['tmp_name'])) {
         $name = $file['name'];
         $path = $file['tmp_name'];
         $type = $file['type'];
         if (!is_uploaded_file($path)) {
             $r->renderError(400, 'no go upload');
         }
         if (!isset(Dase_File::$types_map[$type])) {
             $r->renderError(415, 'unsupported media type: ' . $type);
         }
         $base_dir = $this->config->getMediaDir();
         $thumb_dir = $this->config->getMediaDir() . '/thumb';
         if (!file_exists($base_dir) || !is_writeable($base_dir)) {
             $r->renderError(403, 'media directory not writeable: ' . $base_dir);
         }
         if (!file_exists($thumb_dir) || !is_writeable($thumb_dir)) {
             $r->renderError(403, 'thumbnail directory not writeable: ' . $thumb_dir);
         }
         $ext = strtolower(pathinfo($name, PATHINFO_EXTENSION));
         $basename = Dase_Util::dirify(pathinfo($name, PATHINFO_FILENAME));
         if ('application/pdf' == $type) {
             $ext = 'pdf';
         }
         if ('application/msword' == $type) {
             $ext = 'doc';
         }
         if ('application/vnd.openxmlformats-officedocument.wordprocessingml.document' == $type) {
             $ext = 'docx';
         }
         $newname = $this->_findNextUnique($base_dir, $basename, $ext);
         $new_path = $base_dir . '/' . $newname;
         //move file to new home
         rename($path, $new_path);
         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 = $type;
         $parts = explode('/', $type);
         if (isset($parts[0]) && 'image' == $parts[0]) {
             $thumb_path = $thumb_dir . '/' . $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/img/mime_icons/' . Dase_File::$types_map[$type]['size'] . '.png';
         }
         if (isset($size[0]) && $size[0]) {
             $item->width = $size[0];
         }
         if (isset($size[1]) && $size[1]) {
             $item->height = $size[1];
         }
     } else {
         if (!$item->title) {
             $item->title = substr($item->body, 0, 20);
         }
         if (!$item->title) {
             $params['msg'] = "title or body is required is no file is uploaded";
             $r->renderRedirect('admin/upload', $params);
         }
         $item->name = $this->_findUniqueName(Dase_Util::dirify($item->title));
         $item->thumbnail_url = 'www/img/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;
     $item->insert();
     $r->renderRedirect('items');
 }
Exemplo n.º 27
0
 public function postToItemTypes($r)
 {
     $type_ascii_id = Dase_Util::dirify($r->get('name'));
     //note if type_ascii_id MATCHES, we do not create a new type, we grab match
     $type = Dase_DBO_ItemType::findOrCreate($this->db, $this->collection->ascii_id, $type_ascii_id);
     $type->name = $r->get('name');
     $type->description = $r->get('description');
     $type->update();
     $params['msg'] = "{$type->name} created";
     $r->renderRedirect('manage/' . $this->collection->ascii_id . '/item_type/' . $type->ascii_id, $params);
 }
Exemplo n.º 28
0
 public function postToExerciseCategory($r)
 {
     $exercise = new Dase_DBO_Exercise($this->db);
     $exercise->load($r->get('id'));
     $category = new Dase_DBO_Category($this->db);
     $category->text = trim($r->get('category'));
     if (!$category->findOne()) {
         $category->ascii_id = Dase_Util::dirify($r->get('category'));
         $category->insert();
     }
     $exercat = new Dase_DBO_ExerciseCategory($this->db);
     $exercat->exercise_id = $exercise->id;
     $exercat->category_id = $category->id;
     $exercat->insert();
     $r->renderRedirect('exercise/' . $exercise->id . '/edit');
 }
Exemplo n.º 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";
}
Exemplo n.º 30
0
 function __destruct()
 {
     $now = Dase_Util::getTime();
     $elapsed = round($now - START_TIME, 4);
     Dase_Log::debug(LOG_FILE, 'finished templating ' . $elapsed);
 }