Skip to content

Commit

Permalink
The main files: dispatcher, config, htaccess and logs folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Goteo committed Jun 12, 2012
1 parent c7cbaeb commit 83a2e69
Show file tree
Hide file tree
Showing 4 changed files with 306 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .htaccess
@@ -0,0 +1,30 @@
AddDefaultCharset UTF-8
Options +FollowSymLinks
ServerSignature Off

<Files .*>
Order Deny,Allow
Deny From All
</Files>

# <Files *.php>
# Order Deny,Allow
# Deny From All
# </Files>

<IfModule mod_php5.c>
php_value magic_quotes_runtime "0"
php_value magic_quotes_gpc "0"
php_value register_globals "Off"
php_value register_long_arrays "Off"
php_value session.auto_start "0"
php_value display_startup_errors "On"
</IfModule>

<IfModule mod_rewrite.c>
# TODO: prohibir el acceso directo a index.php
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php?%{QUERY_STRING}
</IfModule>
95 changes: 95 additions & 0 deletions config.php
@@ -0,0 +1,95 @@
<?php
/*
* Copyright (C) 2012 Platoniq y Fundación Fuentes Abiertas (see README for details)
* This file is part of Goteo.
*
* Goteo is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Goteo 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 Goteo. If not, see <http://www.gnu.org/licenses/agpl.txt>.
*
*/

define('GOTEO_PATH', __DIR__ . DIRECTORY_SEPARATOR);
if (function_exists('ini_set')) {
ini_set('include_path', GOTEO_PATH . PATH_SEPARATOR . '.');
} else {
throw new Exception("No puedo añadir la API GOTEO al include_path.");
}

// Nodo actual
define('GOTEO_NODE', 'goteo');

define('PEAR', GOTEO_PATH . 'library' . '/' . 'pear' . '/');
if (function_exists('ini_set')) {
ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . PEAR);
} else {
throw new Exception("No puedo añadir las librerías PEAR al include_path.");
}

if (!defined('PHPMAILER_CLASS')) {
define ('PHPMAILER_CLASS', GOTEO_PATH . 'library' . DIRECTORY_SEPARATOR . 'phpmailer' . DIRECTORY_SEPARATOR . 'class.phpmailer.php');
}
if (!defined('PHPMAILER_LANGS')) {
define ('PHPMAILER_LANGS', GOTEO_PATH . 'library' . DIRECTORY_SEPARATOR . 'phpmailer' . DIRECTORY_SEPARATOR . 'language' . DIRECTORY_SEPARATOR);
}
if (!defined('PHPMAILER_SMTP')) {
define ('PHPMAILER_SMTP', GOTEO_PATH . 'library' . DIRECTORY_SEPARATOR . 'phpmailer' . DIRECTORY_SEPARATOR . 'class.smtp.php');
}
if (!defined('PHPMAILER_POP3')) {
define ('PHPMAILER_POP3', GOTEO_PATH . 'library' . DIRECTORY_SEPARATOR . 'phpmailer' . DIRECTORY_SEPARATOR . 'class.pop3.php');
}

// Metadata
define('GOTEO_META_TITLE', 'Goteo.org Crowdfunding the commons');
define('GOTEO_META_DESCRIPTION', 'Red social de financiacion colectiva');
define('GOTEO_META_KEYWORDS', 'crowdfunding, procomun, commons, social, network, financiacion colectiva, cultural, creative commons, proyectos abiertos, open source, free software, licencias libres');
define('GOTEO_META_AUTHOR', 'Onliners Web Development');
define('GOTEO_META_COPYRIGHT', 'Fundación Fuentes Abiertas');

// Database
define('GOTEO_DB_DRIVER', 'mysql');
define('GOTEO_DB_HOST', 'localhost');
define('GOTEO_DB_PORT', 3306);
define('GOTEO_DB_CHARSET', 'UTF-8');
define('GOTEO_DB_SCHEMA', 'goteo');
define('GOTEO_DB_USERNAME', '');
define('GOTEO_DB_PASSWORD', '');

