コード例 #1
0
 /**
  * A display name handler for media works
  *
  * Includes a thumbnail of the work's placard image as part of the display name
  *
  * @param mixed $id Reason ID or entity
  * @return string
  */
 function reason_media_work_display_name_handler($id)
 {
     if (!is_object($id)) {
         $e = new entity($id);
     } else {
         $e = $id;
     }
     if ($e->get_value('transcoding_status') == 'converting' || $e->get_value('transcoding_status') == 'finalizing') {
         return '<img src="' . REASON_HTTP_BASE_PATH . 'ui_images/spinner_16.gif" width="16" height="16" alt="Converting" /> ' . $e->get_value('name');
     }
     if ($e->get_value('transcoding_status') == 'error') {
         return '<img src="' . REASON_HTTP_BASE_PATH . 'silk_icons/error.png" width="16" height="16" alt="Error" /> ' . $e->get_value('name');
     }
     if ($e->get_value('transcoding_status') && ($images = $e->get_left_relationship('av_to_primary_image'))) {
         $image = current($images);
         if ($path = reason_get_image_path($image, 'thumbnail')) {
             if (file_exists($path)) {
                 if ($size = getimagesize($path)) {
                     return '<img src="' . htmlspecialchars(reason_get_image_url($image, 'thumbnail'), ENT_QUOTES) . '" width="' . round($size[0] / 2) . '" height="' . round($size[1] / 2) . '" alt="' . reason_htmlspecialchars(strip_tags($image->get_value('description'))) . '" /> ' . $e->get_value('name');
                 }
             }
         }
     }
     switch ($e->get_value('av_type')) {
         case 'Audio':
             return '<img src="' . REASON_HTTP_BASE_PATH . 'silk_icons/sound.png" width="16" height="16" alt="Audio" /> ' . $e->get_value('name');
         case 'Video':
             return '<img src="' . REASON_HTTP_BASE_PATH . 'silk_icons/television.png" width="16" height="16" alt="Video" /> ' . $e->get_value('name');
         default:
             return $e->get_value('name');
     }
 }
コード例 #2
0
ファイル: image.php プロジェクト: hunter2814/reason_package
 function delete_entity()
 {
     if (!$this->get_value('id')) {
         return;
     }
     $image = new entity($this->get_value('id'));
     $paths = array();
     $paths['thumbnail'] = reason_get_image_path($image, 'thumbnail');
     $paths['normal'] = reason_get_image_path($image);
     $paths['original'] = reason_get_image_path($image, 'original');
     foreach ($paths as $key => $path) {
         if (file_exists($path)) {
             $largest = $key;
         }
     }
     if ($largest) {
         // move to image graveyard
         if (defined('REASON_IMAGE_GRAVEYARD') && REASON_IMAGE_GRAVEYARD) {
             if (!file_exists(REASON_IMAGE_GRAVEYARD)) {
                 mkdir(REASON_IMAGE_GRAVEYARD);
             }
             rename($paths[$largest], REASON_IMAGE_GRAVEYARD . basename($paths[$largest]));
             unset($paths[$largest]);
         }
         foreach ($paths as $key => $path) {
             if (file_exists($path)) {
                 unlink($path);
             }
         }
     }
     $sized_image_directory = REASON_SIZED_IMAGE_DIR . $image->id() . '/';
     if (file_exists($sized_image_directory)) {
         $this->delete_directory($sized_image_directory);
     }
     $custom_sized_image_directory = REASON_INC . 'www/sized_images_custom/' . $image->id() . '/';
     if (file_exists($custom_sized_image_directory)) {
         $this->delete_directory($custom_sized_image_directory);
     }
     parent::delete_entity();
 }
