当前位置: 首页>>代码示例>>PHP>>正文


PHP Safe::set_time_limit方法代码示例

本文整理汇总了PHP中Safe::set_time_limit方法的典型用法代码示例。如果您正苦于以下问题:PHP Safe::set_time_limit方法的具体用法?PHP Safe::set_time_limit怎么用?PHP Safe::set_time_limit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Safe的用法示例。


在下文中一共展示了Safe::set_time_limit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: debug

 /**
  * remember a string during software debug
  *
  * This script appends information to temporary/debug.txt
  *
  * @param mixed something to be printed
  * @param string an optional label string
  * @return void
  */
 public static function debug($value = '', $label = NULL)
 {
     global $context;
     // ensure we have a string --preserve native string
     $value = Logger::to_string($value, FALSE);
     // stamp the line
     $line = gmdate('Y-m-d H:i:s') . "\t";
     if (isset($label)) {
         $line .= $label . ' ';
     }
     $line .= $value;
     $line .= "\n";
     // ensure enough execution time
     Safe::set_time_limit(30);
     // apend to the debug file
     if ($handle = Safe::fopen($context['path_to_root'] . 'temporary/debug.txt', 'a')) {
         fwrite($handle, $line);
         fclose($handle);
     } else {
         echo $line;
     }
 }
开发者ID:rair,项目名称:yacs,代码行数:31,代码来源:logger.php

示例2: send_body

/**
 * dynamically generate the page
 *
 * @see skins/index.php
 */
