[ Index ] |
|
Code source de Plume CMS 1.2.2 |
1 <?php 2 /* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 3 /* 4 # ***** BEGIN LICENSE BLOCK ***** 5 # This file is part of Plume CMS, a website management application. 6 # Copyright (C) 2001-2005 Loic d'Anterroches and contributors. 7 # 8 # Plume CMS is free software; you can redistribute it and/or modify 9 # it under the terms of the GNU General Public License as published by 10 # the Free Software Foundation; either version 2 of the License, or 11 # (at your option) any later version. 12 # 13 # Plume CMS is distributed in the hope that it will be useful, 14 # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 # GNU General Public License for more details. 17 # 18 # You should have received a copy of the GNU General Public License 19 # along with this program; if not, write to the Free Software 20 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 # 22 # ***** END LICENSE BLOCK ***** */ 23 24 require_once 'path.php'; 25 require_once $_PX_config['manager_path'].'/prepend.php'; 26 require_once $_PX_config['manager_path'].'/inc/class.news.php'; 27 28 auth::checkAuth(PX_AUTH_NORMAL); 29 $is_user_admin = auth::asLevel(PX_AUTH_ADMIN); 30 31 $m = new Manager(); 32 $_px_theme = $m->user->getTheme(); 33 34 /* ================================================= * 35 * Generate sub-menu * 36 * ================================================= */ 37 38 $px_submenu->addItem(__('Back to the list of resources'), 'index.php', 39 'themes/'.$_px_theme.'/images/ico_back.png', false); 40 $px_submenu->addItem(__('News list'), 'news.php?op=list', 41 'themes/'.$_px_theme.'/images/ico_news.png', false); 42 $px_submenu->addItem(__('New news'), 'news.php', 43 'themes/'.$_px_theme.'/images/ico_new.png', false, 44 (!empty($_REQUEST['op'])||empty($_REQUEST['resource_id'])) 45 ); 46 47 48 /* ========================================================================= * 49 * Process block * 50 * ========================================================================= */ 51 52 if (empty($_REQUEST['op'])) { 53 /* ===================================================================== * 54 * add/edit/view a news * 55 * ===================================================================== */ 56 $news = new News(); 57 /*================================================= 58 * Get current news and check if right to edit it 59 *=================================================*/ 60 $is_editable = true; 61 if (!empty($_REQUEST['resource_id'])) { 62 if (false !== $m->loadResource($news, $_REQUEST['resource_id'])) { 63 // check the rights 64 if (!$m->asRightToEdit($news)) { 65 $is_editable = false; 66 } 67 } else { 68 $m->setError(__('Error: The requested news is not available.'), 69 400); 70 $is_editable = false; 71 } 72 } else { 73 // Set default values for a new news. 74 $news->setDefaults($m->user); 75 } 76 /* ================================================= * 77 * No news, set default values or from preview * 78 * ================================================= */ 79 if ((!empty($_POST['preview']) || !empty($_POST['publish']) 80 || !empty($_POST['transform']) || !empty($_POST['addcategory']) 81 || !empty($_POST['increase']) || !empty($_POST['increase_x']) 82 || !empty($_POST['decrease']) || !empty($_POST['decrease_x']) 83 ) && $is_editable) { 84 $news->set(form::getPostField('n_title'), 85 form::getPostField('n_subject'), 86 form::getPostField('n_content'), 87 form::getPostField('n_content_format'), 88 form::getPostField('n_status'), 89 form::getTimeField('n_dt') /*Publication date */, 90 form::getTimeField('n_dt_e') /*End date */, 91 form::getPostField('n_noenddate'), 92 form::getPostField('n_comment_support'), 93 form::getPostField('n_subtype')); 94 95 $news->setDetails(form::getPostField('n_titlewebsite'), 96 form::getPostField('n_linkwebsite')); 97 if ($news->f('resource_id') == '') { 98 $news->setField('category_id', form::getPostField('n_category_id')); 99 } 100 101 if (!empty($_POST['increase']) || !empty($_POST['increase_x'])) { 102 $m->user->increase('news_textarea_content'); 103 } 104 if (!empty($_POST['decrease']) || !empty($_POST['decrease_x'])) { 105 $m->user->decrease('news_textarea_content'); 106 } 107 108 if (!empty($_POST['transform'])) { 109 $news->setField('description', 110 '=html'."\n" 111 .$news->getFormattedContent('description','html')); 112 } 113 } 114 115 /* ================================================= * 116 * Add, edit a news * 117 * ================================================= */ 118 if (!empty($_POST['publish']) && $is_editable) { 119 if ($news->f('resource_id') > 0) { 120 // edit a news 121 if (false !== ($id = $m->saveNews($news))) { 122 if ($news->f('status') != PX_RESOURCE_STATUS_INEDITION) { 123 $m->setMessage(__('The news was successfully saved.')); 124 header('Location: news.php?op=list'); 125 } else { 126 header('Location: news.php?resource_id='. 127 $news->f('resource_id')); 128 } 129 exit; 130 } 131 } else { 132 // add a news 133 $px_news_category_id = form::getPostField('n_category_id'); 134 $m->user->savePref('news_category_id', $px_news_category_id); 135 $m->user->savePref('news_status', 136 form::getPostField('n_status')); 137 $m->user->savePref('content_format', 138 form::getPostField('n_content_format')); 139 $m->user->savePref('news_subtype', 140 form::getPostField('n_subtype')); 141 $m->user->savePref('news_comment_support', 142 form::getPostField('n_comment_support')); 143 $news->setField('category_id', $px_news_category_id); 144 if (false !== ($id = $m->saveNews($news))) { 145 $m->setMessage(__('The news was successfully saved.')); 146 if ($news->f('status') != PX_RESOURCE_STATUS_INEDITION) { 147 header('Location: news.php?op=list'); 148 } else { 149 header('Location: news.php?resource_id='.$id); 150 } 151 exit; 152 } 153 } 154 } 155 156 /* ================================================= * 157 * Associate to a category * 158 * ================================================= */ 159 if (strlen(form::getField('addcategory')) 160 && strlen(form::getField('n_category_id')) 161 && strlen($news->f('resource_id')) 162 && $is_editable) { 163 164 $px_news_category_id = form::getField('n_category_id'); 165 166 $m->user->savePref('news_category_id', $px_news_category_id); 167 168 if ('main' == form::getField('addcategory')) { 169 $type = PX_RESOURCE_CATEGORY_MAIN; 170 } else { 171 $type = PX_RESOURCE_CATEGORY_OTHER; 172 } 173 174 if (false !== $m->addResourceInCategory($news, $px_news_category_id, 175 $type)) { 176 header('Location: news.php?resource_id='.$news->f('resource_id')); 177 exit; 178 } 179 } 180 181 /* ================================================= * 182 * Remove from a category * 183 * ================================================= */ 184 if (strlen(form::getField('delcat')) 185 && strlen($news->f('resource_id')) 186 && strlen(form::getField('n_category_id')) 187 && $is_editable) { 188 189 $px_news_category_id = form::getField('n_category_id'); 190 if (false !== $m->removeResourceFromCategory($news, 191 $px_news_category_id)) { 192 header('Location: news.php?resource_id='.$news->f('resource_id')); 193 exit; 194 } 195 } 196 197 /* ================================================= * 198 * Delete the news * 199 * ================================================= */ 200 if (strlen(form::getPostField('delete')) && $is_editable) { 201 if ($m->delNews($news) !== false) { 202 $m->setMessage(__('The news was successfully deleted.')); 203 header('Location: news.php?op=list'); 204 exit; 205 } 206 } 207 208 /* ================================================= * 209 * Remove a comment * 210 * ================================================= */ 211 if (strlen(form::getField('delete-comment')) 212 && strlen($news->f('resource_id')) 213 && strlen(form::getField('comment_id')) 214 && $is_editable) { 215 216 $id = form::getField('comment_id'); 217 if (false !== ($ct = $m->getComment($id, $news->f('resource_id')))) { 218 if (false !== $m->delComment($ct)) { 219 $m->setMessage(__('The comment was successfully deleted.')); 220 header('Location: news.php?resource_id='.$news->f('resource_id')); 221 exit; 222 } 223 } 224 } 225 226 /* ================================================= * 227 * Add/Edit a comment * 228 * ================================================= */ 229 if (strlen(form::getField('publish-comment')) 230 && strlen($news->f('resource_id')) 231 && $is_editable) { 232 $id = form::getField('comment_id'); 233 $ct = new Comment(); 234 if ((int) $id > 0) { 235 if (false === $ct->load($id)) { 236 $m->setError(__('The requested comment does not exist.')); 237 } 238 } 239 if (false === $m->error()) { 240 $ct->set(form::getField('c_author'), 241 form::getField('c_email'), 242 form::getField('c_website'), 243 form::getField('c_content'), 244 $news->f('resource_id'), 245 ($ct->f('comment_ip')) ? $ct->f('comment_ip') : $_SERVER["REMOTE_ADDR"], 246 form::getField('c_status'), 247 PX_COMMENT_TYPE_NORMAL, 248 ($ct->f('comment_id')) ? $ct->f('comment_user_id') : $m->user->getId()); 249 if (false !== $m->saveComment($ct)) { 250 $m->setMessage(__('The comment was successfully saved.')); 251 header('Location: news.php?resource_id='.$news->f('resource_id')); 252 exit; 253 } 254 } 255 } 256 257 258 /* ================================================= * 259 * Get the categories for the news, array of status * 260 * array for the dates * 261 * ================================================= */ 262 if ($is_editable) { 263 $arry_cat = $m->getArrayCategories(); 264 $arry_subtypes = $m->getSubTypesArray('news'); 265 $arry_subtypes_extra = $m->getSubTypesArray('news', 1); 266 } 267 268 269 } // add/edit/view a news 270 271 272 273 /* ========================================================================= * 274 * List the news * 275 * ========================================================================= */ 276 if (!empty($_REQUEST['op']) && 'list' == $_REQUEST['op']) { 277 278 //Get the category id and save it 279 $cat_id = (!empty($_GET['cat_id'])) ? $_GET['cat_id'] : $m->user->getPref('list_news_cat_id'); 280 281 $m->user->savePref('list_news_cat_id', $cat_id, $_SESSION['website_id'], true); 282 if ($cat_id == 'allcat') $cat_id = ''; 283 284 //Get the search query 285 $px_q = (!empty($_GET['q'])) ? $_GET['q'] : ''; 286 287 //Get available months and selected 288 list($first, $last, $arry_months) = $m->getArrayMonths('news', $cat_id); 289 $px_m_s = $m->user->getPref('list_news_month'); 290 $px_m = (!empty($_GET['m'])) ? $_GET['m'] : ((!empty($px_m_s)) ? $px_m_s : $last); 291 $m->user->savePref('list_news_month', $px_m, $_SESSION['website_id'], true); 292 293 if ($px_m == 'alldate') { 294 $px_m = $first; 295 $px_end = date::stamp(0, 1 /*1 month after now*/, 0); 296 } else { 297 $px_end = date::stamp(0, 1 /*1 month after $px_m */, 0, date::unix($px_m)); 298 } 299 300 if (empty($px_q)) { 301 $res = $m->getResources(''/* All users */, '' /* All status */, $cat_id, 'news', $px_m /*Date start */, $px_end /*Date end */); 302 //get again as possibly modified because of the 'alldate' case 303 $px_m = $m->user->getPref('list_news_month'); 304 } else { 305 $res = $m->searchResources($px_q, false /*Not only the online resources */, 'news', 'ResourceSet' /*Class used for the results */); 306 //Search is made on all the date and all the categories 307 $px_m = 'alldate'; 308 $cat_id = 'allcat'; 309 } 310 311 // Categories 312 $arry_cat = $m->getArrayCategories(true); 313 314 } 315 316 /* ========================================================================= * 317 * Display block * 318 * ========================================================================= */ 319 320 321 $px_title = __('News'); 322 include dirname(__FILE__).'/mtemplates/_top.php'; 323 324 echo '<h1>'.__('News').'</h1>'."\n\n"; 325 326 if (empty($_REQUEST['op'])) { 327 include dirname(__FILE__).'/mtemplates/news-edit.php'; 328 $px_resource_id = $news->f('resource_id'); 329 // Include list of comments 330 // Include add/edit comment 331 } elseif (!empty($_REQUEST['op']) && 'list' == $_REQUEST['op']) { 332 include dirname(__FILE__).'/mtemplates/news-list.php'; 333 } 334 335 include dirname(__FILE__).'/mtemplates/_bottom.php'; 336 337 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 11:57:01 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |