b2evolution PHP Cross Reference Blogging Systems

Source: /inc/links/links.ctrl.php - 232 lines - 6239 bytes - Text - Print

Description: This file implements the UI controller for link objects. b2evolution - {@link http://b2evolution.net/} Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}

   1  <?php
   2  /**

   3   * This file implements the UI controller for link objects.

   4   *

   5   * b2evolution - {@link http://b2evolution.net/}

   6   * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}

   7   * @copyright (c)2003-2014 by Francois Planque - {@link http://fplanque.com/}

   8   * 

   9   * @package admin

  10   * 

  11   * @version $Id: $

  12   */
  13  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  14  
  15  /**

  16   * @var AdminUI

  17   */
  18  global $AdminUI;
  19  
  20  global $Blog, $Session;
  21  
  22  /*

  23   * Initialize everything

  24   */
  25  $action = param_action( 'list' );
  26  $redirect_to = param( 'redirect_to', 'url', /*regenerate_url( '', '', '', '&' )*/NULL );
  27  //$mode = 'iframe';

  28  
  29  switch( $action )
  30  {
  31      case 'set_link_position':
  32          param('link_position', 'string', true);
  33      case 'unlink':
  34      case 'link_move_up':
  35      case 'link_move_down':
  36          // Name of the iframe we want some action to come back to:

  37          param( 'iframe_name', 'string', '', true );
  38  
  39          // TODO fp> when moving an "after_more" above a "teaser" img, it should change to "teaser" too.

  40          // TODO fp> when moving a "teaser" below an "aftermore" img, it should change to "aftermore" too.

  41  
  42          param( 'link_ID', 'integer', true );
  43          $LinkCache = & get_LinkCache();
  44          if( ($edited_Link = & $LinkCache->get_by_ID( $link_ID, false )) !== false )
  45          {    // We have a link, get the LinkOwner it is attached to:
  46              $LinkOwner = & $edited_Link->get_LinkOwner();
  47  
  48              // Load the blog we're in:

  49              $Blog = & $LinkOwner->get_Blog();
  50              set_working_blog( $Blog->ID );
  51          }
  52          else
  53          {    // We could not find the link to edit:
  54              $Messages->add( sprintf( T_('Requested &laquo;%s&raquo; object does not exist any longer.'), T_('Link') ), 'error' );
  55              unset( $edited_Link );
  56              unset( $link_ID );
  57              if( $mode == 'iframe' )
  58              {
  59                  $action = 'edit_links';
  60              }
  61              else
  62              {
  63                  $action = 'nil';
  64              }
  65          }
  66          break;
  67  }
  68  
  69  if( $action == 'edit_links' )
  70  { // set LinkOwner from params
  71      $link_type = param( 'link_type', 'string', 'item', true );
  72      $object_ID = param( 'link_object_ID', 'integer', 0, true );
  73      $LinkOwner = get_link_owner( $link_type, $object_ID );
  74      if( empty( $Blog ) )
  75      { // Load the blog we're in:
  76          $Blog = & $LinkOwner->get_Blog();
  77          set_working_blog( $Blog->ID );
  78      }
  79  }
  80  
  81  if( empty( $LinkOwner ) )
  82  { // If LinkOwner object is not set, we can't process any action
  83      $Messages->add( T_('Requested link owner object does not exist any longer.'), 'error' );
  84      header_redirect( $redirect_to );
  85  }
  86  
  87  switch( $action )
  88  {
  89      case 'edit_links':
  90          // Display link owner attachments

  91  
  92          // Check permission:

  93          $LinkOwner->check_perm( 'edit', true );
  94  
  95          // Add JavaScript to handle links modifications.

  96          require_js( 'links.js' );
  97          break;
  98  
  99      case 'unlink':
 100          // Delete a link:

 101  
 102          // Check that this action request is not a CSRF hacked request:

 103          $Session->assert_received_crumb( "link" );
 104  
 105          // Check permission:

 106          $LinkOwner->check_perm( 'edit', true );
 107  
 108          // Unlink File from Item:

 109          $edited_Link->dbdelete( true );
 110          unset($edited_Link);
 111  
 112          // Update last touched date of Item

 113          $LinkOwner->item_update_last_touched_date();
 114  
 115          $Messages->add( $LinkOwner->translate( 'Link has been deleted from $ownerTitle$' ), 'success' );
 116  
 117          header_redirect( $redirect_to );
 118          break;
 119  
 120      case 'link_move_up':
 121      case 'link_move_down':
 122          // Check that this action request is not a CSRF hacked request:

 123          $Session->assert_received_crumb( "link" );
 124  
 125          // Check permission:

 126          $LinkOwner->check_perm( 'edit', true );
 127  
 128          $ownerLinks = $LinkOwner->get_Links();
 129  
 130          // TODO fp> when moving an "after_more" above a "teaser" img, it should change to "teaser" too.

 131          // TODO fp> when moving a "teaser" below an "aftermore" img, it should change to "aftermore" too.

 132  
 133          // Switch order with the next/prev one

 134          if( $action == 'link_move_up' )
 135          {
 136              $switchcond = 'return ($loop_Link->get("order") > $i
 137                  && $loop_Link->get("order") < '.$edited_Link->get("order").');';
 138              $i = -1;
 139          }
 140          else
 141          {
 142              $switchcond = 'return ($loop_Link->get("order") < $i
 143                  && $loop_Link->get("order") > '.$edited_Link->get("order").');';
 144              $i = PHP_INT_MAX;
 145          }
 146          foreach( $ownerLinks as $loop_Link )
 147          { // find nearest order
 148              if( $loop_Link == $edited_Link )
 149                  continue;
 150  
 151              if( eval($switchcond) )
 152              {
 153                  $i = $loop_Link->get('order');
 154                  $switch_Link = $loop_Link;
 155              }
 156          }
 157          if( $i > -1 && $i < PHP_INT_MAX )
 158          { // switch
 159              $switch_Link->set('order', $edited_Link->get('order'));
 160  
 161              // HACK: go through order=0 to avoid duplicate key conflict

 162              $edited_Link->set('order', 0);
 163              $edited_Link->dbupdate( true );
 164              $switch_Link->dbupdate( true );
 165  
 166              $edited_Link->set('order', $i);
 167              $edited_Link->dbupdate( true );
 168  
 169  
 170              if( $action == 'link_move_up' )
 171                  $msg = T_('Link has been moved up.');
 172              else
 173                  $msg = T_('Link has been moved down.');
 174  
 175              $Messages->add( $msg, 'success' );
 176  
 177              // Update last touched date of Item

 178              $LinkOwner->item_update_last_touched_date();
 179          }
 180          else
 181          {
 182              $Messages->add( T_('Link order has not been changed.'), 'note' );
 183          }
 184  
 185          header_redirect( $redirect_to );
 186          break;
 187  
 188  
 189      case 'set_link_position':
 190          // Check that this action request is not a CSRF hacked request:

 191          $Session->assert_received_crumb( 'link' );
 192  
 193          // Check permission:

 194          $LinkOwner->check_perm( 'edit', true );
 195  
 196          if( $edited_Link->set( 'position', $link_position ) && $edited_Link->dbupdate() )
 197          {
 198              $Messages->add( T_('Link position has been changed.'), 'success' );
 199  
 200              // Update last touched date of Item

 201              $LinkOwner->item_update_last_touched_date();
 202          }
 203          else
 204          {
 205              $Messages->add( T_('Link position has not been changed.'), 'note' );
 206          }
 207  
 208          $header_redirect( $redirect_to );
 209          break;
 210  }
 211  
 212  // require colorbox js

 213  require_js_helper( 'colorbox' );
 214  
 215  $AdminUI->disp_html_head();
 216  $AdminUI->disp_body_top( false );
 217  
 218  switch( $action )
 219  {
 220      case 'edit_links':
 221          // Memorize 'action' for prev/next links

 222          memorize_param( 'action', 'string', NULL );
 223  
 224          // View attachments

 225          $AdminUI->disp_view( 'links/views/_link_list.view.php' );
 226          break;
 227  }
 228  
 229  // Display body bottom, debug info and close </html>:

 230  $AdminUI->disp_global_footer();
 231  
 232  ?>

title

Description

title

Description

title

Description

title

title

Body