Ejemplo n.º 1
0
 function refresh_cache()
 {
     $url = reason_get_page_url($this->get_page());
     $result = get_reason_url_contents($url);
     if ($result) {
         $this->report('Rebuilt the cache by hitting ' . $url);
     }
 }
Ejemplo n.º 2
0
function attach_thumbnail($media_work, $shim)
{
    // create image file in the vimeo temp directory
    $image_url = $shim->get_thumbnail($media_work->get_value('entry_id'));
    if ($image_url) {
        $tmp_path = VimeoShim::get_temp_dir() . 'tmp_thumbnail_' . $media_work->get_value('id');
        $f = fopen($tmp_path, 'w');
        $contents = get_reason_url_contents($image_url);
        fwrite($f, $contents);
        fclose($f);
        $user = new entity($media_work->get_value('created_by'));
        $username = $user->get_value('name');
        // Create a reason entity out of the temp image file
        if (!empty($tmp_path) && file_exists($tmp_path) && $username) {
            if ($id = create_image_entity($media_work, $username)) {
                reason_include_once('content_managers/image.php3');
                $im = new ImageManager();
                $im->thumbnail_width = REASON_STANDARD_MAX_THUMBNAIL_WIDTH;
                $im->thumbnail_height = REASON_STANDARD_MAX_THUMBNAIL_HEIGHT;
                $im->max_width = REASON_STANDARD_MAX_IMAGE_WIDTH;
                $im->max_height = REASON_STANDARD_MAX_IMAGE_HEIGHT;
                $im->load_by_type(id_of('image'), $id, $media_work->get_value('created_by'));
                $im->handle_standard_image($id, $tmp_path);
                $im->create_default_thumbnail($id);
                $values = array();
                foreach ($im->get_element_names() as $element_name) {
                    $values[$element_name] = $im->get_value($element_name);
                }
                reason_update_entity($id, get_user_id($username), $values, false);
                create_relationship($media_work->get_value('id'), $id, relationship_id_of('av_to_primary_image'));
            }
        }
    } else {
        echo date(DATE_RFC822) . ': No thumbnail url found for media work with id ' . $media_work->get_value('entry_id') . "\n";
    }
}
 /**
  * This callback generates the thumbnail image for the video.  It also updates some metadata 
  * such as duration for the entity.
  */
 public function _process_callback()
 {
     $username = reason_check_authentication();
     reason_update_entity($this->manager->get_value('id'), get_user_id($username), array('media_publication_datetime' => date('Y-m-d H:i:s')), false);
     if ($this->manager->get_value('vimeo_url') && $this->manager->get_value('entry_id') != $this->original_entry_id) {
         // create image file in the vimeo temp directory
         $tmp_path = VimeoShim::get_temp_dir() . 'tmp_thumbnail_' . $this->manager->get_value('id');
         $f = fopen($tmp_path, 'w');
         $image_url = $this->shim->get_thumbnail($this->manager->get_value('entry_id'));
         $contents = get_reason_url_contents($image_url);
         fwrite($f, $contents);
         fclose($f);
         // Create a reason entity out of the temp image file
         if (!empty($tmp_path) and file_exists($tmp_path) && $username) {
             if ($id = $this->create_image_entity($username)) {
                 $im = new ImageManager();
                 $im->thumbnail_width = REASON_STANDARD_MAX_THUMBNAIL_WIDTH;
                 $im->thumbnail_height = REASON_STANDARD_MAX_THUMBNAIL_HEIGHT;
                 $im->max_width = REASON_STANDARD_MAX_IMAGE_WIDTH;
                 $im->max_height = REASON_STANDARD_MAX_IMAGE_HEIGHT;
                 $im->load_by_type(id_of('image'), $id, get_user_id($username));
                 $im->handle_standard_image($id, $tmp_path);
                 $im->create_default_thumbnail($id);
                 $values = array();
                 foreach ($im->get_element_names() as $element_name) {
                     $values[$element_name] = $im->get_value($element_name);
                 }
                 reason_update_entity($id, get_user_id($username), $values, false);
                 // Remove any existing association with an image and replace it with this new one
                 delete_relationships(array('entity_a' => $this->manager->get_value('id'), 'type' => relationship_id_of('av_to_primary_image')));
                 create_relationship($this->manager->get_value('id'), $id, relationship_id_of('av_to_primary_image'));
             }
         }
         // update the duration field of the media work.
         $data_obj = $this->shim->get_video_data($this->manager->get_value('entry_id'));
         if ($data_obj) {
             reason_update_entity($this->manager->get_value('id'), get_user_id($username), array('media_duration' => format_seconds_as_human_readable(intval($data_obj->duration))), false);
         }
     }
 }
