예제 #1
0
파일: check.php 프로젝트: rair/yacs
 function check_file($node)
 {
     global $context;
     global $footprints;
     $key = substr($node, strlen($context['path_to_root']));
     // no extension to check
     if (strpos($key, '.') === FALSE) {
     } elseif (!strncmp($node, 'scripts/staging', 16)) {
     } elseif (!strcmp($key, 'footprints.php')) {
     } elseif (!strncmp(substr($key, -9), 'index.php', 9) && ($content = Safe::file_get_contents($node)) && !strcmp($content, Safe::mkdir_index_content())) {
     } elseif (!strncmp($key, 'temporary/cache_i18n_locale_', 28)) {
     } elseif (!strncmp(substr($key, -4), '.php', 4)) {
         // one of the parameter files created by yacs
         if (preg_match('/parameters\\/(agents|control|feeds|files|hooks|letters|root|scripts|services|skins|users|virtual_.+)\\.include\\.php$/i', $key)) {
         } elseif (isset($footprints[$key])) {
             $expected = $footprints[$key];
             $actual = Scripts::hash($node);
             if ($expected[0] != $actual[0] || $expected[1] != $actual[1]) {
                 $context['text'] .= sprintf(i18n::s('ERROR: File %s is missing or corrupted.'), $key) . BR . "\n";
             }
         } else {
             $context['text'] .= sprintf(i18n::s('File %s is not part of Yacs.'), $key) . BR . "\n";
         }
         // not a safe file
     } elseif (!preg_match('/\\.(bak|bat|css|done|dtd|fdb|flv|gif|ico|jpeg|jpg|js|jsmin|htc|htm|html|mo|off|on|pdf|png|po|pot|reg|sh|sql|swf|tgz|txt|xml|zip)$/i', $key)) {
         $context['text'] .= sprintf(i18n::s('File %s is not part of Yacs.'), $key) . BR . "\n";
     }
 }
예제 #2
0
파일: code_graphviz.php 프로젝트: rair/yacs
 /**
  * render graphviz object
  *
  * @return string the rendered text
  **/
 public function render($matches)
 {
     global $context;
     list($text, $variant) = $matches;
     // sanity check
     if (!$text) {
         $text = 'Hello->World!';
     }
     // remove tags put by WYSIWYG editors
     $text = strip_tags(str_replace(array('&gt;', '&lt;', '&amp;', '&quot;', '\\"'), array('>', '<', '&', '"', '"'), str_replace(array('<br />', '</p>'), "\n", $text)));
     // build the .dot content
     switch ($variant) {
         case 'digraph':
         default:
             $text = 'digraph G { ' . $text . ' }' . "\n";
             break;
     }
     // id for this object
     $hash = md5($text);
     // path to cached files
     $path = $context['path_to_root'] . 'temporary/graphviz.';
     // we cache content
     if ($content = Safe::file_get_contents($path . $hash . '.html')) {
         return $content;
     }
     // build a .dot file
     if (!Safe::file_put_contents($path . $hash . '.dot', $text)) {
         $content = '[error writing .dot file]';
         return $content;
     }
     // process the .dot file
     if (isset($context['dot.command'])) {
         $command = $context['dot.command'];
     } else {
         $command = 'dot';
     }
     //		$font = '"/System/Library/Fonts/Times.dfont"';
     //		$command = '/sw/bin/dot -v -Nfontname='.$font
     $command .= ' -Tcmapx -o "' . $path . $hash . '.map"' . ' -Tpng -o "' . $path . $hash . '.png"' . ' "' . $path . $hash . '.dot"';
     if (Safe::shell_exec($command) == NULL) {
         $content = '[error while using graphviz]';
         return $content;
     }
     // produce the HTML
     $content = '<img src="' . $context['url_to_root'] . 'temporary/graphviz.' . $hash . '.png" usemap="#mainmap" />';
     $content .= Safe::file_get_contents($path . $hash . '.map');
     // put in cache
     Safe::file_put_contents($path . $hash . '.html', $content);
     // done
     return $content;
 }
예제 #3
0
 /**
  * check access rights
  *
  * @param string script name
  * @paral string target anchor, if any
  * @return boolean FALSE if access is denied, TRUE otherwise
  */
 function allow($script, $anchor = NULL)
 {
     global $context;
     // limit the scope of our check
     if ($script != 'files/view.php' && $script != 'files/fetch.php' && $script != 'files/fetch_all.php' && $script != 'files/stream.php') {
         return TRUE;
     }
     // sanity check
     if (!$anchor) {
         die(i18n::s('No anchor has been found.'));
     }
     // stop here if the agreement has been gathered previously
     if (isset($_SESSION['agreements']) && is_array($agreements = $_SESSION['agreements'])) {
         foreach ($agreements as $agreement) {
             if ($agreement == $anchor) {
                 return TRUE;
             }
         }
     }
     // which agreement?
     if (!$this->parameters) {
         die(sprintf(i18n::s('No parameter has been provided to %s'), 'behaviors/agree_on_file_access'));
     }
     // do we have a related file to display?
     if (!is_readable($context['path_to_root'] . 'behaviors/agreements/' . $this->parameters)) {
         die(sprintf(i18n::s('Bad parameter to behavior <code>%s %s</code>'), 'agree_on_file_access', $this->parameters));
     }
     // splash message
     $context['text'] .= '<p class="agreement">' . i18n::s('Before moving forward, please read following text and express yourself at the end of the page.') . '</p><hr/>' . "\n";
     // load and display the file to be displayed
     $context['text'] .= Codes::beautify(Safe::file_get_contents($context['path_to_root'] . 'behaviors/agreements/' . $this->parameters));
     // target link to record agreement
     if ($context['with_friendly_urls'] == 'Y') {
         $agree_link = 'behaviors/agreements/agree.php/' . rawurlencode($anchor);
     } else {
         $agree_link = 'behaviors/agreements/agree.php?id=' . urlencode($anchor);
     }
     // display confirmation buttons at the end of the agreement
     $context['text'] .= '<hr/><p class="agreement">' . i18n::s('Do you agree?');
     $context['text'] .= ' ' . Skin::build_link($agree_link, i18n::s('Yes'), 'button');
     $context['text'] .= ' ' . Skin::build_link('behaviors/agreements/deny.php', i18n::s('No'), 'button') . '</p>' . "\n";
     // render the skin based only on text provided by this behavior
     render_skin();
     exit;
 }