コード例 #3
0
ファイル: feature.php プロジェクト: hunter2814/reason_package
 /**
  * A display name handler for features
  *
  * Includes a thumbnail of one of the feature's images as part of the display name
  *
  * @param mixed $id Reason ID or entity
  * @return string
  */
 function reason_feature_display_name_handler($id)
 {
     if (!is_object($id)) {
         $e = new entity($id);
     } else {
         $e = $id;
     }
     if ($images = $e->get_left_relationship('feature_to_image')) {
         $image = reset($images);
         if ($path = reason_get_image_path($image, 'thumbnail')) {
             if (file_exists($path)) {
                 if ($size = getimagesize($path)) {
                     return '<img src="' . htmlspecialchars(reason_get_image_url($image, 'thumbnail'), ENT_QUOTES) . '" width="' . round($size[0] / 2) . '" height="' . round($size[1] / 2) . '" alt="' . reason_htmlspecialchars(strip_tags($image->get_value('description'))) . '" /> ' . $e->get_value('name');
                 }
             }
         }
     } elseif ($media = $e->get_left_relationship('feature_to_media_work')) {
         $m = reset($media);
         $images = $m->get_left_relationship('av_to_primary_image');
         if (!empty($images)) {
             $image = reset($images);
             if ($path = reason_get_image_path($image, 'thumbnail')) {
                 if (file_exists($path)) {
                     if ($size = getimagesize($path)) {
                         return '<img src="' . htmlspecialchars(reason_get_image_url($image, 'thumbnail'), ENT_QUOTES) . '" width="' . round($size[0] / 2) . '" height="' . round($size[1] / 2) . '" alt="' . reason_htmlspecialchars(strip_tags($image->get_value('description'))) . '" /> ' . $e->get_value('name');
                     }
                 }
             }
         }
         switch ($m->get_value('av_type')) {
             case 'Audio':
                 return '<img src="' . REASON_HTTP_BASE_PATH . 'silk_icons/sound.png" width="16" height="16" alt="Audio" /> ' . $e->get_value('name');
             case 'Video':
                 return '<img src="' . REASON_HTTP_BASE_PATH . 'silk_icons/television.png" width="16" height="16" alt="Video" /> ' . $e->get_value('name');
         }
     }
     return $e->get_value('name');
 }
コード例 #4
0
    /**
     * Run the upgrader
     *
     *
     * @return string HTML report
     */
    public function run()
    {
        /* 
        	Check for progress in script -- a starting index of -1 implies that all photos have 
        	already been processed during this session
        */
        if (isset($_SESSION['reason_thumbnail_standardize_script']['last_end_index'])) {
            $start_index = $_SESSION['reason_thumbnail_standardize_script']['last_end_index'];
        } else {
            $start_index = 0;
        }
        if ($start_index == -1) {
            return 'This script has already processed all images during this session!' . '<br />';
        } else {
            $start_time = time();
            $php_max_time = ini_get('max_execution_time');
            if ($php_max_time == 0) {
                $time_limit = 15;
            } else {
                $time_limit = min($php_max_time / 2, 15);
            }
            $es = new entity_selector();
            $es->add_type(id_of('image'));
            $all_image_ids = $es->get_ids();
            $ids_with_only_tb = array();
            $total_num_images = sizeof($all_image_ids);
            /* Start processing images where last time left off, or start at the beginning */
            /* Runs for $time_limit seconds at a time, continues process when script is run again */
            for ($i = $start_index; $i < $total_num_images; $i++) {
                $main_image_path = reason_get_image_path($all_image_ids[$i]);
                /* If no main image exists, copy the thumbnail to be the main image */
                if (!file_exists($main_image_path)) {
                    $thumbnail_path = reason_get_image_path($all_image_ids[$i], 'thumbnail');
                    if (file_exists($thumbnail_path)) {
                        $ids_with_only_tb[] = $all_image_ids[$i];
                        if (!copy($thumbnail_path, $main_image_path)) {
                            echo 'failed to copy image of id ' . $all_image_ids[$i];
                        }
                    }
                }
                if (time() - $start_time > $time_limit) {
                    break;
                }
            }
            /* If all images have been processed, reset the last index*/
            if ($i >= $total_num_images) {
                $_SESSION['reason_thumbnail_standardize_script']['last_end_index'] = -1;
                $_SESSION['reason_thumbnail_standardize_script']['run_again'] = false;
            } else {
                $_SESSION['reason_thumbnail_standardize_script']['last_end_index'] = $i;
                $_SESSION['reason_thumbnail_standardize_script']['run_again'] = true;
            }
            /* Give user some info on how many more times script should be run */
            $percent_remaining = substr(($total_num_images - $i) / $total_num_images * 100, 0, 4);
            echo '<br /> There are ' . $total_num_images . ' total images to process';
            echo '<br /> This execution of the script started at the ' . $start_index . 'th photo';
            echo '<br /> It processed a total of ' . ($i - $start_index) . ' images, and created new main
			images from ' . sizeof($ids_with_only_tb) . ' thumbnails.';
            echo '<br /> A total of ' . ($total_num_images - $i) . ', (' . $percent_remaining . '%)
			images still need to be processed <br />';
        }
    }
