See the list of constants at the top of the file for the serializing
techniques that can be used.
public static unserialize ( mixed $data, mixed $mode = self::BASIC, mixed $params = null ) : string | ||
$data | mixed | The data to be unserialized. |
$mode | mixed | The mode of unserialization. Can be either a single mode or array of modes. If array, will be unserialized in the order provided. |
$params | mixed | Any additional parameters the unserialization method requires. |
리턴 | string | The unserialized data. |
/** * 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; } }
/** * Search for a user's free/busy information. * * @param string $email The email address to lookup * @param boolean $private_only (optional) Only return free/busy * information owned by this used. * * @return Horde_Icalendar_Vfreebusy * @throws Kronolith_Exception */ public function search($email, $private_only = false) { /* Build the SQL query. */ $query = sprintf('SELECT vfb_serialized FROM %s WHERE vfb_email = ? AND (vfb_owner = ?', $this->_params['table']); $values = array($email, $this->_user); if ($private_only) { $query .= ')'; } else { $query .= " OR vfb_owner = '')"; } /* Execute the query. */ try { $result = $this->_db->selectValue($query, $values); if (empty($result)) { throw new Horde_Exception_NotFound(); } return Horde_Serialize::unserialize($result, Horde_Serialize::BASIC); } catch (Horde_Db_Exception $e) { throw new Kronolith_Exception($e); } }
/** * 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; }
/** */ 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'); }
#!/usr/bin/env php <?php /** * Simple Twitter client. * * Copyright 2009-2015 Horde LLC (http://www.horde.org/) * * @author Jan Schneider <*****@*****.**> * @author Michael J. Rubinsky <*****@*****.**> * @license http://www.horde.org/licenses/bsd BSD * @category Horde * @package Service_Twitter */ /* Keys - these are obtained when registering for the service */ $keys = array('consumer_key' => '*****', 'consumer_secret' => '*****', 'access_token' => '*****-*****', 'access_token_secret' => '*****'); /* Enable autoloading. */ require 'Horde/Autoloader/Default.php'; /* Create the Twitter client */ $twitter = Horde_Service_Twitter::create(array('oauth' => $keys)); /* Do something cool.... */ try { $result = $twitter->statuses->update('Testing Horde/Twitter integration 2'); print_r(Horde_Serialize::unserialize($result, Horde_Serialize::JSON)); } catch (Horde_Service_Twitter_Exception $e) { $error = Horde_Serialize::unserialize($e->getMessage(), Horde_Serialize::JSON); echo "{$error->error}\n"; }
public function importData($contents, $header = false) { $data = array(); $json = Horde_Serialize::unserialize($contents, Horde_Serialize::JSON); return $this->_parseJson($json->children, null); }
/** * 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) { $url->add(array('format' => 'json', '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; }
/** * Fetches the fields for a particular form. * * @param integer $form_id The form id of the form to return. * * @return array The fields. * @throws Ulaform_Exception */ public function getFields($form_id, $field_id = null) { $values = array($form_id); $sql = 'SELECT field_id, form_id, field_name, field_order, field_label, field_type, ' . ' field_params, field_required, field_readonly, field_desc FROM ulaform_fields ' . ' WHERE form_id = ?'; if (!is_null($field_id)) { $sql .= ' AND field_id = ?'; $values[] = (int) $field_id; } $sql .= ' ORDER BY field_order'; try { $results = $this->_db->select($sql, $values); } catch (Horde_Db_Exception $e) { throw new Ulaform_Exception($e); } $fields = array(); foreach ($results as $field) { /* If no internal name set, generate one using field_id. */ if (empty($field['field_name'])) { $field['field_name'] = 'field_' . $field['field_id']; } /* Check if any params and unserialize, otherwise return null. */ if (!empty($field['field_params'])) { $field['field_params'] = Horde_Serialize::unserialize($field['field_params'], Horde_Serialize::UTF7_BASIC); } else { $field['field_params'] = null; } $fields[] = $field; } return $fields; }
/** * 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; }
public function testJsonSpaces() { $obj = new stdClass(); $obj->a_string = "\"he\":llo}:{world"; $obj->an_array = array(1, 2, 3); $obj->obj = new stdClass(); $obj->obj->a_number = 123; $obj_js = '{"a_string": "\\"he\\":llo}:{world", "an_array":[1, 2, 3], "obj": {"a_number":123}}'; // checking whether notation with spaces works $this->assertEquals($obj, Horde_Serialize::unserialize($obj_js, Horde_Serialize::JSON)); }
/** * List the current folder. * * @param string $dir The directory name. * * @return array The sorted list of files. * @throws Gollem_Exception */ public static function listFolder($dir) { global $conf; if (!empty($conf['foldercache']['use_cache']) && !empty($conf['cache']['driver']) && $conf['cache']['driver'] != 'none') { $key = self::_getCacheID($dir); $cache = $GLOBALS['injector']->getInstance('Horde_Cache'); $res = $cache->get($key, $conf['foldercache']['lifetime']); if ($res !== false) { $res = Horde_Serialize::unserialize($res, Horde_Serialize::BASIC); if (is_array($res)) { return $res; } } } try { $files = $GLOBALS['injector']->getInstance('Gollem_Vfs')->listFolder($dir, isset(self::$backend['filter']) ? self::$backend['filter'] : null, $GLOBALS['prefs']->getValue('show_dotfiles')); } catch (Horde_Vfs_Exception $e) { throw new Gollem_Exception($e); } $sortcols = array(self::SORT_TYPE => 'sortType', self::SORT_NAME => 'sortName', self::SORT_DATE => 'sortDate', self::SORT_SIZE => 'sortSize'); usort($files, array('Gollem', $sortcols[$GLOBALS['prefs']->getValue('sortby')])); if (isset($cache)) { $cache->set($key, Horde_Serialize::serialize($files, Horde_Serialize::BASIC), $conf['foldercache']['lifetime']); } return $files; }
/** * Fetch ticket history * * @param integer $ticket_id The ticket to fetch history for. * * @return array */ public function getHistory($ticket_id, Horde_Form $form = null) { $rows = $this->_getHistory($ticket_id); $attributes = $attributeDetails = array(); foreach ($rows as $row) { if ($row['log_type'] == 'attribute' && strpos($row['log_value'], ':')) { $attributes[(int) $row['log_value']] = $row['attribute_name']; } if ($row['log_type'] == 'type') { $attributeDetails += $this->getAttributesForType($row['log_value']); } } $renderer = new Horde_Core_Ui_VarRenderer_Html(); $history = array(); foreach ($rows as $row) { $label = null; $human = $value = $row['log_value']; $type = $row['log_type']; $transaction = $row['transaction_id']; $history[$transaction]['timestamp'] = $row['timestamp']; $history[$transaction]['user_id'] = $row['user_id']; $history[$transaction]['ticket_id'] = $row['ticket_id']; switch ($type) { case 'comment': $history[$transaction]['comment'] = $row['comment_text']; $history[$transaction]['changes'][] = array('type' => 'comment', 'value' => $row['log_value'], 'comment' => $row['comment_text']); continue 2; case 'queue': $label = $row['queue_name']; break; case 'version': $label = $row['version_name']; break; case 'type': $label = $row['type_name']; break; case 'state': $label = $row['state_name']; break; case 'priority': $label = $row['priority_name']; break; case 'attribute': continue 2; case 'due': $label = $row['log_value_num']; break; default: if (strpos($type, 'attribute_') === 0) { if (is_string($value) && defined('JSON_BIGINT_AS_STRING')) { $value = json_decode($value, true, 512, constant('JSON_BIGINT_AS_STRING')); } else { try { $value = Horde_Serialize::unserialize($value, Horde_Serialize::JSON); } catch (Horde_Serialize_Exception $e) { } } $attribute = substr($type, 10); if (isset($attributes[$attribute])) { $label = $attributes[$attribute]; if ($form) { if (isset($form->attributes[$attribute])) { /* Attribute is part of the current type, so we * have the form field in the current form. */ $field = $form->attributes[$attribute]; } else { /* Attribute is from a different type, create * the form field manually. */ $detail = $attributeDetails[$attribute]; $field = new Horde_Form_Variable($detail['human_name'], $type, $form->getType($detail['type'], $detail['params']), $detail['required'], $detail['readonly'], $detail['desc']); } $human = $renderer->render($form, $field, new Horde_Variables(array($type => $value))); } $type = 'attribute'; } else { $label = sprintf(_("Attribute %d"), $attribute); } } break; } $history[$transaction]['changes'][] = array('type' => $type, 'value' => $value, 'human' => $human, 'label' => $label); } return $history; }
_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; } } }
/** * Fetches a gateway from the backend. * * @param int $gateway_id The gateway id to fetch. * * @return array An array containing the gateway settings and parameters. */ function &getGateway($gateway_id) { /* Get the gateways. */ $sql = 'SELECT * FROM swoosh_gateways WHERE gateway_id = ?'; $values = array((int) $gateway_id); Horde::log('SQL Query by Hylax_Storage_sql::getGateway(): ' . $sql, 'DEBUG'); $gateway = $this->_db->getRow($sql, $values, DB_FETCHMODE_ASSOC); if (is_a($gateway, 'PEAR_Error')) { Horde::log($gateway, 'ERR'); return $gateway; } /* Unserialize the gateway params. */ $gateway['gateway_params'] = Horde_Serialize::unserialize($gateway['gateway_params'], Horde_Serialize::UTF7_BASIC); /* Unserialize the gateway send params. */ $gateway['gateway_sendparams'] = Horde_Serialize::unserialize($gateway['gateway_sendparams'], Horde_Serialize::UTF7_BASIC); return $gateway; }
/** * Builds an JSON-RPC request and sends it to the server. * * This statically called method is actually the JSON-RPC client. * * @param string|Horde_Url $url The path to the JSON-RPC server on the * called host. * @param string $method The method to call. * @param Horde_Http_Client $client * @param array $params A hash containing any necessary parameters * for the method call. * * @return mixed The returned result from the method. * @throws Horde_Rpc_Exception */ public static function request($url, $method, $client, $params = null) { $headers = array('User-Agent' => 'Horde RPC client', 'Accept' => 'application/json', 'Content-Type' => 'application/json'); $data = array('version' => '1.1', 'method' => $method); if (!empty($params)) { $data['params'] = $params; } $data = Horde_Serialize::serialize($data, Horde_Serialize::JSON); try { $result = $client->post($url, $data, $headers); } catch (Horde_Http_Exception $e) { throw new Horde_Rpc_Exception($e->getMessage()); } if ($result->code == 500) { $response = Horde_Serialize::unserialize($result->getBody(), Horde_Serialize::JSON); if (is_a($response, 'stdClass') && isset($response->error) && is_a($response->error, 'stdClass') && isset($response->error->name) && $response->error->name == 'JSONRPCError') { throw new Horde_Rpc_Exception($response->error->message); /* @todo: Include more information if we have an Exception that can handle this. return PEAR::raiseError($response->error->message, $response->error->code, null, null, isset($response->error->error) ? $response->error->error : null); */ } throw new Horde_Rpc_Exception($http->getResponseBody()); } elseif ($result->code != 200) { throw new Horde_Rpc_Exception('Request couldn\'t be answered. Returned errorcode: "' . $result->code); } return Horde_Serialize::unserialize($result->getBody(), Horde_Serialize::JSON); }
<?php /** * @package Serialize */ require_once 'Horde/Serialize.php'; // Convert a complex value to JSON notation, and send it to the // browser. $value = array('foo', 'bar', array(1, 2, 'baz'), array(3, array(4))); echo Horde_Serialize::serialize($value, Horde_Serialize::JSON); // prints: ["foo","bar",[1,2,"baz"],[3,[4]]] // Accept incoming POST data, assumed to be in JSON notation. var_dump(Horde_Serialize::unserialize(file_get_contents('php://stdin'), Horde_Serialize::JSON));
/** * Helper to decode attribute value, which may be a bare scalar value, or * a json encoded structure that may contain large numeric strings that * should not be taken as integers. * * @param string The value to decode. * * @return mixed The decoded value. */ protected function _json_decode($value) { if (is_string($value) && defined('JSON_BIGINT_AS_STRING')) { $result = json_decode($value, true, 512, constant('JSON_BIGINT_AS_STRING')); // If we failed above, see if it was a bare scalar value. Note we // need to encode it first to be sure we escape any characters that // need escaping and we properly quote strings. if (!isset($result)) { $result = json_decode(json_encode($value), true, 512, constant('JSON_BIGINT_AS_STRING')); } } else { try { $result = Horde_Serialize::unserialize($value, Horde_Serialize::JSON); } catch (Horde_Serialize_Exception $e) { $result = $value; } } return $result; }
/** * 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; }
/** * Imple handler. * * @param Horde_Variables $vars A variables object. * * @return mixed Data to return to the browser. */ public function handle(Horde_Variables $vars) { if (isset($vars->imple_submit)) { $submit = Horde_Serialize::unserialize($vars->imple_submit, Horde_Serialize::JSON); $vars->imple_submit = is_object($submit) ? $submit : new stdClass(); } return $this->_auth && !$GLOBALS['registry']->getAuth() ? false : $this->_handle($vars); }
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; }
/** */ protected function _content() { global $page_output; /* Get the twitter driver */ try { $twitter = $this->_getTwitterObject(); } catch (Horde_Exception $e) { throw new Horde_Exception(sprintf(_("There was an error contacting Twitter: %s"), $e->getMessage())); } /* Get a unique ID in case we have multiple Twitter blocks. */ $instance = (string) new Horde_Support_Randomid(); /* Latest status */ if (empty($this->_profile->status)) { // status might not be set if only updating the block via ajax try { $this->_profile = Horde_Serialize::unserialize($twitter->account->verifyCredentials(), Horde_Serialize::JSON); if (empty($this->_profile)) { return _("Temporarily unable to contact Twitter. Please try again later."); } } catch (Horde_Service_Twitter_Exception $e) { $msg = Horde_Serialize::unserialize($e->getMessage(), Horde_Serialize::JSON); if (is_object($msg)) { $msg = $msg->errors[0]->message; } return sprintf(_("There was an error contacting Twitter: %s"), $msg); } } /* Build values to pass to the javascript twitter client */ $defaultText = addslashes(_("What are you working on now?")); $endpoint = Horde::url('services/twitter/', true); $inReplyToNode = $instance . '_inReplyTo'; $inReplyToText = addslashes(_("In reply to:")); $justNowText = addslashes(_("Just now...")); $refresh = empty($this->_params['refresh_rate']) ? 300 : $this->_params['refresh_rate']; /* Add the client javascript / initialize it */ $page_output->addScriptFile('twitterclient.js', 'horde'); $page_output->addScriptFile('scriptaculous/effects.js', 'horde'); $favorite = _("Favorite"); $unfavorite = _("Unfavorite"); $script = <<<EOT Horde = window.Horde = window.Horde || {}; Horde['twitter{$instance}'] = new Horde_Twitter({ instanceid: '{$instance}', getmore: '{$instance}_getmore', input: '{$instance}_newStatus', spinner: '{$instance}_loading', content: '{$instance}_stream', contenttab: '{$instance}_contenttab', mentiontab: '{$instance}_mentiontab', mentions: '{$instance}_mentions', endpoint: '{$endpoint}', inreplyto: '{$inReplyToNode}', refreshrate: {$refresh}, counter: '{$instance}_counter', strings: { inreplyto: '{$inReplyToText}', defaultText: '{$defaultText}', justnow: '{$justNowText}', favorite: '{$favorite}', unfavorite: '{$unfavorite}' } }); EOT; $page_output->addInlineScript($script, true); /* Build the UI */ $view = new Horde_View(array('templatePath' => HORDE_TEMPLATES . '/block')); $view->addHelper('Tag'); $view->instance = $instance; $view->defaultText = $defaultText; $view->loadingImg = Horde_Themes_Image::tag('loading.gif', array('attr' => array('id' => $instance . '_loading', 'style' => 'display:none;'))); $view->latestStatus = !empty($this->_profile->status) ? htmlspecialchars($this->_profile->status->text) : ''; $view->latestDate = !empty($this->_profile->status) ? Horde_Date_Utils::relativeDateTime(strtotime($this->_profile->status->created_at), $GLOBALS['prefs']->getValue('date_format'), $GLOBALS['prefs']->getValue('twentyFour') ? "%H:%M" : "%I:%M %P") : ''; $view->bodyHeight = empty($this->_params['height']) ? 350 : $this->_params['height']; return $view->render('twitter-layout'); }
/** * 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; }
/** * Helper method for getting a slice of tweets. * * Expects the following in $this->vars: * - max_id: * - since_id: * - i: * - mentions: * * @return [type] [description] */ protected function _doTwitterGetPage() { $twitter = $this->_getTwitterObject(); try { $params = array('include_entities' => 1); if ($max = $this->vars->max_id) { $params['max_id'] = $max; } elseif ($since = $this->vars->since_id) { $params['since_id'] = $since; } if ($this->vars->mentions) { $stream = Horde_Serialize::unserialize($twitter->statuses->mentions($params), Horde_Serialize::JSON); } else { $stream = Horde_Serialize::unserialize($twitter->statuses->homeTimeline($params), Horde_Serialize::JSON); } } catch (Horde_Service_Twitter_Exception $e) { $this->_twitterError($e); return; } if (count($stream)) { $newest = $stream[0]->id_str; } else { $newest = $params['since_id']; $oldest = 0; } $view = new Horde_View(array('templatePath' => HORDE_TEMPLATES . '/block')); $view->addHelper('Tag'); $html = ''; foreach ($stream as $tweet) { /* Don't return the max_id tweet, since we already have it */ if (!empty($params['max_id']) && $params['max_id'] == $tweet->id_str) { continue; } $view = $this->_buildTweet($tweet); $oldest = $tweet->id_str; $html .= $view->render('twitter_tweet'); } $result = array('o' => $oldest, 'n' => $newest, 'c' => $html); return $result; }
/** * TODO */ public function searchEvents() { $query = Horde_Serialize::unserialize($this->vars->query, Horde_Serialize::JSON); if (!isset($query->start)) { $query->start = new Horde_Date($_SERVER['REQUEST_TIME']); } if (!isset($query->end)) { $query->end = null; } switch ($this->vars->time) { case 'all': $query->start = null; $query->end = null; break; case 'future': $query->start = new Horde_Date($_SERVER['REQUEST_TIME']); $query->end = null; break; case 'past': $query->start = null; $query->end = new Horde_Date($_SERVER['REQUEST_TIME']); break; } $tagger = new Kronolith_Tagger(); $cals = Horde_Serialize::unserialize($this->vars->cals, Horde_Serialize::JSON); $events = array(); foreach ($cals as $cal) { if (!($kronolith_driver = $this->_getDriver($cal))) { continue; } try { $result = $kronolith_driver->search($query, true); if ($result) { $events[$cal] = $result; } } catch (Exception $e) { $GLOBALS['notification']->push($e, 'horde.error'); } $split = explode('|', $cal); if ($split[0] == 'internal') { $result = $tagger->search($query->title, array('type' => 'event', 'calendar' => $split[1])); foreach ($result['events'] as $uid) { Kronolith::addSearchEvents($events[$cal], $kronolith_driver->getByUID($uid), $query, true); } } } $result = new stdClass(); $result->view = 'search'; $result->query = $this->vars->query; if ($events) { $result->events = $events; } return $result; }
<?php require_once 'Horde/Autoloader.php'; // Create a Horde_Service_Vimeo_Simple object // 'http_client' is required, a cache and cache_lifetime are optional $params = array('http_client' => new Horde_Http_Client(), 'cache' => $GLOBALS['cache'], 'cache_lifetime' => $GLOBALS['conf']['cache']['default_lifetime']); $v = Horde_Service_Vimeo::factory('Simple', $params); // Get the list of all user videos $results = unserialize($v->user('user1015172')->clips()->run()); // Get the list of all clips in a group $results = unserialize($v->group('bestof08')->clips()->run()); // List of all clips in a channel $results = unserialize($v->channel('theedit')->clips()->run()); // List of clips in an album $results = unserialize($v->album('52803')->clips()->run()); // Get first video to embed - this returns a json encoded array $embed = $v->getEmbedJson($latest['url']); // Decode the data and print out the HTML. You could also just output // the json within your page's javascript for use later etc... $results = Horde_Serialize::unserialize($embed, Horde_Serialize::JSON); echo $results->html;