Changeset 1164 for trunk


Ignore:
Timestamp:
01/14/12 16:18:10 (4 months ago)
Author:
bogdan2412
Message:

Make infoarena compatible with HPHP.

  • Implemented APC caching support since eaccelerator is not compatible with HPHP and although we support memcached, we do not use it on live.
  • Replaced instances of create_function_cached with php anonymous functions. This bumps the PHP version requirement to 5.3, but it allows the code to work with HPHP, since dynamic function generation is replaced with staticly analyzable functions. This also removes a horrible, terrible hack in Textile.php which was storing the current instance of the Textile class being processed as a static variable so that it could be accessed by anonymous functions.
  • Replaced occurrences of assert with log_assert.
  • When running under HPHP, IA_HPHP_ENV is defined and is used to bypass some incompatible code (redundant ini configuration checks).
  • Fixed some includes that were dependent on the working directory being www/
  • Included a sample HPHP configuration file and a Makefile with compilation commands.

REVIEW URL: http://reviewboard.infoarena.ro/r/182/

Location:
trunk
Files:
5 added
28 edited

Legend:

Unmodified
Added
Removed
  • trunk/common/cache.php

    r966 r1164  
    144144//      mem_cache_purge deletes everything from the cache. Try to avoid calling it. 
    145145// 
    146 // FIXME: cache is not logged. See IA_LOG_MEM_CACHE. 
    147146if (IA_MEM_CACHE_METHOD == 'none') { 
    148147 
     
    259258        } 
    260259    } 
     260 
     261} else if (IA_MEM_CACHE_METHOD == 'apc') { 
     262    // APC cache implementation 
     263    function mem_cache_get($cache_id) { 
     264        $res = apc_fetch($cache_id); 
     265        if ($res === false) { 
     266            if (IA_LOG_MEM_CACHE) { 
     267                log_print("MEM CACHE: miss on $cache_id"); 
     268            } 
     269            return false; 
     270        } else { 
     271            if (IA_LOG_MEM_CACHE) { 
     272                log_print("MEM CACHE: hit on $cache_id"); 
     273            } 
     274            return unserialize($res); 
     275        } 
     276    } 
     277 
     278    function mem_cache_set($cache_id, $object, $ttl = IA_MEM_CACHE_EXPIRATION) { 
     279        log_assert($object !== 'false', "Can't cache false values"); 
     280        apc_store($cache_id, serialize($object), $ttl); 
     281 
     282        if (IA_LOG_MEM_CACHE) { 
     283            log_print("MEM CACHE: store $cache_id"); 
     284        } 
     285        return $object; 
     286    } 
     287 
     288    function mem_cache_delete($cache_id) { 
     289        apc_delete($cache_id); 
     290        if (IA_LOG_MEM_CACHE) { 
     291            log_print("MEM CACHE: delete $cache_id"); 
     292        } 
     293    } 
     294 
     295    function mem_cache_purge() { 
     296        if (IA_LOG_MEM_CACHE) { 
     297            log_print("MEM CACHE: purge"); 
     298        } 
     299        apc_clear_cache(); 
     300    } 
    261301} 
    262302 
  • trunk/common/common.php

    r1163 r1164  
    332332 
    333333    // Check for retarded php.ini settings. 
    334     if (IA_HTTP_ENV) { 
     334    if (IA_HTTP_ENV && !defined('IA_HPHP_ENV')) { 
    335335        log_assert(!ini_get("session.auto_start"), 
    336336                   "Please disable session.auto_start. It kills babies!"); 
  • trunk/common/db/attachment.php

    r1145 r1164  
    151151// You may use % as a wildcard 
    152152function attachment_get_all($page, $name='%', $start = 0, $count = 99999999) { 
    153     assert(is_whole_number($start)); 
    154     assert(is_whole_number($count)); 
     153    log_assert(is_whole_number($start)); 
     154    log_assert(is_whole_number($count)); 
    155155    $query = sprintf("SELECT ia_file.*, ia_user.username, ia_user.full_name as user_fullname 
    156156                      FROM ia_file 
     
    165165// _count for the above. 
    166166function attachment_get_count($page, $name='%', $start = 0, $count = 99999999) { 
    167     assert(is_whole_number($start)); 
    168     assert(is_whole_number($count)); 
     167    log_assert(is_whole_number($start)); 
     168    log_assert(is_whole_number($count)); 
    169169    $query = sprintf("SELECT COUNT(*) 
    170170                      FROM ia_file 
     
    184184// FIXME: does this belong here? 
    185185function attachment_get_filepath($attach) { 
    186     assert(is_array($attach)); 
     186    log_assert(is_array($attach)); 
    187187    return IA_ROOT_DIR.'attach/'. 
    188188            strtolower(preg_replace('/[^a-z0-9\.\-_]/i', '_', $attach['page'])) . '_' . 
  • trunk/common/textblock.php

    r1098 r1164  
    152152function textblock_copy_replace($srcprefix, $dstprefix, $replace, $security, 
    153153        $user_id, $remote_ip_info = null) { 
    154     assert($srcprefix != $dstprefix); 
    155     assert($security === null || is_textblock_security_descriptor($security)); 
    156     assert(is_whole_number($user_id)); 
     154    log_assert($srcprefix != $dstprefix); 
     155    log_assert($security === null || 
     156               is_textblock_security_descriptor($security)); 
     157    log_assert(is_whole_number($user_id)); 
    157158 
    158159    $textblocks = textblock_get_by_prefix($srcprefix, true, false); 
  • trunk/www/config.php

    r1071 r1164  
    1616 
    1717// maximum attachment size for wiki pages 
    18 define("IA_ATTACH_MAXSIZE", 70*1024*1024); 
     18define("IA_ATTACH_MAXSIZE", 64*1024*1024); 
    1919 
    2020// maximum jobs to reeval 
  • trunk/www/format/pager.php

    r1063 r1164  
    127127    $access_keys = getattr($options, 'use_digit_access_keys', true); 
    128128 
    129     assert(is_whole_number($display_entries)); 
    130     assert(is_whole_number($first_entry)); 
    131     assert(is_whole_number($total_entries)); 
     129    log_assert(is_whole_number($display_entries)); 
     130    log_assert(is_whole_number($first_entry)); 
     131    log_assert(is_whole_number($total_entries)); 
    132132 
    133133    $curpage = (int)($first_entry / $display_entries); 
  • trunk/www/htaccess.sample

    r1155 r1164  
    3434php_value log_errors true 
    3535php_value html_errors false 
    36 php_value memory_limit "16M" 
    37 php_value post_max_size "71M" 
    38 php_value upload_max_filesize "70M" 
    39  
     36php_value memory_limit "64M" 
     37php_value post_max_size "65M" 
     38php_value upload_max_filesize "64M" 
  • trunk/www/identity.php

    r852 r1164  
    115115        session_set_cookie_params(0, '/', IA_COOKIE_DOMAIN); 
    116116    } 
    117     session_start(); 
     117    if (defined('IA_HPHP_ENV')) { 
     118        // FIXME: Raises PHP Warning: Constant SID already defined when 
     119        // init_php_session is called a second time. 
     120        @session_start(); 
     121    } else { 
     122        session_start(); 
     123    } 
    118124} 
    119125 
  • trunk/www/index.php

    r1159 r1164  
    11<?php 
    2 require_once("../config.php"); 
     2if (!defined('IA_HPHP_ENV')) { 
     3    require_once("../config.php"); 
     4} 
    35require_once(IA_ROOT_DIR."www/config.php"); 
    46require_once(IA_ROOT_DIR."common/log.php"); 
  • trunk/www/macros/macro_rankings.php

    r1134 r1164  
    6767        array( 
    6868            'title' => 'Pozitie', 
    69             'key' => 'pos', 
    70             'rowform' => create_function_cached('$row', 'return $row["ranking"];'), 
     69            'key' => 'ranking', 
    7170            'css_class' => 'number rank' 
    7271        ), 
     
    7473            'title' => 'Nume', 
    7574            'key' => 'user_full', 
    76             'rowform' => create_function_cached('$row', 
    77                 'return format_user_normal($row["user_name"], $row["user_full"], $row["user_rating"]);'), 
     75            'rowform' => function($row) { 
     76                return format_user_normal($row['user_name'], $row['user_full'], $row['user_rating']); 
     77            }, 
    7878        ), 
    7979    ); 
     
    111111            'title' => $column['title'], 
    112112            'key' => $column['name'], 
    113             'rowform' => create_function_cached('$row', 'return round($row[\''.$column['name'].'\']);'), 
     113            'rowform' => function($row) use ($column) { 
     114                return round($row[$column['name']]); 
     115            }, 
    114116            'css_class' => 'number score' 
    115117        )); 
     
    123125        'title' => $total, 
    124126        'key' => 'score', 
    125         'rowform' => create_function_cached('$row', 'return round($row[\'score\']);'), 
     127        'rowform' => function($row) { 
     128            return round($row['score']); 
     129        }, 
    126130        'css_class' => 'number score' 
    127131    )); 
  • trunk/www/macros/macro_tasks.php

    r1134 r1164  
    176176                'title' => 'Număr', 
    177177                'css_class' => 'number', 
    178                 'rowform' => create_function_cached('$row', 
    179                         'return str_pad($row["order"] - 1, 3, \'0\', STR_PAD_LEFT);'), 
     178                'rowform' => function($row) { 
     179                    return str_pad($row["order"] - 1, 3, '0', STR_PAD_LEFT); 
     180                }, 
    180181        ); 
    181182    } 
  • trunk/www/macros/macro_toprated.php

    r852 r1164  
    3232            'title' => 'Nume', 
    3333            'key' => 'full_name', 
    34             'rowform' => create_function_cached('$row', 
    35                                          'return format_user_normal($row["username"], $row["full_name"], $row["rating_cache"]);'), 
     34            'rowform' => function($row) { 
     35                return format_user_normal($row['username'], $row['full_name'], $row['rating_cache']); 
     36            }, 
    3637        ), 
    3738        array( 
    3839            'title' => 'Rating', 
    3940            'key' => 'rating_cache', 
    40             'rowform' => create_function_cached('$row', 'return rating_scale($row[\'rating_cache\']);'), 
     41            'rowform' => function($row) { 
     42                return rating_scale($row['rating_cache']); 
     43            }, 
    4144            'css_class' => 'number rating', 
    4245        ), 
  • trunk/www/utilities.php

    r1017 r1164  
    242242    // warnings about function redeclaration. 
    243243    include($view_file_name); 
    244     //include('views/vardump.php'); 
    245244} 
    246245 
  • trunk/www/views/json.php

    r852 r1164  
    55// encode JSON 
    66$json = new Services_JSON(); 
    7 assert($view['json']); 
     7log_assert($view['json']); 
    88$output = $json->encode($view['json']); 
    99 
  • trunk/www/views/listattach.php

    r1159 r1164  
    1 <?php  
     1<?php 
    22include('header.php'); 
    33require_once(IA_ROOT_DIR . "www/format/table.php"); 
     
    55 
    66?> 
    7      
     7 
    88<script type="text/javascript"> 
    99    function rename_form(id) { 
     
    1212            document.getElementById("link_"+id).style.display = "none"; 
    1313            document.getElementById("rename_link_"+id).textContent = "Anuleaza"; 
    14         }  
     14        } 
    1515        else { 
    1616            document.getElementById("rename_"+id).style.display = "none"; 
     
    7373function format_operations($row) { 
    7474    global $page_name; 
    75      
     75 
    7676    $delurl = format_post_link(url_attachment_delete($page_name, $row['name']), 
    7777                               "Sterge", array(), true, 
     
    103103        'title' => 'Utilizator', 
    104104        'key' => 'username', 
    105         'rowform' => create_function_cached('$row', 
    106                 'return format_user_tiny($row["username"], $row["user_fullname"]);'), 
     105        'rowform' => function($row) { 
     106            return format_user_tiny($row['username'], $row['user_fullname']); 
     107        }, 
    107108    ), 
    108109    array( 
  • trunk/www/views/monitor.php

    r1107 r1164  
    152152            'title' => 'Utilizator', 
    153153            'key' => 'username', 
    154             'rowform' => create_function_cached('$row', 
    155                  'return format_user_tiny($row["user_name"], $row["user_fullname"]);'), 
     154            'rowform' => function($row) { 
     155                return format_user_tiny($row['user_name'], $row['user_fullname']); 
     156            }, 
    156157        ), 
    157158        array( 
  • trunk/www/views/projector.php

    r934 r1164  
    8989            'title' => 'Utilizator', 
    9090            'key' => 'username', 
    91             'rowform' => create_function_cached('$row', 
    92                  'return format_user_tiny($row["user_name"], $row["user_fullname"]);'), 
     91            'rowform' => function($row) { 
     92                 return format_user_tiny($row['user_name'], $row['user_fullname']); 
     93            }, 
    9394        ), 
    9495        array( 
  • trunk/www/views/round_edit.php

    r1125 r1164  
    1212require_once(IA_ROOT_DIR."www/format/form.php"); 
    1313require_once(IA_ROOT_DIR."www/views/round_edit_header.php"); 
    14 include('views/header.php'); 
     14include('header.php'); 
    1515 
    1616echo round_edit_tabs($view['round_id'], 'round-edit-params'); 
     
    1818$can_tag = identity_can('round-tag', $round); 
    1919if ($can_tag) { 
    20     include('views/tags_header.php'); 
     20    include('tags_header.php'); 
    2121} 
    2222 
  • trunk/www/views/round_register.php

    r934 r1164  
    11<?php 
    2 include('views/header.php'); 
     2include('header.php'); 
    33?> 
    44 
  • trunk/www/views/round_register_view.php

    r864 r1164  
    1515        array( 
    1616            'title' => 'Pozitie', 
    17             'rowform' => create_function_cached('$row', 'return $row["position"];'), 
     17            'key' => 'position', 
    1818            'css_class' => 'number rank', 
    1919        ), 
    2020        array( 
    2121            'title' => 'Nume', 
    22             'rowform' => create_function_cached('$row', 
    23                                          'return format_user_normal($row["username"], $row["fullname"], $row["rating"]);'), 
     22            'rowform' => function($row) { 
     23                return format_user_normal($row['username'], $row['fullname'], $row['rating']); 
     24            }, 
    2425        ), 
    2526        array( 
    2627            'title' => 'Rating', 
    27             'rowform' => create_function_cached('$row', 'return rating_scale($row["rating"]);'), 
     28            'rowform' => function($row) { 
     29                return rating_scale($row['rating']); 
     30            }, 
    2831            'css_class' => 'number rating' 
    2932        ), 
  • trunk/www/views/round_task_order.php

    r1132 r1164  
    44require_once(IA_ROOT_DIR."www/views/round_edit_header.php"); 
    55require_once(IA_ROOT_DIR."www/macros/macro_tasks.php"); 
    6 include("views/header.php"); 
     6include('header.php'); 
    77 
    88echo round_edit_tabs($view['round_id'], 'round-edit-task-order'); 
  • trunk/www/views/round_unregister.php

    r992 r1164  
    11<?php 
    2 include('views/header.php'); 
     2include('header.php'); 
    33?> 
    44 
  • trunk/www/views/task_edit.php

    r1111 r1164  
    88    "<script type=\"text/javascript\" src=\"" . html_escape(url_static("js/parameditor.js")) . "\"></script>"; 
    99 
    10 include('views/header.php'); 
    11 include('views/tags_header.php'); 
     10include('header.php'); 
     11include('tags_header.php'); 
    1212 
    1313echo task_edit_tabs($view['task_id'], request("action")); 
  • trunk/www/views/task_filter_results.php

    r1120 r1164  
    109109        'title' => 'Număr', 
    110110        'css_class' => 'number', 
    111         'rowform' => create_function_cached('$row', 
    112         'return str_pad($row["order"] - 1, 3, \'0\', STR_PAD_LEFT);')); 
     111        'rowform' => function($row) { 
     112            return str_pad($row["order"] - 1, 3, '0', STR_PAD_LEFT); 
     113        }); 
    113114 
    114115$column_infos[] = array( 
  • trunk/www/views/task_rating_edit.php

    r1139 r1164  
    44require_once(IA_ROOT_DIR . "www/views/task_edit_header.php"); 
    55 
    6 include('views/header.php'); 
     6include('header.php'); 
    77 
    88echo task_edit_tabs($view['task_id'], request("action")); 
     
    5353</form> 
    5454 
    55 <?php include('views/footer.php'); 
     55<?php include('footer.php'); 
  • trunk/www/views/textblock_edit.php

    r1139 r1164  
    44$view['head'] = getattr($view, 'head')."<script type=\"text/javascript\" src=\"" . html_escape(url_static("js/wikiedit.js")) . "\"></script>"; 
    55 
    6 include('views/header.php'); 
    7 include('views/tags_header.php'); 
     6include('header.php'); 
     7include('tags_header.php'); 
    88 
    99// insert task edit tabs 
  • trunk/www/views/textblock_history.php

    r1030 r1164  
    8484        'title' => 'Utilizator', 
    8585        'key' => 'username', 
    86         'rowform' => create_function_cached('$row', 
    87                 'return format_user_tiny($row["user_name"], $row["user_fullname"], $row["rating_cache"]);'), 
     86        'rowform' => function($row) { 
     87            return format_user_tiny($row['user_name'], $row['user_fullname'], $row['rating_cache']); 
     88        }, 
    8889    ), 
    8990    array( 
     
    119120); 
    120121 
    121 ?>                                                          
     122?> 
    122123 
    123124<form 
     
    153154</form> 
    154155 
    155 <?php include('footer.php'); ?>  
     156<?php include('footer.php'); ?> 
  • trunk/www/wiki/Textile.php

    r918 r1164  
    773773 
    774774    // preserve contents of the '==', 'pre', 'blockcode' sections 
     775    $me =& $this; 
    775776    $str = preg_replace_callback('/( (?<=\n\n)== | (?<=^)== )  (.+?)  ( ==(?=\n\n) | ==(?=$) )  /sx', 
    776                                  $this->_cb('$me->_repl($me->repl[0], $me->format_block(array("text" => $m[2])))'), $str); 
     777                                 function($m) use ($me) { 
     778                                   return $me->_repl($me->repl[0], $me->format_block(array("text" => $m[2]))); 
     779                                 }, $str); 
    777780 
    778781    if (!$this->disable_html()) { 
    779782      // preserve style, script tag contents 
    780       $str = preg_replace_callback('!(<(style|script)(?:>| .+?>).*?</\2>)!s', $this->_cb('$me->_repl($me->repl[0], $m[1])'), $str); 
     783      $str = preg_replace_callback('!(<(style|script)(?:>| .+?>).*?</\2>)!s', 
     784                                   function($m) use ($me) { 
     785                                     return $me->_repl($me->repl[0], $m[1]); 
     786                                   }, $str); 
    781787 
    782788      // preserve HTML comments 
    783       $str = preg_replace_callback('|(<!--.+?-->)|s', $this->_cb('$me->_repl($me->repl[0], $m[1])'), $str); 
     789      $str = preg_replace_callback('|(<!--.+?-->)|s', 
     790                                   function($m) use ($me) { 
     791                                     return $me->_repl($me->repl[0], $m[1]); 
     792                                   }, $str); 
    784793 
    785794      // preserve pre block contents, encode contents by default 
    786795      $pre_start = count($this->repl[0]); 
    787796      $str = preg_replace_callback('{(<pre(?: [^>]*)?>)(.+?)(</pre>)}s', 
    788                                    $this->_cb('"\n\n" . $me->_repl($me->repl[0], $m[1] . $me->encode_html($m[2], 1) . $m[3]) . "\n\n"'), $str); 
     797                                   function($m) use ($me) { 
     798                                     return "\n\n" . $me->_repl($me->repl[0], $m[1] . $me->encode_html($m[2], 1) . $m[3]) . "\n\n"; 
     799                                   }, $str); 
    789800      // fix code tags within pre blocks we just saved. 
    790801      for ($i = $pre_start; $i < count($this->repl[0]); $i++) { 
     
    794805      // preserve code blocks by default, encode contents 
    795806      $str = preg_replace_callback('{(<code(?: [^>]+)?>)(.+?)(</code>)}s', 
    796                                    $this->_cb('$me->_repl($me->repl[0], $m[1] . $me->encode_html($m[2], 1) . $m[3])'), $str); 
     807                                   function($m) use ($me) { 
     808                                     return $me->_repl($me->repl[0], $m[1] . $me->encode_html($m[2], 1) . $m[3]); 
     809                                   }, $str); 
    797810 
    798811      // encode blockcode tag (an XHTML 2 tag) and encode it's 
    799812      // content by default 
    800813      $str = preg_replace_callback('{(<blockcode(?: [^>]+)?>)(.+?)(</blockcode>)}s', 
    801                                    $this->_cb('"\n\n" . $me->_repl($me->repl[0], $m[1] . $me->encode_html($m[2], 1) . $m[3]) . "\n\n"'), $str); 
     814                                   function($m) use ($me) { 
     815                                     return "\n\n" . $me->_repl($me->repl[0], $m[1] . $me->encode_html($m[2], 1) . $m[3]) . "\n\n"; 
     816                                   }, $str); 
    802817    } 
    803818 
    804819    // LaTeX code 
    805     $str = preg_replace_callback('!((<tex>)(.*?)(<\/tex>))!s', $this->_cb('$me->_repl($me->repl[0], $me->format_latex(array("text" => $m[3])))'), $str); 
     820    $str = preg_replace_callback('!((<tex>)(.*?)(<\/tex>))!s', 
     821                                 function($m) use ($me) { 
     822                                   return $me->_repl($me->repl[0], $me->format_latex(array("text" => $m[3]))); 
     823                                 }, $str); 
    806824 
    807825    // pass through and remove links that follow this format 
     
    811829    //$links = array(); 
    812830    $str = preg_replace_callback('{(?:\n|^) [ ]* \[ ([^ ]+?) [ ]*? (?:\( (.+?) \) )?  \] ((?:(?:ftp|https?|telnet|nntp)://|/)[^ ]+?) [ ]* (\n|$)}mx', 
    813                                  $this->_cb('($me->links[$m[1]] = array("url" => $m[3], "title" => $m[2])) ? $m[4] : $m[4]'), $str); 
     831                                 function($m) use ($me) { 
     832                                   return ($me->links[$m[1]] = array("url" => $m[3], "title" => $m[2])) ? $m[4] : $m[4]; 
     833                                 }, $str); 
    814834    //$this->links = $links; 
    815835 
     
    10321052        //                                ==(.+?)== 
    10331053        //                                (?:$|([\]}])|(?=' . $this->punct . '{1,2}|\s))}sx', 
    1034         //                              $this->_cb('$me->_repl($me->repl[0], $me->format_block(array("text" => $m[2], "inline" => 1, "pre" => $m[1], "post" => $m[3])))'), $para); 
     1054        //                              function($m) use ($me) { 
     1055        //                                return $me->_repl($me->repl[0], $me->format_block(array("text" => $m[2], "inline" => 1, "pre" => $m[1], "post" => $m[3]))); 
     1056        //                              }, $para); 
    10351057        $buffer .= $this->encode_html_basic($para, 1); 
    10361058        $buffer = preg_replace('/&lt;textile#(\d+)&gt;/', '<textile#$1>', $buffer); 
     
    12091231 
    12101232    array_unshift($this->repl, array()); 
     1233    $me =& $this; 
    12111234    $buffer = preg_replace_callback('{(?:^|(?<=[\s>])|([{[])) 
    12121235                                      ==(.+?)== 
    12131236                                      (?:$|([\]}])|(?=' . $this->punct . '{1,2}|\s))}sx', 
    1214                                     $this->_cb('$me->_repl($me->repl[0], $me->format_block(array("text" => $m[2], "inline" => 1, "pre" => $m[1], "post" => $m[3])))'), $buffer); 
     1237                                    function($m) use ($me) { 
     1238                                      return $me->_repl($me->repl[0], $me->format_block(array("text" => $m[2], "inline" => 1, "pre" => $m[1], "post" => $m[3]))); 
     1239                                    }, $buffer); 
    12151240 
    12161241    unset($tokens); 
     
    13171342    array_unshift($this->repl, array()); 
    13181343 
    1319     $text = preg_replace_callback('{' . $this->codere . '}mx', $this->_cb('$me->_repl($me->repl[0], $me->format_code(array("text" => $m[2] . $m[4], "lang" => $m[1] . $m[3])))'), $text); 
     1344    $me =& $this; 
     1345    $text = preg_replace_callback('{' . $this->codere . '}mx', 
     1346                                  function($m) use ($me) { 
     1347                                    return $me->_repl($me->repl[0], $me->format_code(array("text" => $m[2] . $m[4], "lang" => $m[1] . $m[3]))); 
     1348                                  }, $text); 
    13201349 
    13211350    // images must be processed before encoding the text since they might 
     
    13341363                                    (?::(\d+|' . $this->urlre . '))? # $7: optional URL 
    13351364                                    (?:$|([\]}])|(?=' . $this->punct . '{1,2}|\s)) # $8: closing brace/bracket 
    1336                                    }mx', $this->_cb('$me->_repl($me->repl[0], $me->format_image(array("pre" => $m[1], "src" => $m[5], "align" => ($m[2] ? $m[2] : $m[4]), "extra" => $m[6], "url" => $m[7], "clsty" => $m[3], "post" => $m[8])))'), $text); 
     1365                                   }mx', 
     1366                                  function($m) use ($me) { 
     1367                                    return $me->_repl($me->repl[0], $me->format_image(array("pre" => $m[1], "src" => $m[5], "align" => ($m[2] ? $m[2] : $m[4]), "extra" => $m[6], "url" => $m[7], "clsty" => $m[3], "post" => $m[8]))); 
     1368                                  }, $text); 
    13371369 
    13381370    $text = preg_replace_callback('{(?:^|(?<=[\s>])|([{[]))     # $1: open brace/bracket 
     
    13461378                                    (?::(\d+|' . $this->urlre . '))? # $6: optional URL 
    13471379                                    (?:$|([]}])|(?=' . $this->punct . '{1,2}|\s)) # $7: closing brace/bracket 
    1348                                    }mx', $this->_cb('$me->_repl($me->repl[0], $me->format_span(array("pre" => $m[1], "text" => $m[5], "align" => ($m[2] ? $m[2] : $m[4]), "cite" => $m[6], "clsty" => $m[3], "post" => $m[7])))'), $text); 
     1380                                   }mx', 
     1381                                  function($m) use ($me) { 
     1382                                    return $me->_repl($me->repl[0], $me->format_span(array("pre" => $m[1], "text" => $m[5], "align" => ($m[2] ? $m[2] : $m[4]), "cite" => $m[6], "clsty" => $m[3], "post" => $m[7]))); 
     1383                                  }, $text); 
    13491384 
    13501385    $text = $this->encode_html($text); 
     
    13781413                                    [\]}] 
    13791414                                   ) 
    1380                                    }mx', $this->_cb('$me->_repl($me->repl[0], $me->format_link(array("text" => $m[1], "linktext" => $m[3] . $m[6], "title" => $me->encode_html_basic($m[4] . $m[7]), "url" => $m[8], "clsty" => $m[2] . $m[5])))'), $text); 
     1415                                   }mx', 
     1416                                  function($m) use ($me) { 
     1417                                    return $me->_repl($me->repl[0], $me->format_link(array("text" => $m[1], "linktext" => $m[3] . $m[6], "title" => $me->encode_html_basic($m[4] . $m[7]), "url" => $m[8], "clsty" => $m[2] . $m[5]))); 
     1418                                  }, $text); 
    13811419 
    13821420    $text = preg_replace_callback('{((?:^|(?<=[\s>\(]))                              # $1: open brace/bracket 
     
    13971435                                    :(\d+|' . $this->urlre . ')                      # $8: URL suffix 
    13981436                                    (?:$|(?=' . $this->punct . '{1,2}|\s)))          # $9: closing brace/bracket 
    1399                                    }mx', $this->_cb('$me->_repl($me->repl[0], $me->format_link(array("text" => $m[1], "linktext" => $m[3] . $m[6], "title" => $me->encode_html_basic($m[4] . $m[7]), "url" => $m[8], "clsty" => $m[2] . $m[5])))'), $text); 
     1437                                   }mx', 
     1438                                  function($m) use ($me) { 
     1439                                    return $me->_repl($me->repl[0], $me->format_link(array("text" => $m[1], "linktext" => $m[3] . $m[6], "title" => $me->encode_html_basic($m[4] . $m[7]), "url" => $m[8], "clsty" => $m[2] . $m[5]))); 
     1440                                  }, $text); 
    14001441 
    14011442    if (preg_match('/^xhtml2/', $this->flavor())) { 
     
    14071448                                      :(\d+|' . $this->urlre . ')                    # $3: optional citation URL 
    14081449                                      (?:$|([\]}])|(?=' . $this->punct . '{1,2}|\s)) # $4: closing brace/bracket 
    1409                                      }mx', $this->_cb('$me->_repl($me->repl[0], $me->format_cite(array("pre" => $m[1], "text" => $m[2], "cite" => $m[3], "post" => $m[4])))'), $text); 
     1450                                     }mx', 
     1451                                    function($m) use ($me) { 
     1452                                      return $me->_repl($me->repl[0], $me->format_cite(array("pre" => $m[1], "text" => $m[2], "cite" => $m[3], "post" => $m[4]))); 
     1453                                    }, $text); 
    14101454    } 
    14111455 
     
    14201464    // translate macros: 
    14211465    $text = preg_replace_callback('{(\{)(.+?)(\})}x', 
    1422                                   $this->_cb('$me->format_macro(array("pre" => $m[1], "post" => $m[3], "macro" => $m[2]))'), $text); 
     1466                                  function($m) use ($me) { 
     1467                                    return $me->format_macro(array("pre" => $m[1], "post" => $m[3], "macro" => $m[2])); 
     1468                                  }, $text); 
    14231469 
    14241470    // these were present with textile 1 and are common enough 
     
    14501496                                                      (?<=\S)' . $qf . '                             # 
    14511497                                                      (?:$|([\]}])|(?=' . $this->punct . '{1,2}|\s)) # $4 - post 
    1452                                                      }mx', $this->_cb('$me->format_tag(array("tag" => end($me->tmp["r"]), "marker" => end($me->tmp["f"]), "pre" => $m[1], "text" => $m[3], "clsty" => $m[2], "post" => $m[4]))'), $text))) { 
     1498                                                     }mx', 
     1499                                                    function($m) use ($me) { 
     1500                                                      return $me->format_tag(array("tag" => end($me->tmp["r"]), "marker" => end($me->tmp["f"]), "pre" => $m[1], "text" => $m[3], "clsty" => $m[2], "post" => $m[4])); 
     1501                                                    }, $text))) { 
    14531502          $redo = ($redo || ($last != $text)); 
    14541503          $last = $text; 
     
    14631512    // ABC(Aye Bee Cee) -> acronym 
    14641513    $text = preg_replace_callback('{\b([A-Z][A-Za-z0-9]*?[A-Z0-9]+?)\b(?:[(]([^)]*)[)])}', 
    1465                                   $this->_cb('$me->_repl($me->repl[0],"<acronym title=\"" . $me->encode_html_basic($m[2]) . "\">$m[1]</acronym>")'), $text); 
     1514                                  function($m) use ($me) { 
     1515                                    return $me->_repl($me->repl[0],"<acronym title=\"" . $me->encode_html_basic($m[2]) . "\">$m[1]</acronym>"); 
     1516                                  }, $text); 
    14661517 
    14671518    // ABC -> 'capped' span 
     
    14701521                                      ((?:[A-Z](?:[A-Z0-9\.,\']|\&amp;){2,}\ *)+?) # \' 
    14711522                                      (?=[^A-Z\.0-9]|$) 
    1472                                      /mx', $this->_cb('$m[1] . $me->_repl($me->repl[0], "<span class=\"" . end($me->tmp["caps"]) . "\">$m[2]</span>")'), $text); 
     1523                                     /mx', 
     1524                                    function($m) use ($me) { 
     1525                                      return $m[1] . $me->_repl($me->repl[0], "<span class=\"" . end($me->tmp["caps"]) . "\">$m[2]</span>"); 
     1526                                    }, $text); 
    14731527    } 
    14741528    array_pop($this->tmp['caps']); 
     
    21022156    $url = preg_replace('/&(?!amp;)/', '&amp;', $url); 
    21032157    $url = preg_replace('/\ /', '+', $url); 
    2104     $url = preg_replace_callback('/^((?:.+?)\?)(.+)$/', $this->_cb('$m[1] . $me->encode_url($m[2])'), $url); 
     2158    $me =& $this; 
     2159    $url = preg_replace_callback('/^((?:.+?)\?)(.+)$/', 
     2160                                 function($m) use ($me) { 
     2161                                   return $m[1] . $me->encode_url($m[2]); 
     2162                                 }, $url); 
    21052163    return $url; 
    21062164  } // function format_url 
     
    26292687   */ 
    26302688  function apply_filters($args) { 
     2689    log_error("Filters are not supported in infoarena's fork of Textile.php " . 
     2690              "because they use old-style anonymous functions."); 
    26312691    $text = $args['text']; 
    26322692    if (!$text) { return ''; } 
     
    26392699      if (!isset($filters[$filter])) { continue; } 
    26402700      if (is_string($filters[$filter])) { 
    2641         $text = (($f = create_function_cached('$text, $param', $filters[$filter])) ? $f($text, $param) : $text); 
     2701        $text = (($f = create_function('$text, $param', $filters[$filter])) ? $f($text, $param) : $text); 
    26422702      } 
    26432703    } 
     
    27692829   */ 
    27702830  function encode_url($str) { 
     2831    $me =& $this; 
    27712832    $str = preg_replace_callback('!([^A-Za-z0-9_\.\-\+\&=%;])!x', 
    2772                             $this->_cb('ord($m[1]) > 255 ? \'%u\' . sprintf("%04X", ord($m[1])) 
    2773                                                        : \'%\'  . sprintf("%02X", ord($m[1]))'), $str); 
     2833                                 function($m) use ($me) { 
     2834                                   return ord($m[1]) > 255 ? '%u' . sprintf("%04X", ord($m[1])) : '%'  . sprintf("%02X", ord($m[1])); 
     2835                                 }, $str); 
    27742836    return $str; 
    27752837  } // function encode_url 
     
    27862848  function mail_encode($addr) { 
    27872849    // granted, this is simple, but it gives off warm fuzzies 
     2850    $me =& $this; 
    27882851    $addr = preg_replace_callback('!([^\$])!x', 
    2789                              $this->_cb('ord($m[1]) > 255 ? \'%u\' . sprintf("%04X", ord($m[1])) 
    2790                                                         : \'%\'  . sprintf("%02X", ord($m[1]))'), $addr); 
     2852                                  function($m) use ($me) { 
     2853                                    return ord($m[1]) > 255 ? '%u' . sprintf("%04X", ord($m[1])) : '%'  . sprintf("%02X", ord($m[1])); 
     2854                                  }, $addr); 
    27912855    return $addr; 
    27922856  } // function mail_encode 
     
    32413305    return array("text" => "2.0.8", "build" => 2005032100); 
    32423306  } // function version 
    3243  
    3244 /** 
    3245    * Creates a custom callback function from the provided PHP 
    3246    * code. The result is used as the callback in 
    3247    * @c preg_replace_callback calls. *JHR* 
    3248    * 
    3249    * @param $function A @c string specifying the PHP code for the 
    3250    *        function body. 
    3251    * 
    3252    * @return A @c function to be used for the callback. 
    3253    * 
    3254    * @private 
    3255    */ 
    3256   function _cb($function) { 
    3257     $current =& Textile::_current_store($this); 
    3258     return create_function_cached('$m', 
    3259             '$me =& Textile::_current(); return '.$function .';'); 
    3260   } // function _cb 
    3261  
    3262   /** 
    3263    * Stores a static variable for the Textile class. This helper 
    3264    * function is used by @c _current to simulate a static 
    3265    * class variable in PHP. *JHR* 
    3266    * 
    3267    * @param $new If a non-@c NULL object reference, the Textile object 
    3268    *        to be set as the current object. 
    3269    * 
    3270    * @return The @c array containing a reference to the current 
    3271    *         Textile object at index 0. An array is used because PHP 
    3272    *         does not allow static variables to be references. 
    3273    * 
    3274    * @static 
    3275    * @private 
    3276    */ 
    3277  /* static */ function &_current_store(&$new) { 
    3278    static $current = array(); 
    3279  
    3280    if ($new != NULL) { 
    3281      $current = array(&$new); 
    3282    } 
    3283  
    3284    return $current; 
    3285  } // function _current_store 
    3286  
    3287   /** 
    3288    * Returns the "current" Textile object. This is used within 
    3289    * anonymous callback functions which cannot have the scope of a 
    3290    * specific object. *JHR* 
    3291    * 
    3292    * @return An @c object reference to the current Textile object. 
    3293    * 
    3294    * @static 
    3295    * @private 
    3296    */ 
    3297  /* static */ function &_current() { 
    3298    $current =& Textile::_current_store($null = NULL); 
    3299    return $current[0]; 
    3300  } // function _current 
    33013307} // class Textile 
    33023308 
     
    34643470 * A pre-formatted block of text. Textile will not add any 
    34653471 * HTML tags for individual lines. Whitespace is also preserved. 
    3466  *  
     3472 * 
    34673473 * Note that within a "pre" block, \< and \> are 
    34683474 * translated into HTML entities automatically.</li> 
     
    34743480 * gets a \<code\> tag (or for XHTML 2, a \<blockcode\> 
    34753481 * tag is used instead). 
    3476  *  
     3482 * 
    34773483 * Note that within a "bc" block, \< and \> are 
    34783484 * translated into HTML entities automatically.</li> 
Note: See TracChangeset for help on using the changeset viewer.