Example #1
0
File: derive.php Project: rair/yacs
 // analyse each script
 foreach ($files as $file) {
     // ensure we have enough time to process this script
     Safe::set_time_limit(30);
     // the origin file
     $origin = 'skins/' . $skin . $file;
     // the target file
     if ($file == '/' . $skin . '.css') {
         $target = 'skins/' . $directory . '/' . $directory . '.css';
     } else {
         $target = 'skins/' . $directory . $file;
     }
     // ensure the path has been created
     Safe::make_path(dirname($target));
     // unlink previous files, if any
     Safe::unlink($context['path_to_root'] . $target);
     // transcode php files
     if (preg_match('/(\\.php|\\.css)$/i', $target) && ($content = Safe::file_get_contents($context['path_to_root'] . $origin))) {
         // change internal reference
         $content = preg_replace('/skins\\/' . preg_quote($skin, '/') . '/i', 'skins/' . $directory, $content);
         $content = preg_replace('/\'' . preg_quote($skin, '/') . '\'/i', "'" . $directory . "'", $content);
         $content = preg_replace('/' . preg_quote($skin, '/') . '\\.css/i', $directory . ".css", $content);
         // 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++;
         }
Example #2
0
/**
 * 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();
}
Example #3
0
        $context['text'] .= '<p>' . sprintf(i18n::s('The configuration file for virtual host %s has been deleted.'), $id) . '</p>';
        // remember the change
        $label = sprintf(i18n::c('%s has been deleted'), $file);
        Logger::remember('control/virtual.php: ' . $label);
    }
    // follow-up commands
    $follow_up = i18n::s('What do you want to do now?');
    $menu = array();
    $menu = array_merge($menu, array('control/virtual.php' => i18n::s('Manage virtual hosts')));
    $menu = array_merge($menu, array('control/' => i18n::s('Control Panel')));
    $follow_up .= Skin::build_list($menu, 'menu_bar');
    $context['text'] .= Skin::build_block($follow_up, 'bottom');
    // save the content of an updated file
} elseif ($id && isset($_REQUEST['content']) && $_REQUEST['content']) {
    // backup the old version, if any
    Safe::unlink($context['path_to_root'] . 'parameters/virtual_' . $id . '.include.php.bak');
    Safe::rename($context['path_to_root'] . 'parameters/virtual_' . $id . '.include.php', $context['path_to_root'] . 'parameters/virtual_' . $id . '.include.php.bak');
    // actual save
    if (Safe::file_put_contents('parameters/virtual_' . $id . '.include.php', $_REQUEST['content']) != strlen($_REQUEST['content'])) {
        Logger::error(sprintf(i18n::s('The target file %s may have been corrupted. Please check file content manually, and revert to the backup file, with the extension .bak, if necessary.'), 'parameters/virtual_' . $id . '.include.php'));
    } else {
        $context['text'] .= '<p>' . sprintf(i18n::s('The target file %s has been successfully updated.'), 'parameters/virtual_' . $id . '.include.php') . '</p>';
        $context['text'] .= Skin::build_box(i18n::s('Configuration'), Safe::highlight_string($_REQUEST['content']), 'unfolded');
        // follow-up commands
        $follow_up = i18n::s('What do you want to do now?');
        $menu = array();
        $menu = array_merge($menu, array('control/virtual.php?id=' . urlencode($id) => i18n::s('View the configuration file')));
        $menu = array_merge($menu, array('control/virtual.php' => i18n::s('Manage virtual hosts')));
        $menu = array_merge($menu, array('control/' => i18n::s('Control Panel')));
        $follow_up .= Skin::build_list($menu, 'menu_bar');
        $context['text'] .= Skin::build_block($follow_up, 'bottom');
Example #4
0
File: edit.php Project: rair/yacs
    // only *.css and template.php can be modified
} elseif ($file && !preg_match('/(\\.css|template\\.php)$/i', $file)) {
    Safe::header('Status: 401 Unauthorized', TRUE, 401);
    Logger::error(i18n::s('You are not allowed to perform this operation.'));
    // ensure the file already exists
} elseif ($file && !file_exists($context['path_to_root'] . 'skins/' . $skin . '/' . $file)) {
    Safe::header('Status: 401 Unauthorized', TRUE, 401);
    Logger::error(i18n::s('You are not allowed to perform this operation.'));
    // save the content of an updated file
} elseif (isset($_REQUEST['content']) && $_REQUEST['content']) {
    // warning if modification of some reference skin
    if (isset($_REQUEST['content']) && $_REQUEST['content'] && preg_match('/^(boxesandarrows|digital|joi|skeleton)$/', $skin)) {
        Logger::error(sprintf(i18n::s('Do not attempt to modify a reference theme directly, your changes would be overwritten on next software update. %s instead to preserve your work over time.'), Skin::build_link('skins/derive.php', i18n::s('Derive a theme'), 'shortcut')));
    }
    // backup the old version, if any
    Safe::unlink($context['path_to_root'] . 'skins/' . $skin . '/' . $file . '.bak');
    Safe::rename($context['path_to_root'] . 'skins/' . $skin . '/' . $file, $context['path_to_root'] . 'skins/' . $skin . '/' . $file . '.bak');
    // actual save
    if (Safe::file_put_contents('skins/' . $skin . '/' . $file, $_REQUEST['content']) != strlen($_REQUEST['content'])) {
        Logger::error(sprintf(i18n::s('The target file %s may have been corrupted. Please check file content manually, and revert to the backup file, with the extension .bak, if necessary.'), 'skins/' . $skin . '/' . $file));
    } else {
        $context['text'] .= '<p>' . sprintf(i18n::s('The target file %s has been successfully updated.'), 'skins/' . $skin . '/' . $file) . '</p>';
        // follow-up commands
        $follow_up = i18n::s('What do you want to do now?');
        $menu = array();
        $menu = array_merge($menu, array('skins/test.php?skin=' . urlencode($skin) => i18n::s('Test this theme')));
        $menu = array_merge($menu, array('skins/edit.php?skin=' . urlencode($skin) => i18n::s('Edit this theme')));
        $menu = array_merge($menu, array('skins/' => i18n::s('Themes')));
        $menu = array_merge($menu, array('skins/configure.php' => i18n::s('Configure the page factory')));
        $follow_up .= Skin::build_list($menu, 'menu_bar');
        $context['text'] .= Skin::build_block($follow_up, 'bottom');
Example #5
0
    $context['text'] .= Skin::finalize_list($menu, 'assistant_bar');
    // end of the form
    $context['text'] .= '</div></form>';
    // set the focus
    Page::insert_script('$("#files_extensions").focus();');
    // general help on this form
    $help = '<p>' . i18n::s('Shared files are not put in the database, but in the file system of the web server.') . '</p>' . '<p>' . i18n::s('If you cannot upload files because of permissions settings, use the configuration panel for users to disable all uploads.') . '</p>';
    $context['components']['boxes'] = Skin::build_box(i18n::s('Help'), $help, 'boxes', 'help');
    // no modifications in demo mode
} elseif (file_exists($context['path_to_root'] . 'parameters/demo.flag')) {
    Safe::header('Status: 401 Unauthorized', TRUE, 401);
    Logger::error(i18n::s('You are not allowed to perform this operation in demonstration mode.'));
    // save updated parameters
} else {
    // backup the old version
    Safe::unlink($context['path_to_root'] . 'parameters/files.include.php.bak');
    Safe::rename($context['path_to_root'] . 'parameters/files.include.php', $context['path_to_root'] . 'parameters/files.include.php.bak');
    // build the new configuration file
    $content = '<?php' . "\n" . '// This file has been created by the configuration script files/configure.php' . "\n" . '// on ' . gmdate("F j, Y, g:i a") . ' GMT, for ' . Surfer::get_name() . '. Please do not modify it manually.' . "\n" . 'global $context;' . "\n";
    if (isset($_REQUEST['files_extensions'])) {
        $content .= '$context[\'files_extensions\']=\'' . addcslashes($_REQUEST['files_extensions'], "\\'") . "';\n";
    }
    if (isset($_REQUEST['files_on_ftp'])) {
        $content .= '$context[\'files_on_ftp\']=\'' . addcslashes($_REQUEST['files_on_ftp'], "\\'") . "';\n";
    }
    if (isset($_REQUEST['files_path'])) {
        $content .= '$context[\'files_path\']=\'' . addcslashes($_REQUEST['files_path'], "\\'") . "';\n";
    }
    if (isset($_REQUEST['files_url'])) {
        $content .= '$context[\'files_url\']=\'' . addcslashes($_REQUEST['files_url'], "\\'") . "';\n";
    }
Example #6
0
File: import.php Project: rair/yacs
 function process($template, $directory = 'blogger_import')
 {
     global $context;
     // we also have to prepare a skin -- the skin split is for scripts/validate.php
     $skin = '<?php' . "\n" . 'class Sk' . 'in extends Skin_skeleton {' . "\n";
     // fix images relative path
     $template = preg_replace('/src="(.+?)"/ie', "'src=\"'.fix_relative('\$1', '{$directory}').'\"'", $template);
     $template = preg_replace('/background="(.+?)"/ie', "'background=\"'.fix_relative('\$1', '{$directory}').'\"'", $template);
     $template = preg_replace('/url\\((.+?)\\)/ie', "'url('.fix_relative('\$1', '{$directory}').')'", $template);
     // <$BlogArchiveFileName$>
     $from = '/<\\$BlogArchiveFileName\\$>/i';
     $to = '<?php echo $context[\'url_to_root\'].\'categories/view.php?id=monthly\'; ?>';
     $template = preg_replace($from, $to, $template);
     // <$BlogArchiveName$>
     $from = '/<\\$BlogArchiveName\\$>/i';
     $to = '<?php echo \'Monthly Archives\'; ?>';
     $template = preg_replace($from, $to, $template);
     // <$BlogArchiveLink$>
     $from = '/<\\$BlogArchiveLink\\$>/i';
     $to = '<?php echo $context[\'url_to_root\'].\'categories/view.php?id=monthly\'; ?>';
     $template = preg_replace($from, $to, $template);
     // <$BlogArchiveURL$>
     $from = '/<\\$BlogArchiveURL\\$>/i';
     $to = '<?php echo $context[\'url_to_root\'].\'categories/view.php?id=monthly\'; ?>';
     $template = preg_replace($from, $to, $template);
     // <$BlogDescription$>
     $from = '/<\\$BlogDescription\\$>/i';
     $to = '<?php' . "\n" . 'if(is_object($anchor))' . "\n" . '	echo $anchor->get_teaser();' . "\n" . '?>';
     $template = preg_replace($from, $to, $template);
     // <$BlogMemberProfile$>
     $from = '/<\\$BlogMemberProfile\\$>/i';
     $to = '<?php echo $context[\'creator_profile\']; ?>';
     $template = preg_replace($from, $to, $template);
     // <$BlogMetaData$>
     $from = '/<\\$BlogMetaData\\$>/i';
     $to = '<?php echo $context[\'page_header\']; ?>';
     $template = preg_replace($from, $to, $template);
     // <$BlogPageTitle$>
     $from = '/<\\$BlogPageTitle\\$>/i';
     $to = '<?php echo ucfirst(strip_tags($context[\'page_title\'])); ?>';
     $template = preg_replace($from, $to, $template);
     // <$BlogTitle$>
     $from = '/<\\$BlogTitle\\$>/i';
     $to = '<?php echo ucfirst(strip_tags($context[\'page_title\'])); ?>';
     $template = preg_replace($from, $to, $template);
     // <$BlogURL$>
     $from = '/<\\$BlogURL\\$>/i';
     $to = '<?php echo $context[\'url_to_home\'].$context[\'url_to_root\']; ?>';
     $template = preg_replace($from, $to, $template);
     // only one type of new lines
     $template = str_replace("\r\n", "\n", $template);
     $template = str_replace("\r", "\n", $template);
     // <MainOrArchivePage>
     $from = '/<MainOrArchivePage>(.*?)<\\/MainOrArchivePage>/is';
     $to = '';
     $template = preg_replace($from, $to, $template);
     // the <BlogItemComments>...</BlogItemComments> block
     $areas = preg_split('/<BlogItemComments>(.*?)<\\/BlogItemComments>/is', trim($template), -1, PREG_SPLIT_DELIM_CAPTURE);
     $template = '';
     $index = 0;
     foreach ($areas as $area) {
         switch ($index % 3) {
             case 0:
                 // prefix block
                 $template .= $area;
                 break;
             case 1:
                 // commenting area
                 // <$BlogCommentDateTime$>
                 $from = '/<\\$BlogCommentDateTime\\$>/i';
                 $to = '\'.Skin::build_date($item[\'create_date\']).\'';
                 $area = preg_replace($from, $to, $area);
                 // <$BlogCommentNumber$>
                 $from = '/<\\$BlogCommentNumber\\$>/i';
                 $to = '\'.$item[\'id\'].\'';
                 $area = preg_replace($from, $to, $area);
                 // <$BlogCommentAuthor$>
                 $from = '/<\\$BlogCommentAuthor\\$>/i';
                 $to = '\'.$item[\'create_name\'].\'';
                 $area = preg_replace($from, $to, $area);
                 // <$BlogCommentAuthorNickname$>
                 $from = '/<\\$BlogCommentAuthorNickname\\$>/i';
                 $to = '\'.$item[\'create_name\'].\'';
                 $area = preg_replace($from, $to, $area);
                 // <$BlogCommentBody$>
                 $comment_prefix .= 'unset($BlogCommentBody);' . "\n" . '$BlogCommentBody .= Codes::beautify(trim($item[\'description\']));' . "\n" . "\n";
                 $from = '/<\\$BlogCommentBody\\$>/i';
                 $to = '\'.$BlogCommentBody.\'';
                 $area = preg_replace($from, $to, $area);
                 // make a skin
                 $skin .= "\n" . '	function layout_comment($item, $variant = \'compact\') {' . "\n" . '		global $context;' . "\n" . '		' . str_replace("\n", "\n\t\t", $comment_prefix) . "\n" . '		//	array($prefix, $title, $suffix, $type, $icon)' . "\n" . '		$prefix = \'' . trim($item_prefix) . '\';' . "\n" . '		$title = \'_\';' . "\n" . '		$suffix = \'' . trim($area) . '\';' . "\n" . '		return array($prefix, $title, $suffix, \'comment\', NULL);' . "\n" . "\t}\n";
                 break;
             case 2:
                 // suffix block
                 $template .= $area;
                 break;
         }
         $index++;
     }
     // the <Blogger>...</Blogger> block
     $areas = preg_split('/<Blogger>(.*?)<\\/Blogger>/is', trim($template), -1, PREG_SPLIT_DELIM_CAPTURE);
     $template = '';
     $index = 0;
     foreach ($areas as $area) {
         // blogging area
         if ($index == 1) {
             $template .= '<?php ' . "\n" . '// display the menu bar, if any' . "\n" . 'if(@count($context[\'page_menu\']) > 0)' . "\n" . '	echo Skin::build_list($context[\'page_menu\'], \'page_menu\');' . "\n" . "\n" . '// display the prefix, if any' . "\n" . 'if($context[\'prefix\'])' . "\n" . '	echo $context[\'prefix\'];' . "\n" . "\n" . '// display the error message, if any' . "\n" . 'if($context[\'error\'])' . "\n" . '	  echo Skin::build_block($context[\'error\'], \'error\');' . "\n" . "\n" . '// display the page image, if any' . "\n" . 'if($context[\'page_image\'])' . "\n" . '	  echo \'<img src="\'.$context[\'page_image\'].\'" class="icon" alt="" />\';' . "\n" . "\n" . '// the main part of the page' . "\n" . 'echo $context[\'text\'];' . "\n" . "\n" . '// display the suffix, if any' . "\n" . 'if($context[\'suffix\'])' . "\n" . '	echo \'<p>\'.$context[\'suffix\'].\'</p>\';' . "\n" . '?>';
             // make a skin for each item of the blogging area
             // break lines to not interfere with regular code
             $area = str_replace("\n", "'\n\t\t\t.'", addcslashes(trim($area), "'"));
             // <$BlogDateHeaderDate$>
             $from = '/<\\$BlogDateHeaderDate\\$>/i';
             $to = '\'.Skin::build_date($item[\'create_date\']).\'';
             $area = preg_replace($from, $to, $area);
             // <$BlogItemArchiveFileName$>
             $from = '/<\\$BlogItemArchiveFileName\\$>/i';
             $to = '\'.$context[\'url_to_root\'].Articles::get_permalink($item).\'';
             $area = preg_replace($from, $to, $area);
             // <$BlogItemAuthor$>
             $from = '/<\\$BlogItemAuthor\\$>/i';
             $to = '\'.$item[\'create_name\'].\'';
             $area = preg_replace($from, $to, $area);
             // <$BlogItemAuthorNickname$>
             $from = '/<\\$BlogItemAuthorNickname\\$>/i';
             $to = '\'.$item[\'create_name\'].\'';
             $area = preg_replace($from, $to, $area);
             // <$BlogItemBody$>
             $article_prefix .= 'unset($BlogItemBody);' . "\n" . '// the introduction' . "\n" . 'if($item[\'introduction\'])' . "\n" . '	$BlogItemBody .= Codes::beautify(trim($item[\'introduction\']));' . "\n" . 'elseif(!is_object($overlay)) {' . "\n" . '	// extract up to markup, if any' . "\n" . '	$raw = preg_split(\'/(\\[|<)/\', $item[\'description\']);' . "\n" . '	$BlogItemBody .= Skin::strip(trim($raw[0]), 30);' . "\n" . '}' . "\n" . 'if($suffix)' . "\n" . '	$BlogItemBody = \' -&nbsp;\'.$suffix;' . "\n" . "\n" . '// insert overlay data, if any' . "\n" . 'if(is_object($overlay))' . "\n" . '	$BlogItemBody .= $overlay->get_text(\'list\', $item);' . "\n" . "\n";
             $from = '/<\\$BlogItemBody\\$>/i';
             $to = '\'.$BlogItemBody.\'';
             $area = preg_replace($from, $to, $area);
             // <$BlogItemCommentCount$>
             $article_prefix .= 'unset($BlogItemCommentCount);' . "\n" . '// info on related comments' . "\n" . 'include_once $context[\'path_to_root\'].\'comments/comments.php\';' . "\n" . '$BlogItemCommentCount = Comments::count_for_anchor(\'article:\'.$item[\'id\']);' . "\n" . "\n";
             $from = '/<\\$BlogItemCommentCount\\$>/i';
             $to = '\'.$BlogItemCommentCount.\'';
             $area = preg_replace($from, $to, $area);
             // <$BlogItemControl$> -- the menu bar for associates and poster
             $article_prefix .= 'unset($BlogItemControl);' . "\n" . 'if(Surfer::is_associate() || Surfer::is($item[\'create_id\']) || Surfer::is($item[\'edit_id\'])) {' . "\n" . '	$menu = array( Articles::get_url($item[\'id\'], \'edit\') => i18n::s(\'edit\'),' . "\n" . '		Articles::get_url($item[\'id\'], \'delete\') => i18n::s(\'delete\') );' . "\n" . '	$BlogItemControl = \' \'.Skin::build_list($menu, \'menu\');' . "\n" . '}' . "\n" . "\n";
             $from = '/<\\$BlogItemControl\\$>/i';
             $to = '\'.$BlogItemControl.\'';
             $area = preg_replace($from, $to, $area);
             // <$BlogItemDateTime$>
             $from = '/<\\$BlogItemDateTime\\$>/i';
             $to = '\'.Skin::build_date($item[\'create_date\']).\'';
             $area = preg_replace($from, $to, $area);
             // <$BlogItemNumber$>
             $from = '/<\\$BlogItemNumber\\$>/i';
             $to = '\'.$item[\'id\'].\'';
             $area = preg_replace($from, $to, $area);
             // <$BlogItemPermalinkURL$>
             $from = '/<\\$BlogItemPermalinkURL\\$>/i';
             $to = '\'.$context[\'url_to_root\'].Articles::get_permalink($item).\'';
             $area = preg_replace($from, $to, $area);
             // <$BlogItemTitle$> -- it has to be the last one for this item
             $from = '/<\\$BlogItemTitle\\$>/i';
             list($item_prefix, $item_suffix) = preg_split($from, $area);
             // make a skin
             $skin .= "\n" . '	function layout_article($item, $variant = \'compact\') {' . "\n" . '		global $context;' . "\n" . '		' . str_replace("\n", "\n\t\t", $article_prefix) . "\n" . '		//	array($prefix, $title, $suffix, $type, $icon)' . "\n" . '		$prefix = \'' . trim($item_prefix) . '\';' . "\n" . '		$title = trim($item[\'title\']);' . "\n" . '		$suffix = \'' . trim($item_suffix) . '\';' . "\n" . '		return array($prefix, $title, $suffix, \'article\', NULL);' . "\n" . "\t}\n";
         } else {
             // suffix block
             $template .= $area;
         }
         $index++;
     }
     // skin end
     $skin .= "}\n" . '?>' . "\n";
     // backup the old skin, if any
     Safe::unlink($context['path_to_root'] . 'skins/' . $directory . '/skin.php.bak');
     Safe::rename($context['path_to_root'] . 'skins/' . $directory . '/skin.php', $context['path_to_root'] . 'skins/' . $directory . '/skin.php.bak');
     // create a new skin file
     if (!$skin) {
         Logger::error(i18n::s('No blogging block has been found.'));
     } elseif (!Safe::make_path('skins/' . $directory)) {
         Logger::error(sprintf(i18n::s('Impossible to create path %s.'), 'skins/' . $directory));
     } elseif (!($handle = Safe::fopen($context['path_to_root'] . 'skins/' . $directory . '/skin.php', 'wb'))) {
         Logger::error(sprintf(i18n::s('Impossible to write to %s.'), $context['path_to_root'] . 'skins/' . $directory . '/skin.php'));
     } else {
         fwrite($handle, $skin);
         fclose($handle);
     }
     // backup the old template, if any
     Safe::unlink($context['path_to_root'] . 'skins/' . $directory . '/template.php.bak');
     if (!$template) {
         Logger::error(i18n::s('Empty template file'));
     } else {
         Safe::rename($context['path_to_root'] . 'skins/' . $directory . '/template.php', $context['path_to_root'] . 'skins/' . $directory . '/template.php.bak');
     }
     // create a new template file
     if (!Safe::make_path('skins/' . $directory)) {
         Logger::error(sprintf(i18n::s('Impossible to create path %s.'), 'skins/' . $directory));
     } elseif (!($handle = Safe::fopen($context['path_to_root'] . 'skins/' . $directory . '/template.php', 'wb'))) {
         Logger::error(sprintf(i18n::s('Impossible to write to %s.'), $context['path_to_root'] . 'skins/' . $directory . '/template.php'));
     } else {
         fwrite($handle, $template);
         fclose($handle);
         $context['text'] .= '<p>' . sprintf(i18n::s('Template has been imported. Check skin %s'), Skin::build_link('skins/test.php?skin=' . $directory, $directory, 'shortcut')) . "</p>\n";
     }
     return NULL;
 }
Example #7
0
File: scan.php Project: rair/yacs
     $context['text'] .= '<p>' . i18n::s('Review provided information and go to the bottom of the page to move forward.') . "</p>\n";
 }
 // include all scripts named 'hook.php' recursively
 foreach ($scanned as $name) {
     include_hook($context['path_to_root'] . $name);
 }
 global $scanned_directories;
 if ($scanned_directories > 1) {
     $context['text'] .= sprintf(i18n::s('%d directories have been scanned.'), $scanned_directories) . BR . "\n";
 }
 // no hook has been found
 if (!count($hooks)) {
     $context['text'] .= i18n::s('No item has been found.');
 } else {
     // backup the old version
     Safe::unlink('../parameters/hooks.include.php.bak');
     Safe::rename('../parameters/hooks.include.php', '../parameters/hooks.include.php.bak');
     // what we have to produce
     $called_items = array();
     $included_items = array();
     $included_items['tick'] = '';
     $linked_items = array();
     $served_items = array();
     // we will remember a xml file as well
     $xml = '';
     // consider each hook
     foreach ($hooks as $hook) {
         // bad script!
         if (!$hook['id'] || !$hook['type'] || $hook['type'] != 'call' && !$hook['script']) {
             $context['text'] .= '<p><strong>' . i18n::s('Bad hook:') . '</strong>' . BR . "\n";
             foreach ($hook as $name => $value) {
Example #8
0
File: cache.php Project: rair/yacs
 /**
  * purge some temporary files
  *
  * This function works in conjunction with Cache::hash().
  *
  * @param string extension of files to purge
  */
 public static function purge($type = '*')
 {
     global $context;
     // delete files cached by yacs
     if ($items = Safe::glob($context['path_to_root'] . 'temporary/cache_*.' . $type)) {
         foreach ($items as $name) {
             Safe::unlink($name);
         }
     }
     // also delete files cached by SimplePie
     if ($items = Safe::glob($context['path_to_root'] . 'temporary/*.spc')) {
         foreach ($items as $name) {
             Safe::unlink($name);
         }
     }
 }
Example #9
0
File: build.php Project: rair/yacs
 // analyse each script
 $footprints = array();
 foreach ($scripts as $file) {
     // silently skip configuration files
     if (strpos($file, '.include.php')) {
         continue;
     }
     // process only reference scripts
     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();
Example #10
0
        $_SESSION['last_uploaded'][$name]['tmp_name'] = $path;
        // @see safe::is_uploaded_file()
        $_SESSION['last_uploaded']['pathes'][] = $path;
        $preview = Files::preview($path, $name);
        // Success!
        outputJSON('File uploaded successfully to "' . UPLOAD_PATH . $_FILES[$name]['name'] . '".', 'success', $preview);
    }
} elseif ($action === 'destroy') {
    if ($name === "all") {
        foreach ($_SESSION['last_uploaded'] as $up) {
            // destroy file
            if (isset($up['tmp_name'])) {
                Safe::unlink($up['tmp_name']);
            }
        }
        unset($_SESSION['last_uploaded']);
        outputJSON(i18n::s('all temporary file destroyed'), 'success');
    }
    if (isset($_SESSION['last_uploaded'][$name])) {
        $filename = $_SESSION['last_uploaded'][$name]['name'];
        // destroy file
        Safe::unlink($_SESSION['last_uploaded'][$name]['tmp_name']);
        // destroy session memory
        unset($_SESSION['last_uploaded'][$name]);
        outputJSON(sprintf(i18n::s('temporary file %s destroyed'), $filename), 'success', Skin::build_input_file($name));
    }
}
////// no direct access
Safe::header('Status: 401 Unauthorized', TRUE, 401);
Logger::error(i18n::s('You are not allowed to perform this operation.'));
render_skin();
Example #11
0
File: edit.php Project: rair/yacs
 function explode_callback($name)
 {
     global $context;
     // reject all files put in sub-folders
     $file_path = Files::get_path($_REQUEST['anchor'], 'images');
     if (($path = substr($name, strlen($file_path . '/'))) && strpos($path, '/') !== FALSE) {
         Safe::unlink($name);
     } elseif (!($attributes = Safe::GetImageSize($name))) {
         Safe::unlink($name);
     } elseif ($attributes[0] > 5000 || $attributes[1] > 5000) {
         Safe::unlink($name);
     }
 }
