| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
class sfSimpleCMSSlotMediaLibrary implements sfSimpleCMSSlotTypeInterface |
|---|
| 26 |
{ |
|---|
| 27 |
public function getSlotValue($slot) |
|---|
| 28 |
{ |
|---|
| 29 |
sfLoader::loadHelpers(array('Asset', 'Url', 'Tag')); |
|---|
| 30 |
$params = sfYaml::load($slot->getValue()); |
|---|
| 31 |
$res = ''; |
|---|
| 32 |
if(isset($params['legend'])) |
|---|
| 33 |
{ |
|---|
| 34 |
$res .= content_tag('p', $params['legend'], array('class' => 'image_legend')); |
|---|
| 35 |
$params['alt'] = $params['legend']; |
|---|
| 36 |
unset($params['legend']); |
|---|
| 37 |
} |
|---|
| 38 |
if(isset($params['url'])) |
|---|
| 39 |
{ |
|---|
| 40 |
$url = $params['url']; |
|---|
| 41 |
unset($params['url']); |
|---|
| 42 |
} |
|---|
| 43 |
if(!isset($params['src'])) |
|---|
| 44 |
{ |
|---|
| 45 |
return sprintf('<strong>Error</strong>: The value of slot %s in incorrect. The image has no source', $slot->getName()); |
|---|
| 46 |
} |
|---|
| 47 |
$src = $params['src']; |
|---|
| 48 |
unset($params['src']); |
|---|
| 49 |
$res = image_tag($src, $params).$res; |
|---|
| 50 |
if(isset($url)) |
|---|
| 51 |
{ |
|---|
| 52 |
return link_to($res, $url); |
|---|
| 53 |
} |
|---|
| 54 |
else |
|---|
| 55 |
{ |
|---|
| 56 |
return $res; |
|---|
| 57 |
} |
|---|
| 58 |
} |
|---|
| 59 |
|
|---|
| 60 |
public function getSlotEditor($slot) |
|---|
| 61 |
{ |
|---|
| 62 |
$params = sfYaml::load($slot->getValue()); |
|---|
| 63 |
$params['form_name'] = "edit_".$slot->getName(); |
|---|
| 64 |
return $this->getControlForAsset('src','MediaLibrary', $params). |
|---|
| 65 |
$this->getControlFor('alt','Alt text', $params). |
|---|
| 66 |
$this->getControlFor('legend','Legend', $params). |
|---|
| 67 |
$this->getControlFor('url','Url', $params); |
|---|
| 68 |
} |
|---|
| 69 |
|
|---|
| 70 |
private function getControlFor($name, $label, $params) |
|---|
| 71 |
{ |
|---|
| 72 |
sfLoader::loadHelpers(array('Form', 'Tag', 'I18N')); |
|---|
| 73 |
return content_tag('div', label_for($name, __($label)).input_tag($name, isset($params[$name]) ? $params[$name] : ''), array('class' => 'image_slot_form')); |
|---|
| 74 |
} |
|---|
| 75 |
private function getControlForAsset($name, $label, $params) |
|---|
| 76 |
{ |
|---|
| 77 |
sfLoader::loadHelpers(array('Form', 'Tag', 'I18N', 'sfMediaLibrary')); |
|---|
| 78 |
return content_tag('div', label_for($name, __($label)).input_asset_tag($name, isset($params[$name]) ? $params[$name] : '', array('form_name'=>$params['form_name'])), array('class' => 'image_slot_form')); |
|---|
| 79 |
} |
|---|
| 80 |
|
|---|
| 81 |
public function getSlotValueFromRequest($request) |
|---|
| 82 |
{ |
|---|
| 83 |
$params = array(); |
|---|
| 84 |
$params['src'] = $request->getParameter('src'); |
|---|
| 85 |
$params['alt'] = $request->getParameter('alt'); |
|---|
| 86 |
$params['legend'] = $request->getParameter('legend'); |
|---|
| 87 |
$params['url'] = $request->getParameter('url'); |
|---|
| 88 |
|
|---|
| 89 |
return sfYaml::dump($params); |
|---|
| 90 |
} |
|---|
| 91 |
} |
|---|
| 92 |
|
|---|