/**
 * Attempt to attach a thumbnail to the media work.
 *
 * @param $obj object
 * @param $media_work entity
 * @param $netid string
 */
function attach_thumbnail($obj, $media_work, $netid)
{
    // check to see if this had thumbnails generated
    if (property_exists($obj, 'thumbnails')) {
        // First, create temp file
        $tmp_path = ZencoderShim::get_temp_dir() . 'temp_media_image_' . $media_work->get_value('entry_id') . '.jpg';
        $f = fopen($tmp_path, 'w');
        $image_url = $obj->thumbnails[0]->images[0]->url;
        $contents = get_reason_url_contents($image_url);
        fwrite($f, $contents);
        fclose($f);
        // Then, create image entity.  Attach it to the media work, too.
        if (!empty($tmp_path) and file_exists($tmp_path)) {
            // Create a new entity for the image
            if ($id = create_image_entity($media_work, $netid)) {
                $im = new ImageManager();
                //$im->convert_non_web_to = $this->convert_non_web_to;
                $im->thumbnail_width = REASON_STANDARD_MAX_THUMBNAIL_WIDTH;
                $im->thumbnail_height = REASON_STANDARD_MAX_THUMBNAIL_HEIGHT;
                $im->max_width = REASON_STANDARD_MAX_IMAGE_WIDTH;
                $im->max_height = REASON_STANDARD_MAX_IMAGE_HEIGHT;
                $im->load_by_type(id_of('image'), $id, get_user_id($netid));
                $im->handle_standard_image($id, $tmp_path);
                //$im->handle_original_image($id, $image);
                $im->create_default_thumbnail($id);
                $dimensions = $obj->thumbnails[0]->images[0]->dimensions;
                $arr = explode('x', $dimensions);
                $thumb_width = intval($arr[0]);
                $thumb_height = intval($arr[1]);
                if ($thumb_width > $im->max_width || $thumb_height > $im->max_height) {
                    $image_path = PHOTOSTOCK . reason_format_image_filename($id, 'jpg');
                    $original_path = add_name_suffix($image_path, '_orig');
                    @copy($image_path, $original_path);
                    resize_image($image_path, $im->max_width, $im->max_height);
                }
                // Pull the values generated in the content manager
                // and save them to the entity
                $values = array();
                foreach ($im->get_element_names() as $element_name) {
                    $values[$element_name] = $im->get_value($element_name);
                }
                reason_update_entity($id, get_user_id($netid), $values, false);
                // Remove any existing association with an image and replace it with this new one
                delete_relationships(array('entity_a' => $media_work->id(), 'type' => relationship_id_of('av_to_primary_image')));
                create_relationship($media_work->id(), $id, relationship_id_of('av_to_primary_image'));
            } else {
                trigger_error('Failed to create image entity.');
            }
        } else {
            trigger_error('No path to image: ' . $tmp_path);
        }
    }
}
 function process_form(&$disco)
 {
     $images = $this->get_images();
     $thumbnail_image = $images[$disco->get_value('thumbnails')];
     $tmp_path = WEB_PATH . trim_slashes(WEB_TEMP) . '/temp_media_image_' . uniqid() . '.jpg';
     $contents = get_reason_url_contents($thumbnail_image);
     if (!$contents) {
         trigger_error('Unable to retrieve file contents for ' . $thumbnail_image . '. The url is invalid or S3 is being slow.');
         return;
     }
     $f = fopen($tmp_path, 'w');
     fwrite($f, $contents);
     fclose($f);
     if (!empty($tmp_path) and file_exists($tmp_path)) {
         // Create a new entity for the image
         if ($id = $this->create_image_entity()) {
             $im = new ImageManager();
             //$im->convert_non_web_to = $this->convert_non_web_to;
             $im->thumbnail_width = REASON_STANDARD_MAX_THUMBNAIL_WIDTH;
             $im->thumbnail_height = REASON_STANDARD_MAX_THUMBNAIL_HEIGHT;
             $im->max_width = REASON_STANDARD_MAX_IMAGE_WIDTH;
             $im->max_height = REASON_STANDARD_MAX_IMAGE_HEIGHT;
             $im->load_by_type(id_of('image'), $id, $this->user->id());
             $im->handle_standard_image($id, $tmp_path);
             //$im->handle_original_image($id, $image);
             $im->create_default_thumbnail($id);
             $image_path = PHOTOSTOCK . reason_format_image_filename($id, 'jpg');
             $original_path = add_name_suffix($image_path, '_orig');
             @copy($image_path, $original_path);
             resize_image($image_path, $im->max_width, $im->max_height);
             // Pull the values generated in the content manager
             // and save them to the entity
             $values = array();
             foreach ($im->get_element_names() as $element_name) {
                 $values[$element_name] = $im->get_value($element_name);
             }
             reason_update_entity($id, $this->user->id(), $values, false);
             // Remove any existing association with an image and replace it with this new one
             delete_relationships(array('entity_a' => $this->media_work->id(), 'type' => relationship_id_of('av_to_primary_image')));
             create_relationship($this->media_work->id(), $id, relationship_id_of('av_to_primary_image'));
         } else {
             trigger_error('Failed to create image entity.');
         }
     } else {
         trigger_error('No path to image: ' . $tmp_path);
     }
 }
