Пример #1
0
 /**
  * Executes any code necessary after applying the filter patterns.
  *
  * @param string $text  The text after the filtering.
  *
  * @return string  The modified text.
  */
 public function postProcess($text)
 {
     try {
         $dom = new Horde_Domhtml($text, $this->_params['charset']);
         $text = Horde_String::convertCharset($this->_node($dom->dom, $dom->dom), 'UTF-8', $this->_params['charset']);
         $dom_convert = true;
     } catch (Exception $e) {
         $text = strip_tags(preg_replace("/\\<br\\s*\\/?\\>/i", "\n", $text));
         $dom_convert = false;
     }
     /* Bring down number of empty lines to 2 max, and remove trailing
      * ws. */
     $text = preg_replace(array("/\\s*\n{3,}/", "/ +\n/"), array("\n\n", "\n"), $text);
     /* Wrap the text to a readable format. */
     if ($this->_params['width']) {
         $text = wordwrap($text, $this->_params['width']);
     }
     /* Add link list. */
     if (!empty($this->_linkList)) {
         $text .= "\n\n" . Horde_Text_Filter_Translation::t("Links") . ":\n" . str_repeat('-', Horde_String::length(Horde_Text_Filter_Translation::t("Links")) + 1) . "\n";
         foreach ($this->_linkList as $key => $val) {
             $text .= '[' . ($key + 1) . '] ' . $val . "\n";
         }
     }
     return ltrim(rtrim($text), "\n");
 }
Пример #2
0
 /**
  * Constructor.
  *
  * @param array $vars  Any required parameters.
  */
 public function __construct($vars = array())
 {
     $this->_vars['folder'] = isset($vars['folder']) ? $vars['folder'] : '';
     if (empty($vars['utf8'])) {
         $this->_vars['folder'] = Horde_String::convertCharset($this->_vars['folder'], 'UTF-8', 'UTF7-IMAP');
     }
 }
Пример #3
0
 /**
  */
 public function configSpecialValues($what)
 {
     switch ($what) {
         case 'apps':
             $apps = Horde_Array::valuesToKeys($GLOBALS['registry']->listApps(array('active')));
             asort($apps);
             return $apps;
         case 'languages':
             $convert_numeric = function ($num) {
                 return Horde_String::convertCharset(pack('H*', $num[1]), 'ucs-2', 'UTF-8');
             };
             $convert_symbolic = function ($symbol) {
                 return Horde_String::convertCharset(html_entity_decode($symbol[1], ENT_COMPAT, 'iso-8859-1'), 'iso-8859-1', 'UTF-8');
             };
             return array_map(function ($val) {
                 return preg_replace_callback(array('/&#x([0-9a-f]{4});/i', '/(&[^;]+;)/'), array($convert_numeric, $convert_symbolic), $val);
             }, $GLOBALS['registry']->nlsconfig->languages);
         case 'blocks':
             return $GLOBALS['injector']->getInstance('Horde_Core_Factory_BlockCollection')->create()->getBlocksList();
         case 'mapsources':
             return array('Google' => 'Google', 'Bing' => 'Bing', 'Cloudmade' => 'CloudMade', 'Mytopo' => 'MyTopo', 'Osm' => 'OpenStreetMap', 'Ocm' => 'OpenCycleMap', 'Mapquest' => 'OpenMapquest');
         case 'geocoders':
             return array('None' => null, 'Google' => 'Google');
     }
 }
Пример #4
0
 /**
  * Return the rendered inline version of the Horde_Mime_Part object.
  *
  * @return array  See parent::render().
  */
 protected function _renderInline()
 {
     $text = Horde_String::convertCharset($this->_mimepart->getContents(), $this->_mimepart->getCharset(), 'UTF-8');
     /* Check for 'flowed' text data. */
     $data = $this->_mimepart->getContentTypeParameter('format') == 'flowed' ? $this->_formatFlowed($text, $this->_mimepart->getContentTypeParameter('delsp')) : $text;
     return $this->_renderReturn($data, 'text/html; charset=UTF-8');
 }
Пример #5
0
 public function testBug9992()
 {
     $text = base64_decode('dGVzdDogtbno6bvtu+nt/eHpu7797Txicj4K');
     $expected = '<p>test: ľščéťíťéíýáéťžýí<br/></p>';
     $dom = new Horde_Domhtml($text, 'iso-8859-2');
     $this->assertEquals(Horde_String::convertCharset($expected, 'UTF-8', 'iso-8859-2'), strtr(trim($dom->returnBody()), array("\n" => '')));
     $this->assertEquals('UTF-8', $dom->getCharset());
 }
Пример #6
0
 public function testBug9567()
 {
     $text = quoted_printable_decode("pr=E9parer =E0 vendre d’ao=FBt");
     $this->assertEquals($text, Horde_Text_Filter::filter('<html><body>' . $text . '</body></html>', 'xss', array('charset' => 'iso-8859-1')));
     $this->assertEquals($text, Horde_Text_Filter::filter('<html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head><body>' . $text . '</body></html>', 'xss', array('charset' => 'iso-8859-1')));
     $text = Horde_String::convertCharset(quoted_printable_decode("pr=E9parer =E0 vendre d&#8217;ao=FBt&nbsp;;"), 'windows-1252', 'UTF-8');
     $expected = "préparer à vendre d’août ;";
     $this->assertEquals($expected, Horde_Text_Filter::filter('<html><body>' . $text . '</body></html>', 'xss', array('charset' => 'utf-8')));
 }