예제 #4
0
파일: build.php 프로젝트: rair/yacs
 // start the zip file
 include_once '../shared/zipfile.php';
 $zipfile = new zipfile();
 // place all files into a single directory --fixed time to allow cacheability
 $zipfile->store('yacs/', 0);
 // process every reference file
 $all_files = array();
 $index = 0;
 foreach ($references as $reference) {
     // let's go
     list($path, $file) = $reference;
     if (strlen(trim($path)) > 0) {
         $file = $path . '/' . $file;
     }
     // read file content
     if (($content = Safe::file_get_contents($file_path . $file)) !== FALSE) {
         // compress textual content
         if ($content && preg_match('/\\.(css|htc|htm|html|include|js|mo|php|po|pot|sql|txt|xml)$/i', $file)) {
             $zipfile->deflate('yacs/' . $file, Safe::filemtime($file_path . $file), $content);
         } else {
             $zipfile->store('yacs/' . $file, Safe::filemtime($file_path . $file), $content);
         }
         // to be included in tar file as well
         $all_files[] = $file_path . $file;
     } else {
         $context['text'] .= BR . 'cannot read ' . $file_path . $file;
     }
     // avoid timeouts
     if (!($index++ % 50)) {
         Safe::set_time_limit(30);
         SQL::ping();
예제 #5
0
파일: fetch_all.php 프로젝트: rair/yacs
    Logger::error(i18n::s('You are not allowed to perform this operation.'));
    // package the files
} else {
    // build a zip archive
    include_once '../shared/zipfile.php';
    $zipfile = new zipfile();
    // get related files from the database
    $items = array();
    if (isset($type) && isset($id)) {
        $items = Files::list_by_date_for_anchor($type . ':' . $id, 0, 20, 'raw');
    }
    // archive each file
    $file_path = $context['path_to_root'] . Files::get_path($type . ':' . $id);
    foreach ($items as $id => $attributes) {
        // read file content
        if ($content = Safe::file_get_contents($file_path . '/' . $attributes['file_name'], 'rb')) {
            // add the binary data
            $zipfile->deflate($attributes['file_name'], Safe::filemtime($file_path . '/' . $attributes['file_name']), $content);
        }
    }
    //
    // transfer to the user agent
    //
    // send the archive content
    if ($archive = $zipfile->get()) {
        // suggest a download
        Safe::header('Content-Type: application/octet-stream');
        // suggest a name for the saved file
        $file_name = utf8::to_ascii($item['title']) . '.zip';
        Safe::header('Content-Disposition: attachment; filename="' . str_replace('"', '', $file_name) . '"');
        // file size
예제 #6
0
파일: setup.php 프로젝트: rair/yacs
    // to the control panel
    $context['text'] .= '<p><a href="control/">' . i18n::s('Control Panel') . "</a></p>\n";
    // end of the installation
} elseif (!file_exists('parameters/switch.on') && !file_exists('parameters/switch.off')) {
    // create the switch
    $content = '---------------------------------------------' . "\n" . 'YACS will process requests if this file is named switch.on,' . "\n" . 'and will redirect everything to control/closed.php if its name is changed to switch.off.' . "\n" . "\n" . 'Associates can use the script control/switch.php to stop and restart remotely.' . "\n" . '---------------------------------------------' . "\n";
    if (!Safe::file_put_contents('parameters/switch.on', $content)) {
        // not enough rights to write the file
        Logger::error(i18n::s('ERROR: YACS cannot create the file parameters/switch.on to activate the server.'));
        // allow for a manual update
        $context['text'] .= '<p style="text-decoration: blink;">' . sprintf(i18n::s('To actually switch on the server, please copy and paste following lines by yourself in file %s.'), 'parameters/switch.on') . "</p>\n";
        // content of the switch file
        $context['text'] .= '<pre>' . $content . "</pre>\n";
    }
    // if there is no index at the upper level
    if (!file_exists($context['path_to_root'] . '../index.php') && ($content = Safe::file_get_contents($context['path_to_root'] . 'index.php'))) {
        // silently attempt to duplicate our index
        Safe::file_put_contents('../index.php', $content);
        // remember this for the next incremental update
        $content = '<?php' . "\n" . '// This file has been created by the setup script setup.php' . "\n" . '// on ' . gmdate("F j, Y, g:i a") . ' GMT, for ' . Surfer::get_name() . '. Please do not modify it manually.' . "\n" . '$context[\'home_at_root\']=\'Y\';' . "\n" . '$context[\'reference_server\']=\'' . addcslashes(i18n::s('www.yacs.fr'), "\\'") . "';\n" . '?>' . "\n";
        Safe::file_put_contents('parameters/scripts.include.php', $content);
    }
    // the splash message
    $context['text'] .= sprintf(i18n::s("<p>You have passed through the several installation steps.</p>\nWhat do you want to do now?<ul>\n<li>Select %s for your site.</li>\n<li>Populate your site with the %s.</li>\n<li>Manage everything from the %s.</li>\n<li>Check the %s of this site.</li>\n<li>Review %s.</li>\n<li>%s.</li>\n<li>Look at the %s.</li>\n<li>Visit %s to learn more.</li>\n</ul>\n<p>Thank you for having selected to use YACS for your web site.</p>\n"), Skin::build_link('skins/', i18n::s('another skin')), Skin::build_link('help/populate.php', i18n::s('Content Assistant')), Skin::build_link('control/', i18n::s('Control Panel')), Skin::build_link($context['url_to_root'], i18n::s('front page')), Skin::build_link('users/view.php', i18n::s('your profile')), Skin::build_link('articles/edit.php', i18n::s('Add a page')), Skin::build_link('help/', i18n::s('Help index')), Skin::build_link(i18n::s('http://www.yacs.fr/'), i18n::s('www.yacs.fr'), 'external')) . "\n";
    // no need for installation
} else {
    // the splash message
    $context['text'] .= i18n::s('<p>Since basic configuration files exist on your server, it is likely that the installation has been achieved successfully. Click on the link below to modify the running parameters of your server.</p>') . "\n";
    // to the control panel
    $context['text'] .= '<p><a href="control/">' . i18n::s('Control Panel') . "</a></p>\n";
}
예제 #7
0
파일: files.php 프로젝트: rair/yacs
 /**
  * adapt GanttProject file to SIMILE Timeline format
  *
  * @param string file location
  * @return string transformation result, or FALSE
  */
 public static function transform_gan_to_simile($file_path)
 {
     global $context;
     // load the file
     $content = Safe::file_get_contents($file_path);
     // used by parsing functions
     $context['gan2simile'] = array();
     $context['gan2simile']['depth'] = 0;
     $context['gan2simile']['tasks'] = array();
     $context['gan2simile']['last_id'] = 0;
     $context['gan2simile']['current_id'] = 0;
     // one tag at a time
     function g2s_startElement($parser, $name, $attrs)
     {
         global $context;
         // remember task basic attributes
         if (!strcmp($name, 'TASK')) {
             if ($context['gan2simile']['depth'] < 5) {
                 // flag duration if not milestone
                 if ($attrs['DURATION'] > 0) {
                     $duration = TRUE;
                 } else {
                     $duration = FALSE;
                 }
                 // remember this task
                 $context['gan2simile']['tasks'][$attrs['ID']] = array('title' => $attrs['NAME'], 'start' => $attrs['START'], 'duration' => $attrs['DURATION'], 'complete' => $attrs['COMPLETE'], 'isDuration' => $duration, 'notes' => '');
                 $context['gan2simile']['current_id'] = $attrs['ID'];
                 // move to children
                 if (!$context['gan2simile']['depth']) {
                     $context['gan2simile']['last_id'] = $attrs['ID'];
                 }
             }
             $context['gan2simile']['depth']++;
         }
     }
     // close a tag
     function g2s_endElement($parser, $name)
     {
         global $context;
         // we check only tasks
         if (!strcmp($name, 'TASK')) {
             $context['gan2simile']['depth']--;
         }
     }
     // parse the GAN file
     $xml_parser = xml_parser_create();
     xml_set_element_handler($xml_parser, "g2s_startElement", "g2s_endElement");
     if (!xml_parse($xml_parser, $content, TRUE)) {
         die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)));
     }
     xml_parser_free($xml_parser);
     // the resulting text
     $text = '<?xml version="1.0" encoding="' . $context['charset'] . '"?>' . "\n" . '<data>' . "\n";
     // process each task
     foreach ($context['gan2simile']['tasks'] as $task) {
         // transcode start date
         $start = strtotime($task['start']);
         // format start date as per SIMILE expectation
         $task['start'] = date('M j Y G:i:s', $start) . ' GMT';
         // which day in week?
         $info = getdate($start);
         // add two days for the first week-end
         if ($info['wday'] > 0 && $info['wday'] < 6 && $info['wday'] + $task['duration'] > 6) {
             $task['duration'] += 2;
         }
         // take week-ends into consideration
         $task['duration'] += intval($task['duration'] / 7) * 2;
         // compute and format end date date as per SIMILE expectation
         $end = $start + $task['duration'] * 24 * 60 * 60;
         $task['end'] = date('M j Y G:i:s', $end) . ' GMT';
         $earliestEnd = ' earliestEnd="' . $task['start'] . '"';
         if ($task['complete'] > 0) {
             // from percentage to number of days
             $task['complete'] = intval($task['complete'] * $task['duration'] / 100);
             // add two days for the first week-end
             if ($info['wday'] > 0 && $info['wday'] < 6 && $info['wday'] + $task['complete'] > 6) {
                 $task['complete'] += 2;
             }
             // take week-ends into consideration
             $task['complete'] += intval($task['complete'] / 7) * 2;
             // current completion
             $end = $start + $task['complete'] * 24 * 60 * 60;
             $earliestEnd = ' earliestEnd="' . date('M j Y G:i:s', $end) . ' GMT"';
         }
         // has this one several children?
         $duration = '';
         if ($task['isDuration']) {
             $duration = ' isDuration="true"';
         }
         // one event per task
         $text .= '	<event title="' . encode_field(str_replace(array("&nbsp;", '"'), ' ', $task['title'])) . '" start="' . $task['start'] . '"' . $earliestEnd . ' end="' . $task['end'] . '" ' . $duration . '/>' . "\n";
     }
     // no more events
     $text .= '</data>';
     // job done
     return $text;
 }
