| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
use_helper('Url'); |
|---|
| 4 |
|
|---|
| 5 |
function auto_wrap_text($text) |
|---|
| 6 |
{ |
|---|
| 7 |
return preg_replace('/([_\-\.])/', '<span class="wrap_space"> </span>$1<span class="wrap_space"> </span>', $text); |
|---|
| 8 |
return wordwrap($text, 2, '<span class="wrap_space"> </span>', true); |
|---|
| 9 |
} |
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
function asset_image_tag($asset, $thumbnail_type = 'full', $options = array(), $relative_path = null) |
|---|
| 21 |
{ |
|---|
| 22 |
|
|---|
| 23 |
$options = array_merge(array( |
|---|
| 24 |
'alt' => $asset->getDescription() . ' ' . $asset->getCopyright(), |
|---|
| 25 |
'title' => $asset->getDescription() . ' ' . $asset->getCopyright() |
|---|
| 26 |
), $options); |
|---|
| 27 |
|
|---|
| 28 |
if($asset->isImage() && $asset->supportsThumbnails()) |
|---|
| 29 |
{ |
|---|
| 30 |
$src = $asset->getUrl($thumbnail_type, $relative_path); |
|---|
| 31 |
} |
|---|
| 32 |
else |
|---|
| 33 |
{ |
|---|
| 34 |
if($thumbnail_type == 'full') |
|---|
| 35 |
{ |
|---|
| 36 |
throw new sfAssetException('Impossible to render a non-image asset in an image tag'); |
|---|
| 37 |
} |
|---|
| 38 |
else |
|---|
| 39 |
{ |
|---|
| 40 |
switch($asset->getType()) |
|---|
| 41 |
{ |
|---|
| 42 |
case 'txt': |
|---|
| 43 |
$src = '/swDoctrineAssetsLibraryPlugin/images/txt.png'; |
|---|
| 44 |
break; |
|---|
| 45 |
case 'xls': |
|---|
| 46 |
$src = '/swDoctrineAssetsLibraryPlugin/images/xls.png'; |
|---|
| 47 |
break; |
|---|
| 48 |
case 'doc': |
|---|
| 49 |
$src = '/swDoctrineAssetsLibraryPlugin/images/doc.png'; |
|---|
| 50 |
break; |
|---|
| 51 |
case 'pdf': |
|---|
| 52 |
$src = '/swDoctrineAssetsLibraryPlugin/images/pdf.png'; |
|---|
| 53 |
break; |
|---|
| 54 |
case 'html': |
|---|
| 55 |
$src = '/swDoctrineAssetsLibraryPlugin/images/html.png'; |
|---|
| 56 |
break; |
|---|
| 57 |
case 'archive': |
|---|
| 58 |
$src = '/swDoctrineAssetsLibraryPlugin/images/archive.png'; |
|---|
| 59 |
break; |
|---|
| 60 |
case 'bin': |
|---|
| 61 |
$src = '/swDoctrineAssetsLibraryPlugin/images/bin.png'; |
|---|
| 62 |
break; |
|---|
| 63 |
default: |
|---|
| 64 |
$src = '/swDoctrineAssetsLibraryPlugin/images/unknown.png'; |
|---|
| 65 |
} |
|---|
| 66 |
} |
|---|
| 67 |
} |
|---|
| 68 |
return image_tag($src, $options); |
|---|
| 69 |
} |
|---|
| 70 |
|
|---|
| 71 |
function link_to_asset($text, $path, $options = array()) |
|---|
| 72 |
{ |
|---|
| 73 |
return str_replace('%2F', '/', link_to($text, $path, $options)); |
|---|
| 74 |
} |
|---|
| 75 |
|
|---|
| 76 |
function link_to_asset_action($text, $asset) |
|---|
| 77 |
{ |
|---|
| 78 |
$user = sfContext::getInstance()->getUser(); |
|---|
| 79 |
if ($user->hasAttribute('popup', 'sf_admin/sf_asset/navigation')) |
|---|
| 80 |
{ |
|---|
| 81 |
switch($user->getAttribute('popup', null, 'sf_admin/sf_asset/navigation')) |
|---|
| 82 |
{ |
|---|
| 83 |
case 1: |
|---|
| 84 |
|
|---|
| 85 |
return link_to($text, "sfAsset/tinyConfigMedia?id=".$asset->getId(), 'title='.$asset->getFilename()); |
|---|
| 86 |
case 2: |
|---|
| 87 |
|
|---|
| 88 |
return link_to_function($text, "setImageField('".$asset->getUrl()."')"); |
|---|
| 89 |
} |
|---|
| 90 |
} |
|---|
| 91 |
else |
|---|
| 92 |
{ |
|---|
| 93 |
|
|---|
| 94 |
return link_to($text, "sfAsset/edit?id=".$asset->getId(), 'title='.$asset->getFilename()); |
|---|
| 95 |
} |
|---|
| 96 |
} |
|---|
| 97 |
|
|---|
| 98 |
function init_asset_library() |
|---|
| 99 |
{ |
|---|
| 100 |
use_helper('Javascript'); |
|---|
| 101 |
use_javascript('/swDoctrineAssetsLibraryPlugin/js/main', 'last'); |
|---|
| 102 |
|
|---|
| 103 |
echo javascript_tag('sfAssetsLibrary.init(\''.url_for('sfAsset/list?popup=2').'\')'); |
|---|
| 104 |
} |
|---|
| 105 |
|
|---|
| 106 |
function object_input_sf_asset_tag($object, $method, $options = array()) |
|---|
| 107 |
{ |
|---|
| 108 |
$options = _parse_attributes($options); |
|---|
| 109 |
$name = _convert_method_to_name($method, $options); |
|---|
| 110 |
$value = _get_object_value($object, $method); |
|---|
| 111 |
|
|---|
| 112 |
return input_sf_asset_tag($name, $value, $options); |
|---|
| 113 |
} |
|---|
| 114 |
|
|---|
| 115 |
function input_sf_asset_tag($name, $value, $options = array()) |
|---|
| 116 |
{ |
|---|
| 117 |
use_helper('Form', 'I18N'); |
|---|
| 118 |
use_javascript('/swDoctrineAssetsLibraryPlugin/js/main', 'last'); |
|---|
| 119 |
$options = _convert_options($options); |
|---|
| 120 |
$type = 'all'; |
|---|
| 121 |
if (isset($options['images_only'])) |
|---|
| 122 |
{ |
|---|
| 123 |
$type = 'image'; |
|---|
| 124 |
unset($options['images_only']); |
|---|
| 125 |
} |
|---|
| 126 |
if(!isset($options['id'])) |
|---|
| 127 |
{ |
|---|
| 128 |
$options['id'] = get_id_from_name($name); |
|---|
| 129 |
} |
|---|
| 130 |
|
|---|
| 131 |
$form_name = 'this.previousSibling.previousSibling.form.name'; |
|---|
| 132 |
if (isset($options['form_name'])) |
|---|
| 133 |
{ |
|---|
| 134 |
$form_name = "'".$options['form_name']."'"; |
|---|
| 135 |
unset($options['form_name']); |
|---|
| 136 |
} |
|---|
| 137 |
|
|---|
| 138 |
|
|---|
| 139 |
$html = input_tag($name, $value, $options) . ' '; |
|---|
| 140 |
$html .= image_tag('/swDoctrineAssetsLibraryPlugin/images/folder_open', array( |
|---|
| 141 |
'alt' => __('Insert Image'), |
|---|
| 142 |
'style' => 'cursor: pointer; vertical-align: middle', |
|---|
| 143 |
'onclick' => " |
|---|
| 144 |
initialDir = document.getElementById('".$options['id']."').value.replace(/\/[^\/]*$/, ''); |
|---|
| 145 |
if(!initialDir) initialDir = '".sfConfig::get('app_swDoctrineAssetsLibraryPlugin_upload_dir', 'media')."'; |
|---|
| 146 |
sfAssetsLibrary.openWindow({ |
|---|
| 147 |
form_name: ".$form_name.", |
|---|
| 148 |
field_name: '".$name."', |
|---|
| 149 |
type: '".$type."', |
|---|
| 150 |
url: '".url_for('sfAsset/list?dir=PLACEHOLDER')."?popup=2'.replace('PLACEHOLDER', initialDir), |
|---|
| 151 |
scrollbars: 'yes' |
|---|
| 152 |
});" |
|---|
| 153 |
)); |
|---|
| 154 |
|
|---|
| 155 |
return $html; |
|---|
| 156 |
} |
|---|
| 157 |
|
|---|
| 158 |
function init_assets_library_popup() |
|---|
| 159 |
{ |
|---|
| 160 |
use_javascript('/swDoctrineAssetsLibraryPlugin/js/main', 'last'); |
|---|
| 161 |
|
|---|
| 162 |
return javascript_tag('sfAssetsLibrary.init(\''.url_for('sfAsset/list').'?popup=2'.'\')'); |
|---|
| 163 |
} |
|---|
| 164 |
|
|---|
| 165 |
function assets_library_breadcrumb($path, $linkLast = false, $action = '') |
|---|
| 166 |
{ |
|---|
| 167 |
$action = $action ? $action : sfContext::getInstance()->getRequest()->getParameter('action'); |
|---|
| 168 |
if($action == "edit") |
|---|
| 169 |
{ |
|---|
| 170 |
$action = "list"; |
|---|
| 171 |
} |
|---|
| 172 |
$html = ''; |
|---|
| 173 |
$breadcrumb = explode("/" , $path); |
|---|
| 174 |
$nb_dirs = count($breadcrumb); |
|---|
| 175 |
$current_dir = ''; |
|---|
| 176 |
$i = 0; |
|---|
| 177 |
foreach ($breadcrumb as $dir) |
|---|
| 178 |
{ |
|---|
| 179 |
if(!$linkLast && ($i == $nb_dirs - 1)) |
|---|
| 180 |
{ |
|---|
| 181 |
$html .= $dir; |
|---|
| 182 |
} |
|---|
| 183 |
else |
|---|
| 184 |
{ |
|---|
| 185 |
$current_dir .= $i ? '/' . $dir : $dir; |
|---|
| 186 |
$html .= link_to_asset($dir, 'sfAsset/'.$action.'?dir='.$current_dir) .'<span class="crumb">/</span>'; |
|---|
| 187 |
} |
|---|
| 188 |
$i++; |
|---|
| 189 |
} |
|---|
| 190 |
return $html; |
|---|
| 191 |
} |
|---|