/** * list files into one directory * * @param string the directory to look at * @return an array of directory entries, or NULL */ public static function list_files($path) { global $context; // we are looking for files $files = array(); // look for directory entries $path_translated = $context['path_to_root'] . $path; if ($handle = Safe::opendir($path_translated)) { // handle files one by one while (($node = Safe::readdir($handle)) !== FALSE) { // skip trivial entries if ($node[0] == '.') { continue; } // skip processed entries if (preg_match('/\\.(done|bak)$/i', $node)) { continue; } // make a real name $target = $path . '/' . $node; $target_translated = $path_translated . '/' . $node; // scan a file if (is_file($target_translated) && is_readable($target_translated)) { $files[] = $target; } } Safe::closedir($handle); } return $files; }
/** * delete a directory and all of its content * * @param string the directory to delete */ function delete_all($path) { global $context; $path_translated = str_replace('//', '/', $context['path_to_root'] . '/' . $path); if ($handle = Safe::opendir($path_translated)) { while (($node = Safe::readdir($handle)) !== FALSE) { if ($node[0] == '.') { continue; } // make a real name $target = str_replace('//', '/', $path . '/' . $node); $target_translated = str_replace('//', '/', $path_translated . '/' . $node); // delete a sub directory if (is_dir($target_translated)) { delete_all($path . '/' . $node); Safe::rmdir($target_translated); // delete the node } else { Safe::unlink($target_translated); } // statistics global $deleted_nodes; $deleted_nodes++; } Safe::closedir($handle); } }
/** * list all files below a certain path * * @param string the path to scan * @return an array of file names */ function list_files_at($root, $path = '') { global $context; // the list of files $files = array(); $path_translated = rtrim(str_replace('//', '/', $context['path_to_root'] . '/' . $root . '/' . $path), '/'); if ($handle = Safe::opendir($path_translated)) { while (($node = Safe::readdir($handle)) !== FALSE) { if ($node[0] == '.') { continue; } // skip transient files if (preg_match('/\\.cache$/i', $node)) { continue; } // make a real name $target = str_replace('//', '/', $path . '/' . $node); $target_translated = str_replace('//', '/', $path_translated . '/' . $node); // extend the list recursively if (is_dir($target_translated)) { $files = array_merge($files, list_files_at($root, $target)); } elseif (is_readable($target_translated)) { $files[] = $path . '/' . $node; } } Safe::closedir($handle); } return $files; }
$items[] = '<option value="' . $item . '"' . $checked . '>' . $item . "</option>\n"; } Safe::closedir($dir); // list items by alphabetical order if (@count($items)) { natsort($items); foreach ($items as $item) { $context['text'] .= $item; } } } $context['text'] .= '</select> ' . Skin::build_submit_button(i18n::s('Go')) . '</p></form>'; // list all cascaded style sheets and template.php for this skin $context['text'] .= '<form method="get" action="' . $context['script_url'] . '"><p>' . '<input type="hidden" name="skin" value="' . encode_field($skin) . '" />'; $context['text'] .= i18n::s('Files') . ' <select name="file">'; if ($dir = Safe::opendir("../skins/" . $skin)) { // list files in the skin directory $items = array(); while (($item = Safe::readdir($dir)) !== FALSE) { if ($item[0] == '.' || is_dir('../skins/' . $item . '/' . $file)) { continue; } if (!preg_match('/(\\.css|template.php)$/i', $item)) { continue; } $checked = ''; if ($file == $item) { $checked = ' selected="selected"'; } $items[] = '<option value="' . $item . '"' . $checked . '>skin/' . $skin . '/' . $item . "</option>\n"; }
/** * 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); } }
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); }
* list available tools * * @author Bernard Paques * @reference * @license http://www.gnu.org/copyleft/lesser.txt GNU Lesser General Public License */ include_once '../shared/global.php'; // load localized strings i18n::bind('tools'); // load the skin load_skin('tools'); // the title of the page $context['page_title'] = i18n::s('Tools'); // list tools available on this system $context['text'] .= '<ul>'; if ($dir = Safe::opendir($context['path_to_root'] . 'tools')) { // every php script is an overlay, except index.php, overlay.php, and hooks while (($file = Safe::readdir($dir)) !== FALSE) { if ($file[0] == '.') { continue; } if ($file == 'index.php') { continue; } if (preg_match('/hook\\.php$/i', $file)) { continue; } if (strpos($file, '.') && !preg_match('/(.*)\\.php$/i', $file, $matches)) { continue; } $tools[] = Skin::build_link('tools/' . $file, $file, 'basic');
/** * walk all files below a certain path * * @param string the absolute path to scan * @param function the function to call back with the file found * * @see scripts/check.php */ public static function walk_files_at($path, $call_back = NULL) { global $context, $script_count; // sanity check $path = rtrim($path, '/'); // list all files at this level $directories = array(); if ($handle = Safe::opendir($path)) { // list all nodes while (($node = Safe::readdir($handle)) !== FALSE) { // special directory names if ($node == '.' || $node == '..') { continue; } // process special nodes if ($node[0] == '.') { continue; } // make a real name $target = $path . '/' . $node; // scan a sub directory if (is_dir($target)) { $directories[] = $target; } elseif (is_readable($target)) { $call_back($target); } } Safe::closedir($handle); } // walk sub-directories as well foreach ($directories as $directory) { Scripts::walk_files_at($directory, $call_back); } }
// load the skin load_skin('scripts'); // the path to this page $context['path_bar'] = array('control/' => i18n::s('Control Panel')); // the title of the page $context['page_title'] = i18n::s('Run one-time scripts'); // the list of script to take into account global $scripts; $scripts = array(); // if the user table exists, check that the user is an admin $query = "SELECT count(*) FROM " . SQL::table_name('users'); if (SQL::query($query) !== FALSE && !Surfer::is_associate()) { Safe::header('Status: 401 Unauthorized', TRUE, 401); Logger::error(i18n::s('You are not allowed to perform this operation.')); // open the directory } elseif (!($dir = Safe::opendir($context['path_to_root'] . 'scripts/run_once'))) { Logger::error(sprintf(i18n::s('Impossible to read %s.'), $context['path_to_run_once_scripts'])); } else { while (($item = Safe::readdir($dir)) !== FALSE) { // script name has to start with a number --actually, a date if ($item[0] < '0' || $item[0] > '9') { continue; } // we only consider php scripts, of course if (strlen($item) < 5 || substr($item, -4) != '.php') { continue; } // do not execute twins, to ensure that scripts are ran only once if (file_exists($context['path_to_root'] . 'scripts/run_once/' . $item . '.done')) { continue; }
* @author Bernard Paques * @reference * @license http://www.gnu.org/copyleft/lesser.txt GNU Lesser General Public License */ include_once '../../shared/global.php'; // load the skin load_skin('users'); // the title of the page $context['page_title'] = i18n::s('Authenticators'); // splash message if (Surfer::is_associate()) { $context['text'] .= '<p>' . i18n::s('Authenticators listed below can be used to link this server to an existing list of users.') . '</p>'; } // list authenticators available on this system $context['text'] .= '<ul>'; if ($dir = Safe::opendir($context['path_to_root'] . 'users/authenticators')) { // every php script is an authenticator, except index.php and hooks while (($file = Safe::readdir($dir)) !== FALSE) { if ($file[0] == '.' || is_dir($context['path_to_root'] . 'authenticators/' . $file)) { continue; } if ($file == 'index.php') { continue; } if (preg_match('/hook\\.php$/i', $file)) { continue; } if (!preg_match('/(.*)\\.php$/i', $file, $matches)) { continue; } $authenticators[] = $matches[1];
function _addList($p_list, $p_add_dir, $p_remove_dir) { $v_result = true; $v_header = array(); // ----- Remove potential windows directory separator $p_add_dir = $this->_translateWinPath($p_add_dir); $p_remove_dir = $this->_translateWinPath($p_remove_dir, false); if (!$this->_file) { $this->_error('Invalid file descriptor'); return false; } if (sizeof($p_list) == 0) { return true; } foreach ($p_list as $v_filename) { if (!$v_result) { break; } // ----- Skip the current tar name if ($v_filename == $this->_tarname) { continue; } if ($v_filename == '') { continue; } if (!file_exists($v_filename)) { $this->_warning("File '{$v_filename}' does not exist"); continue; } // ----- Add the file or directory header if (!$this->_addFile($v_filename, $v_header, $p_add_dir, $p_remove_dir)) { return false; } if (@is_dir($v_filename)) { if (!($p_hdir = Safe::opendir($v_filename))) { $this->_warning("Directory '{$v_filename}' can not be read"); continue; } while (false !== ($p_hitem = Safe::readdir($p_hdir))) { if ($p_hitem[0] != '.') { if ($v_filename != ".") { $p_temp_list[0] = $v_filename . '/' . $p_hitem; } else { $p_temp_list[0] = $p_hitem; } $v_result = $this->_addList($p_temp_list, $p_add_dir, $p_remove_dir); } } unset($p_temp_list); unset($p_hdir); unset($p_hitem); } } return $v_result; }
// derive this skin if (isset($skin) && Surfer::is_associate()) { $context['page_menu'] += array('skins/derive.php?skin=' . $skin => i18n::s('Derive this theme')); } // $context['page_publisher'] - the publisher $context['page_publisher'] = 'webmaestro again, still through some PHP script'; // page tags $context['page_tags'] = i18n::s('<a>tag 1</a> <a>tag 2</a>'); // $context['page_title'] - the title of the page $context['page_title'] = i18n::s('Theme test'); // $context['path_bar'] - back to other sections $context['path_bar'] = array('skins/' => i18n::s('Themes')); // $context['prefix'] - also list skins available on this system $context['prefix'] .= '<form method="get" action="' . $context['script_url'] . '"><p>'; $context['prefix'] .= i18n::s('Theme to test') . ' <select name="skin">'; if ($dir = Safe::opendir("../skins")) { // valid skins have a template.php $skins = array(); while (($file = Safe::readdir($dir)) !== FALSE) { if ($file[0] == '.' || !is_dir('../skins/' . $file)) { continue; } if (!file_exists('../skins/' . $file . '/template.php')) { continue; } $checked = ''; if ($context['skin'] == 'skins/' . $file) { $checked = ' selected="selected"'; } $skins[] = '<option value="' . $file . '"' . $checked . '>' . $file . "</option>\n"; }
$action = 'image:set_as_thumbnail'; $context['text'] .= '<p>' . i18n::s('This has become the thumbnail image of the page.') . '</p>'; } elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'set_as_both') { $action = 'image:set_as_both'; $context['text'] .= '<p>' . i18n::s('The image has been added, and it also has been set as the page thumbnail.') . '</p>'; } else { $action = 'image:create'; $context['text'] .= '<p>' . i18n::s('The image has been inserted.') . '</p>'; } // touch the related anchor $anchor->touch($action, $_REQUEST['id'], isset($_REQUEST['silent']) && $_REQUEST['silent'] == 'Y'); // process several files } else { // scan all image files for this anchor $count = 0; if ($handle = Safe::opendir($file_path)) { // list all nodes $nodes = array(); while (($node = Safe::readdir($handle)) !== FALSE) { // special directory names if ($node == '.' || $node == '..') { continue; } // process special nodes if ($node[0] == '.') { continue; } // skip directories if (is_dir($context['path_to_root'] . $file_path . '/' . $node)) { continue; }
* @see canvas/standard.php */ include_once '../shared/global.php'; // load localized strings i18n::bind('canvas'); // load the skin load_skin('canvas'); // the title of the page $context['page_title'] = i18n::s('Canvas'); // splash message if (Surfer::is_associate()) { $context['text'] .= '<p>' . i18n::s('Canvas listed below can be used to customise articles display attached to some sections.') . '</p>'; } // list canvas available on this system $context['text'] .= '<ul>'; if ($dir = Safe::opendir($context['path_to_root'] . 'canvas')) { // every php script is an canvas, except index.php, canvas.php, and hooks while (($file = Safe::readdir($dir)) !== FALSE) { if ($file[0] == '.' || is_dir($context['path_to_root'] . 'canvas/' . $file)) { continue; } if ($file == 'index.php') { continue; } if ($file == 'canvas.php') { continue; } if (preg_match('/hook\\.php$/i', $file)) { continue; } if (!preg_match('/(.*)\\.php$/i', $file, $matches)) {
* [link=Wellstyled]http://wellstyled.com/tools/colorscheme2/index-en.html[/link]. * * @link http://wellstyled.com/tools/colorscheme2/index-en.html Color schemes generator 2 * * @author Bernard Paques * @reference * @license http://www.gnu.org/copyleft/lesser.txt GNU Lesser General Public License */ include_once '../shared/global.php'; // load the skin load_skin('skins'); // the title of the page $context['page_title'] = i18n::s('Themes'); // read all manifest.php files to list skins $skins = array(); if ($dir = Safe::opendir(".")) { while (($item = Safe::readdir($dir)) !== FALSE) { if ($item[0] == '.' || !is_dir($item)) { continue; } if (is_readable($item . '/manifest.php')) { include_once $item . '/manifest.php'; } } Safe::closedir($dir); } // no skin is shared on this server if (!count($skins)) { $context['text'] .= '<p>' . i18n::s('No theme is currently shared on this server.') . "</p>\n"; } else { // splash message to associates
// current type $overlay_type = ''; if (is_object($overlay)) { $overlay_type = $overlay->get_type(); } // list overlays available on this system $label = i18n::s('Change the overlay'); $input = '<select name="overlay_type">'; if ($overlay_type) { $input .= '<option value="none">(' . i18n::s('none') . ")</option>\n"; $hint = i18n::s('If you change the overlay you may loose some data.'); } else { $hint = i18n::s('No overlay has been selected yet.'); $input .= '<option value="" selected="selected">' . i18n::s('none') . "</option>\n"; } if ($dir = Safe::opendir($context['path_to_root'] . 'overlays')) { // every php script is an overlay, except index.php, overlay.php, and hooks while (($file = Safe::readdir($dir)) !== FALSE) { if ($file[0] == '.' || is_dir($context['path_to_root'] . 'overlays/' . $file)) { continue; } if ($file == 'index.php') { continue; } if ($file == 'overlay.php') { continue; } if (preg_match('/hook\\.php$/i', $file)) { continue; } if (!preg_match('/(.*)\\.php$/i', $file, $matches)) {
// the image $text .= '<input type="file" name="upload" id="upload" size="30" accesskey="i" title="' . encode_field(i18n::s('Press to select a local file')) . '" />'; $text .= ' ' . Skin::build_submit_button(i18n::s('Submit'), i18n::s('Press [s] to submit data'), 's'); $text .= BR . '<span class="details">' . i18n::s('Select a .png, .gif or .jpeg image.') . ' (< ' . Skin::build_number($image_maximum_size, i18n::s('bytes')) . ')</span>'; // end of the form $text .= '</div></form>'; // the script used for form handling at the browser Page::insert_script('$("#upload").focus();'); $context['text'] .= Skin::build_content(NULL, i18n::s('Upload an image'), $text); } // use the library // // where images are $path = 'skins/_reference/avatars'; // browse the path to list directories and files if ($dir = Safe::opendir($context['path_to_root'] . $path)) { $text = ''; if (Surfer::may_upload()) { $text .= '<p>' . i18n::s('Click on one image below to make it your new picture.') . '</p>' . "\n"; } // build the lists while (($image = Safe::readdir($dir)) !== FALSE) { // skip some files if ($image[0] == '.') { continue; } if (is_dir($context['path_to_root'] . $path . '/' . $image)) { continue; } // consider only images if (!preg_match('/(\\.gif|\\.jpeg|\\.jpg|\\.png)$/i', $image)) {
$context['text'] .= Safe::highlight_string($content); } // first installation if (!file_exists('../parameters/switch.on') && !file_exists('../parameters/switch.off')) { // some css files may have to be slightly updated if ($context['url_to_root_parameter'] != '/yacs/' && ($skins = Safe::opendir('../skins'))) { // valid skins have a template.php file while (($skin = Safe::readdir($skins)) !== FALSE) { if ($skin[0] == '.' || !is_dir('../skins/' . $skin)) { continue; } if (!file_exists('../skins/' . $skin . '/template.php')) { continue; } // look for css files if ($files = Safe::opendir('../skins/' . $skin)) { while (($file = Safe::readdir($files)) !== FALSE) { if (!preg_match('/\\.css$/i', $file)) { continue; } // change this css file if ($content = Safe::file_get_contents('../skins/' . $skin . '/' . $file)) { $content = str_replace('/yacs/', $context['url_to_root_parameter'], $content); Safe::file_put_contents('skins/' . $skin . '/' . $file, $content); } } Safe::closedir($files); } } Safe::closedir($skins); }
/** * transform codes to html * * [php] * // build the page * $context['text'] .= ... * * // transform codes * $context['text'] = Codes::render($context['text']); * * // final rendering * render_skin(); * [/php] * * @link http://pureform.wordpress.com/2008/01/04/matching-a-word-characters-outside-of-html-tags/ * * @param string the input string * @return string the transformed string */ public static function render($text) { global $context; // the formatting code interface include_once $context['path_to_root'] . 'codes/code.php'; // streamline newlines, even if this has been done elsewhere $text = str_replace(array("\r\n", "\r"), "\n", $text); // prevent wysiwyg editors to bracket our own tags $text = preg_replace('#^<p>(\\[.+\\])</p>$#m', '$1', $text); // initialize only once static $patterns_map; if (!isset($patterns_map)) { if (Safe::filesize('codes/patterns.auto.php')) { include_once $context['path_to_root'] . 'codes/patterns.auto.php'; } else { // core patterns $patterns_map['|<!-- .* -->|i'] = ''; // remove HTML comments $patterns_map['|</h(\\d)>\\n+|i'] = '</h$1>'; // strip \n after title $patterns_map['/\\n[ \\t]*(From|To|cc|bcc|Subject|Date):(\\s*)/i'] = BR . '$1:$2'; // common message headers $patterns_map['/\\[escape\\](.*?)\\[\\/escape\\]/is'] = 'Codes::render_escaped'; // [escape]...[/escape] (before everything) $patterns_map['/\\[php\\](.*?)\\[\\/php\\]/is'] = 'Codes::render_pre_php'; // [php]...[/php] $patterns_map['/\\[snippet\\](.*?)\\[\\/snippet\\]/is'] = 'Codes::render_pre'; // [snippet]...[/snippet] $patterns_map['/(\\[page\\].*)$/is'] = ''; // [page] (provide only the first one) $patterns_map['/\\[(associate|member|anonymous|hidden|restricted|authenticated)\\](.*?)\\[\\/\\1\\]/is'] = 'Codes::render_hidden'; // [associate]...[/associate] $patterns_map['/\\[redirect=([^\\]]+?)\\]/is'] = 'Codes::render_redirect'; // [redirect=<link>] $patterns_map['/\\[execute=([^\\]]+?)\\]/is'] = 'Codes::render_execute'; // [execute=<name>] $patterns_map['/\\[parameter=([^\\]]+?)\\]/is'] = 'Codes::render_parameter'; // [parameter=<name>] $patterns_map['/\\[lang=([^\\]]+?)\\](.*?)\\[\\/lang\\]/is'] = 'Codes::render_lang'; // [lang=xy]...[/lang] $patterns_map['/\\[(images)=([^\\]]+?)\\]/i'] = 'Codes::render_object'; // [images=<ids>] (before other links) $patterns_map['/\\[(image)=([^\\]]+?)\\]/i'] = 'Codes::render_object'; // [image=<id>] $patterns_map['/##(\\S.*?\\S)##/is'] = '<code>$1</code>'; // ##...## $patterns_map['/\\[code\\](.*?)\\[\\/code\\]/is'] = '<code>$1</code>'; // [code]...[/code] $patterns_map['/\\[indent\\](.*?)\\[\\/(indent)\\]/is'] = 'Skin::build_block'; // [indent]...[indent] $patterns_map['/\\[quote\\](.*?)\\[\\/(quote)\\]/is'] = 'Skin::build_block'; // [quote]...[quote] $patterns_map['/\\[folded(?:=([^\\]]+?))?\\](.*?)\\[\\/(folded)\\]\\s*/is'] = 'Skin::build_box'; // [folded=title]...[/folded],[folded]...[/folded] $patterns_map['/\\[unfolded(?:=([^\\]]+?))?\\](.*?)\\[\\/(unfolded)\\]\\s*/is'] = 'Skin::build_box'; // [unfolded=title]...[/unfolded],[unfolded]...[/unfolded] $patterns_map['/\\[sidebar(?:=([^\\]]+?))?\\](.*?)\\[\\/(sidebar)\\]\\s*/is'] = 'Skin::build_box'; // [sidebar=title]...[/sidebar],[sidebar]...[/sidebar] $patterns_map['/\\[note\\](.*?)\\[\\/(note)\\]\\s*/is'] = 'Skin::build_block'; // [note]...[/note] $patterns_map['/\\[caution\\](.*?)\\[\\/(caution)\\]\\s*/is'] = 'Skin::build_block'; // [caution]...[/caution] $patterns_map['/\\[center\\](.*?)\\[\\/(center)\\]/is'] = 'Skin::build_block'; // [center]...[/center] $patterns_map['/\\[right\\](.*?)\\[\\/(right)\\]/is'] = 'Skin::build_block'; // [right]...[/right] $patterns_map['/\\[(go)=([^\\]]+?)\\]/i'] = 'Codes::render_object'; // [go=<name>] $patterns_map['/\\[(article\\.description)=([^\\]]+?)\\]/i'] = 'Codes::render_object'; // [article.description=<id>] $patterns_map['/\\[(article)=([^\\]]+?)\\]/i'] = 'Codes::render_object'; // [article=<id>] or [article=<id>, title] $patterns_map['/\\[(next)=([^\\]]+?)\\]/i'] = 'Codes::render_object'; // [next=<id>] $patterns_map['/\\[(previous)=([^\\]]+?)\\]/i'] = 'Codes::render_object'; // [previous=<id>] $patterns_map['/\\[random(?:=([^\\]]+?))?\\]/i'] = 'Codes::render_random'; // [random], [random=section:<id>] or [random=category:<id>] $patterns_map['/\\[(section)=([^\\]]+?)\\]/i'] = 'Codes::render_object'; // [section=<id>] or [section=<id>, title] $patterns_map['/\\[(category(?:\\.description)?)=([^\\]]+?)\\]\\n*/is'] = 'Codes::render_object'; // [category=<id>], [category=<id>, title] or [category.description=<id>] $patterns_map['/\\[(user)=([^\\]]+?)\\]/i'] = 'Codes::render_object'; // [user=<id>] $patterns_map['/\\[(users)=([^\\]]+?)\\]/i'] = 'Codes::render_users'; // [users=present] $patterns_map['/\\[(file|download)=([^\\]]+?)\\]/i'] = 'Codes::render_object'; // [file=<id>] or [file=<id>, title] or download=<id>] or [download=<id>, title] $patterns_map['/\\[(comment)=([^\\]]+?)\\]/i'] = 'Codes::render_object'; // [comment=<id>] or [comment=<id>, title] $patterns_map['/\\[(link)(?:=([^\\]]+?))?\\](.*?)\\[\\/link\\]/is'] = 'Codes::render_link'; // [link]url[/link] or [link=label]url[/link] $patterns_map['/\\[(button)=([^\\]]+?)\\](.*?)\\[\\/button\\]/is'] = 'Codes::render_link'; // [button=label]url[/button] $patterns_map['/\\[(button)=([^\\|]+?)\\|([^\\]]+?)]/is'] = 'Codes::render_link'; // [button=label|url] $patterns_map['/\\[(click)=([^\\|]+?)\\|([^\\]]+?)]/is'] = 'Codes::render_link'; // [click=label|url] $patterns_map['/(\\[)([^ ][^\\]\\|]+?[^ ])\\|([^ ][^\\]]+?[^ ])\\]/is'] = 'Codes::render_link'; // [label|url] $patterns_map['#(\\s)([a-z]+?://[a-z0-9_\\-\\.\\~\\/@&;:=%$\\?]+)#'] = 'Codes::render_link'; // make URL clickable $patterns_map['#(\\s)(www\\.[a-z0-9\\-]+\\.[a-z0-9_\\-\\.\\~]+(?:/[^,< \\r\\n\\)]*)?)#i'] = 'Codes::render_link'; // web server url $patterns_map['/http[s]*:\\/\\/www\\.youtube\\.com\\/watch\\?v=([a-zA-Z0-9_\\-]+)[a-zA-Z0-9_\\-&=]*/i'] = '<iframe class="youtube-player" type="text/html" width="445" height="364" src="http://www.youtube.com/embed/$1" frameborder="0"></iframe>'; // YouTube link $patterns_map['/http[s]*:\\/\\/youtu\\.be\\/([a-zA-Z0-9_\\-]+)/i'] = '<iframe class="youtube-player" type="text/html" width="445" height="364" src="http://www.youtube.com/embed/$1" frameborder="0"></iframe>'; // YouTube link too $patterns_map['/\\[clicks=([^\\]]+?)]/is'] = 'Codes::render_clicks'; // [clicks=url] // @TODO: put in extension $patterns_map['/\\[email\\](.*?)\\[\\/email\\]/is'] = 'Codes::render_email'; // [email]url[/email] $patterns_map['/(\\s)([a-z0-9_\\-\\.\\~]+?@[a-z0-9_\\-\\.\\~]+\\.[a-z0-9_\\-\\.\\~]+)/i'] = 'Codes::render_email'; // mail address $patterns_map['/\\[published(?:\\.([^\\]=]+?))?(?:=([^\\]]+?))?\\]\\n*/is'] = 'Codes::render_published'; // [published(.decorated)], [published=section:4029], [published.decorated=section:4029,x] $patterns_map['/\\[updated(?:\\.([^\\]=]+?))?(?:=([^\\]]+?))?\\]\\n*/is'] = 'Codes::render_updated'; // [updated(.decorated)], [updated(.decorated)=section:4029,x] $patterns_map['/\\[sections(?:\\.([^\\]=]+?))?(?:=([^\\]]+?))?\\]\\n*/is'] = 'Codes::render_sections'; // [sections(.decorated)] (site map), [sections(.decorated)=section:4029] (sub-sections), [sections.simple=self] (assigned) $patterns_map['/\\[categories(?:\\.([^\\]=]+?))?(?:=([^\\]]+?))?\\]\\n*/is'] = 'Codes::render_categories'; // [categories(.decorated)] (category tree), [categories(.decorated)=categories:4029] (sub-categories) $patterns_map['/\\[wikipedia=([^\\]]+?)\\]/is'] = 'Codes::render_wikipedia'; // [wikipedia=keyword] or [wikipedia=keyword, title] $patterns_map['/\\[be\\]/i'] = ' <img src="' . $context['url_to_root'] . 'skins/_reference/flags/be.gif" alt="belgian flag" /> '; // [be] belgian flag $patterns_map['/\\[ca\\]/i'] = ' <img src="' . $context['url_to_root'] . 'skins/_reference/flags/ca.gif" alt="canadian flag" /> '; // [ca] canadian flag $patterns_map['/\\[ch\\]/i'] = ' <img src="' . $context['url_to_root'] . 'skins/_reference/flags/ch.gif" alt="swiss flag" /> '; // [ch] swiss flag $patterns_map['/\\[de\\]/i'] = ' <img src="' . $context['url_to_root'] . 'skins/_reference/flags/de.gif" alt="german flag" /> '; // [de] german flag $patterns_map['/\\[en\\]/i'] = ' <img src="' . $context['url_to_root'] . 'skins/_reference/flags/gb.gif" alt="english flag" /> '; // [en] english flag $patterns_map['/\\[es\\]/i'] = ' <img src="' . $context['url_to_root'] . 'skins/_reference/flags/es.gif" alt="spanish flag" /> '; // [es] spanish flag $patterns_map['/\\[fr\\]/i'] = ' <img src="' . $context['url_to_root'] . 'skins/_reference/flags/fr.gif" alt="french flag" /> '; // [fr] french flag $patterns_map['/\\[gr\\]/i'] = ' <img src="' . $context['url_to_root'] . 'skins/_reference/flags/gr.gif" alt="greek flag" /> '; // [gr] greek flag $patterns_map['/\\[it\\]/i'] = ' <img src="' . $context['url_to_root'] . 'skins/_reference/flags/it.gif" alt="italian flag" /> '; // [it] italian flag $patterns_map['/\\[pt\\]/i'] = ' <img src="' . $context['url_to_root'] . 'skins/_reference/flags/pt.gif" alt="portugal flag" /> '; // [pt] portugal flag $patterns_map['/\\[us\\]/i'] = ' <img src="' . $context['url_to_root'] . 'skins/_reference/flags/us.gif" alt="us flag" /> '; // [us] us flag $patterns_map['/\\[clear\\]\\n*/i'] = ' <br style="clear: both;" /> '; // [clear] $patterns_map['/\\[nl\\]\\n*/i'] = BR; // [nl] new line // load formatting codes from files $dir = $context['path_to_root'] . 'codes/'; if ($handle = Safe::opendir($dir)) { while (false !== ($file = Safe::readdir($handle))) { if ($file == '..') { continue; } if ($file == '.') { continue; } //convention : //get file only begining with code_ if (!(substr($file, 0, 5) == 'code_')) { continue; } include_once $dir . $file; //get formatting code patterns from this class $classname = stristr($file, '.', TRUE); $code = new $classname(); $code->get_pattern($patterns_map); unset($code); } Safe::closedir($handle); } // cache all patterns in one unique file for next time Codes::save_patterns($patterns_map); } // end generating patterns from scratch } // end setting $patterns $text = Codes::process($text, $patterns_map); // done return $text; }
$context['text'] .= '<form method="post" action="' . $context['script_url'] . '" id="main_form" enctype="multipart/form-data"><div>'; // upload an archive $context['text'] .= '<p>' . i18n::s('Select the archive file that you want to install remotely.') . '</p>'; // the file $context['text'] .= '<input type="file" name="upload" id="focus" size="30" />' . ' (< ' . $context['file_maximum_size'] . i18n::s('bytes') . ')'; // the submit button $context['text'] .= '<p>' . Skin::build_submit_button(i18n::s('Submit'), i18n::s('Press [s] to submit data'), 's') . '</p>' . "\n"; // end of the form $context['text'] .= '</div></form>'; // the script used for form handling at the browser Page::insert_script('$("#focus").focus();'); // use an available archive $context['text'] .= '<p>' . i18n::s('Alternatively, this script is able to handle archives that have been put in the directory <code>inbox/skins</code>.') . '</p>'; // find available skin archives $archives = array(); if ($dir = Safe::opendir("../inbox/skins")) { // scan the file system while (($file = Safe::readdir($dir)) !== FALSE) { // skip special files if ($file[0] == '.' || $file[0] == '~') { continue; } // skip non-archive files if (!preg_match('/(\\.bz2|\\.tar|\\.tar.gz|\\.tgz|\\.zip)/i', $file)) { continue; } // this is an archive to consider $archives[] = $file; } Safe::closedir($dir); // alphabetical order
/** * help to select an image */ function image_helper($name, $sample, $path = 'skins/flexible/logos', $toggle = '') { global $context; $text = ''; // none $checked = ''; if ($context[$name] == 'none') { $checked = ' checked="checked"'; Page::insert_script("\$('#" . $sample . "').css({'display': 'none'});"); } $to_toggle = ''; if ($toggle) { $to_toggle = '$(\'#' . $toggle . '\').css({\'display\': \'inline\'})'; } $text .= '<div style="text-align: center; float:left; width: 150px; margin: 0 10px 20px 0; background-color: #ddd"><div style="width: 150px; height: 70px; background: transparent; position:relative;"><div style="position: absolute; top:50%; margin: 0 auto; width:150px">' . i18n::s('None') . '</div></div>' . '<input type="radio" name="' . $name . '" value="none"' . $checked . ' onclick="$(\'#' . $sample . '\').css({\'display\': \'none\'});' . $to_toggle . '" /></div>'; // scan files if ($dir = Safe::opendir($path)) { // list files in the skin directory $items = array(); while (($item = Safe::readdir($dir)) !== FALSE) { if ($item[0] == '.' || is_dir($context['path_to_root'] . $path . '/' . $item)) { continue; } if (!preg_match('/(\\.gif|\\.jpeg|\\.jpg|\\.png)$/i', $item)) { continue; } $to_toggle = ''; if ($toggle) { $to_toggle = '$(\'#' . $toggle . '\').css({\'display\': \'none\'})'; } $checked = ''; if (strpos($context[$name], $item)) { $checked = ' checked="checked"'; Page::insert_script("\$('#" . $sample . "').src = '" . $context['url_to_root'] . $path . '/' . $item . "';\$('#" . $sample . "').css({'display': 'inline'});" . $to_toggle); } $items[] = '<div style="text-align: center; float:left; width: 150px; margin: 0 10px 20px 0; background-color: #ddd"><div style="width: 150px; height: 70px; background: transparent url(' . $context['url_to_root'] . $path . '/' . $item . ') no-repeat"> </div>' . '<input type="radio" name="' . $name . '" value="' . $context['url_to_root'] . $path . '/' . $item . '"' . $checked . ' onclick="$(\'#' . $sample . '\').src = \'' . $context['url_to_home'] . $context['url_to_root'] . $path . '/' . $item . '\';$(\'#' . $sample . '\').css({\'display\': \'inline\'});' . $to_toggle . '" /></div>'; } Safe::closedir($dir); // list items by alphabetical order if (@count($items)) { natsort($items); foreach ($items as $item) { $text .= $item; } } } return $text; }
* */ include_once '../shared/global.php'; // load localized strings i18n::bind('behaviors'); // load the skin load_skin('behaviors'); // set page title $context['page_title'] = i18n::s('Behaviors'); // splash message if (Surfer::is_associate()) { $context['text'] .= '<p>' . i18n::s('Behaviors listed below can be used to customise articles attached to some sections.') . '</p>'; } // list behaviors available on this system $context['text'] .= '<ul>'; if ($dir = Safe::opendir($context['path_to_root'] . 'behaviors')) { // every php script is a behavior, except index.php, behavior.php and behaviors.php while (($file = Safe::readdir($dir)) !== FALSE) { if ($file[0] == '.' || is_dir($context['path_to_root'] . 'behaviors/' . $file)) { continue; } if ($file == 'index.php') { continue; } if ($file == 'behavior.php') { continue; } if ($file == 'behaviors.php') { continue; } if (!preg_match('/(.*)\\.php$/i', $file, $matches)) {
/** * list all available locales * * @return array of ($locale => $label) */ public static function &list_locales() { global $context, $locales; // list of locales $locales = array(); // one directory per locale if ($dir = Safe::opendir($context['path_to_root'] . 'i18n/locale')) { while (($item = Safe::readdir($dir)) !== FALSE) { if ($item[0] == '.' || !is_dir($context['path_to_root'] . 'i18n/locale/' . $item)) { continue; } // remember locale $locales[$item] = $item; // enhance with manifest file, if any if (is_readable($context['path_to_root'] . 'i18n/locale/' . $item . '/manifest.php')) { include_once $context['path_to_root'] . 'i18n/locale/' . $item . '/manifest.php'; } } Safe::closedir($dir); } else { logger::remember('i18n/i18n.php: Impossible to browse directory i18n/locale'); } // done return $locales; }