예제 #8
0
파일: derive.php 프로젝트: rair/yacs
 // 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++;
     }
     // copy the file
 } elseif (!Safe::copy($context['path_to_root'] . $origin, $context['path_to_root'] . $target)) {
예제 #9
0
파일: jsmin.php 프로젝트: rair/yacs
         if ($text = Safe::file_get_contents($name)) {
             // actual compression
             if (!preg_match('/\\.min\\./', basename($name))) {
                 $minified .= JSMin::minify($text);
             } else {
                 $minified .= $text;
             }
             // one file has been compressed
             $count++;
         }
     }
 }
 // include shared/yacs.js library
 if (file_exists($context['path_to_root'] . 'shared/yacs.js')) {
     $context['text'] .= 'shared/yacs.js' . BR . "\n";
     $text = Safe::file_get_contents($context['path_to_root'] . 'shared/yacs.js');
     $minified .= JSMin::minify($text);
     $count++;
 }
 // save the library to call in page footer
 $file_min = $context['path_to_root'] . 'included/browser/library_js_endpage.min.js';
 if ($minified) {
     Safe::file_put_contents($file_min, $minified);
 } else {
     Safe:
     unlink($file_min);
 }
 // do the same in included/calendar
 /* if($names = Safe::glob($context['path_to_root'].'included/jscalendar/*.js')) {
 		foreach($names as $name) {
 
예제 #10
0
// process every file
$count = 0;
foreach ($copy as $file) {
    // content of the updated file
    $content = '';
    // expected location in staging repository
    $local_reference = $context['path_to_root'] . 'scripts/staging/' . $file;
    // don't execute PHP scripts, just get them
    if (preg_match('/\\.php$/i', $file)) {
        $remote_reference = 'http://' . $context['reference_server'] . '/scripts/fetch.php?script=' . urlencode($file);
    } else {
        $remote_reference = 'http://' . $context['reference_server'] . '/scripts/reference/' . $file;
    }
    // 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
예제 #11
0
파일: virtual.php 프로젝트: rair/yacs
        $label = sprintf(i18n::c('%s has been created'), $target);
        Logger::remember('control/virtual.php: ' . $label);
    }
    $context['text'] .= Skin::build_box(i18n::s('Configuration'), Safe::highlight_string($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' => 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');
    // view one configuration file
} elseif ($id && $action == 'view') {
    // file has to exist
    $file = 'parameters/virtual_' . $id . '.include.php';
    if (!($content = Safe::file_get_contents($context['path_to_root'] . $file))) {
        Logger::error(i18n::s('No configuration file has been found for this virtual host.'));
    } elseif (file_exists('../parameters/switch.on') || file_exists('../parameters/switch.off')) {
        $context['text'] .= Skin::build_box(i18n::s('Configuration'), Safe::highlight_string($content), 'unfolded');
    } else {
        $context['text'] .= Safe::highlight_string($content);
    }
    // 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) . '&action=edit' => i18n::s('Edit configuration')));
    $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');
    // no action has been triggered so far
예제 #12
0
파일: fetch.php 프로젝트: rair/yacs
    $context['page_title'] = $script;
} else {
    $context['page_title'] = i18n::s('Please indicate a script name.');
}
// no argument has been passed
if (!$script) {
    $context['text'] .= '<p>' . i18n::s('Please indicate a script name.') . "</p>\n";
} else {
    // the separator
    $separator = '----------------------- aqwzsxedcrfvtgbyhnujikolpm ---------------------------' . "\n";
    // the output
    $text = '';
    // one script at a time
    foreach ($script as $name) {
        // read the file from the reference store
        if (!($content = Safe::file_get_contents($context['path_to_root'] . 'scripts/reference/' . $name))) {
            Safe::header('Status: 404 Not Found', TRUE, 404);
            exit('File "' . 'scripts/reference/' . $name . '" not found');
        }
        // happen this to the output buffer
        if ($text) {
            $text .= $separator;
        }
        $text .= $content;
    }
    // only one script has been asked
    if (count($script) == 1) {
        // compress the page if possible, but no transcoding -- the bare handler
        $context['charset'] = 'ASCII';
        render_raw('text/x-httpd-php');
        // send the response to the caller
예제 #13
0
파일: mailer.php 프로젝트: rair/yacs
 /**
  * build and transmit a complex e-mail messages
  *
  * This function allows for individual posts, textual and HTML messages, and attached files.
  *
  * For this to work, e-mail service has to be explicitly activated in the
  * main configuration panel, at [script]control/configure.php[/script].
  *
  * You can refer to local images in HTML parts, and the function will automatically attach these
  * to the message, else mail clients would not display them correctly.
  *
  * The message actually sent has a complex structure, with several parts assembled together,
  * as [explained at altepeter.net|http://altepeter.net/tech/articles/html-emails].
  *
  * @link http://altepeter.net/tech/articles/html-emails
  *
  * Several recipients can be provided as a list of addresses separated by
  * commas. For bulk posts, recipients can be transmitted as an array of strings.
  * In all cases, this function sends one separate message per recipient.
  *
  * This function will ensure that only one mail message is send to a recipient,
  * by maintaining an internal list of addresses that have been processed.
  * Therefore, if this function is called several times, with some repeated recipients,
  * those will receive only the first message, and other messages to the same address
  * will be dropped.
  *
  * Bracketed recipients, such as ##Foo Bar <*****@*****.**>##, are handled properly,
  * meaning ##foo@bar.com## is transmitted to the mailing function, while
  * the string ##To: Foo Bar <*****@*****.**>## is added to headers.
  *
  * If an array of messages is provided to the function, it is turned to a multi-part
  * message, as in the following example:
  *
  * [php]
  * $message = array();
  * $message['text/plain; charset=utf-8'] = 'This is a plain message';
  * $message['text/html'] = '<html><head><body>This is an HTML message</body></html>';
  * Mailer::post($from, $to, $subject, $message);
  * [/php]
  *
  * It is recommended to begin with the bare text, and to have the rich format part coming
  * after, as in the example. Also, if you don't provide a charset, then UTF-8 is used.
  *
  * Long lines of text/plain parts are wrapped according to
  * [link=Dan's suggestion]http://mailformat.dan.info/body/linelength.html[/link].
  *
  * @link http://mailformat.dan.info/body/linelength.html Dan's Mail Format Site: Body: Line Length
  *
  * Message parts are encoded either as quoted-printable (textual entities) or as base-64 (others).
  *
  * A list of files to be attached to the message can be provided as in the following example:
  *
  * [php]
  * $attachments = array();
  * $attachments[] = 'special/report.pdf';
  * $attachments[] = 'skins/my_skin/newsletters/image.png';
  * Mailer::post($from, $to, $subject, $message, $attachments);
  * [/php]
  *
  * Files are named from the installation directory of yacs, as visible in the examples.
  *
  * This function returns the number of successful posts,
  * and populates the error context, where applicable.
  *
  * @param string sender address
  * @param mixed recipient address(es)
  * @param string subject
  * @param mixed actual message, either a string, or an array of message parts
  * @param array attachments, if any
  * @param mixed additional headers, if any
  * @return the number of actual posts, or 0
  *
  * @see articles/mail.php
  * @see letters/new.php
  * @see users/mail.php
  */
 public static function post($from, $to, $subject, $message, $attachments = NULL, $headers = '')
 {
     global $context;
     // ensure that we have a sender
     if (!$from) {
         $from = Mailer::get_from_recipient();
     }
     // email services have to be activated
     if (!isset($context['with_email']) || $context['with_email'] != 'Y') {
         Logger::error(i18n::s('E-mail has not been enabled on this system.'));
         return 0;
         // check sender address
     } elseif (!$from) {
         Logger::error(i18n::s('Empty sender address'));
         return 0;
         // check recipient address
     } elseif (!$to) {
         Logger::error(i18n::s('Empty recipient address'));
         return 0;
         // check mail subject
     } elseif (!$subject) {
         Logger::error(i18n::s('No subject'));
         return 0;
         // check mail content
     } elseif (!$message) {
         Logger::error(i18n::s('No message'));
         return 0;
     }
     // the end of line string for mail messages
     if (!defined('M_EOL')) {
         define('M_EOL', "\n");
     }
     // encode the subject line
     $subject = Mailer::encode_subject($subject);
     // make some text out of an array
     if (is_array($headers)) {
         $headers = implode(M_EOL, $headers);
     }
     // From: header
     if (!preg_match('/^From: /im', $headers)) {
         $headers .= M_EOL . 'From: ' . $from;
     }
     // Reply-To: header
     if (!preg_match('/^Reply-To: /im', $headers)) {
         $headers .= M_EOL . 'Reply-To: ' . $from;
     }
     // Return-Path: header --to process errors
     if (!preg_match('/^Return-Path: /im', $headers)) {
         $headers .= M_EOL . 'Return-Path: ' . $from;
     }
     // Message-ID: header --helps to avoid spam filters
     if (!preg_match('/^Message-ID: /im', $headers)) {
         $headers .= M_EOL . 'Message-ID: <uniqid.' . uniqid() . '@' . $context['host_name'] . '>';
     }
     // MIME-Version: header
     if (!preg_match('/^MIME-Version: /im', $headers)) {
         $headers .= M_EOL . 'MIME-Version: 1.0';
     }
     // arrays are easier to manage
     if (is_string($message)) {
         // turn HTML entities to UTF-8
         $message = Safe::html_entity_decode($message, ENT_QUOTES, 'UTF-8');
         $copy = $message;
         $message = array();
         $message['text/plain; charset=utf-8'] = $copy;
         unset($copy);
     }
     // turn attachments to some array too
     if (is_string($attachments)) {
         $attachments = array($attachments);
     } elseif (!is_array($attachments)) {
         $attachments = array();
     }
     // we only consider objects from this server
     $my_prefix = $context['url_to_home'] . $context['url_to_root'];
     // transcode objects that will be transmitted along the message (i.e., images)
     foreach ($message as $type => $part) {
         // search throughout the full text
         $head = 0;
         while ($head = strpos($part, ' src="', $head)) {
             $head += strlen(' src="');
             // a link has been found
             if ($tail = strpos($part, '"', $head + 1)) {
                 $reference = substr($part, $head, $tail - $head);
                 // remember local links only
                 if (!strncmp($reference, $my_prefix, strlen($my_prefix))) {
                     // local name
                     $name = urldecode(substr($reference, strlen($my_prefix)));
                     // content-id to be used instead of the link
                     $cid = sprintf('%u@%s', crc32($name), $context['host_name']);
                     // transcode the link in this part
                     $part = substr($part, 0, $head) . 'cid:' . $cid . substr($part, $tail);
                     // remember to put content in attachments of this message, if not done yet
                     if (!in_array($name, $attachments)) {
                         $attachments[] = $name;
                     }
                 }
             }
         }
         // remember the transcoded part
         $message[$type] = $part;
     }
     // we need some boundary string
     if (count($message) + count($attachments) > 1) {
         $boundary = md5(time());
     }
     // wrapping threshold
     if (!defined('WRAPPING_LENGTH')) {
         define('WRAPPING_LENGTH', 70);
     }
     // combine message parts
     $content_type = '';
     $body = '';
     foreach ($message as $type => $part) {
         // quote textual entities
         if (!strncmp($type, 'text/', 5)) {
             $content_encoding = 'quoted-printable';
             $part = quoted_printable_encode($part);
             // encode everything else
         } else {
             $content_encoding = 'base64';
             $part = chunk_split(base64_encode($content), 76, M_EOL);
         }
         // only one part
         if (count($message) == 1) {
             $content_type = $type;
             $body = $part;
             // one part among several
         } else {
             // let user agent select among various alternatives
             if (!$content_type) {
                 $content_type = 'multipart/alternative; boundary="' . $boundary . '-internal"';
             }
             // introduction to assembled parts
             if (!$body) {
                 $body = 'This is a multi-part message in MIME format.';
             }
             // this part only --second EOL is part of the boundary chain
             $body .= M_EOL . M_EOL . '--' . $boundary . '-internal' . M_EOL . 'Content-Type: ' . $type . M_EOL . 'Content-Transfer-Encoding: ' . $content_encoding . M_EOL . M_EOL . $part;
         }
     }
     // finalize the body
     if (count($message) > 1) {
         $body .= M_EOL . M_EOL . '--' . $boundary . '-internal--';
     }
     // a mix of things
     if (count($attachments)) {
         // encoding is irrelevant if there are multiple parts
         if (!strncmp($content_type, 'multipart/', 10)) {
             $content_encoding = '';
         } else {
             $content_encoding = M_EOL . 'Content-Transfer-Encoding: ' . $content_encoding;
         }
         // identify the main part of the overall message
         $content_start = 'mainpart';
         // the current body becomes the first part of a larger message
         $body = 'This is a multi-part message in MIME format.' . M_EOL . M_EOL . '--' . $boundary . '-external' . M_EOL . 'Content-Type: ' . $content_type . $content_encoding . M_EOL . 'Content-ID: <' . $content_start . '>' . M_EOL . M_EOL . $body;
         // message parts should be considered as an aggregate whole --see RFC 2387
         $content_type = 'multipart/related; type="multipart/alternative"; boundary="' . $boundary . '-external"';
         $content_encoding = '';
         // process every file
         foreach ($attachments as $name => $content) {
             // read external file content
             if (preg_match('/^[0-9]+$/', $name)) {
                 // only a file name has been provided
                 $name = $content;
                 // read file content from the file system
                 if (!($content = Safe::file_get_contents($name))) {
                     continue;
                 }
             }
             // file name is the file type
             if (preg_match('/name="(.+)?"/', $name, $matches)) {
                 $type = $name;
                 $name = $matches[1];
             } else {
                 $type = Files::get_mime_type($name);
             }
             // a unique id for for this file
             $cid = sprintf('%u@%s', crc32($name), $context['host_name']);
             // set a name that avoids problems
             $basename = utf8::to_ascii(basename($name));
             // headers for one file
             $body .= M_EOL . M_EOL . '--' . $boundary . '-external' . M_EOL . 'Content-Type: ' . $type . M_EOL . 'Content-Disposition: inline; filename="' . str_replace('"', '', $basename) . '"' . M_EOL . 'Content-ID: <' . $cid . '>';
             // transfer textual entities as they are
             if (!strncmp($type, 'text/', 5)) {
                 $body .= M_EOL . 'Content-Transfer-Encoding: quoted-printable' . M_EOL . M_EOL . quoted_printable_encode($content);
                 // encode everything else
             } else {
                 $body .= M_EOL . 'Content-Transfer-Encoding: base64' . M_EOL . M_EOL . chunk_split(base64_encode($content), 76, M_EOL);
             }
         }
         // the closing boundary
         $body .= M_EOL . M_EOL . '--' . $boundary . '-external--';
     }
     // Content-Type: header
     if ($content_type && !preg_match('/^Content-Type: /im', $headers)) {
         $headers .= M_EOL . 'Content-Type: ' . $content_type;
     }
     // Content-Transfer-Encoding: header
     if (!isset($boundary) && $content_encoding && !preg_match('/^Content-Transfer-Encoding: /im', $headers)) {
         $headers .= M_EOL . 'Content-Transfer-Encoding: ' . $content_encoding;
     }
     // Start: header
     if (isset($boundary) && isset($content_start) && $content_start && !preg_match('/^Start: /im', $headers)) {
         $headers .= M_EOL . 'Start: ' . $content_start;
     }
     // X-Mailer: header --helps to avoid spam filters
     if (!preg_match('/^X-Mailer: /im', $headers)) {
         $headers .= M_EOL . 'X-Mailer: yacs';
     }
     // strip leading spaces and newlines
     $headers = trim($headers);
     // make an array of recipients
     if (!is_array($to)) {
         $to = Mailer::explode_recipients($to);
     }
     // the list of recipients contacted during overall script execution
     if (!isset($context['mailer_recipients'])) {
         $context['mailer_recipients'] = array();
     }
     // process every recipient
     $posts = 0;
     foreach ($to as $recipient) {
         // clean the provided string
         $recipient = trim(str_replace(array("\r\n", "\r", "\n", "\t"), ' ', $recipient));
         // this e-mail address has already been processed
         if (in_array($recipient, $context['mailer_recipients'])) {
             if (isset($context['debug_mail']) && $context['debug_mail'] == 'Y') {
                 Logger::remember('shared/mailer.php: Skipping recipient already processed', $recipient, 'debug');
             }
             continue;
             // remember this recipient
         } else {
             $context['mailer_recipients'][] = $recipient;
         }
         // queue the message
         Mailer::queue($recipient, $subject, $body, $headers);
         $posts++;
     }
     // track last submission
     include_once $context['path_to_root'] . 'shared/values.php';
     Values::set('mailer.last.queued', $subject . ' (' . $posts . ' recipients)');
     // return the number of actual posts
     return $posts;
 }
