From f71fec8cdcb5d7d24b7dfa30dfaf24c5115e51c1 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Mon, 14 May 2012 17:57:43 +0200 Subject: Combine and minimize core and default app css files --- lib/app.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib/app.php') diff --git a/lib/app.php b/lib/app.php index f274194b25c..39e90ada019 100644 --- a/lib/app.php +++ b/lib/app.php @@ -73,6 +73,12 @@ class OC_App{ self::$init = true; + if (!defined('DEBUG') || !DEBUG){ + if (is_null($types)) { + OC_Util::$core_styles = OC_Util::$styles; + OC_Util::$styles = array(); + } + } // return return true; } -- cgit v1.2.3 From ce1e4425c2fc96f581428207edab040e42387bbc Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Mon, 14 May 2012 23:15:53 +0200 Subject: Combine and minimize core and default app js files --- 3rdparty/mediawiki/JavaScriptMinifier.php | 606 ++++++++++++++++++++++++++++++ core/minimizer.php | 13 +- core/templates/layout.guest.php | 3 + core/templates/layout.user.php | 3 + lib/app.php | 2 + lib/base.php | 1 + lib/minimizer/js.php | 62 +++ lib/util.php | 1 + 8 files changed, 688 insertions(+), 3 deletions(-) create mode 100644 3rdparty/mediawiki/JavaScriptMinifier.php create mode 100644 lib/minimizer/js.php (limited to 'lib/app.php') diff --git a/3rdparty/mediawiki/JavaScriptMinifier.php b/3rdparty/mediawiki/JavaScriptMinifier.php new file mode 100644 index 00000000000..db5326c7cfb --- /dev/null +++ b/3rdparty/mediawiki/JavaScriptMinifier.php @@ -0,0 +1,606 @@ + + * @license Choose any of Apache, MIT, GPL, LGPL + */ + +/** + * This class is meant to safely minify javascript code, while leaving syntactically correct + * programs intact. Other libraries, such as JSMin require a certain coding style to work + * correctly. OTOH, libraries like jsminplus, that do parse the code correctly are rather + * slow, because they construct a complete parse tree before outputting the code minified. + * So this class is meant to allow arbitrary (but syntactically correct) input, while being + * fast enough to be used for on-the-fly minifying. + */ +class JavaScriptMinifier { + + /* Class constants */ + /* Parsing states. + * The state machine is only necessary to decide whether to parse a slash as division + * operator or as regexp literal. + * States are named after the next expected item. We only distinguish states when the + * distinction is relevant for our purpose. + */ + const STATEMENT = 0; + const CONDITION = 1; + const PROPERTY_ASSIGNMENT = 2; + const EXPRESSION = 3; + const EXPRESSION_NO_NL = 4; // only relevant for semicolon insertion + const EXPRESSION_OP = 5; + const EXPRESSION_FUNC = 6; + const EXPRESSION_TERNARY = 7; // used to determine the role of a colon + const EXPRESSION_TERNARY_OP = 8; + const EXPRESSION_TERNARY_FUNC = 9; + const PAREN_EXPRESSION = 10; // expression which is not on the top level + const PAREN_EXPRESSION_OP = 11; + const PAREN_EXPRESSION_FUNC = 12; + const PROPERTY_EXPRESSION = 13; // expression which is within an object literal + const PROPERTY_EXPRESSION_OP = 14; + const PROPERTY_EXPRESSION_FUNC = 15; + + /* Token types */ + const TYPE_UN_OP = 1; // unary operators + const TYPE_INCR_OP = 2; // ++ and -- + const TYPE_BIN_OP = 3; // binary operators + const TYPE_ADD_OP = 4; // + and - which can be either unary or binary ops + const TYPE_HOOK = 5; // ? + const TYPE_COLON = 6; // : + const TYPE_COMMA = 7; // , + const TYPE_SEMICOLON = 8; // ; + const TYPE_BRACE_OPEN = 9; // { + const TYPE_BRACE_CLOSE = 10; // } + const TYPE_PAREN_OPEN = 11; // ( and [ + const TYPE_PAREN_CLOSE = 12; // ) and ] + const TYPE_RETURN = 13; // keywords: break, continue, return, throw + const TYPE_IF = 14; // keywords: catch, for, with, switch, while, if + const TYPE_DO = 15; // keywords: case, var, finally, else, do, try + const TYPE_FUNC = 16; // keywords: function + const TYPE_LITERAL = 17; // all literals, identifiers and unrecognised tokens + + // Sanity limit to avoid excessive memory usage + const STACK_LIMIT = 1000; + + /* Static functions */ + + /** + * Returns minified JavaScript code. + * + * NOTE: $maxLineLength isn't a strict maximum. Longer lines will be produced when + * literals (e.g. quoted strings) longer than $maxLineLength are encountered + * or when required to guard against semicolon insertion. + * + * @param $s String JavaScript code to minify + * @param $statementsOnOwnLine Bool Whether to put each statement on its own line + * @param $maxLineLength Int Maximum length of a single line, or -1 for no maximum. + * @return String Minified code + */ + public static function minify( $s, $statementsOnOwnLine = false, $maxLineLength = 1000 ) { + // First we declare a few tables that contain our parsing rules + + // $opChars : characters, which can be combined without whitespace in between them + $opChars = array( + '!' => true, + '"' => true, + '%' => true, + '&' => true, + "'" => true, + '(' => true, + ')' => true, + '*' => true, + '+' => true, + ',' => true, + '-' => true, + '.' => true, + '/' => true, + ':' => true, + ';' => true, + '<' => true, + '=' => true, + '>' => true, + '?' => true, + '[' => true, + ']' => true, + '^' => true, + '{' => true, + '|' => true, + '}' => true, + '~' => true + ); + + // $tokenTypes : maps keywords and operators to their corresponding token type + $tokenTypes = array( + '!' => self::TYPE_UN_OP, + '~' => self::TYPE_UN_OP, + 'delete' => self::TYPE_UN_OP, + 'new' => self::TYPE_UN_OP, + 'typeof' => self::TYPE_UN_OP, + 'void' => self::TYPE_UN_OP, + '++' => self::TYPE_INCR_OP, + '--' => self::TYPE_INCR_OP, + '!=' => self::TYPE_BIN_OP, + '!==' => self::TYPE_BIN_OP, + '%' => self::TYPE_BIN_OP, + '%=' => self::TYPE_BIN_OP, + '&' => self::TYPE_BIN_OP, + '&&' => self::TYPE_BIN_OP, + '&=' => self::TYPE_BIN_OP, + '*' => self::TYPE_BIN_OP, + '*=' => self::TYPE_BIN_OP, + '+=' => self::TYPE_BIN_OP, + '-=' => self::TYPE_BIN_OP, + '.' => self::TYPE_BIN_OP, + '/' => self::TYPE_BIN_OP, + '/=' => self::TYPE_BIN_OP, + '<' => self::TYPE_BIN_OP, + '<<' => self::TYPE_BIN_OP, + '<<=' => self::TYPE_BIN_OP, + '<=' => self::TYPE_BIN_OP, + '=' => self::TYPE_BIN_OP, + '==' => self::TYPE_BIN_OP, + '===' => self::TYPE_BIN_OP, + '>' => self::TYPE_BIN_OP, + '>=' => self::TYPE_BIN_OP, + '>>' => self::TYPE_BIN_OP, + '>>=' => self::TYPE_BIN_OP, + '>>>' => self::TYPE_BIN_OP, + '>>>=' => self::TYPE_BIN_OP, + '^' => self::TYPE_BIN_OP, + '^=' => self::TYPE_BIN_OP, + '|' => self::TYPE_BIN_OP, + '|=' => self::TYPE_BIN_OP, + '||' => self::TYPE_BIN_OP, + 'in' => self::TYPE_BIN_OP, + 'instanceof' => self::TYPE_BIN_OP, + '+' => self::TYPE_ADD_OP, + '-' => self::TYPE_ADD_OP, + '?' => self::TYPE_HOOK, + ':' => self::TYPE_COLON, + ',' => self::TYPE_COMMA, + ';' => self::TYPE_SEMICOLON, + '{' => self::TYPE_BRACE_OPEN, + '}' => self::TYPE_BRACE_CLOSE, + '(' => self::TYPE_PAREN_OPEN, + '[' => self::TYPE_PAREN_OPEN, + ')' => self::TYPE_PAREN_CLOSE, + ']' => self::TYPE_PAREN_CLOSE, + 'break' => self::TYPE_RETURN, + 'continue' => self::TYPE_RETURN, + 'return' => self::TYPE_RETURN, + 'throw' => self::TYPE_RETURN, + 'catch' => self::TYPE_IF, + 'for' => self::TYPE_IF, + 'if' => self::TYPE_IF, + 'switch' => self::TYPE_IF, + 'while' => self::TYPE_IF, + 'with' => self::TYPE_IF, + 'case' => self::TYPE_DO, + 'do' => self::TYPE_DO, + 'else' => self::TYPE_DO, + 'finally' => self::TYPE_DO, + 'try' => self::TYPE_DO, + 'var' => self::TYPE_DO, + 'function' => self::TYPE_FUNC + ); + + // $goto : This is the main table for our state machine. For every state/token pair + // the following state is defined. When no rule exists for a given pair, + // the state is left unchanged. + $goto = array( + self::STATEMENT => array( + self::TYPE_UN_OP => self::EXPRESSION, + self::TYPE_INCR_OP => self::EXPRESSION, + self::TYPE_ADD_OP => self::EXPRESSION, + self::TYPE_PAREN_OPEN => self::PAREN_EXPRESSION, + self::TYPE_RETURN => self::EXPRESSION_NO_NL, + self::TYPE_IF => self::CONDITION, + self::TYPE_FUNC => self::CONDITION, + self::TYPE_LITERAL => self::EXPRESSION_OP + ), + self::CONDITION => array( + self::TYPE_PAREN_OPEN => self::PAREN_EXPRESSION + ), + self::PROPERTY_ASSIGNMENT => array( + self::TYPE_COLON => self::PROPERTY_EXPRESSION, + self::TYPE_BRACE_OPEN => self::STATEMENT + ), + self::EXPRESSION => array( + self::TYPE_SEMICOLON => self::STATEMENT, + self::TYPE_BRACE_OPEN => self::PROPERTY_ASSIGNMENT, + self::TYPE_PAREN_OPEN => self::PAREN_EXPRESSION, + self::TYPE_FUNC => self::EXPRESSION_FUNC, + self::TYPE_LITERAL => self::EXPRESSION_OP + ), + self::EXPRESSION_NO_NL => array( + self::TYPE_SEMICOLON => self::STATEMENT, + self::TYPE_BRACE_OPEN => self::PROPERTY_ASSIGNMENT, + self::TYPE_PAREN_OPEN => self::PAREN_EXPRESSION, + self::TYPE_FUNC => self::EXPRESSION_FUNC, + self::TYPE_LITERAL => self::EXPRESSION_OP + ), + self::EXPRESSION_OP => array( + self::TYPE_BIN_OP => self::EXPRESSION, + self::TYPE_ADD_OP => self::EXPRESSION, + self::TYPE_HOOK => self::EXPRESSION_TERNARY, + self::TYPE_COLON => self::STATEMENT, + self::TYPE_COMMA => self::EXPRESSION, + self::TYPE_SEMICOLON => self::STATEMENT, + self::TYPE_PAREN_OPEN => self::PAREN_EXPRESSION + ), + self::EXPRESSION_FUNC => array( + self::TYPE_BRACE_OPEN => self::STATEMENT + ), + self::EXPRESSION_TERNARY => array( + self::TYPE_BRACE_OPEN => self::PROPERTY_ASSIGNMENT, + self::TYPE_PAREN_OPEN => self::PAREN_EXPRESSION, + self::TYPE_FUNC => self::EXPRESSION_TERNARY_FUNC, + self::TYPE_LITERAL => self::EXPRESSION_TERNARY_OP + ), + self::EXPRESSION_TERNARY_OP => array( + self::TYPE_BIN_OP => self::EXPRESSION_TERNARY, + self::TYPE_ADD_OP => self::EXPRESSION_TERNARY, + self::TYPE_HOOK => self::EXPRESSION_TERNARY, + self::TYPE_COMMA => self::EXPRESSION_TERNARY, + self::TYPE_PAREN_OPEN => self::PAREN_EXPRESSION + ), + self::EXPRESSION_TERNARY_FUNC => array( + self::TYPE_BRACE_OPEN => self::STATEMENT + ), + self::PAREN_EXPRESSION => array( + self::TYPE_BRACE_OPEN => self::PROPERTY_ASSIGNMENT, + self::TYPE_PAREN_OPEN => self::PAREN_EXPRESSION, + self::TYPE_FUNC => self::PAREN_EXPRESSION_FUNC, + self::TYPE_LITERAL => self::PAREN_EXPRESSION_OP + ), + self::PAREN_EXPRESSION_OP => array( + self::TYPE_BIN_OP => self::PAREN_EXPRESSION, + self::TYPE_ADD_OP => self::PAREN_EXPRESSION, + self::TYPE_HOOK => self::PAREN_EXPRESSION, + self::TYPE_COLON => self::PAREN_EXPRESSION, + self::TYPE_COMMA => self::PAREN_EXPRESSION, + self::TYPE_SEMICOLON => self::PAREN_EXPRESSION, + self::TYPE_PAREN_OPEN => self::PAREN_EXPRESSION + ), + self::PAREN_EXPRESSION_FUNC => array( + self::TYPE_BRACE_OPEN => self::STATEMENT + ), + self::PROPERTY_EXPRESSION => array( + self::TYPE_BRACE_OPEN => self::PROPERTY_ASSIGNMENT, + self::TYPE_PAREN_OPEN => self::PAREN_EXPRESSION, + self::TYPE_FUNC => self::PROPERTY_EXPRESSION_FUNC, + self::TYPE_LITERAL => self::PROPERTY_EXPRESSION_OP + ), + self::PROPERTY_EXPRESSION_OP => array( + self::TYPE_BIN_OP => self::PROPERTY_EXPRESSION, + self::TYPE_ADD_OP => self::PROPERTY_EXPRESSION, + self::TYPE_HOOK => self::PROPERTY_EXPRESSION, + self::TYPE_COMMA => self::PROPERTY_ASSIGNMENT, + self::TYPE_PAREN_OPEN => self::PAREN_EXPRESSION + ), + self::PROPERTY_EXPRESSION_FUNC => array( + self::TYPE_BRACE_OPEN => self::STATEMENT + ) + ); + + // $push : This table contains the rules for when to push a state onto the stack. + // The pushed state is the state to return to when the corresponding + // closing token is found + $push = array( + self::STATEMENT => array( + self::TYPE_BRACE_OPEN => self::STATEMENT, + self::TYPE_PAREN_OPEN => self::EXPRESSION_OP + ), + self::CONDITION => array( + self::TYPE_PAREN_OPEN => self::STATEMENT + ), + self::PROPERTY_ASSIGNMENT => array( + self::TYPE_BRACE_OPEN => self::PROPERTY_ASSIGNMENT + ), + self::EXPRESSION => array( + self::TYPE_BRACE_OPEN => self::EXPRESSION_OP, + self::TYPE_PAREN_OPEN => self::EXPRESSION_OP + ), + self::EXPRESSION_NO_NL => array( + self::TYPE_BRACE_OPEN => self::EXPRESSION_OP, + self::TYPE_PAREN_OPEN => self::EXPRESSION_OP + ), + self::EXPRESSION_OP => array( + self::TYPE_HOOK => self::EXPRESSION, + self::TYPE_PAREN_OPEN => self::EXPRESSION_OP + ), + self::EXPRESSION_FUNC => array( + self::TYPE_BRACE_OPEN => self::EXPRESSION_OP + ), + self::EXPRESSION_TERNARY => array( + self::TYPE_BRACE_OPEN => self::EXPRESSION_TERNARY_OP, + self::TYPE_PAREN_OPEN => self::EXPRESSION_TERNARY_OP + ), + self::EXPRESSION_TERNARY_OP => array( + self::TYPE_HOOK => self::EXPRESSION_TERNARY, + self::TYPE_PAREN_OPEN => self::EXPRESSION_TERNARY_OP + ), + self::EXPRESSION_TERNARY_FUNC => array( + self::TYPE_BRACE_OPEN => self::EXPRESSION_TERNARY_OP + ), + self::PAREN_EXPRESSION => array( + self::TYPE_BRACE_OPEN => self::PAREN_EXPRESSION_OP, + self::TYPE_PAREN_OPEN => self::PAREN_EXPRESSION_OP + ), + self::PAREN_EXPRESSION_OP => array( + self::TYPE_PAREN_OPEN => self::PAREN_EXPRESSION_OP + ), + self::PAREN_EXPRESSION_FUNC => array( + self::TYPE_BRACE_OPEN => self::PAREN_EXPRESSION_OP + ), + self::PROPERTY_EXPRESSION => array( + self::TYPE_BRACE_OPEN => self::PROPERTY_EXPRESSION_OP, + self::TYPE_PAREN_OPEN => self::PROPERTY_EXPRESSION_OP + ), + self::PROPERTY_EXPRESSION_OP => array( + self::TYPE_PAREN_OPEN => self::PROPERTY_EXPRESSION_OP + ), + self::PROPERTY_EXPRESSION_FUNC => array( + self::TYPE_BRACE_OPEN => self::PROPERTY_EXPRESSION_OP + ) + ); + + // $pop : Rules for when to pop a state from the stack + $pop = array( + self::STATEMENT => array( self::TYPE_BRACE_CLOSE => true ), + self::PROPERTY_ASSIGNMENT => array( self::TYPE_BRACE_CLOSE => true ), + self::EXPRESSION => array( self::TYPE_BRACE_CLOSE => true ), + self::EXPRESSION_NO_NL => array( self::TYPE_BRACE_CLOSE => true ), + self::EXPRESSION_OP => array( self::TYPE_BRACE_CLOSE => true ), + self::EXPRESSION_TERNARY_OP => array( self::TYPE_COLON => true ), + self::PAREN_EXPRESSION => array( self::TYPE_PAREN_CLOSE => true ), + self::PAREN_EXPRESSION_OP => array( self::TYPE_PAREN_CLOSE => true ), + self::PROPERTY_EXPRESSION => array( self::TYPE_BRACE_CLOSE => true ), + self::PROPERTY_EXPRESSION_OP => array( self::TYPE_BRACE_CLOSE => true ) + ); + + // $semicolon : Rules for when a semicolon insertion is appropriate + $semicolon = array( + self::EXPRESSION_NO_NL => array( + self::TYPE_UN_OP => true, + self::TYPE_INCR_OP => true, + self::TYPE_ADD_OP => true, + self::TYPE_BRACE_OPEN => true, + self::TYPE_PAREN_OPEN => true, + self::TYPE_RETURN => true, + self::TYPE_IF => true, + self::TYPE_DO => true, + self::TYPE_FUNC => true, + self::TYPE_LITERAL => true + ), + self::EXPRESSION_OP => array( + self::TYPE_UN_OP => true, + self::TYPE_INCR_OP => true, + self::TYPE_BRACE_OPEN => true, + self::TYPE_RETURN => true, + self::TYPE_IF => true, + self::TYPE_DO => true, + self::TYPE_FUNC => true, + self::TYPE_LITERAL => true + ) + ); + + // Rules for when newlines should be inserted if + // $statementsOnOwnLine is enabled. + // $newlineBefore is checked before switching state, + // $newlineAfter is checked after + $newlineBefore = array( + self::STATEMENT => array( + self::TYPE_BRACE_CLOSE => true, + ), + ); + $newlineAfter = array( + self::STATEMENT => array( + self::TYPE_BRACE_OPEN => true, + self::TYPE_PAREN_CLOSE => true, + self::TYPE_SEMICOLON => true, + ), + ); + + // $divStates : Contains all states that can be followed by a division operator + $divStates = array( + self::EXPRESSION_OP => true, + self::EXPRESSION_TERNARY_OP => true, + self::PAREN_EXPRESSION_OP => true, + self::PROPERTY_EXPRESSION_OP => true + ); + + // Here's where the minifying takes place: Loop through the input, looking for tokens + // and output them to $out, taking actions to the above defined rules when appropriate. + $out = ''; + $pos = 0; + $length = strlen( $s ); + $lineLength = 0; + $newlineFound = true; + $state = self::STATEMENT; + $stack = array(); + $last = ';'; // Pretend that we have seen a semicolon yet + while( $pos < $length ) { + // First, skip over any whitespace and multiline comments, recording whether we + // found any newline character + $skip = strspn( $s, " \t\n\r\xb\xc", $pos ); + if( !$skip ) { + $ch = $s[$pos]; + if( $ch === '/' && substr( $s, $pos, 2 ) === '/*' ) { + // Multiline comment. Search for the end token or EOT. + $end = strpos( $s, '*/', $pos + 2 ); + $skip = $end === false ? $length - $pos : $end - $pos + 2; + } + } + if( $skip ) { + // The semicolon insertion mechanism needs to know whether there was a newline + // between two tokens, so record it now. + if( !$newlineFound && strcspn( $s, "\r\n", $pos, $skip ) !== $skip ) { + $newlineFound = true; + } + $pos += $skip; + continue; + } + // Handle C++-style comments and html comments, which are treated as single line + // comments by the browser, regardless of whether the end tag is on the same line. + // Handle --> the same way, but only if it's at the beginning of the line + if( ( $ch === '/' && substr( $s, $pos, 2 ) === '//' ) + || ( $ch === '<' && substr( $s, $pos, 4 ) === '' ) + ) { + $pos += strcspn( $s, "\r\n", $pos ); + continue; + } + + // Find out which kind of token we're handling. $end will point past the end of it. + $end = $pos + 1; + // Handle string literals + if( $ch === "'" || $ch === '"' ) { + // Search to the end of the string literal, skipping over backslash escapes + $search = $ch . '\\'; + do{ + $end += strcspn( $s, $search, $end ) + 2; + } while( $end - 2 < $length && $s[$end - 2] === '\\' ); + $end--; + // We have to distinguish between regexp literals and division operators + // A division operator is only possible in certain states + } elseif( $ch === '/' && !isset( $divStates[$state] ) ) { + // Regexp literal, search to the end, skipping over backslash escapes and + // character classes + for( ; ; ) { + do{ + $end += strcspn( $s, '/[\\', $end ) + 2; + } while( $end - 2 < $length && $s[$end - 2] === '\\' ); + $end--; + if( $end - 1 >= $length || $s[$end - 1] === '/' ) { + break; + } + do{ + $end += strcspn( $s, ']\\', $end ) + 2; + } while( $end - 2 < $length && $s[$end - 2] === '\\' ); + $end--; + }; + // Search past the regexp modifiers (gi) + while( $end < $length && ctype_alpha( $s[$end] ) ) { + $end++; + } + } elseif( + $ch === '0' + && ($pos + 1 < $length) && ($s[$pos + 1] === 'x' || $s[$pos + 1] === 'X' ) + ) { + // Hex numeric literal + $end++; // x or X + $len = strspn( $s, '0123456789ABCDEFabcdef', $end ); + if ( !$len ) { + return self::parseError($s, $pos, 'Expected a hexadecimal number but found ' . substr( $s, $pos, 5 ) . '...' ); + } + $end += $len; + } elseif( + ctype_digit( $ch ) + || ( $ch === '.' && $pos + 1 < $length && ctype_digit( $s[$pos + 1] ) ) + ) { + $end += strspn( $s, '0123456789', $end ); + $decimal = strspn( $s, '.', $end ); + if ($decimal) { + if ( $decimal > 2 ) { + return self::parseError($s, $end, 'The number has too many decimal points' ); + } + $end += strspn( $s, '0123456789', $end + 1 ) + $decimal; + } + $exponent = strspn( $s, 'eE', $end ); + if( $exponent ) { + if ( $exponent > 1 ) { + return self::parseError($s, $end, 'Number with several E' ); + } + $end++; + + // + sign is optional; - sign is required. + $end += strspn( $s, '-+', $end ); + $len = strspn( $s, '0123456789', $end ); + if ( !$len ) { + return self::parseError($s, $pos, 'No decimal digits after e, how many zeroes should be added?' ); + } + $end += $len; + } + } elseif( isset( $opChars[$ch] ) ) { + // Punctuation character. Search for the longest matching operator. + while( + $end < $length + && isset( $tokenTypes[substr( $s, $pos, $end - $pos + 1 )] ) + ) { + $end++; + } + } else { + // Identifier or reserved word. Search for the end by excluding whitespace and + // punctuation. + $end += strcspn( $s, " \t\n.;,=<>+-{}()[]?:*/%'\"!&|^~\xb\xc\r", $end ); + } + + // Now get the token type from our type array + $token = substr( $s, $pos, $end - $pos ); // so $end - $pos == strlen( $token ) + $type = isset( $tokenTypes[$token] ) ? $tokenTypes[$token] : self::TYPE_LITERAL; + + if( $newlineFound && isset( $semicolon[$state][$type] ) ) { + // This token triggers the semicolon insertion mechanism of javascript. While we + // could add the ; token here ourselves, keeping the newline has a few advantages. + $out .= "\n"; + $state = self::STATEMENT; + $lineLength = 0; + } elseif( $maxLineLength > 0 && $lineLength + $end - $pos > $maxLineLength && + !isset( $semicolon[$state][$type] ) && $type !== self::TYPE_INCR_OP ) + { + // This line would get too long if we added $token, so add a newline first. + // Only do this if it won't trigger semicolon insertion and if it won't + // put a postfix increment operator on its own line, which is illegal in js. + $out .= "\n"; + $lineLength = 0; + // Check, whether we have to separate the token from the last one with whitespace + } elseif( !isset( $opChars[$last] ) && !isset( $opChars[$ch] ) ) { + $out .= ' '; + $lineLength++; + // Don't accidentally create ++, -- or // tokens + } elseif( $last === $ch && ( $ch === '+' || $ch === '-' || $ch === '/' ) ) { + $out .= ' '; + $lineLength++; + } + + $out .= $token; + $lineLength += $end - $pos; // += strlen( $token ) + $last = $s[$end - 1]; + $pos = $end; + $newlineFound = false; + + // Output a newline after the token if required + // This is checked before AND after switching state + $newlineAdded = false; + if ( $statementsOnOwnLine && !$newlineAdded && isset( $newlineBefore[$state][$type] ) ) { + $out .= "\n"; + $lineLength = 0; + $newlineAdded = true; + } + + // Now that we have output our token, transition into the new state. + if( isset( $push[$state][$type] ) && count( $stack ) < self::STACK_LIMIT ) { + $stack[] = $push[$state][$type]; + } + if( $stack && isset( $pop[$state][$type] ) ) { + $state = array_pop( $stack ); + } elseif( isset( $goto[$state][$type] ) ) { + $state = $goto[$state][$type]; + } + + // Check for newline insertion again + if ( $statementsOnOwnLine && !$newlineAdded && isset( $newlineAfter[$state][$type] ) ) { + $out .= "\n"; + $lineLength = 0; + } + } + return $out; + } + + static function parseError($fullJavascript, $position, $errorMsg) { + // TODO: Handle the error: trigger_error, throw exception, return false... + return false; + } +} diff --git a/core/minimizer.php b/core/minimizer.php index e4e6ff50e66..e5703053024 100644 --- a/core/minimizer.php +++ b/core/minimizer.php @@ -1,5 +1,12 @@ findFiles(OC_Util::$core_styles); -$minimizer->output($files); +if ($service == 'core.css'){ + $minimizer = new OC_Minimizer_CSS(); + $files = $minimizer->findFiles(OC_Util::$core_styles); + $minimizer->output($files); +} +else if ($service == 'core.js'){ + $minimizer = new OC_Minimizer_JS(); + $files = $minimizer->findFiles(OC_Util::$core_scripts); + $minimizer->output($files); +} diff --git a/core/templates/layout.guest.php b/core/templates/layout.guest.php index 37a74f46968..84422a10b18 100644 --- a/core/templates/layout.guest.php +++ b/core/templates/layout.guest.php @@ -15,6 +15,9 @@ var oc_appswebroot = ''; var oc_appswebroot = ''; + + + diff --git a/core/templates/layout.user.php b/core/templates/layout.user.php index e6fa910ce04..03b07c07283 100644 --- a/core/templates/layout.user.php +++ b/core/templates/layout.user.php @@ -15,6 +15,9 @@ var oc_appswebroot = ''; var oc_current_user = ''; + + + diff --git a/lib/app.php b/lib/app.php index 39e90ada019..8bd095d8c6c 100644 --- a/lib/app.php +++ b/lib/app.php @@ -75,6 +75,8 @@ class OC_App{ if (!defined('DEBUG') || !DEBUG){ if (is_null($types)) { + OC_Util::$core_scripts = OC_Util::$scripts; + OC_Util::$scripts = array(); OC_Util::$core_styles = OC_Util::$styles; OC_Util::$styles = array(); } diff --git a/lib/base.php b/lib/base.php index 673a47ba450..1b3554a42a9 100644 --- a/lib/base.php +++ b/lib/base.php @@ -231,6 +231,7 @@ class OC{ } OC_AppConfig::setValue('core', 'remote_core.css', '/core/minimizer.php'); + OC_AppConfig::setValue('core', 'remote_core.js', '/core/minimizer.php'); OC_App::updateApps(); } diff --git a/lib/minimizer/js.php b/lib/minimizer/js.php new file mode 100644 index 00000000000..4ddaa79d81a --- /dev/null +++ b/lib/minimizer/js.php @@ -0,0 +1,62 @@ +appendIfExist(OC::$THIRDPARTYROOT, OC::$THIRDPARTYWEBROOT, $script.'.js')) { + + // Is it in apps and overwritten by the theme? + }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$script$fext.js" )) { + }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$script.js" )) { + + // Is it part of an app? + }elseif($this->appendIfExist(OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$script$fext.js" )) { + }elseif($this->appendIfExist(OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$script.js" )) { + + // Is it in the owncloud root but overwritten by the theme? + }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$script$fext.js" )) { + }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$script.js" )) { + + // Is it in the owncloud root ? + }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "$script$fext.js" )) { + }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "$script.js" )) { + + // Is in core but overwritten by a theme? + }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$script$fext.js" )) { + }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$script.js" )) { + + // Is it in core? + }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "core/$script$fext.js" )) { + }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "core/$script.js" )) { + + }else{ + echo('js file not found: script:'.$script.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT); + die(); + } + } + return $this->files; + } + + public function minimizeFiles($files) { + $js_out = ''; + foreach($files as $file_info) { + $file = $file_info[0] . '/' . $file_info[2]; + $js_out .= '/* ' . $file . ' */' . "\n"; + $js_out .= file_get_contents($file); + } + $js_out = JavaScriptMinifier::minify($js_out); + return $js_out; + } +} diff --git a/lib/util.php b/lib/util.php index c7a5a9cfd68..95b5f8df3db 100644 --- a/lib/util.php +++ b/lib/util.php @@ -11,6 +11,7 @@ class OC_Util { private static $rootMounted=false; private static $fsSetup=false; public static $core_styles=array(); + public static $core_scripts=array(); // Can be set up public static function setupFS( $user = "", $root = "files" ){// configure the initial filesystem based on the configuration -- cgit v1.2.3 From f00b57f8be38382b103538813eec9749764658cb Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 20 May 2012 18:49:13 +0200 Subject: files app is always enabled --- lib/app.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/app.php') diff --git a/lib/app.php b/lib/app.php index c4cdd216838..e3e9df0e008 100644 --- a/lib/app.php +++ b/lib/app.php @@ -155,7 +155,7 @@ class OC_App{ * This function checks whether or not an app is enabled. */ public static function isEnabled( $app ){ - if( 'yes' == OC_Appconfig::getValue( $app, 'enabled' )){ + if( 'files'==$app or 'yes' == OC_Appconfig::getValue( $app, 'enabled' )){ return true; } -- cgit v1.2.3 From cb23bae8d90bc7bbed045e2bf8ef8e38ef232bb3 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 20 May 2012 18:51:45 +0200 Subject: dont throw errors when apps dont have types configured --- lib/app.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib/app.php') diff --git a/lib/app.php b/lib/app.php index e3e9df0e008..8ec042ddd60 100644 --- a/lib/app.php +++ b/lib/app.php @@ -114,7 +114,11 @@ class OC_App{ self::$appTypes=OC_Appconfig::getValues(false,'types'); } - return explode(',',self::$appTypes[$app]); + if(isset(self::$appTypes[$app])){ + return explode(',',self::$appTypes[$app]); + }else{ + return array(); + } } /** -- cgit v1.2.3 From d2e2a2b2c0a044113082440b60c50f8c3f7bdfdc Mon Sep 17 00:00:00 2001 From: Florian Hülsmann Date: Tue, 22 May 2012 13:10:42 +0200 Subject: prevent apps from printing output from app.php --- lib/app.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib/app.php') diff --git a/lib/app.php b/lib/app.php index 8ec042ddd60..04fc264d11a 100644 --- a/lib/app.php +++ b/lib/app.php @@ -63,11 +63,14 @@ class OC_App{ // The rest comes here $apps = self::getEnabledApps(); + // prevent app.php from printing output + ob_start(); foreach( $apps as $app ){ if((is_null($types) or self::isType($app,$types))){ self::loadApp($app); } } + ob_end_clean(); self::$init = true; -- cgit v1.2.3 From dfd5a9759c591ed92d5e55c59ca98afbb35eed7d Mon Sep 17 00:00:00 2001 From: Frank Karlitschek Date: Fri, 25 May 2012 11:31:46 +0200 Subject: only enable compatible apps --- lib/app.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'lib/app.php') diff --git a/lib/app.php b/lib/app.php index 04fc264d11a..658aba92904 100644 --- a/lib/app.php +++ b/lib/app.php @@ -189,8 +189,16 @@ class OC_App{ } } if($app!==false){ - OC_Appconfig::setValue( $app, 'enabled', 'yes' ); - return true; + // check if the app is compatible with this version of ownCloud + $info=OC_App::getAppInfo($app); + $version=OC_Util::getVersion(); + if(!isset($info['require']) or ($version[0]>$info['require'])){ + OC_Log::write('core','App can\'t be installed because it is not compatible with this version of ownCloud',OC_Log::ERROR); + return false; + }else{ + OC_Appconfig::setValue( $app, 'enabled', 'yes' ); + return true; + } }else{ return false; } -- cgit v1.2.3 From a945fa10a639cdee9e5e712cd48e8c911a8d9821 Mon Sep 17 00:00:00 2001 From: Frank Karlitschek Date: Sat, 26 May 2012 19:14:24 +0200 Subject: update copyright --- apps/external/ajax/setsites.php | 2 +- apps/external/appinfo/app.php | 2 +- apps/external/index.php | 2 +- apps/files/appinfo/remote.php | 2 +- apps/files_encryption/lib/crypt.php | 2 +- apps/files_versions/history.php | 2 +- apps/remoteStorage/WebDAV.php | 2 +- apps/remoteStorage/ajax/revokeToken.php | 2 +- apps/remoteStorage/auth.php | 2 +- core/lostpassword/index.php | 2 +- core/lostpassword/resetpassword.php | 2 +- files/webdav.php | 2 +- index.php | 3 ++- lib/app.php | 2 +- lib/appconfig.php | 2 +- lib/base.php | 2 +- lib/config.php | 2 +- lib/db.php | 2 +- lib/files.php | 2 +- lib/filestorage.php | 2 +- lib/filesystem.php | 2 +- lib/filesystemview.php | 2 +- lib/group.php | 2 +- lib/group/backend.php | 2 +- lib/group/database.php | 2 +- lib/group/dummy.php | 2 +- lib/group/example.php | 2 +- lib/helper.php | 2 +- lib/installer.php | 2 +- lib/l10n.php | 2 +- lib/ocs.php | 2 +- lib/ocsclient.php | 2 +- lib/preferences.php | 2 +- lib/public/app.php | 2 +- lib/public/config.php | 2 +- lib/public/db.php | 2 +- lib/public/files.php | 2 +- lib/public/json.php | 2 +- lib/public/response.php | 2 +- lib/public/template.php | 2 +- lib/public/user.php | 2 +- lib/public/util.php | 2 +- lib/search.php | 2 +- lib/template.php | 2 +- lib/updater.php | 2 +- lib/user.php | 2 +- lib/user/backend.php | 2 +- lib/user/database.php | 2 +- lib/user/dummy.php | 2 +- lib/user/example.php | 2 +- ocs/providers.php | 2 +- ocs/v1.php | 2 +- settings/apps.php | 2 +- settings/help.php | 2 +- settings/templates/help.php | 2 +- status.php | 2 +- webapps.php | 2 +- 57 files changed, 58 insertions(+), 57 deletions(-) mode change 100644 => 100755 index.php (limited to 'lib/app.php') diff --git a/apps/external/ajax/setsites.php b/apps/external/ajax/setsites.php index c14daa258c1..c758a3508c5 100644 --- a/apps/external/ajax/setsites.php +++ b/apps/external/ajax/setsites.php @@ -1,7 +1,7 @@ + * 2012 Frank Karlitschek frank@owncloud.org * This file is licensed under the Affero General Public License version 3 or later. * See the COPYING-README file. */ diff --git a/apps/external/appinfo/app.php b/apps/external/appinfo/app.php index b569fc305ba..ee5437782cd 100644 --- a/apps/external/appinfo/app.php +++ b/apps/external/appinfo/app.php @@ -4,7 +4,7 @@ * ownCloud - External plugin * * @author Frank Karlitschek - * @copyright 2011 Frank Karlitschek karlitschek@kde.org + * @copyright 2012 Frank Karlitschek frank@owncloud.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE diff --git a/apps/external/index.php b/apps/external/index.php index d63be3ad1d5..81819e76e2f 100644 --- a/apps/external/index.php +++ b/apps/external/index.php @@ -4,7 +4,7 @@ * ownCloud - External plugin * * @author Frank Karlitschek - * @copyright 2011 Frank Karlitschek karlitschek@kde.org + * @copyright 2012 Frank Karlitschek frank@owncloud.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE diff --git a/apps/files/appinfo/remote.php b/apps/files/appinfo/remote.php index b66843556bb..a84216b61b7 100644 --- a/apps/files/appinfo/remote.php +++ b/apps/files/appinfo/remote.php @@ -5,7 +5,7 @@ * * @author Frank Karlitschek * @author Jakob Sack - * @copyright 2010 Frank Karlitschek karlitschek@kde.org + * @copyright 2012 Frank Karlitschek frank@owncloud.org * @copyright 2011 Jakob Sack kde@jakobsack.de * * This library is free software; you can redistribute it and/or diff --git a/apps/files_encryption/lib/crypt.php b/apps/files_encryption/lib/crypt.php index 37eaedc3fc9..ec27900cbc6 100644 --- a/apps/files_encryption/lib/crypt.php +++ b/apps/files_encryption/lib/crypt.php @@ -3,7 +3,7 @@ * ownCloud * * @author Frank Karlitschek - * @copyright 2010 Frank Karlitschek karlitschek@kde.org + * @copyright 2012 Frank Karlitschek frank@owncloud.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE diff --git a/apps/files_versions/history.php b/apps/files_versions/history.php index f12dc618f23..11c07ef86ce 100644 --- a/apps/files_versions/history.php +++ b/apps/files_versions/history.php @@ -4,7 +4,7 @@ * ownCloud - History page of the Versions App * * @author Frank Karlitschek - * @copyright 2011 Frank Karlitschek karlitschek@kde.org + * @copyright 2012 Frank Karlitschek frank@owncloud.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE diff --git a/apps/remoteStorage/WebDAV.php b/apps/remoteStorage/WebDAV.php index ab498db07da..7a81c18e0af 100644 --- a/apps/remoteStorage/WebDAV.php +++ b/apps/remoteStorage/WebDAV.php @@ -5,7 +5,7 @@ * * Original: * @author Frank Karlitschek -* @copyright 2010 Frank Karlitschek karlitschek@kde.org +* @copyright 2012 Frank Karlitschek frank@owncloud.org * * Adapted: * @author Michiel de Jong, 2011 diff --git a/apps/remoteStorage/ajax/revokeToken.php b/apps/remoteStorage/ajax/revokeToken.php index 699b9e9aeec..322d9ed7279 100644 --- a/apps/remoteStorage/ajax/revokeToken.php +++ b/apps/remoteStorage/ajax/revokeToken.php @@ -5,7 +5,7 @@ * * Original: * @author Frank Karlitschek -* @copyright 2010 Frank Karlitschek karlitschek@kde.org +* @copyright 2012 Frank Karlitschek frank@owncloud.org * * Adapted: * @author Michiel de Jong, 2012 diff --git a/apps/remoteStorage/auth.php b/apps/remoteStorage/auth.php index a54be37b2e6..ac0e83bb373 100644 --- a/apps/remoteStorage/auth.php +++ b/apps/remoteStorage/auth.php @@ -5,7 +5,7 @@ * * Original: * @author Frank Karlitschek -* @copyright 2010 Frank Karlitschek karlitschek@kde.org +* @copyright 2012 Frank Karlitschek frank@owncloud.org * * Adapted: * @author Michiel de Jong, 2012 diff --git a/core/lostpassword/index.php b/core/lostpassword/index.php index 2b87a1eb111..6a4748588fc 100644 --- a/core/lostpassword/index.php +++ b/core/lostpassword/index.php @@ -1,6 +1,6 @@ diff --git a/status.php b/status.php index 81f339fa53f..2d31702ecb3 100644 --- a/status.php +++ b/status.php @@ -4,7 +4,7 @@ * ownCloud status page. usefull if you want to check from the outside if an owncloud installation exists * * @author Frank Karlitschek -* @copyright 2010 Frank Karlitschek karlitschek@kde.org +* @copyright 2012 Frank Karlitschek frank@owncloud.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE diff --git a/webapps.php b/webapps.php index 99553fa8ef0..b5fee9bf85f 100644 --- a/webapps.php +++ b/webapps.php @@ -4,7 +4,7 @@ * ownCloud status page. usefull if you want to check from the outside if an owncloud installation exists * * @author Frank Karlitschek -* @copyright 2010 Frank Karlitschek karlitschek@kde.org +* @copyright 2012 Frank Karlitschek frank@owncloud.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE -- cgit v1.2.3 From 982cde0bb1a9230b793f7341eba5d8117c48ca0b Mon Sep 17 00:00:00 2001 From: Frank Karlitschek Date: Sat, 26 May 2012 20:37:10 +0200 Subject: check during ownCloud upgrade if all the installed apps are compatible with the new ownCloud version. Disable them if not --- lib/app.php | 24 ++++++++++++++++++++++-- settings/js/apps.js | 4 ++-- 2 files changed, 24 insertions(+), 4 deletions(-) mode change 100644 => 100755 lib/app.php (limited to 'lib/app.php') diff --git a/lib/app.php b/lib/app.php old mode 100644 new mode 100755 index c639d2c4a5b..78de0fa21b6 --- a/lib/app.php +++ b/lib/app.php @@ -189,11 +189,11 @@ class OC_App{ } } if($app!==false){ - // check if the app is compatible with this version of ownCloud + // check if the app is compatible with this version of ownCloud $info=OC_App::getAppInfo($app); $version=OC_Util::getVersion(); if(!isset($info['require']) or ($version[0]>$info['require'])){ - OC_Log::write('core','App can\'t be installed because it is not compatible with this version of ownCloud',OC_Log::ERROR); + OC_Log::write('core','App "'.$info['name'].'" can\'t be installed because it is not compatible with this version of ownCloud',OC_Log::ERROR); return false; }else{ OC_Appconfig::setValue( $app, 'enabled', 'yes' ); @@ -525,6 +525,26 @@ class OC_App{ } } } + + // check if the current enabled apps are compatible with the current ownCloud version. disable them if not. + // this is important if you upgrade ownCloud and have non ported 3rd party apps installed + $apps =OC_App::getEnabledApps(); + $version=OC_Util::getVersion(); + foreach($apps as $app) { + + // check if the app is compatible with this version of ownCloud + $info=OC_App::getAppInfo($app); + if(!isset($info['require']) or ($version[0]>$info['require'])){ + OC_Log::write('core','App "'.$info['name'].'" can\'t be used because it is not compatible with this version of ownCloud',OC_Log::ERROR); + OC_App::disable( $app ); + } + + + + } + + + } /** diff --git a/settings/js/apps.js b/settings/js/apps.js index 8aa54463b3b..f6e08b608bd 100644 --- a/settings/js/apps.js +++ b/settings/js/apps.js @@ -41,7 +41,7 @@ $(document).ready(function(){ if(active){ $.post(OC.filePath('settings','ajax','disableapp.php'),{appid:app},function(result){ if(!result || result.status!='success'){ - OC.dialogs.alert('Error','Error while disabling app'); + OC.dialogs.alert('Error while disabling app','Error'); } else { element.data('active',false); @@ -54,7 +54,7 @@ $(document).ready(function(){ }else{ $.post(OC.filePath('settings','ajax','enableapp.php'),{appid:app},function(result){ if(!result || result.status!='success'){ - OC.dialogs.alert('Error','Error while enabling app'); + OC.dialogs.alert('Error while enabling app','Error'); } else { element.data('active',true); -- cgit v1.2.3 From a33f580db10483f6daa6142923633a3b1d808794 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Thu, 31 May 2012 13:00:58 +0200 Subject: Remove OC_App::register function The data supplied is never used in OwnCloud. Removed the call from all the apps, and made the public API function empty. --- apps/admin_dependencies_chk/appinfo/app.php | 5 ---- apps/bookmarks/appinfo/app.php | 2 -- apps/calendar/appinfo/app.php | 4 --- apps/contacts/appinfo/app.php | 5 ---- apps/external/appinfo/app.php | 2 -- apps/files/appinfo/app.php | 1 - apps/files_versions/appinfo/app.php | 8 +----- apps/gallery/appinfo/app.php | 5 ---- apps/media/appinfo/app.php | 2 -- apps/remoteStorage/appinfo/app.php | 4 --- apps/tasks/appinfo/app.php | 5 ---- apps/user_webfinger/appinfo/app.php | 4 --- lib/app.php | 40 +---------------------------- lib/public/app.php | 1 - search/appinfo/app.php | 5 ---- settings/appinfo/app.php | 7 ----- 16 files changed, 2 insertions(+), 98 deletions(-) delete mode 100644 search/appinfo/app.php delete mode 100644 settings/appinfo/app.php (limited to 'lib/app.php') diff --git a/apps/admin_dependencies_chk/appinfo/app.php b/apps/admin_dependencies_chk/appinfo/app.php index 72d368a085e..62b26342d23 100644 --- a/apps/admin_dependencies_chk/appinfo/app.php +++ b/apps/admin_dependencies_chk/appinfo/app.php @@ -1,9 +1,4 @@ 14, - 'id' => 'admin_dependencies_chk', - 'name' => 'Owncloud Install Info' )); - OCP\App::registerAdmin('admin_dependencies_chk','settings'); diff --git a/apps/bookmarks/appinfo/app.php b/apps/bookmarks/appinfo/app.php index 8a8f443891c..f4bca9df700 100644 --- a/apps/bookmarks/appinfo/app.php +++ b/apps/bookmarks/appinfo/app.php @@ -10,8 +10,6 @@ OC::$CLASSPATH['OC_Bookmarks_Bookmarks'] = 'apps/bookmarks/lib/bookmarks.php'; OC::$CLASSPATH['OC_Search_Provider_Bookmarks'] = 'apps/bookmarks/lib/search.php'; -OCP\App::register( array( 'order' => 70, 'id' => 'bookmark', 'name' => 'Bookmarks' )); - $l = new OC_l10n('bookmarks'); OCP\App::addNavigationEntry( array( 'id' => 'bookmarks_index', 'order' => 70, 'href' => OCP\Util::linkTo( 'bookmarks', 'index.php' ), 'icon' => OCP\Util::imagePath( 'bookmarks', 'bookmarks.png' ), 'name' => $l->t('Bookmarks'))); diff --git a/apps/calendar/appinfo/app.php b/apps/calendar/appinfo/app.php index b02fc602c6b..886c218f7c1 100644 --- a/apps/calendar/appinfo/app.php +++ b/apps/calendar/appinfo/app.php @@ -11,10 +11,6 @@ OCP\Util::connectHook('OC_User', 'post_deleteUser', 'OC_Calendar_Hooks', 'delete OCP\Util::addscript('calendar','loader'); OCP\Util::addscript("3rdparty", "chosen/chosen.jquery.min"); OCP\Util::addStyle("3rdparty", "chosen/chosen"); -OCP\App::register( array( - 'order' => 10, - 'id' => 'calendar', - 'name' => 'Calendar' )); OCP\App::addNavigationEntry( array( 'id' => 'calendar_index', 'order' => 10, diff --git a/apps/contacts/appinfo/app.php b/apps/contacts/appinfo/app.php index 20d97697bf4..7a04ec7ff5e 100644 --- a/apps/contacts/appinfo/app.php +++ b/apps/contacts/appinfo/app.php @@ -9,11 +9,6 @@ OCP\Util::connectHook('OC_User', 'post_deleteUser', 'OC_Contacts_Hooks', 'delete OCP\Util::connectHook('OC_Calendar', 'getEvents', 'OC_Contacts_Hooks', 'getBirthdayEvents'); OCP\Util::connectHook('OC_Calendar', 'getSources', 'OC_Contacts_Hooks', 'getCalenderSources'); -OCP\App::register( array( - 'order' => 10, - 'id' => 'contacts', - 'name' => 'Contacts' )); - OCP\App::addNavigationEntry( array( 'id' => 'contacts_index', 'order' => 10, diff --git a/apps/external/appinfo/app.php b/apps/external/appinfo/app.php index ee5437782cd..1a02f3a1be8 100644 --- a/apps/external/appinfo/app.php +++ b/apps/external/appinfo/app.php @@ -26,8 +26,6 @@ OCP\Util::addStyle( 'external', 'style'); OCP\App::registerAdmin('external', 'settings'); -OCP\App::register(array('order' => 70, 'id' => 'external', 'name' => 'External')); - $sites = OC_External::getSites(); for ($i = 0; $i < sizeof($sites); $i++) { OCP\App::addNavigationEntry( diff --git a/apps/files/appinfo/app.php b/apps/files/appinfo/app.php index 5c0d3c8db83..db3b213ab8d 100644 --- a/apps/files/appinfo/app.php +++ b/apps/files/appinfo/app.php @@ -1,7 +1,6 @@ 2, "id" => "files", "name" => "Files" )); OCP\App::registerAdmin('files','admin'); OCP\App::addNavigationEntry( array( "id" => "files_index", "order" => 0, "href" => OCP\Util::linkTo( "files", "index.php" ), "icon" => OCP\Util::imagePath( "core", "places/home.svg" ), "name" => $l->t("Files") )); diff --git a/apps/files_versions/appinfo/app.php b/apps/files_versions/appinfo/app.php index 457c5125353..49f1573f7c2 100644 --- a/apps/files_versions/appinfo/app.php +++ b/apps/files_versions/appinfo/app.php @@ -2,14 +2,8 @@ require_once('apps/files_versions/versions.php'); -// Add an entry in the app list -OCP\App::register( array( - 'order' => 10, - 'id' => 'files_versions', - 'name' => 'Versioning' )); - OCP\App::registerAdmin('files_versions', 'settings'); OCP\Util::addscript('files_versions', 'versions'); // Listen to write signals -OCP\Util::connectHook(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_write, "OCA_Versions\Storage", "write_hook"); \ No newline at end of file +OCP\Util::connectHook(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_write, "OCA_Versions\Storage", "write_hook"); diff --git a/apps/gallery/appinfo/app.php b/apps/gallery/appinfo/app.php index 878da48698a..e1db33eb314 100644 --- a/apps/gallery/appinfo/app.php +++ b/apps/gallery/appinfo/app.php @@ -29,11 +29,6 @@ OC::$CLASSPATH['OC_Gallery_Hooks_Handlers'] = 'apps/gallery/lib/hooks_handlers.p $l = OC_L10N::get('gallery'); -OCP\App::register(array( - 'order' => 20, - 'id' => 'gallery', - 'name' => 'Pictures')); - OCP\App::addNavigationEntry( array( 'id' => 'gallery_index', 'order' => 20, diff --git a/apps/media/appinfo/app.php b/apps/media/appinfo/app.php index d6a09c48059..869bc344020 100644 --- a/apps/media/appinfo/app.php +++ b/apps/media/appinfo/app.php @@ -29,8 +29,6 @@ require_once('apps/media/lib_scanner.php'); OCP\Util::addscript('media','loader'); OCP\App::registerPersonal('media','settings'); -OCP\App::register( array( 'order' => 3, 'id' => 'media', 'name' => 'Media' )); - OCP\App::addNavigationEntry(array('id' => 'media_index', 'order' => 2, 'href' => OCP\Util::linkTo('media', 'index.php'), 'icon' => OCP\Util::imagePath('core', 'places/music.svg'), 'name' => $l->t('Music'))); OC_Search::registerProvider('OC_MediaSearchProvider'); diff --git a/apps/remoteStorage/appinfo/app.php b/apps/remoteStorage/appinfo/app.php index 14b8a3d11df..c278fd73056 100644 --- a/apps/remoteStorage/appinfo/app.php +++ b/apps/remoteStorage/appinfo/app.php @@ -1,6 +1,2 @@ 10, - 'id' => 'remoteStorage', - 'name' => 'remoteStorage compatibility' )); OCP\App::registerPersonal('remoteStorage','settings'); diff --git a/apps/tasks/appinfo/app.php b/apps/tasks/appinfo/app.php index f346e2aa4c0..e7c82d6f247 100644 --- a/apps/tasks/appinfo/app.php +++ b/apps/tasks/appinfo/app.php @@ -3,11 +3,6 @@ $l=new OC_L10N('tasks'); OC::$CLASSPATH['OC_Calendar_Calendar'] = 'apps/calendar/lib/calendar.php'; OC::$CLASSPATH['OC_Task_App'] = 'apps/tasks/lib/app.php'; -OCP\App::register( array( - 'order' => 11, - 'id' => 'tasks', - 'name' => 'Tasks' )); - OCP\App::addNavigationEntry( array( 'id' => 'tasks_index', 'order' => 11, diff --git a/apps/user_webfinger/appinfo/app.php b/apps/user_webfinger/appinfo/app.php index a45efd96a46..3336af66820 100644 --- a/apps/user_webfinger/appinfo/app.php +++ b/apps/user_webfinger/appinfo/app.php @@ -1,7 +1,3 @@ 11, - 'id' => 'user_webfinger', - 'name' => 'Webfinger' )); OCP\CONFIG::setAppValue('core', 'public_host-meta', '/apps/user_webfinger/host-meta.php'); OCP\CONFIG::setAppValue('core', 'public_webfinger', '/apps/user_webfinger/webfinger.php'); diff --git a/lib/app.php b/lib/app.php index 78de0fa21b6..124b76cdc3d 100755 --- a/lib/app.php +++ b/lib/app.php @@ -28,7 +28,6 @@ */ class OC_App{ static private $init = false; - static private $apps = array(); static private $activeapp = ''; static private $navigation = array(); static private $settingsForms = array(); @@ -54,14 +53,7 @@ class OC_App{ return true; } - // Our very own core apps are hardcoded - foreach( array( 'settings') as $app ){ - if(is_null($types)){ - require( $app.'/appinfo/app.php' ); - } - } - - // The rest comes here + // Load the enabled apps here $apps = self::getEnabledApps(); // prevent app.php from printing output ob_start(); @@ -216,36 +208,6 @@ class OC_App{ OC_Appconfig::setValue( $app, 'enabled', 'no' ); } - /** - * @brief makes owncloud aware of this app - * @param $data array with all information - * @returns true/false - * - * This function registers the application. $data is an associative array. - * The following keys are required: - * - id: id of the application, has to be unique ('addressbook') - * - name: Human readable name ('Addressbook') - * - version: array with Version (major, minor, bugfix) ( array(1, 0, 2)) - * - * The following keys are optional: - * - order: integer, that influences the position of your application in - * a list of applications. Lower values come first. - * - */ - public static function register( $data ){ - OC_App::$apps[] = $data; - } - - /** - * @brief returns information of all apps - * @return array with all information - * - * This function returns all data it got via register(). - */ - public static function get(){ - return OC_App::$apps; - } - /** * @brief adds an entry to the navigation * @param $data array containing the data diff --git a/lib/public/app.php b/lib/public/app.php index 3960db6d897..1f84087f076 100644 --- a/lib/public/app.php +++ b/lib/public/app.php @@ -52,7 +52,6 @@ class App { * */ public static function register( $data ){ - return \OC_App::register( $data ); } diff --git a/search/appinfo/app.php b/search/appinfo/app.php deleted file mode 100644 index b91341643f2..00000000000 --- a/search/appinfo/app.php +++ /dev/null @@ -1,5 +0,0 @@ - 2, "id" => 'search', 'name' => 'Search' )); - -?> diff --git a/settings/appinfo/app.php b/settings/appinfo/app.php deleted file mode 100644 index d18bcdbff0d..00000000000 --- a/settings/appinfo/app.php +++ /dev/null @@ -1,7 +0,0 @@ - "settings", "name" => "Settings" )); -OC_App::register( array( "order" => 1, "id" => "admin", "name" => "Administration" )); -OC_App::register( array( "order" => 1, "id" => "help", "name" => "Help" )); - -?> -- cgit v1.2.3 From b0d83d6d8d123171d97ac48e2fdb16d99093ca57 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Mon, 4 Jun 2012 21:40:18 +0200 Subject: make it possible to load apps seperately. needed to fix oc-910 without breaking oc-863 --- lib/app.php | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) (limited to 'lib/app.php') diff --git a/lib/app.php b/lib/app.php index 124b76cdc3d..17e0e479031 100755 --- a/lib/app.php +++ b/lib/app.php @@ -35,6 +35,7 @@ class OC_App{ static private $personalForms = array(); static private $appInfo = array(); static private $appTypes = array(); + static private $loadedApps = array(); /** * @brief loads all apps @@ -48,24 +49,18 @@ class OC_App{ * if $types is set, only apps of those types will be loaded */ public static function loadApps($types=null){ - // Did we already load everything? - if( self::$init ){ - return true; - } - // Load the enabled apps here $apps = self::getEnabledApps(); // prevent app.php from printing output ob_start(); foreach( $apps as $app ){ - if((is_null($types) or self::isType($app,$types))){ + if((is_null($types) or self::isType($app,$types)) && !in_array($app, self::$loadedApps)){ self::loadApp($app); + self::$loadedApps[] = $app; } } ob_end_clean(); - self::$init = true; - // return return true; } @@ -121,7 +116,7 @@ class OC_App{ */ public static function setAppTypes($app){ $appData=self::getAppInfo($app); - + if(isset($appData['types'])){ $appTypes=implode(',',$appData['types']); }else{ @@ -183,7 +178,7 @@ class OC_App{ if($app!==false){ // check if the app is compatible with this version of ownCloud $info=OC_App::getAppInfo($app); - $version=OC_Util::getVersion(); + $version=OC_Util::getVersion(); if(!isset($info['require']) or ($version[0]>$info['require'])){ OC_Log::write('core','App "'.$info['name'].'" can\'t be installed because it is not compatible with this version of ownCloud',OC_Log::ERROR); return false; @@ -487,13 +482,13 @@ class OC_App{ } } } - + // check if the current enabled apps are compatible with the current ownCloud version. disable them if not. // this is important if you upgrade ownCloud and have non ported 3rd party apps installed $apps =OC_App::getEnabledApps(); $version=OC_Util::getVersion(); foreach($apps as $app) { - + // check if the app is compatible with this version of ownCloud $info=OC_App::getAppInfo($app); if(!isset($info['require']) or ($version[0]>$info['require'])){ @@ -501,12 +496,12 @@ class OC_App{ OC_App::disable( $app ); } - - + + } - - - + + + } /** -- cgit v1.2.3 From b6c5ca126b802354c44a374e72b2e0b677b2af90 Mon Sep 17 00:00:00 2001 From: Brice Maron Date: Fri, 1 Jun 2012 22:05:20 +0000 Subject: First almost working version --- lib/app.php | 38 ++++++++++++++++------- lib/base.php | 31 ++++++++++--------- lib/helper.php | 4 +-- lib/l10n.php | 4 +-- lib/template.php | 94 ++++++++++++++++++++++++++++++++------------------------ 5 files changed, 100 insertions(+), 71 deletions(-) (limited to 'lib/app.php') diff --git a/lib/app.php b/lib/app.php index 667633e2647..13b6617b23e 100755 --- a/lib/app.php +++ b/lib/app.php @@ -78,7 +78,7 @@ class OC_App{ * @param string app */ public static function loadApp($app){ - if(is_file(OC::$APPSROOT.'/apps/'.$app.'/appinfo/app.php')){ + if(is_file(self::getAppPath($app).'/appinfo/app.php')){ require_once( $app.'/appinfo/app.php' ); } } @@ -322,11 +322,25 @@ class OC_App{ return $list; } + /** + * Get the directory for the given app. + * If the app is defined in multiple directory, the first one is taken. (false if not found) + */ + public static function getAppPath($appid) { + foreach(OC::$APPSROOTS as $dir) { + if(file_exists($dir.'/'.$appid)) { + return $dir.'/'.$appid; + } + } +// OC_Log::write('core','Unable to find app "'.$appid.'"',OC_Log::ERROR); + return false; + } + /** * get the last version of the app, either from appinfo/version or from appinfo/info.xml */ public static function getAppVersion($appid){ - $file=OC::$APPSROOT.'/apps/'.$appid.'/appinfo/version'; + $file= self::getAppPath($appid).'/appinfo/version'; $version=@file_get_contents($file); if($version){ return $version; @@ -349,7 +363,7 @@ class OC_App{ if(isset(self::$appInfo[$appid])){ return self::$appInfo[$appid]; } - $file=OC::$APPSROOT.'/apps/'.$appid.'/appinfo/info.xml'; + $file= self::getAppPath($appid).'/appinfo/info.xml'; } $data=array(); $content=@file_get_contents($file); @@ -462,10 +476,12 @@ class OC_App{ */ public static function getAllApps(){ $apps=array(); - $dh=opendir(OC::$APPSROOT.'/apps'); - while($file=readdir($dh)){ - if(substr($file,0,1)!='.' and is_file(OC::$APPSROOT.'/apps/'.$file.'/appinfo/app.php')){ - $apps[]=$file; + foreach(OC::$APPSROOTS as $apps_dir) { + $dh=opendir($apps_dir); + while($file=readdir($dh)){ + if(substr($file,0,1)!='.' and is_file($apps_dir.'/'.$file.'/appinfo/app.php')){ + $apps[]=$file; + } } } return $apps; @@ -530,14 +546,14 @@ class OC_App{ * @param string appid */ public static function updateApp($appid){ - if(file_exists(OC::$APPSROOT.'/apps/'.$appid.'/appinfo/database.xml')){ - OC_DB::updateDbFromStructure(OC::$APPSROOT.'/apps/'.$appid.'/appinfo/database.xml'); + if(file_exists(self::getAppPath($appid).'/appinfo/database.xml')){ + OC_DB::updateDbFromStructure(self::getAppPath($appid).'/appinfo/database.xml'); } if(!self::isEnabled($appid)){ return; } - if(file_exists(OC::$APPSROOT.'/apps/'.$appid.'/appinfo/update.php')){ - include OC::$APPSROOT.'/apps/'.$appid.'/appinfo/update.php'; + if(file_exists(self::getAppPath($appid).'/appinfo/update.php')){ + include self::getAppPath($appid).'/appinfo/update.php'; } //set remote/public handelers diff --git a/lib/base.php b/lib/base.php index a65a33b166e..b494bbcabc5 100644 --- a/lib/base.php +++ b/lib/base.php @@ -57,7 +57,7 @@ class OC{ /** * The installation path of the apps folder on the server (e.g. /srv/http/owncloud) */ - public static $APPSROOT = ''; + public static $APPSROOTS = array(); /** * the root path of the apps folder for http requests (e.g. owncloud) */ @@ -168,15 +168,17 @@ class OC{ // search the apps folder if(OC_Config::getValue('appsroot', '')<>''){ - OC::$APPSROOT=OC_Config::getValue('appsroot', ''); + OC::$APPSROOTS=explode(':',OC_Config::getValue('appsroot', '')); OC::$APPSWEBROOT=OC_Config::getValue('appsurl', ''); }elseif(file_exists(OC::$SERVERROOT.'/apps')){ - OC::$APPSROOT=OC::$SERVERROOT; - OC::$APPSWEBROOT=OC::$WEBROOT; - }elseif(file_exists(OC::$SERVERROOT.'/../apps')){ - OC::$APPSROOT=rtrim(dirname(OC::$SERVERROOT), '/'); - OC::$APPSWEBROOT=rtrim(dirname(OC::$WEBROOT), '/'); - }else{ + OC::$APPSROOTS= array(OC::$SERVERROOT.'/apps'); + OC::$APPSWEBROOT=OC::$WEBROOT; + } + if(file_exists(OC::$SERVERROOT.'/../apps')){ + OC::$APPSROOTS[] = rtrim(realpath(OC::$SERVERROOT.'/../apps'), '/'); +// OC::$APPSWEBROOT=rtrim(dirname(OC::$WEBROOT), '/'); + } + if(empty(OC::$APPSROOTS)){ echo("apps directory not found! Please put the ownCloud apps folder in the ownCloud folder or the folder above. You can also configure the location in the config.php file."); exit; } @@ -186,8 +188,7 @@ class OC{ OC::$SERVERROOT.'/lib'.PATH_SEPARATOR. OC::$SERVERROOT.'/config'.PATH_SEPARATOR. OC::$THIRDPARTYROOT.'/3rdparty'.PATH_SEPARATOR. - OC::$APPSROOT.PATH_SEPARATOR. - OC::$APPSROOT.'/apps'.PATH_SEPARATOR. + implode(OC::$APPSROOTS,PATH_SEPARATOR).PATH_SEPARATOR. get_include_path().PATH_SEPARATOR. OC::$SERVERROOT ); @@ -273,15 +274,15 @@ class OC{ } public static function loadapp(){ - if(file_exists(OC::$APPSROOT . '/apps/' . OC::$REQUESTEDAPP . '/index.php')){ - require_once(OC::$APPSROOT . '/apps/' . OC::$REQUESTEDAPP . '/index.php'); + if(file_exists(OC_App::getAppPath(OC::$REQUESTEDAPP) . '/index.php')){ + require_once(OC_App::getAppPath(OC::$REQUESTEDAPP) . '/index.php'); }else{ trigger_error('The requested App was not found.', E_USER_ERROR);//load default app instead? } } public static function loadfile(){ - if(file_exists(OC::$APPSROOT . '/apps/' . OC::$REQUESTEDAPP . '/' . OC::$REQUESTEDFILE)){ + if(file_exists(OC_App::getAppPath(OC::$REQUESTEDAPP) . '/' . OC::$REQUESTEDFILE)){ if(substr(OC::$REQUESTEDFILE, -3) == 'css'){ $file = 'apps/' . OC::$REQUESTEDAPP . '/' . OC::$REQUESTEDFILE; $minimizer = new OC_Minimizer_CSS(); @@ -453,8 +454,8 @@ class OC{ $_GET['getfile'] = $file; } if(!is_null(self::$REQUESTEDFILE)){ - $subdir = OC::$APPSROOT . '/apps/' . self::$REQUESTEDAPP . '/' . self::$REQUESTEDFILE; - $parent = OC::$APPSROOT . '/apps/' . self::$REQUESTEDAPP; + $subdir = OC_App::getAppPath(OC::$REQUESTEDAPP) . '/' . self::$REQUESTEDFILE; + $parent = OC_App::getAppPath(OC::$REQUESTEDAPP); if(!OC_Helper::issubdirectory($subdir, $parent)){ self::$REQUESTEDFILE = null; header('HTTP/1.0 404 Not Found'); diff --git a/lib/helper.php b/lib/helper.php index decc1d61336..72ae98222d9 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -40,7 +40,7 @@ class OC_Helper { if( $app != '' ){ $app .= '/'; // Check if the app is in the app folder - if( file_exists( OC::$APPSROOT . '/apps/'. $app.$file )){ + if( file_exists( OC_App::getAppPath($app).$file )){ if(substr($file, -3) == 'php' || substr($file, -3) == 'css'){ if(substr($app, -1, 1) == '/'){ $app = substr($app, 0, strlen($app) - 1); @@ -150,7 +150,7 @@ class OC_Helper { // Check if the app is in the app folder if( file_exists( OC::$SERVERROOT."/themes/$theme/apps/$app/img/$image" )){ return OC::$WEBROOT."/themes/$theme/apps/$app/img/$image"; - }elseif( file_exists( OC::$APPSROOT."/apps/$app/img/$image" )){ + }elseif( file_exists(OC_App::getAppPath($app)."/img/$image" )){ return OC::$APPSWEBROOT."/apps/$app/img/$image"; }elseif( !empty( $app ) and file_exists( OC::$SERVERROOT."/themes/$theme/$app/img/$image" )){ return OC::$WEBROOT."/themes/$theme/$app/img/$image"; diff --git a/lib/l10n.php b/lib/l10n.php index 682e15f0e9b..70b32b92984 100644 --- a/lib/l10n.php +++ b/lib/l10n.php @@ -263,8 +263,8 @@ class OC_L10N{ $i18ndir = OC::$SERVERROOT.'/core/l10n/'; if($app != ''){ // Check if the app is in the app folder - if(file_exists(OC::$APPSROOT.'/apps/'.$app.'/l10n/')){ - $i18ndir = OC::$APPSROOT.'/apps/'.$app.'/l10n/'; + if(file_exists(OC_App::getAppPath($app).'/l10n/')){ + $i18ndir = OC_App::getAppPath($app).'/l10n/'; } else{ $i18ndir = OC::$SERVERROOT.'/'.$app.'/l10n/'; diff --git a/lib/template.php b/lib/template.php index 14833a1e5b5..a354d58a4b1 100644 --- a/lib/template.php +++ b/lib/template.php @@ -202,10 +202,10 @@ class OC_Template{ // Check if it is a app template or not. if( $app != "" ){ // Check if the app is in the app folder or in the root - if( file_exists( OC::$APPSROOT."/apps/$app/templates/" )){ + if( file_exists(OC_App::getAppPath($app)."/templates/" )){ // Check if the template is overwritten by the selected theme if ($this->checkPathForTemplate(OC::$SERVERROOT."/themes/$theme/apps/$app/templates/", $name, $fext)) { - }elseif ($this->checkPathForTemplate(OC::$APPSROOT."/apps/$app/templates/", $name, $fext)) { + }elseif ($this->checkPathForTemplate(OC_App::getAppPath($app)."/templates/", $name, $fext)) { } }else{ // Check if the template is overwritten by the selected theme @@ -317,29 +317,32 @@ class OC_Template{ } } - /* + /** * @brief append the $file-url if exist at $root * @param $type of collection to use when appending * @param $root path to check * @param $web base for path * @param $file the filename + * @param $in_app boolean is part of an app? (default false) */ - public function appendIfExist($type, $root, $web, $file) { - if (is_file($root.'/'.$file)) { - $pathes = explode('/', $file); - if($type == 'cssfiles' && $root == OC::$APPSROOT && $pathes[0] == 'apps'){ - $app = $pathes[1]; - unset($pathes[0]); - unset($pathes[1]); - $path = implode('/', $pathes); - $this->append( $type, OC_Helper::linkTo($app, $path)); - }else{ - $this->append( $type, $web.'/'.$file); - } - return true; - } - return false; - } + public function appendIfExist($type, $root, $web, $file, $in_app = false) { + + if (is_file($root.'/'.$file)) { + $pathes = explode('/', $file); + if($type == 'cssfiles' && $root == OC::$APPSROOTS[0] && $in_app){ + $app = $pathes[0]; + unset($pathes[0]); +// unset($pathes[1]); + $path = implode('/', $pathes); + $this->append( $type, OC_Helper::linkTo($app, $path)); + }else{ + $this->append( $type, $web.'/'.$file); + } + return true; + } + return false; + } + /** * @brief Proceeds the template * @returns content @@ -385,16 +388,12 @@ class OC_Template{ // Add the core js files or the js files provided by the selected theme foreach(OC_Util::$scripts as $script){ // Is it in 3rd party? - if($page->appendIfExist('jsfiles', OC::$THIRDPARTYROOT, OC::$THIRDPARTYWEBROOT, $script.'.js')) { + if($page->appendIfExist('jsfiles', OC::$THIRDPARTYROOT, OC::$THIRDPARTYWEBROOT, $script.'.js')) { // Is it in apps and overwritten by the theme? }elseif($page->appendIfExist('jsfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$script$fext.js" )) { }elseif($page->appendIfExist('jsfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$script.js" )) { - // Is it part of an app? - }elseif($page->appendIfExist('jsfiles', OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$script$fext.js" )) { - }elseif($page->appendIfExist('jsfiles', OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$script.js" )) { - // Is it in the owncloud root but overwritten by the theme? }elseif($page->appendIfExist('jsfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$script$fext.js" )) { }elseif($page->appendIfExist('jsfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$script.js" )) { @@ -412,20 +411,24 @@ class OC_Template{ }elseif($page->appendIfExist('jsfiles', OC::$SERVERROOT, OC::$WEBROOT, "core/$script.js" )) { }else{ - echo('js file not found: script:'.$script.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT); - die(); - + // Is it part of an app? + $append = false; + foreach( OC::$APPSROOTS as $apps_dir) + { + if($page->appendIfExist('jsfiles', $apps_dir, OC::$APPSWEBROOT.'/apps/', "$script$fext.js" , true)) { $append =true; break; } + elseif($page->appendIfExist('jsfiles', $apps_dir, OC::$APPSWEBROOT.'/apps/', "$script.js", true )) { $append =true; break; } + } + if(! $append) { + echo('js file not found: script:'.$script.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT); + die(); + } } } // Add the css files $page->assign('cssfiles', array()); foreach(OC_Util::$styles as $style){ // is it in 3rdparty? - if($page->appendIfExist('cssfiles', OC::$THIRDPARTYROOT, OC::$THIRDPARTYWEBROOT, $style.'.css')) { - - // or in apps? - }elseif($page->appendIfExist('cssfiles', OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$style$fext.css" )) { - }elseif($page->appendIfExist('cssfiles', OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$style.css" )) { + if($page->appendIfExist('cssfiles', OC::$THIRDPARTYROOT, OC::$THIRDPARTYWEBROOT, $style.'.css')) { // or in the owncloud root? }elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "$style$fext.css" )) { @@ -436,22 +439,31 @@ class OC_Template{ }elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "core/$style.css" )) { }else{ - echo('css file not found: style:'.$style.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT); - die(); + // or in apps? + $append = false; + foreach( OC::$APPSROOTS as $apps_dir) + { + if($page->appendIfExist('cssfiles', $apps_dir, OC::$APPSWEBROOT, "$style$fext.css", true)) { $append =true; break; } + elseif($page->appendIfExist('cssfiles', $apps_dir, OC::$APPSWEBROOT, "$style.css", true )) { $append =true; break; } + } + if(! $append) { + echo('css file not found: style:'.$script.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT); + die(); + } } } // Add the theme css files. you can override the default values here if(!empty($theme)) { foreach(OC_Util::$styles as $style){ - if($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$style$fext.css" )) { - }elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$style.css" )) { + if($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$style$fext.css" )) { + }elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$style.css" )) { - }elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$style$fext.css" )) { - }elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$style.css" )) { + }elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$style$fext.css" )) { + }elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$style.css" )) { - }elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$style$fext.css" )) { - }elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$style.css" )) { - } + }elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$style$fext.css" )) { + }elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$style.css" )) { + } } } -- cgit v1.2.3 From cc494259d3e1fc60e82452dfdc1d0e0e0cd848e9 Mon Sep 17 00:00:00 2001 From: Brice Maron Date: Sun, 3 Jun 2012 21:13:30 +0000 Subject: Unit path and webpath, correct some more --- apps/bookmarks/templates/list.php | 2 +- core/templates/layout.user.php | 3 ++- lib/app.php | 22 +++++++++++++++++----- lib/base.php | 31 ++++++++++++++++--------------- lib/helper.php | 4 ++-- lib/template.php | 8 ++++---- 6 files changed, 42 insertions(+), 28 deletions(-) (limited to 'lib/app.php') diff --git a/apps/bookmarks/templates/list.php b/apps/bookmarks/templates/list.php index fdd2b19f79a..84436ae7409 100644 --- a/apps/bookmarks/templates/list.php +++ b/apps/bookmarks/templates/list.php @@ -20,7 +20,7 @@ diff --git a/core/templates/layout.user.php b/core/templates/layout.user.php index 8f6c029007f..5f00a884a04 100644 --- a/core/templates/layout.user.php +++ b/core/templates/layout.user.php @@ -12,7 +12,8 @@ diff --git a/lib/app.php b/lib/app.php index 13b6617b23e..5883a29bb02 100755 --- a/lib/app.php +++ b/lib/app.php @@ -328,11 +328,23 @@ class OC_App{ */ public static function getAppPath($appid) { foreach(OC::$APPSROOTS as $dir) { - if(file_exists($dir.'/'.$appid)) { - return $dir.'/'.$appid; + if(file_exists($dir['path'].'/'.$appid)) { + return $dir['path'].'/'.$appid; + } + } + return false; + } + + /** + * Get the path for the given app on the access + * If the app is defined in multiple directory, the first one is taken. (false if not found) + */ + public static function getAppWebPath($appid) { + foreach(OC::$APPSROOTS as $dir) { + if(file_exists($dir['path'].'/'.$appid)) { + return $dir['web'].'/'.$appid; } } -// OC_Log::write('core','Unable to find app "'.$appid.'"',OC_Log::ERROR); return false; } @@ -477,9 +489,9 @@ class OC_App{ public static function getAllApps(){ $apps=array(); foreach(OC::$APPSROOTS as $apps_dir) { - $dh=opendir($apps_dir); + $dh=opendir($apps_dir['path']); while($file=readdir($dh)){ - if(substr($file,0,1)!='.' and is_file($apps_dir.'/'.$file.'/appinfo/app.php')){ + if(substr($file,0,1)!='.' and is_file($apps_dir['path'].'/'.$file.'/appinfo/app.php')){ $apps[]=$file; } } diff --git a/lib/base.php b/lib/base.php index b494bbcabc5..131485961ad 100644 --- a/lib/base.php +++ b/lib/base.php @@ -55,13 +55,9 @@ class OC{ */ public static $THIRDPARTYWEBROOT = ''; /** - * The installation path of the apps folder on the server (e.g. /srv/http/owncloud) + * The installation path array of the apps folder on the server (e.g. /srv/http/owncloud) 'real' and web path in 'web' */ public static $APPSROOTS = array(); - /** - * the root path of the apps folder for http requests (e.g. owncloud) - */ - public static $APPSWEBROOT = ''; /* * requested app */ @@ -168,27 +164,31 @@ class OC{ // search the apps folder if(OC_Config::getValue('appsroot', '')<>''){ - OC::$APPSROOTS=explode(':',OC_Config::getValue('appsroot', '')); - OC::$APPSWEBROOT=OC_Config::getValue('appsurl', ''); - }elseif(file_exists(OC::$SERVERROOT.'/apps')){ - OC::$APPSROOTS= array(OC::$SERVERROOT.'/apps'); - OC::$APPSWEBROOT=OC::$WEBROOT; - } - if(file_exists(OC::$SERVERROOT.'/../apps')){ - OC::$APPSROOTS[] = rtrim(realpath(OC::$SERVERROOT.'/../apps'), '/'); -// OC::$APPSWEBROOT=rtrim(dirname(OC::$WEBROOT), '/'); + $real_a = explode(':',OC_Config::getValue('appsroot', '')); + $web_a = explode(':',OC_Config::getValue('appsurl', '')); + foreach($real_a as $k => $path) { + if(!isset($web_a[$k])){ + echo("Apps root and appsurl not mathing. You need to have the same number of paths"); + exit; + } + OC::$APPSROOTS[] = array('path'=> $path, 'web' => $web_a[$k]); + } } + if(empty(OC::$APPSROOTS)){ echo("apps directory not found! Please put the ownCloud apps folder in the ownCloud folder or the folder above. You can also configure the location in the config.php file."); exit; } + $paths = array(); + foreach( OC::$APPSROOTS as $path) + $paths[] = $path['path']; // set the right include path set_include_path( OC::$SERVERROOT.'/lib'.PATH_SEPARATOR. OC::$SERVERROOT.'/config'.PATH_SEPARATOR. OC::$THIRDPARTYROOT.'/3rdparty'.PATH_SEPARATOR. - implode(OC::$APPSROOTS,PATH_SEPARATOR).PATH_SEPARATOR. + implode($paths,PATH_SEPARATOR).PATH_SEPARATOR. get_include_path().PATH_SEPARATOR. OC::$SERVERROOT ); @@ -292,6 +292,7 @@ class OC{ require_once(OC::$APPSROOT . '/apps/' . OC::$REQUESTEDAPP . '/' . OC::$REQUESTEDFILE); } }else{ + die(); header('HTTP/1.0 404 Not Found'); exit; } diff --git a/lib/helper.php b/lib/helper.php index 72ae98222d9..550bf9771e4 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -48,7 +48,7 @@ class OC_Helper { $urlLinkTo = OC::$WEBROOT . '/?app=' . $app; $urlLinkTo .= ($file!='index.php')?'&getfile=' . urlencode($file):''; }else{ - $urlLinkTo = OC::$APPSWEBROOT . '/apps/' . $app . $file; + $urlLinkTo = OC_App::getAppWebPath($app) . $file; } } else{ @@ -151,7 +151,7 @@ class OC_Helper { if( file_exists( OC::$SERVERROOT."/themes/$theme/apps/$app/img/$image" )){ return OC::$WEBROOT."/themes/$theme/apps/$app/img/$image"; }elseif( file_exists(OC_App::getAppPath($app)."/img/$image" )){ - return OC::$APPSWEBROOT."/apps/$app/img/$image"; + return OC_App::getAppWebPath($app)."/img/$image"; }elseif( !empty( $app ) and file_exists( OC::$SERVERROOT."/themes/$theme/$app/img/$image" )){ return OC::$WEBROOT."/themes/$theme/$app/img/$image"; }elseif( !empty( $app ) and file_exists( OC::$SERVERROOT."/$app/img/$image" )){ diff --git a/lib/template.php b/lib/template.php index a354d58a4b1..e6525ec6336 100644 --- a/lib/template.php +++ b/lib/template.php @@ -415,8 +415,8 @@ class OC_Template{ $append = false; foreach( OC::$APPSROOTS as $apps_dir) { - if($page->appendIfExist('jsfiles', $apps_dir, OC::$APPSWEBROOT.'/apps/', "$script$fext.js" , true)) { $append =true; break; } - elseif($page->appendIfExist('jsfiles', $apps_dir, OC::$APPSWEBROOT.'/apps/', "$script.js", true )) { $append =true; break; } + if($page->appendIfExist('jsfiles', $apps_dir['path'], $apps_dir['web'], "$script$fext.js" , true)) { $append =true; break; } + elseif($page->appendIfExist('jsfiles', $apps_dir['path'], $apps_dir['web'], "$script.js", true )) { $append =true; break; } } if(! $append) { echo('js file not found: script:'.$script.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT); @@ -443,8 +443,8 @@ class OC_Template{ $append = false; foreach( OC::$APPSROOTS as $apps_dir) { - if($page->appendIfExist('cssfiles', $apps_dir, OC::$APPSWEBROOT, "$style$fext.css", true)) { $append =true; break; } - elseif($page->appendIfExist('cssfiles', $apps_dir, OC::$APPSWEBROOT, "$style.css", true )) { $append =true; break; } + if($page->appendIfExist('cssfiles', $apps_dir['path'], $apps_dir['web'], "$style$fext.css", true)) { $append =true; break; } + elseif($page->appendIfExist('cssfiles', $apps_dir['path'], $apps_dir['web'], "$style.css", true )) { $append =true; break; } } if(! $append) { echo('css file not found: style:'.$script.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT); -- cgit v1.2.3 From 6a812644e4d0f6eed8dca4e20c6f7135d881012a Mon Sep 17 00:00:00 2001 From: Brice Maron Date: Mon, 4 Jun 2012 20:37:00 +0000 Subject: Correct remote and public, and last occurence of OC:: --- apps/bookmarks/ajax/addBookmark.php | 2 +- apps/calendar/appinfo/remote.php | 4 ++-- apps/media/remote.php | 4 ++-- apps/media/server/xml.server.php | 4 ++-- apps/user_webfinger/webfinger.php | 2 +- lib/app.php | 4 ++-- lib/helper.php | 2 +- lib/installer.php | 32 +++++++++++++++++--------------- public.php | 6 +++--- remote.php | 6 +++--- 10 files changed, 34 insertions(+), 32 deletions(-) (limited to 'lib/app.php') diff --git a/apps/bookmarks/ajax/addBookmark.php b/apps/bookmarks/ajax/addBookmark.php index 9241dc8ddf6..d66aab58960 100644 --- a/apps/bookmarks/ajax/addBookmark.php +++ b/apps/bookmarks/ajax/addBookmark.php @@ -30,6 +30,6 @@ $RUNTIME_NOSETUPFS=true; OCP\JSON::checkLoggedIn(); OCP\JSON::checkAppEnabled('bookmarks'); -require_once(OC::$APPSROOT . '/apps/bookmarks/bookmarksHelper.php'); +require_once(OC_App::getAppPath('bookmarks').'/bookmarksHelper.php'); $id = addBookmark($_GET['url'], $_GET['title'], $_GET['tags']); OCP\JSON::success(array('data' => $id)); \ No newline at end of file diff --git a/apps/calendar/appinfo/remote.php b/apps/calendar/appinfo/remote.php index 3bd8737ee97..7ab546245f6 100644 --- a/apps/calendar/appinfo/remote.php +++ b/apps/calendar/appinfo/remote.php @@ -7,8 +7,8 @@ */ OCP\App::checkAppEnabled('calendar'); -if(substr($_SERVER["REQUEST_URI"],0,strlen(OC::$APPSWEBROOT . '/apps/calendar/caldav.php')) == OC::$APPSWEBROOT . '/apps/calendar/caldav.php'){ - $baseuri = OC::$APPSWEBROOT . '/apps/calendar/caldav.php'; +if(substr($_SERVER["REQUEST_URI"],0,strlen(OC_App::getAppWebPath('calendar').'/caldav.php')) == OC_App::getAppWebPath('calendar'). '/caldav.php'){ + $baseuri = OC_App::getAppWebPath('calendar').'/caldav.php'; } // only need authentication apps diff --git a/apps/media/remote.php b/apps/media/remote.php index 01add42b315..0535077cef1 100644 --- a/apps/media/remote.php +++ b/apps/media/remote.php @@ -5,7 +5,7 @@ $RUNTIME_APPTYPES=array('filesystem','authentication'); OC_App::loadApps($RUNTIME_APPTYPES); if($path_info == '/ampache' || $path_info == '/ampache/'){ - require_once(OC::$APPSROOT . '/apps/media/index.php'); + require_once(OC_App::getAppPath('media').'/index.php'); }else{ - require_once(OC::$APPSROOT . '/apps/media/server/xml.server.php'); + require_once(OC_App::getAppPath('media').'/server/xml.server.php'); } diff --git a/apps/media/server/xml.server.php b/apps/media/server/xml.server.php index 6cb6c91ca06..796da130a47 100644 --- a/apps/media/server/xml.server.php +++ b/apps/media/server/xml.server.php @@ -22,8 +22,8 @@ */ OCP\App::checkAppEnabled('media'); - require_once(OC::$APPSROOT . '/apps/media/lib_collection.php'); - require_once(OC::$APPSROOT . '/apps/media/lib_ampache.php'); + require_once(OC_App::getAppPath('media').'/lib_collection.php'); + require_once(OC_App::getAppPath('media').'/lib_ampache.php'); $arguments=$_POST; if(!isset($_POST['action']) and isset($_GET['action'])){ diff --git a/apps/user_webfinger/webfinger.php b/apps/user_webfinger/webfinger.php index e75c546c2cb..67cbba54a4c 100644 --- a/apps/user_webfinger/webfinger.php +++ b/apps/user_webfinger/webfinger.php @@ -59,7 +59,7 @@ echo "{\"links\":["; $apps = OC_Appconfig::getApps(); foreach($apps as $app) { if(OCP\App::isEnabled($app)) { - if(is_file(OC::$APPSROOT . '/apps/' . $app . '/appinfo/webfinger.php')) { + if(is_file(OC_App::getAppPath($app). '/appinfo/webfinger.php')) { require($app . '/appinfo/webfinger.php'); } } diff --git a/lib/app.php b/lib/app.php index 5883a29bb02..43d60f3a684 100755 --- a/lib/app.php +++ b/lib/app.php @@ -571,10 +571,10 @@ class OC_App{ //set remote/public handelers $appData=self::getAppInfo($appid); foreach($appData['remote'] as $name=>$path){ - OCP\CONFIG::setAppValue('core', 'remote_'.$name, '/apps/'.$appid.'/'.$path); + OCP\CONFIG::setAppValue('core', 'remote_'.$name, $path); } foreach($appData['public'] as $name=>$path){ - OCP\CONFIG::setAppValue('core', 'public_'.$name, '/apps/'.$appid.'/'.$path); + OCP\CONFIG::setAppValue('core', 'public_'.$name, $appid.'/'.$path); } self::setAppTypes($appid); diff --git a/lib/helper.php b/lib/helper.php index 550bf9771e4..3cf5107eea9 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -40,7 +40,7 @@ class OC_Helper { if( $app != '' ){ $app .= '/'; // Check if the app is in the app folder - if( file_exists( OC_App::getAppPath($app).$file )){ + if( file_exists( OC_App::getAppPath($app).'/'.$file )){ if(substr($file, -3) == 'php' || substr($file, -3) == 'css'){ if(substr($app, -1, 1) == '/'){ $app = substr($app, 0, strlen($app) - 1); diff --git a/lib/installer.php b/lib/installer.php index afe0b9e1bba..bfa34de2a7d 100644 --- a/lib/installer.php +++ b/lib/installer.php @@ -197,10 +197,10 @@ class OC_Installer{ //set remote/public handelers foreach($info['remote'] as $name=>$path){ - OCP\CONFIG::setAppValue('core', 'remote_'.$name, '/apps/'.$info['id'].'/'.$path); + OCP\CONFIG::setAppValue('core', 'remote_'.$name, $app.'/'.$path); } foreach($info['public'] as $name=>$path){ - OCP\CONFIG::setAppValue('core', 'public_'.$name, '/apps/'.$info['id'].'/'.$path); + OCP\CONFIG::setAppValue('core', 'public_'.$name, $app.'/'.$path); } OC_App::setAppTypes($info['id']); @@ -287,22 +287,24 @@ class OC_Installer{ * This function installs all apps found in the 'apps' directory that should be enabled by default; */ public static function installShippedApps(){ - $dir = opendir( OC::$APPSROOT."/apps" ); - while( false !== ( $filename = readdir( $dir ))){ - if( substr( $filename, 0, 1 ) != '.' and is_dir(OC::$APPSROOT."/apps/$filename") ){ - if( file_exists( OC::$APPSROOT."/apps/$filename/appinfo/app.php" )){ - if(!OC_Installer::isInstalled($filename)){ - $info=OC_App::getAppInfo($filename); - $enabled = isset($info['default_enable']); - if( $enabled ){ - OC_Installer::installShippedApp($filename); - OC_Appconfig::setValue($filename,'enabled','yes'); + foreach(OC::$APPSROOTS as $app_dir) { + $dir = opendir( $app_dir['path'] ); + while( false !== ( $filename = readdir( $dir ))){ + if( substr( $filename, 0, 1 ) != '.' and is_dir($app_dir['path']."/$filename") ){ + if( file_exists( $app_dir['path']."/$filename/appinfo/app.php" )){ + if(!OC_Installer::isInstalled($filename)){ + $info=OC_App::getAppInfo($filename); + $enabled = isset($info['default_enable']); + if( $enabled ){ + OC_Installer::installShippedApp($filename); + OC_Appconfig::setValue($filename,'enabled','yes'); + } } } } } + closedir( $dir ); } - closedir( $dir ); } /** @@ -325,10 +327,10 @@ class OC_Installer{ //set remote/public handelers foreach($info['remote'] as $name=>$path){ - OCP\CONFIG::setAppValue('core', 'remote_'.$name, '/apps/'.$app.'/'.$path); + OCP\CONFIG::setAppValue('core', 'remote_'.$name, $app.'/'.$path); } foreach($info['public'] as $name=>$path){ - OCP\CONFIG::setAppValue('core', 'public_'.$name, '/apps/'.$app.'/'.$path); + OCP\CONFIG::setAppValue('core', 'public_'.$name, $app.'/'.$path); } OC_App::setAppTypes($info['id']); diff --git a/public.php b/public.php index f974e1c50d2..19c02a7a027 100644 --- a/public.php +++ b/public.php @@ -8,8 +8,8 @@ if(is_null($file)){ exit; } -$parts=explode('/',$file); -$app=$parts[2]; +$parts=explode('/',$file,2); +$app=$parts[0]; OC_App::loadApp($app); -require_once(OC::$APPSROOT . $file); +require_once(OC_App::getAppPath($app) .'/'. $parts[1]); diff --git a/remote.php b/remote.php index 7131dfc9407..55b088d775e 100644 --- a/remote.php +++ b/remote.php @@ -17,9 +17,9 @@ if(is_null($file)){ exit; } -$parts=explode('/',$file); -$app=$parts[2]; +$parts=explode('/', $file, 2); +$app=$parts[0]; OC_App::loadApp($app); $baseuri = OC::$WEBROOT . '/remote.php/'.$service.'/'; -require_once(OC::$APPSROOT . $file); \ No newline at end of file +require_once(OC_App::getAppPath($app) .'/'. $parts[1]); \ No newline at end of file -- cgit v1.2.3 From 4260dce826cc0572371d5ab0d30ecf5f1ecb072a Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Thu, 7 Jun 2012 17:28:39 +0200 Subject: Better handling of core.css and core.js Fixes calling remote.php on install. Fixes http://bugs.owncloud.org/thebuggenie/owncloud/issues/oc-933 --- core/templates/layout.guest.php | 4 ++-- core/templates/layout.user.php | 4 ++-- lib/app.php | 5 +++++ lib/base.php | 7 ------- 4 files changed, 9 insertions(+), 11 deletions(-) (limited to 'lib/app.php') diff --git a/core/templates/layout.guest.php b/core/templates/layout.guest.php index 7f5a4d50fc6..55cc8008d9a 100644 --- a/core/templates/layout.guest.php +++ b/core/templates/layout.guest.php @@ -4,7 +4,7 @@ ownCloud - + @@ -14,7 +14,7 @@ var oc_webroot = ''; var oc_appswebroot = ''; - + diff --git a/core/templates/layout.user.php b/core/templates/layout.user.php index 8f6c029007f..e04fcabf137 100644 --- a/core/templates/layout.user.php +++ b/core/templates/layout.user.php @@ -4,7 +4,7 @@ <?php echo isset($_['application']) && !empty($_['application'])?$_['application'].' | ':'' ?>ownCloud <?php echo OC_User::getUser()?' ('.OC_User::getUser().') ':'' ?> - + @@ -15,7 +15,7 @@ var oc_appswebroot = ''; var oc_current_user = ''; - + diff --git a/lib/app.php b/lib/app.php index 667633e2647..e8a5a1291d9 100755 --- a/lib/app.php +++ b/lib/app.php @@ -67,6 +67,11 @@ class OC_App{ OC_Util::$scripts = array(); OC_Util::$core_styles = OC_Util::$styles; OC_Util::$styles = array(); + + if (!OC_AppConfig::getValue('core', 'remote_core.css', false)) { + OC_AppConfig::setValue('core', 'remote_core.css', '/core/minimizer.php'); + OC_AppConfig::setValue('core', 'remote_core.js', '/core/minimizer.php'); + } } } // return diff --git a/lib/base.php b/lib/base.php index a65a33b166e..4bd165862bb 100644 --- a/lib/base.php +++ b/lib/base.php @@ -426,13 +426,6 @@ class OC{ //make sure temporary files are cleaned up register_shutdown_function(array('OC_Helper','cleanTmp')); - if (OC_Config::getValue('installed', false)) { - if (!OC_AppConfig::getValue('core', 'remote_core.css', false)) { - OC_AppConfig::setValue('core', 'remote_core.css', '/core/minimizer.php'); - OC_AppConfig::setValue('core', 'remote_core.js', '/core/minimizer.php'); - } - } - //parse the given parameters self::$REQUESTEDAPP = (isset($_GET['app'])?str_replace(array('\0', '/', '\\', '..'), '', strip_tags($_GET['app'])):OC_Config::getValue('defaultapp', 'files')); if(substr_count(self::$REQUESTEDAPP, '?') != 0){ -- cgit v1.2.3 From 9ec68c819bf409905e3e3ab17cb4b2dd925cbde7 Mon Sep 17 00:00:00 2001 From: Brice Maron Date: Thu, 7 Jun 2012 20:36:55 +0000 Subject: Change parameter 'web' to 'url' and take array of array in config instead of : separated values --- lib/app.php | 2 +- lib/base.php | 21 ++++++++------------- lib/minimizer/css.php | 6 +++--- lib/minimizer/js.php | 4 ++-- lib/template.php | 8 ++++---- 5 files changed, 18 insertions(+), 23 deletions(-) (limited to 'lib/app.php') diff --git a/lib/app.php b/lib/app.php index 43d60f3a684..79a0a2e0534 100755 --- a/lib/app.php +++ b/lib/app.php @@ -342,7 +342,7 @@ class OC_App{ public static function getAppWebPath($appid) { foreach(OC::$APPSROOTS as $dir) { if(file_exists($dir['path'].'/'.$appid)) { - return $dir['web'].'/'.$appid; + return $dir['url'].'/'.$appid; } } return false; diff --git a/lib/base.php b/lib/base.php index 9f2925fa314..6e85f1a7346 100644 --- a/lib/base.php +++ b/lib/base.php @@ -55,7 +55,7 @@ class OC{ */ public static $THIRDPARTYWEBROOT = ''; /** - * The installation path array of the apps folder on the server (e.g. /srv/http/owncloud) 'real' and web path in 'web' + * The installation path array of the apps folder on the server (e.g. /srv/http/owncloud) 'path' and web path in 'url' */ public static $APPSROOTS = array(); /* @@ -161,22 +161,17 @@ class OC{ echo("3rdparty directory not found! Please put the ownCloud 3rdparty folder in the ownCloud folder or the folder above. You can also configure the location in the config.php file."); exit; } - // search the apps folder - if(OC_Config::getValue('appsroot', '')<>''){ - $real_a = explode(':',OC_Config::getValue('appsroot', '')); - $web_a = explode(':',OC_Config::getValue('appsurl', '')); - foreach($real_a as $k => $path) { - if(!isset($web_a[$k])){ - echo("Apps root and appsurl not mathing. You need to have the same number of paths"); - exit; - } - OC::$APPSROOTS[] = array('path'=> $path, 'web' => $web_a[$k]); + $config_paths = OC_Config::getValue('apps_paths', array()); + if(! empty($config_paths)){ + foreach($config_paths as $paths) { + if( isset($paths['url']) && isset($paths['path'])) + OC::$APPSROOTS[] = $paths; } }elseif(file_exists(OC::$SERVERROOT.'/apps')){ - OC::$APPSROOTS[] = array('path'=> OC::$SERVERROOT.'/apps', 'web' => OC::$WEBROOT.'/apps/'); + OC::$APPSROOTS[] = array('path'=> OC::$SERVERROOT.'/apps', 'url' => OC::$WEBROOT.'/apps/'); }elseif(file_exists(OC::$SERVERROOT.'/../apps')){ - OC::$APPSROOTS[] = array('path'=> rtrim(dirname(OC::$SERVERROOT), '/').'/apps', 'web' => rtrim(dirname(OC::$WEBROOT), '/').'/apps/'); + OC::$APPSROOTS[] = array('path'=> rtrim(dirname(OC::$SERVERROOT), '/').'/apps', 'url' => rtrim(dirname(OC::$WEBROOT), '/').'/apps/'); OC::$APPSROOT=rtrim(dirname(OC::$SERVERROOT), '/'); } diff --git a/lib/minimizer/css.php b/lib/minimizer/css.php index 5ba557c4cdc..c7e5d96e06b 100644 --- a/lib/minimizer/css.php +++ b/lib/minimizer/css.php @@ -28,8 +28,8 @@ class OC_Minimizer_CSS extends OC_Minimizer $append = false; foreach( OC::$APPSROOTS as $apps_dir) { - if($this->appendIfExist($apps_dir['path'], $apps_dir['web'], "$style$fext.css", true)) { $append =true; break; } - elseif($this->appendIfExist($apps_dir['path'], $apps_dir['web'], "$style.css", true )) { $append =true; break; } + if($this->appendIfExist($apps_dir['path'], $apps_dir['url'], "$style$fext.css", true)) { $append =true; break; } + elseif($this->appendIfExist($apps_dir['path'], $apps_dir['url'], "$style.css", true )) { $append =true; break; } } if(! $append) { echo('css file not found: style:'.$script.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT); @@ -65,7 +65,7 @@ class OC_Minimizer_CSS extends OC_Minimizer $in_root = false; foreach(OC::$APPSROOTS as $app_root) { if(strpos($file, $app_root['path']) == 0) { - $in_root = $app_root['web']; + $in_root = $app_root['url']; break; } } diff --git a/lib/minimizer/js.php b/lib/minimizer/js.php index 4002b11538f..dd7d15de061 100644 --- a/lib/minimizer/js.php +++ b/lib/minimizer/js.php @@ -42,8 +42,8 @@ class OC_Minimizer_JS extends OC_Minimizer $append = false; foreach( OC::$APPSROOTS as $apps_dir) { - if($this->appendIfExist($apps_dir['path'], $apps_dir['web'], "$script$fext.js" , true)) { $append =true; break; } - elseif($this->appendIfExist($apps_dir['path'], $apps_dir['web'], "$script.js", true )) { $append =true; break; } + if($this->appendIfExist($apps_dir['path'], $apps_dir['url'], "$script$fext.js" , true)) { $append =true; break; } + elseif($this->appendIfExist($apps_dir['path'], $apps_dir['url'], "$script.js", true )) { $append =true; break; } } if(! $append) { echo('js file not found: script:'.$script.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT); diff --git a/lib/template.php b/lib/template.php index 6fe07102034..b99d492a536 100644 --- a/lib/template.php +++ b/lib/template.php @@ -426,8 +426,8 @@ class OC_Template{ $append = false; foreach( OC::$APPSROOTS as $apps_dir) { - if($page->appendIfExist('jsfiles', $apps_dir['path'], $apps_dir['web'], "$script$fext.js" , true)) { $append =true; break; } - elseif($page->appendIfExist('jsfiles', $apps_dir['path'], $apps_dir['web'], "$script.js", true )) { $append =true; break; } + if($page->appendIfExist('jsfiles', $apps_dir['path'], $apps_dir['url'], "$script$fext.js" , true)) { $append =true; break; } + elseif($page->appendIfExist('jsfiles', $apps_dir['path'], $apps_dir['url'], "$script.js", true )) { $append =true; break; } } if(! $append) { echo('js file not found: script:'.$script.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT); @@ -454,8 +454,8 @@ class OC_Template{ $append = false; foreach( OC::$APPSROOTS as $apps_dir) { - if($page->appendIfExist('cssfiles', $apps_dir['path'], $apps_dir['web'], "$style$fext.css", true)) { $append =true; break; } - elseif($page->appendIfExist('cssfiles', $apps_dir['path'], $apps_dir['web'], "$style.css", true )) { $append =true; break; } + if($page->appendIfExist('cssfiles', $apps_dir['path'], $apps_dir['url'], "$style$fext.css", true)) { $append =true; break; } + elseif($page->appendIfExist('cssfiles', $apps_dir['path'], $apps_dir['url'], "$style.css", true )) { $append =true; break; } } if(! $append) { echo('css file not found: style:'.$script.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT); -- cgit v1.2.3 From ac365121022f8b03ac47c41f8b3e32f9ba3f90e6 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 8 Jun 2012 21:23:25 +0200 Subject: Don't use substr to get first char of string --- apps/files_archive/lib/storage.php | 2 +- apps/files_external/lib/ftp.php | 2 +- apps/files_external/lib/smb.php | 8 ++++---- apps/files_external/lib/swift.php | 2 +- apps/files_external/lib/webdav.php | 4 ++-- apps/user_ldap/lib_ldap.php | 4 ++-- lib/app.php | 2 +- lib/archive/tar.php | 4 ++-- lib/archive/zip.php | 2 +- lib/filesystem.php | 10 +++++----- lib/filesystemview.php | 2 +- lib/installer.php | 2 +- lib/user/database.php | 2 +- tests/index.php | 2 +- 14 files changed, 24 insertions(+), 24 deletions(-) (limited to 'lib/app.php') diff --git a/apps/files_archive/lib/storage.php b/apps/files_archive/lib/storage.php index b8f7d468385..86761663611 100644 --- a/apps/files_archive/lib/storage.php +++ b/apps/files_archive/lib/storage.php @@ -18,7 +18,7 @@ class OC_Filestorage_Archive extends OC_Filestorage_Common{ private static $rootView; private function stripPath($path){//files should never start with / - if(substr($path,0,1)=='/'){ + if(!$path || $path[0]=='/'){ $path=substr($path,1); } return $path; diff --git a/apps/files_external/lib/ftp.php b/apps/files_external/lib/ftp.php index e9655ebf3a5..4d5ae670de5 100644 --- a/apps/files_external/lib/ftp.php +++ b/apps/files_external/lib/ftp.php @@ -21,7 +21,7 @@ class OC_FileStorage_FTP extends OC_FileStorage_StreamWrapper{ $this->password=$params['password']; $this->secure=isset($params['secure'])?(bool)$params['secure']:false; $this->root=isset($params['root'])?$params['root']:'/'; - if(substr($this->root,0,1)!='/'){ + if(!$this->root || $this->root[0]!='/'){ $this->root='/'.$this->root; } diff --git a/apps/files_external/lib/smb.php b/apps/files_external/lib/smb.php index f594fbb880d..9112655194a 100644 --- a/apps/files_external/lib/smb.php +++ b/apps/files_external/lib/smb.php @@ -23,13 +23,13 @@ class OC_FileStorage_SMB extends OC_FileStorage_StreamWrapper{ $this->password=$params['password']; $this->share=$params['share']; $this->root=isset($params['root'])?$params['root']:'/'; + if(!$this->root || $this->root[0]!='/'){ + $this->root='/'.$this->root; + } if(substr($this->root,-1,1)!='/'){ $this->root.='/'; } - if(substr($this->root,0,1)!='/'){ - $this->root='/'.$this->root; - } - if(substr($this->share,0,1)!='/'){ + if(!$this->share || $this->share[0]!='/'){ $this->share='/'.$this->share; } if(substr($this->share,-1,1)=='/'){ diff --git a/apps/files_external/lib/swift.php b/apps/files_external/lib/swift.php index e3ba9c240cf..58b95a6ae01 100644 --- a/apps/files_external/lib/swift.php +++ b/apps/files_external/lib/swift.php @@ -269,7 +269,7 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{ $this->user=$params['user']; $this->root=isset($params['root'])?$params['root']:'/'; $this->secure=isset($params['secure'])?(bool)$params['secure']:true; - if(substr($this->root,0,1)!='/'){ + if(!$this->root || $this->root[0]!='/'){ $this->root='/'.$this->root; } $this->auth = new CF_Authentication($this->user, $this->token, null, $this->host); diff --git a/apps/files_external/lib/webdav.php b/apps/files_external/lib/webdav.php index 07c90d4878e..d136f04f3eb 100644 --- a/apps/files_external/lib/webdav.php +++ b/apps/files_external/lib/webdav.php @@ -25,7 +25,7 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{ $this->password=$params['password']; $this->secure=isset($params['secure'])?(bool)$params['secure']:false; $this->root=isset($params['root'])?$params['root']:'/'; - if(substr($this->root,0,1)!='/'){ + if(!$this->root || $this->root[0]!='/'){ $this->root='/'.$this->root; } if(substr($this->root,-1,1)!='/'){ @@ -273,7 +273,7 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{ } private function cleanPath($path){ - if(substr($path,0,1)=='/'){ + if(!$path || $path[0]=='/'){ return substr($path,1); }else{ return $path; diff --git a/apps/user_ldap/lib_ldap.php b/apps/user_ldap/lib_ldap.php index 22d464b65a2..befdf267bcd 100644 --- a/apps/user_ldap/lib_ldap.php +++ b/apps/user_ldap/lib_ldap.php @@ -576,7 +576,7 @@ class OC_LDAP { static private function combineFilter($filters, $operator) { $combinedFilter = '('.$operator; foreach($filters as $filter) { - if(substr($filter,0,1) != '(') { + if($filter[0] != '(') { $filter = '('.$filter.')'; } $combinedFilter.=$filter; @@ -692,4 +692,4 @@ class OC_LDAP { return false; } - } \ No newline at end of file + } diff --git a/lib/app.php b/lib/app.php index e8a5a1291d9..0c51e3c5532 100755 --- a/lib/app.php +++ b/lib/app.php @@ -469,7 +469,7 @@ class OC_App{ $apps=array(); $dh=opendir(OC::$APPSROOT.'/apps'); while($file=readdir($dh)){ - if(substr($file,0,1)!='.' and is_file(OC::$APPSROOT.'/apps/'.$file.'/appinfo/app.php')){ + if($file[0]!='.' and is_file(OC::$APPSROOT.'/apps/'.$file.'/appinfo/app.php')){ $apps[]=$file; } } diff --git a/lib/archive/tar.php b/lib/archive/tar.php index 4ff78779834..944a0ac4ba4 100644 --- a/lib/archive/tar.php +++ b/lib/archive/tar.php @@ -150,7 +150,7 @@ class OC_Archive_TAR extends OC_Archive{ $folderContent=array(); $pathLength=strlen($path); foreach($files as $file){ - if(substr($file,0,1)=='/'){ + if($file[0]=='/'){ $file=substr($file,1); } if(substr($file,0,$pathLength)==$path and $file!=$path){ @@ -241,7 +241,7 @@ class OC_Archive_TAR extends OC_Archive{ } } } - if(substr($path,0,1)!='/'){//not all programs agree on the use of a leading / + if($path[0]!='/'){//not all programs agree on the use of a leading / return $this->fileExists('/'.$path); }else{ return false; diff --git a/lib/archive/zip.php b/lib/archive/zip.php index 22ab48937eb..6631a649b16 100644 --- a/lib/archive/zip.php +++ b/lib/archive/zip.php @@ -191,7 +191,7 @@ class OC_Archive_ZIP extends OC_Archive{ } private function stripPath($path){ - if(substr($path,0,1)=='/'){ + if(!$path || $path[0]=='/'){ return substr($path,1); }else{ return $path; diff --git a/lib/filesystem.php b/lib/filesystem.php index 43d743b639d..337b0f1464b 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -150,7 +150,7 @@ class OC_Filesystem{ if(!$path){ $path='/'; } - if(substr($path,0,1)!=='/'){ + if($path[0]!=='/'){ $path='/'.$path; } $foundMountPoint=''; @@ -313,12 +313,12 @@ class OC_Filesystem{ * @param string mountpoint */ static public function mount($class,$arguments,$mountpoint){ + if($mountpoint[0]!='/'){ + $mountpoint='/'.$mountpoint; + } if(substr($mountpoint,-1)!=='/'){ $mountpoint=$mountpoint.'/'; } - if(substr($mountpoint,0,1)!=='/'){ - $mountpoint='/'.$mountpoint; - } self::$mounts[$mountpoint]=array('class'=>$class,'arguments'=>$arguments); } @@ -349,7 +349,7 @@ class OC_Filesystem{ * @return bool */ static public function isValidPath($path){ - if(substr($path,0,1)!=='/'){ + if(!$path || $path[0]!=='/'){ $path='/'.$path; } if(strstr($path,'/../') || strrchr($path, '/') === '/..' ){ diff --git a/lib/filesystemview.php b/lib/filesystemview.php index 8aa7b49f413..6e34257a460 100644 --- a/lib/filesystemview.php +++ b/lib/filesystemview.php @@ -51,7 +51,7 @@ class OC_FilesystemView { if(!$path){ $path='/'; } - if(substr($path,0,1)!=='/'){ + if($path[0]!=='/'){ $path='/'.$path; } return $this->fakeRoot.$path; diff --git a/lib/installer.php b/lib/installer.php index 5c030d2917d..34c6f8c7bb9 100644 --- a/lib/installer.php +++ b/lib/installer.php @@ -110,7 +110,7 @@ class OC_Installer{ //try to find it in a subdir $dh=opendir($extractDir); while($folder=readdir($dh)){ - if(substr($folder,0,1)!='.' and is_dir($extractDir.'/'.$folder)){ + if($folder[0]!='.' and is_dir($extractDir.'/'.$folder)){ if(is_file($extractDir.'/'.$folder.'/appinfo/info.xml')){ $extractDir.='/'.$folder; } diff --git a/lib/user/database.php b/lib/user/database.php index bb077c8364f..a48b8357d64 100644 --- a/lib/user/database.php +++ b/lib/user/database.php @@ -129,7 +129,7 @@ class OC_User_Database extends OC_User_Backend { $row=$result->fetchRow(); if($row){ $storedHash=$row['password']; - if (substr($storedHash,0,1)=='$'){//the new phpass based hashing + if ($storedHash[0]=='$'){//the new phpass based hashing $hasher=$this->getHasher(); if($hasher->CheckPassword($password.OC_Config::getValue('passwordsalt', ''), $storedHash)){ return $row['uid']; diff --git a/tests/index.php b/tests/index.php index 9c5178f81a8..691bf2a5d45 100644 --- a/tests/index.php +++ b/tests/index.php @@ -47,7 +47,7 @@ function loadTests($dir=''){ } if($dh=opendir($dir)){ while($name=readdir($dh)){ - if(substr($name,0,1)!='.'){//no hidden files, '.' or '..' + if($name[0]!='.'){//no hidden files, '.' or '..' $file=$dir.'/'.$name; if(is_dir($file)){ loadTests($file); -- cgit v1.2.3 From 6da5a2fdd4e8a19ab993b4a1f7de7e45b8922a16 Mon Sep 17 00:00:00 2001 From: Brice Maron Date: Thu, 14 Jun 2012 21:00:02 +0000 Subject: Add possibility to choose the installation folder --- config/config.sample.php | 12 ++++++------ lib/app.php | 39 +++++++++++++++++++++++++++++---------- lib/base.php | 4 ++-- lib/installer.php | 3 +-- lib/util.php | 16 +++++++++------- 5 files changed, 47 insertions(+), 27 deletions(-) (limited to 'lib/app.php') diff --git a/config/config.sample.php b/config/config.sample.php index bc66e9ebc05..afc04f8ec1b 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -33,17 +33,17 @@ $CONFIG = array( * If the apps dir is not writable, you can't download&install extra apps * in the admin apps menu. */ -"writable_appsdir" => true, // "datadirectory" => "", "apps_paths" => array( /* Set an array of path for your apps directories - key 'path' is for the fs path an the key url is for the http path to your - applications paths + key 'path' is for the fs path an the key 'url' is for the http path to your + applications paths. 'writable' indicate if the user can install apps in this folder. */ - array( - 'path'=> '/var/www/owncloud/apps', - 'url' => '/apps', + array( + 'path'=> '/var/www/owncloud/apps', + 'url' => '/apps', + 'writable' => true, ), ), ); diff --git a/lib/app.php b/lib/app.php index 79a0a2e0534..ca7a022f893 100755 --- a/lib/app.php +++ b/lib/app.php @@ -322,17 +322,39 @@ class OC_App{ return $list; } + /** + * Get the path where to install apps + */ + public static function getInstallPath() { + if(OC_Config::getValue('appstoreenabled', true)==false) { + return false; + } + + foreach(OC::$APPSROOTS as $dir) { + if(isset($dir['writable']) && $dir['writable']===true) + return $dir['path']; + } + + OC_Log::write('core','No application directories are marked as writable.',OC_Log::ERROR); + return null; + } + + + protected static function findAppInDirectories($appid) { + foreach(OC::$APPSROOTS as $dir) { + if(file_exists($dir['path'].'/'.$appid)) { + return $dir; + } + } + } /** * Get the directory for the given app. * If the app is defined in multiple directory, the first one is taken. (false if not found) */ public static function getAppPath($appid) { - foreach(OC::$APPSROOTS as $dir) { - if(file_exists($dir['path'].'/'.$appid)) { - return $dir['path'].'/'.$appid; - } + if( ($dir = self::findAppInDirectories($appid)) != false) { + return $dir['path'].'/'.$appid; } - return false; } /** @@ -340,12 +362,9 @@ class OC_App{ * If the app is defined in multiple directory, the first one is taken. (false if not found) */ public static function getAppWebPath($appid) { - foreach(OC::$APPSROOTS as $dir) { - if(file_exists($dir['path'].'/'.$appid)) { - return $dir['url'].'/'.$appid; - } + if( ($dir = self::findAppInDirectories($appid)) != false) { + return $dir['url'].'/'.$appid; } - return false; } /** diff --git a/lib/base.php b/lib/base.php index 6e85f1a7346..ca4052e5a18 100644 --- a/lib/base.php +++ b/lib/base.php @@ -169,9 +169,9 @@ class OC{ OC::$APPSROOTS[] = $paths; } }elseif(file_exists(OC::$SERVERROOT.'/apps')){ - OC::$APPSROOTS[] = array('path'=> OC::$SERVERROOT.'/apps', 'url' => OC::$WEBROOT.'/apps/'); + OC::$APPSROOTS[] = array('path'=> OC::$SERVERROOT.'/apps', 'url' => OC::$WEBROOT.'/apps/', 'writable' => true); }elseif(file_exists(OC::$SERVERROOT.'/../apps')){ - OC::$APPSROOTS[] = array('path'=> rtrim(dirname(OC::$SERVERROOT), '/').'/apps', 'url' => rtrim(dirname(OC::$WEBROOT), '/').'/apps/'); + OC::$APPSROOTS[] = array('path'=> rtrim(dirname(OC::$SERVERROOT), '/').'/apps', 'url' => rtrim(dirname(OC::$WEBROOT), '/').'/apps/', 'writable' => true); OC::$APPSROOT=rtrim(dirname(OC::$SERVERROOT), '/'); } diff --git a/lib/installer.php b/lib/installer.php index bfa34de2a7d..299674b29e4 100644 --- a/lib/installer.php +++ b/lib/installer.php @@ -126,8 +126,6 @@ class OC_Installer{ return false; } $info=OC_App::getAppInfo($extractDir.'/appinfo/info.xml',true); - $basedir=OC_App::getAppPath($info['id']); - // check the code for not allowed calls if(!OC_Installer::checkCode($info['id'],$extractDir)){ OC_Log::write('core','App can\'t be installed because of not allowed code in the App',OC_Log::ERROR); @@ -153,6 +151,7 @@ class OC_Installer{ return false; } + $basedir=OC_App::getInstallPath().'/'.$info['id']; //check if the destination directory already exists if(is_dir($basedir)){ OC_Log::write('core','App directory already exists',OC_Log::WARN); diff --git a/lib/util.php b/lib/util.php index 20888fa71f4..b344d576ebf 100644 --- a/lib/util.php +++ b/lib/util.php @@ -29,13 +29,15 @@ class OC_Util { $tmpl->printPage(); exit; } - - // Check if apps folder is writable. - if(OC_Config::getValue('writable_appsdir', true) && !is_writable(OC::$SERVERROOT."/apps/")) { - $tmpl = new OC_Template( '', 'error', 'guest' ); - $tmpl->assign('errors',array(1=>array('error'=>"Can't write into apps directory 'apps'",'hint'=>"You can usually fix this by giving the webserver user write access to the config directory in owncloud"))); - $tmpl->printPage(); - exit; + + // Check if there is a writable install folder. + if(OC_Config::getValue('appstoreenabled', true)) { + if( OC_App::getInstallPath() === null || !is_writable(OC_App::getInstallPath())) { + $tmpl = new OC_Template( '', 'error', 'guest' ); + $tmpl->assign('errors',array(1=>array('error'=>"Can't write into apps directory 'apps'",'hint'=>"You can usually fix this by giving the webserver user write access to the config directory in owncloud"))); + $tmpl->printPage(); + exit; + } } // Create root dir. -- cgit v1.2.3 From 2b228fba3463722ad19ea6ccd150b96772508791 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 15 Jun 2012 11:18:38 +0200 Subject: Load app before running update script --- lib/app.php | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/app.php') diff --git a/lib/app.php b/lib/app.php index 0c51e3c5532..7fdfc93138f 100755 --- a/lib/app.php +++ b/lib/app.php @@ -542,6 +542,7 @@ class OC_App{ return; } if(file_exists(OC::$APPSROOT.'/apps/'.$appid.'/appinfo/update.php')){ + self::loadApp($appid); include OC::$APPSROOT.'/apps/'.$appid.'/appinfo/update.php'; } -- cgit v1.2.3 From 6e9cd63fa1af24781c981c5535876f22fdb17934 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Sat, 16 Jun 2012 20:50:52 +0200 Subject: Only check for apps owncloud version requirment when there is a new owncloud version --- lib/app.php | 29 +++++++++++++++-------------- lib/base.php | 1 + 2 files changed, 16 insertions(+), 14 deletions(-) (limited to 'lib/app.php') diff --git a/lib/app.php b/lib/app.php index 7fdfc93138f..c08e977b032 100755 --- a/lib/app.php +++ b/lib/app.php @@ -489,32 +489,33 @@ class OC_App{ $currentVersion=OC_App::getAppVersion($app); if ($currentVersion) { if (version_compare($currentVersion, $installedVersion, '>')) { - OC_Log::write($app,'starting app upgrade from '.$installedVersion.' to '.$currentVersion,OC_Log::DEBUG); + OC_Log::write($app, 'starting app upgrade from '.$installedVersion.' to '.$currentVersion,OC_Log::DEBUG); OC_App::updateApp($app); - OC_Appconfig::setValue($app,'installed_version',OC_App::getAppVersion($app)); + OC_Appconfig::setValue($app, 'installed_version', OC_App::getAppVersion($app)); } } } + } - // check if the current enabled apps are compatible with the current ownCloud version. disable them if not. - // this is important if you upgrade ownCloud and have non ported 3rd party apps installed - $apps =OC_App::getEnabledApps(); - $version=OC_Util::getVersion(); + /** + * check if the current enabled apps are compatible with the current + * ownCloud version. disable them if not. + * This is important if you upgrade ownCloud and have non ported 3rd + * party apps installed. + */ + public static function checkAppsRequirements($apps = array()){ + if (empty($apps)) { + $apps = OC_App::getEnabledApps(); + } + $version = OC_Util::getVersion(); foreach($apps as $app) { - // check if the app is compatible with this version of ownCloud - $info=OC_App::getAppInfo($app); + $info = OC_App::getAppInfo($app); if(!isset($info['require']) or ($version[0]>$info['require'])){ OC_Log::write('core','App "'.$info['name'].'" can\'t be used because it is not compatible with this version of ownCloud',OC_Log::ERROR); OC_App::disable( $app ); } - - - } - - - } /** diff --git a/lib/base.php b/lib/base.php index fedc1238851..30f7e5bba63 100644 --- a/lib/base.php +++ b/lib/base.php @@ -229,6 +229,7 @@ class OC{ } OC_Config::setValue('version',implode('.',OC_Util::getVersion())); + OC_App::checkAppsRequirements(); } OC_App::updateApps(); -- cgit v1.2.3 From f46623da6cff1019ccce2adc61ea293e49a6fb34 Mon Sep 17 00:00:00 2001 From: Brice Maron Date: Thu, 21 Jun 2012 21:29:18 +0000 Subject: Do not search apps if oc is not yet installed --- lib/app.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/app.php') diff --git a/lib/app.php b/lib/app.php index 1a2dc370d69..071ac83b4f2 100755 --- a/lib/app.php +++ b/lib/app.php @@ -143,6 +143,8 @@ class OC_App{ * get all enabled apps */ public static function getEnabledApps(){ + if(!OC_Config::getValue('installed', false)) + return array(); $apps=array('files'); $query = OC_DB::prepare( 'SELECT appid FROM *PREFIX*appconfig WHERE configkey = \'enabled\' AND configvalue=\'yes\'' ); $result=$query->execute(); -- cgit v1.2.3 From ba2d203a543bdbf1c029b48485a59cb5e898d630 Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Fri, 22 Jun 2012 09:56:54 +0200 Subject: some path fixes for multi-dir app --- lib/app.php | 2 +- lib/templatelayout.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/app.php') diff --git a/lib/app.php b/lib/app.php index 071ac83b4f2..486704a2229 100755 --- a/lib/app.php +++ b/lib/app.php @@ -370,7 +370,7 @@ class OC_App{ */ public static function getAppWebPath($appid) { if( ($dir = self::findAppInDirectories($appid)) != false) { - return $dir['url'].'/'.$appid; + return OC::$WEBROOT.$dir['url'].'/'.$appid; } } diff --git a/lib/templatelayout.php b/lib/templatelayout.php index 6e1d435f671..d33a87e9e4c 100644 --- a/lib/templatelayout.php +++ b/lib/templatelayout.php @@ -181,8 +181,8 @@ class OC_TemplateLayout extends OC_Template { // Is it part of an app? $append = false; foreach( OC::$APPSROOTS as $apps_dir) { - if(self::appendIfExist($files, $apps_dir['path'], $apps_dir['url'], "$script$fext.js")) { $append =true; break; } - elseif(self::appendIfExist($files, $apps_dir['path'], $apps_dir['url'], "$script.js")) { $append =true; break; } + if(self::appendIfExist($files, $apps_dir['path'], OC::$WEBROOT.$apps_dir['url'], "$script$fext.js")) { $append =true; break; } + elseif(self::appendIfExist($files, $apps_dir['path'], OC::$WEBROOT.$apps_dir['url'], "$script.js")) { $append =true; break; } } if(! $append) { echo('js file not found: script:'.$script.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT); -- cgit v1.2.3 From d39d7fb9ff7d071b8981e6c8caf74fffb9eb0218 Mon Sep 17 00:00:00 2001 From: Brice Maron Date: Fri, 22 Jun 2012 22:05:39 +0000 Subject: Remove references to /apps/ and correct inclusion of settings --- apps/files_versions/appinfo/app.php | 4 ++-- apps/gallery/appinfo/app.php | 16 ++++++++-------- apps/gallery/index.php | 2 +- apps/media/appinfo/app.php | 6 +++--- lib/app.php | 6 +++--- 5 files changed, 17 insertions(+), 17 deletions(-) (limited to 'lib/app.php') diff --git a/apps/files_versions/appinfo/app.php b/apps/files_versions/appinfo/app.php index ef2f54dd3f9..bd06dc0ced3 100644 --- a/apps/files_versions/appinfo/app.php +++ b/apps/files_versions/appinfo/app.php @@ -1,6 +1,6 @@ Date: Sun, 24 Jun 2012 01:57:08 +0200 Subject: Trim trailing whitespace from version. --- lib/app.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/app.php') diff --git a/lib/app.php b/lib/app.php index 84d17957def..b337c55ec60 100755 --- a/lib/app.php +++ b/lib/app.php @@ -381,7 +381,7 @@ class OC_App{ $file= self::getAppPath($appid).'/appinfo/version'; $version=@file_get_contents($file); if($version){ - return $version; + return trim($version); }else{ $appData=self::getAppInfo($appid); return $appData['version']; -- cgit v1.2.3 From 2f0b4983e9019bb4a129f5578cf0a3ced1dab4d7 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Tue, 26 Jun 2012 20:41:11 +0200 Subject: Move app upgrade check to loading of apps --- lib/app.php | 24 ++++++++++-------------- lib/base.php | 4 ++-- 2 files changed, 12 insertions(+), 16 deletions(-) (limited to 'lib/app.php') diff --git a/lib/app.php b/lib/app.php index b337c55ec60..be17beeacc5 100755 --- a/lib/app.php +++ b/lib/app.php @@ -84,6 +84,7 @@ class OC_App{ */ public static function loadApp($app){ if(is_file(self::getAppPath($app).'/appinfo/app.php')){ + self::checkUpgrade($app); require_once( $app.'/appinfo/app.php' ); } } @@ -526,22 +527,17 @@ class OC_App{ } /** - * check if any apps need updating and update those + * check if the app need updating and update when needed */ - public static function updateApps(){ + public static function checkUpgrade($app) { $versions = self::getAppVersions(); - //ensure files app is installed for upgrades - if(!isset($versions['files'])){ - $versions['files']='0'; - } - foreach( $versions as $app=>$installedVersion ){ - $currentVersion=OC_App::getAppVersion($app); - if ($currentVersion) { - if (version_compare($currentVersion, $installedVersion, '>')) { - OC_Log::write($app, 'starting app upgrade from '.$installedVersion.' to '.$currentVersion,OC_Log::DEBUG); - OC_App::updateApp($app); - OC_Appconfig::setValue($app, 'installed_version', OC_App::getAppVersion($app)); - } + $currentVersion=OC_App::getAppVersion($app); + if ($currentVersion) { + $installedVersion = $versions[$app]; + if (version_compare($currentVersion, $installedVersion, '>')) { + OC_Log::write($app, 'starting app upgrade from '.$installedVersion.' to '.$currentVersion,OC_Log::DEBUG); + OC_App::updateApp($app); + OC_Appconfig::setValue($app, 'installed_version', OC_App::getAppVersion($app)); } } } diff --git a/lib/base.php b/lib/base.php index b4da6434e25..11e63e208eb 100644 --- a/lib/base.php +++ b/lib/base.php @@ -208,9 +208,9 @@ class OC{ OC_Config::setValue('version',implode('.',OC_Util::getVersion())); OC_App::checkAppsRequirements(); + // load all apps to also upgrade enabled apps + OC_App::loadApps(); } - - OC_App::updateApps(); } } -- cgit v1.2.3 From dab58f3464ec8aded5e0da4b050e5ee3d0bc5cfc Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Tue, 26 Jun 2012 20:53:28 +0200 Subject: Cache result of OC_App::getAppVersions --- lib/app.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/app.php') diff --git a/lib/app.php b/lib/app.php index be17beeacc5..a9feff1620a 100755 --- a/lib/app.php +++ b/lib/app.php @@ -567,6 +567,10 @@ class OC_App{ * get the installed version of all papps */ public static function getAppVersions(){ + static $versions; + if (isset($versions)) { // simple cache, needs to be fixed + return $versions; // when function is used besides in checkUpgrade + } $versions=array(); $query = OC_DB::prepare( 'SELECT appid, configvalue FROM *PREFIX*appconfig WHERE configkey = \'installed_version\'' ); $result = $query->execute(); -- cgit v1.2.3 From 2d8a380a21716f619bc38e769876dfa5752e6f68 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Wed, 27 Jun 2012 14:56:34 +0200 Subject: Fix recursion when running an update script --- lib/app.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib/app.php') diff --git a/lib/app.php b/lib/app.php index a9feff1620a..61566ed7522 100755 --- a/lib/app.php +++ b/lib/app.php @@ -36,6 +36,7 @@ class OC_App{ static private $appInfo = array(); static private $appTypes = array(); static private $loadedApps = array(); + static private $checkedApps = array(); /** * @brief loads all apps @@ -530,6 +531,10 @@ class OC_App{ * check if the app need updating and update when needed */ public static function checkUpgrade($app) { + if (in_array($app, self::$checkedApps)) { + return; + } + self::$checkedApps[] = $app; $versions = self::getAppVersions(); $currentVersion=OC_App::getAppVersion($app); if ($currentVersion) { -- cgit v1.2.3 From bf09edcbf1775115067611b85b954fbabad74ba3 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Thu, 28 Jun 2012 21:54:33 +0200 Subject: Remember the app root information. --- lib/app.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib/app.php') diff --git a/lib/app.php b/lib/app.php index 61566ed7522..d1f12594a25 100755 --- a/lib/app.php +++ b/lib/app.php @@ -350,9 +350,13 @@ class OC_App{ protected static function findAppInDirectories($appid) { + static $app_dir = array(); + if (isset($app_dir[$appid])) { + return $app_dir[$appid]; + } foreach(OC::$APPSROOTS as $dir) { if(file_exists($dir['path'].'/'.$appid)) { - return $dir; + return $app_dir[$appid]=$dir; } } } -- cgit v1.2.3 From 1ccbbfad530e4efdbfe301c8014ee7f31fa56220 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Thu, 28 Jun 2012 22:01:46 +0200 Subject: Spelling fix --- lib/app.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/app.php') diff --git a/lib/app.php b/lib/app.php index d1f12594a25..4c2c43ec26b 100755 --- a/lib/app.php +++ b/lib/app.php @@ -573,7 +573,7 @@ class OC_App{ } /** - * get the installed version of all papps + * get the installed version of all apps */ public static function getAppVersions(){ static $versions; -- cgit v1.2.3 From b45d3ced79b5a20034c85973760e2f120e1574e7 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 13 Jul 2012 22:44:35 +0200 Subject: fix remote and public.php --- apps/calendar/appinfo/version | 2 +- apps/contacts/appinfo/version | 2 +- apps/files/appinfo/version | 2 +- apps/files_sharing/appinfo/version | 2 +- apps/gallery/appinfo/version | 2 +- apps/media/appinfo/version | 2 +- lib/app.php | 2 +- public.php | 1 + remote.php | 10 ++++------ 9 files changed, 12 insertions(+), 13 deletions(-) (limited to 'lib/app.php') diff --git a/apps/calendar/appinfo/version b/apps/calendar/appinfo/version index 2eb3c4fe4ee..cb0c939a936 100644 --- a/apps/calendar/appinfo/version +++ b/apps/calendar/appinfo/version @@ -1 +1 @@ -0.5 +0.5.2 diff --git a/apps/contacts/appinfo/version b/apps/contacts/appinfo/version index 7dff5b89211..373f8c6f073 100644 --- a/apps/contacts/appinfo/version +++ b/apps/contacts/appinfo/version @@ -1 +1 @@ -0.2.1 \ No newline at end of file +0.2.3 \ No newline at end of file diff --git a/apps/files/appinfo/version b/apps/files/appinfo/version index 8cfbc905b39..9c1218c201f 100644 --- a/apps/files/appinfo/version +++ b/apps/files/appinfo/version @@ -1 +1 @@ -1.1.1 \ No newline at end of file +1.1.3 \ No newline at end of file diff --git a/apps/files_sharing/appinfo/version b/apps/files_sharing/appinfo/version index 7dff5b89211..f4778493c50 100644 --- a/apps/files_sharing/appinfo/version +++ b/apps/files_sharing/appinfo/version @@ -1 +1 @@ -0.2.1 \ No newline at end of file +0.2.2 \ No newline at end of file diff --git a/apps/gallery/appinfo/version b/apps/gallery/appinfo/version index 8f0916f768f..4b9fcbec101 100644 --- a/apps/gallery/appinfo/version +++ b/apps/gallery/appinfo/version @@ -1 +1 @@ -0.5.0 +0.5.1 diff --git a/apps/media/appinfo/version b/apps/media/appinfo/version index e6adf3fc7bb..44bb5d1f743 100644 --- a/apps/media/appinfo/version +++ b/apps/media/appinfo/version @@ -1 +1 @@ -0.4 \ No newline at end of file +0.4.1 \ No newline at end of file diff --git a/lib/app.php b/lib/app.php index 4c2c43ec26b..caf8bd82521 100755 --- a/lib/app.php +++ b/lib/app.php @@ -608,7 +608,7 @@ class OC_App{ //set remote/public handelers $appData=self::getAppInfo($appid); foreach($appData['remote'] as $name=>$path){ - OCP\CONFIG::setAppValue('core', 'remote_'.$name, $path); + OCP\CONFIG::setAppValue('core', 'remote_'.$name, $appid.'/'.$path); } foreach($appData['public'] as $name=>$path){ OCP\CONFIG::setAppValue('core', 'public_'.$name, $appid.'/'.$path); diff --git a/public.php b/public.php index 8846769f467..8383f36a246 100644 --- a/public.php +++ b/public.php @@ -10,6 +10,7 @@ if(is_null($file)){ $parts=explode('/',$file,2); $app=$parts[0]; + OC_Util::checkAppEnabled($app); OC_App::loadApp($app); diff --git a/remote.php b/remote.php index bdce867aaba..8c02c24e2a3 100644 --- a/remote.php +++ b/remote.php @@ -15,27 +15,25 @@ if (!$pos = strpos($path_info, '/', 1)) { $pos = strlen($path_info); } $service=substr($path_info, 1, $pos-1); + $file = OC_AppConfig::getValue('core', 'remote_' . $service); -$file = preg_replace('/apps\//','', $file); //Todo Remove after Multiappdir migration if(is_null($file)){ OC_Response::setStatus(OC_Response::STATUS_NOT_FOUND); exit; } -$file = ltrim ($file, '/'); - $parts=explode('/', $file, 2); $app=$parts[0]; switch ($app) { + case 'core': + $file = OC::$SERVERROOT .'/'. $file; + break; default: OC_Util::checkAppEnabled($app); OC_App::loadApp($app); $file = OC_App::getAppPath($app) .'/'. $parts[1]; break; - case 'core': - $file = OC::$SERVERROOT .'/'. $file; - break; } $baseuri = OC::$WEBROOT . '/remote.php/'.$service.'/'; require_once($file); -- cgit v1.2.3 From e707e948577b927a28b86545d345e7b6c8606352 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Sun, 15 Jul 2012 16:31:28 +0200 Subject: subadmins can now add users --- lib/app.php | 13 +++++-- lib/subadmin.php | 36 +++++++++++++----- lib/util.php | 9 ++--- settings/ajax/createuser.php | 29 +++++++++++++-- settings/js/users.js | 89 ++++++++++++++++++++++++++++++++------------ settings/templates/users.php | 20 ++++++---- settings/users.php | 12 +++--- 7 files changed, 149 insertions(+), 59 deletions(-) (limited to 'lib/app.php') diff --git a/lib/app.php b/lib/app.php index 4c2c43ec26b..9c3411a76bc 100755 --- a/lib/app.php +++ b/lib/app.php @@ -293,16 +293,21 @@ class OC_App{ if (OC_User::isLoggedIn()) { // personal menu $settings[] = array( "id" => "personal", "order" => 1, "href" => OC_Helper::linkTo( "settings", "personal.php" ), "name" => $l->t("Personal"), "icon" => OC_Helper::imagePath( "settings", "personal.svg" )); - + // if there're some settings forms if(!empty(self::$settingsForms)) // settings menu $settings[]=array( "id" => "settings", "order" => 1000, "href" => OC_Helper::linkTo( "settings", "settings.php" ), "name" => $l->t("Settings"), "icon" => OC_Helper::imagePath( "settings", "settings.svg" )); - - // if the user is an admin - if(OC_Group::inGroup( $_SESSION["user_id"], "admin" )) { + + //SubAdmins are also allowed to access user management + if(OC_SubAdmin::isSubAdmin($_SESSION["user_id"]) || OC_Group::inGroup( $_SESSION["user_id"], "admin" )){ // admin users menu $settings[] = array( "id" => "core_users", "order" => 2, "href" => OC_Helper::linkTo( "settings", "users.php" ), "name" => $l->t("Users"), "icon" => OC_Helper::imagePath( "settings", "users.svg" )); + } + + + // if the user is an admin + if(OC_Group::inGroup( $_SESSION["user_id"], "admin" )) { // admin apps menu $settings[] = array( "id" => "core_apps", "order" => 3, "href" => OC_Helper::linkTo( "settings", "apps.php" ).'?installed', "name" => $l->t("Apps"), "icon" => OC_Helper::imagePath( "settings", "apps.svg" )); diff --git a/lib/subadmin.php b/lib/subadmin.php index aad657b024f..b6f0b3007fd 100644 --- a/lib/subadmin.php +++ b/lib/subadmin.php @@ -38,9 +38,6 @@ class OC_SubAdmin{ public static function createSubAdmin($uid, $gid){ $stmt = OC_DB::prepare('INSERT INTO *PREFIX*group_admin (gid,uid) VALUES(?,?)'); $result = $stmt->execute(array($gid, $uid)); - if(OC_DB::isError($result)){ - return false; - } OC_Hook::emit( "OC_SubAdmin", "post_createSubAdmin", array( "gid" => $gid )); return true; } @@ -54,9 +51,6 @@ class OC_SubAdmin{ public static function deleteSubAdmin($uid, $gid){ $stmt = OC_DB::prepare('DELETE FROM *PREFIX*group_admin WHERE gid = ? AND uid = ?'); $result = $stmt->execute(array($gid, $uid)); - if(OC_DB::isError($result)){ - return false; - } OC_Hook::emit( "OC_SubAdmin", "post_deleteSubAdmin", array( "gid" => $gid )); return true; } @@ -68,7 +62,7 @@ class OC_SubAdmin{ */ public static function getSubAdminsGroups($uid){ $stmt = OC_DB::prepare('SELECT gid FROM *PREFIX*group_admin WHERE uid = ?'); - $result = $stmt->execute(array($gid, $uid)); + $result = $stmt->execute(array($uid)); $gids = array(); while($row = $result->fetchRow()){ $gids[] = $row['gid']; @@ -83,7 +77,7 @@ class OC_SubAdmin{ */ public static function getGroupsSubAdmins($gid){ $stmt = OC_DB::prepare('SELECT uid FROM *PREFIX*group_admin WHERE gid = ?'); - $result = $stmt->execute(array($gid, $uid)); + $result = $stmt->execute(array($gid)); $uids = array(); while($row = $result->fetchRow()){ $uids[] = $row['uid']; @@ -97,11 +91,35 @@ class OC_SubAdmin{ */ public static function getAllSubAdmins(){ $stmt = OC_DB::prepare('SELECT * FROM *PREFIX*group_admin'); - $result = $stmt->execute(array($gid, $uid)); + $result = $stmt->execute(); $subadmins = array(); while($row = $result->fetchRow()){ $subadmins[] = $row; } return $subadmins; } + + /** + * @brief checks if a user is a SubAdmin of a group + * @return array + */ + public static function isSubAdminofGroup($uid, $gid){ + $stmt = OC_DB::prepare('SELECT COUNT(*) as count FROM *PREFIX*group_admin where uid = ? AND gid = ?'); + $result = $stmt->execute(array($uid, $gid)); + $result = $result->fetchRow(); + if($result['count'] >= 1){ + return true; + } + return false; + } + + public static function isSubAdmin($uid){ + $stmt = OC_DB::prepare('SELECT COUNT(*) as count FROM *PREFIX*group_admin WHERE uid = ?'); + $result = $stmt->execute(array($uid)); + $result = $result->fetchRow(); + if($result['count'] > 0){ + return true; + } + return false; + } } diff --git a/lib/util.php b/lib/util.php index de9171edc8e..2eb102dfa69 100755 --- a/lib/util.php +++ b/lib/util.php @@ -328,16 +328,13 @@ class OC_Util { // Check if we are a user self::checkLoggedIn(); if(OC_Group::inGroup(OC_User::getUser(),'admin')){ - return OC_Group::getGroups(); + return true; } - $stmt = OC_DB::prepare('SELECT COUNT(*) as count FROM *PREFIX*group_admin WHERE uid = ?'); - $result = $stmt->execute(array(OC_User::getUser())); - $result = $result->fetchRow(); - if($result['count'] == 0){ + if(!OC_SubAdmin::isSubAdmin(OC_User::getUser())){ header( 'Location: '.OC_Helper::linkToAbsolute( '', 'index.php' )); exit(); } - return $groups; + return true; } /** diff --git a/settings/ajax/createuser.php b/settings/ajax/createuser.php index c56df4bc15a..41bf31a05f6 100644 --- a/settings/ajax/createuser.php +++ b/settings/ajax/createuser.php @@ -4,15 +4,36 @@ require_once('../../lib/base.php'); // Check if we are a user -if( !OC_User::isLoggedIn() || !OC_Group::inGroup( OC_User::getUser(), 'admin' )){ +if( !OC_User::isLoggedIn() || (!OC_Group::inGroup( OC_User::getUser(), 'admin' ) && !OC_SubAdmin::isSubAdmin(OC_User::getUser()))){ OC_JSON::error(array("data" => array( "message" => "Authentication error" ))); exit(); } OCP\JSON::callCheck(); -$groups = array(); -if( isset( $_POST["groups"] )){ - $groups = $_POST["groups"]; +$isadmin = OC_Group::inGroup(OC_User::getUser(),'admin')?true:false; + +if($isadmin){ + $groups = array(); + if( isset( $_POST["groups"] )){ + $groups = $_POST["groups"]; + } +}else{ + $accessiblegroups = OC_SubAdmin::getSubAdminsGroups(OC_User::getUser()); + $accessiblegroups = array_flip($accessiblegroups); + if(isset( $_POST["groups"] )){ + $unauditedgroups = $_POST["groups"]; + $groups = array(); + foreach($unauditedgroups as $group){ + if(array_key_exists($group, $accessiblegroups)){ + $groups[] = $group; + } + } + if(count($groups) == 0){ + $groups = array_flip($accessiblegroups); + } + }else{ + $groups = array_flip($accessiblegroups); + } } $username = $_POST["username"]; $password = $_POST["password"]; diff --git a/settings/js/users.js b/settings/js/users.js index dfa28e4c4cb..c86949db384 100644 --- a/settings/js/users.js +++ b/settings/js/users.js @@ -84,18 +84,56 @@ $(document).ready(function(){ } function applyMultiplySelect(element){ + console.log(element); var checked=[]; var user=element.data('username'); - if(element.data('userGroups')){ - checked=element.data('userGroups').split(', '); + if($(element).attr('class') == 'groupsselect'){ + if(element.data('userGroups')){ + checked=element.data('userGroups').split(', '); + } + if(user){ + var checkHandeler=function(group){ + if(user==OC.currentUser && group=='admin'){ + return false; + } + $.post( + OC.filePath('settings','ajax','togglegroups.php'), + { + username:user, + group:group + }, + function(){} + ); + }; + }else{ + checkHandeler=false; + } + var addGroup = function(group) { + $('select[multiple]').each(function(index, element) { + if ($(element).find('option[value="'+group +'"]').length == 0) { + $(element).append(''); + } + }) + }; + element.multiSelect({ + createCallback:addGroup, + createText:'add group', + checked:checked, + oncheck:checkHandeler, + onuncheck:checkHandeler, + minWidth: 100, + }); } - if(user){ + if($(element).attr('class') == 'subadminsselect'){ + if(element.data('subadmin')){ + checked=element.data('subadmin').split(', '); + } var checkHandeler=function(group){ - if(user==OC.currentUser && group=='admin'){ + if(group=='admin'){ return false; } $.post( - OC.filePath('settings','ajax','togglegroups.php'), + OC.filePath('settings','ajax','togglesubadmins.php'), { username:user, group:group @@ -103,24 +141,25 @@ $(document).ready(function(){ function(){} ); }; - }else{ - checkHandeler=false; + + var addSubAdmin = function(group) { + console.log('addSubAdmin called'); + console.log(group); + $('select[multiple]').each(function(index, element) { + if ($(element).find('option[value="'+group +'"]').length == 0) { + $(element).append(''); + } + }) + }; + element.multiSelect({ + createCallback:addSubAdmin, + createText:null, + checked:checked, + oncheck:checkHandeler, + onuncheck:checkHandeler, + minWidth: 100, + }); } - var addGroup = function(group) { - $('select[multiple]').each(function(index, element) { - if ($(element).find('option[value="'+group +'"]').length == 0) { - $(element).append(''); - } - }) - }; - element.multiSelect({ - createCallback:addGroup, - createText:'add group', - checked:checked, - oncheck:checkHandeler, - onuncheck:checkHandeler, - minWidth: 100, - }); } $('select[multiple]').each(function(index,element){ applyMultiplySelect($(element)); @@ -255,12 +294,14 @@ $(document).ready(function(){ OC.dialogs.alert(result.data.message, 'Error creating user'); } else { + groups = result.data.groups; + console.log(groups); var tr=$('#content table tbody tr').first().clone(); tr.attr('data-uid',username); tr.find('td.name').text(username); - var select=$(''); select.data('username',username); - select.data('userGroups',groups.join(', ')); + select.data('userGroups',groups); tr.find('td.groups').empty(); var allGroups=$('#content table').data('groups').split(', '); for(var i=0;i
@@ -16,6 +19,7 @@ $_['subadmingroups'] = $_['groups']; diff --git a/settings/users.php b/settings/users.php index e066956291b..60ffc337a72 100644 --- a/settings/users.php +++ b/settings/users.php @@ -19,20 +19,20 @@ $groups = array(); $isadmin = OC_Group::inGroup(OC_User::getUser(),'admin')?true:false; if($isadmin){ - $groups = OC_Group::getGroups(); + $accessiblegroups = OC_Group::getGroups(); $accessibleusers = OC_User::getUsers(); $subadmins = OC_SubAdmin::getAllSubAdmins(); }else{ - $groups = OC_SubAdmin::getSubAdminsGroups(OC_User::getUser()); - $accessibleusers = OC_Group::usersInGroups($groups); + $accessiblegroups = OC_SubAdmin::getSubAdminsGroups(OC_User::getUser()); + $accessibleusers = OC_Group::usersInGroups($accessiblegroups); $subadmins = false; } foreach($accessibleusers as $i){ - $users[] = array( "name" => $i, "groups" => join( ", ", /*array_intersect(*/OC_Group::getUserGroups($i)/*, OC_SubAdmin::getSubAdminsGroups(OC_User::getUser()))*/),'quota'=>OC_Preferences::getValue($i,'files','quota','default')); + $users[] = array( "name" => $i, "groups" => join( ", ", /*array_intersect(*/OC_Group::getUserGroups($i)/*, OC_SubAdmin::getSubAdminsGroups(OC_User::getUser()))*/),'quota'=>OC_Preferences::getValue($i,'files','quota','default'),'subadmin'=>implode(', ',OC_SubAdmin::getSubAdminsGroups($i))); } -foreach( $groups as $i ){ +foreach( $accessiblegroups as $i ){ // Do some more work here soon $groups[] = array( "name" => $i ); } @@ -55,7 +55,9 @@ if (\OC_App::isEnabled( "files_sharing" ) ) { $tmpl = new OC_Template( "settings", "users", "user" ); $tmpl->assign( "users", $users ); $tmpl->assign( "groups", $groups ); +$tmpl->assign( 'isadmin', $isadmin); $tmpl->assign( 'subadmins', $subadmins); +$tmpl->assign( 'numofgroups', count($accessiblegroups)); $tmpl->assign( 'quota_preset', $quotaPreset); $tmpl->assign( 'default_quota', $defaultQuota); $tmpl->assign( 'share_notice', $shareNotice); -- cgit v1.2.3 From 48306a3c4f708b80143757acbe9b270be476aab4 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 20 Jul 2012 17:51:50 +0200 Subject: fix unused variables --- lib/app.php | 1 - lib/db.php | 9 ++++----- lib/filestorage.php | 2 +- lib/filesystem.php | 17 ++++++++--------- lib/filesystemview.php | 2 +- lib/helper.php | 6 +++--- lib/image.php | 9 +++------ lib/migrate.php | 2 +- lib/ocs.php | 6 +----- lib/ocsclient.php | 2 +- lib/preferences.php | 8 ++++---- lib/setup.php | 1 - lib/streamwrappers.php | 5 ----- lib/template.php | 1 - lib/templatelayout.php | 2 +- lib/util.php | 2 -- 16 files changed, 28 insertions(+), 47 deletions(-) (limited to 'lib/app.php') diff --git a/lib/app.php b/lib/app.php index caf8bd82521..2b975de9ef0 100755 --- a/lib/app.php +++ b/lib/app.php @@ -27,7 +27,6 @@ * upgrading and removing apps. */ class OC_App{ - static private $init = false; static private $activeapp = ''; static private $navigation = array(); static private $settingsForms = array(); diff --git a/lib/db.php b/lib/db.php index 2a06d72ea32..6f083d17cfb 100644 --- a/lib/db.php +++ b/lib/db.php @@ -33,8 +33,6 @@ class OC_DB { static private $MDB2=false; static private $PDO=false; static private $schema=false; - static private $affected=0; - static private $result=false; static private $inTransaction=false; static private $prefix=null; static private $type=null; @@ -222,7 +220,7 @@ class OC_DB { echo( 'can not connect to database, using '.$type.'. ('.self::$MDB2->getUserInfo().')'); OC_Log::write('core',self::$MDB2->getUserInfo(),OC_Log::FATAL); OC_Log::write('core',self::$MDB2->getMessage(),OC_Log::FATAL); - die( $error ); + die(); } // We always, really always want associative arrays @@ -519,8 +517,9 @@ class OC_DB { // Delete our temporary file unlink( $file2 ); - foreach($definition['tables'] as $name=>$table){ - self::dropTable($name); + $tables=array_keys($definition['tables']); + foreach($tables as $table){ + self::dropTable($table); } } diff --git a/lib/filestorage.php b/lib/filestorage.php index 71ef4aed00b..e786127d525 100644 --- a/lib/filestorage.php +++ b/lib/filestorage.php @@ -24,7 +24,7 @@ * Provde a common interface to all different storage options */ abstract class OC_Filestorage{ - public function __construct($parameters){} + abstract public function __construct($parameters); abstract public function mkdir($path); abstract public function rmdir($path); abstract public function opendir($path); diff --git a/lib/filesystem.php b/lib/filesystem.php index 65318fa3ab6..5b31ed6c703 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -46,9 +46,10 @@ class OC_Filesystem{ static private $storages=array(); static private $mounts=array(); - static private $storageTypes=array(); public static $loaded=false; - private $fakeRoot=''; + /** + * @var OC_Filestorage $defaultInstance + */ static private $defaultInstance; @@ -155,7 +156,8 @@ class OC_Filesystem{ } $path=str_replace('//', '/',$path); $foundMountPoint=''; - foreach(OC_Filesystem::$mounts as $mountpoint=>$storage){ + $mountPoints=array_keys(OC_Filesystem::$mounts); + foreach($mountPoints as $mountpoint){ if($mountpoint==$path){ return $mountpoint; } @@ -260,10 +262,7 @@ class OC_Filesystem{ * tear down the filesystem, removing all storage providers */ static public function tearDown(){ - foreach(self::$storages as $mountpoint=>$storage){ - unset(self::$storages[$mountpoint]); - } - $fakeRoot=''; + self::$storages=array(); } /** @@ -287,7 +286,7 @@ class OC_Filesystem{ * @return bool */ static public function chroot($fakeRoot){ - return self::$defaultInstance->chroot($path); + return self::$defaultInstance->chroot($fakeRoot); } /** @@ -485,7 +484,7 @@ class OC_Filesystem{ * @return bool */ static public function hasUpdated($path,$time){ - return self::$defaultInstance->hasUpdated($path); + return self::$defaultInstance->hasUpdated($path,$time); } } diff --git a/lib/filesystemview.php b/lib/filesystemview.php index 448663bb081..a23d7bbe7fd 100644 --- a/lib/filesystemview.php +++ b/lib/filesystemview.php @@ -393,7 +393,7 @@ class OC_FilesystemView { return $this->basicOperation('getMimeType',$path); } public function hash($type,$path){ - return $this->basicOperation('hash',$path,array('read')); + return $this->basicOperation('hash',$path,array('read'),$type); } public function free_space($path='/'){ diff --git a/lib/helper.php b/lib/helper.php index 0d18098a4e7..c4f7e8b2e19 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -676,10 +676,10 @@ class OC_Helper { */ public static function mb_str_replace($search, $replace, $subject, $encoding = 'UTF-8', &$count = null) { $offset = -1; - $length = mb_strlen($search, 'UTF-8'); - while(($i = mb_strrpos($subject, $search, $offset, 'UTF-8'))) { + $length = mb_strlen($search, $encoding); + while(($i = mb_strrpos($subject, $search, $offset, $encoding))) { $subject = OC_Helper::mb_substr_replace($subject, $replace, $i, $length); - $offset = $i - mb_strlen($subject, 'UTF-8') - 1; + $offset = $i - mb_strlen($subject, $encoding) - 1; $count++; } return $subject; diff --git a/lib/image.php b/lib/image.php index 01e843d8316..c438b3d67f6 100644 --- a/lib/image.php +++ b/lib/image.php @@ -24,8 +24,8 @@ //From user comments at http://dk2.php.net/manual/en/function.exif-imagetype.php if ( ! function_exists( 'exif_imagetype' ) ) { function exif_imagetype ( $filename ) { - if ( ( list($width, $height, $type, $attr) = getimagesize( $filename ) ) !== false ) { - return $type; + if ( ( $info = getimagesize( $filename ) ) !== false ) { + return $info[2]; } return false; } @@ -364,7 +364,7 @@ class OC_Image { public function load($imageref) { if(is_resource($imageref)) { if(get_resource_type($imageref) == 'gd') { - $this->resource = $res; + $this->resource = $imageref; return $this->resource; } elseif(in_array(get_resource_type($imageref), array('file','stream'))) { return $this->loadFromFileHandle($imageref); @@ -650,9 +650,6 @@ class OC_Image { OC_Log::write('core',__METHOD__.'(): No image loaded', OC_Log::ERROR); return false; } - $width_orig=imageSX($this->resource); - $height_orig=imageSY($this->resource); - //OC_Log::write('core',__METHOD__.'(): Original size: '.$width_orig.'x'.$height_orig, OC_Log::DEBUG); $process = imagecreatetruecolor($w, $h); if ($process == false) { OC_Log::write('core',__METHOD__.'(): Error creating true color image',OC_Log::ERROR); diff --git a/lib/migrate.php b/lib/migrate.php index f788a637d3c..1b6367ed6ec 100644 --- a/lib/migrate.php +++ b/lib/migrate.php @@ -91,7 +91,7 @@ class OC_Migrate{ if( self::$exporttype == 'user' ){ // Check user exists if( !is_null($uid) ){ - $db = new OC_User_Database; + $db = new OC_User_Database; if( !$db->userExists( $uid ) ){ OC_Log::write('migration', 'User: '.$uid.' is not in the database and so cannot be exported.', OC_Log::ERROR); return json_encode( array( 'success' => false ) ); diff --git a/lib/ocs.php b/lib/ocs.php index 1be41202d78..77dd437d6c6 100644 --- a/lib/ocs.php +++ b/lib/ocs.php @@ -88,7 +88,6 @@ class OC_OCS { $method='get'; }elseif($_SERVER['REQUEST_METHOD'] == 'PUT') { $method='put'; - parse_str(file_get_contents("php://input"),$put_vars); }elseif($_SERVER['REQUEST_METHOD'] == 'POST') { $method='post'; }else{ @@ -356,9 +355,6 @@ class OC_OCS { * @return string xml/json */ private static function apiConfig($format) { - $user=OC_OCS::checkpassword(false); - $url=substr(OCP\Util::getServerHost().$_SERVER['SCRIPT_NAME'],0,-11).''; - $xml['version']='1.5'; $xml['website']='ownCloud'; $xml['host']=OCP\Util::getServerHost(); @@ -416,7 +412,7 @@ class OC_OCS { */ private static function activityPut($format,$message) { // not implemented in ownCloud - $user=OC_OCS::checkpassword(); + OC_OCS::checkpassword(); echo(OC_OCS::generatexml($format,'ok',100,'')); } diff --git a/lib/ocsclient.php b/lib/ocsclient.php index 951d761d7e6..ae35470cff6 100644 --- a/lib/ocsclient.php +++ b/lib/ocsclient.php @@ -71,7 +71,7 @@ class OC_OCSClient{ $tmp=$data->data; $cats=array(); - foreach($tmp->category as $key=>$value) { + foreach($tmp->category as $value) { $id= (int) $value->id; $name= (string) $value->name; diff --git a/lib/preferences.php b/lib/preferences.php index f72378ce94f..c91423e69bc 100644 --- a/lib/preferences.php +++ b/lib/preferences.php @@ -165,7 +165,7 @@ class OC_Preferences{ public static function deleteKey( $user, $app, $key ){ // No need for more comments $query = OC_DB::prepare( 'DELETE FROM *PREFIX*preferences WHERE userid = ? AND appid = ? AND configkey = ?' ); - $result = $query->execute( array( $user, $app, $key )); + $query->execute( array( $user, $app, $key )); return true; } @@ -181,7 +181,7 @@ class OC_Preferences{ public static function deleteApp( $user, $app ){ // No need for more comments $query = OC_DB::prepare( 'DELETE FROM *PREFIX*preferences WHERE userid = ? AND appid = ?' ); - $result = $query->execute( array( $user, $app )); + $query->execute( array( $user, $app )); return true; } @@ -196,7 +196,7 @@ class OC_Preferences{ public static function deleteUser( $user ){ // No need for more comments $query = OC_DB::prepare( 'DELETE FROM *PREFIX*preferences WHERE userid = ?' ); - $result = $query->execute( array( $user )); + $query->execute( array( $user )); return true; } @@ -211,7 +211,7 @@ class OC_Preferences{ public static function deleteAppFromAllUsers( $app ){ // No need for more comments $query = OC_DB::prepare( 'DELETE FROM *PREFIX*preferences WHERE appid = ?' ); - $result = $query->execute( array( $app )); + $query->execute( array( $app )); return true; } diff --git a/lib/setup.php b/lib/setup.php index 027c84db092..4d71bed86e2 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -102,7 +102,6 @@ class OC_Setup { } else { $oldUser=OC_Config::getValue('dbuser', false); - $oldPassword=OC_Config::getValue('dbpassword', false); $query="SELECT user FROM mysql.user WHERE user='$dbuser'"; //this should be enough to check for admin rights in mysql if(mysql_query($query, $connection)) { diff --git a/lib/streamwrappers.php b/lib/streamwrappers.php index f1e0fa0e1d9..f502c6170bd 100644 --- a/lib/streamwrappers.php +++ b/lib/streamwrappers.php @@ -1,6 +1,4 @@ name=substr($path,strlen('fakedir://')); $this->index=0; if(!isset(self::$dirs[$this->name])){ @@ -161,7 +157,6 @@ class OC_StaticStreamWrapper { public function stream_write($data) { if (!$this->writable) return 0; $size = strlen($data); - $len = strlen(self::$data[$this->path]); if ($this->stream_eof()) { self::$data[$this->path] .= $data; } else { diff --git a/lib/template.php b/lib/template.php index 3b48c27b9b4..5b6999af533 100644 --- a/lib/template.php +++ b/lib/template.php @@ -82,7 +82,6 @@ function relative_modified_date($timestamp) { $diffhours = round($diffminutes/60); $diffdays = round($diffhours/24); $diffmonths = round($diffdays/31); - $diffyears = round($diffdays/365); if($timediff < 60) { return $l->t('seconds ago'); } else if($timediff < 120) { return $l->t('1 minute ago'); } diff --git a/lib/templatelayout.php b/lib/templatelayout.php index d33a87e9e4c..588a7845997 100644 --- a/lib/templatelayout.php +++ b/lib/templatelayout.php @@ -123,7 +123,7 @@ class OC_TemplateLayout extends OC_Template { elseif(self::appendIfExist($files, $apps_dir['path'], $apps_dir['url'], "$style.css")) { $append =true; break; } } if(! $append) { - echo('css file not found: style:'.$script.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT); + echo('css file not found: style:'.$style.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT); die(); } } diff --git a/lib/util.php b/lib/util.php index 2a7b8a922f9..f35e5a18e42 100755 --- a/lib/util.php +++ b/lib/util.php @@ -189,8 +189,6 @@ class OC_Util { if(!(is_callable('sqlite_open') or class_exists('SQLite3')) and !is_callable('mysql_connect') and !is_callable('pg_connect')){ $errors[]=array('error'=>'No database drivers (sqlite, mysql, or postgresql) installed.
','hint'=>'');//TODO: sane hint } - $CONFIG_DBTYPE = OC_Config::getValue( "dbtype", "sqlite" ); - $CONFIG_DBNAME = OC_Config::getValue( "dbname", "owncloud" ); //common hint for all file permissons error messages $permissionsHint="Permissions can usually be fixed by giving the webserver write access to the ownCloud directory"; -- cgit v1.2.3 From 856d9c0b54cc971940df4ed64429d994faf770f9 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 24 Jul 2012 00:39:59 +0200 Subject: some indention fixes --- lib/app.php | 6 +- lib/db.php | 6 +- lib/filesystem.php | 186 ++++++++++++++++++++++++++--------------------------- lib/helper.php | 2 - lib/image.php | 13 ++-- lib/installer.php | 30 ++++----- lib/json.php | 14 ++-- lib/ocs.php | 19 +----- lib/util.php | 59 ++++++++--------- 9 files changed, 152 insertions(+), 183 deletions(-) (limited to 'lib/app.php') diff --git a/lib/app.php b/lib/app.php index 2b975de9ef0..56132c08671 100755 --- a/lib/app.php +++ b/lib/app.php @@ -195,7 +195,7 @@ class OC_App{ // check if the app is compatible with this version of ownCloud $info=OC_App::getAppInfo($app); $version=OC_Util::getVersion(); - if(!isset($info['require']) or ($version[0]>$info['require'])){ + if(!isset($info['require']) or ($version[0]>$info['require'])){ OC_Log::write('core','App "'.$info['name'].'" can\'t be installed because it is not compatible with this version of ownCloud',OC_Log::ERROR); return false; }else{ @@ -331,8 +331,8 @@ class OC_App{ } /** - * Get the path where to install apps - */ + * Get the path where to install apps + */ public static function getInstallPath() { if(OC_Config::getValue('appstoreenabled', true)==false) { return false; diff --git a/lib/db.php b/lib/db.php index 6f083d17cfb..6971fe4a583 100644 --- a/lib/db.php +++ b/lib/db.php @@ -368,9 +368,6 @@ class OC_DB { if( $definition instanceof MDB2_Schema_Error ){ die( $definition->getMessage().': '.$definition->getUserInfo()); } -// if(OC_Config::getValue('dbtype','sqlite')=='sqlite'){ -// $definition['overwrite']=true;//always overwrite for sqlite -// } $ret=self::$schema->createDatabase( $definition ); // Die in case something went wrong @@ -527,8 +524,7 @@ class OC_DB { * @brief replaces the owncloud tables with a new set * @param $file string path to the MDB2 xml db export file */ - public static function replaceDB( $file ){ - + public static function replaceDB( $file ){ $apps = OC_App::getAllApps(); self::beginTransaction(); // Delete the old tables diff --git a/lib/filesystem.php b/lib/filesystem.php index ec30ffb8f4c..a5edcf5bab3 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -53,99 +53,99 @@ class OC_Filesystem{ static private $defaultInstance; - /** - * classname which used for hooks handling - * used as signalclass in OC_Hooks::emit() - */ - const CLASSNAME = 'OC_Filesystem'; - - /** - * signalname emited before file renaming - * @param oldpath - * @param newpath - */ - const signal_rename = 'rename'; - - /** - * signal emited after file renaming - * @param oldpath - * @param newpath - */ - const signal_post_rename = 'post_rename'; - - /** - * signal emited before file/dir creation - * @param path - * @param run changing this flag to false in hook handler will cancel event - */ - const signal_create = 'create'; - - /** - * signal emited after file/dir creation - * @param path - * @param run changing this flag to false in hook handler will cancel event - */ - const signal_post_create = 'post_create'; - - /** - * signal emits before file/dir copy - * @param oldpath - * @param newpath - * @param run changing this flag to false in hook handler will cancel event - */ - const signal_copy = 'copy'; - - /** - * signal emits after file/dir copy - * @param oldpath - * @param newpath - */ - const signal_post_copy = 'post_copy'; - - /** - * signal emits before file/dir save - * @param path - * @param run changing this flag to false in hook handler will cancel event - */ - const signal_write = 'write'; - - /** - * signal emits after file/dir save - * @param path - */ - const signal_post_write = 'post_write'; - - /** - * signal emits when reading file/dir - * @param path - */ - const signal_read = 'read'; - - /** - * signal emits when removing file/dir - * @param path - */ - const signal_delete = 'delete'; - - /** - * parameters definitions for signals - */ - const signal_param_path = 'path'; - const signal_param_oldpath = 'oldpath'; - const signal_param_newpath = 'newpath'; - - /** - * run - changing this flag to false in hook handler will cancel event - */ - const signal_param_run = 'run'; - - /** - * get the mountpoint of the storage object for a path - ( note: because a storage is not always mounted inside the fakeroot, the returned mountpoint is relative to the absolute root of the filesystem and doesn't take the chroot into account - * - * @param string path - * @return string - */ + /** + * classname which used for hooks handling + * used as signalclass in OC_Hooks::emit() + */ + const CLASSNAME = 'OC_Filesystem'; + + /** + * signalname emited before file renaming + * @param oldpath + * @param newpath + */ + const signal_rename = 'rename'; + + /** + * signal emited after file renaming + * @param oldpath + * @param newpath + */ + const signal_post_rename = 'post_rename'; + + /** + * signal emited before file/dir creation + * @param path + * @param run changing this flag to false in hook handler will cancel event + */ + const signal_create = 'create'; + + /** + * signal emited after file/dir creation + * @param path + * @param run changing this flag to false in hook handler will cancel event + */ + const signal_post_create = 'post_create'; + + /** + * signal emits before file/dir copy + * @param oldpath + * @param newpath + * @param run changing this flag to false in hook handler will cancel event + */ + const signal_copy = 'copy'; + + /** + * signal emits after file/dir copy + * @param oldpath + * @param newpath + */ + const signal_post_copy = 'post_copy'; + + /** + * signal emits before file/dir save + * @param path + * @param run changing this flag to false in hook handler will cancel event + */ + const signal_write = 'write'; + + /** + * signal emits after file/dir save + * @param path + */ + const signal_post_write = 'post_write'; + + /** + * signal emits when reading file/dir + * @param path + */ + const signal_read = 'read'; + + /** + * signal emits when removing file/dir + * @param path + */ + const signal_delete = 'delete'; + + /** + * parameters definitions for signals + */ + const signal_param_path = 'path'; + const signal_param_oldpath = 'oldpath'; + const signal_param_newpath = 'newpath'; + + /** + * run - changing this flag to false in hook handler will cancel event + */ + const signal_param_run = 'run'; + + /** + * get the mountpoint of the storage object for a path + ( note: because a storage is not always mounted inside the fakeroot, the returned mountpoint is relative to the absolute root of the filesystem and doesn't take the chroot into account + * + * @param string path + * @return string + */ static public function getMountPoint($path){ OC_Hook::emit(self::CLASSNAME,'get_mountpoint',array('path'=>$path)); if(!$path){ diff --git a/lib/helper.php b/lib/helper.php index 59d88f46dad..f328c14ac77 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -175,10 +175,8 @@ class OC_Helper { */ public static function mimetypeIcon( $mimetype ){ $alias=array('application/xml'=>'code/xml'); -// echo $mimetype; if(isset($alias[$mimetype])){ $mimetype=$alias[$mimetype]; -// echo $mimetype; } // Replace slash with a minus $mimetype = str_replace( "/", "-", $mimetype ); diff --git a/lib/image.php b/lib/image.php index c438b3d67f6..90c64320a7c 100644 --- a/lib/image.php +++ b/lib/image.php @@ -23,12 +23,12 @@ //From user comments at http://dk2.php.net/manual/en/function.exif-imagetype.php if ( ! function_exists( 'exif_imagetype' ) ) { - function exif_imagetype ( $filename ) { - if ( ( $info = getimagesize( $filename ) ) !== false ) { - return $info[2]; - } - return false; - } + function exif_imagetype ( $filename ) { + if ( ( $info = getimagesize( $filename ) ) !== false ) { + return $info[2]; + } + return false; + } } function ellipsis($str, $maxlen) { @@ -66,7 +66,6 @@ class OC_Image { public function __construct($imageref = null) { //OC_Log::write('core',__METHOD__.'(): start', OC_Log::DEBUG); if(!extension_loaded('gd') || !function_exists('gd_info')) { - //if(!function_exists('imagecreatefromjpeg')) { OC_Log::write('core',__METHOD__.'(): GD module not installed', OC_Log::ERROR); return false; } diff --git a/lib/installer.php b/lib/installer.php index 00feb6d4709..a8b56cb34f2 100644 --- a/lib/installer.php +++ b/lib/installer.php @@ -126,19 +126,19 @@ class OC_Installer{ return false; } $info=OC_App::getAppInfo($extractDir.'/appinfo/info.xml',true); - // check the code for not allowed calls - if(!OC_Installer::checkCode($info['id'],$extractDir)){ + // check the code for not allowed calls + if(!OC_Installer::checkCode($info['id'],$extractDir)){ OC_Log::write('core','App can\'t be installed because of not allowed code in the App',OC_Log::ERROR); OC_Helper::rmdirr($extractDir); - return false; + return false; } - // check if the app is compatible with this version of ownCloud + // check if the app is compatible with this version of ownCloud $version=OC_Util::getVersion(); - if(!isset($info['require']) or ($version[0]>$info['require'])){ + if(!isset($info['require']) or ($version[0]>$info['require'])){ OC_Log::write('core','App can\'t be installed because it is not compatible with this version of ownCloud',OC_Log::ERROR); OC_Helper::rmdirr($extractDir); - return false; + return false; } //check if an app with the same id is already installed @@ -339,12 +339,12 @@ class OC_Installer{ } - /** - * check the code of an app with some static code checks - * @param string $folder the folder of the app to check - * @returns true for app is o.k. and false for app is not o.k. - */ - public static function checkCode($appname,$folder){ + /** + * check the code of an app with some static code checks + * @param string $folder the folder of the app to check + * @returns true for app is o.k. and false for app is not o.k. + */ + public static function checkCode($appname,$folder){ $blacklist=array( 'exec(', @@ -377,9 +377,7 @@ class OC_Installer{ return true; }else{ - return true; + return true; } - } - - + } } diff --git a/lib/json.php b/lib/json.php index c49b831c12b..b46878375d5 100644 --- a/lib/json.php +++ b/lib/json.php @@ -94,12 +94,12 @@ class OC_JSON{ * Encode and print $data in json format */ public static function encodedPrint($data,$setContentType=true){ - // Disable mimesniffing, don't move this to setContentTypeHeader! - header( 'X-Content-Type-Options: nosniff' ); - if($setContentType){ - self::setContentTypeHeader(); - } - array_walk_recursive($data, array('OC_JSON', 'to_string')); - echo json_encode($data); + // Disable mimesniffing, don't move this to setContentTypeHeader! + header( 'X-Content-Type-Options: nosniff' ); + if($setContentType){ + self::setContentTypeHeader(); + } + array_walk_recursive($data, array('OC_JSON', 'to_string')); + echo json_encode($data); } } diff --git a/lib/ocs.php b/lib/ocs.php index 0cd7888fcf9..9d30e172f55 100644 --- a/lib/ocs.php +++ b/lib/ocs.php @@ -111,21 +111,6 @@ class OC_OCS { $login = self::readData($method, 'login', 'text'); $passwd = self::readData($method, 'password', 'text'); OC_OCS::personcheck($format,$login,$passwd); -/* - } else if ($method == 'post' && $ex[$paracount - 4] == 'v1.php' && $ex[$paracount - 3] == 'person' && $ex[$paracount - 2] == 'add') { - if (OC_Group::inGroup(self::checkPassword(), 'admin')) { - $login = self::readData($method, 'login', 'text'); - $password = self::readData($method, 'password', 'text'); - try { - OC_User::createUser($login, $password); - echo self::generateXml($format, 'ok', 201, ''); - } catch (Exception $exception) { - echo self::generateXml($format, 'fail', 400, $exception->getMessage()); - } - } else { - echo self::generateXml($format, 'fail', 403, 'Permission denied'); - } -*/ // ACTIVITY // activityget - GET ACTIVITY page,pagesize als urlparameter @@ -149,8 +134,8 @@ class OC_OCS { }elseif(($method=='get') and ($ex[$paracount-5] == 'v1.php') and ($ex[$paracount-3] == 'getattribute')){ $app=$ex[$paracount-2]; OC_OCS::privateDataGet($format, $app); - }elseif(($method=='get') and ($ex[$paracount-6] == 'v1.php') and ($ex[$paracount-4] == 'getattribute')){ - + }elseif(($method=='get') and ($ex[$paracount-6] == 'v1.php') and ($ex[$paracount-4] == 'getattribute')){ + $key=$ex[$paracount-2]; $app=$ex[$paracount-3]; OC_OCS::privateDataGet($format, $app,$key); diff --git a/lib/util.php b/lib/util.php index f35e5a18e42..0c563278cc5 100755 --- a/lib/util.php +++ b/lib/util.php @@ -77,13 +77,13 @@ class OC_Util { return '5 pre alpha'; } - /** - * get the current installed edition of ownCloud. There is the community edition that just returns an empty string and the enterprise edition that returns "Enterprise". - * @return string - */ - public static function getEditionString(){ - return ''; - } + /** + * get the current installed edition of ownCloud. There is the community edition that just returns an empty string and the enterprise edition that returns "Enterprise". + * @return string + */ + public static function getEditionString(){ + return ''; + } /** * add a javascript file @@ -131,12 +131,12 @@ class OC_Util { self::$headers[]=array('tag'=>$tag,'attributes'=>$attributes,'text'=>$text); } - /** - * formats a timestamp in the "right" way - * - * @param int timestamp $timestamp - * @param bool dateOnly option to ommit time from the result - */ + /** + * formats a timestamp in the "right" way + * + * @param int timestamp $timestamp + * @param bool dateOnly option to ommit time from the result + */ public static function formatDate( $timestamp,$dateOnly=false){ if(isset($_SESSION['timezone'])){//adjust to clients timezone if we know it $systemTimeZone = intval(date('O')); @@ -438,26 +438,25 @@ class OC_Util { } - /** - * Check if the htaccess file is working by creating a test file in the data directory and trying to access via http - */ - public static function ishtaccessworking() { - + /** + * Check if the htaccess file is working by creating a test file in the data directory and trying to access via http + */ + public static function ishtaccessworking() { // testdata $filename='/htaccesstest.txt'; $testcontent='testcontent'; // creating a test file - $testfile = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" ).'/'.$filename; - $fp = @fopen($testfile, 'w'); - @fwrite($fp, $testcontent); - @fclose($fp); + $testfile = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" ).'/'.$filename; + $fp = @fopen($testfile, 'w'); + @fwrite($fp, $testcontent); + @fclose($fp); // accessing the file via http - $url = OC_Helper::serverProtocol(). '://' . OC_Helper::serverHost() . OC::$WEBROOT.'/data'.$filename; - $fp = @fopen($url, 'r'); - $content=@fread($fp, 2048); - @fclose($fp); + $url = OC_Helper::serverProtocol(). '://' . OC_Helper::serverHost() . OC::$WEBROOT.'/data'.$filename; + $fp = @fopen($url, 'r'); + $content=@fread($fp, 2048); + @fclose($fp); // cleanup @unlink($testfile); @@ -467,13 +466,7 @@ class OC_Util { return(false); }else{ return(true); - } - - } - - - - + } } -- cgit v1.2.3 From a6ce497dd932fc013301e433c635c6286fffe513 Mon Sep 17 00:00:00 2001 From: Alessandro Cosentino Date: Sat, 4 Aug 2012 13:39:36 -0400 Subject: OC_App::getAppVersion return blank if version is not specified --- lib/app.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/app.php') diff --git a/lib/app.php b/lib/app.php index d1018c37aa7..2e9ec4d6308 100755 --- a/lib/app.php +++ b/lib/app.php @@ -394,7 +394,7 @@ class OC_App{ return trim($version); }else{ $appData=self::getAppInfo($appid); - return $appData['version']; + return isset($appData['version'])? $appData['version'] : ''; } } -- cgit v1.2.3 From cc445e4e477944a680bb19919cbfd0330d0f7851 Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Sun, 5 Aug 2012 01:40:19 +0200 Subject: Small changes to allow updating main menu dynamically. --- core/templates/layout.user.php | 2 +- lib/app.php | 11 ++++++----- lib/installer.php | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) (limited to 'lib/app.php') diff --git a/core/templates/layout.user.php b/core/templates/layout.user.php index dc303ffc1a7..2abe4da8538 100644 --- a/core/templates/layout.user.php +++ b/core/templates/layout.user.php @@ -55,7 +55,7 @@