See the list of constants at the top of the file for the serializing
techniques that can be used.
public static serialize ( mixed $data, mixed $mode = [self::BASIC], mixed $params = null ) : string | ||
$data | mixed | The data to be serialized. |
$mode | mixed | The mode of serialization. Can be either a single mode or array of modes. If array, will be serialized in the order provided. |
$params | mixed | Any additional parameters the serialization method requires. |
return | string | The serialized data. |
/** * Returns a serialized value, if necessary. * * @param mixed The original value. * * @return string The JSON encoded value if not already a string. */ protected function _serializeAttribute($value) { if (!is_string($value)) { return Horde_Serialize::serialize($value, Horde_Serialize::JSON); } return $value; }
/** */ protected function _attach($init) { if ($init) { $this->_jsOnDoAction('$("faces_widget_content").update(' . Horde_Serialize::serialize(_("Loading..."), Horde_Serialize::JSON) . ')'); $this->_jsOnComplete('$("faces_widget_content").update(e.memo)'); $GLOBALS['page_output']->addScriptFile('editfaces.js'); } return array('image_id' => $this->_params['image_id']); }
/** * Returns the tree. * * @param boolean $static If true the tree nodes can't be expanded and * collapsed and the tree gets rendered expanded. * * @return string The HTML code of the rendered tree. */ public function getTree($static = false) { $this->_static = $static; $opts = array('extraColsLeft' => $this->_colsLeft, 'extraColsRight' => $this->_colsRight, 'header' => $this->_header, 'nocookie' => !$this->getOption('session'), 'options' => $this->_options, 'target' => $this->_tree->instance, 'cookieDomain' => $GLOBALS['conf']['cookie']['domain'], 'cookiePath' => $GLOBALS['conf']['cookie']['path'], 'imgBlank' => $this->_images['blank'], 'imgFolder' => $this->_images['folder'], 'imgFolderOpen' => $this->_images['folderopen'], 'imgLine' => $this->_images['line'], 'imgJoin' => $this->_images['join'], 'imgJoinBottom' => $this->_images['join_bottom'], 'imgJoinTop' => $this->_images['join_top'], 'imgPlus' => $this->_images['plus'], 'imgPlusBottom' => $this->_images['plus_bottom'], 'imgPlusOnly' => $this->_images['plus_only'], 'imgMinus' => $this->_images['minus'], 'imgMinusBottom' => $this->_images['minus_bottom'], 'imgMinusOnly' => $this->_images['minus_only'], 'imgNullOnly' => $this->_images['null_only'], 'imgLeaf' => $this->_images['leaf'], 'initTree' => $this->renderNodeDefinitions()); if (!($js_var = $this->getOption('jsvar'))) { $js_var = $this->_tree->instance; } $GLOBALS['injector']->getInstance('Horde_PageOutput')->addInlineScript(array('window.' . $js_var . ' = new Horde_Tree(' . Horde_Serialize::serialize($opts, Horde_Serialize::JSON) . ')'), true); return '<div id="' . $this->_tree->instance . '"></div>'; }
/** * Outputs the status line if there are any messages on the 'status' * message stack. * * @param array $events The list of events to handle. * @param array $options An array of options. Not used. */ public function notify($events, $options = array()) { if (empty($events)) { return; } // TODO: Need to add delay to allow browser to correctly populate // location of original page, or else closing notification reloads // previous page (Ticket #11103). $GLOBALS['injector']->getInstance('Horde_PageOutput')->addInlineScript(array('$(function() {HordeMobile.showNotifications(' . Horde_Serialize::serialize($events, Horde_Serialize::JSON) . ');});')); }
/** * Return the encode list of options. * * @return array Options list. */ protected function _getOpts(Horde_Core_Ajax_Imple_AutoCompleter $ac) { $opts = array(); if (!isset($this->params['indicator'])) { $this->params['indicator'] = $ac->getDomId() . '_loading_img'; } foreach ($this->params as $key => $val) { $opts[] = $key . ':' . (in_array($key, $this->_raw) ? $val : Horde_Serialize::serialize($val, Horde_Serialize::JSON)); } return $opts; }
/** */ public function generate(Horde_Core_Ajax_Imple_AutoCompleter $ac) { $dom_id = $ac->getDomId(); if (!isset($this->params['trigger'])) { $this->params['trigger'] = $dom_id; } if (!isset($this->params['uri'])) { $this->params['uri'] = strval($ac->getImpleUrl()->setRaw(true)); } return 'new PrettyAutocompleter(' . Horde_Serialize::serialize($dom_id, Horde_Serialize::JSON) . ',' . '{' . implode(',', $this->_getOpts($ac)) . '})'; }
/** * Send response data to browser. */ public function send() { /* By default, the response is sent JSON encoded. * * Make sure no null bytes sneak into the JSON output stream. Null * bytes cause IE to stop reading from the input stream, causing * malformed JSON data and a failed request. These bytes don't * seem to break any other browser, but might as well remove them * anyway. */ header('Content-Type: application/json'); echo str_replace("", '', Horde_Serialize::serialize($this->data, Horde_Serialize::JSON)); }
/** * Store the freebusy information for a given email address. * * @param string $email The email address to store fb info for. * @param Horde_Icalendar_Vfreebusy $vfb TODO * @param boolean $private_only (optional) TODO * * @throws Kronolith_Exception */ public function store($email, $vfb, $public = false) { /* Build the SQL query. */ $query = sprintf('INSERT INTO %s (vfb_owner, vfb_email, vfb_serialized) VALUES (?, ?, ?)', $this->_params['table']); $values = array($public ? '' : $this->_user, $email, Horde_Serialize::serialize($vfb, Horde_Serialize::BASIC)); /* Execute the query. */ try { $this->_db->insert($query, $values); } catch (Horde_Db_Exception $e) { throw new Kronolith_Exception($e); } }
/** */ protected function _attach($init) { global $page_output; if ($init) { $page_output->addScriptFile('spellchecker.js', 'horde'); $page_output->addScriptPackage('Horde_Core_Script_Package_Keynavlist'); $page_output->addInlineJsVars(array('HordeImple.SpellChecker' => new stdClass())); } $dom_id = $this->getDomId(); $opts = array('locales' => $this->_params['locales'], 'statusButton' => $dom_id, 'target' => $this->_params['targetId'], 'url' => strval($this->getImpleUrl()->setRaw(true)->add(array('input' => $this->_params['targetId'])))); if (isset($this->_params['states'])) { $opts['bs'] = $this->_params['states']; } $page_output->addInlineScript(array('HordeImple.SpellChecker.' . $dom_id . '=new SpellChecker(' . Horde_Serialize::serialize($opts, Horde_Serialize::JSON) . ')'), true); return false; }
/** * Attach the object to a javascript event. */ public function attach() { global $page_output; $result = $this->_attach(!$this->_init); if (!$this->_init) { $page_output->ajax = true; $page_output->addScriptFile('imple.js', 'horde'); $this->_init = true; } if ($result === false) { return; } $args = array('id' => $this->getDomId(), 'observe' => $this->_observe); $args['params'] = is_array($result) ? array_merge($result, $this->_impleParams()) : $result; $page_output->addInlineScript(array('HordeImple.add(' . Horde_Serialize::serialize($args, Horde_Serialize::JSON) . ')'), true); }
/** * Initialize a HordeMap. * * @param array $params */ public static function init(array $params = array()) { global $browser, $conf, $language, $page_output, $registry; // Language specific file needed? $language = str_replace('_', '-', $language); if (!file_exists($registry->get('jsfs', 'horde') . '/map/lang/' . $language . '.js')) { $language = 'en-US'; } $params = array_merge(array('conf' => array('language' => $language, 'markerImage' => strval(Horde_Themes::img('map/marker.png')), 'markerBackground' => strval(Horde_Themes::img('map/marker-shadow.png')), 'useMarkerLayer' => true), 'driver' => 'Horde', 'geocoder' => $conf['maps']['geocoder'], 'jsuri' => $registry->get('jsuri', 'horde') . '/map/', 'providers' => $conf['maps']['providers'], 'ssl' => $browser->usingSSLConnection()), $params); foreach ($params['providers'] as $layer) { switch ($layer) { case 'Google': $params['conf']['apikeys']['google'] = $conf['api']['googlemaps']; break; case 'Yahoo': $params['conf']['apikeys']['yahoo'] = $conf['api']['yahoomaps']; break; case 'Cloudmade': $params['conf']['apikeys']['cloudmade'] = $conf['api']['cloudmade']; break; case 'Mytopo': /* Mytopo requires a hash of the *client* IP address and the * key. Note that this also causes Mytopo to break if the * client's IP address presented as an internal address. */ $params['conf']['apikeys']['mytopo'] = array('id' => $conf['api']['mytopo_partnerID'], 'hash' => strtoupper(md5($conf['api']['mytopo'] . $browser->getIpAddress()))); break; } } if (!empty($params['geocoder'])) { switch ($params['geocoder']) { case 'Google': $params['conf']['apikeys']['google'] = $conf['api']['googlemaps']; break; case 'Yahoo': $params['conf']['apikeys']['yahoo'] = $conf['api']['yahoomaps']; break; case 'Cloudmade': $params['conf']['apikeys']['cloudmade'] = $conf['api']['cloudmade']; break; } } $page_output->addScriptFile('map/map.js', 'horde'); $page_output->addInlineScript(array('HordeMap.initialize(' . Horde_Serialize::serialize($params, HORDE_SERIALIZE::JSON) . ');')); }
/** * @param array $params The following configuration parameters: * - basic: (boolean) Load "basic" editor (a small javascript stub that * will download the full code on demand)? * - config: (mixed) If an array, the javascript config hash used to * indiciate the config for this editor instance. If a string, * will be used directly as the javascript config name to use * when loading (must exist elsewhere in page). * - id: (string) The ID of the text area to turn into an editor. If * empty, won't automatically load the editor. */ public function initialize(array $params = array()) { if (!$this->supportedByBrowser()) { return; } $ck_file = empty($params['basic']) ? 'ckeditor/ckeditor.js' : 'ckeditor/ckeditor_basic.js'; if (isset($params['config'])) { if (is_array($params['config'])) { /* Globally disable spell check as you type. */ $params['config']['scayt_autoStartup'] = false; $params['config'] = Horde_Serialize::serialize($params['config'], Horde_Serialize::JSON); } } else { $params['config'] = array(); } $this->_js = array('files' => array($ck_file), 'script' => array()); if (isset($params['id'])) { $this->_js['script'] = array('CKEDITOR.replace("' . $params['id'] . '",' . $params['config'] . ')'); } }
/** */ protected function _content() { global $page_output, $registry, $injector, $prefs; Horde::initMap(); $page_output->addScriptFile('map.js'); $page_output->addScriptFile('blocks/geotag.js'); try { $images = $injector->getInstance('Ansel_Storage')->getRecentImagesGeodata(null, 0, min($this->_params['limit'], 100)); } catch (Ansel_Exception $e) { return $e->getMessage(); } $images = array_reverse($images); foreach ($images as $key => $image) { $id = $image['image_id']; $gallery = $injector->getInstance('Ansel_Storage')->getGallery($image['gallery_id']); // Don't show locked galleries in the block. if (!$gallery->isOldEnough() || $gallery->hasPasswd()) { continue; } $style = $gallery->getStyle(); // Generate the image view url $url = Ansel::getUrlFor('view', array('view' => 'Image', 'slug' => $gallery->get('slug'), 'gallery' => $gallery->id, 'image' => $id, 'gallery_view' => $style->gallery_view), true); $images[$key]['icon'] = strval(Ansel::getImageUrl($images[$key]['image_id'], 'mini', true)); $images[$key]['link'] = strval($url); $images[$key]['markerOnly'] = false; } // URL for updating selected layer $layerUrl = $registry->getServiceLink('ajax', 'ansel')->setRaw(true); $layerUrl->url .= 'setPrefValue'; // And the current defaultLayer, if any. $defaultLayer = $prefs->getValue('current_maplayer'); $opts = array('layerUpdateEndpoint' => strval($layerUrl), 'layerUpdatePref' => 'current_maplayer', 'defaultBaseLayer' => $defaultLayer); $json = Horde_Serialize::serialize(array_values($images), Horde_Serialize::JSON); $js = array('var opts = ' . Horde_Serialize::serialize($opts, Horde_Serialize::JSON), 'new AnselBlockGeoTag(' . $json . ', opts);'); $page_output->addInlineScript($js, true); return '<div id="ansel_map" style="height:' . $this->_params['height'] . 'px;"></div>'; }
/** * Check for, and handle, image editing actions. * * @param string $actionID The action identifier. * * @return boolean True if an action was handled, otherwise false. * @throws Ansel_Exception */ public static function editActions($actionID) { global $notification, $page_output, $registry; $ansel_storage = $GLOBALS['injector']->getInstance('Ansel_Storage'); $gallery_id = Horde_Util::getFormData('gallery'); $image_id = Horde_Util::getFormData('image'); $date = Ansel::getDateParameter(); $page = Horde_Util::getFormData('page', 0); $watermark_font = Horde_Util::getFormData('font'); $watermark_halign = Horde_Util::getFormData('whalign'); $watermark_valign = Horde_Util::getFormData('wvalign'); $watermark = Horde_Util::getFormData('watermark', $GLOBALS['prefs']->getValue('watermark_text')); // Get the gallery object and style information. try { $gallery = $ansel_storage->getGallery($gallery_id); } catch (Ansel_Exception $e) { $notification->push(sprintf(_("Gallery %s not found."), $gallery_id), 'horde.error'); Ansel::getUrlFor('view', array('view' => 'List'), true)->redirect(); exit; } switch ($actionID) { case 'modify': try { $image = $ansel_storage->getImage($image_id); $ret = Horde_Util::getFormData('ret', 'gallery'); } catch (Ansel_Exception $e) { $notification->push(_("Photo not found."), 'horde.error'); Ansel::getUrlFor('view', array('view' => 'List'), true)->redirect(); exit; } $title = sprintf(_("Edit properties :: %s"), $image->filename); // Set up the form object. $vars = Horde_Variables::getDefaultVariables(); if ($ret == 'gallery') { $vars->set('actionID', 'saveclose'); } else { $vars->set('actionID', 'savecloseimage'); } $form = new Ansel_Form_Image($vars, $title); $renderer = new Horde_Form_Renderer(); // Set up the gallery attributes. $vars->set('image_default', $image->id == $gallery->get('default')); $vars->set('image_desc', $image->caption); $vars->set('image_tags', implode(', ', $image->getTags())); $vars->set('image_originalDate', $image->originalDate); $vars->set('image_uploaded', $image->uploaded); $page_output->header(array('title' => $title)); $form->renderActive($renderer, $vars, Horde::url('image.php'), 'post', 'multipart/form-data'); $page_output->footer(); exit; case 'savecloseimage': case 'saveclose': case 'save': $title = _("Save Photo"); if (!$gallery->hasPermission($registry->getAuth(), Horde_Perms::EDIT)) { $notification->push(_("Access denied saving photo to this gallery."), 'horde.error'); Ansel::getUrlFor('view', array_merge(array('gallery' => $gallery_id, 'slug' => $gallery->get('slug'), 'view' => 'Gallery', 'page' => $page), $date), true)->redirect(); exit; } // Validate the form object. $vars = Horde_Variables::getDefaultVariables(); $vars->set('actionID', 'save'); $renderer = new Horde_Form_Renderer(); $form = new Ansel_Form_Image($vars, _("Edit a photo")); // Update existing image. if ($form->validate($vars)) { $form->getInfo($vars, $info); // Replacing photo if (!empty($info['file0']['file'])) { try { $GLOBALS['browser']->wasFileUploaded('file0'); if (filesize($info['file0']['file'])) { $data = file_get_contents($info['file0']['file']); if (getimagesize($info['file0']['file']) === false) { $notification->push(_("The file you uploaded does not appear to be a valid photo."), 'horde.error'); unset($data); } } } catch (Horde_Browser_Exception $e) { } } $image = $ansel_storage->getImage($image_id); $image->caption = $vars->get('image_desc'); $image->setTags(explode(',', $vars->get('image_tags'))); $newDate = new Horde_Date($vars->get('image_originalDate')); $image->originalDate = (int) $newDate->timestamp(); if (!empty($data)) { try { $image->replace($data); } catch (Ansel_Exception $e) { $notification->push(_("There was an error replacing the photo."), 'horde.error'); } } $image->save(); if ($vars->get('image_default')) { if ($gallery->get('default') != $image_id) { // Changing default - force refresh of stack // If we have a default-pretty already, make sure we delete it $ids = unserialize($gallery->get('default_prettythumb')); if (is_array($ids)) { foreach ($ids as $imageId) { $gallery->removeImage($imageId, true); } } $gallery->set('default_prettythumb', ''); } $gallery->set('default', $image_id); $gallery->set('default_type', 'manual'); } elseif ($gallery->get('default') == $image_id) { // Currently set as default, but we no longer wish it. $gallery->set('default', 0); $gallery->set('default_type', 'auto'); // If we have a default-pretty already, make sure we delete it $ids = unserialize($gallery->get('default_prettythumb')); if (is_array($ids)) { foreach ($ids as $imageId) { $gallery->removeImage($imageId); } } $gallery->set('default_prettythumb', ''); } $gallery->save(); $imageurl = Ansel::getUrlFor('view', array_merge(array('gallery' => $gallery_id, 'image' => $image_id, 'view' => 'Image', 'page' => $page), $date), true); if ($actionID == 'save') { $imageurl->redirect(); } elseif ($actionID == 'saveclose') { $page_output->addInlineScript(array('window.opener.location.href = window.opener.location.href;', 'window.close();')); $page_output->outputInlineScript(); } else { $page_output->addInlineScript(array('window.opener.location.href = "' . $imageurl . '";', 'window.close();')); $page_output->outputInlineScript(); } exit; } break; case 'editimage': case 'cropedit': case 'resizeedit': $imageGenerator_url = Ansel::getUrlFor('view', array_merge(array('gallery' => $gallery_id, 'image' => $image_id, 'view' => 'Image', 'page' => $page), $date), true); $imageurl = Horde::url('image.php')->add(array_merge(array('gallery' => $gallery_id, 'slug' => $gallery->get('slug'), 'image' => $image_id, 'page' => $page), $date)); $galleryurl = Ansel::getUrlFor('view', array_merge(array('gallery' => $gallery_id, 'page' => $page, 'view' => 'Gallery', 'slug' => $gallery->get('slug')), $date)); if (!$gallery->hasPermission($registry->getAuth(), Horde_Perms::EDIT)) { $notification->push(_("Access denied editing the photo."), 'horde.error'); // Return to the image view. $imageGenerator_url->redirect(); exit; } // Retrieve image details. $image = $ansel_storage->getImage($image_id); $title = sprintf(_("Edit %s :: %s"), $gallery->get('name'), $image->filename); if ($actionID == 'cropedit') { $geometry = $image->getDimensions('full'); $x1 = 0; $y1 = 0; $x2 = $geometry['width']; $y2 = $geometry['height']; // js and css files $page_output->addScriptFile('scriptaculous/builder.js', 'horde'); $page_output->addScriptFile('scriptaculous/effects.js', 'horde'); $page_output->addScriptFile('scriptaculous/controls.js', 'horde'); $page_output->addScriptFile('scriptaculous/dragdrop.js', 'horde'); $page_output->addScriptFile('cropper.js'); $page_output->addInlineScript('imageCropper.init();', true); $page_output->addThemeStylesheet('cropper.css'); } elseif ($actionID == 'resizeedit') { // js and css files $geometry = $image->getDimensions('full'); $page_output->addScriptFile('scriptaculous/builder.js', 'horde'); $page_output->addScriptFile('scriptaculous/effects.js', 'horde'); $page_output->addScriptFile('scriptaculous/controls.js', 'horde'); $page_output->addScriptFile('scriptaculous/dragdrop.js', 'horde'); $page_output->addScriptFile('scriptaculous/slider.js', 'horde'); $page_output->addScriptFile('resizeimage.js'); $js = array('window.Ansel = window.Ansel || {}', 'Ansel.image_geometry = ' . Horde_Serialize::serialize($geometry, Horde_Serialize::JSON), "Ansel.slider = new Control.Slider(\n 'handle1',\n 'slider-track',\n {\n minimum: 1,\n maximum: Ansel.image_geometry['width'],\n sliderValue: Ansel.image_geometry['width'],\n handleImage: 'ansel_slider_img',\n axis: 'horizontal',\n onChange: function(e) { resizeImage(e * Ansel.image_geometry['width']); },\n onSlide: function(e) { resizeImage(e * Ansel.image_geometry['width']); }\n }\n );"); $page_output->addInlineScript($js, true); } $page_output->header(array('title' => $title)); $notification->notify(array('listeners' => 'status')); if ($actionID == 'cropedit') { require ANSEL_TEMPLATES . '/image/crop_image.inc'; } elseif ($actionID == 'resizeedit') { require ANSEL_TEMPLATES . '/image/resize_image.inc'; } else { require ANSEL_TEMPLATES . '/image/edit_image.inc'; } $page_output->footer(); exit; case 'watermark': if ($watermark) { $identity = $injector->getInstance('Horde_Core_Factory_Identity')->create(); $name = $identity->getValue('fullname'); if (empty($name)) { $name = $registry->getAuth(); } // Set up array of possible substitutions. $watermark_array = array('%N' => $name, '%L' => $registry->getAuth()); $watermark = str_replace(array_keys($watermark_array), array_values($watermark_array), $watermark); $watermark = strftime($watermark); } if (!$gallery->hasPermission($registry->getAuth(), Horde_Perms::EDIT)) { $notification->push(_("Access denied saving photo to this gallery."), 'horde.error'); // Return to the image view Ansel::getUrlFor('view', array_merge(array('gallery' => $gallery_id, 'image' => $image_id, 'view' => 'Image', 'page' => $page, 'slug' => $gallery->get('slug')), $date), true)->redirect(); exit; } else { $image = $ansel_storage->getImage($image_id); $image->watermark('screen', $watermark, $watermark_halign, $watermark_valign, $watermark_font); $image->updateData($image->raw('screen'), 'screen'); Horde::url('image.php', true)->add(array_merge(array('gallery' => $gallery_id, 'image' => $image_id, 'actionID' => 'editimage', 'page' => $page), $date))->redirect(); exit; } case 'rotate90': case 'rotate180': case 'rotate270': case 'flip': case 'mirror': case 'grayscale': case 'crop': case 'resize': if (!$gallery->hasPermission($registry->getAuth(), Horde_Perms::EDIT)) { $notification->push(_("Access denied saving photo to this gallery."), 'horde.error'); } else { try { $image = $ansel_storage->getImage($image_id); } catch (Ansel_Exception $e) { $notification->push($e->getMessage(), 'horde.error'); Ansel::getUrlFor('view', array('view' => 'List'), true)->redirect(); exit; } switch ($actionID) { case 'rotate90': case 'rotate180': case 'rotate270': $angle = intval(substr($actionID, 6)); try { $image->rotate('full', $angle); } catch (Ansel_Exception $e) { Horde::log($e->getMessage(), 'ERR'); $notification->push($e->getMessage(), 'horde.error'); $error = true; } break; case 'flip': try { $image->flip('full'); } catch (Ansel_Exception $e) { Horde::log($e->getMessage(), 'ERR'); $notification->push($e->getMessage(), 'horde.error'); $error = true; } break; case 'mirror': try { $image->mirror('full'); } catch (Ansel_Exception $e) { Horde::log($e->getMessage(), 'ERR'); $notification->push($e->getMessage(), 'horde.error'); $error = true; } break; case 'grayscale': try { $image->grayscale('full'); } catch (Ansel_Exception $e) { Horde::log($e->getMessage(), 'ERR'); $notification->push($e->getMessage(), 'horde.error'); $error = true; } break; case 'crop': $image->load('full'); $params = Horde_Util::getFormData('params'); list($x1, $y1, $x2, $y2) = explode('.', $params); try { $image->crop($x1, $y1, $x2, $y2); } catch (Ansel_Exception $e) { Horde::log($e->getMessage(), 'ERR'); $notification->push($e->getMessage(), 'horde.error'); $error = true; } break; case 'resize': $image->load('full'); $width = Horde_Util::getFormData('width'); $height = Horde_Util::getFormData('height'); try { $image->resize($width, $height, true); } catch (Ansel_Exception $e) { Horde::log($e->getMessage(), 'ERR'); $notification->push($e->getMessage(), 'horde.error'); $error = true; } break; } if (empty($error)) { $image->updateData($image->raw()); } } Horde::url('image.php', true)->add(array_merge(array('gallery' => $gallery_id, 'image' => $image_id, 'actionID' => 'editimage', 'page' => $page), $date))->redirect(); exit; case 'setwatermark': $title = _("Watermark"); try { $image = $ansel_storage->getImage($image_id); } catch (Ansel_Exception $e) { $notification->push($image->getMessage(), 'horde.error'); Ansel::getUrlFor('view', array('view' => 'List'), true)->redirect(); exit; } $vars = Horde_Variables::getDefaultVariables(); $vars->set('actionID', 'previewcustomwatermark'); $form = new Ansel_Form_Watermark($vars, _("Watermark")); $renderer = new Horde_Form_Renderer(); $page_output->header(array('title' => $title)); $form->renderActive($renderer, $vars, Horde::url('image.php'), 'post'); $page_output->footer(); exit; case 'previewcustomwatermark': $imageurl = Horde::url('image.php', true)->add(array_merge(array('gallery' => $gallery_id, 'image' => $image_id, 'page' => $page, 'watermark' => $watermark, 'font' => $watermark_font, 'whalign' => $watermark_halign, 'wvalign' => $watermark_valign, 'actionID' => 'previewwatermark'), $date)); $page_output->addInlineScript(array('window.opener.location.href = "' . $imageurl . '";', 'window.close();')); $page_output->outputInlineScript(); exit; case 'previewgrayscale': case 'previewwatermark': case 'previewflip': case 'previewmirror': case 'previewrotate90': case 'previewrotate180': case 'previewrotate270': $title = _("Edit Photo"); $action = substr($actionID, 7); $image = $ansel_storage->getImage($image_id); $title = sprintf(_("Preview changes for %s :: %s"), $gallery->get('name'), $image->filename); $page_output->header(array('title' => $title)); require ANSEL_TEMPLATES . '/image/preview_image.inc'; $page_output->footer(); exit; case 'imagerotate90': case 'imagerotate180': case 'imagerotate270': $view = Horde_Util::getFormData('view'); $angle = intval(substr($actionID, 11)); $image = $ansel_storage->getImage($image_id); $image->rotate($view, $angle); $image->display($view); exit; case 'imageflip': $view = Horde_Util::getFormData('view'); $image = $ansel_storage->getImage($image_id); $image->flip($view); $image->display($view); exit; case 'imagemirror': $view = Horde_Util::getFormData('view'); $image = $ansel_storage->getImage($image_id); $image->mirror($view); $image->display($view); exit; case 'imagegrayscale': $view = Horde_Util::getFormData('view'); $image = $ansel_storage->getImage($image_id); $image->grayscale($view); $image->display($view); exit; case 'imagewatermark': $view = Horde_Util::getFormData('view'); $image = $ansel_storage->getImage($image_id); $image->watermark($view, $watermark, $watermark_halign, $watermark_valign, $watermark_font); $image->display($view); exit; case 'previewcrop': if (!$gallery->hasPermission($registry->getAuth(), Horde_Perms::EDIT)) { $notification->push(_("Access denied editing the photo."), 'horde.error'); Ansel::getUrlFor('view', array('gallery' => $gallery_id, 'image' => $image_id, 'view' => 'Image', 'page' => $page))->redirect(); } else { $x1 = (int) Horde_Util::getFormData('x1'); $y1 = (int) Horde_Util::getFormData('y1'); $x2 = (int) Horde_Util::getFormData('x2'); $y2 = (int) Horde_Util::getFormData('y2'); $title = _("Crop"); $action = substr($actionID, 7); $image = $ansel_storage->getImage($image_id); $title = sprintf(_("Preview changes for %s :: %s"), $gallery->get('name'), $image->filename); $params = $x1 . '.' . $y1 . '.' . $x2 . '.' . $y2; $page_output->header(array('title' => $title)); require ANSEL_TEMPLATES . '/image/preview_cropimage.inc'; $page_output->footer(); } exit; case 'imagecrop': if ($gallery->hasPermission($registry->getAuth(), Horde_Perms::EDIT)) { $params = Horde_Util::getFormData('params'); list($x1, $y1, $x2, $y2) = explode('.', $params); $image = $ansel_storage->getImage($image_id); $image->load('full'); $image->crop($x1, $y1, $x2, $y2); $image->display(); } exit; } return false; }
/** * Handle output of the embedded widget: allows embedding calendar widgets * in external websites. * * The following arguments are required: * - calendar: The share_name for the requested calendar. * - container: The DOM node to populate with the widget. * - view: The view (block) we want. * * The following are optional (and are not used for all views) * - css * - days * - maxevents: The maximum number of events to show. * - months: The number of months to include. */ public function embed() { global $page_output, $registry; /* First, determine the type of view we are asking for */ $view = $this->vars->view; /* The DOM container to put the HTML in on the remote site */ $container = $this->vars->container; /* The share_name of the calendar to display */ $calendar = $this->vars->calendar; /* Deault to showing only 1 month when we have a choice */ $count_month = $this->vars->get('months', 1); /* Default to no limit for the number of events */ $max_events = $this->vars->get('maxevents', 0); /* Default to one week */ $count_days = $this->vars->get('days', 7); if ($this->vars->css == 'none') { $nocss = true; } /* Build the block parameters */ $params = array('calendar' => $calendar, 'maxevents' => $max_events, 'months' => $count_month, 'days' => $count_days); /* Call the Horde_Block api to get the calendar HTML */ $title = $registry->call('horde/blockTitle', array('kronolith', $view, $params)); $results = $registry->call('horde/blockContent', array('kronolith', $view, $params)); /* Some needed paths */ $js_path = $registry->get('jsuri', 'kronolith'); /* Local js */ $jsurl = Horde::url($js_path . '/embed.js', true); /* Horde's js */ $hjs_path = $registry->get('jsuri', 'horde'); $hjsurl = Horde::url($hjs_path . '/tooltips.js', true); $pturl = Horde::url($hjs_path . '/prototype.js', true); /* CSS */ if (empty($nocss)) { $page_output->addThemeStylesheet('embed.css'); Horde::startBuffer(); $page_output->includeStylesheetFiles(array('nobase' => true), true); $css = Horde::endBuffer(); } else { $css = ''; } /* Escape the text and put together the javascript to send back */ $container = Horde_Serialize::serialize($container, Horde_Serialize::JSON); $results = Horde_Serialize::serialize('<div class="kronolith_embedded"><div class="title">' . $title . '</div>' . $results . '</div>', Horde_Serialize::JSON); $js = <<<EOT if (typeof kronolith == 'undefined') { if (typeof Prototype == 'undefined') { document.write('<script type="text/javascript" src="{$pturl}"></script>'); } if (typeof Horde_ToolTips == 'undefined') { Horde_ToolTips_Autoload = false; document.write('<script type="text/javascript" src="{$hjsurl}"></script>'); } kronolith = new Object(); kronolithNodes = new Array(); document.write('<script type="text/javascript" src="{$jsurl}"></script>'); document.write('{$css}'); } kronolithNodes[kronolithNodes.length] = {$container}; kronolith[{$container}] = {$results}; EOT; return new Horde_Core_Ajax_Response_Raw($js, 'text/javascript'); }
<?php /** * Copyright 2005-2015 Horde LLC (http://www.horde.org/) * * See the enclosed file LICENSE for license information (BSD). If you * did not receive this file, see http://www.horde.org/licenses/bsdl.php. * * @author Chuck Hagenbuch <*****@*****.**> * @author Jan Schneider <*****@*****.**> */ require_once __DIR__ . '/lib/Application.php'; $hermes = Horde_Registry::appInit('hermes'); $vars = Horde_Variables::getDefaultVariables(); $form = new Horde_Form($vars, _("Stop Watch")); $form->addVariable(_("Stop watch description"), 'description', 'text', true); if ($form->validate($vars)) { Hermes::newTimer($vars->get('description')); echo Horde::wrapInlineScript(array('var t = ' . Horde_Serialize::serialize(sprintf(_("The stop watch \"%s\" has been started and will appear in the menu at the next refresh."), $vars->get('description')), Horde_Serialize::JSON) . ';', 'alert(t);', 'window.close();')); exit; } $page_output->topbar = $page_output->sidebar = false; $page_output->header(array('title' => _("Stop Watch"))); $form->renderActive(new Horde_Form_Renderer(), $vars, Horde::url('start.php'), 'post'); $page_output->footer();
/** * Retrieve json data for an arbitrary list of image ids, not necessarily * from the same gallery. * * @param array $images An array of image ids * @param Ansel_Style $style A gallery style to force if requesting * pretty thumbs. * @param boolean $full Generate full urls * @param string $image_view Which image view to use? screen, thumb etc.. * @param boolean $view_links Include links to the image view * * @return string The json data */ public function getImageJson(array $images, Ansel_Style $style = null, $full = false, $image_view = 'mini', $view_links = false) { $galleries = array(); if (is_null($style)) { $style = Ansel::getStyleDefinition('ansel_default'); } $json = array(); foreach ($images as $id) { $image = $this->getImage($id); $gallery_id = abs($image->gallery); if (empty($galleries[$gallery_id])) { $galleries[$gallery_id]['gallery'] = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($gallery_id); } // Any authentication that needs to take place for any of the // images included here MUST have already taken place or the // image will not be incldued in the output. if (!isset($galleries[$gallery_id]['perm'])) { $galleries[$gallery_id]['perm'] = $galleries[$gallery_id]['gallery']->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::READ) && $galleries[$gallery_id]['gallery']->isOldEnough() && !$galleries[$gallery_id]['gallery']->hasPasswd(); } if ($galleries[$gallery_id]['perm']) { $data = array((string) Ansel::getImageUrl($image->id, $image_view, $full, $style), htmlspecialchars($image->filename), $GLOBALS['injector']->getInstance('Horde_Core_Factory_TextFilter')->filter($image->caption, 'text2html', array('parselevel' => Horde_Text_Filter_Text2html::MICRO_LINKURL)), $image->id, 0); if ($view_links) { $data[] = (string) Ansel::getUrlFor('view', array('gallery' => $image->gallery, 'image' => $image->id, 'view' => 'Image', 'slug' => $galleries[$gallery_id]['gallery']->get('slug')), $full); $data[] = (string) Ansel::getUrlFor('view', array('gallery' => $image->gallery, 'slug' => $galleries[$gallery_id]['gallery']->get('slug'), 'view' => 'Gallery'), $full); } $json[] = $data; } } return Horde_Serialize::serialize($json, Horde_Serialize::JSON); }
/** * Uses DOM Tooltips to display the 'title' attribute for link() calls. * * @param string $url The full URL to be linked to * @param string $status The JavaScript mouse-over string * @param string $class The CSS class of the link * @param string $target The window target to point to. * @param string $onclick JavaScript action for the 'onclick' event. * @param string $title The link title (tooltip). Most not contain * HTML data other than <br>, which will * be converted to a linebreak. * @param string $accesskey The access key to use. * @param array $attributes Any other name/value pairs to add to the * <a> tag. * * @return string The full <a href> tag. */ public static function linkTooltip($url, $status = '', $class = '', $target = '', $onclick = '', $title = '', $accesskey = '', $attributes = array()) { if (strlen($title)) { $attributes['nicetitle'] = Horde_Serialize::serialize(explode("\n", preg_replace('/<br\\s*\\/?\\s*>/', "\n", $title)), Horde_Serialize::JSON); $title = null; $GLOBALS['injector']->getInstance('Horde_PageOutput')->addScriptFile('tooltips.js', 'horde'); } return self::link($url, $title, $class, $target, $onclick, null, $accesskey, $attributes, false); }
/** */ protected function _init() { global $conf, $injector, $notification, $page_output; $ingo_storage = $injector->getInstance('Ingo_Factory_Storage')->create(); switch ($ingo_storage->maxRules()) { case Ingo_Storage::MAX_NONE: Horde::permissionDeniedError('ingo', 'allow_rules', _("You are not allowed to create or edit custom rules.")); Ingo_Basic_Filters::url()->redirect(); case Ingo_Storage::MAX_OVER: Horde::permissionDeniedError('ingo', 'max_rules', sprintf(_("You are not allowed to create more than %d rules."), $ingo_storage->max_rules)); Ingo_Basic_Filters::url()->redirect(); } if (!Ingo::hasSharePermission(Horde_Perms::EDIT)) { $notification->push(_("You do not have permission to edit filter rules."), 'horde.error'); Ingo_Basic_Filters::url()->redirect(); } /* Load the Ingo_Script:: driver. */ $ingo_script_factory = $injector->getInstance('Ingo_Factory_Script'); $ingo_script = $ingo_script_factory->create(Ingo::RULE_FILTER); /* Redirect if no rules are available. */ $availActions = $ingo_script->availableActions(); if (empty($availActions)) { $notification->push(_("Individual rules are not supported in the current filtering driver."), 'horde.error'); Ingo_Basic_Filters::url()->redirect(); } /* This provides the $ingo_fields array. */ $config = new Horde_Registry_LoadConfig('ingo', 'fields.php', 'ingo_fields'); $ingo_fields = $config->config['ingo_fields']; /* Token checking. */ $actionID = $this->_checkToken(array('rule_save', 'rule_delete')); /* Update the current rules before performing any action. */ switch ($this->vars->action) { case 'Ingo_Rule_User_Discard': case 'Ingo_Rule_User_FlagOnly': case 'Ingo_Rule_User_Keep': case 'Ingo_Rule_User_Move': case 'Ingo_Rule_User_MoveKeep': case 'Ingo_Rule_User_Notify': case 'Ingo_Rule_User_Redirect': case 'Ingo_Rule_User_RedirectKeep': case 'Ingo_Rule_User_Reject': $rule = new $this->vars->action(); $rule->combine = $this->vars->combine; $rule->name = $this->vars->name; $rule->stop = $this->vars->stop; $rule->uid = $this->vars->edit; break; default: $rule = isset($this->vars->edit) ? $ingo_storage->getRuleByUid($this->vars->edit) : new Ingo_Rule_User(); break; } if (!$rule) { $notification->push(_("Filter not found."), 'horde.error'); Ingo_Basic_Filters::url()->redirect(); } if ($ingo_script->hasFeature('case_sensitive')) { $casesensitive = $this->vars->case; } foreach (array_filter(isset($this->vars->field) ? $this->vars->field : array()) as $key => $val) { $condition = array(); $f_label = null; if ($val == Ingo::USER_HEADER) { $condition['field'] = empty($this->vars->userheader[$key]) ? '' : $this->vars->userheader[$key]; $condition['type'] = Ingo_Rule_User::TEST_HEADER; } elseif (!isset($ingo_fields[$val])) { $condition['field'] = $val; $condition['type'] = Ingo_Rule_User::TEST_HEADER; } else { $condition['field'] = $val; $f_label = $ingo_fields[$val]['label']; $condition['type'] = $ingo_fields[$val]['type']; } $condition['match'] = isset($this->vars->match[$key]) ? $this->vars->match[$key] : ''; if ($actionID == 'rule_save' && empty($this->vars->value[$key]) && !in_array($condition['match'], array('exists', 'not exist'))) { $notification->push(sprintf(_("You cannot create empty conditions. Please fill in a value for \"%s\"."), is_null($f_label) ? $condition['field'] : $f_label), 'horde.error'); $actionID = null; } $condition['value'] = isset($this->vars->value[$key]) ? $this->vars->value[$key] : ''; if (isset($casesensitive)) { $condition['case'] = isset($casesensitive[$key]) ? $casesensitive[$key] : ''; } $tmp = $rule->conditions; $tmp[] = $condition; $rule->conditions = $tmp; } if ($this->vars->action) { switch ($rule->type) { case Ingo_Rule_User::TYPE_MAILBOX: switch ($actionID) { case 'rule_save': try { $rule->value = $this->validateMbox('actionvalue'); } catch (Ingo_Exception $e) { $notification->push($e, 'horde.error'); $actionID = null; } break; default: $rule->value = $this->vars->actionvalue; if (!$this->vars->actionvalue && isset($this->vars->actionvalue_new)) { $page_output->addInlineScript(array('IngoNewFolder.setNewFolder("actionvalue", ' . Horde_Serialize::serialize($this->vars->actionvalue_new, Horde_Serialize::JSON) . ')'), true); } break; } break; default: $rule->value = $this->vars->actionvalue; break; } } $flags = empty($this->vars->flags) ? array() : $this->vars->flags; $tmp = $rule->flags; foreach ($flags as $val) { $tmp |= $val; } $rule->flags = $tmp; /* Run through action handlers. */ switch ($actionID) { case 'rule_save': if (empty($rule->conditions)) { $notification->push(_("You need to select at least one field to match."), 'horde.error'); break; } $ingo_storage->updateRule($rule); $notification->push(_("Changes saved."), 'horde.success'); try { $ingo_script_factory->activateAll(); } catch (Ingo_Exception $e) { $notification->push($e, 'horde.error'); } Ingo_Basic_Filters::url()->redirect(); case 'rule_delete': if (isset($this->vars->conditionnumber)) { $tmp = $rule->conditions; unset($tmp[intval($this->vars->conditionnumber)]); $rule->conditions = array_values($tmp); } break; } /* Add new, blank condition. */ $rule->conditions[] = array(); /* Prepare the view. */ $view = new Horde_View(array('templatePath' => INGO_TEMPLATES . '/basic/rule')); $view->addHelper('Horde_Core_View_Helper_Help'); $view->addHelper('Horde_Core_View_Helper_Image'); $view->addHelper('Horde_Core_View_Helper_Label'); $view->addHelper('FormTag'); $view->addHelper('Tag'); $view->addHelper('Text'); $view->avail_types = $ingo_script->availableTypes(); $view->edit = $this->vars->edit; $view->fields = $ingo_fields; $view->formurl = $this->_addToken(self::url()); $view->rule = $rule; $view->special = $ingo_script->specialTypes(); $view->userheader = !empty($conf['rules']['userheader']); $filter = array(); $lastcond = count($rule->conditions) - 1; /* Display the conditions. */ foreach ($rule->conditions as $cond_num => $condition) { $tmp = array('cond_num' => intval($cond_num), 'field' => isset($condition['field']) ? $condition['field'] : '', 'lastfield' => $lastcond == $cond_num); if ($view->userheader && isset($condition['type']) && $condition['type'] == Ingo_Rule_User::TEST_HEADER && !isset($ingo_fields[$tmp['field']])) { $tmp['userheader'] = $tmp['field']; } if ($tmp['lastfield']) { $filter[] = $tmp; continue; } /* Create the match listing. */ if (!isset($condition['field']) || $condition['field'] == Ingo::USER_HEADER || !isset($ingo_fields[$condition['field']]['tests'])) { $avail_tests = $ingo_script->availableTests(); } else { $avail_tests = $ingo_fields[$condition['field']]['tests']; } $tmp['matchtest'] = array(); $selected_test = empty($condition['match']) ? null : $condition['match']; foreach ($avail_tests as $test) { if (is_null($selected_test)) { $selected_test = $test; } $tmp['matchtest'][] = array('label' => $rule->getTestInfo($test)->label, 'selected' => isset($condition['match']) && $test == $condition['match'], 'value' => $test); } if (!in_array($selected_test, array('exists', 'not exist'))) { $tmp['match_value'] = isset($condition['value']) ? $condition['value'] : ''; } $testOb = $rule->getTestInfo(!empty($condition['match']) ? $condition['match'] : 'contains'); switch ($testOb->type) { case 'text': if ($ingo_script->hasFeature('case_sensitive')) { $tmp['case_sensitive'] = !empty($condition['case']); } break; } $filter[] = $tmp; } $view->filter = $filter; /* Get the action select output. */ $actions = array(); foreach ($availActions as $val) { $ob = new $val(); $actions[] = array('label' => $ob->label, 'selected' => $ob instanceof $rule, 'value' => $val); } $view->actions = $actions; /* Get the action value output. */ switch ($rule->type) { case Ingo_Rule_User::TYPE_MAILBOX: $view->actionvaluelabel = _("Select target folder"); $view->actionvalue = Ingo_Flist::select($rule->value); break; case Ingo_Rule_User::TYPE_TEXT: $view->actionvaluelabel = _("Value"); $view->actionvalue = '<input id="actionvalue" name="actionvalue" size="40" value="' . htmlspecialchars($rule->value) . '" />'; break; } $view->flags = $rule->flags && Ingo_Rule_User::FLAG_AVAILABLE && $ingo_script->hasFeature('imap_flags'); $view->stop = $ingo_script->hasFeature('stop_script'); $page_output->addScriptFile('rule.js'); $page_output->addInlineJsVars(array('IngoRule.filtersurl' => strval(Ingo_Basic_Filters::url()->setRaw(true)))); $this->header = $rule->name; $this->output = $view->render('rule'); }
/** * Builds an JSON-RPC request and sends it to the server. * * This statically called method is actually the JSON-RPC client. * * @param string|Horde_Url $url The path to the JSON-RPC server on the * called host. * @param string $method The method to call. * @param Horde_Http_Client $client * @param array $params A hash containing any necessary parameters * for the method call. * * @return mixed The returned result from the method. * @throws Horde_Rpc_Exception */ public static function request($url, $method, $client, $params = null) { $headers = array('User-Agent' => 'Horde RPC client', 'Accept' => 'application/json', 'Content-Type' => 'application/json'); $data = array('version' => '1.1', 'method' => $method); if (!empty($params)) { $data['params'] = $params; } $data = Horde_Serialize::serialize($data, Horde_Serialize::JSON); try { $result = $client->post($url, $data, $headers); } catch (Horde_Http_Exception $e) { throw new Horde_Rpc_Exception($e->getMessage()); } if ($result->code == 500) { $response = Horde_Serialize::unserialize($result->getBody(), Horde_Serialize::JSON); if (is_a($response, 'stdClass') && isset($response->error) && is_a($response->error, 'stdClass') && isset($response->error->name) && $response->error->name == 'JSONRPCError') { throw new Horde_Rpc_Exception($response->error->message); /* @todo: Include more information if we have an Exception that can handle this. return PEAR::raiseError($response->error->message, $response->error->code, null, null, isset($response->error->error) ? $response->error->error : null); */ } throw new Horde_Rpc_Exception($http->getResponseBody()); } elseif ($result->code != 200) { throw new Horde_Rpc_Exception('Request couldn\'t be answered. Returned errorcode: "' . $result->code); } return Horde_Serialize::unserialize($result->getBody(), Horde_Serialize::JSON); }
/** * List the current folder. * * @param string $dir The directory name. * * @return array The sorted list of files. * @throws Gollem_Exception */ public static function listFolder($dir) { global $conf; if (!empty($conf['foldercache']['use_cache']) && !empty($conf['cache']['driver']) && $conf['cache']['driver'] != 'none') { $key = self::_getCacheID($dir); $cache = $GLOBALS['injector']->getInstance('Horde_Cache'); $res = $cache->get($key, $conf['foldercache']['lifetime']); if ($res !== false) { $res = Horde_Serialize::unserialize($res, Horde_Serialize::BASIC); if (is_array($res)) { return $res; } } } try { $files = $GLOBALS['injector']->getInstance('Gollem_Vfs')->listFolder($dir, isset(self::$backend['filter']) ? self::$backend['filter'] : null, $GLOBALS['prefs']->getValue('show_dotfiles')); } catch (Horde_Vfs_Exception $e) { throw new Gollem_Exception($e); } $sortcols = array(self::SORT_TYPE => 'sortType', self::SORT_NAME => 'sortName', self::SORT_DATE => 'sortDate', self::SORT_SIZE => 'sortSize'); usort($files, array('Gollem', $sortcols[$GLOBALS['prefs']->getValue('sortby')])); if (isset($cache)) { $cache->set($key, Horde_Serialize::serialize($files, Horde_Serialize::BASIC), $conf['foldercache']['lifetime']); } return $files; }
/* Run through action handlers. */ switch ($vars->actionID) { case 'save_file': try { $injector->getInstance('Gollem_Vfs')->writeData($vars->dir, $vars->file, $vars->content); $message = sprintf(_("%s successfully saved."), $vars->file); } catch (Horde_Vfs_Exception $e) { $message = sprintf(_("Access denied to %s"), $vars->file); } echo Horde::wrapInlineScript(array('alert(' . Horde_Serialize::serialize($message, Horde_Serialize::JSON) . ')')); break; case 'edit_file': try { $data = $injector->getInstance('Gollem_Vfs')->read($vars->dir, $vars->file); } catch (Horde_Vfs_Exception $e) { echo Horde::wrapInlineScript(array('alert(' . Horde_Serialize::serialize(sprintf(_("Access denied to %s"), $vars->file), Horde_Serialize::JSON) . ')')); break; } $mime_type = Horde_Mime_Magic::extToMIME($vars->type); if (strpos($mime_type, 'text/') !== 0) { break; } if ($mime_type == 'text/html') { $injector->getInstance('Horde_Editor')->initialize(array('id' => 'content')); } $view = $injector->createInstance('Horde_View'); $view->self_url = Horde::url('edit.php'); $view->forminput = Horde_Util::formInput(); $view->vars = $vars; $view->data = $data; $page_output->addScriptFile('edit.js');
/** * Initialize the renderer. This *must* be called before any attempt is made * to display or otherwise interact with the renderer. * */ public function init() { global $prefs, $conf, $registry, $page_output; $this->galleryId = $this->view->gallery->id; $this->gallerySlug = $this->view->gallery->get('slug'); $this->page = $this->view->page; // Number perpage from prefs or config if ($this->view->tilesperpage) { $this->perpage = $this->view->tilesperpage; } else { $this->perpage = min($prefs->getValue('tilesperpage'), $conf['thumbnail']['perpage']); } $this->pagestart = $this->page * $this->perpage + 1; // Fetch the children $this->fetchChildren($this->view->force_grouping); // Do we have an explicit style set from the API? // If not, use the gallery's if (!empty($this->view->style)) { $this->style = Ansel::getStyleDefinition($this->view->style); } else { $this->style = $this->view->gallery->getStyle(); } // Include any widgets if (!empty($this->style->widgets) && !$this->view->api) { // Special case widgets - these are built in if (array_key_exists('Actions', $this->style->widgets)) { // Don't show action widget if no actions if ($registry->getAuth() || !empty($conf['report_content']['driver']) && ($conf['report_content']['allow'] == 'authenticated' && $registry->isAuthenticated() || $conf['report_content']['allow'] == 'all')) { $this->view->addWidget(Ansel_Widget::factory('Actions')); } unset($this->style->widgets['Actions']); } // Gallery widgets always receive an array of image ids for // the current page. $ids = $this->getChildImageIds(); foreach ($this->style->widgets as $wname => $wparams) { $wparams = array_merge($wparams, array('images' => $ids)); $this->view->addWidget(Ansel_Widget::factory($wname, $wparams)); } } if (empty($this->view->api)) { $page_output->addScriptFile('views/common.js'); $page_output->addScriptFile('views/gallery.js'); $page_output->addScriptFile('popup.js', 'horde'); $strings = array('delete_conf' => _("Are you sure you want to delete the selected photos?"), 'choose_gallery_move' => _("You must choose a gallery to move photos to."), 'choose_images' => _("You must first choose photos.")); $urls = array('image_date' => strval(Horde::url('edit_dates.php')->add(array('gallery' => $this->galleryId)))); $js = array('Ansel = window.Ansel || {};', 'Ansel.galleryview_strings = ' . Horde_Serialize::serialize($strings, Horde_Serialize::JSON), 'Ansel.galleryview_urls = ' . Horde_Serialize::serialize($urls, Horde_Serialize::JSON), 'Ansel.has_edit = ' . $this->view->gallery->hasPermission($registry->getAuth(), Horde_Perms::EDIT) ? 1 : 0, 'Ansel.has_delete = ' . $this->view->gallery->hasPermission($registry->getAuth(), Horde_Perms::DELETE) ? 1 : 0); $page_output->addInlineScript($js, true); } // Perform any initialization of the subclasses. $this->_init(); }
/** * Outputs the status line if there are any messages on the 'status' * message stack. * * @param array $events The list of events to handle. * @param array $options An array of options. Not used. */ public function notify($events, $options = array()) { if (!empty($events)) { $GLOBALS['page_output']->addInlineScript(array('window.HordeCore.showNotifications(' . Horde_Serialize::serialize($events, Horde_Serialize::JSON) . ')'), true); } }
/** * Notifies about an alarm through javascript. * * @param array $alarm An alarm hash. */ public function notify(array $alarm) { $js = sprintf('if(window.webkitNotifications)(function(){function show(){switch(window.webkitNotifications.checkPermission()){case 0:var notify=window.webkitNotifications.createNotification("%s",%s,%s);notify.show();(function(){notify.cancel()}).delay(5);break;case 1:window.webkitNotifications.requestPermission(function(){});break}}show()})()', $this->_icon, Horde_Serialize::serialize($alarm['title'], Horde_Serialize::JSON), isset($alarm['text']) ? Horde_Serialize::serialize($alarm['text'], Horde_Serialize::JSON) : "''"); call_user_func($this->_jsNotify, $js); }
/** * Add inline javascript variable definitions to the output buffer. * * @param array $data Keys are the variable names, values are the data * to JSON encode. If the key begins with a '-', * the data will be added to the output as-is. * @param mixed $opts If boolean true, equivalent to setting the 'onload' * option to true. Other options: * - onload: (boolean) Wrap the definition in an onload handler? * DEFAULT: false * - ret_vars: (boolean) If true, will return the list of variable * definitions instead of outputting to page. * DEFAULT: false * - top: (boolean) Add definitions to top of stack? * DEFAULT: false * * @return array Returns the variable list of 'ret_vars' option is true. */ public function addInlineJsVars($data, $opts = array()) { $out = array(); if ($opts === true) { $opts = array('onload' => true); } $opts = array_merge(array('onload' => false, 'ret_vars' => false, 'top' => false), $opts); foreach ($data as $key => $val) { if ($key[0] == '-') { $key = substr($key, 1); } else { $val = Horde_Serialize::serialize($val, Horde_Serialize::JSON); } $out[] = $key . '=' . $val; } if ($opts['ret_vars']) { return $out; } $this->addInlineScript($out, $opts['onload'], $opts['top']); }
/** * JSON representation of this gallery's images. We don't use * Ansel_Gallery::toJson() on purpose since that is a general jsonification * of the gallery data. This method is specific to the view, paging, links * etc... * * @param Ansel_Gallery $gallery The gallery to represent in this view * @param array $params An array of parameters for this method: * <pre> * full - Should a full URL be generated? [false] * from - Starting image count [0] * count - The number of images to include (starting at from) [0] * image_view - The type of ImageGenerator to obtain the src url for. [screen] * view_links - Should the JSON include links to the Image and/or Gallery View? [false] * perpage - Number of images per page [from user prefs] * </pre> * * @return string A serialized JSON array. */ public static function json(Ansel_Gallery $gallery, $params = array()) { global $conf, $prefs; $default = array('full' => false, 'from' => 0, 'count' => 0, 'image_view' => 'screen', 'view_links' => false, 'perpage' => $prefs->getValue('tilesperpage', $conf['thumbnail']['perpage'])); $params = array_merge($default, $params); $json = array(); $curimage = 0; $curpage = 0; if (empty($params['images'])) { $images = $gallery->getImages($params['from'], $params['count']); } $style = $gallery->getStyle(); if ($params['image_view'] == 'thumb' && !empty($params['generator'])) { $style->thumbstyle = $params['generator']; } foreach ($images as $image) { // Calculate the page this image will appear on in the gallery view. if (++$curimage > $params['perpage']) { ++$curpage; $curimage = 0; } $data = array((string) Ansel::getImageUrl($image->id, $params['image_view'], $params['full'], $style), htmlspecialchars($image->filename), $GLOBALS['injector']->getInstance('Horde_Core_Factory_TextFilter')->filter($image->caption, 'text2html', array('parselevel' => Horde_Text_Filter_Text2html::MICRO_LINKURL)), $image->id, $curpage); if ($params['view_links']) { $data[] = (string) Ansel::getUrlFor('view', array('gallery' => $gallery->id, 'slug' => $gallery->get('slug'), 'image' => $image->id, 'view' => 'Image', 'page' => $curpage), true); $data[] = (string) Ansel::getUrlFor('view', array('gallery' => $image->gallery, 'slug' => $gallery->get('slug'), 'view' => 'Gallery'), true); } // Source, Width, Height, Name, Caption, Image Id, Gallery Page $json[] = $data; } return Horde_Serialize::serialize($json, Horde_Serialize::JSON); }
/** * Build the HTML for the widget * * @return string */ public function html() { global $page_output; $view = $GLOBALS['injector']->getInstance('Horde_View'); $view->addTemplatePath(ANSEL_TEMPLATES . '/widgets'); $view->title = _("Location"); $view->background = $this->_style->background; $ansel_storage = $GLOBALS['injector']->getInstance('Ansel_Storage'); $geodata = $ansel_storage->getImagesGeodata($this->_params['images']); $viewType = $this->_view->viewType(); // Exit early? if (count($geodata) == 0 && $viewType != 'Image') { return ''; } // Setup map and javascript includes Horde::initMap(); $page_output->addScriptFile('map.js'); $page_output->addScriptFile('popup.js', 'horde'); $page_output->addScriptFile('widgets/geotag.js'); // Values needed by map javascript $relocate_url = Horde::url('map_edit.php', true); $rtext = _("Relocate this image"); $dtext = _("Delete geotag"); $thisTitleText = _("This image"); $otherTitleText = _("Other images in this gallery"); $geotagUrl = $GLOBALS['registry']->getServiceLink('ajax', 'ansel')->setRaw(true); $geotagUrl->url .= 'imageSaveGeotag'; $permsEdit = (int) $this->_view->gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT); $view->haveEdit = $permsEdit; // URL for updating selected layer $layerUrl = $GLOBALS['registry']->getServiceLink('ajax', 'ansel')->setRaw(true); $layerUrl->url .= 'setPrefValue'; // And the current defaultLayer, if any. $defaultLayer = $GLOBALS['prefs']->getValue('current_maplayer'); // Add extra information to the JSON data to be sent: foreach ($geodata as $id => $data) { $geodata[$id]['icon'] = (string) Ansel::getImageUrl($geodata[$id]['image_id'], 'mini', true); $geodata[$id]['markerOnly'] = $viewType == 'Image'; $geodata[$id]['link'] = (string) Ansel::getUrlFor('view', array('view' => 'Image', 'gallery' => $this->_view->gallery->id, 'image' => $geodata[$id]['image_id']), true); } // Image view? $view->isImageView = $viewType == 'Image'; // If this is an image view, get the other gallery images if ($viewType == 'Image' && !empty($geodata)) { $image_id = $this->_view->resource->id; $others = $this->_getGalleryImagesWithGeodata(); foreach ($others as $id => $data) { if ($id != $image_id) { $others[$id]['icon'] = (string) Ansel::getImageUrl($others[$id]['image_id'], 'mini', true); $others[$id]['link'] = (string) Ansel::getUrlFor('view', array('view' => 'Image', 'gallery' => $this->_view->gallery->id, 'image' => $others[$id]['image_id']), true); } else { unset($others[$id]); } } $geodata = array_values(array_merge($geodata, $others)); $view->geodata = $geodata; } if ($permsEdit) { // Image view, but no geotags, provide ability to add it. $addurl = Horde::url('map_edit.php')->add('image', $this->_params['images'][0]); $view->addLink = $addurl->link(array('onclick' => Horde::popupJs(Horde::url('map_edit.php'), array('params' => array('image' => $this->_params['images'][0]), 'urlencode' => true, 'width' => '750', 'height' => '600')) . 'return false;')); $view->imgs = $ansel_storage->getRecentImagesGeodata($GLOBALS['registry']->getAuth()); if (count($view->imgs) > 0) { foreach ($view->imgs as $id => &$data) { if (!empty($data['image_location'])) { $data['title'] = $data['image_location']; } else { $data['title'] = sprintf('%s %s', Ansel::point2Deg($data['image_latitude'], true), Ansel::point2Deg($data['image_longitude'])); } $data['add_link'] = $addurl->link(array('title' => $title, 'onclick' => "Ansel.widgets.geotag.setLocation(" . $image_id . ",'" . $data['image_latitude'] . "', '" . $data['image_longitude'] . "'); return false")); } } } // Build the javascript to handle the map on the gallery/image views. $json = Horde_Serialize::serialize(array_values($geodata), Horde_Serialize::JSON); $js_params = array('smallMap' => 'ansel_map_small', 'mainMap' => 'ansel_map', 'viewType' => $viewType, 'relocateUrl' => strval($relocate_url), 'relocateText' => $rtext, 'markerLayerTitle' => $thisTitleText, 'imageLayerTitle' => $otherTitleText, 'defaultBaseLayer' => $defaultLayer, 'deleteGeotagText' => $dtext, 'hasEdit' => $permsEdit, 'updateEndpoint' => strval($geotagUrl), 'layerUpdateEndpoint' => strval($layerUrl), 'layerUpdatePref' => 'current_maplayer', 'geocoder' => $GLOBALS['conf']['maps']['geocoder']); $js = array('Ansel.widgets = Ansel.widgets || {};', 'Ansel.widgets.geotag = new AnselGeoTagWidget(' . $json . ',' . Horde_Serialize::serialize($js_params, Horde_Serialize::JSON) . ');'); $page_output->addInlineScript($js, true); if (count($geodata)) { $page_output->addInlineScript('Ansel.widgets.geotag.doMap();', true); } return $view->render('geotag'); }
/** */ public function generate(Horde_Core_Ajax_Imple_AutoCompleter $ac) { $dom_id = $ac->getDomId(); return 'new Autocompleter.Local(' . Horde_Serialize::serialize($dom_id, Horde_Serialize::JSON) . ',' . (is_string($this->_search) ? $this->_search : Horde_Serialize::serialize($this->_search, Horde_Serialize::JSON)) . ',' . '{' . implode(',', $this->_getOpts($ac)) . '})'; }
/** * Saves the passed field into the db, either inserting * a new field if no field_id is available, or updating * an existing field if a field_id has been passed. * If no form_id is available will throw an exception. * * @param array $params An array with the field details. * * @return boolean True on success. * @throws Horde_Exception_NotFound * @throws Ulaform_Exception */ public function saveField(&$info) { if (empty($info['form_id'])) { throw new Horde_Exception_NotFound(_("Missing form")); } $values = array(); if (!empty($info['field_id'])) { $values[] = $info['field_id']; } else { if (empty($info['field_order'])) { $info['field_order'] = $this->_nextFieldOrder($info['form_id']); } } /* Set up the field data. */ $info['field_required'] = $info['field_required'] ? 1 : 0; $info['field_readonly'] = $info['field_readonly'] ? 1 : 0; if (!empty($info['field_params'])) { $info['field_params'] = Horde_Serialize::serialize($info['field_params'], Horde_Serialize::UTF7_BASIC); } else { $info['field_params'] = null; } array_unshift($values, $info['form_id'], Horde_String::convertCharset($info['field_name'], 'UTF-8', $this->_charset), Horde_String::convertCharset($info['field_label'], 'UTF-8', $this->_charset), $info['field_type'], Horde_String::convertCharset($info['field_params'], 'UTF-8', $this->_charset), $info['field_required'], $info['field_readonly'], Horde_String::convertCharset($info['field_desc'], 'UTF-8', $this->_charset), $info['field_order']); if (empty($info['field_id'])) { $sql = 'INSERT INTO ulaform_fields (form_id, field_name, field_label, field_type, field_params, field_required, field_readonly, field_desc, field_order) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)'; try { $this->_db->insert($sql, $values); } catch (Horde_Db_Exception $e) { throw new Ulaform_Exception($e->getMessage()); } } else { $sql = 'UPDATE ulaform_fields SET form_id = ?, field_name = ?, field_label = ?, field_type = ?, field_params = ?, field_required = ?, field_readonly = ?, field_desc = ?, field_order = ? WHERE field_id = ?'; try { $this->_db->update($sql, $values); } catch (Horde_Db_Exception $e) { throw new Ulaform_Exception($e->getMessage()); } } return true; }