function uploadPhoto($title, $descr, $tags, $slug, $oldPath = '') { global $wpdb, $user_ID; PhotoQHelper::debug('enter uploadPhoto() ' . $title); //get the current user if (empty($post_author)) { $post_author = $user_ID; } //we still didn't get an author -> set it to default if (empty($post_author)) { $post_author = $this->_oc->getValue('qPostAuthor'); } //put uploaded file into qdir $file = $this->_handleUpload($this->_oc->getQDir(), $oldPath); //PhotoQHelper::debug(print_r($file,true)); //check for errors if (!$file) { return false; } //get exif meta data $exif = serialize(PhotoQExif::readExif($file)); PhotoQHelper::debug('uploadPhoto: got EXIF'); $filename = basename($file); //make nicer titles $title = addslashes($this->makeAutoTitle($title)); PhotoQHelper::debug('uploadPhoto: created auto title'); //add photo to queue if (!($result = $wpdb->query("INSERT INTO {$this->QUEUE_TABLE} (q_title, q_imgname, q_position, q_slug, q_descr, q_tags, q_exif, q_fk_author_id) VALUES ('{$title}', '{$filename}', '" . ($this->_queue->getLength() + 1) . "', '{$slug}', '{$descr}', '{$tags}', '{$exif}', '{$post_author}')"))) { return false; } //get the id assigned to this entry $imgID = mysql_insert_id(); PhotoQHelper::debug('uploadPhoto: post added to DB. ID: ' . $imgID); // Insert categories $post_categories = apply_filters('category_save_pre', PhotoQHelper::arrayAttributeEscape($_POST['post_category'])); // Check to make sure there is a category, if not just set it to some default if (!$post_categories) { $post_categories[] = $this->_oc->getValue('qPostDefaultCat'); } foreach ($post_categories as $post_category) { // Double check it's not there already $exists = $wpdb->get_row("SELECT * FROM {$this->QCAT_TABLE} WHERE q_fk_img_id = {$imgID} AND category_id = {$post_category}"); if (!$exists) { $this->_db->insertCategory($imgID, $post_category); } } //handle the fields $results = $wpdb->get_results("SELECT * FROM {$this->QFIELDS_TABLE} WHERE 1"); $fieldValue = ''; if ($results) { foreach ($results as $field_entry) { //the common info box for ftp uploads submits an array we don't want to use here if (!is_array($_POST["{$field_entry->q_field_name}"])) { $fieldValue = $_POST["{$field_entry->q_field_name}"]; } $insert_meta_query = "INSERT INTO {$this->QUEUEMETA_TABLE} (q_fk_img_id, q_fk_field_id, q_field_value)\n\t\t\t\t\tVALUES ({$imgID}, {$field_entry->q_field_id}, '" . $fieldValue . "')"; $wpdb->query($insert_meta_query); } } PhotoQHelper::debug('leave uploadPhoto()'); return new PhotoQStatusMessage(sprintf(_c('Successfully uploaded. \'%1$s\' added to queue at position %2$d.|filename postion'), $filename, $this->_queue->getLength() + 1), 'PhotoQ'); }
/** * Recursively removes entries containing ':unknown' in key from input array. * * @param array $in the input array * @return array the filtered array */ function _filterUseless($in) { $out = array(); if (is_array($in)) { foreach ($in as $key => $value) { if (strpos($key, 'unknown:') === false && !in_array($key, PhotoQExif::_getUselessTagNames())) { if (is_array($value)) { $out[$key] = PhotoQExif::_filterUseless($value); } else { $out[$key] = PhotoQExif::_sanitizeExifValue($value); } } } } return $out; }
/** * PHP5 type constructor */ function __construct($postID, $title, $descr = '', $path = '', $imgname, $tags = '', $slug = '', $edited = false) { if (empty($path)) { $path = get_post_meta($postID, 'path', true); } //correct the path value if needed. on windows machines we might //find ourselves with all backslashes removed $path = str_replace(ABSPATH, '', trim($path)); //try to remove standard abspath $absNoSlash = str_replace('\\', '', ABSPATH); //create the crippled abspath $path = str_replace($absNoSlash, '', trim($path)); //try to remove crippled abspath $path = ABSPATH . $path; //add correct abspath if (empty($descr)) { $descr = get_post_meta($postID, 'descr', true); } //if it is still empty, the descr was inlined, we need to get it back if (empty($descr)) { //we are now trying to find the description $post = get_post($postID); $descr = $this->getInlineDescription($post->post_content, 'photo_description'); } //get the exif information $exif = serialize(PhotoQExif::readExif($path)); parent::__construct($postID, $title, $descr, $exif, $path); }