Copyright 2001-2016 Horde LLC (http://www.horde.org/) See the enclosed file COPYING for license information (LGPL). If you did not receive this file, see http://www.horde.org/licenses/lgpl21.
Автор: Stephane Huther (shuther1@free.fr)
Автор: Michael Slusarz (slusarz@horde.org)
Пример #1
0
 /**
  * Retrieves the txt_datavalue or int_datavalue depending on context
  */
 public function getDataValue()
 {
     /* These field-specific handlers should better be delegated to field
      * definitions. */
     switch ($this->property->datatype) {
         case 'date':
         case 'datetime':
         case 'hourminutesecond':
         case 'monthdayyear':
         case 'monthyear':
         case 'time':
             if (is_int($this->txt_datavalue)) {
                 return new Horde_Date($this->txt_datavalue);
             }
             $dt = new Horde_Date();
             foreach (Horde_Serialize::unserialize($this->txt_datavalue, Horde_Serialize::BASIC) as $marker => $content) {
                 if (strlen($content)) {
                     $dt->{$marker} = $content;
                 }
             }
             return $dt;
         case 'image':
             return array('hash' => $this->txt_datavalue);
         default:
             return $this->txt_datavalue;
     }
 }
Пример #2
0
 /**
  */
 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']);
 }
Пример #3
0
 /**
  * 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) . ');});'));
 }
Пример #4
0
 /**
  * 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>';
 }
Пример #5
0
 /**
  */
 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)) . '})';
 }
Пример #6
0
 /**
  * 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;
 }
Пример #7
0
 /**
  * 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);
     }
 }
Пример #8
0
 /**
  * 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));
 }
Пример #9
0
 /**
  */
 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;
 }
Пример #10
0
 /**
  * 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) . ');'));
 }
Пример #11
0
 /**
  * @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'] . ')');
     }
 }
Пример #12
0
 /**
  * AJAX action: Return Turba minisearch information.
  *
  * Variables used:
  *   - abooks: (array) UIDs of source addressbook.
  *   - search: (string) Search string.
  *
  * @return object  HTML search output in the 'html' parameter.
  */
 public function minisearch()
 {
     global $attributes, $injector, $registry;
     $ob = new stdClass();
     $results = array();
     $search = trim($this->vars->search);
     if (!is_null($search)) {
         foreach (Horde_Serialize::unserialize($this->vars->abooks, Horde_Serialize::JSON) as $val) {
             try {
                 $res = $injector->getInstance('Turba_Factory_Driver')->create($val)->search(array('name' => $search));
                 while ($ob = $res->next()) {
                     if ($ob->isGroup()) {
                         continue;
                     }
                     foreach ($ob->getAttributes() as $k => $v) {
                         if (!empty($attributes[$k]['type']) && $attributes[$k]['type'] == 'email') {
                             if (!empty($v)) {
                                 try {
                                     $mail_link = $registry->call('mail/compose', array(array('to' => $v)));
                                 } catch (Horde_Exception $e) {
                                     $mail_link = 'mailto:' . urlencode($v);
                                 }
                             }
                             $link = empty($v) ? htmlspecialchars($ob->getValue('name')) : htmlspecialchars($ob->getValue('name') . ' <' . $v . '>');
                             $results[] = '<li class="linedRow">' . Horde::link(Horde::url($ob->url()), _("View Contact"), '', '_parent') . Horde_Themes_Image::tag('contact.png', array('alt' => _("View Contact"))) . '</a> ' . (!empty($v) ? '<a href="' . $mail_link . '">' : '') . $link . (!empty($v) ? '</a>' : '') . '</li>';
                             break;
                         }
                     }
                 }
             } catch (Turba_Exception $e) {
             }
         }
     }
     if (count($results)) {
         $ob->html = '<ul>' . implode('', $results) . '</ul>';
     } elseif (!is_null($search)) {
         $ob->html = _("No contacts found");
     }
     return $ob;
 }
Пример #13
0
 /**
  */
 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>';
 }