예제 #14
0
파일: scan.php 프로젝트: rair/yacs
        $context['text'] .= Skin::build_block('<form method="post" action="setup.php"><p class="assistant_bar">' . "\n" . Skin::build_submit_button(i18n::s('Database maintenance')) . "\n" . '<input type="hidden" name="action" value="build" />' . "\n" . '</p></form>', 'bottom');
        // this may take several minutes
        $context['text'] .= '<p>' . i18n::s('When you will click on the button the server will be immediately requested to proceed. However, because of the so many things to do on the back-end, you may have to wait for minutes before getting a response displayed. Thank you for your patience.') . '</p>';
        // create the database on first installation
    } elseif (!file_exists('../parameters/switch.on')) {
        $context['text'] .= Skin::build_block('<form method="post" action="setup.php"><p class="assistant_bar">' . "\n" . Skin::build_submit_button(i18n::s('Create tables in the database')) . "\n" . '<input type="hidden" name="action" value="build" />' . "\n" . '</p></form>', 'bottom');
        // this may take several minutes
        $context['text'] .= '<p>' . i18n::s('When you will click on the button the server will be immediately requested to proceed. However, because of the so many things to do on the back-end, you may have to wait for minutes before getting a response displayed. Thank you for your patience.') . '</p>';
        // or back to the control panel
    } else {
        $menu = array('control/' => i18n::s('Control Panel'), 'control/setup.php' => i18n::s('Database maintenance'));
        $context['text'] .= Skin::build_list($menu, 'menu_bar');
    }
    // display current hooks
} else {
    // the splash message
    $context['text'] .= i18n::s('This script will scan your php scripts to install software hooks.');
    // the submit button
    $context['text'] .= '<form method="post" action="' . $context['script_url'] . '" id="main_form"><p>' . Skin::build_submit_button(i18n::s('Scan scripts for software extensions'), NULL, NULL, 'confirmed') . '<input type="hidden" name="action" value="check" />' . '</p></form>';
    // the script used for form handling at the browser
    Page::insert_script('$("#confirmed").focus();');
    // this may take several minutes
    $context['text'] .= '<p>' . i18n::s('When you will click on the button the server will be immediately requested to proceed. However, because of the so many things to do on the back-end, you may have to wait for minutes before getting a response displayed. Thank you for your patience.') . '</p>';
    // display the existing hooks configuration file, if any
    $content = Safe::file_get_contents('../parameters/hooks.include.php');
    if (strlen($content)) {
        $context['text'] .= Skin::build_box(sprintf(i18n::s('Current content of %s'), 'parameters/hooks.include.php'), Safe::highlight_string($content), 'folded');
    }
}
// render the skin
render_skin();
예제 #15
0
파일: backup.php 프로젝트: rair/yacs
 $context['text'] .= '<p>' . i18n::s('On-going archive preparation...') . '</p>' . "\n";
 // build a zip archive
 include_once '../shared/zipfile.php';
 $zipfile = new zipfile();
 // process every skin/current_skin/ file
 $index = 0;
 foreach ($datafiles as $datafile) {
     // let's go
     list($path, $filename) = $datafile;
     if ($path) {
         $file = $path . '/' . $filename;
     } else {
         $file = $filename;
     }
     // read file content
     if (($content = Safe::file_get_contents($file_prefix . $file)) !== FALSE) {
         // store binary data
         $zipfile->store($file, Safe::filemtime($file_prefix . $file), $content);
         // avoid timeouts
         if (!($index++ % 50)) {
             Safe::set_time_limit(30);
             SQL::ping();
         }
     }
 }
 // suggest a download
 Safe::header('Content-Type: application/zip');
 Safe::header('Content-Disposition: attachment; filename="backup_' . $context['skin'] . '.zip"');
 // send the archive content
 echo $zipfile->get();
 // do not allow for regular rendering
