Commit 987971ca authored by rjsmelo's avatar rjsmelo

[REF] Code reformat

parent bd5804a7
<?php
// (c) Copyright 2002-2016 by authors of the Tiki Wiki CMS Groupware Project
//
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$
......@@ -10,16 +10,16 @@ class TikiWebdav_Auth_Default extends ezcWebdavBasicAuth implements ezcWebdavAut
protected $tokens;
protected $storageFile;
protected $credentials = array(
protected $credentials = [
'guest' => 'guest'
);
];
public function __construct($storageFile = null)
{
print_debug("Auth_Default: $storageFile\n");
$this->storageFile = $storageFile;
$this->tokens = array();
$this->tokens = [];
if (file_exists($storageFile)) {
$this->tokens = unserialize(file_get_contents($storageFile));
}
......@@ -27,15 +27,16 @@ class TikiWebdav_Auth_Default extends ezcWebdavBasicAuth implements ezcWebdavAut
public function __destruct()
{
if (empty($this->storageFile))
if (empty($this->storageFile)) {
return true;
}
print_debug("Auth_Default __destruct: " . $this->storageFile . "\n");
if ($this->tokens !== array()) {
if ($this->tokens !== []) {
file_put_contents($this->storageFile, serialize($this->tokens));
} else {
print_debug('Auth_Default __destruct: '. serialize($this->tokens). " \n");
print_debug('Auth_Default __destruct: ' . serialize($this->tokens) . " \n");
}
}
}
public function authenticateAnonymous(ezcWebdavAnonymousAuth $data)
{
......@@ -47,10 +48,10 @@ class TikiWebdav_Auth_Default extends ezcWebdavBasicAuth implements ezcWebdavAut
public function authenticateBasic(ezcWebdavBasicAuth $data)
{
global $user, $prefs;
if (!isset($_SESSION['webdav_user'])) {
if (! isset($_SESSION['webdav_user'])) {
if ($data->username === '' or $data->username === 'Anonymous') {
$user = $_SESSION['webdav_user'] = 'Anonymous';
print_debug("Login Anonymous User=".$data->username." Already logged\n");
print_debug("Login Anonymous User=" . $data->username . " Already logged\n");
return true;
}
$userlib = TikiLib::lib('user');
......@@ -63,10 +64,10 @@ class TikiWebdav_Auth_Default extends ezcWebdavBasicAuth implements ezcWebdavAut
$userlib->update_expired_groups();
$user = $_SESSION['webdav_user'] = $data->username;
return $isvalid; ///FIXME
}
}
return false;
} else {
print_debug("Login Basic User=".$data->username." Already logged\n");
print_debug("Login Basic User=" . $data->username . " Already logged\n");
$user = $_SESSION['webdav_user'];
return true;
}
......@@ -75,7 +76,7 @@ class TikiWebdav_Auth_Default extends ezcWebdavBasicAuth implements ezcWebdavAut
public function authenticateDigest(ezcWebdavDigestAuth $data)
{
global $user;
if (!isset($_SESSION['webdav_user'])) {
if (! isset($_SESSION['webdav_user'])) {
if ($data->username === '' or $data->username === 'Anonymous') {
$user = $_SESSION['webdav_user'] = 'Anonymous';
return true;
......@@ -100,12 +101,14 @@ class TikiWebdav_Auth_Default extends ezcWebdavBasicAuth implements ezcWebdavAut
{
global $tikilib;
$filegallib = TikiLib::lib('filegal');
print_debug("Authorize...PATH=$path ACCESS=" . ($access == self::ACCESS_READ?'READ':'WRITE') . "\n");
print_debug("Authorize...PATH=$path ACCESS=" . ($access == self::ACCESS_READ ? 'READ' : 'WRITE') . "\n");
$dir_path = dirname(urldecode($path));
if ($dir_path === '/' && $access === self::ACCESS_READ) return true;
if ($dir_path === '/' && $access === self::ACCESS_READ) {
return true;
}
$fgal = $filegallib->get_objectid_from_virtual_path($dir_path);
$id = $fgal['id'];
if (!$id) {
if (! $id) {
print_debug("Authorize...PATH=$dir_path does not exist\n");
return false;
}
......@@ -113,39 +116,42 @@ class TikiWebdav_Auth_Default extends ezcWebdavBasicAuth implements ezcWebdavAut
$groups = $tikilib->get_user_groups($user);
$perms = Perms::getInstance();
$perms->setGroups($groups);
$perms = Perms::get(array('type'=>'file gallery', 'object'=>$id));
$perms = Perms::get(['type' => 'file gallery', 'object' => $id]);
print_debug("Authorize...PERMS:" . print_r($perms, true) . "\n");
$ret = false;
if ($access === self::ACCESS_READ) {
print_debug("Authorize...READ " . ($perms->view_file_gallery?'OK':'PAS') . " " . ($perms->list_file_gallery?'OK':'PAS') . "\n");
print_debug("Authorize...READ " . ($perms->view_file_gallery ? 'OK' : 'PAS') . " " . ($perms->list_file_gallery ? 'OK' : 'PAS') . "\n");
if ($perms->view_file_gallery || $perms->list_file_gallery) {
$ret = true;
}
} elseif ($access === self::ACCESS_WRITE) {
print_debug("Authorize...WRITE " . ($perms->upload_files?'OK':'PAS') . " " . ($perms->admin_file_galleries?'OK':'PAS') . "\n");
print_debug("Authorize...WRITE " . ($perms->upload_files ? 'OK' : 'PAS') . " " . ($perms->admin_file_galleries ? 'OK' : 'PAS') . "\n");
if ($perms->upload_files || $perms->admin_file_galleries) {
$ret = true;
}
}
print_debug("Authorize...USER=$user PATH=$path " . ($ret?'OK':'PAS OK') . "\n");
print_debug("Authorize...USER=$user PATH=$path " . ($ret ? 'OK' : 'PAS OK') . "\n");
return $ret;
}
public function assignLock($user, $lockToken)
{
if ($user == '')
if ($user == '') {
$user = 'Anonymous';
}
print_debug("Assigning Lock($user, $lockToken)...\n");
if (!isset($this->tokens[$user])) {
$this->tokens[$user] = array();
if (! isset($this->tokens[$user])) {
$this->tokens[$user] = [];
}
$this->tokens[$user][$lockToken] = true;
}
public function ownsLock($user, $lockToken)
{
if ($user == '') $user = 'Anonymous';
if ($user == '') {
$user = 'Anonymous';
}
print_debug("Checking Lock($user, $lockToken): " . (isset($this->tokens[$user][$lockToken]) ? 'OK' : 'NOT OK') . "\n");
return isset($this->tokens[$user][$lockToken]);
}
......@@ -153,8 +159,9 @@ class TikiWebdav_Auth_Default extends ezcWebdavBasicAuth implements ezcWebdavAut
public function releaseLock($user, $lockToken)
{
print_debug("Releasing Lock($user, $lockToken)...\n");
if ($user == '')
if ($user == '') {
$user = 'Anonymous';
}
unset($this->tokens[$user][$lockToken]);
}
}
}
......@@ -21,7 +21,7 @@ class TikiWebdav_Auth_Wiki extends TikiWebdav_Auth_Default
$groups = $tikilib->get_user_groups($user);
$perms = Perms::getInstance();
$perms->setGroups($groups);
$perms = $tikilib->page_exists($page) ? Perms::get(array('type' => 'wiki page', 'object' => substr($path, 1))) : Perms::get();
$perms = $tikilib->page_exists($page) ? Perms::get(['type' => 'wiki page', 'object' => substr($path, 1)]) : Perms::get();
return ($access === self::ACCESS_READ && $perms->view) || ($access === self::ACCESS_WRITE && $perms->edit);
}
......
<?php
// (c) Copyright 2002-2016 by authors of the Tiki Wiki CMS Groupware Project
//
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$
......
This diff is collapsed.
......@@ -11,7 +11,7 @@ class TikiWebdav_Backends_Wiki extends ezcWebdavSimpleBackend
protected $root;
protected $lockLevel = 0;
protected $handledLiveProperties = array(
protected $handledLiveProperties = [
'getcontentlength',
'getlastmodified',
'creationdate',
......@@ -19,7 +19,7 @@ class TikiWebdav_Backends_Wiki extends ezcWebdavSimpleBackend
'getetag',
'getcontenttype',
'resourcetype',
);
];
protected $propertyStorage = null;
......@@ -34,18 +34,18 @@ class TikiWebdav_Backends_Wiki extends ezcWebdavSimpleBackend
// avoid not having a deadlock when trying to acquire WebDav lock
print_debug('Lock Directory: ' . $prefs['fgal_use_dir'] . "\n" . "\n");
if (!empty($prefs['fgal_use_dir']) && file_exists($prefs['fgal_use_dir'])) {
if (! empty($prefs['fgal_use_dir']) && file_exists($prefs['fgal_use_dir'])) {
$this->root = realpath($prefs['fgal_use_dir']);
} else {
$this->root = realpath('temp/');
}
$this->options = new ezcWebdavFileBackendOptions(
array(
[
'lockFileName' => $this->root . '/.webdav_lock',
'waitForLock' => 200000,
'propertyStoragePath' => $this->root,
'noLock' => false )
'noLock' => false ]
);
$this->propertyStorage = new ezcWebdavBasicPropertyStorage();
......@@ -120,7 +120,7 @@ class TikiWebdav_Backends_Wiki extends ezcWebdavSimpleBackend
return $tikilib->create_page($this->get_page_name_from_virtual_path($path), 0, $content, $tikilib->now, "Created from WebDAV", $user, $tikilib->get_ip_address());
}
protected function setResourceContents( $path, $content )
protected function setResourceContents($path, $content)
{
global $user, $tikilib, $prefs;
......@@ -134,7 +134,8 @@ class TikiWebdav_Backends_Wiki extends ezcWebdavSimpleBackend
$this->get_page_name_from_virtual_path($path),
$content,
'Edited from WebDAV',
$user, $tikilib->get_ip_address()
$user,
$tikilib->get_ip_address()
);
}
......@@ -157,7 +158,7 @@ class TikiWebdav_Backends_Wiki extends ezcWebdavSimpleBackend
{
print_debug('getPropertyStorage ' . $path . "\n");
if ( @file_exists($storagePath = $this->options->propertyStoragePath . '/properties-' . md5($path)) ) {
if (@file_exists($storagePath = $this->options->propertyStoragePath . '/properties-' . md5($path))) {
$xml = ezcWebdavServer::getInstance()->xmlTool->createDom(@file_get_contents($storagePath));
} else {
$xml = ezcWebdavServer::getInstance()->xmlTool->createDom();
......@@ -166,7 +167,7 @@ class TikiWebdav_Backends_Wiki extends ezcWebdavSimpleBackend
try {
$handler->extractProperties($xml->getElementsByTagNameNS('DAV:', '*'), $this->propertyStorage);
} catch ( Exception $e ) {
} catch (Exception $e) {
}
return $this->propertyStorage;
......@@ -198,7 +199,7 @@ class TikiWebdav_Backends_Wiki extends ezcWebdavSimpleBackend
return $doc->save($storagePath);
}
public function setProperty( $path, ezcWebdavProperty $property )
public function setProperty($path, ezcWebdavProperty $property)
{
print_debug('setProperty ' . $path . "\n");
......@@ -255,14 +256,14 @@ class TikiWebdav_Backends_Wiki extends ezcWebdavSimpleBackend
print_debug('getProperty ' . $path . ' ' . $propertyName . ' ' . $namespace . "\n");
if (!$this->nodeExists($path)) {
if (! $this->nodeExists($path)) {
return false;
}
$isCollection = $this->isCollection($path);
$tikiInfo = null;
if (!$isCollection) {
if (! $isCollection) {
$tikiInfo = $tikilib->get_page_info($this->get_page_name_from_virtual_path($path));
}
......@@ -323,7 +324,7 @@ class TikiWebdav_Backends_Wiki extends ezcWebdavSimpleBackend
return $property;
case 'supportedlock':
if (!isset($properties[$namespace][$propertyName])) {
if (! isset($properties[$namespace][$propertyName])) {
$property = new ezcWebdavLockDiscoveryProperty();
} else {
$property = $properties[$namespace][$propertyName];
......@@ -332,7 +333,7 @@ class TikiWebdav_Backends_Wiki extends ezcWebdavSimpleBackend
return $property;
case 'lockdiscovery':
if (!isset($properties[$namespace][$propertyName])) {
if (! isset($properties[$namespace][$propertyName])) {
$property = new ezcWebdavLockDiscoveryProperty();
} else {
$property = $properties[$namespace][$propertyName];
......@@ -358,7 +359,7 @@ class TikiWebdav_Backends_Wiki extends ezcWebdavSimpleBackend
{
print_debug('getETag ' . $path . "\n");
if ( $etag = $this->getProperty($path, 'getetag')) {
if ($etag = $this->getProperty($path, 'getetag')) {
return $this->getProperty($path, 'getetag')->etag;
} else {
return md5($path);
......@@ -389,21 +390,21 @@ class TikiWebdav_Backends_Wiki extends ezcWebdavSimpleBackend
$page = $this->get_page_name_from_virtual_path($fromPath);
$info = $tikilib->get_page_info($page);
if (!$info) {
return array(ezcWebdavResponse::STATUS_404);
if (! $info) {
return [ezcWebdavResponse::STATUS_404];
}
$perms = $tikilib->get_perm_object($page, 'wiki page', $info);
if ($perms['tiki_p_edit'] == 'y' && !$this->isCollection($fromPath) && !$this->nodeExists($toPath)) {
if ($perms['tiki_p_edit'] == 'y' && ! $this->isCollection($fromPath) && ! $this->nodeExists($toPath)) {
if ($wikilib->wiki_duplicate_page($page, $this->get_page_name_from_virtual_path($toPath))) {
return array();
return [];
} else {
return array(ezcWebdavResponse::STATUS_500);
return [ezcWebdavResponse::STATUS_500];
}
}
return array(ezcWebdavResponse::STATUS_409);
return [ezcWebdavResponse::STATUS_409];
}
protected function performDelete($path)
......@@ -415,21 +416,21 @@ class TikiWebdav_Backends_Wiki extends ezcWebdavSimpleBackend
$page = $this->get_page_name_from_virtual_path($path);
$info = $tikilib->get_page_info($page);
if (!$info) {
return array(ezcWebdavResponse::STATUS_404);
if (! $info) {
return [ezcWebdavResponse::STATUS_404];
}
$perms = $tikilib->get_perm_object($page, 'wiki page', $info);
if ( $perms['tiki_p_remove'] == 'y' && $perms['tiki_p_edit'] == 'y' && !$this->isCollection($path) ) {
if ($perms['tiki_p_remove'] == 'y' && $perms['tiki_p_edit'] == 'y' && ! $this->isCollection($path)) {
if ($tikilib->remove_all_versions($this->get_page_name_from_virtual_path($path), "Remove from WebDav")) {
return array();
return [];
} else {
return array(ezcWebdavResponse::STATUS_500);
return [ezcWebdavResponse::STATUS_500];
}
}
return array(ezcWebdavResponse::STATUS_409);
return [ezcWebdavResponse::STATUS_409];
}
protected function nodeExists($path)
......@@ -466,7 +467,7 @@ class TikiWebdav_Backends_Wiki extends ezcWebdavSimpleBackend
print_debug('getCollectionMembers ' . $path . "\n");
$contents = array();
$contents = [];
if ($path !== '/') {
return $contents;
......
<?php
// (c) Copyright 2002-2016 by authors of the Tiki Wiki CMS Groupware Project
//
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$
......
<?php
// (c) Copyright 2002-2016 by authors of the Tiki Wiki CMS Groupware Project
//
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$
......@@ -9,7 +9,7 @@ class TikiWebdav_PathFactories_File implements ezcWebdavPathFactory
{
protected $baseUri = '';
protected $baseUriLength = 0;
protected $collectionPathes = array();
protected $collectionPathes = [];
public function parseUriToPath($uri)
{
......
......@@ -9,7 +9,7 @@ class TikiWebdav_PathFactories_Wiki implements ezcWebdavPathFactory
{
protected $baseUri = '';
protected $baseUriLength = 0;
protected $collectionPathes = array();
protected $collectionPathes = [];
public function parseUriToPath($uri)
{
......
<?php
// (c) Copyright 2002-2016 by authors of the Tiki Wiki CMS Groupware Project
//
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$
......
<?php
// (c) Copyright 2002-2016 by authors of the Tiki Wiki CMS Groupware Project
//
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$
......
<?php
// (c) Copyright 2002-2016 by authors of the Tiki Wiki CMS Groupware Project
//
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$
......@@ -8,13 +8,13 @@
require_once 'lib/ezcomponents/Base/src/base.php';
/**
* Autoload ezc classes
*
* @param string $className
* Autoload ezc classes
*
* @param string $className
*/
function webdav_autoload($className)
{
ezcBase::autoload($className);
ezcBase::autoload($className);
}
spl_autoload_register('webdav_autoload');
<?php
// (c) Copyright 2002-2016 by authors of the Tiki Wiki CMS Groupware Project
//
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$
......
This diff is collapsed.
<?php
// (c) Copyright 2002-2016 by authors of the Tiki Wiki CMS Groupware Project
//
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$
......
......@@ -14,30 +14,30 @@ class ActivityLib
$table = $this->rulesTable();
$table->useExceptions();
return $table->fetchAll(
array(
[
'ruleId',
'eventType',
'ruleType',
'rule',
'notes',
),
array()
],
[]
);
}
function getRule($id)
{
return $this->rulesTable()->fetchRow(
array(
[
'ruleId',
'eventType',
'ruleType',
'rule',
'notes',
),
array(
],
[
'ruleId' => $id,
)
]
);
}
......@@ -52,27 +52,27 @@ class ActivityLib
return $this->rulesTable()->insertOrUpdate(
$data,
array(
[
'ruleId' => $id,
)
]
);
}
function deleteRule($id)
{
return $this->rulesTable()->delete(
array(
[
'ruleId' => $id,
)
]
);
}
function deleteActivity($id)
{
$info = $this->streamTable()->delete(
array(
[
'activityId' => $id,
)
]
);
require_once 'lib/search/refresh-functions.php';
refresh_index('activity', $id);
......@@ -82,15 +82,15 @@ class ActivityLib
{
$table = $this->rulesTable();
return $table->deleteMultiple(
array(
[
'ruleId' => $table->notIn($ids),
)
]
);
}
function recordEvent($event, $arguments)
{
if (!$event) {
if (! $event) {
return; // prevent false recording of test runs
}
......@@ -102,11 +102,11 @@ class ActivityLib
}
$id = $this->streamTable()->insert(
array(
[
'eventType' => $event,
'eventDate' => TikiLib::lib('tiki')->now,
'arguments' => json_encode($arguments),
)
]
);
TikiLib::lib('unifiedsearch')->invalidateObject('activity', $id);
......@@ -120,24 +120,24 @@ class ActivityLib
* @param $event
* @param $arguments
*/
function logEvent($event, $arguments, $includes = array(), $excludes = array())
function logEvent($event, $arguments, $includes = [], $excludes = [])
{
if (!$event) {
if (! $event) {
return; // prevent false recording of test runs
}
if ($includes) {
// if includes is provided, then everything is excluded by default
$clean_args = array();
$clean_args = [];
foreach ($arguments as $k => $v) {
if (in_array($k, $includes)) {
$clean_args[$k] = $v;
}
}
} else if ($excludes) {
$clean_args = array();
} elseif ($excludes) {
$clean_args = [];
foreach ($arguments as $k => $v) {
if (!in_array($k, $excludes)) {
if (! in_array($k, $excludes)) {
$clean_args[$k] = $v;
}
}
......@@ -153,13 +153,13 @@ class ActivityLib
function bindBasicEvents(Tiki_Event_Manager $manager)
{
global $prefs;
$map = array(
$map = [
'activity_basic_tracker_create' => 'tiki.trackeritem.create',