コード例 #1
0
 /**
  * Get custom computed values for an asset
  * @access private
  * @param object (entity) $e
  * @param string $indent
  * @return array lines
  */
 function _get_custom_values_for_asset($e, $indent)
 {
     $lines = array();
     $lines[] = $indent . '<value name="url" type="computed">' . htmlspecialchars(reason_get_asset_url($e)) . '</value>';
     $lines[] = $indent . '<value name="filesystem_location" type="computed">' . htmlspecialchars(reason_get_asset_filesystem_location($e)) . '</value>';
     return $lines;
 }
コード例 #2
0
ファイル: assets.php プロジェクト: hunter2814/reason_package
 /**
  * Merge and send a set of pdfs
  *
  * @access private
  */
 function _merge_and_send_pdfs($pdfs)
 {
     if (!empty($pdfs)) {
         $username = reason_check_authentication();
         if (!$this->_has_access($pdfs, $username)) {
             if (!empty($username)) {
                 $this->_display_403_page();
                 die;
             } else {
                 header('Location: ' . REASON_LOGIN_URL . '?dest_page=' . urlencode(get_current_url()));
                 die;
             }
         }
         $pdf_files = array();
         $titles = array();
         foreach ($pdfs as $pdf) {
             $file_location = reason_get_asset_filesystem_location($pdf);
             $pdf_files[] = $file_location;
             $titles[$file_location] = strip_tags($pdf->get_value('name'));
         }
         include_once CARL_UTIL_INC . 'pdf/pdf_utils.php';
         $merged = carl_merge_pdfs($pdf_files, $titles);
         if (empty($merged)) {
             trigger_error('PDF merge failed');
         } else {
             if (carl_send_pdf($merged, $this->cur_page->get_value('url_fragment') . '.pdf')) {
                 die;
             } else {
                 trigger_error('Unable to send PDF');
             }
         }
     }
 }
コード例 #3
0
 /**
  * _send_file delivers the asset to the client - if should be invoked using the run function of the class and not called directly
  *
  * @author nwhite
  * @access private
  */
 function _send_file()
 {
     //$extensions_to_display_inline = array('jpg', 'gif', 'htm', 'html', 'swf', 'txt');
     $file_name = $this->asset->get_value('file_name');
     $file_ext = $this->asset->get_value('file_type');
     $file_path = reason_get_asset_filesystem_location($this->asset);
     if (file_exists($file_path)) {
         $file_size = filesize($file_path);
         // disposition needs some extensive testing - should it be attachment or inline?
         $file_disposition = $file_ext == 'pdf' ? 'attachment' : 'inline';
         // download by default
         $mime_type = $this->get_mime_type();
         if (!empty($mime_type) && strstr($mime_type, "text/")) {
             $file_handle = fopen($file_path, "r");
         } else {
             $file_handle = fopen($file_path, "rb");
         }
         //if (in_array($file_ext, $extensions_to_display_inline)) $file_disposition = 'inline';
         if (empty($mime_type)) {
             $mime_type = 'application/octet-stream';
         }
         ob_end_clean();
         header('Pragma: public');
         header('Cache-Control: max-age=0');
         //added to squash weird IE 6 bug where pdfs say that the file is not found
         header('Content-Type: ' . $mime_type);
         header('Content-Disposition: ' . $file_disposition . '; filename="' . $file_name . '"');
         header('Content-Length: ' . $file_size);
         header('Content-Transfer-Encoding: binary');
         header('Expires: 0');
         fpassthru($file_handle);
         exit;
     } else {
         trigger_error('The asset at ' . $file_path . ' could not be sent to the user because it does not exist');
     }
 }
コード例 #4
0
/**
 * Used to update an asset that is already in the filesystem.
 *
 * @param int asset_id id of asset
 * @param int user_id id of person modifying asset
 * @param file array with keys: path, name
 * @return mixed entity_id of existing asset or FALSE on failure
 */
function reason_update_asset($asset_id, $user_id, $file)
{
    if (!is_null($asset_id)) {
        if (empty($asset_id) || intval($asset_id) != $asset_id) {
            trigger_error('reason_update_asset was provided an invalid asset_id parameter (' . $asset_id . ')');
            return false;
        } else {
            $asset = new entity(intval($asset_id));
            if (!reason_is_entity($asset, 'asset')) {
                trigger_error('reason_update_asset was provided a asset_id that is not a reason asset entity id (' . $asset_id . ')');
                return false;
            }
        }
    }
    if (empty($user_id) || intval($user_id) != $user_id) {
        trigger_error('reason_update_asset was provided an invalid user_id parameter (' . $user_id . ')');
        return false;
    } else {
        $user = new entity(intval($user_id));
        if (!reason_is_entity($user, 'user')) {
            trigger_error('reason_update_asset was provided a user_id that is not a reason user entity id (' . $user_id . ')');
            return false;
        }
    }
    if (empty($file) || !is_array($file)) {
        trigger_error('reason_update_asset requires the file parameter to be an array with keys path, name');
        return false;
    } elseif (empty($file['path']) || !file_exists($file['path'])) {
        if (empty($file['path'])) {
            trigger_error('reason_update_asset requires a file parameter with a key "path" that contains the full path to a file');
        } else {
            trigger_error('reason_update_asset was provided a file path (' . $file['path'] . ') that does not exist');
        }
        return false;
    } elseif (empty($file['name'])) {
        trigger_error('reason_update_asset requires a file parameter with a key "name" that specifies what filename should be used for downloading the file');
        return false;
    }
    $cur_path = reason_get_asset_filesystem_location($asset);
    $cur_name = $asset->get_value('file_name');
    // if our name or path has changed lets update the asset
    if ($file['path'] != $cur_path || $file['name'] != $cur_name) {
        $asset_owner = $asset->get_owner();
        $values['mime_type'] = get_mime_type($file['path'], 'application/octet-stream');
        $values['file_name'] = _reason_get_asset_filename($asset_owner->id(), $file['name'], $asset->id());
        $values['file_type'] = _reason_get_asset_extension($file['path'], $values['mime_type']);
        $values['file_size'] = _reason_get_asset_size($file['path']);
        // if the entity update changed the file name lets do rewrites.
        if (reason_update_entity($asset->id(), $user_id, $values, false)) {
            if ($cur_name != $values['file_name']) {
                $um = new url_manager($asset_owner->id());
                $um->update_rewrites();
            }
        }
        if ($file['path'] != $cur_path) {
            $asset_dest = ASSET_PATH . $asset_id . '.' . $values['file_type'];
            if (server_is_windows() && file_exists($asset_dest)) {
                unlink($asset_dest);
            }
            rename($file['path'], $asset_dest);
        }
        return $asset_id;
    }
    return false;
}