Пример #1
0
 /**
  * duplicate all tables 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('tables') . " 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'] = Tables::post($item)) {
                 // more pairs of strings to transcode
                 $transcoded[] = array('/\\[table=' . preg_quote($old_id, '/') . '/i', '[table=' . $item['id']);
                 $transcoded[] = array('/\\[table.bars=' . preg_quote($old_id, '/') . '/i', '[table.bars=' . $item['id']);
                 $transcoded[] = array('/\\[table.chart=' . preg_quote($old_id, '/') . '/i', '[table.chart=' . $item['id']);
                 $transcoded[] = array('/\\[table.filter=' . preg_quote($old_id, '/') . '/i', '[table.filter=' . $item['id']);
                 $transcoded[] = array('/\\[table.line=' . preg_quote($old_id, '/') . '/i', '[table.line=' . $item['id']);
                 // duplicate elements related to this item
                 Anchors::duplicate_related_to('table:' . $old_id, 'table:' . $item['id']);
                 // stats
                 $count++;
             }
         }
         // transcode in anchor
         if ($anchor = Anchors::get($anchor_to)) {
             $anchor->transcode($transcoded);
         }
         // clear the cache for tables
         Cache::clear(array('tables', 'table:'));
     }
     // number of duplicated records
     return $count;
 }
Пример #2
0
 /**
  * duplicate all links 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('links') . " WHERE anchor LIKE '" . SQL::escape($anchor_from) . "'";
     if (($result = SQL::query($query)) && SQL::count($result)) {
         // 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'] = Links::post($item)) {
                 // duplicate elements related to this item
                 Anchors::duplicate_related_to('link:' . $old_id, 'link:' . $item['id']);
                 // stats
                 $count++;
             }
         }
     }
     // number of duplicated records
     return $count;
 }
Пример #3
0
 /**
  * duplicate all sections 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('sections') . " 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']);
             // creator has to be the person who duplicates
             unset($item['create_address']);
             unset($item['create_date']);
             unset($item['create_id']);
             unset($item['create_name']);
             unset($item['edit_address']);
             unset($item['edit_date']);
             unset($item['edit_id']);
             unset($item['edit_name']);
             // target anchor
             $item['anchor'] = $anchor_to;
             // actual duplication
             if ($item['id'] = Sections::post($item, FALSE)) {
                 // more pairs of strings to transcode
                 $transcoded[] = array('/\\[section=' . preg_quote($old_id, '/') . '/i', '[section=' . $item['id']);
                 // duplicate elements related to this item
                 Anchors::duplicate_related_to('section:' . $old_id, 'section:' . $item['id']);
                 // stats
                 $count++;
             }
         }
         // transcode in anchor
         if ($anchor = Anchors::get($anchor_to)) {
             $anchor->transcode($transcoded);
         }
     }
     // number of duplicated records
     return $count;
 }
Пример #4
0
 unset($item['publish_address']);
 unset($item['publish_date']);
 unset($item['publish_id']);
 unset($item['publish_name']);
 // ensure this is a copy
 $item['title'] = sprintf(i18n::s('Copy of %s'), $item['title']);
 // create a new page
 if ($item['id'] = Articles::post($item)) {
     // also duplicate the provided overlay, if any -- re-use 'overlay_type' only
     $overlay = Overlay::load($item, 'article:' . $item['id']);
     // post an overlay, with the new article id
     if (is_object($overlay)) {
         $overlay->remember('insert', $item, 'article:' . $item['id']);
     }
     // duplicate all related items, images, etc.
     Anchors::duplicate_related_to($original_anchor, 'article:' . $item['id']);
     // if poster is a registered user
     if (Surfer::get_id()) {
         // increment the post counter of the surfer
         Users::increment_posts(Surfer::get_id());
         // add this page to watch list
         Members::assign('article:' . $item['id'], 'user:'******'article:' . $item['id'], TRUE);
     $context['page_title'] = i18n::s('Thank you for your contribution');
     // the page has been duplicated
     $context['text'] .= '<p>' . i18n::s('The page has been duplicated.') . '</p>';
     // follow-up commands
     $follow_up = i18n::s('What do you want to do now?');
     $menu = array();
Пример #5
0
 /**
  * duplicate all files 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('files') . " WHERE anchor LIKE '" . SQL::escape($anchor_from) . "'";
     if (($result = SQL::query($query)) && SQL::count($result)) {
         // create target folders
         $file_to = Files::get_path($anchor_to);
         if (!Safe::make_path($file_to)) {
             Logger::error(sprintf(i18n::s('Impossible to create path %s.'), $file_to));
         }
         $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 = Files::get_path($anchor_from);
         while ($item = SQL::fetch($result)) {
             // sanity check
             if (!file_exists($context['path_to_root'] . $file_from . '/' . $item['file_name'])) {
                 continue;
             }
             // duplicate file
             if (!copy($context['path_to_root'] . $file_from . '/' . $item['file_name'], $file_to . $item['file_name'])) {
                 Logger::error(sprintf(i18n::s('Impossible to copy file %s.'), $item['file_name']));
                 continue;
             }
             // this will be filtered by umask anyway
             Safe::chmod($file_path . $item['file_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 = Files::post($item)) {
                 // more pairs of strings to transcode
                 $transcoded[] = array('/\\[embed=' . preg_quote($old_id, '/') . '/i', '[embed=' . $new_id);
                 $transcoded[] = array('/\\[file=' . preg_quote($old_id, '/') . '/i', '[file=' . $new_id);
                 $transcoded[] = array('/\\[flash=' . preg_quote($old_id, '/') . '/i', '[flash=' . $new_id);
                 // obsolete, to be removed by end 2009
                 $transcoded[] = array('/\\[download=' . preg_quote($old_id, '/') . '/i', '[download=' . $new_id);
                 $transcoded[] = array('/\\[sound=' . preg_quote($old_id, '/') . '/i', '[sound=' . $new_id);
                 // duplicate elements related to this item
                 Anchors::duplicate_related_to('file:' . $old_id, 'file:' . $new_id);
                 // stats
                 $count++;
             }
         }
         // transcode in anchor
         if ($anchor = Anchors::get($anchor_to)) {
             $anchor->transcode($transcoded);
         }
     }
     // number of duplicated records
     return $count;
 }
Пример #6
0
         // change the handle
         unset($section['handle']);
         // ensure this is a copy
         $section['title'] = sprintf(i18n::s('Copy of %s'), $section['title']);
         // target anchor
         $section['anchor'] = $_REQUEST['duplicate_to'];
         // actual duplication
         if ($section['id'] = Sections::post($section, FALSE)) {
             // also duplicate the provided overlay, if any -- re-use 'overlay_type' only
             $overlay = Overlay::load($section, 'section:' . $section['id']);
             // post an overlay, with the new section id
             if (is_object($overlay)) {
                 $overlay->remember('insert', $section, 'section:' . $section['id']);
             }
             // duplicate elements related to this item
             Anchors::duplicate_related_to('section:' . $old_id, 'section:' . $section['id']);
             // stats
             $count++;
         }
     }
 }
 // report on results
 $context['text'] .= '<p>' . sprintf(i18n::ns('%d section has been duplicated.', '%d sections have been duplicated.', $count), $count) . '</p>';
 // follow-up commands
 $follow_up = i18n::s('What do you want to do now?');
 $menu = array();
 $menu[] = Skin::build_link(Sections::get_permalink($item), i18n::s('View the section'), 'span');
 $menu[] = Skin::build_link(Sections::get_url($item['id'], 'manage'), i18n::s('Manage it'), 'span');
 $follow_up .= Skin::finalize_list($menu, 'menu_bar');
 $context['text'] .= Skin::build_block($follow_up, 'bottom');
 // nothing to do
Пример #7
0
 unset($item['edit_date']);
 unset($item['edit_id']);
 unset($item['edit_name']);
 // ensure this is a copy
 $item['title'] = sprintf(i18n::s('Copy of %s'), $item['title']);
 $item['index_title'] = $item['title'];
 // create a new page
 if ($item['id'] = Sections::post($item, FALSE)) {
     // also duplicate the provided overlay, if any -- re-use 'overlay_type' only
     $overlay = Overlay::load($item, 'section:' . $item['id']);
     // post an overlay, with the new section id
     if (is_object($overlay)) {
         $overlay->remember('insert', $item, 'section:' . $item['id']);
     }
     // duplicate all related items, images, etc.
     Anchors::duplicate_related_to($original_anchor, 'section:' . $item['id']);
     // if poster is a registered user
     if (Surfer::get_id()) {
         // increment the post counter of the surfer
         Users::increment_posts(Surfer::get_id());
         // add this page to watch list
         Members::assign('section:' . $item['id'], 'user:'******'section:' . $item['id'], TRUE);
     $context['page_title'] = i18n::s('Thank you for your contribution');
     // the page has been duplicated
     $context['text'] .= '<p>' . i18n::s('The section has been duplicated.') . '</p>';
     // follow-up commands
     $follow_up = i18n::s('What do you want to do now?');
     $menu = array();