Skip to content

Commit

Permalink
Coding standards/tweaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrubinsk committed Dec 29, 2015
1 parent 74c5fe3 commit 8893ea6
Showing 1 changed file with 21 additions and 24 deletions.
45 changes: 21 additions & 24 deletions nag/lib/Driver/Kolab.php
Expand Up @@ -96,13 +96,17 @@ public function get($taskId)
return new Nag_Task($this, $nag_task);
}

/* Little helper function, detecting if a string is already
* based64-encoded or not
/**
* Detect if a string is already Horde_Url::uriB64Encode()'ed or not.
*
* @param string $s The string to test.
*
* @return boolean True if $s was base64 encoded.
* @todo This will be removed in Horde 6.
*/
private function _is_base64_encoded_uid($s) {

/* redo stuff possibly done by Horde_Url::uriB64Encode()
*/
public function _isBase64EncodedUid($s)
{
// Redo stuff possibly done by Horde_Url::uriB64Encode()
$data = str_replace(array('-', '_'), array('+', '/'), $s);
$mod4 = strlen($data) % 4;
if ($mod4) {
Expand All @@ -112,23 +116,19 @@ private function _is_base64_encoded_uid($s) {
return false;
}

/* Decode the string in strict mode and check the results
*/
// Decode the string in strict mode and check the results
$decoded = base64_decode($data, true);
if(false === $decoded) {
if ($decoded === false) {
return false;
}

/* Check if the decoded string resembles a uid hash...
*/
// Check if the decoded string resembles a uid hash...
if (!preg_match('/^[a-zA-Z0-9-]+$/', $decoded)) {
return false;
}

/* Encode the string again
*/
if(base64_encode($decoded) != $data)
{
// Encode the string again for a final sanity check.
if (base64_encode($decoded) != $data) {
return false;
}

Expand All @@ -146,16 +146,11 @@ private function _is_base64_encoded_uid($s) {
*/
protected function _buildTask($task)
{

/*
* This decoding of parent ID hashes is required because of a probably
* long-existing bug in Nag_Driver_Kolab.
*
* For details, see:
* https://bugs.horde.org/ticket/14197
*/
// This decoding of parent ID hashes is required because of a
// previous bug in Nag_Driver_Kolab.
// See Bug: 14197
$parent_uid = $task['parent'];
if (!empty($parent_uid) && $this->_is_base64_encoded_uid($parent_uid)) {
if (!empty($parent_uid) && $this->_isBase64EncodedUid($parent_uid)) {
$parent_uid = Horde_Url::uriB64Decode($parent_uid);
}

Expand All @@ -165,6 +160,7 @@ protected function _buildTask($task)
'name' => $task['summary'],
'desc' => $task['body'],
'priority' => $task['priority'],
// parent is keyed to internal id, not UID.
'parent' => Horde_Url::uriB64Encode($parent_uid),
'alarm' => $task['alarm'],
'completed' => !empty($task['completed']),
Expand Down Expand Up @@ -396,6 +392,7 @@ protected function _getObject($task)
'summary' => $task['name'],
'body' => $task['desc'],
'priority' => $task['priority'],
// Kolab's parent field is UID, Nag's parent is id.
'parent' => Horde_Url::uriB64Decode($task['parent']),
);
if (!empty($task['start'])) {
Expand Down

0 comments on commit 8893ea6

Please sign in to comment.