コード例 #1
0
ファイル: mime.image.php プロジェクト: kailIII/liberty
/**
 * mime_image_create_panorama
 *
 * @param array $pStoreRow
 * @access public
 * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
 */
function mime_image_create_panorama(&$pStoreRow)
{
    global $gBitSystem, $gThumbSizes;
    // we know the panorama image will be a jpeg, so we don't need the canThumbFunc check here
    if (($panoramaFunc = liberty_get_function('panorama')) && !empty($pStoreRow['source_file']) && is_file($pStoreRow['source_file'])) {
        // the panorama has to be a jpg
        $gBitSystem->setConfig('liberty_thumbnail_format', 'jpg');
        $width = $gBitSystem->getConfig('mime_image_panorama_width', 3000);
        $gThumbSizes['panorama'] = array($width, $width / 2);
        // for the panorama, we will force a quality lower than 75 to reduce image size
        if ($gBitSystem->getConfig('liberty_thumbnail_quality', 85) > 75) {
            $gBitSystem->setConfig('liberty_thumbnail_quality', 75);
        }
        $genHash = array('attachment_id' => $pStoreRow['attachment_id'], 'dest_branch' => liberty_mime_get_storage_branch(array('sub_dir' => $pStoreRow['attachment_id'], 'user_id' => $pStoreRow['user_id'], 'package' => liberty_mime_get_storage_sub_dir_name($pStoreRow))), 'file_name' => dirname($pStoreRow['file_name']) . "/", 'source_file' => $pStoreRow['source_file'], 'type' => $pStoreRow['mime_type'], 'thumbnail_sizes' => array('panorama'));
        if (liberty_generate_thumbnails($genHash)) {
            // we want to modify the panorama
            $genHash['source_file'] = $genHash['icon_thumb_path'];
            if (!$panoramaFunc($genHash)) {
                $pStoreRow['errors']['panorama'] = $genHash['error'];
            }
        }
        return empty($pStoreRow['errors']);
    }
}
コード例 #2
0
ファイル: liberty_lib.php プロジェクト: bitweaver/liberty
/**
 * liberty_process_image
 *
 * @param array $pFileHash
 * @access public
 * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
 */
function liberty_process_image(&$pFileHash, $pMoveFile = TRUE)
{
    global $gBitSystem;
    $ret = NULL;
    list($type, $ext) = explode('/', strtolower($pFileHash['type']));
    if ($resizePath = liberty_process_generic($pFileHash, $pMoveFile)) {
        $pFileHash['source_file'] = $resizePath;
        //set permissions if possible - necessary for some wonky shared hosting environments
        if (chmod($pFileHash['source_file'], 0644)) {
            //does nothing, but fails elegantly
        }
        $nameHold = $pFileHash['name'];
        $sizeHold = $pFileHash['size'];
        $ret = $pFileHash['source_file'];
        // do not thumbnail only if intentionally set to FALSE
        if (!isset($pFileHash['thumbnail']) || $pFileHash['thumbnail'] == TRUE) {
            liberty_generate_thumbnails($pFileHash);
        }
        $pFileHash['name'] = $nameHold;
        $pFileHash['size'] = $sizeHold;
    }
    return $ret;
}
コード例 #3
0
ファイル: mime.video.php プロジェクト: kailIII/liberty
/**
 * This function will create a thumbnail for a given video
 *
 * @param string $pFile path to video file
 * @param numric $pOffset Offset in seconds to use to create thumbnail from
 * @access public
 * @return TRUE on success, FALSE on failure
 */
