예제 #1
0
파일: locations.php 프로젝트: rair/yacs
 /**
  * duplicate all locations 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('locations') . " WHERE anchor LIKE '" . SQL::escape($anchor_from) . "'";
     if (($result = SQL::query($query)) && SQL::count($result)) {
         // the list of transcoded strings
         $transcoded = array();
         // process all matching records one at a time
         while ($item = SQL::fetch($result)) {
             // a new id will be allocated
             $old_id = $item['id'];
             unset($item['id']);
             // target anchor
             $item['anchor'] = $anchor_to;
             // actual duplication
             if ($item['id'] = Locations::post($item)) {
                 // more pairs of strings to transcode
                 $transcoded[] = array('/\\[location=' . preg_quote($old_id, '/') . '/i', '[location=' . $item['id']);
                 // duplicate elements related to this item
                 Anchors::duplicate_related_to('location:' . $old_id, 'location:' . $item['id']);
                 // stats
                 $count++;
             }
         }
         // transcode in anchor
         if ($anchor = Anchors::get($anchor_to)) {
             $anchor->transcode($transcoded);
         }
     }
     // number of duplicated records
     return $count;
 }
예제 #2
0
파일: edit.php 프로젝트: rair/yacs
    Safe::header('Status: 404 Not Found', TRUE, 404);
    Logger::error(i18n::s('No anchor has been found.'));
    // maybe posts are not allowed here
} elseif (!isset($item['id']) && is_object($anchor) && $anchor->has_option('locked') && !Surfer::is_empowered()) {
    Safe::header('Status: 401 Unauthorized', TRUE, 401);
    Logger::error(i18n::s('This page has been locked.'));
    // an error occured
} elseif (count($context['error'])) {
    $item = $_REQUEST;
    $with_form = TRUE;
    // process uploaded data
} elseif (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'POST') {
    // the follow-up page
    $next = $context['url_to_home'] . $context['url_to_root'] . $anchor->get_url();
    // display the form on error
    if (!($_REQUEST['id'] = Locations::post($_REQUEST))) {
        $item = $_REQUEST;
        $with_form = TRUE;
        // reward the poster for new posts
    } elseif (!isset($item['id'])) {
        // increment the post counter of the surfer
        Users::increment_posts(Surfer::get_id());
        // change page title
        $context['page_title'] = i18n::s('Thank you for your contribution');
        // show location attributes
        $attributes = array();
        if ($_REQUEST['geo_place_name']) {
            $attributes[] = $_REQUEST['geo_place_name'];
        }
        if ($_REQUEST['geo_position']) {
            $attributes[] = $_REQUEST['geo_position'];