protected function main() { $this->set_title(Nw::$lang['news']['en_attente_title']); $this->set_tpl('news/list_versions.html'); inc_lib('news/news_exists'); $count_news_existe = news_exists($_GET['id']); if ($count_news_existe == false) { redir(Nw::$lang['news']['news_not_exist'], false, 'news-70.html'); } inc_lib('news/get_info_news'); $donnees_news = get_info_news($_GET['id']); // Fil ariane $this->set_filAriane(array(Nw::$lang['news']['news_section'] => array('news-70.html'), $donnees_news['c_nom'] => array($donnees_news['c_rewrite'] . '/'), $donnees_news['n_titre'] => array($donnees_news['c_rewrite'] . '/' . rewrite($donnees_news['n_titre']) . '-' . $_GET['id'] . '/'), Nw::$lang['news']['gestion_vrs'] => array('news-16-' . $_GET['id'] . '.html'), Nw::$lang['news']['list_vrs_fa'] => array(''))); // Ce membre a le droit d'éditer la news ? if ($donnees_news['n_etat'] != 3 && !is_logged_in()) { redir(Nw::$lang['news']['not_view_news_perm'], false, './'); } // Redirection pour comparer 2 versions if (isset($_POST['compare_diff']) && isset($_POST['rev_old']) && isset($_POST['rev_new'])) { if ($_POST['rev_new'] != $_POST['rev_old']) { header('Location: news-16-' . $_GET['id'] . '.html?vrs1=' . intval($_POST['rev_old']) . '&vrs2=' . intval($_POST['rev_new'])); } } /** * Comparaison de 2 versions d'une news * Requiert SHELL /!\ **/ $output_compare = ''; $compare_versions = false; $news_vrs1 = 0; $news_vrs2 = 0; if ($donnees_news['n_nb_versions'] > 1) { // Parser BBcode inc_lib('bbcode/unparse'); $news_vrs1 = 0; $news_vrs2 = 0; $id_unique = uniqid(); // On compare 2 versions if (isset($_GET['vrs1']) && is_numeric($_GET['vrs1']) && isset($_GET['vrs2']) && is_numeric($_GET['vrs2'])) { $news_vrs1 = $_GET['vrs1']; $news_vrs2 = $_GET['vrs2']; $compare_versions = true; } inc_lib('news/get_compare_text_vrs'); $textes_compare = get_compare_text_vrs($_GET['id'], $news_vrs1, $news_vrs2); $news_vrs1 = isset($textes_compare[1][0]) ? $textes_compare[1][0] : ''; $news_vrs2 = isset($textes_compare[0][0]) ? $textes_compare[0][0] : ''; function clean_cache_file($content) { $content = explode("\r", trim($content)); $array_return = array(); foreach ($content as $texte_trim) { if (strlen(trim($texte_trim)) > 0) { $array_return[] = trim($texte_trim); } } return $array_return; } /** * Utilisation de la classe Text_diff (http://pear.php.net/package/Text_Diff/download/1.1.0) **/ include_once 'Text/Diff.php'; include_once 'Text/Diff/Renderer/unified.php'; $lines1 = clean_cache_file(unparse($textes_compare[1][1], 0)); $lines2 = clean_cache_file(unparse($textes_compare[0][1], 0)); $diff = new Text_Diff($lines1, $lines2); $renderer = new Text_Diff_Renderer_unified(); $array_compare = explode("\n", $renderer->render($diff)); foreach ($array_compare as $donnees) { $first_cararacter = ''; $style_line = ''; if (isset($donnees[0]) && in_array($donnees[0], array('-', '+'))) { if ($donnees[0] == '-') { $style_line = ' style="background-color: #ffcccc;"'; } elseif ($donnees[0] == '+') { $style_line = ' style="background-color: #ccffcc;"'; } $first_cararacter = $donnees[0]; $ligne_changee = substr($donnees, 1); } else { $ligne_changee = $donnees; } if (!in_array(substr($donnees, 0, 2), array('@@')) && strlen(trim($ligne_changee)) > 0) { $output_compare .= '<tr> <td class="line_statut">' . $first_cararacter . '</td> <td' . $style_line . '>' . trim($ligne_changee) . '</td> </tr>'; } } } /** * Affichage de la liste des versions **/ inc_lib('news/get_list_vrs'); $numeros_version = array(); $donnees_version = get_list_vrs($_GET['id']); foreach ($donnees_version as $donnees) { Nw::$tpl->setBlock('versions', array('ID' => $donnees['v_id'], 'NUM' => $donnees['v_number'], 'AUTEUR' => $donnees['u_pseudo'], 'AUTEUR_ID' => $donnees['u_id'], 'AUTEUR_ALIAS' => $donnees['u_alias'], 'MINEURE' => $donnees['v_mineure'], 'DATE' => date_sql($donnees['date'], $donnees['heures_date'], $donnees['jours_date']), 'COMMENT' => $donnees['v_raison'], 'IP' => long2ip($donnees['v_ip']))); $numeros_version[$donnees['v_id']] = $donnees['v_number']; } $numbers_vrs = array_flip($numeros_version); $texte_compare = ''; if ($donnees_news['n_nb_versions'] > 1) { $texte_compare = sprintf(Nw::$lang['news']['comparaison_2_versions'], $numeros_version[$news_vrs1], $numeros_version[$news_vrs2]); } $droit_edit_news = false; if (is_logged_in()) { inc_lib('news/can_edit_news'); $droit_edit_news = can_edit_news($donnees_news['n_id_auteur'], $donnees_news['n_etat']); } Nw::$tpl->set(array('ID' => $_GET['id'], 'TITRE' => $donnees_news['n_titre'], 'REWRITE' => rewrite($donnees_news['n_titre']), 'CAT_REWRITE' => $donnees_news['c_rewrite'], 'COMPARAISON' => $output_compare, 'LAST_VERSION' => $donnees_news['n_last_version'], 'NB_VERSIONS' => $donnees_news['n_nb_versions'], 'NUMBERS_VRS' => $numbers_vrs, 'TXT_COMPARE' => $texte_compare, 'DRT_VIEW_IP' => is_logged_in() && Nw::$droits['can_see_ip'], 'NUM_OLD' => $news_vrs1, 'NUM_NEW' => $news_vrs2, 'NEWS_AUTEUR' => $donnees_news['n_id_auteur'], 'CHG_MY_VERSIONS' => is_logged_in() && Nw::$droits['can_change_version_my_news'], 'CHG_ALL_VERSIONS' => is_logged_in() && Nw::$droits['can_change_version_all_news'], 'DLT_VERSIONS' => is_logged_in() && Nw::$droits['can_delete_version'], 'LINK_NB_CONTRIB' => sprintf(Nw::$lang['news']['edit_nb_contrib'], $donnees_news['n_nb_versions']), 'DRT_EDIT' => $droit_edit_news)); }
protected function main() { if (!is_logged_in()) { redir(Nw::$lang['common']['need_login'], false, 'users-10.html'); } $this->set_title(Nw::$lang['news']['en_redaction_title']); $this->set_tpl('news/redaction.html'); $this->add_wid_in_content('redaction'); // Fil ariane $this->set_filAriane(array(Nw::$lang['news']['news_section'] => array('news-70.html'), Nw::$lang['news']['en_redaction_title'] => array(''))); // On compte le nbr de news en rédaction inc_lib('news/count_news'); $nombre_news = count_news('n_etat = 1'); // Pagination $page = isset($_GET['page']) ? intval($_GET['page']) : 1; $nombreDePages = ceil($nombre_news / Nw::$pref['nb_news_redac']); // On vérifie bien que la page existe if ($nombreDePages > 0 && $page > $nombreDePages) { redir(Nw::$lang['common']['pg_not_exist'], false, 'news-70.html'); } // On recherche toutes les news en rédaction inc_lib('news/get_list_news'); $list_dn_news = get_list_news('n_etat = 1', 'f_type DESC, n_last_mod DESC', $page, Nw::$pref['nb_news_redac']); $news_act = 'null'; if ($nombre_news > 0) { inc_lib('news/get_list_tags_news'); inc_lib('news/get_list_flags_news'); $list_tags = array(); $list_flags = array(); $array_favoris = array(); $donnees_tags = get_list_tags_news(1); $donnees_flags = get_list_flags_news(1); foreach ($donnees_flags as $all_flags) { if ($all_flags['f_type'] == 1) { $array_favoris[] = $all_flags['f_id_news']; } $list_flags[$all_flags['f_id_news']][] = '<li class="netat"><a href="news-5.html?flag=' . $all_flags['f_type'] . '&status=1">' . $all_flags['txt_lang'] . '</a></li>'; } foreach ($donnees_tags as $all_tags) { $list_tags[$all_tags['t_id_news']][] = '<li class="ntag"><a href="search.html?s=' . $all_tags['rewrite'] . '">' . $all_tags['t_tag'] . '</a></li>'; } } $nbr_news = 0; // On affiche toutes les news en rédaction inc_lib('news/can_edit_news'); foreach ($list_dn_news as $donnees_news) { $flags_html = ''; // Affichage du séparateur if ($donnees_news['f_type'] != $news_act) { $texte_title = ''; // Séparation des news if ($donnees_news['f_type'] == 0) { $texte_title = '<div class="separation_news"></div>'; } Nw::$tpl->setBlock('redaction', array('NAME' => $texte_title)); $news_act = $donnees_news['f_type']; } // Cette news a des flags? (Je rédige, etc.) if (isset($list_flags[$donnees_news['n_id']]) && count($list_flags[$donnees_news['n_id']]) > 0) { $flags_html = implode(' ', $list_flags[$donnees_news['n_id']]); } if (isset($list_tags[$donnees_news['n_id']])) { $tags_news = array_slice($list_tags[$donnees_news['n_id']], 0, 5); } else { $tags_news = array(); } // Il y a au moins un tag if (count($tags_news) > 0) { $tags_html = implode(' ', $tags_news); } else { $tags_html = '<li class="ntag"><span>' . Nw::$lang['news']['none_tag'] . '</span></li>'; } Nw::$tpl->setBlock('redaction.news', array('ID' => $donnees_news['n_id'], 'CAT_ID' => $donnees_news['c_id'], 'CAT_TITRE' => $donnees_news['c_nom'], 'CAT_REWRITE' => $donnees_news['c_rewrite'], 'TITRE' => $donnees_news['n_titre'], 'RESUME' => $donnees_news['n_resume'], 'REWRITE' => rewrite($donnees_news['n_titre']), 'AUTEUR' => $donnees_news['u_pseudo'], 'AUTEUR_ID' => $donnees_news['u_id'], 'AUTEUR_ALIAS' => $donnees_news['u_alias'], 'AUTEUR_AVATAR' => $donnees_news['u_avatar'], 'DATE' => date_sql($donnees_news['date_news'], $donnees_news['heures_date_news'], $donnees_news['jours_date_news']), 'NBR_COMS' => sprintf(Nw::$lang['news']['nbr_comments_news'], $donnees_news['n_nbr_coms'], $donnees_news['n_nbr_coms'] > 1 ? Nw::$lang['news']['add_s_comments'] : ''), 'NBR_VERSIONS' => $donnees_news['n_nb_versions'] > 1 ? '<a href="news-16-' . $donnees_news['n_id'] . '.html">' . sprintf(Nw::$lang['news']['nbr_versions_news'], $donnees_news['n_nb_versions']) . '</a>' : Nw::$lang['news']['none_versions'], 'TAGS' => $tags_html, 'FLAGS' => $flags_html, 'COLOR' => $nbr_news % 2, 'FLAGS_FAV' => (bool) in_array($donnees_news['n_id'], $array_favoris), 'EDIT' => can_edit_news($donnees_news['n_id_auteur'], $donnees_news['n_etat']), 'DELETE' => $donnees_news['n_id_auteur'] == Nw::$dn_mbr['u_id'] && Nw::$droits['can_delete_mynews'] || Nw::$droits['can_delete_news'] ? true : false)); ++$nbr_news; } /** * Dernières news créées **/ inc_lib('news/get_list_news'); $last_news = get_list_news('n_etat = 1', 'n_date DESC', 1, 7); foreach ($last_news as $donnees_news) { Nw::$tpl->setBlock('ln', array('ID' => $donnees_news['n_id'], 'TITRE' => $donnees_news['n_titre'], 'CAT_REWRITE' => $donnees_news['c_rewrite'], 'REWRITE' => rewrite($donnees_news['n_titre']), 'NBR_COMS' => sprintf(Nw::$lang['news']['nbr_comments_news'], $donnees_news['n_nbr_coms'], $donnees_news['n_nbr_coms'] > 1 ? Nw::$lang['news']['add_s_comments'] : ''), 'NBR_VERSIONS' => $donnees_news['n_nb_versions'] > 1 ? '<a href="news-16-' . $donnees_news['n_id'] . '.html">' . sprintf(Nw::$lang['news']['nbr_versions_news'], $donnees_news['n_nb_versions']) . '</a>' : Nw::$lang['news']['none_versions'])); } /** * Dernière contribution **/ inc_lib('news/get_list_vrs'); $last_contrib = get_list_vrs(0, 7); foreach ($last_contrib as $donnees_contrib) { Nw::$tpl->setBlock('lc', array('ID' => $donnees_contrib['v_id'], 'ID_NEWS' => $donnees_contrib['v_id_news'], 'RAISON' => $donnees_contrib['v_raison'], 'AUTEUR' => $donnees_contrib['u_pseudo'], 'AUTEUR_ID' => $donnees_contrib['u_id'], 'AUTEUR_ALIAS' => $donnees_contrib['u_alias'], 'AUTEUR_AVATAR' => $donnees_contrib['u_avatar'], 'REWRITE' => rewrite($donnees_contrib['n_titre']), 'CAT_REWRITE' => $donnees_contrib['c_rewrite'], 'INT' => sprintf(Nw::$lang['news']['version_x'], $donnees_contrib['v_id']), 'DATE' => date_sql($donnees_contrib['date'], $donnees_contrib['heures_date'], $donnees_contrib['jours_date']))); } Nw::$tpl->set(array('LIST_PG' => list_pg($nombreDePages, $page, 'news-70%s.html'))); }