function mime_video_create_thumbnail($pFile, $pOffset = 60)
{
    global $gBitSystem;
    $ret = FALSE;
    if (!empty($pFile) && is_file($pFile)) {
        $destPath = dirname($pFile);
        // try to use an app designed specifically to extract a thumbnail
        if (shell_exec(shell_exec('which ffmpegthumbnailer') . ' -h')) {
            $thumbnailer = trim(shell_exec('which ffmpegthumbnailer'));
        } elseif (shell_exec(shell_exec('which ffmpegvideothumbnailer') . ' -h')) {
            $thumbnailer = trim(shell_exec('which ffmpegvideothumbnailer'));
        }
        if (!empty($thumbnailer) && is_executable($thumbnailer)) {
            shell_exec("{$thumbnailer} -i '{$pFile}' -o '{$destPath}/thumb.jpg' -s 1024");
        }
        if (is_file("{$destPath}/thumb.jpg") && filesize("{$destPath}/thumb.jpg") > 1) {
            $fileHash['type'] = 'image/jpg';
            $fileHash['source_file'] = "{$destPath}/thumb.jpg";
            $fileHash['dest_branch'] = str_replace(STORAGE_PKG_PATH, '', "{$destPath}/");
            liberty_generate_thumbnails($fileHash);
            $ret = TRUE;
            // remove temp file
            @unlink("{$destPath}/thumb.jpg");
        } else {
            // fall back to using ffmepg
            $ffmpeg = trim($gBitSystem->getConfig('ffmpeg_path', shell_exec('which ffmpeg')));
            shell_exec("{$ffmpeg} -i '{$pFile}' -an -ss {$pOffset} -t 00:00:01 -r 1 -y '{$destPath}/preview%d.jpg'");
            if (is_file("{$destPath}/preview1.jpg")) {
                $fileHash['type'] = 'image/jpg';
                $fileHash['source_file'] = "{$destPath}/preview1.jpg";
                $fileHash['dest_branch'] = str_replace(STORAGE_PKG_PATH, '', "{$destPath}/");
                liberty_generate_thumbnails($fileHash);
                $ret = TRUE;
                // remove temp file
                @unlink("{$destPath}/preview1.jpg");
            }
        }
    }
    return $ret;
}
コード例 #4
0
 /**
  * Store TreasuryGallery
  *
  * @param $pParamHash contains all data to store the gallery
  * @param $pParamHash[title] title of the new gallery
  * @param $pParamHash[edit] description of the gallery
  * @param $pParamHash[root_structure_id] if this is set, it will add the gallery to this structure. if it's not set, a new structure / top level gallery is created
  * @param $pParamHash[parent_id] set the structure_id that will server as the parent in the structure
  * @return bool TRUE on success, FALSE if store could not occur. If FALSE, $this->mErrors will have reason why
  * @access public
  **/
 function store(&$pParamHash)
 {
     $this->mDb->StartTrans();
     if ($this->verify($pParamHash) && LibertyContent::store($pParamHash)) {
         $table = BIT_DB_PREFIX . "treasury_gallery";
         // this really confusing, strange order way of saving items is due to strange behaviour of GenID
         // probably has to do with not null default nextval('public.liberty_structures_id_seq'::text)
         if (!empty($pParamHash['update'])) {
             if (!empty($pParamHash['gallery_store'])) {
                 $result = $this->mDb->associateUpdate($table, $pParamHash['gallery_store'], array("content_id" => $this->mContentId));
             }
             $pParamHash['structure_location_id'] = $this->mStructureId;
         } else {
             // update the gallery_store and structure_store content_id with the one from LibertyMime::store()
             $pParamHash['structure_store']['content_id'] = $pParamHash['content_id'];
             $pParamHash['gallery_store']['content_id'] = $pParamHash['content_id'];
             // we need to store the new structure node now
             global $gStructure;
             // create new object if needed
             if (empty($gStructure)) {
                 $gStructure = new LibertyStructure();
             }
             $pParamHash['structure_location_id'] = $gStructure->storeNode($pParamHash['structure_store']);
             // get the corrent structure_id
             // structure_id has to be done like this since it's screwed up in the schema
             $pParamHash['gallery_store']['structure_id'] = $this->mDb->getOne("SELECT MAX( `structure_id` ) FROM `" . BIT_DB_PREFIX . "liberty_structures`");
             $result = $this->mDb->associateInsert($table, $pParamHash['gallery_store']);
         }
         $this->mDb->CompleteTrans();
         // process image upload
         if (empty($this->mErrors)) {
             // now deal with the uploaded image
             if (!empty($pParamHash['thumb']['tmp_name'])) {
                 $checkFunc = liberty_get_function('can_thumbnail');
                 if ($checkFunc($pParamHash['thumb']['type'])) {
                     $fileHash = $pParamHash['thumb'];
                     $fileHash['dest_branch'] = $this->getGalleryThumbBaseUrl();
                     $fileHash['source_file'] = $fileHash['tmp_name'];
                     liberty_clear_thumbnails($fileHash);
                     liberty_generate_thumbnails($fileHash);
                 } else {
                     $this->mErrors['thumb'] = tra("The file you uploaded doesn't appear to be a valid image. The reported mime type is") . ": " . $pParamHash['thumb']['type'];
                 }
             }
         }
         $this->load();
     }
     return count($this->mErrors) == 0;
 }
