uriB64Encode() public static method

URL-safe base64 encoding, with trimmed '='.
public static uriB64Encode ( string $string ) : string
$string string String to encode.
return string URL-safe, base64 encoded data.
Ejemplo n.º 1
0
 /**
  * Retrieves sub-tasks from the database.
  *
  * @param string $parentId          The parent id for the sub-tasks to
  *                                  retrieve.
  * @param boolean $include_history  Include created/modified info? Not
  *                                  currently honored.
  *
  * @return array  List of sub-tasks.
  * @throws Nag_Exception
  */
 public function getChildren($parentId, $include_history = true)
 {
     $task_list = $this->_getData()->getObjects();
     if (empty($task_list)) {
         return array();
     }
     $tasks = array();
     foreach ($task_list as $task) {
         if (Horde_Url::uriB64Encode($task['parent']) != $parentId) {
             continue;
         }
         $t = new Nag_Task($this, $this->_buildTask($task));
         $children = $this->getChildren($t->id);
         $t->mergeChildren($children);
         $tasks[] = $t;
     }
     return $tasks;
 }
Ejemplo n.º 2
0
 /**
  * Construct the ID from the owner name and the folder subpath.
  *
  * @param string $owner  The share owner.
  * @param string $name   The name of the folder without the namespace prefix.
  * @param string $prefix The namespace prefix.
  *
  * @return string The encoded ID.
  */
 public function constructId($owner, $name, $prefix = null)
 {
     return Horde_Url::uriB64Encode(serialize(array($owner, $name, $prefix)));
 }
Ejemplo n.º 3
0
 /**
  * Generates a connection id and returns it.
  *
  * @param string $seed  A unique ID to be included in the token.
  *
  * @return string  The generated id string.
  */
 public static function generateId($seed = '')
 {
     return Horde_Url::uriB64Encode(pack('H*', hash('sha1', uniqid(mt_rand()) . $seed . (isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''))));
 }
Ejemplo n.º 4
0
 /**
  * Saves an event in the backend.
  *
  * @param Kronolith_Event $event  The event to save.
  *
  * @return string  The event id.
  * @throws Horde_Mime_Exception
  */
 protected function _saveEvent($event, $edit)
 {
     $this->synchronize();
     $action = $edit ? array('action' => 'modify') : array('action' => 'add');
     if (!$event->uid) {
         $event->uid = $this->_data->generateUID();
         $event->id = Horde_Url::uriB64Encode($event->uid);
     }
     $object = $event->toKolab();
     if ($edit) {
         $this->_data->modify($object);
     } else {
         $this->_data->create($object);
     }
     /* Deal with tags */
     if ($edit) {
         $this->_updateTags($event);
     } else {
         $this->_addTags($event);
     }
     /* Notify about the changed event. */
     Kronolith::sendNotification($event, $edit ? 'edit' : 'add');
     /* Log the creation/modification of this item in the history log. */
     try {
         $GLOBALS['injector']->getInstance('Horde_History')->log('kronolith:' . $event->calendar . ':' . $event->uid, $action, true);
     } catch (Exception $e) {
         Horde::log($e, 'ERR');
     }
     // refresh IMAP cache
     $this->synchronize(true);
     if (is_callable('Kolab', 'triggerFreeBusyUpdate')) {
         //Kolab::triggerFreeBusyUpdate($this->_data->parseFolder($event->calendar));
     }
     return $event->id;
 }
Ejemplo n.º 5
0
 /**
  * Create an object key for a new object.
  *
  * @param array $attributes  The attributes (in driver keys) of the
  *                           object being added.
  *
  * @return string  A unique ID for the new object.
  */
 protected function _makeKey(array $attributes)
 {
     return Horde_Url::uriB64Encode(isset($attributes['uid']) ? $attributes['uid'] : $this->_generateUid());
 }
Ejemplo n.º 6
0
 /**
  * Return a new signed token.
  *
  * @param string $seed  A unique ID to be included in the token.
  *
  * @return string The new token.
  */
 public function get($seed = '')
 {
     $nonce = $this->getNonce();
     return Horde_Url::uriB64Encode($nonce . $this->_hash($nonce . $seed));
 }