//Uploads i catxe
define('GOTEO_DATA_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR);

// Mail
define('GOTEO_MAIL_FROM', 'noreply@goteo.org');
define('GOTEO_MAIL_NAME', 'Goteo.org');
define('GOTEO_MAIL_TYPE', 'mail');
define('GOTEO_MAIL_SMTP_AUTH', true);
define('GOTEO_MAIL_SMTP_SECURE', 'ssl');
define('GOTEO_MAIL_SMTP_HOST', '');
define('GOTEO_MAIL_SMTP_PORT', 465);
define('GOTEO_MAIL_SMTP_USERNAME', '');
define('GOTEO_MAIL_SMTP_PASSWORD', '');

define('GOTEO_MAIL', 'hola@goteo.org');

// Language
define('GOTEO_DEFAULT_LANG', 'es');

// url
define('SITE_URL', 'http://free.goteo.org');
define('SRC_URL', 'http://free.goteo.org');

// Cron params
define('CRON_PARAM', '');
define('CRON_VALUE', '');

// Código liberado
define('GOTEO_FREE', true);
181 changes: 181 additions & 0 deletions index.php
@@ -0,0 +1,181 @@
<?php
/*
* Copyright (C) 2012 Platoniq y Fundación Fuentes Abiertas (see README for details)
* This file is part of Goteo.
*
* Goteo is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Goteo 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 Goteo. If not, see <http://www.gnu.org/licenses/agpl.txt>.
*
*/

use Goteo\Core\Resource,
Goteo\Core\Error,
Goteo\Core\Redirection,
Goteo\Core\ACL,
Goteo\Library\Text,
Goteo\Library\Message,
Goteo\Library\Lang;

require_once 'config.php';
require_once 'core/common.php';

// Include path
//set_include_path(GOTEO_PATH . PATH_SEPARATOR . '.');

// Autoloader
spl_autoload_register(

function ($cls) {

$file = __DIR__ . '/' . implode('/', explode('\\', strtolower(substr($cls, 6)))) . '.php';
$file = realpath($file);

if ($file === false) {

// Try in library
// $file = __DIR__ . '/library/' . implode('/', explode('\\', strtolower(substr($cls, 6)))) . '.php';
$file = __DIR__ . '/library/' . strtolower($cls) . '.php';
// die($cls . ' - ' . $file); //Si uso Text::get(id) no lo pilla
}

if ($file !== false) {
include $file;
}

}

);

// Error handler
set_error_handler (

function ($errno, $errstr, $errfile, $errline, $errcontext) {
// @todo Insert error into buffer
// echo "Error: {$errno}, {$errstr}, {$errfile}, {$errline}, {$errcontext}<br />";
//throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
}

);

/**
* Sesión.
*/
session_name('goteo');
session_start();

// set Lang
Lang::set();

// cambiamos el locale
\setlocale(\LC_TIME, Lang::locale());

// Get URI without query string
$uri = strtok($_SERVER['REQUEST_URI'], '?');

// Get requested segments
$segments = preg_split('!\s*/+\s*!', $uri, -1, \PREG_SPLIT_NO_EMPTY);

// Normalize URI
$uri = '/' . implode('/', $segments);

try {

// Check permissions on requested URI
if (!ACL::check($uri)) {
Message::Info(Text::get('user-login-required-access'));

//si es un cron (ejecutandose) con los parámetros adecuados, no redireccionamos
if (strpos($uri, 'cron') !== false && strcmp($_GET[md5(CRON_PARAM)], md5(CRON_VALUE)) === 0) {
// proceed
} else {
throw new Redirection("/user/login/?return=".rawurlencode($uri));
}
}

// Get controller name
if (!empty($segments) && class_exists("Goteo\\Controller\\{$segments[0]}")) {
// Take first segment as controller
$controller = array_shift($segments);
} else {
$controller = 'index';
}

// Continue
try {

$class = new ReflectionClass("Goteo\\Controller\\{$controller}");

if (!empty($segments) && $class->hasMethod($segments[0])) {
$method = array_shift($segments);
} else {
// Try default method
$method = 'index';
}

// ReflectionMethod
$method = $class->getMethod($method);

// Number of params defined in method
$numParams = $method->getNumberOfParameters();
// Number of required params
$reqParams = $method->getNumberOfRequiredParameters();
// Given params
$gvnParams = count($segments);

if ($gvnParams >= $reqParams && (!($gvnParams > $numParams && $numParams <= $reqParams))) {

// Try to instantiate
$instance = $class->newInstance();

// Start output buffer
ob_start();

// Invoke method
$result = $method->invokeArgs($instance, $segments);

if ($result === null) {
// Get buffer contents
$result = ob_get_contents();
}

ob_end_clean();

if ($result instanceof Resource\MIME) {
header("Content-type: {$result->getMIME()}");
}

echo $result;

// Farewell
die;

}

} catch (\ReflectionException $e) {}

throw new Error(Error::NOT_FOUND);

} catch (Redirection $redirection) {
$url = $redirection->getURL();
$code = $redirection->getCode();
header("Location: {$url}");

} catch (Error $error) {

include "view/error.html.php";

} catch (Exception $exception) {

// Default error (500)
include "view/error.html.php";
}
Empty file added logs/logs_here
Empty file.

0 comments on commit 83a2e69

Please sign in to comment.