function send_body()
{
    global $context;
    // only associates can proceed
    if (!Surfer::is_associate()) {
        Safe::header('Status: 401 Unauthorized', TRUE, 401);
        echo '<p>' . i18n::s('You are not allowed to perform this operation.') . "</p>\n";
        // forward to the index page
        $menu = array('scripts/' => i18n::s('Server software'));
        echo Skin::build_list($menu, 'menu_bar');
        // ask for confirmation
    } elseif (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'GET') {
        // the splash message
        echo '<p>' . i18n::s('This tool will include most of the running reference PHP scripts. Any syntax error should be spotted easily.') . '</p>';
        // the submit button
        echo '<form method="post" action="' . $context['script_url'] . '" id="main_form"><p>' . Skin::build_submit_button(i18n::s('Yes, I want to validate scripts'), NULL, NULL, 'confirmed') . '</p></form>';
        // set the focus on the button
        Page::insert_script('$("#confirmed").focus();');
        // this may take some time
        echo '<p>' . i18n::s('When you will click on the button the server will be immediately requested to proceed. However, because of the so many things to do on the back-end, you may have to wait for minutes before getting a response displayed. Thank you for your patience.') . '</p>';
        // just do it
    } else {
        // the splash message
        echo '<p>' . i18n::s('All reference scripts are included, to show evidence of possible syntax errors.') . "</p>\n";
        // list running scripts
        echo '<p>' . i18n::s('Listing files...') . BR . "\n";
        // locate script files starting at root
        $scripts = Scripts::list_scripts_at(NULL);
        if (is_array($scripts) && count($scripts)) {
            echo BR . sprintf(i18n::s('%d scripts have been found.'), count($scripts)) . "\n";
            natsort($scripts);
        }
        echo "</p>\n";
        // including scripts
        echo '<p>' . i18n::s('Including reference scripts...') . BR . "\n";
        // strip as much output as possible
        $_SERVER['REQUEST_METHOD'] = 'HEAD';
        // we will finalize this page later on
        global $finalizing_fuse;
        $finalizing_fuse = FALSE;
        // take care of dependancies
        include_once '../behaviors/behavior.php';
        include_once '../services/codec.php';
        include_once '../users/authenticator.php';
        // analyse each script
        $included_files = 0;
        $links_to_be_checked_manually = array();
        foreach ($scripts as $file) {
            // ensure we have enough time to process this script
            Safe::set_time_limit(30);
            // skip run once scripts
            if (strpos($file, 'run_once/')) {
                continue;
            }
            // don't include ourself
            if ($file == 'scripts/validate.php') {
                continue;
            }
            // process only reference scripts
            if (!Scripts::hash($file)) {
                continue;
            }
            // check file content
            if (!($handle = Safe::fopen($file, 'rb'))) {
                echo sprintf(i18n::s('%s has no readable content.'), $file) . BR . "\n";
                continue;
            }
            // look at the beginning of the file
            if (!($header = fread($handle, 16384))) {
                echo sprintf(i18n::s('%s has no readable content.'), $file) . BR . "\n";
                fclose($handle);
                continue;
            }
            fclose($handle);
            // skip scripts that generate content asynchronously
            if (stripos($header, 'send_body') || stripos($header, 'page::content')) {
                $links_to_be_checked_manually[$file] = '(asynchronous)';
                continue;
            }
            // skip scripts that would redefine our skin
            if (stripos($header, 'extends skin_skeleton')) {
                $links_to_be_checked_manually[$file] = '(skin)';
                continue;
            }
            // log script inclusion on development host
            if ($context['with_debug'] == 'Y') {
                logger::remember('scripts/validate.php: inclusion of ' . $file, '', 'debug');
            }
            // include the script and display any error
            $included_files += 1;
            $validate_stamp = time();
            echo sprintf(i18n::s('inclusion of %s'), $file) . "\n";
            Safe::chdir($context['path_to_root'] . dirname($file));
            include_once $context['path_to_root'] . $file;
            $duration = time() - $validate_stamp;
//.........这里部分代码省略.........
开发者ID:rair,项目名称:yacs,代码行数:101,代码来源:validate.php

示例3: include_hook

function include_hook($path)
{
    global $context, $hooks;
    // animate user screen and take care of time
    global $scanned_directories;
    $scanned_directories++;
    // ensure enough execution time
    Safe::set_time_limit(30);
    // open the directory
    if (!($dir = Safe::opendir($path))) {
        $context['text'] .= sprintf(i18n::s('Impossible to read %s.'), $path) . BR . "\n";
        return;
    }
    // browse the directory
    while (($item = Safe::readdir($dir)) !== FALSE) {
        // skip some files
        if ($item[0] == '.') {
            continue;
        }
        // load any 'hook.php', or any file which names ends with 'hook.php'
        $actual_item = str_replace('//', '/', $path . '/' . $item);
        if (preg_match('/hook\\.php$/i', $item)) {
            include_once $actual_item;
            $context['text'] .= sprintf(i18n::s('Hook %s has been included'), $actual_item) . BR . "\n";
            // scan any sub dir except at server root
        } elseif (is_dir($actual_item) && $path != $context['path_to_root'] && !strpos($path, '/files/') && !strpos($path, '/images/')) {
            include_hook($actual_item);
        }
    }
    // close the directory
    Safe::closedir($dir);
}
开发者ID:rair,项目名称:yacs,代码行数:32,代码来源:scan.php

示例4: process_queue

 /**
  * process all messages from one mailbox
  *
  * This is original code compliant to RFC 1939 for the authentication,
  * fetching and processing of messages queued in a POP3 mailbox.
  *
  * @param array of mailbox attributes ($server, $account, $password)
  * @return the number of processed messages
  */
 public static function process_queue($queue)
 {
     global $context;
     // useless if we don't have a valid database connection
     if (!$context['connection']) {
         return 0;
     }
     // make queue parameters available
     $context['mail_queue'] = $queue;
     // use queue parameters to connect to the server
     list($server, $account, $password, $allowed, $match, $section, $options, $hooks, $prefix, $suffix) = $queue;
     // no host, assume it's us
     if (!$server) {
         $server = $context['host_name'];
     }
     // assume the standard pop3 socket
     $port = 110;
     // use alternate port if required to do so
     if (preg_match('/^(.+):([0-9]+)$/', $server, $matches)) {
         $server = $matches[1];
         $port = intval($matches[2]);
     }
     // ensure that we can support tls communications
     if (isset($server) && !strncmp($server, 'ssl://', 6) && is_callable('extension_loaded') && !extension_loaded('openssl')) {
         Logger::remember('agents/messages.php: Load the OpenSSL extension to support secured transmissions to mail server ' . $server);
         return 0;
     }
     // open a network connection
     if (!($handle = Safe::fsockopen($server, $port, $errno, $errstr, 10))) {
         Logger::remember('agents/messages.php: ' . sprintf('Impossible to connect to %s', $server));
         return 0;
     }
     // ensure enough execution time
     Safe::set_time_limit(30);
     // get server banner
     if (($reply = fgets($handle)) === FALSE) {
         Logger::remember('agents/messages.php: Impossible to get banner of ' . $server);
         fclose($handle);
         return 0;
     }
     if ($context['debug_messages'] == 'Y') {
         Logger::remember('agents/messages.php: POP <-', rtrim($reply), 'debug');
     }
     // expecting an OK
     if (strncmp($reply, '+OK', 3)) {
         Logger::remember('agents/messages.php: Mail service is closed at ' . $server, rtrim($reply));
         fclose($handle);
         return 0;
     }
     // maybe the server accepts APOP
     $stamp = '';
     if (preg_match('/<.+@.+>/U', $reply, $matches)) {
         $stamp = $matches[0];
     }
     // we will go with APOP, only if explicitly allowed
     $authenticated = FALSE;
     if ($stamp && preg_match('/\\bwith_apop\\b/i', $options)) {
         // the digest
         if ($context['debug_messages'] == 'Y') {
             Logger::remember('agents/messages.php: POP stamp', $stamp . $password, 'debug');
         }
         $hash = md5($stamp . $password);
         // send user name and hash
         $request = 'APOP ' . $account . ' ' . $hash;
         fputs($handle, $request . CRLF);
         if ($context['debug_messages'] == 'Y') {
             Logger::remember('agents/messages.php: POP ->', $request, 'debug');
         }
         // expecting an OK
         if (($reply = fgets($handle)) === FALSE) {
             Logger::remember('agents/messages.php: No reply to APOP command at ' . $server);
             fclose($handle);
             return 0;
         }
         if ($context['debug_messages'] == 'Y') {
             Logger::remember('agents/messages.php: POP <-', rtrim($reply), 'debug');
         }
         if (strncmp($reply, '+OK', 3)) {
             Logger::remember('agents/messages.php: Impossible to authenticate account ' . $account . ' at ' . $server, rtrim($reply));
         } else {
             $authenticated = TRUE;
         }
     }
     // we will transmit the password in clear
     if (!$authenticated) {
         // send user name
         $request = 'USER ' . $account;
         fputs($handle, $request . CRLF);
         if ($context['debug_messages'] == 'Y') {
             Logger::remember('agents/messages.php: POP ->', $request, 'debug');
         }
//.........这里部分代码省略.........
开发者ID:rair,项目名称:yacs,代码行数:101,代码来源:messages.php

示例5: render_smileys

 /**
  * transform some text to load related images
  *
  * @param string the input text
  * @return the tansformed text
  */
 public static function render_smileys($text)
 {
     global $context;
     // no content on HEAD request --see scripts/validate.php
     if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'HEAD') {
         return $text;
     }
     // sanity check
     $text = trim($text);
     if (!$text) {
         return $text;
     }
     // the list of codes to be interpreted --initialize only once
     static $pattern, $replace;
     if (!isset($pattern)) {
         $pattern = array();
         $replace = array();
         $prefix = ' <img src="' . $context['url_to_root'] . 'skins/_reference/smileys/';
         $suffix = '" alt="" /> ';
         $pattern[] = '>:(';
         $replace[] = $prefix . 'angry.gif' . $suffix;
         $pattern[] = ':-D';
         $replace[] = $prefix . 'cheesy.gif' . $suffix;
         $pattern[] = " :'(";
         $replace[] = $prefix . 'cry.gif' . $suffix;
         $pattern[] = ":'-(";
         $replace[] = $prefix . 'cry.gif' . $suffix;
         $pattern[] = '8-)';
         $replace[] = $prefix . 'cool.gif' . $suffix;
         $pattern[] = ':-(';
         $replace[] = $prefix . 'frown.gif' . $suffix;
         $pattern[] = '???';
         $replace[] = $prefix . 'confused.gif' . $suffix;
         $pattern[] = ':-[';
         $replace[] = $prefix . 'embarassed.gif' . $suffix;
         $pattern[] = ':blush:';
         $replace[] = $prefix . 'blushing.gif' . $suffix;
         $pattern[] = ':-X';
         $replace[] = $prefix . 'sealed.gif' . $suffix;
         $pattern[] = ':-P';
         $replace[] = $prefix . 'tongue.gif' . $suffix;
         $pattern[] = ':medal:';
         $replace[] = $prefix . 'medal_full.gif' . $suffix;
         $pattern[] = ':half_medal:';
         $replace[] = $prefix . 'medal_half.gif' . $suffix;
         $pattern[] = '::-)';
         $replace[] = $prefix . 'rolleyes.gif' . $suffix;
         $pattern[] = ' :)';
         $replace[] = $prefix . 'smile.gif' . $suffix;
         $pattern[] = ':-)';
         $replace[] = $prefix . 'smile.gif' . $suffix;
         $pattern[] = ':-o';
         $replace[] = $prefix . 'shocked.gif' . $suffix;
         $pattern[] = ' :/';
         $replace[] = $prefix . 'undecided.gif' . $suffix;
         $pattern[] = ':-/';
         $replace[] = $prefix . 'undecided.gif' . $suffix;
         $pattern[] = ' ;)';
         $replace[] = $prefix . 'winkgrin.gif' . $suffix;
         $pattern[] = ';-)';
         $replace[] = $prefix . 'winkgrin.gif' . $suffix;
         $pattern[] = ':party:';
         $replace[] = $prefix . 'partygirl.gif' . $suffix;
         $pattern[] = ':*:';
         $replace[] = $prefix . 'star.gif' . $suffix;
         $pattern[] = ' :*';
         $replace[] = $prefix . 'kiss.gif' . $suffix;
         $pattern[] = ':-*';
         $replace[] = $prefix . 'kiss.gif' . $suffix;
         $pattern[] = ' :+';
         $replace[] = $prefix . 'thumbsup.gif' . $suffix;
         $pattern[] = ':up:';
         $replace[] = $prefix . 'thumbsup.gif' . $suffix;
         $pattern[] = ' :-';
         $replace[] = $prefix . 'thumbsdown.gif' . $suffix;
         $pattern[] = ':down:';
         $replace[] = $prefix . 'thumbsdown.gif' . $suffix;
         $pattern[] = ':?!';
         $replace[] = $prefix . 'idea.gif' . $suffix;
         $pattern[] = ' :?2';
         $replace[] = $prefix . 'question2.gif' . $suffix;
         $pattern[] = ' :?';
         $replace[] = $prefix . 'question.gif' . $suffix;
         $pattern[] = ' :!2';
         $replace[] = $prefix . 'exclamation2.gif' . $suffix;
         $pattern[] = ' :!';
         $replace[] = $prefix . 'exclamation.gif' . $suffix;
     }
     // ensure we have enough processing time
     Safe::set_time_limit(30);
     // process dotted smileys --insert a space for smileys at the very beginning of the string
     $text = str_replace($pattern, $replace, ' ' . $text);
     // process any image file
     $text = preg_replace_callback('/:([\\w_]+):/', array('smileys', 'parse_match'), $text);
//.........这里部分代码省略.........
开发者ID:rair,项目名称:yacs,代码行数:101,代码来源:smileys.php

示例6: while

 $context['text'] .= Skin::build_block(sprintf(i18n::s('Analyzing table %s...'), SQL::table_name('comments')), 'title');
 // scan up to 20000 items
 $count = 0;
 $query = "SELECT id, anchor FROM " . SQL::table_name('comments') . " ORDER BY anchor LIMIT 0, 100000";
 if (!($result = SQL::query($query))) {
     return;
 } else {
     // fetch one anchor and the linked member
     $errors_count = 0;
     while ($row = SQL::fetch($result)) {
         // animate user screen and take care of time
         $count++;
         if (!($count % 500)) {
             $context['text'] .= sprintf(i18n::s('%d records have been processed'), $count) . BR . "\n";
             // ensure enough execution time
             Safe::set_time_limit(30);
         }
         // check that the anchor exists, if any
         if ($row['anchor'] && !Anchors::get($row['anchor'])) {
             $context['text'] .= sprintf(i18n::s('Orphan: %s'), 'comment ' . Skin::build_link(Comments::get_url($row['id']), $row['id'])) . BR . "\n";
             if (++$errors_count >= 5) {
                 $context['text'] .= i18n::s('Too many successive errors. Aborted') . BR . "\n";
                 break;
             }
         } else {
             $errors_count = 0;
         }
     }
 }
 // ending message
 $context['text'] .= sprintf(i18n::s('%d records have been processed'), $count) . BR . "\n";
开发者ID:rair,项目名称:yacs,代码行数:31,代码来源:check.php

示例7: validate

 /**
  * validate a link
  *
  * This function submits a HTTP request to the target server to check that the page actually exists
  *
  * @param the link to validate
  * @return A date if Last-Modified has been provided, or TRUE if the link is reachable, FALSE otherwise
  */
 function validate($url)
 {
     global $context;
     // parse this url
     $items = @parse_url($url);
     // assume the link is correct if not http
     if ($items['scheme'] && $items['scheme'] != 'http') {
         return TRUE;
     }
     // no host, assume it's us
     if (!($host = $items['host'])) {
         $host = $context['host_name'];
     }
     // sometime parse_url() adds a '_'
     $host = rtrim($host, '_');
     // no port, assume the standard
     if (!($port = $items['port'])) {
         $port = 80;
     }
     // assume the link is correct when outbound web is not authorized
     if (isset($context['without_outbound_http']) && $context['without_outbound_http'] == 'Y') {
         return TRUE;
     }
     // open a network connection -- wait for up to 10 seconds for the TCP connection
     if (!($handle = Safe::fsockopen($host, $port, $errno, $errstr, 10))) {
         if ($context['with_debug'] == 'Y') {
             logger::remember('links/link.php: ' . $host . ':' . $port . ' is not reachable', $url, 'debug');
         }
         return FALSE;
     }
     // ensure enough execution time
     Safe::set_time_limit(30);
     // build the path
     $path = $items['path'];
     if (!$path) {
         $path = '/';
     }
     // sometime parse_url() adds a '_'
     $path = rtrim($path, '_');
     // include any query
     if ($items['query']) {
         $path .= '?' . $items['query'];
     }
     // send an HTTP request
     fputs($handle, 'HEAD ' . $path . " HTTP/1.0" . CRLF . 'Host: ' . $host . CRLF . "User-Agent: YACS (www.yacs.fr)" . CRLF . "Connection: close" . CRLF . CRLF);
     // we are interested into the header only
     $response = '';
     while (!feof($handle) && strlen($response) < 5242880) {
         // ask for Ethernet-sized chunks
         $chunk = fread($handle, 1500);
         // split on headers boundary
         $here = strpos($chunk, CRLF . CRLF);
         if ($here !== FALSE) {
             $chunk = substr($chunk, 0, $here);
             $response .= $chunk;
             break;
         }
         // gather header information
         $response .= $chunk;
     }
     fclose($handle);
     // split headers into lines
     $lines = explode(CRLF, $response);
     // ensure we have a valid HTTP status line
     if (!preg_match('/^HTTP\\/[0-9\\.]+ 20\\d /', $lines[0])) {
         if ($context['with_debug'] == 'Y') {
             logger::remember('links/link.php: bad status: ' . $lines[0], $url, 'debug');
         }
         return FALSE;
     }
     // scan lines for "Last-Modified" header
     foreach ($lines as $line) {
         if (preg_match('/^Last-Modified: (.*?)/', $line, $matches)) {
             // return the stamp for this link
             return date("Y-m-d H:i:s", strtotime($matches[1]));
         }
     }
     // no date, but the link has been validated anyway
     return TRUE;
 }
开发者ID:rair,项目名称:yacs,代码行数:88,代码来源:link.php

示例8: while

 /**
  * transcode multi-byte characters to HTML representations for Unicode
  *
  * This function is aiming to preserve Unicode characters through storage in a ISO-8859-1 compliant system.
  *
  * Every multi-byte UTF-8 character is transformed to its equivalent HTML numerical entity (eg, &amp;#4568;)
  * that may be handled safely by PHP and by MySQL.
  *
  * Of course, this solution does not allow for full-text search in the database and therefore, is not a
  * definitive solution to internationalization issues.
  * It does enable, however, practical use of Unicode to build pages in foreign languages.
  *
  * Also, this function transforms HTML entities into their equivalent Unicode entities.
  * For example, w.bloggar posts pages using HTML entities.
  * If you have to modify these pages using web forms, you would like to get UTF-8 instead.
  *
  * @link http://www.evolt.org/article/A_Simple_Character_Entity_Chart/17/21234/ A Simple Character Entity Chart
  *
  * @param mixed the original UTF-8 string, or an array
  * @return a string acceptable in an ISO-8859-1 storage system (ie., PHP4 + MySQL 3)
  */
 public static function &to_unicode($input)
 {
     global $context;
     // transcode arrays as well
     if (is_array($input)) {
         utf8::to_unicode_recursively($input);
         $output = $input;
         return $output;
     }
     // scan the whole string
     $output = '';
     $index = 0;
     $tick = 0;
     while ($index < strlen($input)) {
         // for jumbo pages --observed 167 seconds processing time for 414kbyte input
         $tick++;
         if (!($tick % 25000)) {
             Safe::set_time_limit(30);
         }
         // look at one char
         $char = ord($input[$index]);
         // one byte (0xxxxxxx)
         if ($char < 0x80) {
             // some chars may be undefined
             $output .= chr($char);
             $index += 1;
             // two bytes (110xxxxx 10xxxxxx)
         } elseif ($char < 0xe0) {
             // strip weird sequences (eg, C0 80 -> NUL)
             if ($value = $char % 0x20 * 0x40 + ord($input[$index + 1]) % 0x40) {
                 $output .= '&#' . $value . ';';
             }
             $index += 2;
             // three bytes (1110xxxx 10xxxxxx 10xxxxxx) example: euro sign = \xE2\x82\xAC -> &#8364;
         } elseif ($char < 0xf0) {
             // strip weird sequences
             if ($value = $char % 0x10 * 0x1000 + ord($input[$index + 1]) % 0x40 * 0x40 + ord($input[$index + 2]) % 0x40) {
                 $output .= '&#' . $value . ';';
             }
             $index += 3;
             // four bytes (11110xxx 10xxxxxx 10xxxxxx 10xxxxxx)
         } elseif ($char < 0xf8) {
             // strip weird sequences
             if ($value = $char % 0x8 * 0x40000 + ord($input[$index + 1]) % 0x40 * 0x1000 + ord($input[$index + 2]) % 0x40 * 0x40 + ord($input[$index + 3]) % 0x40) {
                 $output .= '&#' . $value . ';';
             }
             $index += 4;
             // five bytes (111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx)
         } elseif ($char < 0xfc) {
             // strip weird sequences
             if ($value = $char % 0x4 * 0x1000000 + ord($input[$index + 1]) % 0x40 * 0x40000 + ord($input[$index + 2]) % 0x40 * 0x1000 + ord($input[$index + 3]) % 0x40 * 0x40 + ord($input[$index + 4]) % 0x40) {
                 $output .= '&#' . $value . ';';
             }
             $index += 5;
             // six bytes (1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx)
         } else {
             // strip weird sequences
             if ($value = $char % 0x2 * 0x40000000 + ord($input[$index + 1]) % 0x40 * 0x1000000 + ord($input[$index + 2]) % 0x40 * 0x40000 + ord($input[$index + 3]) % 0x40 * 0x1000 + ord($input[$index + 4]) % 0x40 * 0x40 + ord($input[$index + 4]) % 0x40) {
                 $output .= '&#' . $value . ';';
             }
             $index += 6;
         }
     }
     // transcode explicit unicode entities %u2019 -> &#8217;
     $output = preg_replace_callback('/%u([0-9a-z]{4})/is', function ($matches) {
         return '&#' . hexdec($matches[1]);
     }, $output);
     // transcode HTML entities to Unicode entities
     $output =& utf8::transcode($output);
     // translate extended ISO8859-1 chars, if any, to utf-8
     $output = utf8_encode($output);
     // return the translated string
     return $output;
 }
开发者ID:rair,项目名称:yacs,代码行数:95,代码来源:utf8.php

示例9: parse

 /**
  * parse one script to build the php documentation
  *
  * @param string one script
  * @param the path to access the script
  * @return either NULL or an error message
  */
 function parse($script, $path = 'scripts/reference/')
 {
     global $context, $page_count;
     // at least put the script name as a title
     $this->titles[$script] = $script;
     // read the file
     if (!($handle = Safe::fopen($path . $script, 'rb'))) {
         $this->comments[$script] = sprintf(i18n::s('Impossible to read %s.'), $script);
         return sprintf(i18n::s('Impossible to read %s.'), $context['path_to_root'] . $path . $script);
     }
     // locate php comments
     $comment = array();
     global $first_comment;
     $first_comment = TRUE;
     $in_comment = FALSE;
     $count = 0;
     while (!feof($handle)) {
         // up to 4k per line
         $line = fgets($handle, 4096);
         // ensure we have enough execution time
         $count++;
         if (!($count % 1000)) {
             Safe::set_time_limit(30);
         }
         // a comment ends
         if ($in_comment && preg_match('/\\s*\\*+\\//', $line)) {
             $in_comment = FALSE;
             // a comment continues
         } elseif ($in_comment) {
             // strip the '*' at the beginning of the line
             $comment[] = preg_replace('/^\\s*\\*\\s{0,1}/', '', $line);
             // comment begins
         } elseif (preg_match('/\\s*\\/\\*{2,}/', $line)) {
             $in_comment = TRUE;
             // class extension
         } elseif (preg_match('/^\\s*class\\s+(\\w+)\\s+extends\\s+(\\w+)/i', $line, $matches)) {
             $name = $matches[0];
             $this->comment_block($script, $name, $comment);
             $comment = array();
             // class definition
         } elseif (preg_match('/^\\s*class\\s+(\\w+)/i', $line, $matches)) {
             $name = $matches[0];
             $this->comment_block($script, $name, isset($comment) ? $comment : '');
             $comment = array();
             // function definition
         } elseif (preg_match('/^\\s*function\\s+(&{0,1}\\w+)\\s*\\((.*)\\)/i', $line, $matches)) {
             $name = $matches[0];
             $this->comment_block($script, $name, isset($comment) ? $comment : '');
             $comment = array();
             // only a comment
         } elseif (preg_match('/^\\s*\\/\\//', $line)) {
             // a blank line
         } elseif (preg_match('/^\\s*$/', $line)) {
             // not a declaration
         } elseif (@count($comment)) {
             $this->comment_block($script, '', $comment);
             $comment = array();
         }
     }
     // ensure enough execution time
     Safe::set_time_limit(30);
     // generate the documentation page for this file
     $fields['name'] = $script;
     $fields['anchor'] = dirname($script);
     $fields['label'] = isset($this->index[$script]) ? $this->index[$script] : '*** you should add a phpDoc label line to this file';
     $fields['content'] = isset($this->comments[$script]) ? "[toc]" . $this->comments[$script] : '*** you should expand phpDoc comments for this file';
     $query = "INSERT INTO " . SQL::table_name('phpdoc') . " SET " . " name='" . SQL::escape($fields['name']) . "'," . " anchor='" . SQL::escape($fields['anchor']) . "'," . " label='" . SQL::escape($fields['label']) . "'," . " content='" . SQL::escape($fields['content']) . "'," . " edit_date='" . gmstrftime('%Y-%m-%d %H:%M:%S') . "'";
     if (SQL::query($query, TRUE) === FALSE) {
         echo $query . BR . SQL::error() . BR . "\n";
     }
     $page_count++;
 }
开发者ID:rair,项目名称:yacs,代码行数:79,代码来源:phpdoc.php

示例10: _extractList


//.........这里部分代码省略.........
         } else {
             $v_extract_file = TRUE;
         }
         // ----- Look if this file need to be extracted
         if ($v_extract_file && !$v_listing) {
             if ($p_remove_path != '' && substr($v_header['filename'], 0, $p_remove_path_size) == $p_remove_path) {
                 $v_header['filename'] = substr($v_header['filename'], $p_remove_path_size);
             }
             if ($p_path != './' && $p_path != '/') {
                 while (substr($p_path, -1) == '/') {
                     $p_path = substr($p_path, 0, strlen($p_path) - 1);
                 }
                 if (substr($v_header['filename'], 0, 1) == '/') {
                     $v_header['filename'] = $p_path . $v_header['filename'];
                 } else {
                     $v_header['filename'] = $p_path . '/' . $v_header['filename'];
                 }
             }
             if (file_exists($v_header['filename'])) {
                 if (@is_dir($v_header['filename']) && $v_header['typeflag'] == '') {
                     $this->_error('File ' . $v_header['filename'] . ' already exists as a directory');
                     return false;
                 }
                 if ($this->_isArchive($v_header['filename']) && $v_header['typeflag'] == "5") {
                     $this->_error('Directory ' . $v_header['filename'] . ' already exists as a file');
                     return false;
                 }
                 if (!is_writeable($v_header['filename'])) {
                     $this->_error('File ' . $v_header['filename'] . ' already exists and is write protected');
                     return false;
                 }
                 if (filemtime($v_header['filename']) > $v_header['mtime']) {
                     // To be completed : An error or silent no replace ?
                 }
             } elseif (($v_result = $this->_dirCheck($v_header['typeflag'] == "5" ? $v_header['filename'] : dirname($v_header['filename']))) != 1) {
                 $this->_error('Unable to create path for ' . $v_header['filename']);
                 return false;
             }
             if ($v_extract_file) {
                 if ($v_header['typeflag'] == "5") {
                     if (!@file_exists($v_header['filename'])) {
                         global $context;
                         if (!@mkdir($v_header['filename'], $context['directory_mask'])) {
                             $this->_error('Unable to create directory {' . $v_header['filename'] . '}');
                             return false;
                         }
                     }
                 } else {
                     if (($v_dest_file = @fopen($v_header['filename'], "wb")) == 0) {
                         $this->_error('Error while opening {' . $v_header['filename'] . '} in write binary mode');
                         return false;
                     } else {
                         $n = floor($v_header['size'] / 512);
                         for ($i = 0; $i < $n; $i++) {
                             $v_content = $this->_readBlock();
                             fwrite($v_dest_file, $v_content, 512);
                         }
                         if ($v_header['size'] % 512 != 0) {
                             $v_content = $this->_readBlock();
                             fwrite($v_dest_file, $v_content, $v_header['size'] % 512);
                         }
                         @fclose($v_dest_file);
                         // ----- Change the file mode, mtime
                         @touch($v_header['filename'], $v_header['mtime']);
                         // To be completed
                         Safe::chmod($v_header['filename']);
                     }
                     // ----- Check the file size
                     clearstatcache();
                     if (filesize($v_header['filename']) != $v_header['size']) {
                         $this->_error('Extracted file ' . $v_header['filename'] . ' does not have the correct file size \'' . filesize($v_header['filename']) . '\' (' . $v_header['size'] . ' expected). Archive may be corrupted.');
                         return false;
                     }
                 }
             } else {
                 $this->_jumpBlock(ceil($v_header['size'] / 512));
             }
         } else {
             $this->_jumpBlock(ceil($v_header['size'] / 512));
         }
         /* TBC : Seems to be unused ...
         	  if ($this->_compress)
         		$v_end_of_file = @gzeof($this->_file);
         	  else
         		$v_end_of_file = @feof($this->_file);
         		*/
         if ($v_listing || $v_extract_file || $v_extraction_stopped) {
             // ----- Log extracted files
             if (($v_file_dir = dirname($v_header['filename'])) == $v_header['filename']) {
                 $v_file_dir = '';
             }
             if (substr($v_header['filename'], 0, 1) == '/' && $v_file_dir == '') {
                 $v_file_dir = '/';
             }
             $p_list_detail[$v_nb++] = $v_header;
         }
         Safe::set_time_limit(30);
     }
     return true;
 }
开发者ID:rair,项目名称:yacs,代码行数:101,代码来源:tar.php

示例11: tick_hook


//.........这里部分代码省略.........
  * This parameter has a default value of 50, meaning YACS will not send more
  * than 50 messages per hour.
  *
  * Background processing is either added to regular page generation or delegated
  * to an external sub-system (e.g., cron). In case of a large site, we recommend
  * to use the second solution, even if this adds additional setup steps. Your
  * choice will be recorded in the configuration panel for system parameters.
  *
  * @see control/configure.php
  *
  * The number of messages sent on each tick can go up to the bucket size if
  * background processing is external. Else it is one fourth of bucket size, to
  * minimize impact on watching surfer.
  *
  * @see cron.php
  */
 public static function tick_hook()
 {
     global $context;
     // email services have to be activated
     if (!isset($context['with_email']) || $context['with_email'] != 'Y') {
         return;
     }
     // useless if we don't have a valid database connection
     if (!$context['connection']) {
         return;
     }
     // remember start time
     $start = get_micro_time();
     // get bucket size --force it if set to 0
     if (!isset($context['mail_hourly_maximum']) || $context['mail_hourly_maximum'] < 5) {
         $context['mail_hourly_maximum'] = 50;
     }
     // get record related to last tick
     include_once $context['path_to_root'] . 'shared/values.php';
     $bucket = Values::get_record('mailer.bucket.content', 0);
     $bucket['value'] = intval($bucket['value']);
     // some content to leak
     if ($bucket['value'] > 0) {
         // date of last stamp
         if (isset($bucket['edit_date'])) {
             $stamp = SQL::strtotime($bucket['edit_date']);
         } else {
             $stamp = time() - 3600;
         }
         // leak is maximum after one hour
         $leak = intval($context['mail_hourly_maximum'] * (time() - $stamp) / 3600);
         // preserve previous value until actual leak
         if ($leak < 1) {
             return;
         }
         // actual leak
         $bucket['value'] = max(0, $bucket['value'] - $leak);
     }
     // process some messages only when bucket is empty
     $count = 0;
     if ($bucket['value'] < 1) {
         // reduced speed if on-line processing
         if (isset($_SERVER['REMOTE_ADDR'])) {
             $slice = intval($context['mail_hourly_maximum'] / 4);
         } else {
             $slice = intval($context['mail_hourly_maximum']);
         }
         // get some messages, if any
         $query = "SELECT * FROM " . SQL::table_name('messages') . " ORDER BY edit_date LIMIT 0, " . $slice;
         if ($result = SQL::query($query)) {
             // process every message
             while ($item = SQL::fetch($result)) {
                 Mailer::process($item['recipient'], $item['subject'], $item['message'], $item['headers']);
                 // purge the queue
                 $query = 'DELETE FROM ' . SQL::table_name('messages') . ' WHERE id = ' . $item['id'];
                 SQL::query($query);
                 // fill the bucket
                 $bucket['value'] += 1;
                 $count++;
                 // take care of time
                 if (!($count % 50)) {
                     // ensure enough execution time
                     Safe::set_time_limit(30);
                 }
             }
             // close connection
             Mailer::close();
         }
     }
     // remember new state of the bucket
     Values::set('mailer.bucket.content', $bucket['value']);
     // compute execution time
     $time = round(get_micro_time() - $start, 2);
     // report on work achieved
     if ($count > 1) {
         return 'shared/mailer.php: ' . $count . ' messages have been processed (' . $time . ' seconds)' . BR;
     } elseif ($count == 1) {
         return 'shared/mailer.php: 1 message has been processed (' . $time . ' seconds)' . BR;
     } elseif ($bucket['value']) {
         return 'shared/mailer.php: delaying messages (' . $time . ' seconds)' . BR;
     } else {
         return 'shared/mailer.php: nothing to do (' . $time . ' seconds)' . BR;
     }
 }
开发者ID:rair,项目名称:yacs,代码行数:101,代码来源:mailer.php

示例12: parse_tag_close

 function parse_tag_close($parser, $tag)
 {
     global $context;
     global $in_overlay, $overlay_class, $overlay_parameters;
     global $parsed_cdata, $parsed_item, $parsed_overlay, $parsing_report;
     // save gathered data if necessary
     switch ($tag) {
         case 'article':
             // end of article
             // transcode owner id
             $parsed_item['owner_id'] = Surfer::get_id();
             if (isset($parsed_item['owner_nick_name']) && ($user = Users::get($parsed_item['owner_nick_name']))) {
                 $parsed_item['owner_id'] = $user['id'];
             }
             // transcode creator id
             $parsed_item['create_id'] = Surfer::get_id();
             if (isset($parsed_item['create_nick_name']) && ($user = Users::get($parsed_item['create_nick_name']))) {
                 $parsed_item['create_id'] = $user['id'];
             }
             // transcode editor id
             $parsed_item['edit_id'] = Surfer::get_id();
             if (isset($parsed_item['edit_nick_name']) && ($user = Users::get($parsed_item['edit_nick_name']))) {
                 $parsed_item['edit_id'] = $user['id'];
             }
             // transcode publisher id
             $parsed_item['publish_id'] = Surfer::get_id();
             if (isset($parsed_item['publish_nick_name']) && ($user = Users::get($parsed_item['publish_nick_name']))) {
                 $parsed_item['publish_id'] = $user['id'];
             }
             // bind to given overlay
             $overlay = NULL;
             if ($overlay_class) {
                 $overlay = Overlay::bind($overlay_class . ' ' . $overlay_parameters);
             }
             // when the page has been overlaid
             if (is_object($overlay)) {
                 // update the overlay from content
                 foreach ($parsed_overlay as $label => $value) {
                     $overlay->attributes[$label] = $value;
                 }
                 // save content of the overlay in this item
                 $parsed_item['overlay'] = $overlay->save();
                 $parsed_item['overlay_id'] = $overlay->get_id();
             }
             // find anchor from handle
             if (isset($parsed_item['anchor_handle']) && ($reference = Sections::lookup($parsed_item['anchor_handle']))) {
                 $parsed_item['anchor'] = $reference;
             }
             // update an existing page
             if (isset($parsed_item['handle']) && ($item = Articles::get($parsed_item['handle']))) {
                 // transcode page id
                 $parsed_item['id'] = $item['id'];
                 // stop on error
                 if (!Articles::put($parsed_item) || is_object($overlay) && !$overlay->remember('update', $parsed_item, 'article:' . $item['id'])) {
                     Logger::error(sprintf('Unable to save article %s', $parsed_item['title'] . ' (' . $parsed_item['id'] . ')'));
                 }
                 // create a new page
             } else {
                 unset($parsed_item['id']);
                 // stop on error
                 if (!($parsed_item['id'] = Articles::post($parsed_item))) {
                     Logger::error(sprintf('Unable to save article %s', $parsed_item['title']));
                 } else {
                     // save overlay content
                     if (is_object($overlay)) {
                         $overlay->remember('insert', $parsed_item, 'article:' . $parsed_item['id']);
                     }
                 }
             }
             // report to surfer
             $parsing_report .= '<li>' . Skin::build_link(Articles::get_permalink($parsed_item), $parsed_item['title']) . "</li>\n";
             // ready for next item
             $overlay_class = NULL;
             $overlay_parameters = '';
             $parsed_overlay = array();
             $parsed_item = array();
             Safe::set_time_limit(30);
             break;
         case 'overlay':
             // end of overlay data
             $in_overlay = FALSE;
             break;
         case 'section':
             // end of section
             // transcode owner id
             $parsed_item['owner_id'] = Surfer::get_id();
             if (isset($parsed_item['owner_nick_name']) && ($user = Users::get($parsed_item['owner_nick_name']))) {
                 $parsed_item['owner_id'] = $user['id'];
             }
             // transcode creator id
             $parsed_item['create_id'] = Surfer::get_id();
             if (isset($parsed_item['create_nick_name']) && ($user = Users::get($parsed_item['create_nick_name']))) {
                 $parsed_item['create_id'] = $user['id'];
             }
             // transcode editor id
             $parsed_item['edit_id'] = Surfer::get_id();
             if (isset($parsed_item['edit_nick_name']) && ($user = Users::get($parsed_item['edit_nick_name']))) {
                 $parsed_item['edit_id'] = $user['id'];
             }
             // bind to given overlay
//.........这里部分代码省略.........
开发者ID:rair,项目名称:yacs,代码行数:101,代码来源:import.php

示例13: index_keywords

 function index_keywords($file_name)
 {
     // parse keywords in some files
     if (preg_match('/(\\.txt|\\.doc|\\.xls)$/i', $file_name) && ($handle = Safe::fopen($file_name, 'rb')) !== FALSE) {
         // load noise words
         Safe::load('files/noise_words.php');
         // use chunks of 50 kbytes
         $filtered_words = array();
         while (count($noise_words) && ($buffer = fread($handle, 51200))) {
             // strip binary stuff
             $buffer = preg_replace("/[вда]/m", 'a', $buffer);
             $buffer = preg_replace("/[йкли]/m", 'e', $buffer);
             $buffer = preg_replace("/[оп]/m", 'i', $buffer);
             $buffer = preg_replace("/[фц]/m", 'o', $buffer);
             $buffer = preg_replace("/[ыь]/m", 'u', $buffer);
             $buffer = str_replace('з', 'c', $buffer);
             $buffer = preg_replace('/[^a-zA-Z_0-9]+/m', ' ', $buffer);
             // ensure enough execution time
             Safe::set_time_limit(30);
             // strip html-like things
             $buffer = strip_tags($buffer);
             $buffer = preg_replace('/&\\w;/m', '', $buffer);
             // ensure enough execution time
             Safe::set_time_limit(30);
             // extract all readable words
             //					$context['debug'][] = 'buffer=<pre>'.$buffer.'</pre>';
             $words = preg_split("/[\\s]+/", $buffer);
             //					$context['debug'][] = count($words).' words extracted';
             // ensure enough execution time
             Safe::set_time_limit(30);
             // filter words
             foreach ($words as $word) {
                 // mysql does not index words of less than 3 chars
                 $length = strlen($word);
                 if ($length <= 3 || $length > 25) {
                     continue;
                 }
                 if (preg_match('/[0-9]/', $word)) {
                     continue;
                 }
                 if (preg_match('/^[_0-9]/', $word)) {
                     continue;
                 }
                 // filter words against the list of noise words
                 $word = strtolower($word);
                 if (!in_array($word, $noise_words)) {
                     $filtered_words[$word] += 1;
                 }
             }
             // ensure enough execution time
             Safe::set_time_limit(30);
         }
         // the complete file has been read
         fclose($handle);
         // ensure enough execution time
         Safe::set_time_limit(30);
         // memorize up to 1000 keywords
         if (is_array($filtered_words)) {
             ksort($filtered_words);
             reset($filtered_words);
             $keywords = '';
             if (is_array($filtered_words)) {
                 foreach ($filtered_words as $word => $count) {
                     $keywords .= $word . ' ';
                     if ($keywords_count++ > 1000) {
                         break;
                     }
                 }
             }
         }
         // ensure enough execution time
         Safe::set_time_limit(30);
     }
     return $keywords;
 }
开发者ID:rair,项目名称:yacs,代码行数:75,代码来源:hook_index_keywords.php

示例14: process

 /**
  * Internal function to process text replacement according
  * to codes' patterns.
  * uses preg_replace_callback and do the following treatment with priority :
  * 1. try to find a function among loaded script ( could be this class, or Skin class)
  * 2. try to find a class within codes extensions (in /codes/code_*.php) to perform the rendering
  * 3. perform a regular preg_replace
  * 4. let the text as is 
  * 
  * @global array $context
  * @param string $text to transform
  * @param array $patterns_map all the patterns to check and action to do with them
  * @return string transformed text.
  */
 private static function process($text, $patterns_map)
 {
     global $context;
     // ensure we have enough time to execute
     Safe::set_time_limit(30);
     foreach ($patterns_map as $pattern => $action) {
         // use lowercase, we may look for a file with this
         $action = strtolower($action);
         // use of preg_replace_callback with an anonymous function
         $text = preg_replace_callback($pattern, function ($matches) use($pattern, $action, $context) {
             // returned text
             $replace = '';
             // function to call
             $func = '';
             // array of captured element
             $capture = array_slice($matches, 1);
             // test if mapped action is a callable function (case 1)
             if (is_callable($action)) {
                 $func = $action;
                 // test if map is a class
             } elseif (Safe::filesize('codes/' . $action . '.php')) {
                 // delegate rendering to an extension (case 2)
                 include_once $context['path_to_root'] . 'codes/' . $action . '.php';
                 $code = new $action();
                 $replace = $code->render($capture);
                 unset($code);
                 return $replace;
             }
             if ($func) {
                 // call of class Codes method, with or without parameters (case 1)
                 if (count($capture)) {
                     $replace .= call_user_func_array($func, $capture);
                 } else {
                     $replace .= call_user_func($func);
                 }
             } else {
                 // regular preg_replace (case 3 and 4)
                 $replace .= preg_replace($pattern, $action, $matches[0]);
             }
             return $replace;
         }, $text);
     }
     return $text;
 }
开发者ID:rair,项目名称:yacs,代码行数:58,代码来源:codes.php

示例15: delete_staging

/**
 * delete staging files
 *
 * @param string the directory to start with
 * @see scripts/update.php
 */
function delete_staging($path)
{
    global $context;
    $path_translated = str_replace('//', '/', $context['path_to_root'] . '/scripts/staging' . $path);
    if ($handle = Safe::opendir($path_translated)) {
        while (($node = Safe::readdir($handle)) !== FALSE) {
            if ($node == '.' || $node == '..') {
                continue;
            }
            // make a real name
            $target = str_replace('//', '/', $path . '/' . $node);
            $target_translated = str_replace('//', '/', $path_translated . '/' . $node);
            // delete sub directory content
            if (is_dir($target_translated)) {
                delete_staging($target);
                Safe::rmdir($target_translated);
                // delete all files
            } else {
                $context['text'] .= sprintf(i18n::s('Deleting %s'), '/scripts/staging' . $target) . BR . "\n";
                Safe::unlink($target_translated);
                global $deleted_nodes;
                $deleted_nodes++;
            }
            // ensure we have enough time
            Safe::set_time_limit(30);
        }
        Safe::closedir($handle);
    }
}
开发者ID:rair,项目名称:yacs,代码行数:35,代码来源:purge.php


注:本文中的Safe::set_time_limit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。