Пример #7
0
 /**
  * Save bookmark.
  */
 public function save($crawl = true)
 {
     if (!strlen($this->url)) {
         throw new Trean_Exception('Incomplete bookmark');
     }
     $charset = $GLOBALS['trean_db']->getOption('charset');
     $c_url = Horde_String::convertCharset($this->url, 'UTF-8', $charset);
     $c_title = Horde_String::convertCharset($this->title, 'UTF-8', $charset);
     $c_description = Horde_String::convertCharset($this->description, 'UTF-8', $charset);
     $c_favicon_url = Horde_String::convertCharset($this->favicon_url, 'UTF-8', $charset);
     if ($this->id) {
         // Update an existing bookmark.
         $GLOBALS['trean_db']->update('
             UPDATE trean_bookmarks
             SET user_id = ?,
                 bookmark_url = ?,
                 bookmark_title = ?,
                 bookmark_description = ?,
                 bookmark_clicks = ?,
                 bookmark_http_status = ?,
                 favicon_url = ?
             WHERE bookmark_id = ?', array($this->userId, $c_url, $c_title, $c_description, $this->clicks, $this->http_status, $c_favicon_url, $this->id));
         $GLOBALS['injector']->getInstance('Trean_Tagger')->replaceTags((string) $this->id, $this->tags, $GLOBALS['registry']->getAuth(), 'bookmark');
     } else {
         // Saving a new bookmark.
         $bookmark_id = $GLOBALS['trean_db']->insert('
             INSERT INTO trean_bookmarks (
                 user_id,
                 bookmark_url,
                 bookmark_title,
                 bookmark_description,
                 bookmark_clicks,
                 bookmark_http_status,
                 favicon_url,
                 bookmark_dt
             ) VALUES (?, ?, ?, ?, ?, ?, ?, ?)', array($this->userId, $c_url, $c_title, $c_description, $this->clicks, $this->http_status, $c_favicon_url, $this->dt));
         $this->id = (int) $bookmark_id;
         $GLOBALS['injector']->getInstance('Trean_Tagger')->tag((string) $this->id, $this->tags, $GLOBALS['registry']->getAuth(), 'bookmark');
     }
     if ($crawl) {
         try {
             $queue = $GLOBALS['injector']->getInstance('Horde_Queue_Storage');
             $queue->add(new Trean_Queue_Task_Crawl($this->url, $this->title, $this->description, $this->id, $this->userId));
         } catch (Exception $e) {
             Horde::log($e, 'INFO');
         }
     }
     return $this->id;
 }
Пример #8
0
 /**
  * Return the rendered inline version of the Horde_Mime_Part object.
  *
  * @return array  See parent::render().
  */
 protected function _renderInline()
 {
     /* Determine the language and brush from the mime type. */
     $mimeType = $this->_mimepart->getType();
     $language = $this->_mimeTypeToLanguage($mimeType);
     $brush = $this->_languageToBrush($language);
     $page_output = $GLOBALS['injector']->getInstance('Horde_PageOutput');
     if (!self::$_shLoaded) {
         $page_output->addScriptFile('syntaxhighlighter/scripts/syntaxhighlighter.js', 'horde');
         self::$_shLoaded = true;
         $sh_js_fs = $this->getConfigParam('registry')->get('jsfs', 'horde') . '/syntaxhighlighter/styles/';
         $sh_js_uri = Horde::url($this->getConfigParam('registry')->get('jsuri', 'horde'), false, -1) . '/syntaxhighlighter/styles/';
         $page_output->addStylesheet($sh_js_fs . 'theme.css', $sh_js_uri . 'theme.css');
     }
     $results = '<pre class="brush: ' . $language . '; toolbar: false;">' . htmlspecialchars(Horde_String::convertCharset($this->_mimepart->getContents(), $this->_mimepart->getCharset(), $this->getConfigParam('charset')), ENT_QUOTES, $this->getConfigParam('charset')) . '</pre>';
     return $this->_renderReturn($results, 'text/html; charset=' . $this->getConfigParam('charset'));
 }
Пример #9
0
 /**
  * Actually carry out the action.
  *
  * @return boolean  True on success.
  * @throws Ulaform_Exception
  */
 public function doAction($form_params, $form_data, $fields)
 {
     /* Check if table exists. */
     if (!in_array($form_params['table'], $this->_db->tables())) {
         try {
             $this->_createDataTable($form_params, $fields);
         } catch (Horde_Db_Exception $e) {
             throw new Ulaform_Exception($e->getMessage());
         }
     }
     /* Submit data to database. */
     $columns = array();
     $values = array();
     foreach ($fields as $field) {
         switch ($field['field_type']) {
             case 'file':
             case 'image':
                 if (count($form_data[$field['field_name']])) {
                     $data = file_get_contents($form_data[$field['field_name']]['file']);
                     if (Horde_String::lower($this->_db->adapterName()) == 'pgsql') {
                         $data = bin2hex($data);
                     }
                     $columns[] = $field['field_name'];
                     $values[] = $data;
                 }
                 break;
             case 'set':
                 $columns[] = $field['field_name'];
                 $values[] = implode(', ', $form_data[$field['field_name']]);
                 break;
             default:
                 $data = $form_data[$field['field_name']];
                 $columns[] = $field['field_name'];
                 $values[] = Horde_String::convertCharset($data, 'UTF-8', $this->_charset);
                 break;
         }
     }
     $sql = sprintf('INSERT INTO %s (%s) VALUES (%s)', $form_params['table'], implode(', ', $columns), str_repeat('?, ', count($values) - 1) . '?');
     try {
         $this->_db->insert($sql, $values);
     } catch (Horde_Db_Exception $e) {
         throw new Ulaform_Exception($e->getMessage());
     }
     return true;
 }
Пример #10
0
 /**
  * Executes any code necessary after applying the filter patterns.
  *
  * @param string $text  The text after the filtering.
  *
  * @return string  The modified text.
  */
 public function postProcess($text)
 {
     if (!Horde_Util::extensionExists('tidy') || $this->_params['size'] !== false && strlen($text) > $this->_params['size']) {
         return $text;
     }
     $tidy_config = array('enclose-block-text' => true, 'hide-comments' => true, 'indent' => false, 'numeric-entities' => true, 'preserve-entities' => true, 'show-body-only' => !empty($this->_params['body_only']), 'tab-size' => 0, 'wrap' => 0);
     $tidy = new tidy();
     if (strtolower($this->_params['charset']) == 'us-ascii') {
         if ($tidy->parseString($text, $tidy_config, 'ascii')) {
             $tidy->cleanRepair();
             $text = $tidy->value;
         }
     } elseif ($tidy->parseString(Horde_String::convertCharset($text, $this->_params['charset'], 'UTF-8'), $tidy_config, 'utf8')) {
         $tidy->cleanRepair();
         $text = Horde_String::convertCharset($tidy->value, 'UTF-8', $this->_params['charset']);
     }
     return $text;
 }
Пример #11
0
 /**
  * Sets the charset of the search text.
  *
  * @param string $charset   The charset to use for the search.
  * @param boolean $convert  Convert existing text values?
  *
  * @throws Horde_Imap_Client_Exception_SearchCharset
  */
 public function charset($charset, $convert = true)
 {
     $oldcharset = $this->_charset;
     $this->_charset = strtoupper($charset);
     if (!$convert || $oldcharset == $this->_charset) {
         return;
     }
     foreach (array('header', 'text') as $item) {
         if (isset($this->_search[$item])) {
             foreach ($this->_search[$item] as $key => $val) {
                 $new_val = Horde_String::convertCharset($val['text'], $oldcharset, $this->_charset);
                 if (Horde_String::convertCharset($new_val, $this->_charset, $oldcharset) != $val['text']) {
                     throw new Horde_Imap_Client_Exception_SearchCharset($this->_charset);
                 }
                 $this->_search[$item][$key]['text'] = $new_val;
             }
         }
     }
 }
Пример #12
0
 /**
  * Parse the requested folder for the owner of that folder.
  *
  * @param string $req_folder The folder requested.
  *
  * @return boolean|PEAR_Error True if successful.
  */
 protected function handleCalleePart($callee_part)
 {
     /* Handle the owner/folder name and make sure the owner part is in lower case */
     $req_folder = Horde_String::convertCharset($req_folder, 'UTF-8', 'UTF7-IMAP');
     $folder = explode('/', $req_folder);
     if (count($folder) < 2) {
         return PEAR::raiseError(sprintf(Horde_Kolab_FreeBusy_Translation::t("No such folder %s"), $req_folder));
     }
     $folder[0] = Horde_String::lower($folder[0]);
     $req_folder = implode('/', $folder);
     $this->owner = $folder[0];
     unset($folder[0]);
     $this->folder = join('/', $folder);
     $result = $this->_process();
     if (is_a($result, 'PEAR_Error')) {
         return $result;
     }
     return true;
 }
Пример #13
0
    public function testBug10431()
    {
        $text = 'Das könnte zum Beispiel so aussehen, dass wir bei entsprechenden Anfragen diese an eine Kontaktperson bei Euch weiterleiten. Oder Ihr schnürt ein entsprechendes Paket, dass wir in unseren Angeboten mit anführen. Bei erfolgreicher Vermittlung bekämen wir eine Vermittlungsgebühr.
Wir ständen dann weiterhin für 3rd-Level-Support zur Verfügung, d.h. für alle Anfragen des Kunden bzgl. Horde, die nicht zum Tagesgeschäft gehören.';
        $text = Horde_String::convertCharset($text, 'UTF-8', 'ISO-8859-1');
        $textBody = new Horde_Mime_Part();
        $textBody->setType('text/plain');
        $textBody->setCharset('ISO-8859-1');
        $flowed = new Horde_Text_Flowed($text, 'ISO-8859-1');
        $flowed->setDelSp(true);
        $textBody->setContents($flowed->toFlowed());
        $flowed_txt = $textBody->toString(array('headers' => false));
        $textBody2 = new Horde_Mime_Part();
        $textBody2->setType('text/plain');
        $textBody2->setCharset('ISO-8859-1');
        $textBody2->setContents($flowed_txt, array('encoding' => 'quoted-printable'));
        $flowed2 = new Horde_Text_Flowed($textBody2->getContents(), 'ISO-8859-1');
        $flowed2->setMaxLength(0);
        $flowed2->setDelSp(true);
        $this->assertEquals($text, trim($flowed2->toFixed()));
    }
Пример #14
0
 /**
  * Retrieve Free/Busy data for the specified resource.
  *
  * @param string $resource Fetch the Free/Busy data for this resource.
  *
  * @return Horde_Icalendar_Vfreebusy The Free/Busy data.
  */
 public function get($resource)
 {
     global $conf;
     $url = self::getUrl($resource);
     Horde::log(sprintf('Freebusy URL for resource %s is %s', $resource, $url), 'DEBUG');
     list($user, $domain) = explode('@', $resource);
     if (empty($domain)) {
         $domain = $conf['kolab']['filter']['email_domain'];
     }
     /**
      * This section matches Kronolith_Freebusy and should be merged with it
      * again in a single Horde_Freebusy module.
      */
     $options = array('method' => 'GET', 'timeout' => 5, 'allowRedirects' => true);
     if (!empty($conf['http']['proxy']['proxy_host'])) {
         $options = array_merge($options, $conf['http']['proxy']);
     }
     $http = new HTTP_Request($url, $options);
     $http->setBasicAuth($conf['kolab']['filter']['calendar_id'] . '@' . $domain, $conf['kolab']['filter']['calendar_pass']);
     @$http->sendRequest();
     if ($http->getResponseCode() != 200) {
         throw new Horde_Kolab_Resource_Exception(sprintf('Unable to retrieve free/busy information for %s', $resource), Horde_Kolab_Resource_Exception::NO_FREEBUSY);
     }
     $vfb_text = $http->getResponseBody();
     // Detect the charset of the iCalendar data.
     $contentType = $http->getResponseHeader('Content-Type');
     if ($contentType && strpos($contentType, ';') !== false) {
         list(, $charset, ) = explode(';', $contentType);
         $vfb_text = Horde_String::convertCharset($vfb_text, trim(str_replace('charset=', '', $charset)), 'UTF-8');
     }
     $iCal = new Horde_Icalendar();
     $iCal->parsevCalendar($vfb_text, 'VCALENDAR');
     $vfb =& $iCal->findComponent('VFREEBUSY');
     if ($vfb === false) {
         throw new Horde_Kolab_Resource_Exception(sprintf('Invalid or no free/busy information available for %s', $resource), Horde_Kolab_Resource_Exception::NO_FREEBUSY);
     }
     $vfb->simplify();
     return $vfb;
 }
Пример #15
0
 /**
  * Copy/move messages.
  *
  * @param string $mbox          The mailbox name to copy/move the task to.
  * @param IMP_Indices $indices  An indices object.
  * @param boolean $move         Move if true, copy if false.
  *
  * @return boolean  True on success.
  */
 public function copy($mbox, IMP_Indices $indices, $move)
 {
     global $injector;
     $success = true;
     foreach ($indices as $ob) {
         foreach ($ob->uids as $uid) {
             /* Fetch the message contents. */
             $imp_contents = $injector->getInstance('IMP_Factory_Contents')->create($ob->mbox->getIndicesOb($uid));
             /* Fetch the message headers. */
             $subject = strval($imp_contents->getHeader()->getHeader('Subject'));
             /* Re-flow the message for prettier formatting. */
             $body_part = $imp_contents->getMimePart($imp_contents->findBody());
             if (!$body_part) {
                 $success = false;
                 continue;
             }
             $flowed = new Horde_Text_Flowed($body_part->getContents());
             if ($body_part->getContentTypeParameter('delsp') == 'yes') {
                 $flowed->setDelSp(true);
             }
             $body = $flowed->toFlowed(false);
             /* Convert to current charset */
             /* TODO: When Horde_Icalendar supports setting of charsets
              * we need to set it there instead of relying on the fact
              * that both Nag and IMP use the same charset. */
             $body = Horde_String::convertCharset($body, $body_part->getCharset(), 'UTF-8');
             if (!$this->_create($mbox, $subject, $body)) {
                 $success = false;
             }
         }
     }
     /* Delete the original messages if this is a "move" operation. */
     if ($move) {
         $indices->delete();
     }
     return $success;
 }
Пример #16
0
 /**
  * Upgrades the given preferences from the old H3 way of storing
  * serialized data.
  * OLD method: convert charset, serialize, store.
  * NEW method: serialize, convert charset, store.
  *
  * @param Horde_Prefs $prefs_ob  The preferences object.
  * @param array $names           The list of names to upgrade.
  */
 public function upgradeSerialized($prefs_ob, array $names)
 {
     /* Only do upgrade for SQL driver. */
     foreach ($prefs_ob->getStorage() as $storage) {
         if ($storage instanceof Horde_Prefs_Storage_Sql) {
             break;
         }
     }
     if (!$storage instanceof Horde_Prefs_Storage_Sql) {
         return;
     }
     /* Only do upgrade if charset is not UTF-8. */
     $charset = $storage->getCharset();
     if (strcasecmp($charset, 'UTF-8') === 0) {
         return;
     }
     foreach ($names as $name) {
         if (!$prefs_ob->isDefault($name)) {
             $data = $prefs_ob->getValue($name);
             /* Need to convert only if unserialize fails. If it succeeds,
              * the data has already been converted or there is no need
              * to convert. */
             if (@unserialize($data) === false) {
                 /* Re-convert to original charset. */
                 $data = Horde_String::convertCharset($data, 'UTF-8', $charset);
                 /* Unserialize. If we fail here, remove the value
                  * outright since it is invalid and can not be fixed. */
                 if (($data = @unserialize($data)) !== false) {
                     $data = Horde_String::convertCharset($data, $charset, 'UTF-8');
                     /* Re-save in the prefs backend in the new format. */
                     $prefs_ob->setValue($name, serialize($data));
                 }
             }
         }
     }
 }
 /**
  * Upgrade.
  */
 public function up()
 {
     // shares ng
     $this->addColumn('kronolith_sharesng', 'attribute_email', 'text');
     $this->addColumn('kronolith_sharesng', 'attribute_members', 'text');
     $this->addColumn('kronolith_sharesng', 'attribute_response_type', 'integer');
     $this->addColumn('kronolith_sharesng', 'attribute_type', 'integer', array('default' => Kronolith::SHARE_TYPE_USER));
     $this->addColumn('kronolith_sharesng', 'attribute_isgroup', 'integer', array('default' => 0));
     // legacy shares
     $this->addColumn('kronolith_shares', 'attribute_email', 'text');
     $this->addColumn('kronolith_shares', 'attribute_members', 'text');
     $this->addColumn('kronolith_shares', 'attribute_response_type', 'integer');
     $this->addColumn('kronolith_shares', 'attribute_type', 'integer', array('default' => Kronolith::SHARE_TYPE_USER));
     $this->addColumn('kronolith_shares', 'attribute_isgroup', 'integer', array('default' => 0));
     /** Migrate existing resources to shares */
     $columns = $this->_connection->columns('kronolith_resources');
     /** Try to get existing data charset **/
     $config = Horde::getDriverConfig('resource', 'sql');
     $charset = empty($config['charset']) ? 'utf-8' : $config['charset'];
     $rows = $this->_connection->select('SELECT * FROM kronolith_resources');
     $shares = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Share')->create('kronolith');
     foreach ($rows as $row) {
         $share = $shares->newShare(null, $row['resource_calendar'], Horde_String::convertCharset($row['resource_name'], $charset, 'utf-8'));
         $share->set('desc', $columns['resource_description']->binaryToString($row['resource_description']));
         $share->set('email', $row['resource_email']);
         $share->set('response_type', $row['resource_response_type']);
         $share->set('calendar_type', Kronolith::SHARE_TYPE_RESOURCE);
         $share->set('isgroup', $row['resource_type'] == 'Group');
         $share->set('members', $columns['resource_members']->binaryToString($row['resource_members']));
         /* Perms to match existing behavior */
         $share->addDefaultPermission(Horde_Perms::SHOW);
         $share->addDefaultPermission(Horde_Perms::READ);
         $share->addDefaultPermission(Horde_Perms::EDIT);
         $share->save();
     }
 }
Пример #18
0
 /**
  * Converts the text fields of a story from the backend charset to the
  * output charset.
  *
  * @param array $story  A story hash.
  *
  * @return array  The converted hash.
  */
 protected function _convertFromBackend($story)
 {
     $story['title'] = Horde_String::convertCharset($story['title'], $this->_params['charset'], 'UTF-8');
     $story['description'] = Horde_String::convertCharset($story['description'], $this->_params['charset'], 'UTF-8');
     if (isset($story['body'])) {
         $story['body'] = Horde_String::convertCharset($story['body'], $this->_params['charset'], 'UTF-8');
     }
     if (isset($story['tags'])) {
         $story['tags'] = Horde_String::convertCharset($story['tags'], $this->_params['charset'], 'UTF-8');
     }
     return $story;
 }
Пример #19
0
    public function testPgpSign()
    {
        $clear = $this->_getFixture('clear.txt');
        $out = $this->_pgp->encrypt($clear, array('passphrase' => 'Secret', 'privkey' => $this->_getPrivateKey(), 'pubkey' => $this->_getPublicKey(), 'type' => 'signature'));
        $this->assertStringMatchesFormat('-----BEGIN PGP SIGNATURE-----
Version: GnuPG %s

%s
%s
=%s
-----END PGP SIGNATURE-----', $out);
        $out = $this->_pgp->encrypt($clear, array('passphrase' => 'Secret', 'privkey' => $this->_getPrivateKey(), 'pubkey' => $this->_getPublicKey(), 'sigtype' => 'cleartext', 'type' => 'signature'));
        $this->assertStringMatchesFormat('-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

0123456789012345678901234567890123456789
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
0123456789012345678901234567890123456789
!"$§%&()=?^´°`+#-.,*\'_:;<>|~\\{[]}
-----BEGIN PGP SIGNATURE-----
Version: GnuPG %s

%s
%s
=%s
-----END PGP SIGNATURE-----', Horde_String::convertCharset($out, 'ISO-8859-1', 'UTF-8'));
    }
Пример #20
0
 /**
  * Return the rendered inline version of the Horde_Mime_Part object.
  *
  * @return array  See parent::render().
  */
 protected function _renderInline()
 {
     return $this->_renderReturn(Horde_String::convertCharset($this->_toHTML(), $this->_mimepart->getCharset(), 'UTF-8'), 'text/html; charset=UTF-8');
 }
Пример #21
0
 /**
  * Takes all necessary actions for the given import step, parameters and
  * form values and returns the next necessary step.
  *
  * @param integer $action  The current step. One of the IMPORT_* constants.
  * @param array $param     An associative array containing needed
  *                         parameters for the current step. Keys for this
  *                         driver:
  *   - check_charset: (boolean) Do some checks to see if the correct
  *                    charset has been provided. Throws charset exception
  *                    on error.
  *   - import_mapping: TODO
  *
  * @return mixed  Either the next step as an integer constant or imported
  *                data set after the final step.
  * @throws Horde_Data_Exception
  * @throws Horde_Data_Exception_Charset
  */
 public function nextStep($action, array $param = array())
 {
     switch ($action) {
         case Horde_Data::IMPORT_FILE:
             parent::nextStep($action, $param);
             /* Move uploaded file so that we can read it again in the next
                step after the user gave some format details. */
             $file_name = $_FILES['import_file']['tmp_name'];
             if (($file_data = file_get_contents($file_name)) === false) {
                 throw new Horde_Data_Exception(Horde_Data_Translation::t("The uploaded file could not be saved."));
             }
             /* Do charset checking now, if requested. */
             if (isset($param['check_charset'])) {
                 $charset = isset($this->_vars->charset) ? Horde_String::lower($this->_vars->charset) : 'utf-8';
                 switch ($charset) {
                     case 'utf-8':
                         $error = !Horde_String::validUtf8($file_data);
                         break;
                     default:
                         $error = $file_data != Horde_String::convertCharset(Horde_String::convertCharset($file_data, $charset, 'UTF-8'), 'UTF-8', $charset);
                         break;
                 }
                 if ($error) {
                     $e = new Horde_Data_Exception_Charset(Horde_Data_Translation::t("Incorrect charset given for the data."));
                     $e->badCharset = $charset;
                     throw $e;
                 }
             }
             $this->storage->set('charset', $this->_vars->charset);
             $this->storage->set('file_data', $file_data);
             /* Read the file's first two lines to show them to the user. */
             $first_lines = '';
             if ($fp = @fopen($file_name, 'r')) {
                 for ($line_no = 1, $line = fgets($fp); $line_no <= 3 && $line; $line_no++, $line = fgets($fp)) {
                     $line = Horde_String::convertCharset($line, $this->_vars->charset, 'UTF-8');
                     $first_lines .= Horde_String::truncate($line);
                     if (Horde_String::length($line) > 100) {
                         $first_lines .= "\n";
                     }
                 }
             }
             $this->storage->set('first_lines', $first_lines);
             /* Import the first line to guess the number of fields. */
             if ($first_lines) {
                 rewind($fp);
                 $line = self::getCsv($fp);
                 if ($line) {
                     $this->storage->set('fields', count($line));
                 }
             }
             return Horde_Data::IMPORT_CSV;
         case Horde_Data::IMPORT_CSV:
             $this->storage->set('header', $this->_vars->header);
             $import_mapping = array();
             if (isset($param['import_mapping'])) {
                 $import_mapping = $param['import_mapping'];
             }
             $file_name = Horde_Util::getTempFile('import');
             file_put_contents($file_name, $this->storage->get('file_data'));
             $this->storage->set('data', $this->importFile($file_name, $this->_vars->header, $this->_vars->sep, $this->_vars->quote, $this->_vars->fields, $import_mapping, $this->storage->get('charset'), $this->storage->get('crlf')));
             $this->storage->set('map');
             return Horde_Data::IMPORT_MAPPED;
         default:
             return parent::nextStep($action, $param);
     }
 }
Пример #22
0
 /**
  * Stores the specified data in the storage backend.
  *
  * @access private
  *
  * @param Ingo_Storage_Rule|Ingo_Storage_Filters $ob  The object to store.
  */
 protected function _store($ob)
 {
     switch ($ob->obType()) {
         case self::ACTION_BLACKLIST:
         case self::ACTION_WHITELIST:
             $is_blacklist = (int) ($ob->obType() == self::ACTION_BLACKLIST);
             if ($is_blacklist) {
                 $filters = $this->retrieve(self::ACTION_FILTERS);
                 $id = $filters->findRuleId(self::ACTION_BLACKLIST);
                 if ($id !== null) {
                     $rule = $filters->getRule($id);
                     if (!isset($rule['action-value']) || $rule['action-value'] != $ob->getBlacklistFolder()) {
                         $rule['action-value'] = $ob->getBlacklistFolder();
                         $filters->updateRule($rule, $id);
                     }
                 }
             }
             $query = sprintf('DELETE FROM %s WHERE list_owner = ? AND list_blacklist = ?', $this->_params['table_lists']);
             $values = array(Ingo::getUser(), $is_blacklist);
             try {
                 $this->_params['db']->delete($query, $values);
             } catch (Horde_Db_Exception $e) {
                 Horde::log($e, 'ERR');
                 throw new Ingo_Exception($e);
             }
             $query = sprintf('INSERT INTO %s (list_owner, list_blacklist, list_address) VALUES (?, ?, ?)', $this->_params['table_lists']);
             $addresses = $is_blacklist ? $ob->getBlacklist() : $ob->getWhitelist();
             foreach ($addresses as $address) {
                 try {
                     $result = $this->_params['db']->insert($query, array(Ingo::getUser(), $is_blacklist, $address));
                 } catch (Horde_Db_Exception $e) {
                     Horde::log($result, 'ERR');
                     throw new Ingo_Exception($e);
                 }
             }
             $ob->setSaved(true);
             break;
         case self::ACTION_FORWARD:
             $values = array(implode("\n", $ob->getForwardAddresses()), (int) (bool) $ob->getForwardKeep(), Ingo::getUser());
             try {
                 if ($ob->isSaved()) {
                     $query = sprintf('UPDATE %s SET forward_addresses = ?, forward_keep = ? WHERE forward_owner = ?', $this->_params['table_forwards']);
                     $this->_params['db']->update($query, $values);
                 } else {
                     $query = sprintf('INSERT INTO %s (forward_addresses, forward_keep, forward_owner) VALUES (?, ?, ?)', $this->_params['table_forwards']);
                     $this->_params['db']->insert($query, $values);
                 }
             } catch (Horde_Db_Exception $e) {
                 throw new Ingo_Exception($e);
             }
             $ob->setSaved(true);
             break;
         case self::ACTION_VACATION:
             $values = array(implode("\n", $ob->getVacationAddresses()), Horde_String::convertCharset($ob->getVacationSubject(), 'UTF-8', $this->_params['charset']), Horde_String::convertCharset($ob->getVacationReason(), 'UTF-8', $this->_params['charset']), (int) $ob->getVacationDays(), (int) $ob->getVacationStart(), (int) $ob->getVacationEnd(), implode("\n", $ob->getVacationExcludes()), (int) (bool) $ob->getVacationIgnorelist(), Ingo::getUser());
             try {
                 if ($ob->isSaved()) {
                     $query = sprintf('UPDATE %s SET vacation_addresses = ?, vacation_subject = ?, vacation_reason = ?, vacation_days = ?, vacation_start = ?, vacation_end = ?, vacation_excludes = ?, vacation_ignorelists = ? WHERE vacation_owner = ?', $this->_params['table_vacations']);
                     $this->_params['db']->update($query, $values);
                 } else {
                     $query = sprintf('INSERT INTO %s (vacation_addresses, vacation_subject, vacation_reason, vacation_days, vacation_start, vacation_end, vacation_excludes, vacation_ignorelists, vacation_owner) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)', $this->_params['table_vacations']);
                     $this->_params['db']->insert($query, $values);
                 }
             } catch (Horde_Db_Exception $e) {
                 throw new Ingo_Exception($e);
             }
             $ob->setSaved(true);
             break;
         case self::ACTION_SPAM:
             $values = array((int) $ob->getSpamLevel(), $ob->getSpamFolder(), Ingo::getUser());
             try {
                 if ($ob->isSaved()) {
                     $query = sprintf('UPDATE %s SET spam_level = ?, spam_folder = ? WHERE spam_owner = ?', $this->_params['table_spam']);
                     $this->_params['db']->update($query, $values);
                 } else {
                     $query = sprintf('INSERT INTO %s (spam_level, spam_folder, spam_owner) VALUES (?, ?, ?)', $this->_params['table_spam']);
                     $this->_params['db']->insert($query, $values);
                 }
             } catch (Horde_Db_Exception $e) {
                 throw new Ingo_Exception($e);
             }
             $ob->setSaved(true);
             break;
     }
 }
Пример #23
0
 /**
  * Perform sanity checking on a raw header (e.g. handle 8-bit characters).
  *
  * @param string $data  The header data.
  *
  * @return string  The cleaned header data.
  */
 protected function _sanityCheck($data)
 {
     $charset_test = array('windows-1252', self::$defaultCharset);
     if (!Horde_String::validUtf8($data)) {
         /* Appears to be a PHP error with the internal String structure
          * which prevents accurate manipulation of the string. Copying
          * the data to a new variable fixes things. */
         $data = substr($data, 0);
         /* Assumption: broken charset in headers is generally either
          * UTF-8 or ISO-8859-1/Windows-1252. Test these charsets
          * first before using default charset. This may be a
          * Western-centric approach, but it's better than nothing. */
         foreach ($charset_test as $charset) {
             $tmp = Horde_String::convertCharset($data, $charset, 'UTF-8');
             if (Horde_String::validUtf8($tmp)) {
                 return $tmp;
             }
         }
     }
     return $data;
 }
Пример #24
0
 protected function _fromBackend($value)
 {
     return Horde_String::convertCharset($value, $this->_db->getOption('charset'), 'UTF-8');
 }
Пример #25
0
 /**
  * Converts a value from the default charset to the driver's charset.
  *
  * @param mixed $value  A value to convert.
  *
  * @return mixed  The converted value.
  */
 public function convertToDriver($value)
 {
     return Horde_String::convertCharset($value, 'UTF-8', $this->_charset);
 }
Пример #26
0
 /**
  * Returns a list of Ansel_Images of the most recently added images for the
  * current user.
  *
  * @param array $galleries  An array of gallery ids to search in. If
  *                          left empty, will search all galleries
  *                          with Horde_Perms::SHOW.
  * @param integer $limit    The maximum number of images to return
  * @param string $slugs     An array of gallery slugs.
  * @param string $where     Additional where clause
  *
  * @return array An array of Ansel_Image objects
  * @throws Ansel_Exception
  */
 public function getRecentImages(array $galleries = array(), $limit = 10, array $slugs = array())
 {
     $results = array();
     if (!count($galleries) && !count($slugs)) {
         // Don't need the Ansel_Gallery object, so save some resources and
         // only query the share system.
         foreach ($this->_shares->listShares($GLOBALS['registry']->getAuth()) as $share) {
             $galleries[] = $share->getId();
         }
         if (empty($galleries)) {
             return array();
         }
     }
     if (!count($slugs)) {
         // Searching by gallery_id
         $sql = 'SELECT ' . $this->_getImageFields() . ' FROM ansel_images ' . 'WHERE gallery_id IN (' . str_repeat('?, ', count($galleries) - 1) . '?) ';
         $criteria = $galleries;
     } elseif (count($slugs)) {
         // Searching by gallery_slug so we need to join the share table
         $sql = 'SELECT ' . $this->_getImageFields() . ' FROM ansel_images LEFT JOIN ' . $this->_shares->getTable() . ' ON ansel_images.gallery_id = ' . $this->_shares->getTable() . '.share_id ' . 'WHERE attribute_slug IN (' . str_repeat('?, ', count($slugs) - 1) . '?) ';
         $criteria = $slugs;
     }
     $sql .= ' ORDER BY image_uploaded_date DESC';
     if ($limit > 0) {
         $sql = $this->_db->addLimitOffset($sql, array('limit' => (int) $limit));
     }
     try {
         $images = $this->_db->selectAll($sql, $criteria);
     } catch (Horde_Db_Exception $e) {
         throw new Ansel_Exception($e);
     }
     foreach ($images as $image) {
         $image['image_filename'] = Horde_String::convertCharset($image['image_filename'], $GLOBALS['conf']['sql']['charset'], 'UTF-8');
         $image['image_caption'] = Horde_String::convertCharset($image['image_caption'], $GLOBALS['conf']['sql']['charset'], 'UTF-8');
         $results[] = new Ansel_Image($image);
     }
     return $results;
 }
Пример #27
0
 /**
  * Format and encode attributes including postal addresses,
  * character set encoding, etc.
  *
  * @param array $attributes  The attributes array.
  */
 protected function _encodeAttributes(&$attributes)
 {
     foreach ($attributes as $key => $val) {
         /* If schema checking is enabled check the backend syntax. */
         if (!empty($this->_params['checksyntax'])) {
             $postal = $this->_isPostalAddress($key);
         } else {
             /* Otherwise rely on the attribute mapping in
              * attributes.php. */
             $attr = array_search($key, $this->map);
             $postal = !empty($attr) && !empty($val) && !empty($GLOBALS['attributes'][$attr]) && $GLOBALS['attributes'][$attr]['type'] == 'address';
         }
         if ($postal) {
             /* Correctly store postal addresses. */
             $val = str_replace(array("\r\n", "\r", "\n"), '$', $val);
         }
         if (!is_array($val)) {
             $attributes[$key] = Horde_String::convertCharset($val, 'UTF-8', $this->_params['charset']);
         }
     }
 }
Пример #28
0
 /**
  * Utility function to convert TO the SQL server's charset.
  *
  * @see Horde_Share#toDriverCharset
  */
 public function toDriverCharset($data)
 {
     if (!is_array($data)) {
         return $data;
     }
     foreach ($data as $key => &$value) {
         if (substr($key, 0, 9) == 'attribute') {
             $value = Horde_String::convertCharset($value, 'UTF-8', $this->_db->getOption('charset'));
         }
     }
     return $data;
 }
Пример #29
0
 /**
  * Output to use if text size is over the limit.
  * See IMP_Contents::renderMIMEPart().
  *
  * @return string  The text to display inline.
  */
 public function overLimitText()
 {
     $stream = $this->_mimepart->getContents(array('stream' => true));
     rewind($stream);
     // Escape text
     $filters = array('text2html' => array('parselevel' => Horde_Text_Filter_Text2html::MICRO), 'tabs2spaces' => array());
     return '<div class="fixed">' . $this->_textFilter(Horde_String::convertCharset(fread($stream, 1024), $this->_mimepart->getCharset(), 'UTF-8'), array_keys($filters), array_values($filters)) . ' [...]</div>';
 }
Пример #30
0
 /**
  * Converts a value from the default charset to the driver's charset.
  *
  * @param mixed $value  A value to convert.
  *
  * @return mixed  The converted value.
  */
 protected function _convertToDriver($value)
 {
     return Horde_String::convertCharset($value, 'UTF-8', $this->_db->getOption('charset'));
 }