예제 #1
0
파일: derive.php 프로젝트: rair/yacs
         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)) {
             $context['text'] .= sprintf(i18n::s('Impossible to copy file %s.'), $target) . BR . "\n";
             $errors++;
             // attempt to preserve the modification date of the origin file
         } else {
             Safe::touch($context['path_to_root'] . $target, Safe::filemtime($context['path_to_root'] . $origin));
             $context['text'] .= sprintf(i18n::s('%s has been copied'), $target) . BR . "\n";
         }
         // this will be filtered by umask anyway
         Safe::chmod($context['path_to_root'] . $target, $context['file_mask']);
     }
     $context['text'] .= "</p>\n";
 }
 // some errors have occured
 if ($errors) {
     $context['text'] .= '<p>' . i18n::s('Operation has failed.') . "</p>\n";
예제 #2
0
파일: images.php 프로젝트: rair/yacs
 /**
  * duplicate all images for a given anchor
  *
  * This function duplicates records in the database, and changes anchors
  * to attach new records as per second parameter.
  *
  * @param string the source anchor
  * @param string the target anchor
  * @return int the number of duplicated records
  *
  * @see shared/anchors.php
  */
 public static function duplicate_for_anchor($anchor_from, $anchor_to)
 {
     global $context;
     // look for records attached to this anchor
     $count = 0;
     $query = "SELECT * FROM " . SQL::table_name('images') . " WHERE anchor LIKE '" . SQL::escape($anchor_from) . "'";
     if (($result = SQL::query($query)) && SQL::count($result)) {
         // create target folders
         $file_to = $context['path_to_root'] . Files::get_path($item['anchor'], 'images');
         if (!Safe::make_path($file_to . '/thumbs')) {
             Logger::error(sprintf(i18n::s('Impossible to create path %s.'), $file_to . '/thumbs'));
         }
         $file_to = $context['path_to_root'] . $file_to . '/';
         // the list of transcoded strings
         $transcoded = array();
         // process all matching records one at a time
         $file_from = $context['path_to_root'] . Files::get_path($anchor_from, 'images');
         while ($item = SQL::fetch($result)) {
             // sanity check
             if (!file_exists($context['path_to_root'] . $file_from . '/' . $item['image_name'])) {
                 continue;
             }
             // duplicate image file
             if (!copy($context['path_to_root'] . $file_from . '/' . $item['image_name'], $file_to . $item['image_name'])) {
                 Logger::error(sprintf(i18n::s('Impossible to copy file %s.'), $item['image_name']));
                 continue;
             }
             // this will be filtered by umask anyway
             Safe::chmod($file_to . $item['image_name'], $context['file_mask']);
             // copy the thumbnail as well
             Safe::copy($context['path_to_root'] . $file_from . '/' . $item['thumbnail_name'], $file_to . $item['thumbnail_name']);
             // this will be filtered by umask anyway
             Safe::chmod($file_to . $item['thumbnail_name'], $context['file_mask']);
             // a new id will be allocated
             $old_id = $item['id'];
             unset($item['id']);
             // target anchor
             $item['anchor'] = $anchor_to;
             // actual duplication
             if ($new_id = Images::post($item)) {
                 // more pairs of strings to transcode --no automatic solution for [images=...]
                 $transcoded[] = array('/\\[image=' . preg_quote($old_id, '/') . '/i', '[image=' . $new_id);
                 // duplicate elements related to this item
                 Anchors::duplicate_related_to('image:' . $old_id, 'image:' . $new_id);
                 // stats
                 $count++;
             }
         }
         // transcode in anchor
         if ($anchor = Anchors::get($anchor_to)) {
             $anchor->transcode($transcoded);
         }
     }
     // number of duplicated records
     return $count;
 }
예제 #3
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');
예제 #4
0
파일: build.php 프로젝트: rair/yacs
     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();
     }
 }
 if (count($footprints)) {
     $context['text'] .= sprintf(i18n::s('%d reference scripts have been copied.'), count($footprints)) . "\n";