| 1 |
<?php |
|---|
| 2 |
use_helper('Form', 'Javascript', 'I18N'); |
|---|
| 3 |
|
|---|
| 4 |
function include_editor_tools($page) |
|---|
| 5 |
{ |
|---|
| 6 |
if (sfContext::getInstance()->getRequest()->getParameter('edit') == 'true' && !sfConfig::get('app_sfSimpleCMS_disable_editor_toolbar', false)) |
|---|
| 7 |
{ |
|---|
| 8 |
use_stylesheet('/sfSimpleCMSPlugin/css/CMSEditorTools.css'); |
|---|
| 9 |
include_component('sfSimpleCMS', 'editorTools', array('page' => $page)); |
|---|
| 10 |
} |
|---|
| 11 |
} |
|---|
| 12 |
|
|---|
| 13 |
function sf_simple_cms_has_slot($page, $slot_name) |
|---|
| 14 |
{ |
|---|
| 15 |
$request = sfContext::getInstance()->getRequest(); |
|---|
| 16 |
if ($request->getParameter('edit') == 'true' && !$request->getParameter('preview')) |
|---|
| 17 |
{ |
|---|
| 18 |
return true; |
|---|
| 19 |
} |
|---|
| 20 |
$slot_value = $page->getSlotValue($slot_name); |
|---|
| 21 |
if($slot_value) |
|---|
| 22 |
{ |
|---|
| 23 |
return true; |
|---|
| 24 |
} |
|---|
| 25 |
return false; |
|---|
| 26 |
} |
|---|
| 27 |
|
|---|
| 28 |
function sf_simple_cms_slot($page, $slot, $default_text = null, $default_type = 'Text') |
|---|
| 29 |
{ |
|---|
| 30 |
$context = sfContext::getInstance(); |
|---|
| 31 |
$request = $context->getRequest(); |
|---|
| 32 |
|
|---|
| 33 |
$culture = $request->getAttribute('culture'); |
|---|
| 34 |
$slot_object = $page->getSlot($slot, constant(sfConfig::get('app_sfSimpleCMS_escaping_strategy', 'ESC_RAW'))); |
|---|
| 35 |
if(!$slot_object) |
|---|
| 36 |
{ |
|---|
| 37 |
$slot_object = new sfSimpleCMSSlot(); |
|---|
| 38 |
$slot_object->setType($default_type); |
|---|
| 39 |
$slot_object->setCulture($culture); |
|---|
| 40 |
} |
|---|
| 41 |
$slot_value = $slot_object->getValue(); |
|---|
| 42 |
$slot_type_name = $slot_object->getType(); |
|---|
| 43 |
|
|---|
| 44 |
$slot_type_class = 'sfSimpleCMSSlot'.$slot_type_name; |
|---|
| 45 |
$slot_type = new $slot_type_class(); |
|---|
| 46 |
|
|---|
| 47 |
if ($request->getParameter('edit') == 'true' && !$request->getParameter('preview')) |
|---|
| 48 |
{ |
|---|
| 49 |
echo '<div class="editable_slot" title="'.__('Double-click to edit').'" id="simplecmsslot_'.$slot.'" onDblClick="Element.show(\'edit_'.$slot.'\');Element.hide(\'simplecmsslot_'.$slot.'\');">'; |
|---|
| 50 |
|
|---|
| 51 |
if($slot_value) |
|---|
| 52 |
{ |
|---|
| 53 |
|
|---|
| 54 |
echo $slot_type->getSlotValue($slot_object); |
|---|
| 55 |
} |
|---|
| 56 |
else |
|---|
| 57 |
{ |
|---|
| 58 |
|
|---|
| 59 |
echo $default_text ? $default_text : sfConfig::get('app_sfSimpleCMS_default_text', __('[add text here]')); |
|---|
| 60 |
} |
|---|
| 61 |
|
|---|
| 62 |
echo '</div>'; |
|---|
| 63 |
|
|---|
| 64 |
echo form_remote_tag(array( |
|---|
| 65 |
'url' => 'sfSimpleCMS/updateSlot', |
|---|
| 66 |
'script' => 'true', |
|---|
| 67 |
'update' => 'simplecmsslot_'.$slot, |
|---|
| 68 |
'success' => 'Element.show(\'simplecmsslot_'.$slot.'\'); |
|---|
| 69 |
Element.hide(\'edit_'.$slot.'\'); |
|---|
| 70 |
'.visual_effect('highlight', 'simplecmsslot_'.$slot), |
|---|
| 71 |
), array( |
|---|
| 72 |
'class' => 'edit_slot', |
|---|
| 73 |
'id' => 'edit_'.$slot, |
|---|
| 74 |
'style' => 'display:none' |
|---|
| 75 |
)); |
|---|
| 76 |
echo input_hidden_tag('slug', $page->getSlug(), 'id=edit_path'.$slot); |
|---|
| 77 |
echo input_hidden_tag('slot', $slot); |
|---|
| 78 |
if(sfConfig::get('app_sfSimpleCMS_use_l10n', false)) |
|---|
| 79 |
{ |
|---|
| 80 |
echo input_hidden_tag('sf_culture', $slot_object->getCulture()); |
|---|
| 81 |
} |
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
echo $slot_type->getSlotEditor($slot_object); |
|---|
| 85 |
|
|---|
| 86 |
echo label_for('slot_type', __('Type: ')); |
|---|
| 87 |
echo select_tag( |
|---|
| 88 |
'slot_type', |
|---|
| 89 |
options_for_select( |
|---|
| 90 |
sfConfig::get('app_sfSimpleCMS_slot_types', array( |
|---|
| 91 |
'Text' => __('Simple Text'), |
|---|
| 92 |
'RichText' => __('Rich text'), |
|---|
| 93 |
'Php' => __('PHP code'), |
|---|
| 94 |
'Image' => __('Image'), |
|---|
| 95 |
'Modular' => __('List of partials/components'))), |
|---|
| 96 |
$slot_type_name |
|---|
| 97 |
) |
|---|
| 98 |
); |
|---|
| 99 |
if($rich = sfConfig::get('app_sfSimpleCMS_rich_editing', false)) |
|---|
| 100 |
{ |
|---|
| 101 |
|
|---|
| 102 |
$rich = ($slot_type_name == 'RichText'); |
|---|
| 103 |
} |
|---|
| 104 |
echo submit_tag('update', array( |
|---|
| 105 |
'onclick' => ($rich ? 'tinymceDeactivate()'.';submitForm(\'edit_'. $slot .'\'); return false' : ''), |
|---|
| 106 |
'class' => 'submit_tag' |
|---|
| 107 |
)); |
|---|
| 108 |
echo button_to_function('cancel', 'Element.hide(\'edit_'.$slot.'\');Element.show(\'simplecmsslot_'.$slot.'\');', 'class=submit_tag'); |
|---|
| 109 |
|
|---|
| 110 |
echo '</form>'; |
|---|
| 111 |
} |
|---|
| 112 |
else |
|---|
| 113 |
{ |
|---|
| 114 |
echo $slot_type->getSlotValue($slot_object); |
|---|
| 115 |
} |
|---|
| 116 |
} |
|---|
| 117 |
|
|---|
| 118 |
function link_to_with_path($text, $uri, $options = array()) |
|---|
| 119 |
{ |
|---|
| 120 |
return str_replace('%2F', '/', link_to($text, $uri, $options)); |
|---|
| 121 |
} |
|---|
| 122 |
|
|---|
| 123 |
function button_to_with_path($text, $uri, $options = array()) |
|---|
| 124 |
{ |
|---|
| 125 |
return str_replace('%2F', '/', button_to($text, $uri, $options)); |
|---|
| 126 |
} |
|---|