Changeset 940


Ignore:
Timestamp:
11/05/08 18:16:54 (4 years ago)
Author:
bogdan2412
Message:

Merged changes from review request http://reviewboard.infoarena.ro/r/13/.

Diff 2 (which was already merged) to diff 5.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/common/string.php

    r922 r940  
    11<?php 
    22 
    3   // Various string processing functions. 
     3// Various string processing functions. 
    44 
    55function starts_with($s, $substr) { 
     6    log_assert(is_string($s) && is_string($substr)); 
    67    return substr($s, 0, strlen($substr)) == $substr; 
    78} 
    89 
    910function ends_with($s, $substr) { 
     11    log_assert(is_string($s) && is_string($substr)); 
    1012    return substr($s, -strlen($substr)) == $substr; 
    1113} 
  • trunk/www/config.php

    r933 r940  
    6969define("IA_LATEX_ENABLE", false); 
    7070 
    71 // List of infoarena controllers 
    72 // Direct controllers 
    73 $IA_DIRECT_CONTROLLERS = array('register', 'news_feed', 'changes', 
    74                                'login', 'logout', 'json', 'job_detail', 
    75                                'monitor', 'projector', 'submit', 
    76                                'plot', 'search', 
    77                                'unsubscribe', 'resetpass', 'reeval'); 
    78  
    79 // List of controllers which do not point to a textblock  
    80 $IA_NONTEXTBLOCK_CONTROLLERS = array_merge(array('account', 'admin', 'forum', 'confirm', 
    81                                            'inregistrare-runda', 'lista-inregistrare'), 
    82                                            $IA_DIRECT_CONTROLLERS); 
    83  
    84 // List of all controllers 
    85 $IA_CONTROLLERS = array_merge(array('blog'), 
    86                               $IA_NONTEXTBLOCK_CONTROLLERS); 
    87  
    8871// List of safe MIME types 
    8972// FIXME: add more? 
  • trunk/www/index.php

    r938 r940  
    3737// Filter empty path elements. Strips extra '/'s 
    3838$page = normalize_page_name($page); 
    39 $page_path = explode('/', $page); 
    40  
    41 $url_root = getattr($page_path, 0, ''); 
    42 $page_id = implode('/', array_slice($page_path, 1)); 
     39$pagepath = explode('/', $page); 
     40 
     41$urlstart = getattr($pagepath, 0, ''); 
     42$page_id = implode('/', array_slice($pagepath, 1)); 
    4343$action = request('action', 'view'); 
    4444 
    45 // Check if page gets passed to a controller or is a simple textblock 
    46 if (in_array($url_root, $IA_CONTROLLERS)) { 
    47     // Trivial direct mappings 
    48     if (in_array($url_root, $IA_DIRECT_CONTROLLERS)) { 
    49         require_once(IA_ROOT_DIR."www/controllers/{$url_root}.php"); 
    50         $fname = "controller_{$url_root}"; 
    51         $fname($page_id); 
    52     } 
    53  
    54     // Account edit page 
    55     if ($url_root == 'account') { 
    56         require_once(IA_ROOT_DIR.'www/controllers/account.php'); 
    57         controller_account(getattr($page_path, 1)); 
    58     } 
    59  
    60     // Admin controller 
    61     if ($url_root == 'admin') { 
    62         $subcontroller = getattr($page_path, 1); 
    63  
    64         // Blog admin 
    65         if ($subcontroller == 'blog') { 
    66             $obj_id = implode("/", array_slice($page_path, 1)); 
    67             require_once(IA_ROOT_DIR.'www/controllers/blog.php'); 
    68             controller_blog_admin($obj_id); 
    69         } 
    70  
    71         // Task creator 
    72         if ($subcontroller == 'problema-noua') { 
    73             require_once(IA_ROOT_DIR.'www/controllers/task.php'); 
    74             controller_task_create(); 
    75         } 
    76  
    77         // Task detail editor 
    78         if ($subcontroller == 'problema') { 
    79             $obj_id = implode("/", array_slice($page_path, 2)); 
    80             require_once(IA_ROOT_DIR.'www/controllers/task.php'); 
    81             controller_task_details($obj_id); 
    82         } 
    83  
    84         // Round creator 
    85         if ($subcontroller == 'runda-noua') { 
    86             require_once(IA_ROOT_DIR.'www/controllers/round.php'); 
    87             controller_round_create(); 
    88         } 
    89  
    90         // Round detail editor 
    91         if ($subcontroller == 'runda') { 
    92             $obj_id = implode("/", array_slice($page_path, 2)); 
    93             require_once(IA_ROOT_DIR.'www/controllers/round.php'); 
    94             controller_round_details($obj_id); 
    95         } 
    96  
    97         // Invalid subcontroller 
    98         flash_error('URL invalid'); 
    99         redirect(url_home()); 
    100     } 
    101  
    102     if ($url_root == 'inregistrare-runda') { 
    103         $obj_id = implode("/", array_slice($page_path, 1)); 
    104         require_once(IA_ROOT_DIR.'www/controllers/round_register.php'); 
    105         controller_round_register($obj_id); 
    106     } 
    107  
    108     // Round registered users 
    109     if ($url_root == 'lista-inregistrare') { 
    110         $obj_id = implode("/", array_slice($page_path, 1)); 
    111         require_once(IA_ROOT_DIR.'www/controllers/round_register.php'); 
    112         controller_round_register_view($obj_id); 
    113     } 
    114  
    115     // Password reset confirmation 
    116     if ($url_root == 'confirm') { 
    117         require_once(IA_ROOT_DIR.'www/controllers/resetpass.php'); 
    118         controller_resetpass_confirm($page_id); 
    119     } 
    120  
    121     // Special textblock controllers 
    122     // Blog controller 
    123     if ($url_root == 'blog') 
    124     { 
    125         // Blog index 
    126         if ($page == 'blog') { 
    127             // Blog RSS feed 
    128             if ($action == 'rss') { 
    129                 require_once(IA_ROOT_DIR.'www/controllers/blog.php'); 
    130                 controller_blog_feed(); 
    131             } else { 
    132                 require_once(IA_ROOT_DIR.'www/controllers/blog.php'); 
    133                 controller_blog_index(); 
    134             } 
    135         } 
    136  
    137         // Blog edit 
    138         if ($action == 'edit') { 
    139             require_once(IA_ROOT_DIR.'www/controllers/textblock_edit.php'); 
    140             controller_textblock_edit($page, 'private'); 
    141         } 
    142  
    143         // Blog view 
    144         if ($action == 'view') { 
    145             require_once(IA_ROOT_DIR.'www/controllers/blog.php'); 
    146             controller_blog_view($page, request('revision')); 
    147         } 
    148     } 
     45// Direct mapping list 
     46// Note: array_flip() flips keys with values in a dictionary. 
     47// FIXME: change this to Romanian! 
     48$directmaps = array_flip(array('register', 'news_feed', 'changes', 
     49                               'login', 'logout', 'json', 'job_detail', 
     50                               'monitor', 'projector', 'submit', 'userinfo', 
     51                               'plot', 'search', 
     52                               'unsubscribe', 'resetpass', 'reeval' 
     53)); 
     54// 
     55// Here comes the big url mapper. 
     56// We include in the if statement to avoid an extra parsing load. 
     57// 
     58 
     59// Trivial direct mappings 
     60if (isset($directmaps[$urlstart])) { 
     61    require_once(IA_ROOT_DIR."www/controllers/{$urlstart}.php"); 
     62    $fname = "controller_{$urlstart}"; 
     63    $fname($page_id); 
     64} 
     65 
     66// Account edit page 
     67else if ($urlstart == 'account') { 
     68    require_once(IA_ROOT_DIR.'www/controllers/account.php'); 
     69    controller_account(getattr($pagepath, 1)); 
     70} 
     71 
     72// Blog admin 
     73else if ($urlstart == 'admin' && getattr($pagepath, 1) == 'blog') { 
     74    $obj_id = implode("/", array_slice($pagepath, 1)); 
     75    require_once(IA_ROOT_DIR.'www/controllers/blog.php'); 
     76    controller_blog_admin($obj_id); 
     77} 
     78 
     79// Task creator 
     80else if ($page == 'admin/problema-noua') { 
     81    require_once(IA_ROOT_DIR.'www/controllers/task.php'); 
     82    controller_task_create(); 
     83} 
     84 
     85// Task detail editor 
     86else if ($urlstart == 'admin' && getattr($pagepath, 1) == 'problema') { 
     87    $obj_id = implode("/", array_slice($pagepath, 2)); 
     88    require_once(IA_ROOT_DIR.'www/controllers/task.php'); 
     89    controller_task_details($obj_id); 
     90} 
     91 
     92// Round creator 
     93else if ($page == 'admin/runda-noua') { 
     94    require_once(IA_ROOT_DIR.'www/controllers/round.php'); 
     95    controller_round_create(); 
     96} 
     97 
     98// Round detail editor 
     99else if ($urlstart == 'admin' && getattr($pagepath, 1) == 'runda') { 
     100    $obj_id = implode("/", array_slice($pagepath, 2)); 
     101    require_once(IA_ROOT_DIR.'www/controllers/round.php'); 
     102    controller_round_details($obj_id); 
     103} 
     104 
     105// Round registration  
     106else if ($urlstart == 'inregistrare-runda') { 
     107    $obj_id = implode("/", array_slice($pagepath, 1)); 
     108    require_once(IA_ROOT_DIR.'www/controllers/round_register.php'); 
     109    controller_round_register($obj_id); 
     110} 
     111 
     112// Round registered users 
     113else if ($urlstart == 'lista-inregistrare') { 
     114    $obj_id = implode("/", array_slice($pagepath, 1)); 
     115    require_once(IA_ROOT_DIR.'www/controllers/round_register.php'); 
     116    controller_round_register_view($obj_id); 
     117} 
     118 
     119// Blog RSS feed 
     120else if ($page == 'blog' && $action == 'rss') { 
     121    require_once(IA_ROOT_DIR.'www/controllers/blog.php'); 
     122    controller_blog_feed(); 
     123} 
     124 
     125// Blog index 
     126else if ($page == 'blog') { 
     127    require_once(IA_ROOT_DIR.'www/controllers/blog.php'); 
     128    controller_blog_index(); 
     129} 
     130 
     131// Blog edit 
     132else if ($urlstart == 'blog' && $action == 'edit') { 
     133    require_once(IA_ROOT_DIR.'www/controllers/textblock_edit.php'); 
     134    controller_textblock_edit($page, 'private'); 
     135} 
     136 
     137// Blog view 
     138else if ($urlstart == 'blog' && $action == 'view') { 
     139    require_once(IA_ROOT_DIR.'www/controllers/blog.php'); 
     140    controller_blog_view($page, request('revision')); 
    149141} 
    150142 
     
    152144// FIXME: quick array of sorts? 
    153145//  - edit textblock 
    154 if ($action == 'edit') { 
     146else if ($action == 'edit') { 
    155147    require_once(IA_ROOT_DIR.'www/controllers/textblock_edit.php'); 
    156148    controller_textblock_edit($page); 
     
    216208} 
    217209 
     210// reset password 
     211else if ('confirm' == $urlstart) { 
     212    // confirm reset password 
     213    require_once(IA_ROOT_DIR.'www/controllers/resetpass.php'); 
     214    controller_resetpass_confirm($page_id); 
     215} 
     216 
    218217// user profile, view personal page / statistics / rating evolution 
    219 else if (IA_USER_TEXTBLOCK_PREFIX == $url_root.'/' && 
     218else if (IA_USER_TEXTBLOCK_PREFIX == $urlstart.'/' && 
    220219         ('view' == $action || 'rating' == $action || 'stats' == $action )) { 
    221220    require_once(IA_ROOT_DIR.'www/controllers/user.php'); 
  • trunk/www/wiki/MyTextile.php

    r934 r940  
    131131        $args['extra'] = $alt; 
    132132 
    133         // Catch internal images 
    134133        // To avoid CSRF exploits we restrict all images to textblock attachments 
    135134        $allowed = false; 
    136135        // $allowed_urls are exceptions to this rule 
    137         $allowed_urls = array("static/images/", "plot/rating", "plot/distribution"); 
     136        $allowed_urls = array("static/images/", "plot/"); 
    138137 
    139138        foreach ($allowed_urls as $url) { 
     
    144143            } 
    145144        } 
    146       
    147         if (!$allowed && !preg_match('/^'.IA_RE_EXTERNAL_URL.'$/xi', $srcpath)) { 
     145 
     146        // Catch internal images 
     147        if (!preg_match('/^'.IA_RE_EXTERNAL_URL.'$/xi', $srcpath)) { 
    148148            if (preg_match('/^ ('.IA_RE_PAGE_NAME.') \? '. 
    149149                           '('.IA_RE_ATTACHMENT_NAME.')'. 
     
    158158                $args['src'] = html_escape(url_absolute(url_image_resize($matches[1], $matches[2], $extra))); 
    159159                $allowed = true; 
    160  
    161                 // Test if $srcpath references an internal url that is NOT a textblock 
    162                 // in case someone tries to trick the regexp with something like !logout?something! 
    163  
    164                 $tmp = explode("?", $srcpath); 
    165                 $srcpath_root = $tmp[0];                  // Strips everything after "?" 
    166                 $tmp = explode("/", $srcpath_root); 
    167                 $srcpath_controller = $tmp[0];            // Strips everything after first "/" 
    168                 global $IA_NONTEXTBLOCK_CONTROLLERS; 
    169                 if (in_array(strtolower($srcpath_controller), $IA_NONTEXTBLOCK_CONTROLLERS)) { 
    170                     $allowed = false; 
    171                 } 
    172160            } 
    173161        } 
    174162 
    175163        if (!$allowed) { 
    176             return macro_error("Imaginile trebuie neaparat sa fie atasamente ale unei pagini"); 
     164            return macro_error("Imaginile trebuie neaparat sa fie atasamente ale unei pagini."); 
    177165        } 
    178166        //log_print("passing to parent::format image"); 
Note: See TracChangeset for help on using the changeset viewer.