Example #12
0
File: import.php Project: rair/yacs
            $parser = xml_parser_create();
            xml_set_element_handler($parser, 'parse_tag_open', 'parse_tag_close');
            xml_set_character_data_handler($parser, 'parse_cdata');
            // case is meaningful
            xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, FALSE);
            // parse data
            if (!xml_parse($parser, $content)) {
                Logger::error('Parsing error: ' . xml_error_string(xml_get_error_code($parser)) . ' at line ' . xml_get_current_line_number($parser));
            } else {
                $context['text'] = '<p>' . i18n::s('Following items have been processed:') . "</p>\n";
                $context['text'] .= '<ul>' . $parsing_report . '</ul>';
            }
            xml_parser_free($parser);
        }
        // delete the temporary file
        Safe::unlink($file_upload);
        // clear the full cache
        Cache::clear();
    }
} else {
    // the form to post a file
    $context['text'] .= '<form method="post" action="' . $context['script_url'] . '" id="main_form" enctype="multipart/form-data"><div>';
    // the file
    $label = i18n::s('File');
    $input = '<input type="file" name="upload" id="upload" size="30" />' . ' (&lt;&nbsp;' . $context['file_maximum_size'] . i18n::s('bytes') . ')';
    $hint = i18n::s('Select the file to upload');
    $fields[] = array($label, $input, $hint);
    // build the form
    $context['text'] .= Skin::build_form($fields);
    // the submit button
    $context['text'] .= '<p>' . Skin::build_submit_button(i18n::s('Submit')) . '</p>';
Example #13
0
File: codes.php Project: rair/yacs
 /**
  * internal method to store patterns of this serveur in a file
  * this to spare time for parsing each extension in /codes at page loading
  * @see method render
  * 
  * @global array $context
  * @param array $patterns_map
  */
 private static function save_patterns($patterns_map)
 {
     global $context;
     // backup the old version
     Safe::unlink($context['path_to_root'] . 'codes/patterns.auto.php.bak');
     Safe::rename($context['path_to_root'] . 'codes/patterns.auto.php', $context['path_to_root'] . 'codes/auto.patterns.auto.php.bak');
     $content = '<?php' . "\n" . '// This file has been created by the script codes/codes.php' . "\n" . '// on ' . gmdate("F j, Y, g:i a") . ' GMT, Please do not modify it manually.' . "\n";
     foreach ($patterns_map as $pattern => $action) {
         $content .= '$patterns_map[\'' . $pattern . '\']="' . addcslashes(str_replace("\n", '\\n', $action), '"') . "\";\n";
     }
     if (!Safe::file_put_contents('codes/patterns.auto.php', $content)) {
         Logger::error(sprintf(i18n::s('ERROR: Impossible to write to the file %s. The configuration has not been saved.'), 'codes/patterns.auto.php'));
     }
 }
Example #14
0
 /**
  * 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);
     }
 }
Example #15
0
    $context['text'] .= Skin::finalize_list($menu, 'assistant_bar');
    // end of the form
    $context['text'] .= '</div></form>';
    // set the focus
    Page::insert_script('$("#flash_font_r").focus();');
    // general help on this form
    $help = '<p>' . i18n::s('Do not set any background color to achieve a transparent object.') . '</p>';
    $context['components']['boxes'] = Skin::build_box(i18n::s('Help'), $help, 'boxes', 'help');
    // no modifications in demo mode
} elseif (file_exists($context['path_to_root'] . 'parameters/demo.flag')) {
    Safe::header('Status: 401 Unauthorized', TRUE, 401);
    Logger::error(i18n::s('You are not allowed to perform this operation in demonstration mode.'));
    // save updated parameters
} else {
    // backup the old version
    Safe::unlink($context['path_to_root'] . 'parameters/feeds.flash.include.php.bak');
    Safe::rename($context['path_to_root'] . 'parameters/feeds.flash.include.php', $context['path_to_root'] . 'parameters/feeds.flash.include.php.bak');
    // build the new configuration file
    $content = '<?php' . "\n" . '// This file has been created by the configuration script feeds/flash/configure.php' . "\n" . '// on ' . gmdate("F j, Y, g:i a") . ' GMT, for ' . Surfer::get_name() . '. Please do not modify it manually.' . "\n";
    if (isset($_REQUEST['flash_font_r'])) {
        $content .= '$context[\'flash_font_r\']=' . addcslashes($_REQUEST['flash_font_r'], "\\'") . ";\n";
    }
    if (isset($_REQUEST['flash_font_g'])) {
        $content .= '$context[\'flash_font_g\']=' . addcslashes($_REQUEST['flash_font_g'], "\\'") . ";\n";
    }
    if (isset($_REQUEST['flash_font_b'])) {
        $content .= '$context[\'flash_font_b\']=' . addcslashes($_REQUEST['flash_font_b'], "\\'") . ";\n";
    }
    if (isset($_REQUEST['flash_background_r'])) {
        $content .= '$context[\'flash_background_r\']=' . addcslashes($_REQUEST['flash_background_r'], "\\'") . ";\n";
    }
Example #16
0
File: images.php Project: rair/yacs
 /**
  * delete one image in the database and in the file system
  *
  * @param int the id of the image to delete
  * @return boolean TRUE on success, FALSE otherwise
  */
 public static function delete($id)
 {
     global $context;
     // load the row
     $item = Images::get($id);
     if (!$item['id']) {
         Logger::error(i18n::s('No item has been found.'));
         return FALSE;
     }
     // delete the image files silently
     $file_path = $context['path_to_root'] . Files::get_path($item['anchor'], 'images');
     Safe::unlink($file_path . '/' . $item['image_name']);
     Safe::unlink($file_path . '/' . $item['thumbnail_name']);
     Safe::rmdir($file_path . '/thumbs');
     Safe::rmdir($file_path);
     Safe::rmdir(dirname($file_path));
     // delete related items
     Anchors::delete_related_to('image:' . $id);
     // delete the record in the database
     $query = "DELETE FROM " . SQL::table_name('images') . " WHERE id = " . SQL::escape($item['id']);
     if (SQL::query($query) === FALSE) {
         return FALSE;
     }
     // job done
     return TRUE;
 }
Example #17
0
File: safe.php Project: rair/yacs
 /**
  * remove a directory
  *
  * @param string path to directory to delete
  * @return TRUE on success, FALSE on failure
  */
 public static function rmdir($path)
 {
     // translate the path
     $path = Safe::realpath($path);
     // maybe path has been already removed
     if (!is_dir($path)) {
         return TRUE;
     }
     // ensure call is allowed
     if (is_callable('rmdir')) {
         // remove 'index.php', if any
         Safe::unlink($path . '/index.php');
         // do remove the directory
         return @rmdir($path);
     }
     // tough luck
     return FALSE;
 }
Example #18
0
 /**
  * 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);
         }
     }
 }
Example #19
0
 /**
  * create a referenced image
  *
  * @param array of entity attributes (e.g., 'Content-Disposition')
  * @param string image actual content
  * @param array poster attributes
  * @param string the target anchor (e.g., 'article:123')
  * @param string reference of the object to be extended, if any
  * @return string reference to the created object, or NULL
  */
 public static function submit_image($entity_headers, $content, $user, $anchor, $target = NULL)
 {
     global $context;
     // retrieve queue parameters
     list($server, $account, $password, $allowed, $match, $section, $options, $hooks, $prefix, $suffix) = $context['mail_queue'];
     // locate content-disposition
     foreach ($entity_headers as $header) {
         if (preg_match('/Content-Disposition/i', $header['name'])) {
             $content_disposition = $header['value'];
             break;
         }
     }
     // find file name in content-disposition
     $file_name = '';
     if ($content_disposition && preg_match('/filename="*([a-zA-Z0-9\'\\(\\)\\+_,-\\.\\/:=\\? ]+)"*\\s*/i', $content_disposition, $matches)) {
         $file_name = $matches[1];
     }
     // as an alternative, look in content-type
     if (!$file_name) {
         // locate content-type
         foreach ($entity_headers as $header) {
             if (preg_match('/Content-Type/i', $header['name'])) {
                 $content_type = $header['value'];
                 break;
             }
         }
         // find file name in content-type
         if ($content_type && preg_match('/name="*([a-zA-Z0-9\'\\(\\)\\+_,-\\.\\/:=\\? ]+)"*\\s*/i', $content_type, $matches)) {
             $file_name = $matches[1];
         }
     }
     // as an alternative, look in content-description
     if (!$file_name) {
         // locate content-description
         foreach ($entity_headers as $header) {
             if (preg_match('/Content-Description/i', $header['name'])) {
                 $content_description = $header['value'];
                 break;
             }
         }
         // find file name in content-description
         $file_name = $content_description;
     }
     // sanity check
     if (!$file_name) {
         Logger::remember('agents/messages.php: No file name to use for submitted image');
         return NULL;
     }
     // file size
     $file_size = strlen($content);
     // sanity check
     if ($file_size < 7) {
         Logger::remember('agents/messages.php: Short image skipped', $file_name);
         return NULL;
     }
     // sanity check
     if (!$anchor) {
         Logger::remember('agents/messages.php: No anchor to use for submitted image', $file_name);
         return NULL;
     }
     // get anchor data -- this is a mutable object
     $host = Anchors::get($anchor, TRUE);
     if (!is_object($host)) {
         Logger::remember('agents/messages.php: Unknown anchor ' . $anchor, $file_name);
         return NULL;
     }
     // create target folders
     $file_path = Files::get_path($anchor, 'images');
     if (!Safe::make_path($file_path)) {
         Logger::remember('agents/messages.php: Impossible to create ' . $file_path);
         return NULL;
     }
     if (!Safe::make_path($file_path . '/thumbs')) {
         Logger::remember('agents/messages.php: Impossible to create ' . $file_path . '/thumbs');
         return NULL;
     }
     $file_path = $context['path_to_root'] . $file_path . '/';
     // save the entity in the file system
     if (!($file = Safe::fopen($file_path . $file_name, 'wb'))) {
         Logger::remember('agents/messages.php: Impossible to open ' . $file_path . $file_name);
         return NULL;
     }
     if (fwrite($file, $content) === FALSE) {
         Logger::remember('agents/messages.php: Impossible to write to ' . $file_path . $file_name);
         return NULL;
     }
     fclose($file);
     // get image information
     if (!($image_information = Safe::GetImageSize($file_path . $file_name))) {
         Safe::unlink($file_path . $file_name);
         Logger::remember('agents/messages.php: No image information in ' . $file_path . $file_name);
         return NULL;
     }
     // we accept only gif, jpeg and png
     if ($image_information[2] != 1 && $image_information[2] != 2 && $image_information[2] != 3) {
         Safe::unlink($file_path . $file_name);
         Logger::remember('agents/messages.php: Rejected image type for ' . $file_path . $file_name);
         return NULL;
     }
     // build a thumbnail
     $thumbnail_name = 'thumbs/' . $file_name;
     // do not stop on error
     include_once $context['path_to_root'] . 'images/image.php';
     if (!Image::shrink($file_path . $file_name, $file_path . $thumbnail_name, FALSE, FALSE)) {
         Logger::remember('agents/messages.php: No thumbnail has been created for ' . $file_path . $file_name);
     }
     // resize the image where applicable
     if (Image::adjust($file_path . $file_name, FALSE)) {
         $file_size = Safe::filesize($file_path . $file_name);
     }
     // all details
     $details = array();
     // image size
     if ($image_information = Safe::GetImageSize($file_path . $file_name)) {
         $details[] = i18n::c('Size') . ': ' . $image_information[0] . ' x ' . $image_information[1];
     }
     // update image description
     $item = array();
     $item['anchor'] = $anchor;
     $item['image_name'] = $file_name;
     $item['thumbnail_name'] = $thumbnail_name;
     $item['image_size'] = $file_size;
     $item['description'] = '';
     if (isset($content_description) && $content_description != $file_name) {
         $item['description'] .= $content_description;
     }
     if (@count($details)) {
         $item['description'] .= "\n\n" . '<p class="details">' . implode("<br />\n", $details) . "</p>\n";
     }
     $item['edit_date'] = gmstrftime('%Y-%m-%d %H:%M:%S', time());
     $item['edit_name'] = $user['nick_name'];
     $item['edit_id'] = $user['id'];
     $item['edit_address'] = $user['email'];
     // create an image record in the database
     include_once $context['path_to_root'] . 'images/images.php';
     if (!($item['id'] = Images::post($item))) {
         Logger::remember('agents/messages.php: Impossible to save image ' . $item['image_name']);
         return NULL;
     }
     if ($context['debug_messages'] == 'Y') {
         Logger::remember('agents/messages.php: Messages::submit_image()', $item, 'debug');
     }
     // insert the image in the anchor page
     $host->touch('image:create', $item['id'], TRUE);
     return 'image:' . $item['id'];
 }
Example #20
0
File: index.php Project: rair/yacs
     } else {
         $content .= $chunk;
     }
 }
 // with Indexes
 if (isset($_SESSION['htaccess']['indexes'])) {
     if (!($chunk = Safe::file_get_contents('control/htaccess/indexes/.htaccess'))) {
         Logger::error(sprintf(i18n::s('Impossible to read %s.'), 'control/htaccess/indexes/.htaccess'));
     } else {
         $content .= $chunk;
     }
 }
 // ensure smooth operations
 if ($content && !count($context['error'])) {
     // backup the old version
     Safe::unlink($context['path_to_root'] . '.htaccess.bak');
     Safe::rename($context['path_to_root'] . '.htaccess', $context['path_to_root'] . '.htaccess.bak');
     // update the parameters file
     if (!Safe::file_put_contents($context['path_to_root'] . '.htaccess', $content)) {
         Logger::error(sprintf(i18n::s('ERROR: Impossible to write to the file %s. The configuration has not been saved.'), $context['path_to_root'] . '.htaccess'));
         // 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.'), $context['path_to_root'] . '.htaccess') . "</p>\n";
         // job done
     } else {
         $context['text'] .= '<p>' . sprintf(i18n::s('The following configuration has been saved into the file %s.'), '.htaccess') . "</p>\n";
         // remember the change
         $label = sprintf(i18n::c('%s has been updated'), '.htaccess');
         Logger::remember('control/htaccess/index.php: ' . $label);
     }
     // display updated parameters
     $context['text'] .= Skin::build_box(i18n::s('Configuration parameters'), str_replace("\n", BR, htmlspecialchars($content)), 'folded');
Example #21
0
File: purge.php Project: rair/yacs
/**
 * 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);
    }
}
Example #22
0
}
// version 8.4
if (!defined('YACS')) {
    define('YACS', TRUE);
}
// version 8.5 - new side menu
if (!isset($context['page_tools'])) {
    $context['page_tools'] = array();
}
if (!isset($context['script_url'])) {
    $context['script_url'] = '';
}
// version 8.6 - new page components
if (!isset($context['page_tags'])) {
    $context['page_tags'] = '';
}
if (!isset($_SESSION['surfer_interface'])) {
    $_SESSION['surfer_interface'] = 'C';
}
// force a refresh of compacted javascript libraries
if ($items = Safe::glob($context['path_to_root'] . 'temporary/cache_*.js')) {
    foreach ($items as $name) {
        Safe::unlink($name);
    }
}
// safe copy of footprints.php to the root directory
Safe::unlink($context['path_to_root'] . 'footprints.php.bak');
Safe::rename($context['path_to_root'] . 'footprints.php', $context['path_to_root'] . 'footprints.php.bak');
Safe::copy($context['path_to_root'] . 'scripts/staging/footprints.php', $context['path_to_root'] . 'footprints.php');
// remember this as a significant event --i18n::s does not exist before 6.12
Logger::remember('scripts/update_trailer.php: update trailer has been executed');
Example #23
0
     $context['text'] .= i18n::s('<p>The new page will now be reviewed before its publication. It is likely that this will be done within the next 24 hours at the latest.</p>');
 }
 if (!isset($_REQUEST['first_comment'])) {
     $_REQUEST['first_comment'] = '';
 }
 // attach some file
 $file_path = Files::get_path('article:' . $_REQUEST['id']);
 if (isset($_FILES['upload']) && ($uploaded = Files::upload($_FILES['upload'], $file_path, 'article:' . $_REQUEST['id']))) {
     // several files have been added
     if (is_array($uploaded)) {
         $_REQUEST['first_comment'] .= '<div>' . Skin::build_list(Files::list_for_anchor_and_name('article:' . $_REQUEST['id'], $uploaded, 'compact'), 'compact') . '</div>';
     } elseif ($file =& Files::get_by_anchor_and_name('article:' . $_REQUEST['id'], $uploaded)) {
         $_REQUEST['first_comment'] .= '<div>' . Codes::render_object('file', $file['id']) . '</div>';
         // silently delete the previous file if the name has changed
         if (isset($file['file_name']) && $file['file_name'] != $uploaded) {
             Safe::unlink($file_path . '/' . $file['file_name']);
         }
     }
 }
 // capture first comment too
 if (isset($_REQUEST['first_comment']) && $_REQUEST['first_comment']) {
     include_once $context['path_to_root'] . 'comments/comments.php';
     $fields = array();
     $fields['anchor'] = 'article:' . $_REQUEST['id'];
     $fields['description'] = $_REQUEST['first_comment'];
     Comments::post($fields);
 }
 // post an overlay, with the new article id --don't stop on error
 if (is_object($overlay)) {
     $overlay->remember('insert', $_REQUEST, 'article:' . $_REQUEST['id']);
 }
 }
 // get the file locally
 if (file_exists($local_reference)) {
     $content = Safe::file_get_contents($local_reference);
 } elseif (($content = http::proceed($remote_reference)) === FALSE) {
     $local['error_en'] = 'Unable to get ' . $file;
     $local['error_fr'] = 'Impossible d\'obtenir ' . $file;
     echo i18n::user('error') . "<br />\n";
 }
 // we have something in hand
 if ($content) {
     // create missing directories where applicable
     Safe::make_path(dirname($file));
     // create backups, if possible
     if (file_exists($context['path_to_root'] . $file)) {
         Safe::unlink($context['path_to_root'] . $file . '.bak');
         Safe::rename($context['path_to_root'] . $file, $context['path_to_root'] . $file . '.bak');
     }
     // update the target file
     if (!Safe::file_put_contents($file, $content)) {
         $local['label_en'] = 'Impossible to write to the file ' . $file . '.';
         $local['label_fr'] = 'Impossible d\'&eacute;crire le fichier ' . $file . '.';
         echo i18n::user('label') . "<br />\n";
     } else {
         $local['label_en'] = 'has been updated';
         $local['label_fr'] = 'a &eacute;t&eacute; mis &agrave; jour';
         echo $file . ' ' . i18n::user('label') . "<br />\n";
     }
 }
 // next one
 $count += 1;
Example #25
0
File: stage.php Project: rair/yacs
/**
 * 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);
    }
}
Example #26
0
File: files.php Project: rair/yacs
 function explode_callback($name)
 {
     global $context;
     // reject all files put in sub-folders
     if (($path = substr($name, strlen($context['uploaded_path'] . '/'))) && strpos($path, '/') !== FALSE) {
         Safe::unlink($name);
     } elseif (!Files::is_authorized($name)) {
         Safe::unlink($name);
     } else {
         // make it easy to download
         $ascii = utf8::to_ascii(basename($name));
         Safe::rename($name, $context['uploaded_path'] . '/' . $ascii);
         // remember this name
         $context['uploaded_files'][] = $ascii;
     }
 }
Example #27
0
File: switch.php Project: rair/yacs
// the path to this page
$context['path_bar'] = array('control/' => i18n::s('Control Panel'));
// the title of the page
$context['page_title'] = i18n::s('Main Switch');
// only associates can used the switch
if (!Surfer::is_associate()) {
    // prevent access to this script
    Safe::header('Status: 401 Unauthorized', TRUE, 401);
    Logger::error(i18n::s('You are not allowed to perform this operation.'));
    // back to the control panel
    $menu = array('control/' => i18n::s('Control Panel'));
    $context['text'] .= Skin::build_list($menu, 'menu_bar');
    // switch on
} elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'on') {
    // delete switch parameters, if any
    Safe::unlink('../parameters/switch.include.php');
    // rename the switch file
    if (Safe::rename($context['path_to_root'] . 'parameters/switch.off', $context['path_to_root'] . 'parameters/switch.on')) {
        $context['text'] .= '<p>' . i18n::s('The server has been successfully switched on. Pages are provided normally to surfers.') . "</p>\n";
        // clear the cache, to avoid side effects of complex updates
        Cache::clear();
        // remember the change
        $label = i18n::c('The server has been switched on.');
        Logger::remember('control/switch.php: ' . $label);
        // if the server is currently switched on
    } elseif (file_exists($context['path_to_root'] . 'parameters/switch.on')) {
        $context['text'] .= '<p>' . i18n::s('The server is currently switched on. Pages are provided normally to surfers.') . "</p>\n";
        // failure
    } else {
        Logger::error(i18n::s('The server has NOT been switched on successfully. Please rename the file parameters/switch.off to parameters/switch.on.'));
    }
Example #28
0
File: jsmin.php Project: rair/yacs
             if (!preg_match('/\\.min\\./', basename($name))) {
                 $minified .= JSMin::minify($text);
             } else {
                 $minified .= $text;
             }
             // one file has been compressed
             $count++;
         }
     }
 }
 // save the library to call in page header
 $file_min = $context['path_to_root'] . 'included/browser/library_js_header.min.js';
 if ($minified) {
     Safe::file_put_contents($file_min, $minified);
 } else {
     Safe::unlink($file_min);
 }
 // do the same with included/browser/js_endpage, including shared/yacs.js
 $minified = '';
 $files = Safe::glob($context['path_to_root'] . 'included/browser/js_endpage/*.js');
 if (is_array($files) && count($files)) {
     foreach ($files as $name) {
         if (in_array(basename($name), $to_avoid)) {
             continue;
         }
         $context['text'] .= 'included/browser/js_endpage/' . basename($name) . BR . "\n";
         // we do have some content
         if ($text = Safe::file_get_contents($name)) {
             // actual compression
             if (!preg_match('/\\.min\\./', basename($name))) {
                 $minified .= JSMin::minify($text);