From: Jakob Sack Date: Sun, 13 Mar 2011 16:25:34 +0000 (+0100) Subject: OC_HELPER, OC_LOG and OC_TEMPLATE prepared for refactoring X-Git-Tag: v3.0~267^2~558^2~172 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a3070405d94621d01cc97ca10cc9cdf220e14064;p=nextcloud-server.git OC_HELPER, OC_LOG and OC_TEMPLATE prepared for refactoring --- diff --git a/lib/app.php b/lib/app.php index 52c9f11456a..203bf7b684c 100644 --- a/lib/app.php +++ b/lib/app.php @@ -83,6 +83,7 @@ class OC_APP{ * */ public static function register( $data ){ + // TODO: write function OC_APP::$apps[] = $data; } @@ -93,6 +94,7 @@ class OC_APP{ * This function returns all data it got via register(). */ public static function get(){ + // TODO: write function return OC_APP::$apps; } diff --git a/lib/config.php b/lib/config.php index 637497734ca..3e660a5fb55 100644 --- a/lib/config.php +++ b/lib/config.php @@ -20,6 +20,19 @@ * License along with this library. If not, see . * */ +/* + * + * An example of config.php + * + * "mysql", + * "firstrun" => false, + * "pi" => 3.14 + * ); + * ?> + * + */ /** * This class is responsible for reading and writing config.php, the very basic @@ -86,5 +99,3 @@ class OC_CONFIG{ } } ?> - - diff --git a/lib/helper.php b/lib/helper.php index 5999c33a458..a10697c3933 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -1,64 +1,62 @@ . -* -*/ - + * ownCloud + * + * @author Frank Karlitschek + * @author Jakob Sack + * @copyright 2010 Frank Karlitschek karlitschek@kde.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see . + * + */ /** - * Class for utility functions - * + * Collection of useful functions */ class OC_HELPER { /** - * Create an url + * @brief Creates an url + * @param $app app + * @param $file file + * @returns the url * - * @param string $application - * @param string $file + * Returns a url to the given app and file. */ - public static function linkTo( $application, $file = null ){ + public static function linkTo( $app, $file ){ global $WEBROOT; - if( is_null( $file )){ - $file = $application; - $application = ""; - } - return "$WEBROOT/$application/$file"; + return "$WEBROOT/$app/$file"; } /** - * Create an image link + * @brief Creates path to an image + * @param $app app + * @param $image image name + * @returns the url * - * @param string $application - * @param string $file + * Returns the path to the image. */ - public static function imagePath( $application, $file = null ){ + public static function imagePath( $app, $image ){ global $WEBROOT; - if( is_null( $file )){ - $file = $application; - $application = ""; - } - return "$WEBROOT/$application/img/$file"; + return "$WEBROOT/$app/img/$image"; } /** - * show an icon for a filetype + * @brief get path to icon of mime type + * @param $mimetype mimetype + * @returns the url * + * Returns the path to the image of this mime type. */ public static function mimetypeIcon( $mimetype ){ global $SERVERROOT; @@ -81,8 +79,11 @@ class OC_HELPER { } /** - * Human filesize (1 kB for 1024 etc. ) + * @brief Make a human file size + * @param $bytes file size in bytes + * @returns a human readable file size * + * Makes 2048 to 2 kB. */ public static function humanFileSize( $bytes ){ if( $bytes < 1024 ){ diff --git a/lib/log.php b/lib/log.php index f2f935b466b..289ab18faba 100644 --- a/lib/log.php +++ b/lib/log.php @@ -1,75 +1,90 @@ . -* -*/ - + * ownCloud + * + * @author Frank Karlitschek + * @author Jakob Sack + * @copyright 2010 Frank Karlitschek karlitschek@kde.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see . + * + */ +/* + * + * The following SQL statement is just a help for developers and will not be + * executed! + * + * CREATE TABLE `log` ( + * `id` INT PRIMARY KEY AUTO INCREMENT, + * `timestamp` DATETIME NOT NULL, + * `appid` VARCHAR( 255 ) NOT NULL , + * `subject` VARCHAR( 255 ), + * `predicate` VARCHAR( 255 ), + * `object` TEXT + * ) + * + */ /** - * Class for logging features - * + * This class is for logging */ class OC_LOG { - /** - * array to define different log types + * @brief adds an entry to the log + * @param $appid id of the app + * @param $subject username + * @param $predicate action + * @param $object = null; additional information + * @returns true/false * + * This function adds another entry to the log database */ - public static $TYPE = array ( - 1=>'login', - 2=>'logout', - 3=>'read', - 4=>'write' ); - + public static function add( $subject, $predicate, $object = null ){ + // TODO: write function + return true; + } /** - * log an event + * @brief Fetches log entries + * @param $filter = array(); array with filter options + * @returns array with entries + * + * This function fetches the log entries according to the filter options + * passed. * - * @param username $user - * @param type $type - * @param message $message + * $filter is an associative array. + * The following keys are optional: + * - from: all entries after this date + * - until: all entries until this date + * - user: username (default: current user) + * - app: only entries for this app */ - public static function event($user,$type,$message){ - global $CONFIG_DBTABLEPREFIX; - $result = OC_DB::query('INSERT INTO `' . $CONFIG_DBTABLEPREFIX . 'log` (`timestamp`,`user`,`type`,`message`) VALUES ('.time().',\''.addslashes($user).'\','.addslashes($type).',\''.addslashes($message).'\');'); + public static function get( $filter = array()){ + // TODO: write function + return array(); } - /** - * get log entries + * @brief removes log entries + * @param $date delete entries older than this date + * @returns true/false + * + * This function deletes all entries that are older than $date. */ - public static function get(){ - global $CONFIG_DATEFORMAT; - global $CONFIG_DBTABLEPREFIX; - - $result; - - if(OC_USER::ingroup($_SESSION['username_clean'],'admin')){ - $result = OC_DB::select('select `timestamp`,`user`,`type`,`message` from '.$CONFIG_DBTABLEPREFIX.'log order by timestamp desc limit 20'); - } - else{ - $user=$_SESSION['username_clean']; - $result = OC_DB::select('select `timestamp`,`user`,`type`,`message` from '.$CONFIG_DBTABLEPREFIX.'log where user=\''.$user.'\' order by timestamp desc limit 20'); - } - - return $result; + public static function deleteBefore( $date ){ + // TODO: write function + return true; } } diff --git a/lib/template.php b/lib/template.php index cd576a89f94..6184e4f59a2 100644 --- a/lib/template.php +++ b/lib/template.php @@ -1,100 +1,155 @@ . -* -*/ + * ownCloud + * + * @author Frank Karlitschek + * @author Jakob Sack + * @copyright 2010 Frank Karlitschek karlitschek@kde.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see . + * + */ /** + * @brief make OC_HELPER::linkTo available as a simple function + * @param $app app + * @param $file file + * @returns link to the file * + * For further information have a look at OC_HELPER::linkTo */ function link_to( $app, $file ){ return OC_HELPER::linkTo( $app, $file ); } /** + * @brief make OC_HELPER::imagePath available as a simple function + * @param $app app + * @param $image image + * @returns link to the image * + * For further information have a look at OC_HELPER::imagePath */ -function image_path( $app, $file ){ - return OC_HELPER::imagePath( $app, $file ); +function image_path( $app, $image ){ + return OC_HELPER::imagePath( $app, $image ); } /** + * @brief make OC_HELPER::mimetypeIcon available as a simple function + * @param $mimetype mimetype + * @returns link to the image * + * For further information have a look at OC_HELPER::mimetypeIcon */ function mimetype_icon( $mimetype ){ return OC_HELPER::mimetypeIcon( $mimetype ); } /** + * @brief make OC_HELPER::humanFileSize available as a simple function + * @param $bytes size in bytes + * @returns size as string * + * For further information have a look at OC_HELPER::humanFileSize */ function human_file_size( $bytes ){ return OC_HELPER::humanFileSize( $bytes ); } +/** + * This class provides the templates for owncloud. + */ class OC_TEMPLATE{ private $renderas; // Create a full page? private $application; // template Application private $vars; // The smarty object private $template; // The smarty object - public function __construct( $application, $name, $renderas = "" ){ + /** + * @brief Constructor + * @param $app app providing the template + * @param $file name of the tempalte file (without suffix) + * @param $renderas = ""; produce a full page + * @returns OC_TEMPLATE object + * + * This function creates an OC_TEMPLATE object. + * + * If $renderas is set, OC_TEMPLATE will try to produce a full page in the + * according layout. For now, renderas can be set to "guest", "user" or + * "admin". + */ + public function __construct( $app, $name, $renderas = "" ){ // Global vars we need global $SERVERROOT; - $template = "$SERVERROOT/templates/"; // Get the right template folder - if( $application != "core" && $application != "" ){ - $template = "$SERVERROOT/$application/templates/"; + $template = "$SERVERROOT/templates/"; + if( $app != "core" && $app != "" ){ + $template = "$SERVERROOT/$app/templates/"; } // Templates have the ending .tmpl - $template .= "$name.php"; + $template .= "$name.html"; // Set the private data $this->renderas = $renderas; - $this->application = $application; + $this->application = $app; $this->template = $template; $this->vars = array(); } - public function assign( $a, $b ){ - $this->vars[$a] = $b; + /** + * @brief Assign variables + * @param $key key + * @param $value value + * @returns true + * + * This function assigns a variable. It can be accessed via $_[$key] in + * the template. + * + * If the key existed before, it will be overwritten + */ + public function assign( $key, $value ){ + $this->vars[$key] = $value; + return true; } - public function append( $a, $b ){ - if( array_key_exists( $a, $this->vars )){ - if( is_array( $this->vars[$a] )){ - $this->vars[$a][] = $b; - } - else - { - $array = array( $this->vars[$a], $b ); - $this->vars[$a] = $array; - } + /** + * @brief Appends a variable + * @param $key key + * @param $value value + * @returns true + * + * This function assigns a variable in an array context. If the key already + * exists, the value will be appended. It can be accessed via + * $_[$key][$position] in the template. + */ + public function append( $key, $value ){ + if( array_key_exists( $key, $this->vars )){ + $this->vars[$key][] = $value; } else{ - $this->vars[$a] = $b; + $this->vars[$key] = array( $value ); } } + /** + * @brief Prints the proceeded template + * @returns true/false + * + * This function proceeds the template and prints its output. + */ public function printPage() { $data = $this->fetchPage(); @@ -109,6 +164,13 @@ class OC_TEMPLATE{ } } + /** + * @brief Proceeds the template + * @returns content + * + * This function proceeds the template. If $this->renderas is set, it will + * will produce a full page. + */ public function fetchPage() { // global Data we need @@ -143,8 +205,8 @@ class OC_TEMPLATE{ } // Add navigation entry and personal menu - $page->assign( "navigation", OC_UTIL::$navigation ); - $page->assign( "personalmenu", OC_UTIL::$personalmenu ); + $page->assign( "navigation", OC_APP::getNavigation()); + $page->assign( "personalmenu", OC_UTIL::getPersonalMenu()); // Add css files and js files $page->assign( "content", $data ); @@ -155,9 +217,13 @@ class OC_TEMPLATE{ return $data; } } - public function __destruct(){ - } + /** + * @brief doing the actual work + * @returns content + * + * Includes the template file, fetches its output + */ private function _fetch(){ // Register the variables $_ = $this->vars; @@ -184,7 +250,7 @@ class OC_TEMPLATE{ foreach( $parameters as $key => $value ){ $content->assign( $key, $value ); } - return $content->printPage(); + print $content->printPage(); } /**