Ejemplo n.º 6
0
/**
 * Is mod rewrite available and working? We check like this:
 *
 * 1. create an .htaccess file
 * 2. create an .html file
 * 3. test the rewrite with curl
 * 4. cleanup
 * 5. return true or false
 *
 */
function mod_rewrite_check()
{
    $test_string = 'reason_rocks';
    // randomize me
    $dir_name = 'mod_rewrite_check/';
    $dir_url = $path = carl_construct_link(array(''), array(''), WEB_TEMP . $dir_name);
    $dir_path = rtrim($_SERVER['DOCUMENT_ROOT'], DIRECTORY_SEPARATOR) . WEB_TEMP . $dir_name;
    $file_content = "<?php\nif (isset(\$_GET['zzz']))\n{\necho ('" . $test_string . "');\n}\n?>";
    $file_name = 'test_file.php';
    $file_path = $dir_path . $file_name;
    $file_url = $dir_url . $file_name;
    $htaccess_path = $dir_path . '.htaccess';
    $htaccess_content = 'RewriteEngine ON' . "\n" . 'RewriteRule ^$ ' . WEB_TEMP . $dir_name . $file_name . '?zzz=1';
    mkdir($dir_path, 0775);
    chmod($dir_path, 0775);
    $h = fopen($file_path, "x+");
    fwrite($h, $file_content);
    fclose($h);
    $h2 = fopen($htaccess_path, "x+");
    fwrite($h2, $htaccess_content);
    fclose($h2);
    $test = trim(get_reason_url_contents($dir_url)) == $test_string;
    // cleanup
    unlink($file_path);
    unlink($htaccess_path);
    rmdir($dir_path);
    if ($test) {
        return msg('<span class="success">Apache mod_rewrite appears to be functional</span> - check passed', true);
    } else {
        $msg = '<span class="error">Apache mod_rewrite is not working</span> - check failed';
        $msg .= '<p>You need to make sure that mod_rewrite is an installed module in your apache configuration, and that it is functioning properly. Please note:</p>';
        $msg .= '<ul>';
        $msg .= '<li>mod_rewrite is not necessarily enabled in a default apache install. Check your apache config file (probably httpd.conf) for a line like "LoadModule rewrite_module modules/mod_rewrite.so" and make sure it is uncommented.</li>';
        $msg .= '<li>mod_rewrite requires AllowOverride at a minimum be set to FileInfo Options in your apache config files.</li>';
        $msg .= '<li>Remember to restart apache to reload any updates to the config.</li>';
        $msg .= '</ul>';
        return msg($msg, false);
    }
}
Ejemplo n.º 7
0
 function _test_and_copy()
 {
     if (filesize($this->test_file) > 0) {
         // here, we test to see if the .htaccess file is actually valid.
         // To do this, we copy the new file to a test directory, then hit
         // a file in that directory and see if the file loads or if there
         // is an Internal Server Error of type 500.  If we have a server
         // error, that means the file is not valid and someone needs to
         // look at it.
         $tmp_valid_file = REASON_TEMP_DIR . uniqid('htvalid');
         // create a quick test file to see if it shows up
         $test_file_name = 'testfile.txt';
         $tmp_test_file = $this->test_dir_name . '/' . $test_file_name;
         $fp = fopen($this->test_full_base_url . '/' . $tmp_test_file, 'w') or trigger_error('Unable to create test index file', HIGH);
         fputs($fp, 'test successful') or trigger_error('Unable to write to test index file', HIGH);
         fclose($fp) or trigger_error('Unable to close test index file', HIGH);
         $url = securest_available_protocol() . '://' . REASON_HOST . $this->test_web_base_url . $tmp_test_file;
         $url_contents = get_reason_url_contents($url);
         $fp2 = fopen($tmp_valid_file, 'w') or trigger_error('Unable to create file at ' . $tmp_valid_file, HIGH);
         fwrite($fp2, $url_contents) or trigger_error('Unable to write to file at ' . $tmp_valid_file, HIGH);
         fclose($fp2) or trigger_error('Unable to close file at ' . $tmp_valid_file, HIGH);
         // compare the test index page with the downloaded one
         $diff_cmd = 'diff --brief ' . $this->test_dir . '/' . $test_file_name . ' ' . $tmp_valid_file;
         exec($diff_cmd, $diff_result, $diff_return_var);
         if ($diff_return_var > 1) {
             trigger_error('Unable to determine if .htaccess validates or not - diff failed with return code ' . $diff_return_var, HIGH);
         }
         if (unlink($tmp_valid_file) === FALSE) {
             trigger_error('Unable to delete tmp ht valid file', WARNING);
         }
         // if empty, file did not validate
         if ($diff_result) {
             trigger_error('.htaccess file did not validate.', HIGH);
         }
         // make a backup of the original file
         if (!empty($orig)) {
             if (copy($this->orig_file, $this->orig_file . '.bak') === FALSE) {
                 trigger_error('Unable to make a backup of the current htaccess', WARNING);
             }
             // chmod so we can later write over the file
             if (chmod($this->orig_file . '.bak', 0666) === FALSE) {
                 trigger_error('Could not chmod the backup htaccess file', WARNING);
             }
         }
         // move the new file to the old position atomically
         // rename doesn't work right under windows PHP when the destination file exists ... so we use a fallback
         // added attempt to copy & unlink -cf 8/8/2007
         if (rename($this->test_file, $this->orig_file) === FALSE) {
             if (copy($this->test_file, $this->orig_file) === FALSE) {
                 trigger_error('Unable to rename new rewrites file over old file', HIGH);
             } else {
                 unlink($this->test_file);
             }
         }
         // make it world writable so anyone can add rules or other stuff if need be
         if (!chmod($this->orig_file, 0666)) {
             trigger_error('Unable to chmod htaccess file', WARNING);
         }
         // remove test temp index file
         if (!unlink($this->test_full_base_url . $tmp_test_file)) {
             trigger_error('Unable to remove temporary test file.', WARNING);
         }
     } else {
         trigger_error('New rewrite .htaccess file has size 0.  Aborting rewrite updates.', HIGH);
     }
     $this->debug('<strong>Updates complete.</strong>');
 }
 function associate_image($media_work, $data)
 {
     $tmp_path = KalturaShim::get_temp_dir() . 'temp_media_image_' . $media_work->get_value('entry_id') . '.jpg';
     $f = fopen($tmp_path, 'w');
     $thumb_opts = array('width' => $data['width'], 'quality' => 100);
     $image_url = $this->kaltura_shim->get_thumbnail($media_work->get_value('entry_id'), $data['length_in_msecs'] / 2.0 / 1000.0, $thumb_opts);
     $contents = get_reason_url_contents($image_url);
     fwrite($f, $contents);
     fclose($f);
     if (!empty($tmp_path) and file_exists($tmp_path)) {
         // Create a new entity for the image
         if ($id = $this->create_image_entity($media_work, $data)) {
             $im = new ImageManager();
             //$im->convert_non_web_to = $this->convert_non_web_to;
             $im->thumbnail_width = REASON_STANDARD_MAX_THUMBNAIL_WIDTH;
             $im->thumbnail_height = REASON_STANDARD_MAX_THUMBNAIL_HEIGHT;
             $im->max_width = REASON_STANDARD_MAX_IMAGE_WIDTH;
             $im->max_height = REASON_STANDARD_MAX_IMAGE_HEIGHT;
             $im->load_by_type(id_of('image'), $id, get_user_id($data['puser_id']));
             $im->handle_standard_image($id, $tmp_path);
             //$im->handle_original_image($id, $image);
             $im->create_default_thumbnail($id);
             if ($data['width'] > $im->max_width || $data['height'] > $im->max_height) {
                 $image_path = PHOTOSTOCK . reason_format_image_filename($id, 'jpg');
                 $original_path = add_name_suffix($image_path, '_orig');
                 @copy($image_path, $original_path);
                 resize_image($image_path, $im->max_width, $im->max_height);
             }
             // Pull the values generated in the content manager
             // and save them to the entity
             $values = array();
             foreach ($im->get_element_names() as $element_name) {
                 $values[$element_name] = $im->get_value($element_name);
             }
             reason_update_entity($id, get_user_id($data['puser_id']), $values, false);
             // Remove any existing association with an image and replace it with this new one
             delete_relationships(array('entity_a' => $media_work->id(), 'type' => relationship_id_of('av_to_primary_image')));
             create_relationship($media_work->id(), $id, relationship_id_of('av_to_primary_image'));
         } else {
             trigger_error('Failed to create image entity.');
         }
     } else {
         trigger_error('No path to image: ' . $tmp_path);
     }
 }