Skip to content

Commit

Permalink
Merge pull request #5 from mrbaseman/move_post
Browse files Browse the repository at this point in the history
allow moving posts across section borders
  • Loading branch information
instantflorian committed Apr 16, 2019
2 parents 330627e + 7d52d19 commit b85a1b0
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 37 deletions.
2 changes: 1 addition & 1 deletion add.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@
$commenting = 'none';
$use_captcha = true;

$database->query("INSERT INTO `".TABLE_PREFIX."mod_news_img_settings` (`section_id`,`page_id`,`header`,`post_loop`,`footer`,`post_header`,`post_content`,`image_loop`,`post_footer`,`comments_header`,`comments_loop`,`comments_footer`,`comments_page`,`commenting`,`use_captcha`) VALUES ('$section_id','$page_id','$header','$post_loop','$footer','$post_header','$post_content','$image_loop','$post_footer','$comments_header','$comments_loop','$comments_footer','$comments_page','$commenting','$use_captcha')");
$database->query("INSERT INTO `".TABLE_PREFIX."mod_news_img_settings` (`section_id`,`page_id`,`header`,`post_loop`,`footer`,`post_header`,`post_content`,`image_loop`,`post_footer`,`comments_header`,`comments_loop`,`comments_footer`,`comments_page`,`commenting`,`use_captcha`,`gallery`) VALUES ('$section_id','$page_id','$header','$post_loop','$footer','$post_header','$post_content','$image_loop','$post_footer','$comments_header','$comments_loop','$comments_footer','$comments_page','$commenting','$use_captcha','')");
8 changes: 6 additions & 2 deletions info.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@
$module_directory = 'news_img';
$module_name = 'News with Images';
$module_function = 'page';
$module_version = '3.7.4';
$module_version = '3.7.5';
$module_platform = '2.8.x';
$module_author = 'Ryan Djurovich, Rob Smith, Silvia Reins, Martin Hecht, Bianka Martinovic';
$module_author = 'Ryan Djurovich, Rob Smith, Silvia Reins, Martin Hecht, Florian Meerwinck, Bianka Martinovic';
$module_license = 'GNU General Public License';
$module_description = 'This page type is designed for making a news page with Images and Lightboxeffect.';