Пример #14
0
 /**
  */
 public function display(Horde_Core_Prefs_Ui $ui)
 {
     global $injector, $prefs, $registry, $session;
     $twitter = $injector->getInstance('Horde_Service_Twitter');
     $token = unserialize($prefs->getValue('twitter'));
     /* Check for an existing token */
     if (!empty($token['key']) && !empty($token['secret'])) {
         $auth_token = new Horde_Oauth_Token($token['key'], $token['secret']);
         $twitter->auth->setToken($auth_token);
     }
     try {
         $profile = Horde_Serialize::unserialize($twitter->account->verifyCredentials(), Horde_Serialize::JSON);
     } catch (Horde_Service_Twitter_Exception $e) {
     }
     $view = new Horde_View(array('templatePath' => HORDE_TEMPLATES . '/prefs'));
     $view->addHelper('Text');
     $view->appname = $registry->get('name');
     /* Could not find a valid auth token, and we are not in the process of
      * getting one */
     if (empty($profile)) {
         try {
             $results = $twitter->auth->getRequestToken();
         } catch (Horde_Service_Twitter_Exception $e) {
             throw new Horde_Exception(sprintf(_("Error connecting to Twitter: %s Details have been logged for the administrator."), $e->getMessage()));
         }
         $session->store($results->secret, false, 'twitter_request_secret');
         $view->link = new Horde_Url(Horde::externalUrl($twitter->auth->getUserAuthorizationUrl($results), false));
     } else {
         $view->haveSession = true;
         $view->profile_image_url = $profile->profile_image_url;
         $view->profile_screenname = $profile->screen_name;
         $view->profile_name = $profile->name;
         $view->profile_location = $profile->location;
     }
     return $view->render('twitter');
 }
Пример #15
0
 /**
  */
 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');
 }
Пример #16
0
 /**
  * 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;
 }
Пример #17
0
 protected function _makeRequest($url, $lifetime = 86400)
 {
     $cachekey = md5('hordeweather' . $url);
     if (!empty($this->_cache) && !($results = $this->_cache->get($cachekey, $lifetime)) || empty($this->_cache)) {
         $url = new Horde_Url($url);
         $response = $this->_http->get((string) $url);
         if (!$response->code == '200') {
             throw new Horde_Service_Weather_Exception($response->code);
         }
         $results = $response->getBody();
         if (!empty($this->_cache)) {
             $this->_cache->set($cachekey, $results);
         }
     }
     $results = Horde_Serialize::unserialize($results, Horde_Serialize::JSON);
     if (!$results instanceof StdClass) {
         throw new Horde_Service_Weather_Exception('Error, unable to decode response.');
     }
     return $results;
 }
Пример #18
0
 /**
  * Returns the attributes for a specific ticket.
  *
  * This method will check if external attributes need to be fetched from
  * hooks or whether to use the standard ones defined within Whups.
  *
  * @params integer $ticket_id  The ticket ID.
  *
  * @return array  List of attributes.
  */
 public function getAllTicketAttributesWithNames($ticket_id)
 {
     $ta = $this->_getAllTicketAttributesWithNames($ticket_id);
     $attributes = array();
     foreach ($ta as $id => $attribute) {
         try {
             $value = Horde_Serialize::unserialize($attribute['attribute_value'], Horde_Serialize::JSON);
         } catch (Horde_Serialize_Exception $e) {
             $value = $attribute['attribute_value'];
         }
         $attributes[$attribute['attribute_id']] = array('id' => $attribute['attribute_id'], 'human_name' => $attribute['attribute_name'], 'type' => $attribute['attribute_type'], 'required' => $attribute['attribute_required'], 'readonly' => false, 'desc' => $attribute['attribute_description'], 'params' => $attribute['attribute_params'], 'value' => $value);
     }
     return $attributes;
 }
