|
{$lang['edit_title']}
| {$lang['st_views']}
| {$lang['edit_com']}
| {$lang['edit_approve']}
| {$lang['edit_cl']}
| {$lang['edit_autor']}
|
|
|
{$entries}
|
HTML;
// pagination
$npp_nav = "";
if( $start_from > 0 ) {
$previous = $start_from - $news_per_page;
$npp_nav .= " << ";
}
if( $all_count_news > $news_per_page ) {
$enpages_count = @ceil( $all_count_news / $news_per_page );
$enpages_start_from = 0;
$enpages = "";
if( $enpages_count <= 10 ) {
for($j = 1; $j <= $enpages_count; $j ++) {
if( $enpages_start_from != $start_from ) {
$enpages .= " $j ";
} else {
$enpages .= " $j ";
}
$enpages_start_from += $news_per_page;
}
$npp_nav .= $enpages;
} else {
$start = 1;
$end = 10;
if( $start_from > 0 ) {
if( ($start_from / $news_per_page) > 4 ) {
$start = @ceil( $start_from / $news_per_page ) - 3;
$end = $start + 9;
if( $end > $enpages_count ) {
$start = $enpages_count - 10;
$end = $enpages_count - 1;
}
$enpages_start_from = ($start - 1) * $news_per_page;
}
}
if( $start > 2 ) {
$enpages .= " 1 ... ";
}
for($j = $start; $j <= $end; $j ++) {
if( $enpages_start_from != $start_from ) {
$enpages .= " $j ";
} else {
$enpages .= " $j ";
}
$enpages_start_from += $news_per_page;
}
$enpages_start_from = ($enpages_count - 1) * $news_per_page;
$enpages .= "... $enpages_count ";
$npp_nav .= $enpages;
}
}
if( $all_count_news > $i ) {
$how_next = $all_count_news - $i;
if( $how_next > $news_per_page ) {
$how_next = $news_per_page;
}
$npp_nav .= " >>";
}
$npp_nav .= " ";
// pagination
if( $entries_showed != 0 ) {
echo <<{$npp_nav} |
|
HTML;
if( $all_count_news > $news_per_page ) {
echo << |
{$lang['edit_go_page']}
|
HTML;
}
}
echo <<
|
|
|
|
|
HTML;
}
echofooter();
}
// ********************************************************************************
// Показ новости и редактирование
// ********************************************************************************
elseif( $action == "editnews" ) {
$id = intval( $_GET['id'] );
$row = $db->super_query( "SELECT * FROM " . PREFIX . "_post where id = '$id'" );
$found = FALSE;
if( $id == $row['id'] ) $found = TRUE;
if( ! $found ) {msg( "error", $lang['cat_error'], $lang['edit_nonews'] );}
$cat_list = explode( ',', $row['category'] );
$have_perm = 0;
if( $user_group[$member_id['user_group']]['allow_edit'] and $row['autor'] == $member_id['name'] ) {
$have_perm = 1;
}
if( $user_group[$member_id['user_group']]['allow_all_edit'] ) {
$have_perm = 1;
$allow_list = explode( ',', $user_group[$member_id['user_group']]['cat_add'] );
foreach ( $cat_list as $selected ) {
if( $allow_list[0] != "all" and !in_array( $selected, $allow_list ) AND $row['approve']) $have_perm = 0;
}
}
if( ($member_id['user_group'] == 1) ) {
$have_perm = 1;
}
if( ! $have_perm ) {
msg( "error", $lang['addnews_denied'], $lang['edit_denied'], "$PHP_SELF?mod=editnews&action=list" );
}
$row['title'] = $parse->decodeBBCodes( $row['title'], false );
$row['title'] = str_replace("&","&", $row['title'] );
$row['descr'] = $parse->decodeBBCodes( $row['descr'], false );
$row['keywords'] = $parse->decodeBBCodes( $row['keywords'], false );
$row['metatitle'] = stripslashes( $row['metatitle'] );
$row['short_story'] = $parse->decodeBBCodes( $row['short_story'], false );
$row['full_story'] = $parse->decodeBBCodes( $row['full_story'], false );
$access = permload( $row['access'] );
if( $row['votes'] ) {
$poll = $db->super_query( "SELECT * FROM " . PREFIX . "_poll where news_id = '{$row['id']}'" );
$poll['title'] = $parse->decodeBBCodes( $poll['title'], false );
$poll['frage'] = $parse->decodeBBCodes( $poll['frage'], false );
$poll['body'] = $parse->decodeBBCodes( $poll['body'], false );
$poll['multiple'] = $poll['multiple'] ? "checked" : "";
}
echoheader( "editnews", $lang['edit_head'] );
echo "
";
echo "
HTML;
echofooter();
}
// ********************************************************************************
// Сохранение или удаление новости
// ********************************************************************************
elseif( $action == "doeditnews" ) {
$id = intval( $_GET['id'] );
$allow_comm = isset( $_POST['allow_comm'] ) ? intval( $_POST['allow_comm'] ) : 0;
$allow_main = isset( $_POST['allow_main'] ) ? intval( $_POST['allow_main'] ) : 0;
$approve = isset( $_POST['approve'] ) ? intval( $_POST['approve'] ) : 0;
$allow_rating = isset( $_POST['allow_rating'] ) ? intval( $_POST['allow_rating'] ) : 0;
$news_fixed = isset( $_POST['news_fixed'] ) ? intval( $_POST['news_fixed'] ) : 0;
$category = $_POST['category'];
if( ! count( $category ) ) {
$category = array ();
$category[] = '0';
}
$category_list = array();
foreach ( $category as $value ) {$category_list[] = intval($value);}
$category_list = $db->safesql( implode( ',', $category ) );
$allow_list = explode( ',', $user_group[$member_id['user_group']]['cat_add'] );
foreach ( $category as $selected ) {if( $allow_list[0] != "all" and ! in_array( $selected, $allow_list ) and $member_id['user_group'] != 1 ) $approve = 0;}
if( !$user_group[$member_id['user_group']]['moderation'] ) $approve = 0;
$title = $parse->process( trim( strip_tags ($_POST['title']) ) );
$full_story = $parse->process( $_POST['full_story'] );
$short_story = $parse->process( $_POST['short_story'] );
$full_story = $db->safesql( $parse->BB_Parse( $full_story, false ) );
$short_story = $db->safesql( $parse->BB_Parse( $short_story, false ) );
if( $parse->not_allowed_text ) {
msg( "error", $lang['addnews_error'], $lang['news_err_39'], "javascript:history.go(-1)" );
}
if( trim( $title ) == "" and $ifdelete != "yes" ) msg( "error", $lang['cat_error'], $lang['addnews_ertitle'], "javascript:history.go(-1)" );
if( strlen( $title ) > 255 ) {msg( "error", $lang['cat_error'], $lang['addnews_ermax'], "javascript:history.go(-1)" );}
if( trim( $_POST['alt_name'] ) == "" or ! $_POST['alt_name'] ) $alt_name = totranslit( stripslashes( $title ) );
else $alt_name = totranslit( stripslashes( $_POST['alt_name'] ) );
$remote_addr = $_POST['remote_addr'];
$title = $db->safesql( $title );
$metatags = create_metatags( $short_story . $full_story );
$catalog_url = $db->safesql( substr( htmlspecialchars( strip_tags( stripslashes( trim( $_POST['catalog_url'] ) ) ) ), 0, 3 ) );
if( preg_match( "/[\||\'|\<|\>|\"|\!|\?|\$|\@|\/|\\\|\&\~\*\+]/", $_POST['tags'] ) ) $_POST['tags'] = "";
else $_POST['tags'] = $db->safesql( htmlspecialchars( strip_tags( stripslashes( trim( $_POST['tags'] ) ) ), ENT_QUOTES ) );
if ( $_POST['tags'] ) {
$temp_array = array();
$tags_array = array();
$temp_array = explode (",", $_POST['tags']);
if (count($temp_array)) {
foreach ( $temp_array as $value ) {
if( trim($value) ) $tags_array[] = trim( $value );
}}
if ( count($tags_array) ) $_POST['tags'] = implode(", ", $tags_array); else $_POST['tags'] = "";
}
// обработка опроса
if( trim( $_POST['vote_title'] != "" ) ) {
$add_vote = 1;
$vote_title = trim( $db->safesql( $parse->process( $_POST['vote_title'] ) ) );
$frage = trim( $db->safesql( $parse->process( $_POST['frage'] ) ) );
$vote_body = $db->safesql( $parse->BB_Parse( $parse->process( $_POST['vote_body'] ), false ) );
$allow_m_vote = intval( $_POST['allow_m_vote'] );
} else $add_vote = 0;
// обработка доступа
if( $member_id['user_group'] < 3 and $ifdelete != "yes" ) {
$group_regel = array ();
foreach ( $_POST['group_extra'] as $key => $value ) {
if( $value ) $group_regel[] = intval( $key ) . ':' . intval( $value );
}
if( count( $group_regel ) ) $group_regel = implode( "||", $group_regel );
else $group_regel = "";
} else $group_regel = '';
$no_permission = FALSE;
$okdeleted = FALSE;
$okchanges = FALSE;
$db->query( "SELECT id, title, autor, category, approve, tags FROM " . PREFIX . "_post where id = '$id'" );
while ( $row = $db->get_row() ) {
$item_db[0] = $row['id'];
$item_db[1] = $row['autor'];
$item_db[2] = $row['tags'];
$item_db[3] = $row['approve'];
$item_db[4] = $db->safesql( $row['title'] );
$item_db[5] = explode( ',', $row['category'] );
}
$db->free();
if( $item_db[0] ) {
$have_perm = 0;
if( $user_group[$member_id['user_group']]['allow_all_edit'] ) $have_perm = 1;
if( $user_group[$member_id['user_group']]['allow_edit'] and $item_db[1] == $member_id['name'] ) {$have_perm = 1;}
if( $ifdelete == "yes" ) {
$allow_list = explode( ',', $user_group[$member_id['user_group']]['cat_add'] );
foreach ( $item_db[5] as $selected ) {if( $allow_list[0] != "all" AND !in_array($selected, $allow_list) ) $have_perm = 0;}
if( !$user_group[$member_id['user_group']]['moderation']) {$have_perm = 0;
}}
if( ($member_id['user_group'] == 1) ) {$have_perm = 1;}
if( $have_perm ) {
if( $ifdelete != "yes" ) {
$okchanges = TRUE;
// Обработка даты и времени
$added_time = time() + ($config['date_adjust'] * 60);
$newdate = $_POST['newdate'];
if( $_POST['allow_date'] != "yes" ) {
if( $_POST['allow_now'] == "yes" ) $thistime = date( "Y-m-d H:i:s", $added_time );
elseif( (($newsdate = strtotime( $newdate )) === - 1) or !$newsdate ) {
msg( "error", $lang['cat_error'], $lang['addnews_erdate'], "javascript:history.go(-1)" );
} else {
$thistime = date( "Y-m-d H:i:s", $newsdate );
if( ! intval( $config['no_date'] ) and $newsdate > $added_time ) {
$thistime = date( "Y-m-d H:i:s", $added_time );
}
}
$result = $db->query( "UPDATE " . PREFIX . "_post set title='$title', date='$thistime', short_story='$short_story', full_story='$full_story', descr='{$metatags['description']}', keywords='{$metatags['keywords']}', category='$category_list', alt_name='$alt_name', allow_comm='$allow_comm', approve='$approve', allow_main='$allow_main', allow_rate='$allow_rating', fixed='$news_fixed', votes='$add_vote', access='$group_regel', remote_addr='$remote_addr', editdate='$added_time', tags='{$_POST['tags']}', metatitle='{$metatags['title']}' WHERE id='$item_db[0]'" );
} else {
$result = $db->query( "UPDATE " . PREFIX . "_post set title='$title', short_story='$short_story', full_story='$full_story', descr='{$metatags['description']}', keywords='{$metatags['keywords']}', category='$category_list', alt_name='$alt_name', allow_comm='$allow_comm', approve='$approve', allow_main='$allow_main', allow_rate='$allow_rating', fixed='$news_fixed', votes='$add_vote', access='$group_regel', remote_addr='$remote_addr', editdate='$added_time', tags='{$_POST['tags']}', metatitle='{$metatags['title']}' WHERE id='$item_db[0]'" );
}
include (SYSTEM_DIR . '/inc/newsimg/doeditimg.php');
if( $add_vote ) {
$count = $db->super_query( "SELECT COUNT(*) as count FROM " . PREFIX . "_poll WHERE news_id = '$item_db[0]'" );
if( $count['count'] ) $db->query( "UPDATE " . PREFIX . "_poll set title='$vote_title', frage='$frage', body='$vote_body', multiple='$allow_m_vote' WHERE news_id = '$item_db[0]'" );
else $db->query( "INSERT INTO " . PREFIX . "_poll (news_id, title, frage, body, votes, multiple) VALUES('$item_db[0]', '$vote_title', '$frage', '$vote_body', 0, '$allow_m_vote')" );
} else {
$db->query( "DELETE FROM " . PREFIX . "_poll WHERE news_id='$item_db[0]'" );
$db->query( "DELETE FROM " . PREFIX . "_poll_log WHERE news_id='$item_db[0]'" );
}
// Смена автора публикации
if( $member_id['user_group'] == 1 and $_POST['new_author'] != $_POST['old_author'] ) {
$_POST['new_author'] = $db->safesql( $_POST['new_author'] );
$row = $db->super_query( "SELECT user_id FROM " . USERPREFIX . "_users WHERE name = '{$_POST['new_author']}'" );
if( $row['user_id'] ) {
$db->query( "UPDATE " . PREFIX . "_post SET autor='{$_POST['new_author']}' WHERE id='$item_db[0]'" );
$db->query( "UPDATE " . PREFIX . "_images SET author='{$_POST['new_author']}' WHERE news_id='$item_db[0]'" );
$db->query( "UPDATE " . PREFIX . "_files SET author='{$_POST['new_author']}' WHERE news_id='$item_db[0]'" );
$db->query( "UPDATE " . PREFIX . "_torrents SET author='{$_POST['new_author']}' WHERE news_id='$item_db[0]'" );
$db->query( "UPDATE " . USERPREFIX . "_users SET news_num=news_num+1 where user_id='{$row['user_id']}'" );
$db->query( "UPDATE " . USERPREFIX . "_users SET news_num=news_num-1 where name='$item_db[1]'" );
} else {
msg( "error", $lang['addnews_error'], $lang['edit_no_author'], "javascript:history.go(-1)" );
}
}
// Облако тегов
if( $_POST['tags'] != $item_db[2] or $approve != $item_db[3] ) {
$db->query( "DELETE FROM " . PREFIX . "_tags WHERE news_id = '$item_db[0]'" );
if( $_POST['tags'] != "" and $approve ) {
$tags = array ();
$_POST['tags'] = explode( ",", $_POST['tags'] );
foreach ( $_POST['tags'] as $value ) {
$tags[] = "('" . $item_db[0] . "', '" . trim( $value ) . "')";
}
$tags = implode( ", ", $tags );
$db->query( "INSERT INTO " . PREFIX . "_tags (news_id, tag) VALUES " . $tags );
}
}
} else {
$db->query( "DELETE FROM " . PREFIX . "_post WHERE id='$item_db[0]'" );
$db->query( "DELETE FROM " . PREFIX . "_comments WHERE post_id='$item_db[0]'" );
$db->query( "DELETE FROM " . PREFIX . "_poll WHERE news_id='$item_db[0]'" );
$db->query( "DELETE FROM " . PREFIX . "_poll_log WHERE news_id='$item_db[0]'" );
$db->query( "DELETE FROM " . PREFIX . "_rate WHERE type_id='$item_db[0]' AND type=1" );
$db->query( "DELETE FROM " . PREFIX . "_tags WHERE news_id = '$item_db[0]'" );
$db->query( "UPDATE " . USERPREFIX . "_users set news_num=news_num-1 where name='$item_db[1]'" );
$okdeleted = TRUE;
$db->query("SELECT id, link, thumb FROM " . PREFIX . "_covers WHERE newsid = '$item_db[0]'");
while($row_covers = $db->get_row()){
@unlink(ROOT_DIR."/uploads".$row_covers['link']);
@unlink(ROOT_DIR."/uploads".$row_covers['thumb']);
}
$db->query("DELETE FROM " . PREFIX . "_covers WHERE newsid = '$item_db[0]'");
$row = $db->super_query( "SELECT images FROM " . PREFIX . "_images where news_id = '$item_db[0]'" );
$listimages = explode( "|||", $row['images'] );
if( $row['images'] != "" ) foreach ( $listimages as $dataimages ) {
$url_image = explode( "/", $dataimages );
if( count( $url_image ) == 2 ) {
$folder_prefix = $url_image[0] . "/";
$dataimages = $url_image[1];
} else {
$folder_prefix = "";
$dataimages = $url_image[0];
}
@unlink( ROOT_DIR . "/uploads/posts/" . $folder_prefix . $dataimages );
@unlink( ROOT_DIR . "/uploads/posts/" . $folder_prefix . "thumbs/" . $dataimages );
}
$db->query( "DELETE FROM " . PREFIX . "_images WHERE news_id = '$item_db[0]'" );
$db->query("SELECT id, onserver FROM " . PREFIX . "_torrents WHERE news_id = '$item_db[0]'");
while($row_torrents = $db->get_row()){
@unlink(ROOT_DIR."/uploads/torrents/".$row_torrents['onserver']);
}
//$db->query("DELETE FROM " . PREFIX . "_torrents WHERE news_id = '$item_db[0]'");
$db->query( "UPDATE " . PREFIX . "_torrents SET flags=1 where news_id='$item_db[0]'" );
$db->query( "SELECT id, onserver FROM " . PREFIX . "_files WHERE news_id = '$item_db[0]'" );
while ( $row = $db->get_row() ) {
@unlink( ROOT_DIR . "/uploads/files/" . $row['onserver'] );
}
$db->query( "DELETE FROM " . PREFIX . "_files WHERE news_id = '$item_db[0]'" );
}
} else
$no_permission = TRUE;
}
$cache->clear();
if( ! $_SESSION['admin_referrer'] ) {
$_SESSION['admin_referrer'] = "?mod=editnews&action=list";
}
if( $no_permission ) {
msg( "error", $lang['addnews_error'], $lang['edit_denied'], $_SESSION['admin_referrer'] );
} elseif( $okdeleted ) {
msg( "info", $lang['edit_delok'], $lang['edit_delok_1'], $_SESSION['admin_referrer'] );
} elseif( $okchanges ) {
msg( "info", $lang['edit_alleok'], $lang['edit_alleok_1'], $_SESSION['admin_referrer'] );
} else {
msg( "error", $lang['addnews_error'], $lang['edit_allerr'], $_SESSION['admin_referrer'] );
}
}
?> |