本文整理汇总了PHP中Safe::load方法的典型用法代码示例。如果您正苦于以下问题:PHP Safe::load方法的具体用法?PHP Safe::load怎么用?PHP Safe::load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Safe
的用法示例。
在下文中一共展示了Safe::load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_banned_pattern
/**
* list banned servers
*
* This function is used to limit external links saved into the database.
* It makes a pattern suitable for [code]preg_match()[/code] out of this list.
*
* Banned hosts and domains are manually put in the configuration file for servers,
* as a list of words separated by spaces or commas.
*
* Following domains are always banned:
* - mail.yahoo.com
* - gmail.google.com
* - www.laposte.net
*
* Here is an example of usage:
* [php]
* // the url to check
* $url = ...
*
* // list banned servers
* include_once '../servers/servers.php';
* $banned_pattern = Servers::get_banned_pattern();
*
* // skip banned hosts
* if(preg_match($banned_pattern, $url))
* continue;
* [/php]
*
* This function will always return a valid pattern string, even if no configuration file has been saved.
*
* @return a string to be used in [code]preg_match()[/code]
*
* @see agents/referrals.php
* @see feeds/feeds.php
* @see servers/test.php
*/
public static function get_banned_pattern()
{
global $context;
// use the configuration file
Safe::load('parameters/servers.include.php');
// get parameter
if (isset($context['banned_hosts']) && $context['banned_hosts']) {
$banned = $context['banned_hosts'];
} else {
$banned = '.kanoodle.com, \\bporn, \\bsex';
}
// quote tokens to build a pattern
$banned_pattern = array();
$banned_tokens = preg_split('/[\\s,]+/', $banned, -1, PREG_SPLIT_NO_EMPTY);
foreach ($banned_tokens as $banned_token) {
$banned_pattern[] = str_replace(array('.', '/'), array('\\.', '\\/'), $banned_token);
}
return '/(' . implode('|', $banned_pattern) . ')/';
}
示例2: load_skin
// load the skin
load_skin('agents');
// the path to this page
$context['path_bar'] = array('control/' => i18n::s('Control Panel'));
// the title of the page
$context['page_title'] = sprintf(i18n::s('%s: %s'), i18n::s('Configure'), i18n::s('Background processing'));
// anonymous users are invited to log in or to register
if (!Surfer::is_logged()) {
Safe::redirect($context['url_to_home'] . $context['url_to_root'] . 'users/login.php?url=' . urlencode('agents/configure.php'));
} elseif (!Surfer::is_associate()) {
Safe::header('Status: 401 Unauthorized', TRUE, 401);
Logger::error(i18n::s('You are not allowed to perform this operation.'));
// display the input form
} elseif (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') {
// load current parameters, if any
Safe::load('parameters/agents.include.php');
// the form
$context['text'] .= '<form method="post" action="' . $context['script_url'] . '" id="main_form"><div>';
//
// messages
//
$messages = '';
// introduction to the queue list
$messages .= '<p>' . i18n::s('Mail accounts from which messages can be fetched and posted in the database.') . "</p>\n";
// list existing queues
if (isset($context['mail_queues']) && is_array($context['mail_queues'])) {
$count = 0;
foreach ($context['mail_queues'] as $name => $attributes) {
// queues list
$count++;
$messages .= '<p><b>' . sprintf(i18n::s('Queue #%d'), $count) . "</b></p>\n";
示例3: tick_hook
/**
* process new messages, if any
*
* This function checks inbound mailboxes, and process new messages on their arrival.
*
* This function is aiming to run silently, therefore errors are logged in a file.
*
* @return a string to be displayed in resulting page, if any
*/
public static function tick_hook()
{
global $context;
// useless if we don't have a valid database connection
if (!$context['connection']) {
return;
}
// we need some queue definitions
Safe::load('parameters/agents.include.php');
if (!isset($context['mail_queues']) || !is_array($context['mail_queues']) || !count($context['mail_queues'])) {
return 'agents/messages.php: no queue has been defined' . BR;
}
// remember start time
$stamp = get_micro_time();
// process each inbound queue
include_once $context['path_to_root'] . 'shared/values.php';
// messages.tick
$count = 0;
foreach ($context['mail_queues'] as $name => $queue) {
// count messages retrieved
$messages = Messages::process_queue($queue);
$count += $messages;
// remember tick date
Values::set('messages.tick.' . $name, $messages);
}
// rebuild index pages
if ($count) {
Cache::clear();
}
// compute execution time
$time = round(get_micro_time() - $stamp, 2);
// report on work achieved
if ($count > 1) {
return 'agents/messages.php: ' . $count . ' messages have been processed (' . $time . ' seconds)' . BR;
} elseif ($count == 1) {
return 'agents/messages.php: 1 message has been processed (' . $time . ' seconds)' . BR;
} else {
return 'agents/messages.php: nothing to do (' . $time . ' seconds)' . BR;
}
}
示例4: load_skin
// load the skin
load_skin('overlays');
// the path to this page
$local['control_en'] = 'Control Panel';
$local['control_fr'] = 'Panneau de contrôle';
$context['path_bar'] = array('control/index.php' => i18n::user('control'));
// page title
$context['page_title'] = i18n::s('Configure: BigBlueButton meetings');
// only associates can proceed
if (!Surfer::is_associate()) {
Safe::header('Status: 401 Unauthorized', TRUE, 401);
$context['error'] .= '<p>' . i18n::s('You are not allowed to perform this operation.') . '</p>';
// display the input form
} elseif (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') {
// load current parameters, if any
Safe::load('parameters/overlays.bbb_meetings.include.php');
// the form
$context['text'] .= '<form method="post" action="' . $context['self_script'] . '" id="main_form">';
$fields = array();
// server name
$label = i18n::s('BBB server');
$input = '<input type="text" name="bbb_server" id="bbb_server" size="32" value="' . encode_field(isset($context['bbb_server']) ? $context['bbb_server'] : '') . '" maxlength="255" />';
$fields[] = array($label, $input);
// server salt
$label = i18n::s('Security salt');
$input = '<input type="text" name="bbb_salt" id="bbb_salt" size="32" value="' . encode_field(isset($context['bbb_salt']) ? $context['bbb_salt'] : '') . '" maxlength="255" />';
$fields[] = array($label, $input);
// build the form
$context['text'] .= Skin::build_form($fields);
$fields = array();
// bottom commands
示例5: load_skin
// load the skin
load_skin('letters');
// maximum number of recipients
if (!defined('MAXIMUM_RECIPIENTS')) {
define('MAXIMUM_RECIPIENTS', 5000);
}
// wrapping threshold
if (!defined('WRAPPING_LENGTH')) {
define('WRAPPING_LENGTH', 70);
}
// the path to this page
$context['path_bar'] = array('letters/' => i18n::s('Newsletters'));
// the title of the page
$context['page_title'] = i18n::s('Post a letter');
// load parameters for letters
Safe::load('parameters/letters.include.php');
// default values if no configuration file is available
if (!isset($context['letter_body'])) {
$context['letter_body'] = '';
}
if (!isset($context['letter_prefix'])) {
$context['letter_prefix'] = '';
}
if (!isset($context['letter_suffix'])) {
$context['letter_suffix'] = '';
}
if (!isset($context['letter_title'])) {
$context['letter_title'] = '';
}
if (!isset($context['title_prefix'])) {
$context['title_prefix'] = '*** ';
示例6: tick_hook
/**
* get news from remote servers
*
* This function queries remote sources and populate the table of links based on fetched news.
*
* On tick, the including hook calls [code]Feeds::tick_hook()[/code].
* See [script]control/scan.php[/script] for a more complete description of hooks.
*
* The function browses the database to locate servers acting as feeders, and read the URLs to use.
*
* A round-robin algorithm is implemented, meaning that servers are polled in sequence throughout successive ticks.
* At most 1 feed is parsed on each tick, to limit impact when the "poor-man" cron mechanism is used,
* which is the default setting.
*
* XML feeds are fetched and parsed according to their type.
* At the moment YACS is able to process RSS and slashdot feeds.
* Link records are created or updated in the database saving as much of possible of provided data.
* Item data is reflected in Link, Title, and Description fields.
* Channel data is used to populate the Source field.
* Stamping information is based on feeding date, and channel title.
* Also, the edit action 'link:feed' marks links that are collected from feeders.
* The anchor field is set to the category assigned in the server profile.
*
* At the end of the feeding process, the database is purged from oldest links according to the limit
* defined in parameters/feeds.include.php, set through feeds/configure.php.
* See Links::purge_old_news().
*
* @param boolean if set to true, fetch news on each call; else use normal period of time
* @return a string to be displayed in resulting page, if any
*
* @see control/scan.php
* @see feeds/configure.php
*/
public static function tick_hook($forced = FALSE)
{
global $context;
// load librairies only once
include_once $context['path_to_root'] . 'links/links.php';
include_once $context['path_to_root'] . 'servers/servers.php';
include_once $context['path_to_root'] . 'shared/values.php';
// feeds.tick
// get feeding parameters
Safe::load('parameters/feeds.include.php');
// delay between feeds - minimum is 5 minutes
if (!isset($context['minutes_between_feeds']) || $context['minutes_between_feeds'] < 5) {
$context['minutes_between_feeds'] = 5;
}
// do not wait for the end of a feeding cycle
if ($forced) {
$threshold = gmstrftime('%Y-%m-%d %H:%M:%S');
} else {
$threshold = gmstrftime('%Y-%m-%d %H:%M:%S', time() - $context['minutes_between_feeds'] * 60);
}
// get a batch of feeders
if (!($feeders = Servers::list_for_feed(0, 1, 'feed'))) {
return 'feeds/feeds.php: no feed has been defined' . BR;
}
// remember start time
$start_time = get_micro_time();
// list banned tokens
$banned_pattern = Servers::get_banned_pattern();
// browse each feed
$count = 0;
foreach ($feeders as $server_id => $attributes) {
// get specific feed parameters
list($feed_url, $feed_title, $anchor, $stamp) = $attributes;
// skip servers processed recently
if ($stamp > $threshold) {
continue;
}
// flag this record to enable round-robin even on error
Servers::stamp($server_id);
// fetch news from the provided link
if (!($news = Feeds::get_remote_news_from($feed_url)) || !is_array($news)) {
continue;
}
// no anchor has been defined for this feed
if (!$anchor) {
// create a default section if necessary
if (!($anchor = Sections::lookup('external_news'))) {
$fields = array();
$fields['nick_name'] = 'external_news';
$fields['create_date'] = gmstrftime('%Y-%m-%d %H:%M:%S', time());
$fields['edit_date'] = gmstrftime('%Y-%m-%d %H:%M:%S', time());
$fields['index_map'] = 'N';
$fields['locked'] = 'Y';
// no direct contributions
$fields['rank'] = 40000;
// at the end of the list
$fields['title'] = i18n::c('External News');
$fields['description'] = i18n::c('Received from feeding servers');
if (!($fields['id'] = Sections::post($fields))) {
Logger::remember('feeds/feeds.php: Impossible to add a section.');
return;
}
$anchor = 'section:' . $fields['id'];
}
}
// process retrieved links
$links = 0;
//.........这里部分代码省略.........
示例7: initialize
/**
* initialize this instance
*
* @see overlays/bbb_meetings/configure.php
* @see overlays/overlay.php
*
*/
function initialize()
{
global $context;
// load current parameters, if any
Safe::load('parameters/overlays.bbb_meetings.include.php');
// default host
if (!isset($context['bbb_server']) || !$context['bbb_server']) {
$context['bbb_server'] = $context['host_name'];
}
}
示例8: 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;
}
示例9: process_handx_weblog
/**
* process one file uploaded by handx weblog
*
* @param string the file to process
*/
public static function process_handx_weblog($file)
{
global $context;
// load parameters for uploads
Safe::load('parameters/agents.include.php');
if (!$context['uploads_nick_name']) {
Logger::remember('agents/upload.php: no parameters, skipping ' . $file);
return;
}
// read the input queue
if (!($content = trim(Safe::file_get_contents($context['path_to_root'] . $file)))) {
return;
}
// save in the output queue
if ($handle = Safe::fopen($context['path_to_root'] . $file . '.bak', 'ab')) {
fwrite($handle, $content);
fclose($handle);
// delete the input queue
Safe::unlink($context['path_to_root'] . $file);
}
// date is derived from file name
$name = basename($file);
$year = substr($name, 0, 4);
$month = substr($name, 4, 2);
$day = substr($name, 6, 2);
// split entries using the default separator value
$separator = "/<table width=100%><tr><td class='time'>(.+?)<\\/td><\\/tr><\\/table>/";
$entries = preg_split($separator, $content, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
// no time information
if (@count($entries) == 1) {
// make a stamp
$stamp = gmstrftime('%Y-%m-%d %H:%M:%S', mktime(0, 0, 0, $month, $day, $year));
// process this entry
Uploads::process_handx_entry(trim($entries[0]), $stamp);
// pairs of time and content strings
} elseif (@count($entries) > 1) {
// process all pairs
for ($index = 0; $index < count($entries); $index++) {
// the time as extracted by preg_split()
$stamp = '';
if (preg_match('/(\\d{1,2}):(\\d{1,2}) (am|pm)/', $entries[$index], $matches)) {
$index++;
// make a stamp
$hour = $matches[1];
$minutes = $matches[2];
if ($matches[3] == 'pm') {
$hour += 12;
}
$stamp = gmstrftime('%Y-%m-%d %H:%M:%S', mktime($hour, $minutes, 0, $month, $day, $year));
}
// the entry itself
$entry = $entries[$index];
// process this entry
Uploads::process_handx_entry(trim($entry), $stamp);
}
}
}
示例10: initialize
/**
* initialize this instance
*
* @see overlays/etherpad_meetings/configure.php
* @see overlays/overlay.php
*
*/
function initialize()
{
global $context;
// load current parameters, if any
Safe::load('parameters/overlays.etherpad_meetings.include.php');
// use some unique id
if (!isset($this->attributes['meeting_id'])) {
$this->attributes['meeting_id'] = md5(mt_rand());
}
}
示例11: array
}
// report on failures, if any
if ($failures) {
$context['text'] .= '<p>' . FAILURE_PREFIX . i18n::s('Warning! Some files have not been updated.') . FAILURE_SUFFIX . "</p>\n";
}
// report on missing files, if any
if ($missing_files) {
$context['text'] .= '<p>' . FAILURE_PREFIX . i18n::s('Some updated files are missing.') . FAILURE_SUFFIX . "</p>\n";
// forward to the staging script
$menu = array('scripts/stage.php' => i18n::s('Stage updated scripts'));
$context['text'] .= Skin::build_list($menu, 'menu_bar');
}
// list staging files
} else {
// load the special update prefix, if any
Safe::load('scripts/staging/scripts/update_header.php');
// splash message
$context['text'] .= '<p>' . sprintf(i18n::s('Reference set of %d files built on %s on server %s'), count($footprints), $generation['date'], $generation['server']) . "</p>\n";
// sort footprints by alphabetical order
ksort($footprints);
reset($footprints);
// use footprints of reference files to locate updates
$staging_files = 0;
$missing_files = 0;
$box = '';
foreach ($footprints as $file => $attributes) {
// only consider php scripts at the moment
if (!preg_match('/\\.php$/', $file)) {
continue;
}
// maybe the script has already been executed -- never expect an exact copy
示例12: strip_tags
* @license http://www.gnu.org/copyleft/lesser.txt GNU Lesser General Public License
*/
// common definitions and initial processing
include_once '../shared/global.php';
include_once 'scripts.php';
// what to do
$action = '';
if (isset($_REQUEST['action'])) {
$action = $_REQUEST['action'];
}
if (!$action && isset($context['arguments'][0])) {
$action = $context['arguments'][0];
}
$action = strip_tags($action);
// load footprints, if any
Safe::load('footprints.php');
// load localized strings
i18n::bind('scripts');
// load the skin
load_skin('scripts');
// the path to this page
$context['path_bar'] = array('scripts/' => i18n::s('Server software'));
// the title of the page
$context['page_title'] = i18n::s('Check software integrity');
// anonymous users are invited to log in or to register
if (!Surfer::is_logged()) {
Safe::redirect($context['url_to_home'] . $context['url_to_root'] . 'users/login.php?url=' . urlencode('scripts/update.php'));
} elseif (!Surfer::is_associate()) {
Safe::header('Status: 401 Unauthorized', TRUE, 401);
Logger::error(i18n::s('You are not allowed to perform this operation.'));
// invalid staging index
示例13: sprintf
Logger::error(sprintf(i18n::s('ERROR: Impossible to write to the file %s. The configuration has not been saved.'), $parameters_file));
// allow for a manual update
$context['text'] .= '<p style="text-decoration: blink;">' . sprintf(i18n::s('To actually change the configuration, please copy and paste following lines by yourself in file %s.'), $parameters_file) . "</p>\n";
// job done
} else {
$context['text'] .= '<p>' . sprintf(i18n::s('The following configuration has been saved into the file %s.'), $parameters_file) . "</p>\n";
// purge the cache
Cache::clear();
// remember the change
$label = sprintf(i18n::c('%s has been updated'), $parameters_file);
Logger::remember('skins/flexible/configure.php: ' . $label);
}
// display updated parameters
$context['text'] .= Skin::build_box(i18n::s('Configuration parameters'), Safe::highlight_string($content), 'folded');
// reload current parameters, to be sure
Safe::load($parameters_file, TRUE);
// read the template file
if (!($content = Safe::file_get_contents($template_file))) {
Logger::error(sprintf(i18n::s('ERROR: Impossible to read the file %s.'), $template_file));
} else {
// prepare the transformation
$needles = array();
$values = array();
// page-level parameters
$needles[] = '!!body_background!!';
$values[] = $context['flexible_body_bg'];
$needles[] = '!!page_background!!';
$values[] = $context['flexible_page_bg'];
// page width
$needles[] = '!!width!!';
if ($context['flexible_width'] == '960px') {
示例14: sprintf
// the title of the page
$context['page_title'] = sprintf(i18n::s('%s: %s'), i18n::s('Configure'), i18n::s('Page factory'));
// anonymous users are invited to log in or to register
if (!Surfer::is_logged()) {
Safe::redirect($context['url_to_home'] . $context['url_to_root'] . 'users/login.php?url=' . urlencode('skins/configure.php'));
} elseif (!Surfer::is_associate()) {
Safe::header('Status: 401 Unauthorized', TRUE, 401);
Logger::error(i18n::s('You are not allowed to perform this operation.'));
// display the input form
} elseif (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') {
// first installation
if (!file_exists('../parameters/switch.on') && !file_exists('../parameters/switch.off')) {
$context['text'] .= '<p>' . i18n::s('You can use default values and change these later on. Hit the button at the bottom of the page to move forward.') . "</p>\n";
}
// load current parameters, if any
Safe::load('parameters/skins.include.php');
// the form
$context['text'] .= '<form method="post" action="' . $context['script_url'] . '" id="main_form"><div>';
//
// meta-information
//
$meta = '';
// site name
$label = i18n::s('Site name');
$input = '<input type="text" name="site_name" size="50" value="' . encode_field($context['site_name']) . '" maxlength="255" />';
$hint = i18n::s('Short and meaningful title, such as "My little big server", used almost everywhere, and appended to the title of every page of this site');
$fields[] = array($label, $input, $hint);
// site slogan
if (!isset($context['site_slogan'])) {
$context['site_slogan'] = '-- just do it. and do it right. and make it free. and let it be. and... (your turn)';
}
示例15: array
* At the end of the staging process a link is displayed to launch [script]scripts/update.php[/script], that will
* actually move the staging files to running directories. But this is another story.
*
* @see scripts/update.php
*
* @author Bernard Paques
* @author GnapZ
* @tester Paddy
* @reference
* @license http://www.gnu.org/copyleft/lesser.txt GNU Lesser General Public License
*/
// common definitions and initial processing
include_once '../shared/global.php';
include_once 'scripts.php';
// parameters for scripts
Safe::load('parameters/scripts.include.php');
// ensure we have a default reference server
if (!isset($context['reference_server']) || !$context['reference_server']) {
$context['reference_server'] = i18n::s('www.yacs.fr');
}
// no local file at the moment
$id = NULL;
$external_id = NULL;
// load localized strings
i18n::bind('scripts');
// load the skin
load_skin('scripts');
// the path to this page
$context['path_bar'] = array('scripts/' => i18n::s('Server software'));
// the title of the page
$context['page_title'] = i18n::s('Stage updated scripts');