$countrys = $db->query("SELECT id, name FROM `country`");
$countrysList = array();
while ($row = $db->get_row()) {
$country = new \stdClass();
$country->name = $row["name"];
$countryList[] = $country;
}
$db->free();
echo <<<HTML
<pre>
HTML;
print_r($countrysList);
echo <<<HTML
</pre>
HTML;
function id2country($s) {
global $countrysList;
return "("
. implode( // собрать все обратно
", ",
array_map( // для каждого элемента после explode()
function($el) use ($countrysList) {
return $countrysList[intval(trim($el))]->name; // убрать пробелы, перевести в int и взять название страны из массива
},
explode( // разбить по запятой
",",
trim($s, "()") // убрать внешние скобки
)
)
)
. ")";
}
$db->query( "SELECT p.id, p.date, p.title, p.category, p.country, p.autor, p.alt_name, p.comm_num, p.approve, p.fixed, e.news_read, e.votes, e.user_id, e.need_pass FROM " . PREFIX . "_post p LEFT JOIN " . PREFIX . "_post_extras e ON (p.id=e.news_id) " . $where . " ORDER BY " . $order_by . " LIMIT {$start_from},{$news_per_page}" );
// Prelist Entries
$i = $start_from;
if( $start_from == "0" ) {
$start_from = "";
}
$entries_showed = 0;
$entries = "";
while ( $row = $db->get_array() ) {
$i ++;
if( $langformatdate ) {
$itemdate = date( $langformatdate, strtotime( $row['date'] ) );
} else {
$itemdate = date( "d.m.Y", strtotime( $row['date'] ) );
}
$title = $row['title'];
$title = htmlspecialchars( stripslashes( $title ), ENT_QUOTES, $config['charset'] );
$title = str_replace("&","&", $title );
$entries .= "<tr><td class=\"hidden-xs hidden-sm text-nowrap cursor-pointer text-center\" onclick=\"document.location = '?mod=editnews&action=editnews&id={$row['id']}'; return false;\">{$itemdate}</td><td class=\"cursor-pointer\" onclick=\"document.location = '?mod=editnews&action=editnews&id={$row['id']}'; return false;\">";
if( $config['allow_alt_url'] ) {
if( $config['seo_type'] == 1 OR $config['seo_type'] == 2 ) {
if( intval( $row['category'] ) and $config['seo_type'] == 2 ) {
$full_link = $config['http_home_url'] . get_url( intval( $row['category'] ) ) . "/" . $row['id'] . "-" . $row['alt_name'] . ".html";
} else {
$full_link = $config['http_home_url'] . $row['id'] . "-" . $row['alt_name'] . ".html";
}
} else {
$full_link = $config['http_home_url'] . date( 'Y/m/d/', strtotime( $row['date'] ) ) . $row['alt_name'] . ".html";
}
} else {
$full_link = $config['http_home_url'] . "index.php?newsid=" . $row['id'];
}
if( $row['comm_num'] > 0 ) {
$row['comm_num'] = number_format( $row['comm_num'], 0, ',', ' ');
$comm_link = <<<HTML
<div class="btn-group">
<a href="{$full_link}" target="_blank" data-toggle="dropdown" data-original-title="{$lang['edit_com']}" class="tip">{$row['comm_num']}</a>
<ul class="dropdown-menu text-left">
<li><a href="{$full_link}" target="_blank"><i class="fa fa fa-eye"></i> {$lang['comm_view']}</a></li>
<li><a href="?mod=comments&action=edit&id={$row['id']}"><i class="fa fa-pencil"></i> {$lang['vote_edit']}</a></li>
<li><a href="?mod=comments&user_hash={$dle_login_hash}&action=dorebuild&id={$row['id']}"><i class="fa fa-retweet"></i> {$lang['news_r_comments']}</a></li>
<li class="divider"></li>
<li><a onclick="javascript:cdelete('{$row['id']}'); return(false)" href="?mod=comments&user_hash={$dle_login_hash}&action=dodelete&id={$row['id']}"><i class="fa fa-trash-o"></i> {$lang['comm_del']}</a></li>
</ul>
</div>
HTML;
} else {
$comm_link = <<<HTML
<div class="btn-group">
<a href="{$full_link}" target="_blank" data-toggle="dropdown" data-original-title="{$lang['edit_com']}" class="tip">{$row['comm_num']}</a>
<ul class="dropdown-menu text-left">
<li><a href="?mod=comments&user_hash={$dle_login_hash}&action=dorebuild&id={$row['id']}"><i class="fa fa-retweet"></i> {$lang['news_r_comments']}</a></li>
</ul>
</div>
HTML;
}
$row['news_read'] = number_format( $row['news_read'], 0, ',', ' ');
if( $row['fixed'] ) $entries .= "<span class=\"badge badge-danger position-left\">{$lang['edit_fix']}</span>";
if( $row['votes'] ) $entries .= "<i class=\"fa fa-bar-chart position-left text-muted\"></i>";
if( $row['need_pass'] ) $entries .= "<i class=\"fa fa-lock position-left text-muted\"></i>";
$entries .= "<a title='{$lang['edit_act']}' href=\"?mod=editnews&action=editnews&id={$row['id']}\">{$title}</a></td>
<td class=\"hidden-xs text-nowrap text-center\"><a data-original-title=\"{$lang['st_views']}\" class=\"tip\" href=\"{$full_link}\" target=\"_blank\">{$row['news_read']}</a></td>";
$strani = id2country($row['country']);
$entries .= "</td><td class=\"hidden-xs cursor-pointer\">{$strani}</td>";
$entries .= "<td class=\"hidden-xs text-nowrap text-center\" style=\"text-align: center\">{$comm_link}</td><td style=\"text-align: center\" class=\"cursor-pointer\" onclick=\"document.location = '?mod=editnews&action=editnews&id={$row['id']}'; return false;\">";
if( $row['approve'] ) $erlaub = "<span class=\"text-success\"><b><i class=\"fa fa-check-circle\"></i></b></span>";
else $erlaub = "<span class=\"text-danger\"><b><i class=\"fa fa-exclamation-circle\"></i></b></span>";
$entries .= $erlaub;
if( ! $row['category'] ) $my_cat = "---";
else {
$my_cat = array ();
$cat_list = explode( ',', $row['category'] );
foreach ( $cat_list as $element ) {
if( $element AND $cat_info[$element]['name'] ) $my_cat[] = $cat_info[$element]['name'];
}
if( count($my_cat) ) $my_cat = implode( ', ', $my_cat );
else $my_cat = "---";
}
$entries .= "</td><td class=\"hidden-xs cursor-pointer\" onclick=\"document.location = '?mod=editnews&action=editnews&id={$row['id']}'; return false;\">{$my_cat}</td>";
if( $user_group[$member_id['user_group']]['admin_editusers'] ) {
$entries .= "<td class=\"hidden-xs hidden-sm text-center\"><a href=\"{$full_link}\" target=\"_blank\">" . $row['id'] . "</a></td>";
} else {
$entries .= "<td class=\"hidden-xs hidden-sm text-center\">" . $row['id'] . "</td>";
}
$entries .= "<td style=\"text-align: center\"><input name=\"selected_news[]\" value=\"{$row['id']}\" type=\"checkbox\" class=\"icheck\"></td></tr>";
$entries_showed ++;
}