1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11: class Ansel_Ajax_Imple_EditCaption extends Horde_Core_Ajax_Imple
12: {
13: public function __construct($params)
14: {
15:
16: if (empty($params['rows'])) {
17: $params['rows'] = 2;
18: }
19: if (empty($params['cols'])) {
20: $params['cols'] = 20;
21: }
22: parent::__construct($params);
23: }
24:
25: public function attach()
26: {
27: Horde::addScriptFile('effects.js', 'horde');
28: Horde::addScriptFile('inplaceeditor.js', 'horde');
29:
30: $params = array('input' => 'value',
31: 'id' => $this->_params['id']);
32:
33: $url = $this->_getUrl('EditCaption', 'ansel', $params);
34: $loadTextUrl = $this->_getUrl('EditCaption', 'ansel', array_merge($params, array('action' => 'load')));
35: $js = array();
36:
37: $js[] = "new InPlaceEditor('" . $this->_params['domid'] . "', '" . $url . "', {"
38: . " callback: function(form, value) {"
39: . " return 'value=' + encodeURIComponent(value);},"
40: . " loadTextURL: '". $loadTextUrl . "',"
41: . " rows:" . $this->_params['rows'] . ","
42: . " width:" . $this->_params['width'] . ","
43: . " emptyText: '" . _("Click to add caption...") . "',"
44: . " onComplete: function(ipe, opts) { ipe.checkEmpty() },"
45: . " cancelText: '" . _("Cancel") . "',"
46: . " okText: '" . _("Ok") . "',"
47: . " cancelClassName: ''"
48: . " });";
49:
50: Horde::addInlineScript($js, 'dom');
51: }
52:
53: public function handle($args, $post)
54: {
55: if ($GLOBALS['registry']->getAuth()) {
56:
57: if (!empty($args['action']) && $args['action'] == 'load') {
58: $id = $args['id'];
59: $image = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImage($id);
60: $caption = $image->caption;
61:
62: return $caption;
63: }
64: if (empty($args['input']) ||
65: is_null($pref_value = Horde_Util::getPost($args['input'], null)) ||
66: empty($args['id']) || !is_numeric($args['id'])) {
67:
68: return '';
69: }
70: $id = $args['id'];
71: $image = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImage($id);
72: $g = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($image->gallery);
73: if ($g->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) {
74: $image->caption = $pref_value;
75: try {
76: $result = $image->save();
77: } catch (Ansel_Exception $e) {
78: return '';
79: }
80: }
81: return $GLOBALS['injector']->getInstance('Horde_Core_Factory_TextFilter')->filter(
82: $image->caption,
83: 'text2html',
84: array('parselevel' => Horde_Text_Filter_Text2html::MICRO));
85: }
86: }
87:
88: }
89: