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


PHP Safe::touch方法代码示例

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


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

示例1: send_body

/**
 * dynamically generate the page
 *
 * @see skins/index.php
 */
function send_body()
{
    global $context, $local;
    // $local is required to localize included scripts
    // include every script that has to be run once
    global $scripts, $scripts_count;
    if (@count($scripts)) {
        // the alphabetical order may be used to control script execution order
        sort($scripts);
        reset($scripts);
        // process each script one by one
        foreach ($scripts as $item) {
            // do not execute on first installation
            if (file_exists('../parameters/switch.on') || file_exists('../parameters/switch.off')) {
                // ensure we have a valid database resource
                if (!$context['connection']) {
                    break;
                }
                // remember this as an event
                Logger::remember('scripts/run_once.php: ' . sprintf(i18n::c('script %s has been executed'), $item));
                // where scripts actually are
                $actual_item = str_replace('//', '/', $context['path_to_root'] . 'scripts/run_once/' . $item);
                // include the script to execute it
                $scripts_count++;
                echo Skin::build_block($item, 'subtitle');
                include $actual_item;
                echo "\n";
            }
            // ensure enough overall execution time
            Safe::set_time_limit(30);
            // stamp the file to remember execution time
            Safe::touch($actual_item);
            // rename the script to avoid further execution
            Safe::unlink($actual_item . '.done');
            Safe::rename($actual_item, $actual_item . '.done');
        }
        // refresh javascript libraries
        Cache::purge('js');
    }
    // report on actual execution
    if ($scripts_count) {
        echo '<p>&nbsp;</p><p>' . sprintf(i18n::ns('%d script has been executed', '%d scripts have been executed', $scripts_count), $scripts_count) . "</p>\n";
    } else {
        echo '<p>' . i18n::s('No script has been executed') . "</p>\n";
    }
    // display the total execution time
    $time = round(get_micro_time() - $context['start_time'], 2);
    if ($time > 30) {
        echo '<p>' . sprintf(i18n::s('Script terminated in %.2f seconds.'), $time) . '</p>';
    }
    // if the server has been switched off, go back to the control panel
    if (file_exists('../parameters/switch.off')) {
        echo '<form method="get" action="' . $context['url_to_root'] . 'control/">' . "\n" . '<p class="assistant_bar">' . Skin::build_submit_button(i18n::s('Control Panel')) . '</p>' . "\n" . '</form>' . "\n";
        // else back to the control panel as well, but without a button
    } else {
        $menu = array('control/' => i18n::s('Control Panel'));
        echo Skin::build_list($menu, 'menu_bar');
    }
    // purge the cache, since it is likely that we have modified some data
    Cache::clear();
}
开发者ID:rair,项目名称:yacs,代码行数:66,代码来源:run_once.php

示例2: sprintf

     if (!($footprint = Scripts::hash($file))) {
         $context['text'] .= sprintf(i18n::s('%s is not a reference script'), $file) . BR . "\n";
         continue;
     }
     // store the footprint for later use --number of lines, content hash
     $footprints[$file] = array($footprint[0], $footprint[1]);
     // ensure a clean reference store
     Safe::unlink($context['path_to_reference'] . $file);
     // create adequate path
     if (!Safe::make_path($context['path_to_reference'] . dirname($file))) {
         $context['text'] .= sprintf(i18n::s('Impossible to create path %s.'), $context['path_to_reference'] . dirname($file)) . BR . "\n";
     } elseif (!Safe::copy($context['path_to_root'] . $file, $context['path_to_reference'] . $file)) {
         $context['text'] .= sprintf(i18n::s('Impossible to copy file %s.'), $file) . BR . "\n";
     } else {
         // try to preserve the modification date
         Safe::touch($context['path_to_reference'] . $file, Safe::filemtime($context['path_to_root'] . $file));
         // this will be filtered by umask anyway
         Safe::chmod($context['path_to_reference'] . $file, $context['file_mask']);
     }
     // avoid timeouts
     if (!(count($footprints) % 50)) {
         Safe::set_time_limit(30);
         SQL::ping();
     }
 }
 if (count($footprints)) {
     $context['text'] .= sprintf(i18n::s('%d reference scripts have been copied.'), count($footprints)) . "\n";
 }
 $context['text'] .= "</p>\n";
 // purge documentation pages
 $context['text'] .= '<p>' . i18n::s('Purging the documentation pages...') . "</p>\n";
开发者ID:rair,项目名称:yacs,代码行数:31,代码来源:build.php

示例3: preg_replace

             // not part of the reference set anymore
             $content = preg_replace('/\\s*\\*\\s+@reference\\s*\\n/i', "\n", $content);
             // save it as the new cache file
             if (Safe::file_put_contents($target, $content)) {
                 $context['text'] .= sprintf(i18n::s('%s has been transcoded'), $target) . BR . "\n";
             } else {
                 $context['text'] .= sprintf(i18n::s('Impossible to write to %s.'), $target) . BR . "\n";
                 $errors++;
             }
             // copy the file
         } elseif (!Safe::copy($context['path_to_root'] . $origin, $context['path_to_root'] . $target)) {
             $context['text'] .= sprintf(i18n::s('Impossible to copy file %s.'), $target) . BR . "\n";
             $errors++;
             // attempt to preserve the modification date of the origin file
         } else {
             Safe::touch($context['path_to_root'] . $target, Safe::filemtime($context['path_to_root'] . $origin));
             $context['text'] .= sprintf(i18n::s('%s has been copied'), $target) . BR . "\n";
         }
         // this will be filtered by umask anyway
         Safe::chmod($context['path_to_root'] . $target, $context['file_mask']);
     }
     $context['text'] .= "</p>\n";
 }
 // some errors have occured
 if ($errors) {
     $context['text'] .= '<p>' . i18n::s('Operation has failed.') . "</p>\n";
 } else {
     $context['text'] .= '<p>' . i18n::s('Congratulations, themes have been updated.') . '</p>' . '<p>' . sprintf(i18n::s('Feel free to change and adjust files at skins/%s to better suit your needs.'), $directory) . '</p>';
     // follow-up commands
     $follow_up = i18n::s('What do you want to do now?');
     $menu = array();
开发者ID:rair,项目名称:yacs,代码行数:31,代码来源:derive.php

示例4: purge_run_once

 /**
  * flag all scripts in scripts/run_once
  *
  */
 public static function purge_run_once()
 {
     global $context;
     // silently purge pending run-once scripts, if any
     if ($handle = Safe::opendir($context['path_to_root'] . 'scripts/run_once')) {
         // process every file in the directory
         while (($node = Safe::readdir($handle)) !== FALSE) {
             // skip special entries
             if ($node[0] == '.') {
                 continue;
             }
             // we are only interested in php scripts
             if (!preg_match('/\\.php$/i', $node)) {
                 continue;
             }
             // full name
             $target = $context['path_to_root'] . 'scripts/run_once/' . $node;
             // skip directories and links
             if (!is_file($target)) {
                 continue;
             }
             // check we have enough permissions
             if (!is_readable($target)) {
                 continue;
             }
             // stamp the file to remember execution time
             Safe::touch($target);
             // flag script as being already processed
             Safe::unlink($target . '.done');
             Safe::rename($target, $target . '.done');
         }
         Safe::closedir($handle);
     }
 }
开发者ID:rair,项目名称:yacs,代码行数:38,代码来源:scripts.php


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