コード例 #5
0
 function _orig_exists()
 {
     if (!isset($this->orig_exists)) {
         $entity = $this->get_entity();
         $this->orig_exists = file_exists(reason_get_image_path($entity, 'original'));
     }
     return $this->orig_exists;
 }
コード例 #6
0
 protected function get_media_placard_info($media)
 {
     if ($placards = $media->get_left_relationship('av_to_primary_image')) {
         $placard = current($placards);
         $placard_url = reason_get_image_url($placard, 'tn');
         list($width, $height) = getimagesize(reason_get_image_path($placard, 'tn'));
     } else {
         $placard_url = REASON_HTTP_BASE_PATH . 'modules/publications/media_placeholder_thumbnail.png';
         $width = 125;
         $height = 70;
     }
     return array('url' => $placard_url, 'width' => $width, 'height' => $height);
 }
コード例 #7
0
 /**
  * Run the upgrader
  *
  * @return string HTML report
  */
 public function run()
 {
     /* 
     	Check for progress in script -- a starting index of -1 implies that all photos have 
     	already been processed during this session
     */
     $current_user = check_authentication();
     if (!reason_user_has_privs(get_user_id($current_user), 'db_maintenance')) {
         die('don\'t have the right permissions?');
     }
     if (isset($_SESSION['reason_image_type_script']['last_end_index'])) {
         $start_index = $_SESSION['reason_image_type_script']['last_end_index'];
     } else {
         $start_index = 0;
     }
     if ($start_index == -1) {
         echo '<p>This script has already processed all images during this session!' . '</p>';
     } else {
         $start_time = time();
         $php_max_time = ini_get('max_execution_time');
         if ($php_max_time == 0) {
             $time_limit = 30;
         } else {
             $time_limit = min($php_max_time / 2, 50);
         }
         $es = new entity_selector();
         $es->add_type(id_of('image'));
         $all_image_ids = $es->get_ids('', 'All', 'get_ids_error');
         /* 
             3 cases for which FILES actually exist
             1. only standard -- no need to update the image Entity table
             2. standard and thumbnail -- give these entities a thumbnail_image_type field
             3. standard, thumbnail, original (full-size) -- give these entites a thumbnail_image_type and
             original_image_type field
         */
         $ids_with_tn = array();
         $ids_with_tn_full = array();
         chdir(PHOTOSTOCK);
         $total_num_image_ids = count($all_image_ids);
         // make sure fields we are going to write to actually exist
         $this->add_unexisting_image_fields();
         for ($index = $start_index; $index < $total_num_image_ids; $index++) {
             $image_id = $all_image_ids[$index];
             if (file_exists(reason_get_image_path($image_id, 'thumbnail'))) {
                 $image = new entity($image_id);
                 // Check if the entity already has a thumbnail_image_type to avoid clobbering an old value
                 // when the UPDATE SQL query is run
                 // Note: at this point, we have determined a thumbnail exists, so 'thumbnail_image_type'
                 // will not be null if the field already exists
                 if (!$image->has_value('thumbnail_image_type')) {
                     if (file_exists(reason_get_image_path($image_id, 'original'))) {
                         $ids_with_tn_full[] = $image_id;
                     } else {
                         $ids_with_tn[] = $image_id;
                     }
                 }
             }
             if (time() - $start_time > $time_limit) {
                 break;
             }
         }
         $this->run_sql_queries($ids_with_tn, $ids_with_tn_full);
         // Session stuff
         if ($index >= $total_num_image_ids) {
             $_SESSION['reason_image_type_script']['last_end_index'] = -1;
             $_SESSION['reason_image_type_script']['run_again'] = false;
         } else {
             $_SESSION['reason_image_type_script']['last_end_index'] = $index;
             $_SESSION['reason_image_type_script']['run_again'] = true;
         }
         echo '<p>Started at index ' . $start_index . ' out of ' . $total_num_image_ids . '<br />';
         echo 'Ended at index ' . $index . ' (' . round($index / $total_num_image_ids * 100, 2) . '%)<br />';
         echo 'Processed ' . ($index - $start_index) . ' total images<br />';
         echo 'There were a total of ' . count($ids_with_tn) . ' ids with a main image and thumbnail <br />';
         echo 'There were a total of ' . count($ids_with_tn_full) . ' ids with a main image, thumbnail, and full</p>';
     }
 }
