return;
}
-function get_guid($size = 16, $prefix = '')
-{
- if (is_bool($prefix) && !$prefix) {
- $prefix = '';
- } elseif ($prefix == '') {
- $a = get_app();
- $prefix = hash('crc32', $a->get_hostname());
- }
-
- while (strlen($prefix) < ($size - 13)) {
- $prefix .= mt_rand();
- }
-
- if ($size >= 24) {
- $prefix = substr($prefix, 0, $size - 22);
- return str_replace('.', '', uniqid($prefix, true));
- } else {
- $prefix = substr($prefix, 0, max($size - 13, 0));
- return uniqid($prefix);
- }
-}
-
/**
* @brief Used to end the current process, after saving session state.
* @deprecated
$owner_record = q("SELECT * FROM `contact` WHERE `uid`= %d AND `self` LIMIT 1", intval(api_user()));
$arr = [];
- $arr['guid'] = get_guid(32);
+ $arr['guid'] = System::createGUID(32);
$arr['uid'] = intval(api_user());
$arr['uri'] = $uri;
$arr['parent-uri'] = $uri;
function generate_user_guid() {
$found = true;
do {
- $guid = get_guid(32);
+ $guid = System::createGUID(32);
$x = q("SELECT `uid` FROM `user` WHERE `guid` = '%s' LIMIT 1",
dbesc($guid)
);
$emailcc = notags(trim(defaults($_REQUEST, 'emailcc' , '')));
$body = escape_tags(trim(defaults($_REQUEST, 'body' , '')));
$network = notags(trim(defaults($_REQUEST, 'network' , NETWORK_DFRN)));
- $guid = get_guid(32);
+ $guid = System::createGUID(32);
$postopts = defaults($_REQUEST, 'postopts', '');
$uri = Item::newURI($page_owner_uid);
$arr = [];
- $arr['guid'] = get_guid(32);
+ $arr['guid'] = System::createGUID(32);
$arr['uid'] = $page_owner_uid;
$arr['uri'] = $uri;
$arr['parent-uri'] = $uri;
$uri = Item::newURI($page_owner_uid);
$arr = [];
- $arr['guid'] = get_guid(32);
+ $arr['guid'] = System::createGUID(32);
$arr['uid'] = $page_owner_uid;
$arr['uri'] = $uri;
$arr['parent-uri'] = $uri;
$arr['coord'] = $lat . ' ' . $lon;
}
- $arr['guid'] = get_guid(32);
+ $arr['guid'] = System::createGUID(32);
$arr['uid'] = $page_owner_uid;
$arr['uri'] = $uri;
$arr['parent-uri'] = $uri;
$arr = [];
- $arr['guid'] = get_guid(32);
+ $arr['guid'] = System::createGUID(32);
$arr['uid'] = $uid;
$arr['uri'] = $uri;
$arr['parent-uri'] = ($parent_uri ? $parent_uri : $uri);
die();
}
- $fields = ['uid' => 0, 'contact-id' => 0, 'guid' => get_guid(), 'resource-id' => $urlhash, 'created' => DateTimeFormat::utcNow(), 'edited' => DateTimeFormat::utcNow(),
+ $fields = ['uid' => 0, 'contact-id' => 0, 'guid' => System::createGUID(), 'resource-id' => $urlhash, 'created' => DateTimeFormat::utcNow(), 'edited' => DateTimeFormat::utcNow(),
'filename' => basename($_REQUEST['url']), 'type' => '', 'album' => '', 'height' => imagesy($image), 'width' => imagesx($image),
'datasize' => 0, 'data' => $img_str, 'scale' => 100, 'profile' => 0,
'allow_cid' => '', 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => '', 'desc' => $mime];
$arr = [];
- $arr['guid'] = get_guid(32);
+ $arr['guid'] = System::createGUID(32);
$arr['uri'] = $uri;
$arr['uid'] = $owner_uid;
$arr['contact-id'] = $contact['id'];
$arr = [];
- $arr['guid'] = get_guid(32);
+ $arr['guid'] = System::createGUID(32);
$arr['uri'] = $uri;
$arr['uid'] = $owner_uid;
$arr['contact-id'] = $contact['id'];
use Friendica\App;
use Friendica\Core\Config;
use Friendica\Core\L10n;
+use Friendica\Core\System;
use Friendica\Database\DBM;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Mimetype;
$filedata = @file_get_contents($src);
$mimetype = Mimetype::getContentType($filename);
- $hash = get_guid(64);
+ $hash = System::createGUID(64);
$created = DateTimeFormat::utcNow();
$fields = ['uid' => $page_owner_uid, 'hash' => $hash, 'filename' => $filename, 'filetype' => $mimetype,
killme();
}
+ /**
+ * Generates a GUID with the given parameters
+ *
+ * @param int $size The size of the GUID (default is 16)
+ * @param bool|string $prefix A given prefix (default is empty)
+ * @return string a generated GUID
+ */
+ public static function createGUID($size = 16, $prefix = '')
+ {
+ if (is_bool($prefix) && !$prefix) {
+ $prefix = '';
+ } elseif (!isset($prefix)) {
+ $prefix = hash('crc32', self::getApp()->get_hostname());
+ }
+
+ while (strlen($prefix) < ($size - 13)) {
+ $prefix .= mt_rand();
+ }
+
+ if ($size >= 24) {
+ $prefix = substr($prefix, 0, $size - 22);
+ return str_replace('.', '', uniqid($prefix, true));
+ } else {
+ $prefix = substr($prefix, 0, max($size - 13, 0));
+ return uniqid($prefix);
+ }
+ }
+
/// @todo Move the following functions from boot.php
/*
- function get_guid($size = 16, $prefix = "")
function killme()
function goaway($s)
function local_user()
Addon::callHooks('event_updated', $event['id']);
} else {
- $event['guid'] = get_guid(32);
+ $event['guid'] = System::createGUID(32);
// New event. Store it.
dba::insert('event', $event);
} elseif (!empty($item['uri'])) {
$guid = self::guidFromUri($item['uri'], $prefix_host);
} else {
- $guid = get_guid(32, hash('crc32', $prefix_host));
+ $guid = System::createGUID(32, hash('crc32', $prefix_host));
}
return $guid;
public static function newURI($uid, $guid = "")
{
if ($guid == "") {
- $guid = get_guid(32);
+ $guid = System::createGUID(32);
}
$hostname = self::getApp()->get_hostname();
}
if ($contact['network'] != NETWORK_FEED) {
- $datarray["guid"] = get_guid(32);
+ $datarray["guid"] = System::createGUID(32);
unset($datarray["plink"]);
$datarray["uri"] = self::newURI($contact['uid'], $datarray["guid"]);
$datarray["parent-uri"] = $datarray["uri"];
$objtype = $item['resource-id'] ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE ;
$new_item = [
- 'guid' => get_guid(32),
+ 'guid' => System::createGUID(32),
'uri' => self::newURI($item['uid']),
'uid' => $item['uid'],
'contact-id' => $item_contact_id,
return -2;
}
- $guid = get_guid(32);
+ $guid = System::createGUID(32);
$uri = 'urn:X-dfrn:' . System::baseUrl() . ':' . local_user() . ':' . $guid;
$convid = 0;
$recip_handle = (($contact['addr']) ? $contact['addr'] : $contact['nick'] . '@' . $recip_host);
$sender_handle = $a->user['nickname'] . '@' . substr(System::baseUrl(), strpos(System::baseUrl(), '://') + 3);
- $conv_guid = get_guid(32);
+ $conv_guid = System::createGUID(32);
$convuri = $recip_handle . ':' . $conv_guid;
$handles = $recip_handle . ';' . $sender_handle;
$subject = L10n::t('[no subject]');
}
- $guid = get_guid(32);
+ $guid = System::createGUID(32);
$uri = 'urn:X-dfrn:' . System::baseUrl() . ':' . local_user() . ':' . $guid;
$me = Probe::uri($replyto);
return -2;
}
- $conv_guid = get_guid(32);
+ $conv_guid = System::createGUID(32);
$recip_handle = $recipient['nickname'] . '@' . substr(System::baseUrl(), strpos(System::baseUrl(), '://') + 3);
if (DBM::is_result($photo)) {
$guid = $photo['guid'];
} else {
- $guid = get_guid();
+ $guid = System::createGUID();
}
$existing_photo = dba::selectFirst('photo', ['id'], ['resource-id' => $rid, 'uid' => $uid, 'contact-id' => $cid, 'scale' => $scale]);
*/
public static function newResource()
{
- return get_guid(32, false);
+ return system::createGUID(32, false);
}
}
$author = self::myHandle($owner);
$message = ["author" => $author,
- "guid" => get_guid(32),
+ "guid" => System::createGUID(32),
"parent_type" => "Post",
"parent_guid" => $item["guid"]];
namespace Friendica\Test;
-use Friendica\App;
use Friendica\Core\Config;
use Friendica\Core\PConfig;
use Friendica\Network\BadRequestException;
*/
protected function setUp()
{
- global $a;
parent::setUp();
- // Reusable App object
- $this->app = new App(__DIR__.'/../');
- $a = $this->app;
-
// User data that the test database is populated with
$this->selfUser = [
'id' => 42,
'authenticated' => true,
'uid' => $this->selfUser['id']
];
-
- // Default config
- Config::set('config', 'hostname', 'localhost');
- Config::set('system', 'throttle_limit_day', 100);
- Config::set('system', 'throttle_limit_week', 100);
- Config::set('system', 'throttle_limit_month', 100);
- Config::set('system', 'theme', 'system_theme');
}
/**
namespace Friendica\Test;
use dba;
+use Friendica\App;
+use Friendica\Core\Config;
use Friendica\Database\DBStructure;
use PHPUnit_Extensions_Database_DB_IDatabaseConnection;
use PHPUnit\DbUnit\DataSet\YamlDataSet;
*/
abstract class DatabaseTest extends TestCase
{
+ /**
+ * @var \Friendica\App
+ */
+ protected $app;
use TestCaseTrait;
+ /**
+ * Creates basic instances for testing with databases
+ *
+ * @throws \Exception
+ */
+ protected function setUp()
+ {
+ global $a;
+ parent::setUp();
+
+ // Reusable App object
+ $this->app = new App(__DIR__.'/../');
+ $a = $this->app;
+
+ // Default config
+ Config::set('config', 'hostname', 'localhost');
+ Config::set('system', 'throttle_limit_day', 100);
+ Config::set('system', 'throttle_limit_week', 100);
+ Config::set('system', 'throttle_limit_month', 100);
+ Config::set('system', 'theme', 'system_theme');
+ }
+
/**
* Renames an eventually existing .htconfig.php to .htconfig.php.tmp
* Creates a new .htconfig.php for bin/worker.php execution
namespace Friendica\Test\src\Core\Cache;
-use Friendica\App;
-use Friendica\Core\Config;
use Friendica\Test\DatabaseTest;
use Friendica\Util\DateTimeFormat;
protected function setUp()
{
- global $a;
parent::setUp();
$this->instance = $this->getInstance();
-
- // Reusable App object
- $this->app = new App(__DIR__.'/../');
- $a = $this->app;
-
- // Default config
- Config::set('config', 'hostname', 'localhost');
- Config::set('system', 'throttle_limit_day', 100);
- Config::set('system', 'throttle_limit_week', 100);
- Config::set('system', 'throttle_limit_month', 100);
- Config::set('system', 'theme', 'system_theme');
}
function testSimple() {
namespace Friendica\Test\src\Core\Lock;
-use Friendica\App;
-use Friendica\Core\Config;
use Friendica\Test\DatabaseTest;
-use PHPUnit\Framework\TestCase;
abstract class LockTest extends DatabaseTest
{
protected function setUp()
{
- global $a;
parent::setUp();
$this->instance = $this->getInstance();
-
- // Reusable App object
- $this->app = new App(__DIR__.'/../');
- $a = $this->app;
-
- // Default config
- Config::set('config', 'hostname', 'localhost');
- Config::set('system', 'throttle_limit_day', 100);
- Config::set('system', 'throttle_limit_week', 100);
- Config::set('system', 'throttle_limit_month', 100);
- Config::set('system', 'theme', 'system_theme');
}
public function testLock() {
--- /dev/null
+<?php
+
+namespace Friendica\Test\src\Core;
+
+use Friendica\Core\System;
+use PHPUnit\Framework\TestCase;
+
+class SystemTest extends TestCase
+{
+ private function assertGuid($guid, $length)
+ {
+ $this->assertRegExp("/^[a-z0-9]{" . $length . "}?$/", $guid);
+ }
+
+ function testGuidWithoutParameter()
+ {
+ $guid = System::createGUID();
+ $this->assertGuid($guid, 16);
+ }
+
+ function testGuidWithSize() {
+ $guid = System::createGUID(20);
+ $this->assertGuid($guid, 20);
+ }
+}
\ No newline at end of file