/**
* v3.7.5 - 2019-04-14 Martin Hecht
* + allow moving posts across section borders
* + a few bugfixes
*
* v3.7.4 - 2019-04-14
* - Martin Hecht:
* + use news_img throughout the module, especially in the search tables
Expand Down
82 changes: 66 additions & 16 deletions modify_post.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,23 +124,73 @@ function show_wysiwyg_editor($name,$id,$content,$width,$height) {
</td>
</tr>
<tr>
<td><?php echo $TEXT['GROUP']; ?>:</td>
<td>
<select name="group" style="width: 100%;">
<option value="0"><?php echo $TEXT['NONE']; ?></option>
<?php
$query = $database->query("SELECT `group_id`,`title` FROM `".TABLE_PREFIX."mod_news_img_groups` WHERE `section_id` = '$section_id' ORDER BY `position` ASC");
if($query->numRows() > 0) {
// Loop through groups
while($group = $query->fetchRow()) {
?>
<option value="<?php echo $group['group_id']; ?>"<?php if($fetch_content['group_id'] == $group['group_id']) { echo ' selected="selected"'; } ?>><?php echo $group['title']; ?></option>
<?php
}
<td><?php echo $TEXT['GROUP']; ?>:</td>
<td>
<select name="group" style="width: 100%;">
<?php
// We encode the group_id, section_id and page_id into an urlencoded serialized array.
// So we have a single string that we can submit safely and decode it when receiving.
echo '<option value="'.urlencode(serialize(array('g' => 0, 's' => $section_id, 'p' => $page_id))).'">'
. $TEXT['NONE']." (".$TEXT['CURRENT']." ".$TEXT['SECTION']." ".$section_id.")</option>";
$query = $database->query("SELECT `group_id`,`title` FROM `".TABLE_PREFIX."mod_news_img_groups`"
. " WHERE `section_id` = '$section_id' ORDER BY `position` ASC");
if($query->numRows() > 0) {
// Loop through groups
while($group = $query->fetchRow()) {
echo '<option value="'
. urlencode(serialize(array('g' => intval($group['group_id']), 's' => $section_id, 'p' => $page_id))).'"';
if($fetch_content['group_id'] == $group['group_id']) {
echo ' selected="selected"';
}
echo '>'.$group['title'].' ('.$TEXT['CURRENT']." ".$TEXT['SECTION'].' '.$section_id.')</option>';
}
}
// this was just assignment to a group within the local section. Let's find out which sections exist
// and offer to move the post to another news_img section
$query_sections = $database->query("SELECT `section_id`,`page_id` FROM `".TABLE_PREFIX."mod_news_img_settings`"
. " WHERE `section_id` != '$section_id' ORDER BY `page_id`,`section_id` ASC");
$pid = $page_id;
if($query_sections->numRows() > 0) {
// Loop through all news_img sections, do sanity checks and filter out the current section which is handled above
while($sect = $query_sections->fetchRow()) {
if($sect['section_id'] != $section_id){
if($sect['page_id'] != $pid){ // for new pages insert a separator
$pid = intval($sect['page_id']);
$page_title = "";
$page_details = "";
if($pid != 0){ // find out the page title and print separator line
$page_details = $admin->get_page_details($pid);
if (!empty($page_details)){
$page_title=isset($page_details['page_title'])?$page_details['page_title']:"";
echo '<option value="'.urlencode(serialize(array('g' => 0, 's' => 0, 'p' => 0))).'">'
.'[--- '.$TEXT['PAGE'].' '.$pid.' ('.$page_title.') ---]</option>';
}
}
}
if($pid != 0){
echo '<option value="'.urlencode(serialize(array('g' => 0, 's' => $sect['section_id'], 'p' => $pid))).'">'
. $TEXT['NONE']." (".$TEXT['SECTION']." ".$sect['section_id'].")</option>";
// now loop through groups of this section, at least for the ones which are not dummy sections
$query_groups = $database->query("SELECT `group_id`,`title` FROM `".TABLE_PREFIX."mod_news_img_groups`"
. " WHERE `section_id` = '".intval($sect['section_id'])."' ORDER BY `position` ASC");
if($query_groups->numRows() > 0) {
// Loop through groups
while($group = $query_groups->fetchRow()) {
echo '<option value="'
. urlencode(serialize(array(
'g' => intval($group['group_id']),
's' => intval($sect['section_id']),
'p' => $pid)))
.'">'.$group['title'].' ('.$TEXT['SECTION'].' '.$sect['section_id'].')</option>';
}
}
}
?>
</select>
</td>
}
}
}
?>
</select>
</td>
</tr>
<tr>
<td><?php echo $TEXT['COMMENTING']; ?>:</td>
Expand Down
81 changes: 63 additions & 18 deletions save_post.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ function image_resize($src, $dst, $width, $height, $crop=0){
$update_when_modified = true; // Tells script to update when this page was last updated
require WB_PATH.'/modules/admin.php';

$group="";

// Validate all fields
if($admin->get_post('title') == '' AND $admin->get_post('url') == '')
{
Expand All @@ -191,9 +193,28 @@ function image_resize($src, $dst, $width, $height, $crop=0){
$commenting = $admin->get_post_escaped('commenting');
$active = $admin->get_post_escaped('active');
$old_link = $admin->get_post_escaped('link');
$group_id = $admin->get_post_escaped('group');
$group = $admin->get_post_escaped('group');
}

$group_id = 0;
$old_section_id = $section_id;
$old_page_id = $page_id;

if(!empty($group)){
$gid_value = urldecode($group);
$values = unserialize($gid_value);
if(!isset($values['s']) OR !isset($values['g']) OR !isset($values['p'])){
header("Location: ".ADMIN_URL."/pages/index.php");
exit( 0 );
}
if(intval($values['p'])!=0){
$group_id = intval($values['g']);
$section_id = intval($values['s']);
$page_id = intval($values['p']);
}
}


// Get page link URL
$query_page = $database->query("SELECT `level`,`link` FROM `".TABLE_PREFIX."pages` WHERE `page_id` = '$page_id'");
$page = $query_page->fetchRow();
Expand Down Expand Up @@ -238,14 +259,14 @@ function image_resize($src, $dst, $width, $height, $crop=0){
if($publisheduntil == '' || $publisheduntil < 1)
$publisheduntil=0;

if(!defined('ORDERING_CLASS_LOADED')) {
require WB_PATH.'/framework/class.order.php';
}

//post images
if (isset($_FILES["foto"])) {
// 2014-04-10 by BlackBird Webprogrammierung:
// image position (order)
if(!defined('ORDERING_CLASS_LOADED')) {
require WB_PATH.'/framework/class.order.php';
}

foreach($_FILES as $picture) {
if(!isset($picture['name']) || !is_array($picture['name'])) {
Expand Down Expand Up @@ -374,26 +395,50 @@ function image_resize($src, $dst, $width, $height, $crop=0){

// strip HTML from title
$title = strip_tags($title);

$position="";
// if we are moving posts across section borders we have to update the order of the posts
if($old_section_id!=$section_id)
{
// Get new order
$order = new order(TABLE_PREFIX.'mod_news_img_posts', 'position', 'post_id', 'section_id');
$position = "`position` = '".$order->get_new($section_id)."',";
}


// Update row
$database->query("UPDATE `".TABLE_PREFIX."mod_news_img_posts` SET `group_id` = '$group_id', `title` = '$title', `link` = '$post_link', `content_short` = '$short', `content_long` = '$long', `content_block2` = '$block2', `image` = '$image', `commenting` = '$commenting', `active` = '$active', `published_when` = '$publishedwhen', `published_until` = '$publisheduntil', `posted_when` = '".time()."', `posted_by` = '".$admin->get_user_id()."' WHERE `post_id` = '$post_id'");

//update Bildbeschreibungen der tabelle mod_news_img_img
$query_img = $database->query("SELECT * FROM `".TABLE_PREFIX."mod_news_img_img` WHERE `post_id` = ".$post_id);
if($query_img->numRows() > 0) {

while($row = $query_img->fetchRow()) {
$row_id = $row['id'];
// var_dump($row_id);
//var_dump($_POST['bildbeschreibung'][$row_id]);
$bildbeschreibung = isset($_POST['bildbeschreibung'][$row_id])
? $_POST['bildbeschreibung'][$row_id]
: '';
$database->query("UPDATE `".TABLE_PREFIX."mod_news_img_img` SET `bildbeschreibung` = '$bildbeschreibung' WHERE id = '$row_id'");
$database->query("UPDATE `".TABLE_PREFIX."mod_news_img_posts` SET `page_id` = '$page_id', `section_id` = '$section_id', $position `group_id` = '$group_id', `title` = '$title', `link` = '$post_link', `content_short` = '$short', `content_long` = '$long', `content_block2` = '$block2', `image` = '$image', `commenting` = '$commenting', `active` = '$active', `published_when` = '$publishedwhen', `published_until` = '$publisheduntil', `posted_when` = '".time()."', `posted_by` = '".$admin->get_user_id()."' WHERE `post_id` = '$post_id'");

// when no error has occurred go ahead and update the image descriptions
if(!($database->is_error()))
{
//update Bildbeschreibungen der tabelle mod_news_img_img
$query_img = $database->query("SELECT * FROM `".TABLE_PREFIX."mod_news_img_img` WHERE `post_id` = ".$post_id);
if($query_img->numRows() > 0) {

while($row = $query_img->fetchRow()) {
$row_id = $row['id'];
// var_dump($row_id);
//var_dump($_POST['bildbeschreibung'][$row_id]);
$bildbeschreibung = isset($_POST['bildbeschreibung'][$row_id])
? $_POST['bildbeschreibung'][$row_id]
: '';
$database->query("UPDATE `".TABLE_PREFIX."mod_news_img_img` SET `bildbeschreibung` = '$bildbeschreibung' WHERE id = '$row_id'");
}
}
}

// if this went fine so far and we are moving posts across section borders we still have to update the comments tables and reorder
if((!($database->is_error()))&&($old_section_id!=$section_id))
{
// Update row
$database->query("UPDATE `".TABLE_PREFIX."mod_news_img_comments` SET `page_id` = '$page_id', `section_id` = '$section_id' WHERE `post_id` = '$post_id'");

// Clean up ordering
$order = new order(TABLE_PREFIX.'mod_news_img_posts', 'position', 'post_id', 'section_id');
$order->clean($old_section_id);

}

// exit;
// Check if there is a db error, otherwise say successful
Expand Down

0 comments on commit b85a1b0

Please sign in to comment.