コード例 #8
0
 function _get_max_dimensions($image)
 {
     $orig_path = reason_get_image_path($image, 'original');
     if (!file_exists($orig_path) || $this->admin_page->site_id != get_owner_site_id($this->admin_page->id)) {
         $largest_width = $image->get_value('width');
         $largest_height = $image->get_value('height');
     } else {
         list($largest_width, $largest_height) = getimagesize($orig_path);
     }
     return array('width' => $largest_width, 'height' => $largest_height);
 }
コード例 #9
0
/**
* A test function for testing _imagemagick_crop_image.  It allows
* you to test several cases quickly.
*/
function im_resize_images()
{
    global $d;
    $img_ids = explode(",", $d['image_id']);
    $width = (int) $d['w'];
    $height = (int) $d['h'];
    $crop_style = $d['crop_style'];
    $target = array();
    $source = array();
    $url = array();
    foreach ($img_ids as $id) {
        $rsi = new reasonSizedImage();
        $rsi->set_id($id);
        $rsi->set_width($width);
        $rsi->set_height($height);
        $rsi->set_crop_style($crop_style);
        $target[] = $rsi->_get_path();
        $entity = new entity($id);
        $source[] = reason_get_image_path($entity, 'standard');
        $url[] = $rsi->_get_url();
    }
    //	print_r($target);
    //	pray($source);
    //	pray($url);
    for ($i = 0; $i < count($source); $i++) {
        _imagemagick_crop_image($width, $height, $source[$i], $target[$i], false);
    }
    $str = "";
    for ($i = 0; $i < count($url); $i++) {
        $str .= "" . $url[$i] . ",";
    }
    $str = trim($str, ",");
    echo $str;
    //		_imagemagick_crop_image($nw,$nh,$source,$target,false);
    //	resize_images();
}
コード例 #10
0
 function show_image($image, $thumbnail = true)
 {
     if ($thumbnail) {
         if (0 != $this->params['thumbnail_height'] or 0 != $this->params['thumbnail_width']) {
             $rsi = new reasonSizedImage();
             $rsi->set_id($image->id());
             if (0 != $this->params['thumbnail_height']) {
                 $rsi->set_height($this->params['thumbnail_height']);
             }
             if (0 != $this->params['thumbnail_width']) {
                 $rsi->set_width($this->params['thumbnail_width']);
             }
             if ('' != $this->params['thumbnail_crop']) {
                 $rsi->set_crop_style($this->params['thumbnail_crop']);
             }
             $width = $rsi->get_image_width();
             $height = $rsi->get_image_height();
             $image_url = $rsi->get_url();
             $image_path = $rsi->get_file_system_path_and_file_of_dest();
         } else {
             $image_path = reason_get_image_path($image, 'tn');
             $image_url = reason_get_image_url($image, 'tn');
             if (!file_exists($image_path)) {
                 $image_path = reason_get_image_path($image);
                 $image_url = reason_get_image_url($image);
             }
             list($width, $height) = getimagesize($image_path);
         }
         $class = 'thumbnail';
     } elseif (!$thumbnail) {
         if (0 != $this->params['height'] or 0 != $this->params['width']) {
             $rsi = new reasonSizedImage();
             $rsi->set_id($image->id());
             if (0 != $this->params['height']) {
                 $rsi->set_height($this->params['height']);
             }
             if (0 != $this->params['width']) {
                 $rsi->set_width($this->params['width']);
             }
             if ('' != $this->params['crop']) {
                 $rsi->set_crop_style($this->params['crop']);
             }
             $width = $rsi->get_image_width();
             $height = $rsi->get_image_height();
             $image_url = $rsi->get_url();
             $image_path = $rsi->get_file_system_path_and_file_of_dest();
         } else {
             $image_path = reason_get_image_path($image);
             list($width, $height) = getimagesize($image_path);
             $image_url = reason_get_image_url($image);
         }
         $class = 'mainImage';
     }
     if (file_exists($image_path)) {
         $alt = $image->get_value('description');
         if (!$alt) {
             $alt = $image->get_value('keywords');
             if (!$alt) {
                 $alt = $image->get_value('name');
             }
         }
         $mod_time = filemtime($image_path);
         return $this->show_image_markup($image_url, $height, $width, $alt, $class, $mod_time);
     } else {
         return false;
     }
 }