コード例 #5
0
ファイル: BitArticleTopic.php プロジェクト: kailIII/articles
 public function storeTopic($iParamHash = NULL)
 {
     global $gLibertySystem;
     global $gBitUser;
     if ($this->verify($iParamHash)) {
         if (!$iParamHash['topic_id']) {
             $topicId = $this->mDb->GenID('article_topics_id_seq');
         } else {
             $topicId = $this->mTopicId;
         }
         if (!empty($_FILES['upload']) && $_FILES['upload']['tmp_name']) {
             $checkFunc = liberty_get_function('can_thumbnail');
             if ($checkFunc($_FILES['upload']['type'])) {
                 $fileHash = $_FILES['upload'];
                 $fileHash['dest_branch'] = $this->getTopicImageBaseUrl($topicId);
                 $fileHash['source_file'] = $fileHash['tmp_name'];
                 liberty_clear_thumbnails($fileHash);
                 liberty_generate_thumbnails($fileHash);
                 $iParamHash['has_topic_image'] = 'y';
             } else {
                 $this->mErrors = tra("The file you uploaded doesn't appear to be a valid image. The reported mime type is") . ": " . $_FILES['upload']['type'];
             }
         }
         if ($iParamHash['topic_id']) {
             $this->mDb->associateUpdate(BIT_DB_PREFIX . "article_topics", $iParamHash, array('topic_id' => $iParamHash['topic_id']));
         } else {
             $iParamHash['topic_id'] = $topicId;
             $this->mDb->associateInsert(BIT_DB_PREFIX . "article_topics", $iParamHash);
         }
     }
     $this->mTopicId = $iParamHash['topic_id'];
 }
コード例 #6
0
ファイル: mime.themes.php プロジェクト: bitweaver/treasury
/**
 * All the files that have been extracted so far need to be processed and moved around
 * 
 * @param array $pStoreRow 
 * @access public
 * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
 */
function treasury_theme_process_extracted_files($pStoreRow)
{
    // if this is a theme, we need to convert the preview image into thumbnails
    if (!empty($pStoreRow['thumb'])) {
        $pStoreRow['thumb']['source_file'] = $pStoreRow['thumb']['tmp_name'];
        $pStoreRow['thumb']['dest_branch'] = $pStoreRow['upload']['dest_branch'];
        $pStoreRow['thumb']['dest_base_name'] = $pStoreRow['thumb']['name'];
        liberty_generate_thumbnails($pStoreRow['thumb']);
    }
    // if we have screenshots we better do something with them
    if (!empty($pStoreRow['screenshots'])) {
        foreach ($pStoreRow['screenshots'] as $key => $sshot) {
            $resizeFunc = liberty_get_function('resize');
            $sshot['source_file'] = $sshot['tmp_name'];
            $sshot['dest_base_name'] = $sshot['name'];
            $sshot['dest_branch'] = $pStoreRow['upload']['dest_branch'];
            $sshot['max_width'] = 400;
            $sshot['max_height'] = 300;
            $sshot['medium_thumb_path'] = BIT_ROOT_PATH . $resizeFunc($sshot);
        }
    }
    // if we have icons, we should place them somewhere that we can display them
    if (!empty($pStoreRow['icons'])) {
        @mkdir(BIT_ROOT_PATH . $pStoreRow['upload']['dest_branch'] . 'icons');
        foreach ($pStoreRow['icons'] as $icon) {
            $dest = BIT_ROOT_PATH . $pStoreRow['upload']['dest_branch'] . 'icons/' . basename($icon);
            if ($icon != $dest) {
                rename($icon, $dest);
            }
        }
    }
    // now that all is done, we can remove temporarily extracted files
    if (!empty($pStoreRow['ext_path'])) {
        unlink_r($pStoreRow['ext_path']);
    }
}
コード例 #7
0
ファイル: FisheyeImage.php プロジェクト: bitweaver/fisheye
 function renderThumbnails($pThumbSizes = NULL)
 {
     global $gBitSystem;
     if ($this->getField('file_name') || $this->load()) {
         $fileHash['source_file'] = $this->getSourceFile();
         $fileHash['type'] = $gBitSystem->verifyMimeType($fileHash['source_file']);
         $fileHash['size'] = filesize($fileHash['source_file']);
         $fileHash['dest_branch'] = $this->getStorageBranch($fileHash);
         $fileHash['name'] = $this->getField('file_name');
         $fileHash['thumbnail_sizes'] = $pThumbSizes;
         // just generate thumbnails
         liberty_generate_thumbnails($fileHash);
         if (!empty($fileHash['error'])) {
             $this->mErrors['thumbnail'] = $fileHash['error'];
         }
     }
     return count($this->mErrors) == 0;
 }