예제 #16
0
파일: browse.php 프로젝트: rair/yacs
// the title of the page
if ($script && $store == 'reference') {
    $context['page_title'] = sprintf(i18n::s('Reference script: %s'), $script);
} elseif ($script && $store == 'staging') {
    $context['page_title'] = sprintf(i18n::s('Staging script: %s'), $script);
} else {
    $context['page_title'] = i18n::s('Script view');
}
// no script has been provided
if (!$script) {
    Logger::error(i18n::s('No script has been provided.'));
} elseif (!file_exists($translated)) {
    Logger::error(i18n::s('Script does not exist.'));
} else {
    // lookup for information inside the file
    $content = Safe::file_get_contents($translated);
    // protect from spammers and robots
    $content = preg_replace('/\\[email\\].+\\[\\/email\\]/i', '', $content);
    // highlight php code
    $context['text'] .= "\n" . Codes::render_pre($content);
    // menu bar for reference scripts
    if ($content && $store == 'reference') {
        // browsing is safe
        $context['page_tools'][] = Skin::build_link(Scripts::get_url($script, 'view'), i18n::s('View the documentation page'));
        // protect from spammers and robots
        if (Surfer::is_logged()) {
            $context['page_tools'][] = Skin::build_link(Scripts::get_url($script, 'fetch'), i18n::s('Fetch the script file'));
        }
    }
}
// render the skin
예제 #17
0
파일: import.php 프로젝트: rair/yacs
    // process uploaded data
} elseif (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'POST') {
    // no file has been uploaded
    if (!$_FILES['upload']['name'] || $_FILES['upload']['name'] == 'none') {
        Logger::error(i18n::s('Nothing has been received.'));
        // process the temporary file
    } else {
        // access the temporary uploaded file
        $file_upload = $_FILES['upload']['tmp_name'];
        // zero bytes transmitted
        $_REQUEST['file_size'] = $_FILES['upload']['size'];
        if (!$_FILES['upload']['size']) {
            Logger::error(i18n::s('Nothing has been received.'));
        } elseif (!Safe::is_uploaded_file($file_upload)) {
            Logger::error(i18n::s('Possible file attack.'));
        } elseif (!($content = ltrim(Safe::file_get_contents($file_upload)))) {
            Logger::error(sprintf(i18n::s('Impossible to read %s.'), $file_upload));
        } else {
            // parsing an overlay, or not
            global $in_overlay;
            $in_overlay = FALSE;
            // class of the overlay to use
            global $overlay_class;
            $overlay_class = NULL;
            // overlay parameters
            global $overlay_parameters;
            $overlay_parameters = '';
            // opening a new tag
            function parse_tag_open($parser, $tag, $attributes)
            {
                global $in_overlay, $overlay_class, $overlay_parameters;
예제 #18
0
파일: faceme.php 프로젝트: rair/yacs
        if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'HEAD') {
            echo Safe::json_encode($result);
        }
        // the post-processing hook
        finalize_page();
        return;
    }
    // some error has occured
    Safe::header('Status: 500 Internal Error', TRUE, 500);
    die(Logger::error_pop());
    // retrieve session data through AJAX call
} elseif (isset($_REQUEST['describe_session'])) {
    // we need some session id
    if (!$id) {
        Logger::error(sprintf('OpenTok: %s', 'no session id has been provided'));
    } elseif (!($data = Safe::file_get_contents($context['path_to_root'] . 'temporary/faceme.txt'))) {
        Logger::error(i18n::s('The service is not available'));
    } elseif (($head = strpos($data, $id)) === FALSE) {
        Logger::error(i18n::s('The service is not available'));
    } else {
        $response = array();
        // retrieve session id from the file
        $head += strlen($id) + 1;
        $count = strlen($data);
        for ($tail = $head + 1; $tail <= $count; $tail++) {
            if ($data[$tail] == "\n") {
                break;
            }
        }
        // to be returned to caller
        $response['session_id'] = substr($data, $head, $tail - $head);
예제 #19
0
include_once '../shared/logger.php';
// load the adequate codec
include_once 'codec.php';
include_once 'xml_rpc_codec.php';
$codec = new xml_rpc_Codec();
// load some xml
//$xml = Safe::file_get_contents('xml-rpc/blogger.getUserInfo.request.xml');
//$xml = Safe::file_get_contents('xml-rpc/blogger.getUserInfo.response.xml');
//$xml = Safe::file_get_contents('xml-rpc/blogger.newPost.fault.xml');
//$xml = Safe::file_get_contents('xml-rpc/blogger.newPost.request.xml');
//$xml = Safe::file_get_contents('xml-rpc/blogger.newPost.response.xml');
//$xml = Safe::file_get_contents('xml-rpc/blogger.getUsersBlogs.request.xml');
//$xml = Safe::file_get_contents('xml-rpc/blogger.getUsersBlogs.response.xml');
//$xml = Safe::file_get_contents('xml-rpc/blogger.getUsersBlogs.response.2.xml');
//$xml = Safe::file_get_contents('xml-rpc/metaWeblog.newPost.request.xml');
$xml = Safe::file_get_contents('xml-rpc/metaWeblog.newPost.request.2.xml');
//$xml = Safe::file_get_contents('xml-rpc/getTemplate.response.xml');
//echo "Request:\n".$xml."\n";
if (!trim($xml)) {
    return;
}
// parse parameters
//$result = $codec->decode($xml);
$result = $codec->import_request($xml);
//$result = $codec->import_response($xml);
$status = @$result[0];
$parameters = @$result[1];
// if it was a HEAD request, stop here
if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'HEAD') {
    return;
}
예제 #20
0
파일: edit.php 프로젝트: rair/yacs
            if ($file == $item) {
                $checked = ' selected="selected"';
            }
            $items[] = '<option value="' . $item . '"' . $checked . '>skin/' . $skin . '/' . $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>';
    // allow for content modification
    if ($file) {
        // start of the form
        $context['text'] .= '<form method="post" action="' . $context['script_url'] . '"><div>' . '<input type="hidden" name="skin" value="' . encode_field($skin) . '" />' . '<input type="hidden" name="file" value="' . encode_field($file) . '" />';
        // load file content
        if (!($content = Safe::file_get_contents('../skins/' . $skin . '/' . $file))) {
            Logger::error(i18n::s('No file has been transmitted.'));
        }
        // textarea to edit the file
        $context['text'] .= '<textarea name="content" rows="25" cols="50" accesskey="c">' . encode_field($content) . '</textarea>';
        // button to upload changes
        $context['text'] .= BR . Skin::build_submit_button(i18n::s('Submit'), i18n::s('Press [s] to submit data'), 's') . '</div></form>' . "\n";
    }
}
// render the skin
render_skin();
예제 #21
0
파일: uploads.php 프로젝트: rair/yacs
 /**
  * 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);
         }
     }
 }
예제 #22
0
파일: feed.php 프로젝트: rair/yacs
        Safe::header('WWW-Authenticate: Basic realm="' . utf8::to_iso8859($context['site_name']) . '"');
        Safe::header('Status: 401 Unauthorized', TRUE, 401);
    }
    // permission denied to authenticated user
    Safe::header('Status: 401 Unauthorized', TRUE, 401);
    Logger::error(i18n::s('You are not allowed to perform this operation.'));
    // display feed content
} else {
    // get the list from the cache, if possible
    if (is_object($anchor)) {
        $cache_id = Cache::hash('comments/feed/' . $anchor->get_reference) . '.xml';
    } else {
        $cache_id = Cache::hash('comments/feed') . '.xml';
    }
    // save for 5 minutes
    if (!file_exists($context['path_to_root'] . $cache_id) || filemtime($context['path_to_root'] . $cache_id) + 300 < time() || !($text = Safe::file_get_contents($context['path_to_root'] . $cache_id))) {
        $text = '';
        // loads feeding parameters
        Safe::load('parameters/feeds.include.php');
        // set channel information
        $values = array();
        $values['channel'] = array();
        if (is_object($anchor)) {
            $values['channel']['title'] = sprintf(i18n::s('Comments for: %s'), $anchor->get_title());
            $values['channel']['link'] = $context['url_to_home'] . $context['url_to_root'] . $anchor->get_url();
            $values['channel']['description'] = $anchor->get_teaser('quote');
        } else {
            $values['channel']['title'] = sprintf(i18n::s('Recent comments at %s'), $context['site_name']);
            $values['channel']['link'] = $context['url_to_home'] . $context['url_to_root'];
            $values['channel']['description'] = i18n::s('Each article also has its own newsfeed.');
        }
예제 #23
0
파일: configure.php 프로젝트: rair/yacs
     $context['text'] .= '<p style="text-decoration: blink;">' . sprintf(i18n::s('To actually change the configuration, please copy and paste following lines by yourself in file %s.'), $parameters_file) . "</p>\n";
     // job done
 } else {
     $context['text'] .= '<p>' . sprintf(i18n::s('The following configuration has been saved into the file %s.'), $parameters_file) . "</p>\n";
     // purge the cache
     Cache::clear();
     // remember the change
     $label = sprintf(i18n::c('%s has been updated'), $parameters_file);
     Logger::remember('skins/flexible/configure.php: ' . $label);
 }
 // display updated parameters
 $context['text'] .= Skin::build_box(i18n::s('Configuration parameters'), Safe::highlight_string($content), 'folded');
 // reload current parameters, to be sure
 Safe::load($parameters_file, TRUE);
 // read the template file
 if (!($content = Safe::file_get_contents($template_file))) {
     Logger::error(sprintf(i18n::s('ERROR: Impossible to read the file %s.'), $template_file));
 } else {
     // prepare the transformation
     $needles = array();
     $values = array();
     // page-level parameters
     $needles[] = '!!body_background!!';
     $values[] = $context['flexible_body_bg'];
     $needles[] = '!!page_background!!';
     $values[] = $context['flexible_page_bg'];
     // page width
     $needles[] = '!!width!!';
     if ($context['flexible_width'] == '960px') {
         $values[] = '/* fixed width */' . "\n" . '#page {' . "\n" . '	background: ' . $context['flexible_page_bg'] . ';' . "\n" . '	width: 960px;' . "\n" . '	text-align: left;' . "\n" . '	margin: 0 auto;' . "\n" . '}' . "\n";
     } elseif ($context['flexible_width'] == '850px') {
예제 #24
0
파일: code_embed.php 프로젝트: rair/yacs
 /**
  * embed an interactive object
  *
  * The id designates the target file.
  * It can also include width and height of the target canvas, as in: '12, 100%, 250px'
  *
  * @param string id of the target file
  * @return string the rendered string
  **/
 public static function render_embed($id)
 {
     global $context;
     // split parameters
     $attributes = preg_split("/\\s*,\\s*/", $id, 4);
     $id = $attributes[0];
     // get the file
     if (!($item = Files::get($id))) {
         $output = '[embed=' . $id . ']';
         return $output;
     }
     // stream in a separate page
     if (isset($attributes[1]) && preg_match('/window/i', $attributes[1])) {
         if (!isset($attributes[2])) {
             $attributes[2] = i18n::s('Play in a separate window');
         }
         $output = '<a href="' . $context['url_to_home'] . $context['url_to_root'] . Files::get_url($item['id'], 'stream', $item['file_name']) . '" onclick="window.open(this.href); return false;" class="button"><span>' . $attributes[2] . '</span></a>';
         return $output;
     }
     // file extension
     $extension = strtolower(substr($item['file_name'], -3));
     // set a default size
     if (!isset($attributes[1])) {
         if (!strcmp($extension, 'gan')) {
             $attributes[1] = '98%';
         } elseif (!strcmp($extension, 'mm') && isset($context['skins_freemind_canvas_width'])) {
             $attributes[1] = $context['skins_freemind_canvas_width'];
         } else {
             $attributes[1] = 480;
         }
     }
     if (!isset($attributes[2])) {
         if (!strcmp($extension, 'gan')) {
             $attributes[2] = '300px';
         } elseif (!strcmp($extension, 'mm') && isset($context['skins_freemind_canvas_height'])) {
             $attributes[2] = $context['skins_freemind_canvas_height'];
         } else {
             $attributes[2] = 360;
         }
     }
     // object attributes
     $width = $attributes[1];
     $height = $attributes[2];
     $flashvars = '';
     if (isset($attributes[3])) {
         $flashvars = $attributes[3];
     }
     // rendering depends on file extension
     switch ($extension) {
         // stream a video
         case '3gp':
         case 'flv':
         case 'm4v':
         case 'mov':
         case 'mp4':
             // a flash player to stream a flash video
             $flvplayer_url = $context['url_to_home'] . $context['url_to_root'] . 'included/browser/player_flv_maxi.swf';
             // file is elsewhere
             if (isset($item['file_href']) && $item['file_href']) {
                 $url = $item['file_href'];
             } else {
                 $url = $context['url_to_home'] . $context['url_to_root'] . Files::get_url($item['id'], 'fetch', $item['file_name']);
             }
             // pass parameters to the player
             if ($flashvars) {
                 $flashvars = str_replace('autostart=true', 'autoplay=1', $flashvars) . '&';
             }
             $flashvars .= 'width=' . $width . '&height=' . $height;
             // if there is a static image for this video, use it
             if (isset($item['icon_url']) && $item['icon_url']) {
                 $flashvars .= '&startimage=' . urlencode($item['icon_url']);
             }
             // if there is a subtitle file for this video, use it
             if (isset($item['file_name']) && ($srt = 'files/' . str_replace(':', '/', $item['anchor']) . '/' . str_replace('.' . $extension, '.srt', $item['file_name'])) && file_exists($context['path_to_root'] . $srt)) {
                 $flashvars .= '&srt=1&srturl=' . urlencode($context['url_to_home'] . $context['url_to_root'] . $srt);
             }
             // if there is a logo file in the skin, use it
             Skin::define_img_href('FLV_IMG_HREF', 'codes/flvplayer_logo.png', '');
             if (FLV_IMG_HREF) {
                 $flashvars .= '&top1=' . urlencode(FLV_IMG_HREF . '|10|10');
             }
             // rely on Flash
             if (Surfer::has_flash()) {
                 // the full object is built in Javascript --see parameters at http://flv-player.net/players/maxi/documentation/
                 $output = '<div id="flv_' . $item['id'] . '" class="no_print">Flash plugin or Javascript are turned off. Activate both and reload to view the object</div>' . "\n";
                 Page::insert_script('var flashvars = { flv:"' . $url . '", ' . str_replace(array('&', '='), array('", ', ':"'), $flashvars) . '", autoload:0, margin:1, showiconplay:1, playeralpha:50, iconplaybgalpha:30, showfullscreen:1, showloading:"always", ondoubleclick:"fullscreen" }' . "\n" . 'var params = { allowfullscreen: "true", allowscriptaccess: "always" }' . "\n" . 'var attributes = { id: "file_' . $item['id'] . '", name: "file_' . $item['id'] . '"}' . "\n" . 'swfobject.embedSWF("' . $flvplayer_url . '", "flv_' . $item['id'] . '", "' . $width . '", "' . $height . '", "9", "' . $context['url_to_home'] . $context['url_to_root'] . 'included/browser/expressinstall.swf", flashvars, params);' . "\n");
                 // native support
             } else {
                 // <video> is HTML5, <object> is legacy
                 $output = '<video width="' . $width . '" height="' . $height . '" autoplay="" controls="" src="' . $url . '" >' . "\n" . '	<object width="' . $width . '" height="' . $height . '" data="' . $url . '" type="' . Files::get_mime_type($item['file_name']) . '">' . "\n" . '		<param value="' . $url . '" name="movie" />' . "\n" . '		<param value="true" name="allowFullScreen" />' . "\n" . '		<param value="always" name="allowscriptaccess" />' . "\n" . '		<a href="' . $url . '">No video playback capabilities, please download the file</a>' . "\n" . '	</object>' . "\n" . '</video>' . "\n";
             }
             // job done
             return $output;
             // a ganttproject timeline
         // a ganttproject timeline
         case 'gan':
             // where the file is
             $path = Files::get_path($item['anchor']) . '/' . rawurlencode($item['file_name']);
             // we actually use a transformed version of the file
             $cache_id = Cache::hash($path) . '.xml';
             // apply the transformation
             if (!file_exists($context['path_to_root'] . $cache_id) || filemtime($context['path_to_root'] . $cache_id) < filemtime($context['path_to_root'] . $path) || !($text = Safe::file_get_contents($context['path_to_root'] . $cache_id))) {
                 // transform from GanttProject to SIMILE Timeline
                 $text = Files::transform_gan_to_simile($path);
                 // put in cache
                 Safe::file_put_contents($cache_id, $text);
             }
             // load the SIMILE Timeline javascript library in shared/global.php
             $context['javascript']['timeline'] = TRUE;
             // cache would kill the loading of the library
             cache::poison();
             // 1 week ago
             $now = gmdate('M d Y H:i:s', time() - 7 * 24 * 60 * 60);
             // load the right file
             $output = '<div id="gantt" style="height: ' . $height . '; width: ' . $width . '; border: 1px solid #aaa; font-family: Trebuchet MS, Helvetica, Arial, sans serif; font-size: 8pt"></div>' . "\n";
             Page::insert_script('var simile_handle;' . "\n" . 'function onLoad() {' . "\n" . '  var eventSource = new Timeline.DefaultEventSource();' . "\n" . '	var theme = Timeline.ClassicTheme.create();' . "\n" . '            theme.event.bubble.width = 350;' . "\n" . '            theme.event.bubble.height = 300;' . "\n" . '  var bandInfos = [' . "\n" . '    Timeline.createBandInfo({' . "\n" . '        eventSource:    eventSource,' . "\n" . '        date:           "' . $now . '",' . "\n" . '        width:          "80%",' . "\n" . '        intervalUnit:   Timeline.DateTime.WEEK,' . "\n" . '        intervalPixels: 200,' . "\n" . '		  theme:          theme,' . "\n" . '        layout:         "original"  // original, overview, detailed' . "\n" . '    }),' . "\n" . '    Timeline.createBandInfo({' . "\n" . '        showEventText: false,' . "\n" . '        trackHeight: 0.5,' . "\n" . '        trackGap: 0.2,' . "\n" . '        eventSource:    eventSource,' . "\n" . '        date:           "' . $now . '",' . "\n" . '        width:          "20%",' . "\n" . '        intervalUnit:   Timeline.DateTime.MONTH,' . "\n" . '        intervalPixels: 50' . "\n" . '    })' . "\n" . '  ];' . "\n" . '  bandInfos[1].syncWith = 0;' . "\n" . '  bandInfos[1].highlight = true;' . "\n" . '  bandInfos[1].eventPainter.setLayout(bandInfos[0].eventPainter.getLayout());' . "\n" . '  simile_handle = Timeline.create(document.getElementById("gantt"), bandInfos, Timeline.HORIZONTAL);' . "\n" . '	simile_handle.showLoadingMessage();' . "\n" . '  Timeline.loadXML("' . $context['url_to_home'] . $context['url_to_root'] . $cache_id . '", function(xml, url) { eventSource.loadXML(xml, url); });' . "\n" . '	simile_handle.hideLoadingMessage();' . "\n" . '}' . "\n" . "\n" . 'var resizeTimerID = null;' . "\n" . 'function onResize() {' . "\n" . '    if (resizeTimerID == null) {' . "\n" . '        resizeTimerID = window.setTimeout(function() {' . "\n" . '            resizeTimerID = null;' . "\n" . '            simile_handle.layout();' . "\n" . '        }, 500);' . "\n" . '    }' . "\n" . '}' . "\n" . "\n" . '// observe page major events' . "\n" . '$(document).ready( onLoad);' . "\n" . '$(window).resize(onResize);' . "\n");
             // job done
             return $output;
             // a Freemind map
         // a Freemind map
         case 'mm':
             // if we have an external reference, use it
             if (isset($item['file_href']) && $item['file_href']) {
                 $target_href = $item['file_href'];
                 // else redirect to ourself
             } else {
                 // ensure a valid file name
                 $file_name = utf8::to_ascii($item['file_name']);
                 // where the file is
                 $path = Files::get_path($item['anchor']) . '/' . rawurlencode($item['file_name']);
                 // map the file on the regular web space
                 $url_prefix = $context['url_to_home'] . $context['url_to_root'];
                 // redirect to the actual file
                 $target_href = $url_prefix . $path;
             }
             // allow several viewers to co-exist in the same page
             static $freemind_viewer_index;
             if (!isset($freemind_viewer_index)) {
                 $freemind_viewer_index = 1;
             } else {
                 $freemind_viewer_index++;
             }
             // load flash player
             $url = $context['url_to_home'] . $context['url_to_root'] . 'included/browser/visorFreemind.swf';
             // variables
             $flashvars = 'initLoadFile=' . $target_href . '&openUrl=_self';
             $output = '<div id="freemind_viewer_' . $freemind_viewer_index . '">Flash plugin or Javascript are turned off. Activate both and reload to view the object</div>' . "\n";
             Page::insert_script('var params = {};' . "\n" . 'params.base = "' . dirname($url) . '/";' . "\n" . 'params.quality = "high";' . "\n" . 'params.wmode = "transparent";' . "\n" . 'params.menu = "false";' . "\n" . 'params.flashvars = "' . $flashvars . '";' . "\n" . 'swfobject.embedSWF("' . $url . '", "freemind_viewer_' . $freemind_viewer_index . '", "' . $width . '", "' . $height . '", "6", "' . $context['url_to_home'] . $context['url_to_root'] . 'included/browser/expressinstall.swf", false, params);' . "\n");
             // offer to download a copy of the map
             $menu = array($target_href => i18n::s('Browse this map with Freemind'));
             // display menu commands below the viewer
             $output .= Skin::build_list($menu, 'menu_bar');
             // job done
             return $output;
             // native flash
         // native flash
         case 'swf':
             // where to get the file
             if (isset($item['file_href']) && $item['file_href']) {
                 $url = $item['file_href'];
             } else {
                 $url = $context['url_to_home'] . $context['url_to_root'] . 'files/' . str_replace(':', '/', $item['anchor']) . '/' . rawurlencode($item['file_name']);
             }
             $output = '<div id="swf_' . $item['id'] . '" class="no_print">Flash plugin or Javascript are turned off. Activate both and reload to view the object</div>' . "\n";
             Page::insert_script('var params = {};' . "\n" . 'params.base = "' . dirname($url) . '/";' . "\n" . 'params.quality = "high";' . "\n" . 'params.wmode = "transparent";' . "\n" . 'params.allowfullscreen = "true";' . "\n" . 'params.allowscriptaccess = "always";' . "\n" . 'params.flashvars = "' . $flashvars . '";' . "\n" . 'swfobject.embedSWF("' . $url . '", "swf_' . $item['id'] . '", "' . $width . '", "' . $height . '", "6", "' . $context['url_to_home'] . $context['url_to_root'] . 'included/browser/expressinstall.swf", false, params);' . "\n");
             return $output;
             // link to file page
         // link to file page
         default:
             // link label
             $text = Skin::strip($item['title'] ? $item['title'] : str_replace('_', ' ', $item['file_name']));
             // make a link to the target page
             $url = Files::get_permalink($item);
             // return a complete anchor
             $output =& Skin::build_link($url, $text);
             return $output;
     }
 }
예제 #25
0
파일: index.php 프로젝트: rair/yacs
 if (!($chunk = Safe::file_get_contents('control/htaccess/basic/.htaccess'))) {
     Logger::error(sprintf(i18n::s('Impossible to read %s.'), 'control/htaccess/basic/.htaccess'));
 } else {
     $content = str_replace('!!url_to_root!!', $context['url_to_root'], $chunk);
 }
 // with Options
 if (isset($_SESSION['htaccess']['options'])) {
     if (!($chunk = Safe::file_get_contents('control/htaccess/options/.htaccess'))) {
         Logger::error(sprintf(i18n::s('Impossible to read %s.'), 'control/htaccess/options/.htaccess'));
     } 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";