本文整理汇总了PHP中Anchors::duplicate_related_to方法的典型用法代码示例。如果您正苦于以下问题:PHP Anchors::duplicate_related_to方法的具体用法?PHP Anchors::duplicate_related_to怎么用?PHP Anchors::duplicate_related_to使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Anchors
的用法示例。
在下文中一共展示了Anchors::duplicate_related_to方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: duplicate_for_anchor
/**
* 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: duplicate_for_anchor
/**
* 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: duplicate_for_anchor
/**
* 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: unset
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:' . Surfer::get_id());
}
// get the new item
$article = Anchors::get('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: duplicate_for_anchor
/**
* 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: unset
// 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