Ejemplo n.º 7
0
 /**
  * Imports a backend specific event object.
  *
  * @param array $event  Backend specific event object that this object
  *                      will represent.
  */
 public function fromDriver($event)
 {
     $this->uid = $event['uid'];
     $this->id = Horde_Url::uriB64Encode($event['uid']);
     if (isset($event['summary'])) {
         $this->title = $event['summary'];
     }
     if (isset($event['body'])) {
         $this->description = $event['body'];
     }
     if (isset($event['location'])) {
         $this->location = $event['location'];
     }
     if (isset($event['sensitivity']) && ($event['sensitivity'] == 'private' || $event['sensitivity'] == 'confidential')) {
         $this->private = true;
     }
     if (isset($event['organizer']['smtp-address'])) {
         if (Kronolith::isUserEmail($GLOBALS['registry']->getAuth(), $event['organizer']['smtp-address'])) {
             $this->creator = $GLOBALS['registry']->getAuth();
         } else {
             $this->creator = $event['organizer']['smtp-address'];
         }
     }
     if (isset($event['alarm'])) {
         $this->alarm = $event['alarm'];
     }
     if (isset($event['horde-alarm-methods'])) {
         $this->methods = @unserialize($event['horde-alarm-methods']);
     }
     $tz_local = date_default_timezone_get();
     $this->start = new Horde_Date($event['start-date']);
     $this->start->setTimezone($tz_local);
     $this->end = new Horde_Date($event['end-date']);
     $this->end->setTimezone($tz_local);
     $this->durMin = ($this->end->timestamp() - $this->start->timestamp()) / 60;
     if (!empty($event['creation-date'])) {
         $this->created = new Horde_Date($event['creation-date']);
     }
     if (!empty($event['last-modification-date'])) {
         $this->modified = new Horde_Date($event['last-modification-date']);
     }
     if (isset($event['show-time-as'])) {
         switch ($event['show-time-as']) {
             case 'free':
                 $this->status = Kronolith::STATUS_FREE;
                 break;
             case 'tentative':
                 $this->status = Kronolith::STATUS_TENTATIVE;
                 break;
             case 'busy':
             case 'outofoffice':
             default:
                 $this->status = Kronolith::STATUS_CONFIRMED;
         }
     } else {
         $this->status = Kronolith::STATUS_CONFIRMED;
     }
     // Recurrence
     if (isset($event['recurrence'])) {
         if (isset($event['recurrence']['exclusion'])) {
             $exceptions = array();
             foreach ($event['recurrence']['exclusion'] as $exclusion) {
                 if (!empty($exclusion)) {
                     $exceptions[] = $exclusion->format('Ymd');
                 }
             }
             $event['recurrence']['exceptions'] = $exceptions;
         }
         if (isset($event['recurrence']['complete'])) {
             $completions = array();
             foreach ($event['recurrence']['complete'] as $complete) {
                 if (!empty($complete)) {
                     $completions[] = $complete->format('Ymd');
                 }
             }
             $event['recurrence']['completions'] = $completions;
         }
         $this->recurrence = new Horde_Date_Recurrence($this->start);
         $this->recurrence->fromKolab($event['recurrence']);
     }
     // Attendees
     $attendee_count = 0;
     if (!empty($event['attendee'])) {
         foreach ($event['attendee'] as $attendee) {
             $name = $attendee['display-name'];
             $email = $attendee['smtp-address'];
             $role = $attendee['role'];
             switch ($role) {
                 case 'optional':
                     $role = Kronolith::PART_OPTIONAL;
                     break;
                 case 'resource':
                     $role = Kronolith::PART_NONE;
                     break;
                 case 'required':
                 default:
                     $role = Kronolith::PART_REQUIRED;
                     break;
             }
             $status = $attendee['status'];
             switch ($status) {
                 case 'accepted':
                     $status = Kronolith::RESPONSE_ACCEPTED;
                     break;
                 case 'declined':
                     $status = Kronolith::RESPONSE_DECLINED;
                     break;
                 case 'tentative':
                     $status = Kronolith::RESPONSE_TENTATIVE;
                     break;
                 case 'none':
                 default:
                     $status = Kronolith::RESPONSE_NONE;
                     break;
             }
             $this->addAttendee($email, $role, $status, $name);
         }
     }
     // Tags
     if (isset($event['categories'])) {
         $this->_internaltags = $event['categories'];
     }
     $this->initialized = true;
     $this->stored = true;
 }
Ejemplo n.º 8
0
 /**
  * Verify a signature and timestamp on a query string.
  *
  * @param string $data  The signed query string.
  * @param integer $now  The current time (can override for testing).
  *
  * @return boolean  Whether or not the string was valid.
  */
 public static function verifySignedQueryString($data, $now = null)
 {
     if (is_null($now)) {
         $now = time();
     }
     $pos = strrpos($data, '&_h=');
     if ($pos === false) {
         return false;
     }
     $pos += 4;
     $queryString = substr($data, 0, $pos);
     $hmac = substr($data, $pos);
     if ($hmac != Horde_Url::uriB64Encode(hash_hmac('sha1', $queryString, $GLOBALS['conf']['secret_key'], true))) {
         return false;
     }
     // String was not tampered with; now validate timestamp
     parse_str($queryString, $values);
     return !($values['_t'] + $GLOBALS['conf']['urls']['hmac_lifetime'] * 60 < $now);
 }
Ejemplo n.º 9
0
 /**
  * Generates a local note ID.
  *
  * @return string  A new note ID.
  */
 protected function _generateId()
 {
     return Horde_Url::uriB64Encode($this->_getData()->generateUid());
 }