Browse Source

change all root directory constant with one DOCUMENT_ROOT (named like apache), remove one warning on url dispatch, adding a class autoloader

pull/16/head
www-data 12 years ago
parent
commit
7417fda968
  1. 9
      app/controllers/ControllerBase.php
  2. 10
      app/controllers/ControllerMain.php
  3. 20
      app/widgets/Admin/Admin.php
  4. 10
      index.php
  5. 8
      infos.php
  6. 8
      jajax.php
  7. 36
      loader.php
  8. 2
      mud.php
  9. 4
      system/Conf.php
  10. 6
      system/Logger.php
  11. 27
      system/Route.php
  12. 2
      system/User.php
  13. 18
      system/UtilsPicture.php
  14. 10
      system/i18n/i18n.php
  15. 2
      system/widget/WidgetBase.php
  16. 1
      themes/movim/css/style.css
  17. 2
      themes/movim/login.tpl
  18. 10
      upload.php

9
app/controllers/ControllerBase.php

@ -42,12 +42,12 @@ class ControllerBase
public function handle()
{
$r = new Route();
// Note that the request is always specified by 'q'.
if($request = $this->fetch_get('q'))
if($request = $this->fetch_get('q')) {
$this->run_req($request);
else
} else {
$this->error404();
}
}
/**
@ -78,8 +78,11 @@ class ControllerBase
*/
protected function run_req($request)
{
if(is_callable(array($this, $request))) {
call_user_func(array($this, $request));
} else {
die('not found query');
}
}

10
app/controllers/ControllerMain.php

