mirror of
https://github.com/owncloudarchive/contacts.git
synced 2025-01-20 09:52:17 +01:00
Reuse Sabre\VObject\UUIDUtil to generate UUIDs
This commit is contained in:
parent
513b1d6875
commit
4ae5e52fda
@ -23,6 +23,8 @@
|
|||||||
namespace OCA\Contacts\Utils;
|
namespace OCA\Contacts\Utils;
|
||||||
|
|
||||||
use OCA\Contacts\App;
|
use OCA\Contacts\App;
|
||||||
|
use OCA\Contacts\VObject\VCard;
|
||||||
|
use Sabre\VObject\UUIDUtil;
|
||||||
|
|
||||||
Properties::$l10n = \OCP\Util::getL10N('contacts');
|
Properties::$l10n = \OCP\Util::getL10N('contacts');
|
||||||
|
|
||||||
@ -39,7 +41,7 @@ Class Properties {
|
|||||||
/**
|
/**
|
||||||
* @brief language object for calendar app
|
* @brief language object for calendar app
|
||||||
*
|
*
|
||||||
* @var OC_L10N
|
* @var \OCP\IL10N
|
||||||
*/
|
*/
|
||||||
public static $l10n;
|
public static $l10n;
|
||||||
|
|
||||||
@ -207,9 +209,12 @@ Class Properties {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function generateUID($app = 'contacts') {
|
/**
|
||||||
$uuid = new UUID();
|
* @return string
|
||||||
return $uuid->get() . '@' . \OCP\Util::getServerHostName();
|
*/
|
||||||
|
public static function generateUID() {
|
||||||
|
$uuid = UUIDUtil::getUUID();
|
||||||
|
return $uuid . '@' . \OCP\Util::getServerHostName();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -246,13 +251,13 @@ Class Properties {
|
|||||||
* If it is a valid object the old properties will first be purged
|
* If it is a valid object the old properties will first be purged
|
||||||
* and the current properties indexed.
|
* and the current properties indexed.
|
||||||
*
|
*
|
||||||
* @param string $contactid
|
* @param string $contactId
|
||||||
* @param \OCA\VObject\VCard|null $vcard
|
* @param VCard|null $vCard
|
||||||
*/
|
*/
|
||||||
public static function updateIndex($contactid, $vcard = null) {
|
public static function updateIndex($contactId, $vCard = null) {
|
||||||
self::purgeIndexes(array($contactid));
|
self::purgeIndexes(array($contactId));
|
||||||
|
|
||||||
if(is_null($vcard)) {
|
if(is_null($vCard)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,7 +265,7 @@ Class Properties {
|
|||||||
self::$updateindexstmt = \OCP\DB::prepare( 'INSERT INTO `' . self::$indexTableName . '` '
|
self::$updateindexstmt = \OCP\DB::prepare( 'INSERT INTO `' . self::$indexTableName . '` '
|
||||||
. '(`userid`, `contactid`,`name`,`value`,`preferred`) VALUES(?,?,?,?,?)' );
|
. '(`userid`, `contactid`,`name`,`value`,`preferred`) VALUES(?,?,?,?,?)' );
|
||||||
}
|
}
|
||||||
foreach($vcard->children as $property) {
|
foreach($vCard->children as $property) {
|
||||||
if(!in_array($property->name, self::$indexProperties)) {
|
if(!in_array($property->name, self::$indexProperties)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -275,7 +280,7 @@ Class Properties {
|
|||||||
$result = self::$updateindexstmt->execute(
|
$result = self::$updateindexstmt->execute(
|
||||||
array(
|
array(
|
||||||
\OC::$server->getUserSession()->getUser()->getUId(),
|
\OC::$server->getUserSession()->getUser()->getUId(),
|
||||||
$contactid,
|
$contactId,
|
||||||
$property->name,
|
$property->name,
|
||||||
substr($property->getValue(), 0, 254),
|
substr($property->getValue(), 0, 254),
|
||||||
$preferred,
|
$preferred,
|
||||||
@ -294,7 +299,7 @@ Class Properties {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static function cacheThumbnail($backendName, $addressBookId, $contactId,
|
public static function cacheThumbnail($backendName, $addressBookId, $contactId,
|
||||||
\OCP\Image $image = null, $vcard = null, $options = array()
|
\OCP\Image $image = null, $vCard = null, $options = array()
|
||||||
) {
|
) {
|
||||||
$cache = \OC::$server->getCache();
|
$cache = \OC::$server->getCache();
|
||||||
$key = self::THUMBNAIL_PREFIX . $backendName . '::' . $addressBookId . '::' . $contactId;
|
$key = self::THUMBNAIL_PREFIX . $backendName . '::' . $addressBookId . '::' . $contactId;
|
||||||
@ -320,12 +325,12 @@ Class Properties {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($image)) {
|
if (is_null($image)) {
|
||||||
if (is_null($vcard)) {
|
if (is_null($vCard)) {
|
||||||
$app = new App();
|
$app = new App();
|
||||||
$vcard = $app->getContact($backendName, $addressBookId, $contactId);
|
$vCard = $app->getContact($backendName, $addressBookId, $contactId);
|
||||||
}
|
}
|
||||||
$image = new \OCP\Image();
|
$image = new \OCP\Image();
|
||||||
if (!isset($vcard->PHOTO) || !$image->loadFromBase64((string)$vcard->PHOTO)) {
|
if (!isset($vCard->PHOTO) || !$image->loadFromBase64((string)$vCard->PHOTO)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,71 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace OCA\Contacts\Utils;
|
|
||||||
|
|
||||||
class UUID {
|
|
||||||
|
|
||||||
protected $urand;
|
|
||||||
|
|
||||||
public function __construct() {
|
|
||||||
$this->urand = @fopen ( '/dev/urandom', 'rb' );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Generates a Universally Unique IDentifier, version 4.
|
|
||||||
*
|
|
||||||
* This function generates a truly random UUID. The built in CakePHP String::uuid() function
|
|
||||||
* is not cryptographically secure. You should uses this function instead.
|
|
||||||
* From http://php.net/manual/en/function.uniqid.php comments
|
|
||||||
*
|
|
||||||
* @see http://tools.ietf.org/html/rfc4122#section-4.4
|
|
||||||
* @see http://en.wikipedia.org/wiki/UUID
|
|
||||||
* @return string A UUID, made up of 32 hex digits and 4 hyphens.
|
|
||||||
*/
|
|
||||||
public function get() {
|
|
||||||
|
|
||||||
$prBits = false;
|
|
||||||
if (is_a($this, 'uuid')) {
|
|
||||||
if (is_resource($this->urand)) {
|
|
||||||
$prBits .= @fread($this->urand, 16);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!$prBits) {
|
|
||||||
$fp = @fopen('/dev/urandom', 'rb');
|
|
||||||
if ($fp !== false) {
|
|
||||||
$prBits .= @fread($fp, 16);
|
|
||||||
@fclose ( $fp );
|
|
||||||
} else {
|
|
||||||
// If /dev/urandom isn't available (eg: in non-unix systems), use mt_rand().
|
|
||||||
$prBits = "";
|
|
||||||
for($cnt = 0; $cnt < 16; $cnt ++) {
|
|
||||||
$prBits .= chr(mt_rand(0, 255));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$timeLow = bin2hex(substr($prBits, 0, 4));
|
|
||||||
$timeMid = bin2hex(substr($prBits, 4, 2));
|
|
||||||
$timeHiAndVersion = bin2hex(substr($prBits, 6, 2));
|
|
||||||
$clockSeqHiAndReserved = bin2hex(substr($prBits, 8, 2));
|
|
||||||
$node = bin2hex(substr($prBits, 10, 6));
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the four most significant bits (bits 12 through 15) of the
|
|
||||||
* time_hi_and_version field to the 4-bit version number from
|
|
||||||
* Section 4.1.3.
|
|
||||||
* @see http://tools.ietf.org/html/rfc4122#section-4.1.3
|
|
||||||
*/
|
|
||||||
$timeHiAndVersion = hexdec($timeHiAndVersion);
|
|
||||||
$timeHiAndVersion = $timeHiAndVersion >> 4;
|
|
||||||
$timeHiAndVersion = $timeHiAndVersion | 0x4000;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the two most significant bits (bits 6 and 7) of the
|
|
||||||
* clock_seq_hi_and_reserved to zero and one, respectively.
|
|
||||||
*/
|
|
||||||
$clockSeqHiAndReserved = hexdec($clockSeqHiAndReserved);
|
|
||||||
$clockSeqHiAndReserved = $clockSeqHiAndReserved >> 2;
|
|
||||||
$clockSeqHiAndReserved = $clockSeqHiAndReserved | 0x8000;
|
|
||||||
|
|
||||||
return sprintf('%08s-%04s-%04x-%04x-%012s', $timeLow, $timeMid, $timeHiAndVersion, $clockSeqHiAndReserved, $node);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user