Changeset 7010

Show
Ignore:
Timestamp:
11/18/08 16:43:37 (7 weeks ago)
Author:
inureyes
Message:

refs #777

  • Input validation 루틴의 이전
  • config 로드 시점 변경
  • dispatcher 에 TODO 갱신
  • initialize 루틴 수정
Location:
trunk
Files:
13 modified

Legend:

Unmodified
Added
Removed
  • trunk/dispatcher.php

    r7007 r7010  
    1111define('ROOT', '.'); 
    1212 
    13 /// Load config.php. 
    14 if (file_exists(ROOT.'/config.php')) { 
    15     require_once(ROOT.'/config.php'); 
    16 } else { 
     13/// Check config.php. 
     14if (!file_exists(ROOT.'/config.php')) { 
    1715    require(ROOT.'/setup.php'); 
    1816    exit; 
     
    2523$config = Config::getInstance(); 
    2624 
    27 // Parse and normalize URI. */ 
     25/** Parse and normalize URI. */ 
    2826/* TODO: Unify the environment and do work-arounds. (For IIS, Apache - mod_php or fastcgi, lighttpd, and etc.) */ 
    2927// Structure of fancy URL: 
    3028//   host + blog prefix + interface path + pagination info + extra arguments not in $_REQUEST 
    3129// TODO: Apply this structure to $context->accessInfo... 
     30 
    3231try { 
    3332    $context = Context::getInstance(); // automatic initialization via first instanciation 
     
    3938} 
    4039 
    41 /* Special pre-handlers. (favicon.ico, index.gif) */ 
     40/// Special pre-handlers. (favicon.ico, index.gif) 
    4241if ($context->accessInfo['prehandler']) { 
    4342    // Skip further processes such as session management. 
     
    4645} 
    4746 
    48 /* TODO: Session management. */ 
     47/// Input Validation 
     48// Basic POST/GET variable validation. 
     49if (isset($IV)) { 
     50    if (!Validator::validate($IV)) { 
     51        header('HTTP/1.1 404 Not Found'); 
     52        exit; 
     53    } 
     54} 
     55// Basic SERVER variable validation. 
     56$basicIV = array( 
     57    'SCRIPT_NAME' => array('string'), 
     58    'REQUEST_URI' => array('string'), 
     59    'REDIRECT_URL' => array('string', 'mandatory' => false) 
     60); 
     61Validator::validateArray($_SERVER, $basicIV); 
     62/*if(isset($accessInfo)) { 
     63    $basicIV = array( 
     64        'fullpath' => array('string'), 
     65        'input'    => array('string'), 
     66        'position' => array('string'), 
     67        'root'     => array('string'), 
     68        'input'    => array('string', 'mandatory' => false) 
     69    ); 
     70    $accessInfo['fullpath'] = urldecode($accessInfo['fullpath']); 
     71    Validator::validateArray($accessInfo, $basicIV); 
     72}*/ 
    4973 
    50 // TODO: Do input validation as soon as possible? 
     74/* TODO: Database Initialization (if necessary) 
     75/* TODO: Parse virtual blog information (if necessary) 
     76/* TODO: Session management. (if necessary) */ 
     77/* TODO: ACL validation */ 
     78 
    5179/* Load final interface handler. */ 
    5280// Each interface... 
  • trunk/library/context.php

    r7007 r7010  
    9797 
    9898        // TODO: Parse $_GET, $_POST, and etc. 
    99  
     99        if(isset($accessInfo['URLfragment'][0]) && $accessInfo['URLfragment'][0] == 'owner') $this->mode = 'owner'; 
     100        else $this->mode = 'blog'; 
    100101        $this->accessInfo = $accessInfo; 
    101102    } 
  • trunk/library/data/POD.php

    r6989 r7010  
    1919    /** Initialization **/ 
    2020    function __construct($domain = null, $type = null, $prefix = '') { 
    21         requireComponent('Needlworks.Cache.PageCache'); 
    2221        global $_pod_setting; 
    2322        if($domain != null) $this->_domain = $domain; 
  • trunk/library/environment/config.php

    r6998 r7010  
    2222global $database, $service, $blog, $memcache; 
    2323 
     24// Default configuration. 
    2425$database['server'] = 'localhost'; 
    2526$database['database'] = ''; 
     
    3334$service['language'] = 'ko'; 
    3435$service['timezone'] = 'Asia/Seoul'; 
    35 $service['encoding'] = 'EUC-KR'; 
     36$service['encoding'] = 'UTF-8'; 
    3637$service['umask'] = 0; 
    3738$service['skin'] = 'coolant'; 
     
    5455$service['debug_rewrite_module'] = false; 
    5556$service['useNumericURLonRSS'] = false; 
    56 // Map port setting. 
    57 if (@is_numeric($_SERVER['SERVER_PORT']) && ($_SERVER['SERVER_PORT'] != 80) && ($_SERVER['SERVER_PORT'] != 443)) 
    58     $service['port'] = $_SERVER['SERVER_PORT']; 
    59  
    60 // Include installation configuration. 
    61 $service['session_cookie_path'] = '/'; 
    62 if(!defined('__TEXTCUBE_SETUP__')) @include ROOT . '/config.php'; 
    63  
    64 // Set resource path. 
    65 if($service['externalresources']) { 
    66     if(isset($service['resourceURL']) && !empty($service['resourceURL']))  
    67         $service['resourcepath'] = $service['resourceURL']; 
    68     else  
    69         $service['resourcepath'] = TEXTCUBE_RESOURCE_URL; 
    70 } else { 
    71     $service['resourcepath'] = $service['path'].'/resources'; 
    72 } 
    73  
    74 // Database setting. 
    75 if(isset($service['dbms'])) { 
    76     if($service['dbms'] == 'mysql' && class_exists('mysqli')) $service['dbms'] = 'mysqli'; 
    77 } 
    78  
    79 // Debug mode configuration. 
    80 if($service['debugmode'] == true) { 
    81     if(isset($service['dbms'])) { 
    82         switch($service['dbms']) { 
    83             case 'mysqli':         requireLibrary("debug/MySQLi"); break; 
    84             case 'mysql': default: requireLibrary("debug/MySQL"); break; 
    85         } 
    86     } else requireLibrary("debug/MySQL");  
    87 } 
    88  
    89 // Session cookie patch. 
    90 if(!empty($service['domain']) && strstr( $_SERVER['HTTP_HOST'], $service['domain'] ) ) { 
    91     $service['session_cookie_domain'] = $service['domain']; 
    92 } else { 
    93     $service['session_cookie_domain'] = $_SERVER['HTTP_HOST']; 
    94 } 
    95  
    96 // Basic POST/GET variable validation. 
    97 if (isset($IV)) { 
    98     if (!Validator::validate($IV)) { 
    99         header('HTTP/1.1 404 Not Found'); 
    100         exit; 
    101     } 
    102 } 
    103 // Basic SERVER variable validation. 
    104 $basicIV = array( 
    105     'SCRIPT_NAME' => array('string'), 
    106     'REQUEST_URI' => array('string'), 
    107     'REDIRECT_URL' => array('string', 'mandatory' => false) 
    108 ); 
    109 Validator::validateArray($_SERVER, $basicIV); 
    110 if(isset($accessInfo)) { 
    111     $basicIV = array( 
    112         'fullpath' => array('string'), 
    113         'input'    => array('string'), 
    114         'position' => array('string'), 
    115         'root'     => array('string'), 
    116         'input'    => array('string', 'mandatory' => false) 
    117     ); 
    118     $accessInfo['fullpath'] = urldecode($accessInfo['fullpath']); 
    119     Validator::validateArray($accessInfo, $basicIV); 
    120 } 
     57$service['dbms'] = 'mysql'; 
    12158?> 
  • trunk/library/include.php

    r7009 r7010  
    4040} 
    4141 
    42 /***** Autoload components *****/ 
    43 class Autoload { 
    44     private static $drivers = array( 
    45         'auth'        => array('Auth','OpenID',array('Privilege'=>'Auth','Acl'=>'Auth')), 
    46         'cache'       => array('PageCache'), 
    47         'data'        => array('BlogSetting','BlogStatistics','DailyStatistics', 
    48             'DataMaintenance','Filter','Image','MySQL','MySQLi','POD','RSS', 
    49             'RefererLog','RefererStatistics','ServiceSetting','Setting', 
    50             'Statistics','SubscriptionLog','SubscriptionStatistics','Syndication', 
    51             'TData','UserInfo','UserSetting'), 
    52         'entry'       => array( 
    53             'Attachment','Category','Comment','CommentNotified','CommentNotifiedSiteInfo', 
    54             'Feed','GuestComment','Keyword','Link','Notice','PluginSetting', 
    55             'Post','RemoteResponse','SkinSetting','Tag','Trackback','TrackbackLog'), 
    56         'environment' => array( 
    57             'Base64Stream','HTTPRequest','OutputWriter','XMLRPC', 
    58             array('XMLRPCFault'=>'XMLRPC','XMLCustomType'=>'XMLRPC'), 
    59             'XMLTree','Pop3'), 
    60         'plugin'      => array('Misc','PluginCustomConfig'), 
    61         'session'     => array('Session'), 
    62         'skin'        => array('BlogSkin'), 
    63         'view'        => array('BlogView','Paging','Respond')); 
    64     private static $relation = array(); 
    65     public static function register() { 
    66         foreach (self::$drivers as $namespace => $classes) { 
    67             if(!empty($classes)) foreach($classes as $class) { 
    68                 if(is_array($class)) { 
    69                     foreach($class as $module => $file) self::$relation[$module] = $namespace.'/'.$file; 
    70                 } else self::$relation[$class] = $namespace.'/'.$class; 
    71             } 
    72         }    
    73     } 
    74     public static function load($name) { 
    75         global $service; 
    76         $name = ucfirst($name); 
    77         if(empty(self::$relation)) {self::register();} 
    78         if (in_array($name,array('DBQuery'))) { 
    79             if (!isset($service['dbms'])) $service['dbms'] = 'mysql'; 
    80             require_once(ROOT . "/library/data/".$service['dbms']."/Adapter.php"); 
    81             require_once(ROOT . "/library/data/Database.php"); 
    82         } else if(self::$relation[$name] == 'session' && isset($service['memcached']) && $service['memcached'] == true) { 
    83             require_once(ROOT . "/library/session/Session_Memcached.php"); 
    84         } else if(empty(self::$relation[$name])) { 
    85             if(defined('TCDEBUG')) print "Textcube: Unregisterred auto load class: $name<br/>\n"; 
    86         } else { 
    87             require_once(ROOT . "/library/".self::$relation[$name]."/".$name.".php"); 
    88         } 
    89  
    90     } 
    91 } 
    92 spl_autoload_register(array('Autoload', 'load')); 
    93  
    9442/***** Pre-define basic components *****/ 
    9543$__coreLibrary = array( 
    9644    'environment/Needlworks.PHP.UnifiedEnvironment', 
    97     'environment/Needlworks.PHP.Core', 
     45//  'environment/Needlworks.PHP.Core', 
    9846    'environment/Locale', 
    9947    'data/Core', 
  • trunk/library/includeForBlog.php

    r7004 r7010  
    66$__requireComponent = array(); 
    77$__requireBasics = array( 
    8     'environment/config',                   // Basics 
     8    // Basics 
    99    'function/string', 
    1010    'function/time', 
  • trunk/library/includeForBlogOwner.php

    r6999 r7010  
    77$__requireComponent = array(); 
    88$__requireBasics = array( 
    9     'environment/config',               // Basics 
    109    'function/string', 
    1110    'function/time', 
  • trunk/library/includeForFeeder.php

    r6999 r7010  
    88$__requireComponent = array(); 
    99$__requireBasics = array(       // Basics 
    10     'environment/config', 
    1110    'function/string', 
    1211    'function/time', 
  • trunk/library/includeForIcon.php

    r6999 r7010  
    88$__requireComponent = array(); 
    99$__requireBasics = array(       // Basics 
    10     'environment/config', 
    1110    'function/file'); 
    1211$__requireLibrary = array(      // Library 
  • trunk/library/includeForReader.php

    r6999 r7010  
    77$__requireComponent = array(); 
    88$__requireBasics = array(       // Basics 
    9     'environment/config', 
    109    'function/string', 
    1110    'function/time', 
  • trunk/library/initialize.php

    r6985 r7010  
    112112            $adminSkinSetting['editorTemplate'] = "/resources/style/default-wysiwyg.css"; 
    113113    } 
    114     if (!file_exists(ROOT . '/config.php')) { 
    115         header('Location: ' . ROOT . '/setup.php'); 
    116         exit; 
    117     } 
    118114} 
    119115?> 
  • trunk/library/loader.php

    r7007 r7010  
    66final class FrameworkAutoloader 
    77{ 
    8     private static $classPaths = array( 
    9             'Context' => './library/context.php', 
    10             'Debug' => './library/debug.php', 
    11             'IModel' => './library/data/IAdapter.php', 
    12             'DBException' => './library/data/IAdapter.php', 
    13             'DBConnectionError' => './library/data/IAdapter.php', 
    14             'DBQueryError' => './library/data/IAdapter.php', 
    15             'IAdapter' => './library/data/IModel.php', 
    16             'ICache' => './library/cache/ICache.php', 
    17             'Entry' => './library/model/Entry.php', 
     8    private static $classInfo = array( 
     9        'auth'        => array('Auth','OpenID',array('Privilege'=>'Auth','Acl'=>'Auth')), 
     10        'cache'       => array('PageCache','ICache'), 
     11        'data'        => array('BlogSetting','BlogStatistics','DailyStatistics', 
     12            'DataMaintenance','Filter','Image','MySQL','MySQLi','POD','RSS', 
     13            'RefererLog','RefererStatistics','ServiceSetting','Setting', 
     14            'Statistics','SubscriptionLog','SubscriptionStatistics','Syndication', 
     15            'TData','UserInfo','UserSetting', 
     16            array('IAdapter'=>'IModel','DBQueryError'=>'IAdapter', 
     17                'DBConnectionError'=>'IAdapter','DBException'=>'IAdapter') 
     18                ), 
     19        'entry'       => array( 
     20            'Attachment','Category','Comment','CommentNotified','CommentNotifiedSiteInfo', 
     21            'Feed','GuestComment','Keyword','Link','Notice','PluginSetting', 
     22            'Post','RemoteResponse','SkinSetting','Tag','Trackback','TrackbackLog'), 
     23        'environment' => array( 
     24            'Base64Stream','HTTPRequest','OutputWriter','XMLRPC', 
     25            'XMLTree','Pop3', 
     26            array('XMLRPCFault'=>'XMLRPC','XMLCustomType'=>'XMLRPC', 
     27                'Validator'=>'Needlworks.PHP.Core')), 
     28        'plugin'      => array('Misc','PluginCustomConfig'), 
     29        'session'     => array('Session'), 
     30        'skin'        => array('BlogSkin'), 
     31        'view'        => array('BlogView','Paging','Respond'), 
     32        'root'        => array('Context','Debug') 
    1833        ); 
    19  
     34         
    2035    static function init() { 
    2136        $config = Config::getInstance(); 
    22  
    2337        // Set paths for DB classes according to the current backend configuration. 
    24         self::$classPaths['Adapter'] = './data/' . $config->backend_name . '/Adapter.php'; 
    25         self::$classPaths['Model'] = './data/' . $config->backend_name . '/Model.php'; 
     38        array_push(self::$classInfo['data'],array('IAdapter'=>'data/'.$config->backend_name.'/Adapter.php')); 
     39        array_push(self::$classInfo['data'],array('IModel'=>'data/'.$config->backend_name.'/Model.php')); 
    2640    } 
    2741 
    28     static function autoload($name) { 
    29         if (isset(self::$classPaths[$name])) 
    30             require_once(self::$classPaths[$name]); 
    31         // Because multiple autoload functions can be defined, we don't throw any exception here. 
    32         // If PHP finally fails finding the class, it will say FATAL error. 
     42    private static $relation = array(); 
     43     
     44    public static function register() { 
     45        foreach (self::$classInfo as $namespace => $classes) { 
     46            if(!empty($classes)) {  
     47                foreach($classes as $class) { 
     48                    if($namespace == 'root') self::$relation[$class] = $class;  
     49                    else if(is_array($class)) { 
     50                        foreach($class as $module => $file) self::$relation[$module] = $namespace.'/'.$file; 
     51                    } else self::$relation[$class] = $namespace.'/'.$class; 
     52                } 
     53            } 
     54        }    
     55    } 
     56    public static function autoload($name) { 
     57        global $service; 
     58        $name = ucfirst($name); 
     59        if(empty(self::$relation)) {self::register();} 
     60        if (in_array($name,array('DBQuery'))) { 
     61            if (!isset($service['dbms'])) $service['dbms'] = 'mysql'; 
     62            require_once(ROOT . "/library/data/".$service['dbms']."/Adapter.php"); 
     63            require_once(ROOT . "/library/data/Database.php"); 
     64        } else if(self::$relation[$name] == 'session' && isset($service['memcached']) && $service['memcached'] == true) { 
     65            require_once(ROOT . "/library/session/Session_Memcached.php"); 
     66        } else if(empty(self::$relation[$name])) { 
     67            if(defined('TCDEBUG')) print "Textcube: Unregisterred auto load class: $name<br/>\n"; 
     68        } else { 
     69            require_once(ROOT . "/library/".self::$relation[$name].".php"); 
     70        } 
    3371    } 
    3472} 
    35  
    3673FrameworkAutoloader::init(); 
    3774spl_autoload_register(array('FrameworkAutoloader', 'autoload')); 
  • trunk/library/settings.php

    r7007 r7010  
    1212 
    1313    protected function __construct() { 
     14        global $database, $service; 
     15 
    1416        $this->settings = array(); 
     17        require_once(ROOT.'/library/environment/config.php');   // Loading default configuration 
     18        if (file_exists(ROOT.'/config.php')) require_once(ROOT.'/config.php');  // Override configuration 
     19        // Map port setting. 
     20        if (@is_numeric($_SERVER['SERVER_PORT']) && ($_SERVER['SERVER_PORT'] != 80) && ($_SERVER['SERVER_PORT'] != 443)) 
     21            $service['port'] = $_SERVER['SERVER_PORT']; 
     22         
     23        // Include installation configuration. 
     24        $service['session_cookie_path'] = '/'; 
     25        if(!defined('__TEXTCUBE_SETUP__')) @include ROOT . '/config.php'; 
     26         
     27        // Set resource path. 
     28        if($service['externalresources']) { 
     29            if(isset($service['resourceURL']) && !empty($service['resourceURL']))  
     30                $service['resourcepath'] = $service['resourceURL']; 
     31            else  
     32                $service['resourcepath'] = TEXTCUBE_RESOURCE_URL; 
     33        } else { 
     34            $service['resourcepath'] = $service['path'].'/resources'; 
     35        } 
     36         
     37        // Database setting. 
     38        if(isset($service['dbms'])) { 
     39            if($service['dbms'] == 'mysql' && class_exists('mysqli')) $service['dbms'] = 'mysqli'; 
     40        } 
     41         
     42        // Debug mode configuration. 
     43        if($service['debugmode'] == true) { 
     44            if(isset($service['dbms'])) { 
     45                switch($service['dbms']) { 
     46                    case 'mysqli':         require_once(ROOT. "/library/debug/MySQLi.php"); break; 
     47                    case 'mysql': default: require_once(ROOT. "/library/debug/MySQL.php"); break; 
     48                } 
     49            } else requireLibrary("debug/MySQL");  
     50        } 
     51         
     52        // Session cookie patch. 
     53        if(!empty($service['domain']) && strstr( $_SERVER['HTTP_HOST'], $service['domain'] ) ) { 
     54            $service['session_cookie_domain'] = $service['domain']; 
     55        } else { 
     56            $service['session_cookie_domain'] = $_SERVER['HTTP_HOST']; 
     57        } 
    1558 
    16         // TODO: Temporary implementation: just import from config.php's global variables 
    17         global $database, $service; 
    1859        $this->database = $database; 
    1960        $this->service = $service; 
    20         $this->backend_name = isset($service['dbms']) ? $service['dbms'] : 'mysql'; 
     61        $this->backend_name = $service['dbms']; 
    2162    } 
    2263