$remote_contact = false;
$contact_id = 0;
- $owner_uid = $a->data['user']['uid'];
+ $owner_uid = intval($a->data['user']['uid']);
$nick = $a->data['user']['nickname'];
if (!empty($_SESSION['remote']) && is_array($_SESSION['remote'])) {
}
if ($mode == 'export') {
- if (!intval($owner_uid)) {
+ if (!$owner_uid) {
notice(L10n::t('User not found'));
return;
}
// Test permissions
// Respect the export feature setting for all other /cal pages if it's not the own profile
- if ((local_user() !== intval($owner_uid)) && !Feature::isEnabled($owner_uid, "export_calendar")) {
+ if ((local_user() !== $owner_uid) && !Feature::isEnabled($owner_uid, "export_calendar")) {
notice(L10n::t('Permission denied.') . EOL);
$a->internalRedirect('cal/' . $nick);
}
// If it the own calendar return to the events page
// otherwise to the profile calendar page
- if (local_user() === intval($owner_uid)) {
+ if (local_user() === $owner_uid) {
$return_path = "events";
} else {
$return_path = "cal/" . $nick;
$can_post = false;
$visitor = 0;
- $page_owner_uid = $a->data['user']['uid'];
+ $page_owner_uid = intval($a->data['user']['uid']);
$community_page = $a->data['user']['page-flags'] == User::PAGE_FLAGS_COMMUNITY;
if (local_user() && (local_user() == $page_owner_uid)) {
* @return boolean
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
- public static function isEnabled($uid, $feature)
+ public static function isEnabled(int $uid, $feature)
{
$x = Config::get('feature_lock', $feature, false);
{
$a = \get_app();
- if (!Feature::isEnabled($a->profile['profile_uid'], 'categories')) {
+ $uid = intval($a->profile['profile_uid']);
+
+ if (!Feature::isEnabled($uid, 'categories')) {
return '';
}
- $saved = PConfig::get($a->profile['profile_uid'], 'system', 'filetags');
+ $saved = PConfig::get($uid, 'system', 'filetags');
if (!strlen($saved)) {
return;
}
{
$a = \get_app();
- if (!$a->profile['profile_uid'] || !$a->profile['url']) {
+ $uid = intval($a->profile['profile_uid']);
+
+ if (!$uid || !$a->profile['url']) {
return '';
}
- if (Feature::isEnabled($a->profile['profile_uid'], 'tagadelic')) {
+ if (Feature::isEnabled($uid, 'tagadelic')) {
$owner_id = Contact::getIdForURL($a->profile['url'], 0, true);
if (!$owner_id) {
return '';
}
- return Widget\TagCloud::getHTML($a->profile['profile_uid'], $limit, $owner_id, 'wall');
+ return Widget\TagCloud::getHTML($uid, $limit, $owner_id, 'wall');
}
return '';
return;
}
- $owner_uid = $a->data['user']['uid'];
+ $owner_uid = intval($a->data['user']['uid']);
// The permission testing is a little bit tricky because we have to respect many cases.
* {@inheritDoc}
*
*/
- public function load($uid, string $cat = 'config')
+ public function load(int $uid, string $cat = 'config')
{
// If not connected or no uid, do nothing
- if (!is_int($uid) || !$this->configModel->isConnected()) {
+ if (!$uid || !$this->configModel->isConnected()) {
return;
}
/**
* {@inheritDoc}
*/
- public function get($uid, string $cat, string $key, $default_value = null, bool $refresh = false)
+ public function get(int $uid, string $cat, string $key, $default_value = null, bool $refresh = false)
{
- if (!is_int($uid)) {
+ if (!$uid) {
return $default_value;
}
/**
* {@inheritDoc}
*/
- public function set($uid, string $cat, string $key, $value)
+ public function set(int $uid, string $cat, string $key, $value)
{
- if (!is_int($uid)) {
+ if (!$uid) {
return false;
}
/**
* {@inheritDoc}
*/
- public function delete($uid, string $cat, string $key)
+ public function delete(int $uid, string $cat, string $key)
{
- if (!is_int($uid)) {
+ if (!$uid) {
return false;
}
/**
* Loads all configuration values of a user's config family into a cached storage.
*
- * All configuration values of the given user are stored with the $uid in
- * the cache ( @param int $uid The user_id
+ * All configuration values of the given user are stored with the $uid in the cache
*
+ * @param int $uid The user_id
* @param string $cat The category of the configuration value
*
* @return void
* @see PConfigCache )
*
*/
- abstract public function load($uid, string $cat = 'config');
+ abstract public function load(int $uid, string $cat = 'config');
/**
* Get a particular user's config variable given the category name
*
* @return mixed Stored value or null if it does not exist
*/
- abstract public function get($uid, string $cat, string $key, $default_value = null, bool $refresh = false);
+ abstract public function get(int $uid, string $cat, string $key, $default_value = null, bool $refresh = false);
/**
* Sets a configuration value for a user
*
* @return bool Operation success
*/
- abstract public function set($uid, string $cat, string $key, $value);
+ abstract public function set(int $uid, string $cat, string $key, $value);
/**
* Deletes the given key from the users's configuration.
*
* @return bool
*/
- abstract public function delete($uid, string $cat, string $key);
+ abstract public function delete(int $uid, string $cat, string $key);
}
* This loads all config values everytime load is called
*
*/
- public function load($uid, string $cat = 'config')
+ public function load(int $uid, string $cat = 'config')
{
// Don't load the whole configuration twice or with invalid uid
- if (!is_int($uid) || !empty($this->config_loaded[$uid])) {
+ if (!$uid || !empty($this->config_loaded[$uid])) {
return;
}
/**
* {@inheritDoc}
*/
- public function get($uid, string $cat, string $key, $default_value = null, bool $refresh = false)
+ public function get(int $uid, string $cat, string $key, $default_value = null, bool $refresh = false)
{
- if (!is_int($uid)) {
+ if (!$uid) {
return $default_value;
}
/**
* {@inheritDoc}
*/
- public function set($uid, string $cat, string $key, $value)
+ public function set(int $uid, string $cat, string $key, $value)
{
- if (!is_int($uid)) {
+ if (!$uid) {
return false;
}
/**
* {@inheritDoc}
*/
- public function delete($uid, string $cat, string $key)
+ public function delete(int $uid, string $cat, string $key)
{
- if (!is_int($uid)) {
+ if (!$uid) {
return false;
}
/**
* @brief Loads all configuration values of a user's config family into a cached storage.
*
- * @param string $uid The user_id
+ * @param int $uid The user_id
* @param string $cat The category of the configuration value
*
* @return void
*/
- public static function load($uid, $cat)
+ public static function load(int $uid, string $cat)
{
self::$config->load($uid, $cat);
}
* @brief Get a particular user's config variable given the category name
* ($cat) and a key.
*
- * @param string $uid The user_id
+ * @param int $uid The user_id
* @param string $cat The category of the configuration value
* @param string $key The configuration key to query
* @param mixed $default_value optional, The value to return if key is not set (default: null)
*
* @return mixed Stored value or null if it does not exist
*/
- public static function get($uid, $cat, $key, $default_value = null, $refresh = false)
+ public static function get(int $uid, string $cat, string $key, $default_value = null, bool $refresh = false)
{
return self::$config->get($uid, $cat, $key, $default_value, $refresh);
}
/**
* @brief Sets a configuration value for a user
*
- * @param string $uid The user_id
+ * @param int $uid The user_id
* @param string $cat The category of the configuration value
* @param string $key The configuration key to set
* @param mixed $value The value to store
*
* @return bool Operation success
*/
- public static function set($uid, $cat, $key, $value)
+ public static function set(int $uid, string $cat, string $key, $value)
{
return self::$config->set($uid, $cat, $key, $value);
}
/**
* @brief Deletes the given key from the users's configuration.
*
- * @param string $uid The user_id
+ * @param int $uid The user_id
* @param string $cat The category of the configuration value
* @param string $key The configuration key to delete
*
* @return bool
*/
- public static function delete($uid, $cat, $key)
+ public static function delete(int $uid, string $cat, string $key)
{
return self::$config->delete($uid, $cat, $key);
}
public static function getAdvanced(App $a)
{
- $uid = $a->profile['uid'];
+ $uid = intval($a->profile['uid']);
if ($a->profile['name']) {
$tpl = Renderer::getMarkupTemplate('profile_advanced.tpl');
parent::testGetWithRefresh($uid, $data);
}
- public function testGetWrongWithoutDB()
- {
- $this->configModel->shouldReceive('isConnected')
- ->andReturn(false)
- ->times(3);
-
- parent::testGetWrongWithoutDB();
- }
-
/**
* @dataProvider dataTests
*/
// mocking one get without result
$this->configModel->shouldReceive('get')
- ->with(0, 'test', 'it')
+ ->with(42, 'test', 'it')
->andReturn(null)
->once();
*/
public function testDeleteWithDB()
{
- $this->configCache->load(0, ['test' => ['it' => 'now', 'quarter' => 'true']]);
+ $uid = 42;
+
+ $this->configCache->load($uid, ['test' => ['it' => 'now', 'quarter' => 'true']]);
$this->configModel->shouldReceive('delete')
- ->with(0, 'test', 'it')
+ ->with($uid, 'test', 'it')
->andReturn(false)
->once();
$this->configModel->shouldReceive('delete')
- ->with(0, 'test', 'second')
+ ->with($uid, 'test', 'second')
->andReturn(true)
->once();
$this->configModel->shouldReceive('delete')
- ->with(0, 'test', 'third')
+ ->with($uid, 'test', 'third')
->andReturn(false)
->once();
$this->configModel->shouldReceive('delete')
- ->with(0, 'test', 'quarter')
+ ->with($uid, 'test', 'quarter')
->andReturn(true)
->once();
$this->assertInstanceOf(PConfigCache::class, $this->testedConfig->getCache());
// directly set the value to the cache
- $this->testedConfig->getCache()->set(0, 'test', 'it', 'now');
+ $this->testedConfig->getCache()->set($uid, 'test', 'it', 'now');
- $this->assertEquals('now', $this->testedConfig->get(0, 'test', 'it'));
- $this->assertEquals('now', $this->testedConfig->getCache()->get(0, 'test', 'it'));
+ $this->assertEquals('now', $this->testedConfig->get($uid, 'test', 'it'));
+ $this->assertEquals('now', $this->testedConfig->getCache()->get($uid, 'test', 'it'));
// delete from cache only
- $this->assertTrue($this->testedConfig->delete(0, 'test', 'it'));
+ $this->assertTrue($this->testedConfig->delete($uid, 'test', 'it'));
// delete from db only
- $this->assertTrue($this->testedConfig->delete(0, 'test', 'second'));
+ $this->assertTrue($this->testedConfig->delete($uid, 'test', 'second'));
// no delete
- $this->assertFalse($this->testedConfig->delete(0, 'test', 'third'));
+ $this->assertFalse($this->testedConfig->delete($uid, 'test', 'third'));
// delete both
- $this->assertTrue($this->testedConfig->delete(0, 'test', 'quarter'));
+ $this->assertTrue($this->testedConfig->delete($uid, 'test', 'quarter'));
$this->assertEmpty($this->testedConfig->getCache()->getAll());
}
public function testInvalidUid()
{
// bad UID!
- $uid = null;
+ $uid = 0;
$this->testedConfig = $this->getInstance();
parent::testGetWithRefresh($uid, $data);
}
-
- public function testGetWrongWithoutDB()
- {
- $this->configModel->shouldReceive('isConnected')
- ->andReturn(false)
- ->times(3);
-
- parent::testGetWrongWithoutDB();
- }
-
/**
* @dataProvider dataTests
*/
// constructor loading
$this->configModel->shouldReceive('load')
- ->with(0)
+ ->with(42)
->andReturn(['config' => []])
->once();