$target = stripslashes(rawurldecode($_GET["target"]));
-if(OC_Filesystem::file_exists($target . '/' . $file)){
+if(OC_Filesystem::file_exists($target . '/' . $file)) {
OCP\JSON::error(array("data" => array( "message" => "Could not move $file - File with this name already exists" )));
exit;
}
foreach($files['size'] as $size) {
$totalSize+=$size;
}
-if($totalSize>OC_Filesystem::free_space($dir)){
+if($totalSize>OC_Filesystem::free_space($dir)) {
OCP\JSON::error(array("data" => array( "message" => "Not enough space available" )));
exit();
}
if (version_compare($installedVersion, '1.1.6', '<')) {
$query = OC_DB::prepare( "SELECT `propertyname`, `propertypath`, `userid` FROM `*PREFIX*properties`" );
$result = $query->execute();
- while( $row = $result->fetchRow()){
+ while( $row = $result->fetchRow()) {
if ( $row["propertyname"][0] != '{' ) {
$query = OC_DB::prepare( 'UPDATE `*PREFIX*properties` SET `propertyname` = ? WHERE `userid` = ? AND `propertypath` = ?' );
$query->execute( array( '{DAV:}' + $row["propertyname"], $row["userid"], $row["propertypath"] ));
// We use this function to handle (unexpected) shutdowns
function handleUnexpectedShutdown() {
// Delete lockfile
- if( !my_temporary_cron_class::$keeplock && file_exists( my_temporary_cron_class::$lockfile )){
+ if( !my_temporary_cron_class::$keeplock && file_exists( my_temporary_cron_class::$lockfile )) {
unlink( my_temporary_cron_class::$lockfile );
}
}
// check if backgroundjobs is still running
- if( file_exists( my_temporary_cron_class::$lockfile )){
+ if( file_exists( my_temporary_cron_class::$lockfile )) {
my_temporary_cron_class::$keeplock = true;
my_temporary_cron_class::$sent = true;
echo "Another instance of cron.php is still running!";
* are "none", "ajax", "webcron", "cron"
*/
public static function setExecutionType( $type ) {
- if( !in_array( $type, array('none', 'ajax', 'webcron', 'cron'))){
+ if( !in_array( $type, array('none', 'ajax', 'webcron', 'cron'))) {
return false;
}
return OC_Appconfig::setValue( 'core', 'backgroundjobs_mode', $type );
* trigger an update for the cache by setting the mtimes to 0
* @param string $user (optional)
*/
- public static function triggerUpdate($user=''){
+ public static function triggerUpdate($user='') {
if($user) {
$query=OC_DB::prepare('UPDATE `*PREFIX*fscache` SET `mtime`=0 WHERE `user`=? AND `mimetype`="httpd/unix-directory"');
$query->execute(array($user));
$file=$path.'/'.$filename;
$isDir=$view->is_dir($file);
if(self::hasUpdated($file, $root, $isDir)) {
- if($isDir){
+ if($isDir) {
self::updateFolder($file, $root);
}elseif($root===false) {//filesystem hooks are only valid for the default root
OC_Hook::emit('OC_Filesystem', 'post_write', array('path'=>$file));
}else{
$size=OC_FileCache::scanFile($path, $root);
}
- if($path !== '' and $path !== '/'){
+ if($path !== '' and $path !== '/') {
OC_FileCache::increaseSize(dirname($path), $size-$cachedSize, $root);
}
}
static $rootView;
public function premkdir($path) {
- if(!self::$rootView){
+ if(!self::$rootView) {
self::$rootView = new OC_FilesystemView('');
}
return !self::$rootView->file_exists($path);
}
public function preCopy($path1, $path2) {
- if(!self::$rootView){
+ if(!self::$rootView) {
self::$rootView = new OC_FilesystemView('');
}
return (self::$rootView->filesize($path1)<$this->getFreeSpace($path2) or $this->getFreeSpace($path2)==0);
if(strstr($path, '/../') || strrchr($path, '/') === '/..' ) {
return false;
}
- if(self::isFileBlacklisted($path)){
+ if(self::isFileBlacklisted($path)) {
return false;
}
return true;
}
}
- static public function isFileBlacklisted($path){
+ static public function isFileBlacklisted($path) {
$blacklist = array('.htaccess');
$filename = strtolower(basename($path));
return in_array($filename, $blacklist);
return $this->basicOperation('filemtime', $path);
}
public function touch($path, $mtime=null) {
- if(!is_null($mtime) and !is_numeric($mtime)){
+ if(!is_null($mtime) and !is_numeric($mtime)) {
$mtime = strtotime($mtime);
}
return $this->basicOperation('touch', $path, array('write'), $mtime);
$path = $this->getRelativePath($absolutePath);
$exists = $this->file_exists($path);
$run = true;
- if( $this->fakeRoot==OC_Filesystem::getRoot() ){
+ if( $this->fakeRoot==OC_Filesystem::getRoot() ) {
if(!$exists) {
OC_Hook::emit(
OC_Filesystem::CLASSNAME,
$count=OC_Helper::streamCopy($data, $target);
fclose($target);
fclose($data);
- if( $this->fakeRoot==OC_Filesystem::getRoot() ){
+ if( $this->fakeRoot==OC_Filesystem::getRoot() ) {
if(!$exists) {
OC_Hook::emit(
OC_Filesystem::CLASSNAME,
return false;
}
$run=true;
- if( $this->fakeRoot==OC_Filesystem::getRoot() ){
+ if( $this->fakeRoot==OC_Filesystem::getRoot() ) {
OC_Hook::emit(
OC_Filesystem::CLASSNAME, OC_Filesystem::signal_rename,
array(
$storage1->unlink($this->getInternalPath($path1.$postFix1));
$result = $count>0;
}
- if( $this->fakeRoot==OC_Filesystem::getRoot() ){
+ if( $this->fakeRoot==OC_Filesystem::getRoot() ) {
OC_Hook::emit(
OC_Filesystem::CLASSNAME,
OC_Filesystem::signal_post_rename,
return false;
}
$run=true;
- if( $this->fakeRoot==OC_Filesystem::getRoot() ){
+ if( $this->fakeRoot==OC_Filesystem::getRoot() ) {
OC_Hook::emit(
OC_Filesystem::CLASSNAME,
OC_Filesystem::signal_copy,
$target = $this->fopen($path2.$postFix2, 'w');
$result = OC_Helper::streamCopy($source, $target);
}
- if( $this->fakeRoot==OC_Filesystem::getRoot() ){
+ if( $this->fakeRoot==OC_Filesystem::getRoot() ) {
OC_Hook::emit(
OC_Filesystem::CLASSNAME,
OC_Filesystem::signal_post_copy,
$dirs = explode(PATH_SEPARATOR, $path);
// WARNING : We have to check if open_basedir is enabled :
$obd = ini_get('open_basedir');
- if($obd != "none"){
+ if($obd != "none") {
$obd_values = explode(PATH_SEPARATOR, $obd);
- if(count($obd_values) > 0 and $obd_values[0]){
+ if(count($obd_values) > 0 and $obd_values[0]) {
// open_basedir is in effect !
// We need to check if the program is in one of these dirs :
$dirs = $obd_values;
}
}
- foreach($dirs as $dir){
- foreach($exts as $ext){
+ foreach($dirs as $dir) {
+ foreach($exts as $ext) {
if($check_fn("$dir/$name".$ext))
return true;
}
}
//Fatal errors handler
- public static function onShutdown(){
+ public static function onShutdown() {
$error = error_get_last();
if($error) {
//ob_end_clean();
}
// Uncaught exception handler
- public static function onException($exception){
+ public static function onException($exception) {
self::write('PHP', $exception->getMessage() . ' at ' . $exception->getFile() . '#' . $exception->getLine(), self::FATAL);
}
//Recoverable errors handler
- public static function onError($number, $message, $file, $line){
+ public static function onError($number, $message, $file, $line) {
if (error_reporting() === 0) {
return;
}
if( self::$exporttype == 'user' ) {
// Check user exists
self::$uid = is_null($uid) ? OC_User::getUser() : $uid;
- if(!OC_User::userExists(self::$uid)){
+ if(!OC_User::userExists(self::$uid)) {
return json_encode( array( 'success' => false) );
}
}
if( !is_null( $this->db ) ) {
// Get db path
$db = $this->db->getDatabase();
- if(!in_array($db, $this->tmpfiles)){
+ if(!in_array($db, $this->tmpfiles)) {
$this->tmpfiles[] = $db;
}
}
public function getRoutingFiles() {
if (!isset($this->routing_files)) {
$this->routing_files = array();
- foreach(OC_APP::getEnabledApps() as $app){
+ foreach(OC_APP::getEnabledApps() as $app) {
$file = OC_App::getAppPath($app).'/appinfo/routes.php';
if(file_exists($file)) {
$this->routing_files[$app] = $file;
if(empty($options['dbname'])) {
$error[] = "$dbprettyname enter the database name.";
}
- if(substr_count($options['dbname'], '.') >= 1){
+ if(substr_count($options['dbname'], '.') >= 1) {
$error[] = "$dbprettyname you may not use dots in the database name";
}
if($dbtype != 'oci' && empty($options['dbhost'])) {
* Prints an XSS escaped string
* @param string $string the string which will be escaped and printed
*/
-function p($string){
+function p($string) {
print(OC_Util::sanitizeHTML($string));
}
* Prints an unescaped string
* @param string $string the string which will be printed as it is
*/
-function print_unescaped($string){
+function print_unescaped($string) {
print($string);
}
require_once __DIR__.'/../lib/base.php';
-if(!class_exists('PHPUnit_Framework_TestCase')){
+if(!class_exists('PHPUnit_Framework_TestCase')) {
require_once('PHPUnit/Autoload.php');
}
//SimpleTest compatibility
abstract class UnitTestCase extends PHPUnit_Framework_TestCase{
- function assertEqual($expected, $actual, $string=''){
+ function assertEqual($expected, $actual, $string='') {
$this->assertEquals($expected, $actual, $string);
}
- function assertNotEqual($expected, $actual, $string=''){
+ function assertNotEqual($expected, $actual, $string='') {
$this->assertNotEquals($expected, $actual, $string);
}
- static function assertTrue($actual, $string=''){
+ static function assertTrue($actual, $string='') {
parent::assertTrue((bool)$actual, $string);
}
- static function assertFalse($actual, $string=''){
+ static function assertFalse($actual, $string='') {
parent::assertFalse((bool)$actual, $string);
}
}
protected $instance;
public function tearDown() {
- if($this->instance){
+ if($this->instance) {
$this->instance->clear();
}
}
class Test_Cache_APC extends Test_Cache {
public function setUp() {
- if(!extension_loaded('apc')){
+ if(!extension_loaded('apc')) {
$this->markTestSkipped('The apc extension is not available.');
return;
}
- if(!ini_get('apc.enable_cli') && OC::$CLI){
+ if(!ini_get('apc.enable_cli') && OC::$CLI) {
$this->markTestSkipped('apc not available in CLI.');
return;
}
class Test_Cache_XCache extends Test_Cache {
public function setUp() {
- if(!function_exists('xcache_get')){
+ if(!function_exists('xcache_get')) {
$this->markTestSkipped('The xcache extension is not available.');
return;
}
class Test_TemplateFunctions extends UnitTestCase {
- public function testP(){
+ public function testP() {
// FIXME: do we need more testcases?
$htmlString = "<script>alert('xss');</script>";
ob_start();
$this->assertEqual("<script>alert('xss');</script>", $result);
}
- public function testPNormalString(){
+ public function testPNormalString() {
$normalString = "This is a good string!";
ob_start();
p($normalString);
}
- public function testPrintUnescaped(){
+ public function testPrintUnescaped() {
$htmlString = "<script>alert('xss');</script>";
ob_start();
$this->assertEqual($htmlString, $result);
}
- public function testPrintUnescapedNormalString(){
+ public function testPrintUnescapedNormalString() {
$normalString = "This is a good string!";
ob_start();
print_unescaped($normalString);