Пример #19
0
<?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();
Пример #20
0
 /**
  * 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);
 }
Пример #21
0
 /**
  * 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);
 }
Пример #22
0
 /**
  * Returns attribute values and information of a ticket.
  *
  * @param integer $ticket_id  A ticket IDs.
  *
  * @return array  A list of hashes with attribute information and attribute
  *                value.
  * @throws Whups_Exception
  */
 protected function _getAllTicketAttributesWithNames($ticket_id)
 {
     try {
         $attributes = $this->_db->selectAll('SELECT d.attribute_id, d.attribute_name, ' . 'd.attribute_description, d.attribute_type, ' . 'd.attribute_params, d.attribute_required, ' . 'a.attribute_value FROM whups_attributes_desc d ' . 'LEFT JOIN whups_tickets t ON (t.ticket_id = ?) ' . 'LEFT OUTER JOIN whups_attributes a ' . 'ON (d.attribute_id = a.attribute_id AND a.ticket_id = ?) ' . 'WHERE d.type_id = t.type_id ORDER BY d.attribute_name', array($ticket_id, $ticket_id));
     } catch (Horde_Db_Exception $e) {
         throw new Whups_Exception($e);
     }
     foreach ($attributes as &$attribute) {
         $attribute['attribute_name'] = $this->_fromBackend($attribute['attribute_name']);
         $attribute['attribute_description'] = $this->_fromBackend($attribute['attribute_description']);
         $attribute['attribute_type'] = empty($attribute['attribute_type']) ? 'text' : $attribute['attribute_type'];
         $attribute['attribute_params'] = $this->_fromBackend(@unserialize($attribute['attribute_params']));
         $attribute['attribute_required'] = (bool) $attribute['attribute_required'];
         try {
             $attribute['attribute_value'] = Horde_Serialize::unserialize($attribute['attribute_value'], Horde_Serialize::JSON);
         } catch (Horde_Serialize_Exception $e) {
         }
     }
     return $attributes;
 }
Пример #23
0
 /**
  * Make the remote API call.
  *
  * @param Horde_Url $url  The endpoint.
  *
  * @return mixed  The unserialized results form the remote API call.
  * @throws Horde_Service_Weather_Exception
  */
 protected function _makeRequest(Horde_Url $url)
 {
     // Owm returns temperature data in Kelvin by default!
     if ($this->units == Horde_Service_Weather::UNITS_METRIC) {
         $url->add('units', 'metric');
     } else {
         $url->add('units', 'imperial');
     }
     $url->add(array('key' => $this->_key))->setRaw(true);
     $cachekey = md5('hordeweather' . $url);
     if (!empty($this->_cache) && !($results = $this->_cache->get($cachekey, $this->_cache_lifetime)) || empty($this->_cache)) {
         $response = $this->_http->get((string) $url);
         if (!$response->code == '200') {
             throw new Horde_Service_Weather_Exception($response->code);
         }
         $results = $response->getBody();
         if (!empty($this->_cache)) {
             $this->_cache->set($cachekey, $results);
         }
     }
     $results = Horde_Serialize::unserialize($results, Horde_Serialize::JSON);
     if (!$results instanceof StdClass) {
         throw new Horde_Service_Weather_Exception(sprintf('Error, unable to decode response: %s', $results));
     }
     return $results;
 }
Пример #24
0
 public function importData($contents, $header = false)
 {
     $data = array();
     $json = Horde_Serialize::unserialize($contents, Horde_Serialize::JSON);
     return $this->_parseJson($json->children, null);
 }
Пример #25
0
 /**
  * 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;
 }
Пример #26
0
 /**
  * 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);
     }
 }
Пример #27
0
    /**
     * 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');
    }
Пример #28
0
/* 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');
Пример #29
0
 /**
  */
 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)) . '})';
 }
Пример #30
0
        _outputError($e);
    }
    /* Clear the temporary request secret */
    $session->purge('twitter_request_secret');
    if ($auth_token === false || empty($auth_token)) {
        // We had a request secret, but something went wrong. maybe navigated
        // back here between requests?
        // fall through? Display message? What?....
        //'echo';
        //
    } else {
        /* Successfully obtained an auth token, save it to prefs etc... */
        $prefs->setValue('twitter', serialize(array('key' => $auth_token->key, 'secret' => $auth_token->secret)));
        /* Now try again */
        $twitter->auth->setToken($auth_token);
        try {
            $profile = Horde_Serialize::unserialize($twitter->account->verifyCredentials(), Horde_Serialize::JSON);
        } catch (Horde_Service_Twitter_Exception $e) {
            _outputError($e);
        }
        if (!empty($profile->error)) {
            _outputError($profile->error);
        }
        if (!empty($profile)) {
            $page_output->header();
            echo '<script type="text/javascript">window.opener.location.reload(true);window.close();</script>';
            $page_output->footer();
            exit;
        }
    }
}