Пример #1
0
 function get_json()
 {
     if ($assets = $this->get_assets()) {
         $site = new entity($this->config('site_id'));
         foreach ($assets as $asset) {
             $asset_list['name'] = strip_tags($asset->get_value('name'));
             $asset_list['url'] = reason_get_asset_url($asset, $site);
         }
         return json_encode($asset_list);
     } else {
         return '{}';
     }
 }
Пример #2
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;
 }
Пример #3
0
 function get_json()
 {
     if ($assets = $this->get_assets()) {
         $asset_list = array();
         $asset_json['site_id'] = $this->config('site_id');
         $site = new entity($this->config('site_id'));
         foreach ($assets as $asset) {
             array_push($asset_list, array('name' => strip_tags($asset->get_value('name')), 'url' => reason_get_asset_url($asset, $site), 'id' => strip_tags($asset->get_value('id'))));
         }
         $asset_json['assets'] = $asset_list;
         return json_encode($asset_json);
     } else {
         return '{}';
     }
 }
Пример #4
0
/**
 * Build standardized markup for a list of assets
 * @todo move away from this style of coding towards templates and models
 *
 * @param array $assets (each asset is an entity)
 * @param object $site (the site entity that the assets are being displayed within)
 * @param array $fields (the fields to display)
 * @param string $date_format (how to format the dates)
 * @return string XHTML markup
 */
function make_assets_list_markup($assets, $site, $fields = array('name', 'file_size', 'file_type', 'description', 'datetime'), $date_format = 'j F Y')
{
    if (empty($fields)) {
        trigger_error('make_assets_list_markup(): $fields must be a populated array');
        return '';
    }
    $recognized_field_names = array('name', 'file_size', 'file_type', 'description', 'author', 'datetime');
    foreach ($recognized_field_names as $field_name) {
        $var_name = '_show_' . $field_name;
        if (in_array($field_name, $fields)) {
            ${$var_name} = true;
        } else {
            ${$var_name} = false;
        }
    }
    $file_types = array('pdf' => 'PDF Document', 'doc' => 'Word Document', 'docx' => 'Word Document', 'xls' => 'Excel Document', 'xlsx' => 'Excel Document', 'ppt' => 'Powerpoint Document', 'pptx' => 'Powerpoint Document', 'html' => 'HTML Document', 'htm' => 'HTML Document', 'txt' => 'Plain Text Document', 'rtf' => 'Rich Text Document', 'csv' => 'Comma-Separated Values File', 'eps' => 'Encapsulated Postscript Document', 'zip' => 'Compressed ZIP Archive', 'sit' => 'Compressed Stuffit Archive', 'sit' => 'Compressed Stuffit Archive', 'svg' => 'Scalable Vector Graphics Document', 'psd' => 'Adobe Photoshop Document', 'tif' => 'TIFF Image File', 'tiff' => 'TIFF Image File', 'mpp' => 'Microsoft Project Document', 'exe' => 'Windows Executable Program', 'css' => 'Cascading Style Sheet File', 'xml' => 'XML data file');
    if (!empty($assets)) {
        $txt = '<ul>' . "\n";
        foreach ($assets as $asset) {
            $owner_site = $asset->get_owner();
            $type = '';
            if ($asset->get_value('file_type')) {
                if (array_key_exists($asset->get_value('file_type'), $file_types)) {
                    $type = $file_types[$asset->get_value('file_type')];
                } else {
                    $type = htmlspecialchars('.' . $asset->get_value('file_type') . ' file');
                }
            }
            $url = '';
            $txt .= '<li class="' . htmlspecialchars($asset->get_value('file_type'), ENT_QUOTES) . '">';
            if ($_show_name || $_show_file_size || $_show_file_type) {
                $txt .= '<div class="name">';
                if ($_show_name) {
                    $txt .= '<a href="' . htmlspecialchars(reason_get_asset_url($asset, $owner_site), ENT_QUOTES) . '"><strong>' . $asset->get_value('name') . '</strong></a>';
                }
                if ($_show_file_size || $_show_file_type) {
                    if (!empty($type) || $asset->get_value('file_size')) {
                        $txt .= ' (';
                        if ($asset->get_value('file_size') && $_show_file_size) {
                            $txt .= $asset->get_value('file_size') . ' KB';
                        }
                        if (!empty($type) && $_show_file_type) {
                            $txt .= ' ' . $type;
                        }
                        $txt .= ')';
                    }
                }
                $txt .= '</div>' . "\n";
            }
            if ($_show_author && $asset->get_value('author')) {
                $txt .= '<div class="author">' . $asset->get_value('author') . '</div> ';
            }
            if ($_show_datetime && $asset->get_value('datetime')) {
                $txt .= '<div class="date">' . prettify_mysql_datetime($asset->get_value('datetime'), $date_format) . '</div> ';
            }
            if ($_show_description && $asset->get_value('description') && $asset->get_value('description') != $asset->get_value('name')) {
                $txt .= '<div class="description">' . $asset->get_value('description') . '</div>' . "\n";
            }
            $txt .= '</li>' . "\n";
        }
        $txt .= '</ul>' . "\n";
        return $txt;
    } else {
        return '';
    }
}