Changeset 538:aedf484a0a44 for plugins/simpleMenu/index.php
- Timestamp:
- 07/09/11 18:44:49 (14 years ago)
- Branch:
- themes
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/simpleMenu/index.php
r534 r538 19 19 $p_url = 'plugin.php?p=simpleMenu'; 20 20 21 # Url du blog 22 $blog_url = html::stripHostURL($core->blog->url); 23 21 24 # Liste des catégories 22 25 $categories_combo = array(); … … 111 114 } 112 115 113 # Menu par défaut114 $blog_url = html::stripHostURL($core->blog->url);115 $menu_default = array(116 array('label' => __('Home'), 'descr' => __('Recent posts'), 'url' => $blog_url),117 array('label' => __('Archives'), 'descr' => __('Old posts'), 'url' => $blog_url.$core->url->getBase('archive'))118 );119 120 116 # Lecture menu existant 121 117 $menu = $core->blog->settings->system->get('simpleMenu'); 122 118 $menu = @unserialize($menu); 123 119 if (!is_array($menu)) { 124 $menu = $menu_default; 125 $core->blog->settings->system->put('simpleMenu',serialize($menu)); 120 $menu = array(); 126 121 } 127 122 … … 129 124 $item_type = isset($_POST['item_type']) ? $_POST['item_type'] : ''; 130 125 $item_select = isset($_POST['item_select']) ? $_POST['item_select'] : ''; 126 $item_label = isset($_POST['item_label']) ? $_POST['item_label'] : ''; 127 $item_descr = isset($_POST['item_descr']) ? $_POST['item_descr'] : ''; 128 $item_url = isset($_POST['item_url']) ? $_POST['item_url'] : ''; 131 129 132 130 # Traitement … … 209 207 // Fourth step, menu item to be added 210 208 try { 211 if ( $item_label && $item_url)209 if (($item_label != '') && ($item_url != '')) 212 210 { 213 211 // Add new item menu in menu array … … 231 229 break; 232 230 } 231 } else { 232 if (!empty($_POST['removeaction'])) 233 { 234 try { 235 if (!empty($_POST['items_selected'])) { 236 foreach ($_POST['items_selected'] as $k => $v) { 237 $menu[$k]['label'] = ''; 238 } 239 $newmenu = array(); 240 foreach ($menu as $k => $v) { 241 if ($v['label']) { 242 $newmenu[] = array( 243 'label' => $v['label'], 244 'descr' => $v['descr'], 245 'url' => $v['url']); 246 } 247 } 248 $menu = $newmenu; 249 // Save menu in blog settings 250 $core->blog->settings->system->put('simpleMenu',serialize($menu)); 251 252 // All done successfully, return to menu items list 253 http::redirect($p_url.'&removed=1'); 254 } else { 255 throw new Exception(__('No menu items selected.')); 256 } 257 } 258 catch (Exception $e) { 259 $core->error->add($e->getMessage()); 260 } 261 } 262 if (!empty($_POST['updateaction'])) 263 { 264 try { 265 foreach ($_POST['items_label'] as $k => $v) { 266 if (!$v) throw new Exception(__('Label is mandatory.')); 267 } 268 foreach ($_POST['items_url'] as $k => $v) { 269 if (!$v) throw new Exception(__('URL is mandatory.')); 270 } 271 $newmenu = array(); 272 for ($i = 0; $i < count($_POST['items_label']); $i++) 273 { 274 $newmenu[] = array( 275 'label' => $_POST['items_label'][$i], 276 'descr' => $_POST['items_descr'][$i], 277 'url' => $_POST['items_url'][$i]); 278 } 279 $menu = $newmenu; 280 // Save menu in blog settings 281 $core->blog->settings->system->put('simpleMenu',serialize($menu)); 282 283 // All done successfully, return to menu items list 284 http::redirect($p_url.'&updated=1'); 285 } 286 catch (Exception $e) { 287 $core->error->add($e->getMessage()); 288 } 289 } 290 291 # Order menu items 292 $order = array(); 293 if (empty($_POST['im_order']) && !empty($_POST['order'])) { 294 $order = $_POST['order']; 295 asort($order); 296 $order = array_keys($order); 297 } elseif (!empty($_POST['im_order'])) { 298 $order = explode(',',$_POST['im_order']); 299 } 300 301 if (!empty($_POST['saveorder']) && !empty($order)) 302 { 303 try { 304 $newmenu = array(); 305 foreach ($order as $i => $k) { 306 $newmenu[] = array( 307 'label' => $menu[$k]['label'], 308 'descr' => $menu[$k]['descr'], 309 'url' => $menu[$k]['url']); 310 } 311 $menu = $newmenu; 312 // Save menu in blog settings 313 $core->blog->settings->system->put('simpleMenu',serialize($menu)); 314 315 // All done successfully, return to menu items list 316 http::redirect($p_url.'&neworder=1'); 317 } 318 catch (Exception $e) { 319 $core->error->add($e->getMessage()); 320 } 321 } 322 233 323 } 234 324 … … 238 328 <html> 239 329 <head> 240 <title><?php echo $page_title; ?></title> 330 <title><?php echo $page_title; ?></title> 331 <?php 332 echo 333 dcPage::jsToolMan(); //. 334 // dcPage::jsLoad('index.php?pf=simpleMenu/dragdrop.js'); 335 ?> 336 <!-- 337 <link rel="stylesheet" type="text/css" href="index.php?pf=simpleMenu/style.css" /> 338 --> 241 339 </head> 242 340 … … 252 350 } 253 351 if (!empty($_GET['neworder'])) { 352 echo '<p class="message">'.__('Menu items have been successfully updated.').'</p>'; 353 } 354 if (!empty($_GET['updated'])) { 254 355 echo '<p class="message">'.__('Menu items have been successfully updated.').'</p>'; 255 356 } … … 266 367 echo '<fieldset><legend>'.__('Select type').'</legend>'; 267 368 echo '<p class="field"><label for"item_type" class="classic">'.__('Type of item menu:').'</label>'.form::combo('item_type',$items_combo,'').'</p>'; 268 echo '<p>'.$core->formNonce().'<input type="submit" name="append " value="'.__('Continue').'" />'.'</p>';369 echo '<p>'.$core->formNonce().'<input type="submit" name="appendaction" value="'.__('Continue').'" />'.'</p>'; 269 370 echo '</fieldset>'; 270 371 echo '</form>'; … … 298 399 } 299 400 echo form::hidden('item_type',$item_type); 300 echo '<p>'.$core->formNonce().'<input type="submit" name="append " value="'.__('Continue').'" /></p>';401 echo '<p>'.$core->formNonce().'<input type="submit" name="appendaction" value="'.__('Continue').'" /></p>'; 301 402 echo '</fieldset>'; 302 403 echo '</form>'; … … 308 409 echo '<fieldset><legend>'.$item_type_label.($item_select_label != '' ? ' ('.$item_select_label.')' : '').'</legend>'; 309 410 echo '<p class="field"><label for"item_label" class="classic">'.__('Label of item menu:').'</label>'.form::field('item_label',10,255,$item_label).'</p>'; 310 echo '<p class="field"><label for"item_descr" class="classic">'.__('Description of item menu:').'</label>'.form::field('item_ label',20,255,$item_descr).'</p>';411 echo '<p class="field"><label for"item_descr" class="classic">'.__('Description of item menu:').'</label>'.form::field('item_descr',20,255,$item_descr).'</p>'; 311 412 echo '<p class="field"><label for"item_url" class="classic">'.__('URL of item menu:').'</label>'.form::field('item_url',40,255,$item_url).'</p>'; 312 413 echo form::hidden('item_type',$item_type).form::hidden('item_select',$item_select); 313 echo '<p>'.$core->formNonce().'<input type="submit" name="append " value="'.__('Add item').'" /></p>';414 echo '<p>'.$core->formNonce().'<input type="submit" name="appendaction" value="'.__('Add item').'" /></p>'; 314 415 echo '</fieldset>'; 315 416 echo '</form>'; 316 417 break; 317 418 } 419 } 420 421 // Liste des items 422 if (!$step) { 423 echo '<h2>'.html::escapeHTML($core->blog->name).' › <span class="page-title">'.$page_title.'</span></h2>'; 424 } 425 426 if (count($menu)) { 427 if (!$step) { 428 echo '<form id="menuitems" action="'.$p_url.'" method="post">'; 429 } 430 // Entête table 431 echo 432 '<table id="menuitemslist">'. 433 '<caption>'.__('Menu items list').'</caption>'. 434 '<thead>'. 435 '<tr>'; 436 if (!$step) { 437 echo '<th scope="col"></th>'; 438 if (count($menu) > 1) { 439 echo '<th scope="col">'.__('Order').'</th>'; 440 } 441 } 442 echo 443 '<th scope="col">'.__('Label').'</th>'. 444 '<th scope="col">'.__('Description').'</th>'. 445 '<th scope="col">'.__('URL').'</th>'. 446 '</tr>'. 447 '</thead>'. 448 '<tbody>'; 449 $count = 0; 450 foreach ($menu as $i => $m) { 451 echo '<tr>'; 452 if (!$step) { 453 $count++; 454 echo '<td>'.form::checkbox(array('items_selected[]','ims-'.$i),false,'','','',($step)).'</td>'; 455 if (count($menu) > 1) { 456 echo '<td>'.form::field(array('order['.$i.']'),2,3,$count,'position','',false,'title="'.sprintf(__('position of %s'),__($m['label'])).'"'). 457 form::hidden(array('dynorder[]','dynorder-'.$i),$i).'</td>'; 458 } 459 echo '<td class="nowrap" scope="row">'.form::field(array('items_label[]','iml-'.$i),10,255,__($m['label']),'','',($step)).'</td>'; 460 echo '<td class="nowrap">'.form::field(array('items_descr[]','imd-'.$i),20,255,__($m['descr']),'','',($step)).'</td>'; 461 echo '<td class="nowrap">'.form::field(array('items_url[]','imu-'.$i),40,255,$m['url'],'','',($step)).'</td>'; 462 } else { 463 echo '<td class="nowrap" scope="row">'.__($m['label']).'</td>'; 464 echo '<td class="nowrap">'.__($m['descr']).'</td>'; 465 echo '<td class="nowrap">'.$m['url'].'</td>'; 466 } 467 echo '</tr>'; 468 } 469 echo '</tbody>'. 470 '</table>'; 471 if (!$step) { 472 echo '<p>'.form::hidden('im_order','').$core->formNonce(); 473 if (count($menu) > 1) { 474 echo '<input type="submit" name="saveorder" value="'.__('Save order').'" /> '; 475 } 476 echo 477 '<input type="submit" name="updateaction" value="'.__('Update menu items').'" /> '. 478 '<input type="submit" class="delete" name="removeaction" '. 479 'value="'.__('Delete selected menu items').'" '. 480 'onclick="return window.confirm(\''.html::escapeJS(__('Are you sure you want to remove selected menu items?')).'\');" />'. 481 '</p>'; 482 echo '</form>'; 483 } 318 484 } else { 319 // Liste des items 320 echo '<h2>'.html::escapeHTML($core->blog->name).' › <span class="page-title">'.$page_title.'</span></h2>'; 321 485 echo 486 '<p>'.__('Currently no menu items').'</p>'; 487 } 488 489 if (!$step) { 322 490 echo '<form id="menuitems" action="'.$p_url.'&add=1" method="post">'; 323 echo '<p>'.$core->formNonce().'<input type="submit" name="append" value="'.__('Add an item').'" /></p>';491 echo '<p>'.$core->formNonce().'<input class="add" type="submit" name="appendaction" value="'.__('Add an item').'" /></p>'; 324 492 echo '</form>'; 325 493 }
Note: See TracChangeset
for help on using the changeset viewer.