コード例 #8
0
ファイル: edit_item.php プロジェクト: bitweaver/treasury
            $_REQUEST['update_file'] = TRUE;
        }
    } else {
        $feedback['error'] = tra('The file could not be reprocessed. There was a problem locating the original file.');
    }
}
if (!empty($_REQUEST['update_file'])) {
    // this will override any thumbnails created by the plugin
    if (!empty($_FILES['icon']['tmp_name'])) {
        if (preg_match('#^image/#i', strtolower($_FILES['icon']['type']))) {
            if (!empty($_FILES['icon']['tmp_name'])) {
                $fileHash = $_FILES['icon'];
                $fileHash['dest_branch'] = dirname($gContent->mInfo['storage_path']) . '/';
                $fileHash['source_file'] = $_FILES['icon']['tmp_name'];
                liberty_clear_thumbnails($fileHash);
                liberty_generate_thumbnails($fileHash);
            }
            // we've done everything with the icon. this will ensure that LibertyMime doesn't get any crazy ideas
            unset($_FILES['icon']);
        } else {
            $feedback['error'] = tra("The file you uploaded doesn't appear to be a valid image. The reported mime type is") . ": " . $_FILES['icon']['type'];
        }
    }
    if (!empty($_FILES['file']['tmp_name'])) {
        $_REQUEST['upload'] = $_FILES['file'];
    }
    if ($gContent->store($_REQUEST)) {
        $feedback = $gContent->mErrors;
    }
    // give some feedback if all went well
    if (empty($feedback['error'])) {
コード例 #9
0
ファイル: mime.pdfx.php プロジェクト: kailIII/liberty
/**
 * mime_pdf_convert_pdf2swf Convert a PDF to a SWF video
 *
 * @param array $pFileHash file details.
 * @param array $pFileHash[upload] should contain a complete hash from $_FILES
 * @access public
 * @return TRUE on success, FALSE on failure
 */
function mime_pdfx_thumbnail($pFileHash)
{
    global $gBitSystem;
    $mwconvert = trim($gBitSystem->getConfig('mwconvert_path', shell_exec('which convert')));
    if (is_executable($mwconvert) && $gBitSystem->getConfig('pdf_thumbnails', 'y') == 'y') {
        $source = STORAGE_PKG_PATH . $pFileHash['upload']['dest_branch'];
        if ($gBitSystem->isFeatureActive('liberty_jpeg_originals')) {
            $source .= 'original.jpg';
        } else {
            $source .= $pFileHash['upload']['name'];
        }
        $dest_branch = dirname($source);
        $thumb_file = "{$dest_branch}/thumb.jpg";
        $mwccommand = "{$mwconvert} '{$source}' '{$thumb_file}'";
        shell_exec($mwccommand);
        if (is_file($thumb_file) && filesize($thumb_file) > 0) {
        } else {
            if (is_file("{$dest_branch}/thumb-0.jpg")) {
                $thumb_file = "{$dest_branch}/thumb-0.jpg";
            }
        }
        $genHash = array('attachment_id' => $pFileHash['attachment_id'], 'dest_branch' => $pFileHash['upload']['dest_branch'], 'source_file' => $thumb_file, 'type' => 'image/jpeg', 'thumbnail_sizes' => array('extra-large', 'large', 'medium', 'small', 'avatar', 'icon'));
        if (liberty_generate_thumbnails($genHash)) {
            //				$genHash['source_file'] = $genHash['icon_thumb_path'];
            //				if( !$panoramaFunc( $genHash )) {
            //					$pStoreRow['errors']['panorama'] = $genHash['error'];
            //				}
        }
        $mask = "{$dest_branch}/thumb*.jpg";
        array_map("unlink", glob($mask));
    }
    return empty($pFileHash['log']);
}
コード例 #10
0
ファイル: mime.audio.php プロジェクト: kailIII/liberty
/**
 * mime_audio_converter 
 * 
 * @param array $pParamHash 
 * @access public
 * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
 */
function mime_audio_converter(&$pParamHash)
{
    global $gBitSystem;
    // audio conversion can take a while
    ini_set("max_execution_time", "1800");
    $ret = FALSE;
    $log = array();
    $source = STORAGE_PKG_PATH . $pParamHash['upload']['dest_branch'] . $pParamHash['upload']['name'];
    $destPath = dirname($source);
    if (@BitBase::verifyId($pParamHash['attachment_id'])) {
        $pattern = "#.*\\.(mp3|m4a)\$#i";
        if (!$gBitSystem->isFeatureActive('mime_audio_force_encode') && preg_match($pattern, $pParamHash['upload']['name'])) {
            // make a copy of the original maintaining the original extension
            $dest_file = $destPath . '/bitverted.' . preg_replace($pattern, "\$1", strtolower($pParamHash['upload']['name']));
            if (!is_file($dest_file) && !link($source, $dest_file)) {
                copy($source, $dest_file);
            }
            $ret = TRUE;
        } else {
            // TODO: have a better mechanism of converting audio to mp3. ffmpeg works well as long as the source is 'perfect'
            //       there are many audiofiles that can't be read by ffmpeg but by other tools like flac, faac, oggenc
            //       mplayer is very good, but has a lot of dependencies and not many servers have it installed
            //       also, using mplayer is a 2 step process: decoding and encoding
            // if we convert audio, we always make an mp3
            $dest_file = $destPath . '/bitverted.mp3';
            if (!($ret = mime_audio_converter_ffmpeg($pParamHash, $source, $dest_file))) {
                // fall back to using slower mplayer / lame combo
                $ret = mime_audio_converter_mplayer_lame($pParamHash, $source, $dest_file);
            }
        }
        // if the conversion was successful, we'll copy the tags to the new mp3 file and import data to meta tables
        if ($ret == TRUE) {
            $log['success'] = 'Successfully converted to mp3 audio';
            // now that we have a new mp3 file, we might as well copy the tags accross in case someone downloads it
            require_once UTIL_PKG_PATH . 'getid3/getid3/getid3.php';
            $getID3 = new getID3();
            // we silence this since this will spew lots of ugly errors when using UTF-8 and some odd character in the file ID
            $meta = @$getID3->analyze($source);
            getid3_lib::CopyTagsToComments($meta);
            // write tags to new mp3 file
            if ($errors = mime_audio_update_tags($dest_file, $meta['comments'])) {
                $log['tagging'] = $errors;
            }
            // getID3 returns everything in subarrays - we want to store everything in [0]
            foreach ($meta['comments'] as $key => $comment) {
                $store[$key] = $comment[0];
            }
            $store['playtimeseconds'] = $meta['playtime_seconds'];
            $store['playtimestring'] = $meta['playtime_string'];
            // make sure we remove previous entries first
            LibertyMime::expungeMetaData($pParamHash['attachment_id']);
            if (!LibertyMime::storeMetaData($pParamHash['attachment_id'], 'ID3', $store)) {
                $log['store_meta'] = "There was a problem storing the meta data in the database";
            }
            // if we have an image in the id3v2 tag, we might as well do something with it
            // we'll simply use the first image we can find in the file
            if (!empty($meta['id3v2']['APIC'][0]['data'])) {
                $image = $meta['id3v2']['APIC'][0];
            } elseif (!empty($meta['id3v2']['PIC'][0]['data'])) {
                $image = $meta['id3v2']['PIC'][0];
            }
            if (!empty($image)) {
                // write the image to temp file for us to process
                $tmpfile = str_replace("//", "/", tempnam(TEMP_PKG_PATH, LIBERTY_PKG_NAME));
                if ($fp = fopen($tmpfile, 'w')) {
                    fwrite($fp, $image['data']);
                    fclose($fp);
                    $fileHash['type'] = $image['mime'];
                    $fileHash['source_file'] = $tmpfile;
                    $fileHash['dest_branch'] = $pParamHash['upload']['dest_branch'];
                    liberty_generate_thumbnails($fileHash);
                    // remove temp file
                    if (!empty($tmpfile) && is_file($tmpfile)) {
                        unlink($tmpfile);
                    }
                }
            }
            // TODO: when tags package is enabled add an option to add tags
            //       recommended tags might be artist and album
            // TODO: fetch album cover from amazon.com or musicbrainz.org
            //       fetch lyrics from lyricwiki.org
            //$item->mLogs['audio_converter'] = "Audio file was successfully converted to MP3.";
        }
    }
    // update log
    $pParamHash['log'] = array_merge($pParamHash['log'], $log);
    return $ret;
}