@ -18,7 +18,7 @@
class ControllerMain extends ControllerBase
{
protected $default_handler = 'main';
private $page;
protected $page;
function __construct()
{
@ -32,6 +32,7 @@ class ControllerMain extends ControllerBase
function main()
{
$user = new User();
if(!$user->isLogged()) {
@ -51,6 +52,7 @@ class ControllerMain extends ControllerBase
$this->page->setContent($content->build('main.tpl'));
echo $this->page->build('page.tpl');
}
}
@ -361,11 +363,15 @@ class ControllerMain extends ControllerBase
error_reporting(0);
$this->page->setTitle(t('%s - Login to Movim', APP_TITLE));
$this->page->menuAddLink(t('Home'), 'main', true);
$this->page->menuAddLink(t('About'), 'about');
$content = new TplPageBuilder($user);
$this->page->setContent($content->build('login.tpl'));
echo $this->page->build('page.tpl');
}

20
app/widgets/Admin/Admin.php

@ -47,36 +47,36 @@ class Admin extends WidgetBase {
* Create the dirs
*/
function createDirs(){
if(!file_exists(BASE_PATH.'cache') && !@mkdir(BASE_PATH.'cache')) {
if(!file_exists(DOCUMENT_ROOT.'/cache') && !@mkdir(DOCUMENT_ROOT.'/cache')) {
echo t("Couldn't create directory '%s'.", 'cache');
return false;
}
if(!file_exists(BASE_PATH.'log') && !@mkdir(BASE_PATH.'log')) {
if(!file_exists(DOCUMENT_ROOT.'/log') && !@mkdir(DOCUMENT_ROOT.'/log')) {
echo t("Couldn't create directory '%s'.", 'log');
return false;
}
if(!file_exists(BASE_PATH.'config') && !@mkdir(BASE_PATH.'config')) {
if(!file_exists(DOCUMENT_ROOT.'/config') && !@mkdir(DOCUMENT_ROOT.'/config')) {
echo t("Couldn't create directory '%s'.", 'config');
return false;
}
if(!file_exists(BASE_PATH.'users') && !@mkdir(BASE_PATH.'users')) {
if(!file_exists(DOCUMENT_ROOT.'/users') && !@mkdir(DOCUMENT_ROOT.'/users')) {
echo t("Couldn't create directory '%s'.", 'users');
return false;
} else
touch(BASE_PATH.'users/index.html');
touch(DOCUMENT_ROOT.'/users/index.html');
}
private function listThemes()
{
$dir = opendir(BASE_PATH.'themes');
$dir = opendir(DOCUMENT_ROOT.'/themes');
$themes = array();
while($theme = readdir($dir)) {
if(preg_match('/^\.+$/', $theme)
|| !is_dir(BASE_PATH.'themes/'.$theme)) {
|| !is_dir(DOCUMENT_ROOT.'/themes/'.$theme)) {
continue;
}
@ -88,7 +88,7 @@ class Admin extends WidgetBase {
private function listLangs()
{
$dir = opendir(BASE_PATH.'locales');
$dir = opendir(DOCUMENT_ROOT.'/locales');
$langs = array('en' => 'English');
$languages = get_lang_list();
@ -195,7 +195,7 @@ class Admin extends WidgetBase {
private function prepareAdminComp()
{
if($this->testDir(BASE_PATH))
if($this->testDir(DOCUMENT_ROOT))
$this->createDirs();
$submit = $this->genCallAjax('ajaxAdminSubmit', "movim_parse_form('admin')")
@ -231,7 +231,7 @@ class Admin extends WidgetBase {
<div class="'.$this->isValid(extension_loaded('SimpleXml')).'">
'.t('SimpleXML').'
</div>
<div class="'.$this->isValid($this->testDir(BASE_PATH)).'">
<div class="'.$this->isValid($this->testDir(DOCUMENT_ROOT)).'">
'.t('Read and write rights for the webserver in Movim\'s root directory').'
</div>

10
index.php

@ -40,9 +40,9 @@
/**
* BOOTSTRAP
**/
define('ROOTDIR', dirname(__FILE__));
require_once(ROOTDIR.'/system/Utils.php');
require_once(ROOTDIR.'/system/Conf.php');
define('DOCUMENT_ROOT', dirname(__FILE__));
require_once(DOCUMENT_ROOT.'/system/Utils.php');
require_once(DOCUMENT_ROOT.'/system/Conf.php');
try {
define('ENVIRONMENT',Conf::getServerConfElement('environment'));
} catch (Exception $e) {
@ -58,7 +58,7 @@ if (ENVIRONMENT === 'development') {
ini_set('display_errors', 0);
ini_set('error_reporting', E_ALL ^ E_DEPRECATED ^ E_NOTICE);
}
ini_set('error_log', ROOTDIR.'/log/php.log');
ini_set('error_log', DOCUMENT_ROOT.'/log/php.log');
// Run
require_once('init.php');
@ -73,7 +73,7 @@ WidgetWrapper::getInstance(false);
WidgetWrapper::destroyInstance();
if (ENVIRONMENT === 'development') {
print ' <div id="debug"><div class="carreful"><p>Be carrefull you are actually in devlopment environment</p></div>';
print ' <div id="debug"><div class="carreful"><p>Be careful you are actually in development environment</p></div>';
print '<div id="logs">';
echo Logger::displayLog();
print '</div></div>';

8
infos.php

@ -20,9 +20,9 @@
/**
* BOOTSTRAP
**/
define('ROOTDIR', dirname(__FILE__));
require_once(ROOTDIR.'/system/Utils.php');
require_once(ROOTDIR.'/system/Conf.php');
define('DOCUMENT_ROOT', dirname(__FILE__));
require_once(DOCUMENT_ROOT.'/system/Utils.php');
require_once(DOCUMENT_ROOT.'/system/Conf.php');
try {
define('ENVIRONMENT',Conf::getServerConfElement('environment'));
} catch (Exception $e) {
@ -37,7 +37,7 @@ if (ENVIRONMENT === 'development') {
ini_set('display_errors', 0);
ini_set('error_reporting', E_ALL ^ E_DEPRECATED ^ E_NOTICE);
}
ini_set('error_log', ROOTDIR.'/log/php.log');
ini_set('error_log', DOCUMENT_ROOT.'/log/php.log');
// Run
require_once('init.php');

8
jajax.php

@ -18,9 +18,9 @@
/**
* BOOTSTRAP
**/
define('ROOTDIR', dirname(__FILE__));
require_once(ROOTDIR.'/system/Utils.php');
require_once(ROOTDIR.'/system/Conf.php');
define('DOCUMENT_ROOT', dirname(__FILE__));
require_once(DOCUMENT_ROOT.'/system/Utils.php');
require_once(DOCUMENT_ROOT.'/system/Conf.php');
try {
define('ENVIRONMENT',Conf::getServerConfElement('environment'));
} catch (Exception $e) {
@ -29,7 +29,7 @@ try {
ini_set('log_errors', 1);
ini_set('display_errors', 0);
ini_set('error_reporting', E_ALL ^ E_DEPRECATED ^ E_NOTICE);
ini_set('error_log', ROOTDIR.'/log/php.log');
ini_set('error_log', DOCUMENT_ROOT.'/log/php.log');
// Run
require_once('init.php');

36
loader.php

@ -1,20 +1,36 @@
<?php
function __autoload($className)
{
$className = ltrim($className, '\\');
$fileName = DOCUMENT_ROOT;
$namespace = '';
if ($lastNsPos = strrpos($className, '\\')) {
$namespace = substr($className, 0, $lastNsPos);
$className = substr($className, $lastNsPos + 1);
$fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
}
$fileName .= '/'.str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
if (file_exists($fileName)) {
require_once( $fileName);
} else {
return false;
}
}
// A few constants...
define('BASE_PATH', dirname(__FILE__) . '/');
define('APP_NAME', 'movim');
#define('LIB_PATH', BASE_PATH.'system/');
define('THEMES_PATH', BASE_PATH . 'themes/');
define('USERS_PATH', BASE_PATH . 'users/');
define('APP_PATH', BASE_PATH . 'app/');
define('SYSTEM_PATH', BASE_PATH . 'system/');
define('LIB_PATH', BASE_PATH . 'lib/');
define('LOCALES_PATH', BASE_PATH . 'locales/');
define('CACHE_PATH', BASE_PATH . 'cache/');
define('THEMES_PATH', DOCUMENT_ROOT . '/themes/');
define('USERS_PATH', DOCUMENT_ROOT . '/users/');
define('APP_PATH', DOCUMENT_ROOT . '/app/');
define('SYSTEM_PATH', DOCUMENT_ROOT . '/system/');
define('LIB_PATH', DOCUMENT_ROOT . '/lib/');
define('LOCALES_PATH', DOCUMENT_ROOT . '/locales/');
define('CACHE_PATH', DOCUMENT_ROOT . '/cache/');
// Loads up all system libraries.
require_once(SYSTEM_PATH . "i18n/i18n.php");
require_once(SYSTEM_PATH . "/i18n/i18n.php");
require_once(SYSTEM_PATH . "Session.php");
require_once(SYSTEM_PATH . "Utils.php");

2
mud.php

@ -45,7 +45,7 @@ function comploc() {
$langs = load_lang_array();
foreach($langs as $key => $value) {
$langarr = parse_lang_file(BASE_PATH . '/locales/' . $key . '.po');
$langarr = parse_lang_file(DOCUMENT_ROOT . '/locales/' . $key . '.po');
$out = '<?php global $translations;
$translations = array(';

4
system/Conf.php

@ -12,7 +12,7 @@ class Conf
/* Return the general configuration */
static function getServerConf() {
$conf_file = ROOTDIR . self::$conf_path . "/conf.xml";
$conf_file = DOCUMENT_ROOT . self::$conf_path . "/conf.xml";
return self::getConf('server', $conf_file);
}
@ -88,7 +88,7 @@ class Conf
}
$xml = $doc->saveXML();
file_put_contents(BASE_PATH.self::$conf_path.'/conf.xml', $xml);
file_put_contents(DOCUMENT_ROOT.self::$conf_path.'/conf.xml', $xml);
}
/**

6
system/Logger.php

@ -1,9 +1,9 @@
<?php
if (!defined('ROOTDIR')) {
if (!defined('DOCUMENT_ROOT')) {
die('Error 57895');
}
if (!is_dir(ROOTDIR)) {
if (!is_dir(DOCUMENT_ROOT)) {
die('Error 57896');
}
@ -104,7 +104,7 @@ class Logs
public function defaultSaveLogs()
{
$this->saveLogs(ROOTDIR . '/log/logger.log');
$this->saveLogs(DOCUMENT_ROOT . '/log/logger.log');
}

27
system/Route.php

@ -27,9 +27,13 @@ class Route extends ControllerBase {
'server' => array('s'),
);
if($_SERVER['HTTP_MOD_REWRITE']) {
if ($_SERVER['HTTP_MOD_REWRITE']) {
$q = $this->fetch_get('query');
$this->find($q);
//load data in $_GET variable
if (!$this->find($q)) {
$this->error404();
exit;
}
} else {
$q = $this->fetch_get('q');
if(empty($q))
@ -37,32 +41,31 @@ class Route extends ControllerBase {
}
}
private function find($q) {
protected function find($q) {
// We decompose the URL
$request = explode('/', $q);
if(empty($q)) {
$_GET['q'] = 'main';
return true;
}
// And we search a pattern for the current page
elseif(isset($this->_routes[$request[0]])) {
} elseif (isset($this->_routes[$request[0]])) {
// And we search a pattern for the current page
$route = $this->_routes[$request[0]];
$_GET['q'] = $request[0];
$_GET['q'] = $request[0];
array_shift($request);
// If we find it we see if it's a simple page (with no GET)
if($route != false) {
//check if something else to get...
if(count($request) ) {
$i = 0;
foreach($route as $key) {
$_GET[$key] = $request[$i];
if (isset($request[$i])) {
$_GET[$key] = $request[$i];
}
$i++;
}
}
return true;
} else
return false;

2
system/User.php

@ -31,7 +31,7 @@ class User {
$this->sizelimit = (int)Conf::getServerConfElement('sizeLimit');
$this->userdir = BASE_PATH.'users/'.$this->username.'/';
$this->userdir = DOCUMENT_ROOT.'/users/'.$this->username.'/';
$this->useruri = BASE_URI.'users/'.$this->username.'/';
}
}

18
system/UtilsPicture.php

@ -15,15 +15,15 @@ function createThumbnailPicture($path, $filename) {
}
function createThumbnails($jid, $photobin) {
unlink(BASE_PATH.'cache/'.$jid.'_l.jpg');
unlink(BASE_PATH.'cache/'.$jid.'_m.jpg');
unlink(BASE_PATH.'cache/'.$jid.'_s.jpg');
unlink(BASE_PATH.'cache/'.$jid.'_xs.jpg');
createThumbnailSize(base64_decode($photobin), 200, BASE_PATH.'cache/'.$jid.'_l.jpg');
createThumbnailSize(base64_decode($photobin), 120, BASE_PATH.'cache/'.$jid.'_m.jpg');
createThumbnailSize(base64_decode($photobin), 50, BASE_PATH.'cache/'.$jid.'_s.jpg');
createThumbnailSize(base64_decode($photobin), 28, BASE_PATH.'cache/'.$jid.'_xs.jpg');
createThumbnailSize(base64_decode($photobin), 24, BASE_PATH.'cache/'.$jid.'_xxs.jpg');
unlink(DOCUMENT_ROOT.'/cache/'.$jid.'_l.jpg');
unlink(DOCUMENT_ROOT.'/cache/'.$jid.'_m.jpg');
unlink(DOCUMENT_ROOT.'/cache/'.$jid.'_s.jpg');
unlink(DOCUMENT_ROOT.'/cache/'.$jid.'_xs.jpg');
createThumbnailSize(base64_decode($photobin), 200, DOCUMENT_ROOT.'/cache/'.$jid.'_l.jpg');
createThumbnailSize(base64_decode($photobin), 120, DOCUMENT_ROOT.'/cache/'.$jid.'_m.jpg');
createThumbnailSize(base64_decode($photobin), 50, DOCUMENT_ROOT.'/cache/'.$jid.'_s.jpg');
createThumbnailSize(base64_decode($photobin), 28, DOCUMENT_ROOT.'/cache/'.$jid.'_xs.jpg');
createThumbnailSize(base64_decode($photobin), 24, DOCUMENT_ROOT.'/cache/'.$jid.'_xxs.jpg');
}
function createThumbnailSize($photobin, $size, $path) {

10
system/i18n/i18n.php

@ -146,7 +146,7 @@ function load_language_auto()
if($key == 'en') {
load_language(Conf::getServerConfElement('defLang'));
$langNotFound = false;
} elseif(file_exists(BASE_PATH . '/locales/' . $key . '.po')) {
} elseif(file_exists(DOCUMENT_ROOT . '/locales/' . $key . '.po')) {
load_language($key);
$langNotFound = false;
}
@ -166,11 +166,11 @@ function load_language($lang)
}
// Here we load the compiled language file
if(file_exists(BASE_PATH . '/cache/locales/' . $lang . '.php')) {
if(file_exists(DOCUMENT_ROOT . '/cache/locales/' . $lang . '.php')) {
// And we set our gloabl $translations
require_once(BASE_PATH . '/cache/locales/' . $lang . '.php');
require_once(DOCUMENT_ROOT . '/cache/locales/' . $lang . '.php');
} else
$translations = parse_lang_file(BASE_PATH . '/locales/' . $lang . '.po');
$translations = parse_lang_file(DOCUMENT_ROOT . '/locales/' . $lang . '.po');
$language = $lang;
@ -217,7 +217,7 @@ function load_extra_lang($directory)
function load_lang_array() {
$lang_list = get_lang_list();
$dir = scandir(BASE_PATH . '/locales/');
$dir = scandir(DOCUMENT_ROOT . '/locales/');
$po = array();
foreach($dir as $files) {
$explode = explode('.', $files);

2
system/widget/WidgetBase.php

@ -133,7 +133,7 @@ class WidgetBase
$path .= 'app/widgets/' . $folder . '/' . $file;
if($fspath) {
$path = BASE_PATH . $path;
$path = DOCUMENT_ROOT . '/'.$path;
} else {
$path = BASE_URI . $path;
}

1
themes/movim/css/style.css

@ -758,5 +758,6 @@ dl dd {
border:1px solid black;
}
.carreful {
background-color: #fff;
color:red;
}

2
themes/movim/login.tpl

@ -1,6 +1,6 @@
<?php /* -*- mode: html -*- */
?>
<div class="main">
<?php $this->widget('Login');?>
<?php $this->widget('Login'); ?>
<div class="clear"></div>
</div>

10
upload.php

@ -2,9 +2,9 @@
/**
* BOOTSTRAP
**/
define('ROOTDIR', dirname(__FILE__));
require_once(ROOTDIR.'/system/Utils.php');
require_once(ROOTDIR.'/system/Conf.php');
define('DOCUMENT_ROOT', dirname(__FILE__));
require_once(DOCUMENT_ROOT.'/system/Utils.php');
require_once(DOCUMENT_ROOT.'/system/Conf.php');
try {
define('ENVIRONMENT',Conf::getServerConfElement('environment'));
} catch (Exception $e) {
@ -13,7 +13,7 @@ try {
ini_set('log_errors', 1);
ini_set('display_errors', 0);
ini_set('error_reporting', E_ALL ^ E_DEPRECATED ^ E_NOTICE);
ini_set('error_log', ROOTDIR.'/log/php.log');
ini_set('error_log', DOCUMENT_ROOT.'/log/php.log');
// Run
require_once('init.php');
@ -29,7 +29,7 @@ $sFileSize = bytesToSize1024($_FILES['image_file']['size'], 1);
$user = new User();
define('USER_PATH', BASE_PATH . 'users/'.$user->getLogin().'/');
define('USER_PATH', DOCUMENT_ROOT . '/users/'.$user->getLogin().'/');
$error = $_FILES['image_file']['error'];

Loading…
Cancel
Save