[ Index ]
 

Code source de b2evolution 2.1.0-beta

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/blogs/inc/collections/ -> collections.ctrl.php (source)

   1  <?php
   2  /**

   3   * This file implements the UI controller for blog params management, including permissions.

   4   *

   5   * This file is part of the evoCore framework - {@link http://evocore.net/}

   6   * See also {@link http://sourceforge.net/projects/evocms/}.

   7   *

   8   * @copyright (c)2003-2007 by Francois PLANQUE - {@link http://fplanque.net/}

   9   * Parts of this file are copyright (c)2004-2006 by Daniel HAHLER - {@link http://thequod.de/contact}.

  10   *

  11   * {@internal License choice

  12   * - If you have received this file as part of a package, please find the license.txt file in

  13   *   the same folder or the closest folder above for complete license terms.

  14   * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)

  15   *   then you must choose one of the following licenses before using the file:

  16   *   - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php

  17   *   - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php

  18   * }}

  19   *

  20   * {@internal Open Source relicensing agreement:

  21   * Daniel HAHLER grants Francois PLANQUE the right to license

  22   * Daniel HAHLER's contributions to this file and the b2evolution project

  23   * under any OSI approved OSS license (http://www.opensource.org/licenses/).

  24   * }}

  25   *

  26   * @package admin

  27   *

  28   * {@internal Below is a list of authors who have contributed to design/coding of this file: }}

  29   * @author fplanque: Francois PLANQUE.

  30   *

  31   * @todo (sessions) When creating a blog, provide "edit options" (3 tabs) instead of a single long "New" form (storing the new Blog object with the session data).

  32   * @todo Currently if you change the name of a blog it gets not reflected in the blog list buttons!

  33   *

  34   * @version $Id: collections.ctrl.php,v 1.5 2007/11/02 02:46:27 fplanque Exp $

  35   */
  36  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  37  
  38  $AdminUI->set_path( 'blogs' );
  39  
  40  param_action( 'list' );
  41  
  42  if( $action != 'new'
  43      && $action != 'new-selskin'
  44      && $action != 'new-name'
  45      && $action != 'list'
  46      && $action != 'create' )
  47  {
  48      if( valid_blog_requested() )
  49      {
  50          // echo 'valid blog requested';

  51          $edited_Blog = & $Blog;
  52      }
  53      else
  54      {
  55          // echo 'NO valid blog requested';

  56          $action = 'list';
  57      }
  58  }
  59  else
  60  {    // We are not working on a specific blog (yet) -- prevent highlighting one in the list
  61      set_working_blog( 0 );
  62  }
  63  
  64  
  65  /**

  66   * Perform action:

  67   */
  68  switch( $action )
  69  {
  70      case 'new':
  71          // New collection:

  72          // Check permissions:

  73          $current_User->check_perm( 'blogs', 'create', true );
  74  
  75          $AdminUI->append_path_level( 'new', array( 'text' => T_('New') ) );
  76          break;
  77  
  78      case 'new-selskin':
  79          // New collection:

  80          // Check permissions:

  81          $current_User->check_perm( 'blogs', 'create', true );
  82  
  83          param( 'kind', 'string', true );
  84  
  85          // dh> TODO: "New %s" is probably too generic. What can %s become? (please comment it in "TRANS")

  86          $AdminUI->append_path_level( 'new', array( 'text' => sprintf( T_('New %s'), Blog::kind_name($kind) ) ) );
  87          break;
  88  
  89      case 'new-name':
  90          // New collection:

  91          // Check permissions:

  92          $current_User->check_perm( 'blogs', 'create', true );
  93  
  94          $edited_Blog = & new Blog( NULL );
  95  
  96          param( 'kind', 'string', true );
  97          $edited_Blog->init_by_kind( $kind );
  98  
  99           param( 'skin_ID', 'integer', true );
 100  
 101          $AdminUI->append_path_level( 'new', array( 'text' => sprintf( T_('New %s'), Blog::kind_name($kind) ) ) );
 102          break;
 103  
 104      case 'create':
 105          // Insert into DB:

 106          // Check permissions:

 107          $current_User->check_perm( 'blogs', 'create', true );
 108  
 109          $edited_Blog = & new Blog( NULL );
 110  
 111          param( 'kind', 'string', true );
 112          $edited_Blog->init_by_kind( $kind );
 113  
 114           param( 'skin_ID', 'integer', true );
 115          $edited_Blog->set( 'skin_ID', $skin_ID );
 116  
 117          if( $edited_Blog->load_from_Request( array() ) )
 118          {
 119              $DB->begin();
 120  
 121              // DB INSERT

 122              $edited_Blog->dbinsert();
 123  
 124              $Messages->add( T_('The new blog has been created.'), 'success' );
 125  
 126              // Set default user permissions for this blog (All permissions for the current user)

 127              // Proceed insertions:

 128              $DB->query( "
 129                      INSERT INTO T_coll_user_perms( bloguser_blog_ID, bloguser_user_ID, bloguser_ismember,
 130                              bloguser_perm_poststatuses, bloguser_perm_delpost, bloguser_perm_comments,
 131                              bloguser_perm_cats, bloguser_perm_properties,
 132                              bloguser_perm_media_upload, bloguser_perm_media_browse, bloguser_perm_media_change )
 133                      VALUES ( $edited_Blog->ID, $current_User->ID, 1,
 134                              'published,protected,private,draft,deprecated', 1, 1, 1, 1, 1, 1, 1 )" );
 135  
 136              // Create default category:

 137        load_class( 'chapters/model/_chapter.class.php' );
 138              $edited_Chapter = & new Chapter( NULL, $edited_Blog->ID );
 139              $edited_Chapter->set( 'name', T_('Uncategorized') );
 140              $edited_Chapter->set( 'urlname', 'main' );
 141              $edited_Chapter->dbinsert();
 142  
 143              $Messages->add( T_('A default category has been created for this blog.'), 'success' );
 144  
 145              // ADD DEFAULT WIDGETS:

 146              if( $edited_Blog->get( 'in_bloglist' ) )
 147              {    // This is a public blog, let's give it a public global navigation list by default:
 148                  $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code )
 149                                           VALUES( '.$edited_Blog->ID.', "Page Top", 1, "core", "colls_list_public" )' );
 150              }
 151              else
 152              {    // This is not a public blog, let's give it a restricted navigation list by default:
 153                  $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code )
 154                                           VALUES( '.$edited_Blog->ID.', "Page Top", 1, "core", "colls_list_owner" )' );
 155              }
 156  
 157              // Add title to all blog Headers:

 158              $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code )
 159                                       VALUES( '.$edited_Blog->ID.', "Header", 1, "core", "coll_title" )' );
 160              // Add tagline to all blogs Headers:

 161              $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code )
 162                                       VALUES( '.$edited_Blog->ID.', "Header", 2, "core", "coll_tagline" )' );
 163  
 164              // Add home link to all blogs Menus:

 165              $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code, wi_params )
 166                                       VALUES( '.$edited_Blog->ID.', "Menu", 1, "core", "menu_link", "'.$DB->escape(serialize(array('link_type'=>'home'))).'" )' );
 167              // Add info pages to all blogs Menus:

 168              $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code )
 169                                       VALUES( '.$edited_Blog->ID.', "Menu", 2, "core", "coll_page_list" )' );
 170              // Add contact link to all blogs Menus:

 171              $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code, wi_params )
 172                                       VALUES( '.$edited_Blog->ID.', "Menu", 3, "core", "menu_link", "'.$DB->escape(serialize(array('link_type'=>'ownercontact'))).'" )' );
 173              // Add login link to all blogs Menus:

 174              $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code, wi_params )
 175                                       VALUES( '.$edited_Blog->ID.', "Menu", 4, "core", "menu_link", "'.$DB->escape(serialize(array('link_type'=>'login'))).'" )' );
 176  
 177              // Add Calendar plugin to all blog Sidebars:

 178              $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code )
 179                                       VALUES( '.$edited_Blog->ID.', "Sidebar", 1, "plugin", "evo_Calr" )' );
 180              // Add title to all blog Sidebars:

 181              $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code )
 182                                       VALUES( '.$edited_Blog->ID.', "Sidebar", 2, "core", "coll_title" )' );
 183              // Add longdesc to all blogs Sidebars:

 184              $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code )
 185                                       VALUES( '.$edited_Blog->ID.', "Sidebar", 3, "core", "coll_longdesc" )' );
 186              // Add common links to all blogs Sidebars:

 187              $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code )
 188                                       VALUES( '.$edited_Blog->ID.', "Sidebar", 4, "core", "coll_common_links" )' );
 189              // Add search form to all blogs Sidebars:

 190              $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code )
 191                                       VALUES( '.$edited_Blog->ID.', "Sidebar", 5, "core", "coll_search_form" )' );
 192              // Add category links to all blog Sidebars:

 193              $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code )
 194                                       VALUES( '.$edited_Blog->ID.', "Sidebar", 6, "core", "coll_category_list" )' );
 195              // Add XML feeds to all blogs Sidebars:

 196              $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code )
 197                                       VALUES( '.$edited_Blog->ID.', "Sidebar", 7, "core", "coll_xml_feeds" )' );
 198  
 199              $Messages->add( T_('Default widgets have been set-up for this blog.'), 'success' );
 200  
 201              $DB->commit();
 202  
 203              // Commit changes in cache:

 204              $BlogCache = & get_Cache( 'BlogCache' );
 205              $BlogCache->add( $edited_Blog );
 206  
 207              // We want to highlight the edited object on next list display:

 208               // $Session->set( 'fadeout_array', array( 'blog_ID' => array($edited_Blog->ID) ) );

 209  
 210              header_redirect( 'admin.php?ctrl=coll_settings&tab=features&blog='.$edited_Blog->ID ); // will save $Messages into Session

 211          }
 212          break;
 213  
 214  
 215      case 'delete':
 216          // ----------  Delete a blog from DB ----------

 217          // Check permissions:

 218          $current_User->check_perm( 'blog_properties', 'edit', true, $blog );
 219  
 220          if( param( 'confirm', 'integer', 0 ) )
 221          { // confirmed
 222              // Delete from DB:

 223              $msg = sprintf( T_('Blog &laquo;%s&raquo; deleted.'), $edited_Blog->dget('name') );
 224  
 225              param( 'delete_static_file', 'integer', 0 );
 226              $edited_Blog->dbdelete( $delete_static_file );
 227  
 228              $Messages->add( $msg, 'success' );
 229  
 230              $BlogCache->remove_by_ID( $blog );
 231              unset( $edited_Blog );
 232              unset( $Blog );
 233              forget_param( 'blog' );
 234              set_working_blog( 0 );
 235              $UserSettings->delete( 'selected_blog' );    // Needed or subsequent pages may try to access the delete blog

 236              $UserSettings->dbupdate();
 237  
 238              $action = 'list';
 239          }
 240          break;
 241  
 242  
 243      case 'GenStatic':
 244          // ----------  Generate static homepage for blog ----------

 245          $AdminUI->append_to_titlearea( sprintf( T_('Generating static page for blog [%s]'), $edited_Blog->dget('name') ) );
 246          $current_User->check_perm( 'blog_genstatic', 'any', true, $blog );
 247  
 248          param( 'redir_after_genstatic', 'string', NULL );
 249  
 250          $sourcefile = $edited_Blog->get_setting('source_file');
 251          if( empty( $sourcefile ) )
 252          {
 253              $Messages->add( T_('You haven\'t defined a source file for this blog!') );
 254          }
 255          else
 256          {
 257              $staticfilename = $edited_Blog->get_setting('static_file');
 258              if( empty( $staticfilename ) )
 259              {
 260                  $Messages->add( T_('You haven\'t defined a static file for this blog!') );
 261              }
 262              else
 263              {
 264                  // GENERATION!

 265                  $static_gen_saved_locale = $current_locale;
 266                  $generating_static = true;
 267                  $resolve_extra_path = false;
 268  
 269                  ob_start();
 270  
 271                  // Set some defaults in case they're not set by stub/source file:

 272                  // We need to set required variables

 273                  $blog = $edited_Blog->ID;
 274                  # This setting retricts posts to those published, thus hiding drafts.

 275                  $show_statuses = array();
 276                  # Here you can set a limit before which posts will be ignored

 277                  $timestamp_min = '';
 278                  # Here you can set a limit after which posts will be ignored

 279                  $timestamp_max = 'now';
 280  
 281                  require $edited_Blog->get('dynfilepath');
 282  
 283                  $generated_static_page_html = ob_get_contents();
 284                  ob_end_clean();
 285  
 286                  unset( $generating_static );
 287  
 288                  // Switch back to saved locale (the blog page may have changed it):

 289                  locale_activate( $static_gen_saved_locale);
 290  
 291                  $staticfilename = $edited_Blog->get('staticfilepath');
 292  
 293                  if( ! ($fp = @fopen( $staticfilename, 'w' )) )
 294                  { // could not open file
 295                      $Messages->add( T_('File cannot be written!') );
 296                      $Messages->add( sprintf( '<p>'.T_('You should check the file permissions for [%s]. See <a %s>online manual on file permissions</a>.').'</p>',$staticfilename, 'href="http://b2evolution.net/man/install/file_permissions.html"' ) );
 297                  }
 298                  else
 299                  { // file is writable
 300                      fwrite( $fp, $generated_static_page_html );
 301                      fclose( $fp );
 302                      $Messages->add( sprintf( T_('Generated static file &laquo;%s&raquo;.'), $staticfilename ), 'success' );
 303                  }
 304              }
 305          }
 306  
 307          if( !empty( $redir_after_genstatic ) )
 308          {
 309              header_redirect( $redir_after_genstatic );
 310          }
 311          break;
 312  }
 313  
 314  /**

 315   * Display page header, menus & messages:

 316   */
 317  if( strpos( $action, 'new' ) === false )
 318  { // Not creating a new blog:
 319      // fp> TODO: fall back to ctrl=chapters when no perm for blog_properties

 320      $blogListButtons = $AdminUI->get_html_collection_list( 'blog_properties', 'edit',
 321                                                  '?ctrl=coll_settings&amp;tab=general&amp;blog=%d',
 322                                                  T_('List'), '?ctrl=collections&amp;blog=0' );
 323  }
 324  
 325  // Display <html><head>...</head> section! (Note: should be done early if actions do not redirect)

 326  $AdminUI->disp_html_head();
 327  
 328  // Display title, menu, messages, etc. (Note: messages MUST be displayed AFTER the actions)

 329  $AdminUI->disp_body_top();
 330  
 331  
 332  switch($action)
 333  {
 334      case 'new':
 335          $AdminUI->displayed_sub_begin = 1;    // DIRTY HACK :/ replacing an even worse hack...

 336          $AdminUI->disp_payload_begin();
 337  
 338          $AdminUI->disp_view( 'collections/views/_coll_sel_type.view.php' );
 339  
 340          $AdminUI->disp_payload_end();
 341          break;
 342  
 343  
 344      case 'new-selskin':
 345          $AdminUI->displayed_sub_begin = 1;    // DIRTY HACK :/ replacing an even worse hack...

 346          $AdminUI->disp_payload_begin();
 347  
 348          $AdminUI->disp_view( 'skins/views/_coll_sel_skin.view.php' );
 349  
 350          $AdminUI->disp_payload_end();
 351          break;
 352  
 353  
 354      case 'new-name':
 355      case 'create': // in case of validation error
 356          $AdminUI->displayed_sub_begin = 1;    // DIRTY HACK :/ replacing an even worse hack...

 357          $AdminUI->disp_payload_begin();
 358  
 359          // ---------- "New blog" form ----------

 360          echo '<h2>'.sprintf( T_('New %s'), Blog::kind_name($kind) ).':</h2>';
 361  
 362          $next_action = 'create';
 363  
 364          $AdminUI->disp_view( 'collections/views/_coll_general.form.php' );
 365  
 366          $AdminUI->disp_payload_end();
 367          break;
 368  
 369  
 370      case 'delete':
 371          // ----------  Delete a blog from DB ----------

 372          // Not confirmed

 373          ?>
 374          <div class="panelinfo">
 375              <h3><?php printf( T_('Delete blog [%s]?'), $edited_Blog->dget( 'name' ) )?></h3>
 376  
 377              <p><?php echo T_('Deleting this blog will also delete all its categories, posts and comments!') ?></p>
 378  
 379              <p><?php echo T_('THIS CANNOT BE UNDONE!') ?></p>
 380  
 381              <p>
 382  
 383              <?php
 384  
 385                  $Form = & new Form( NULL, '', 'get', 'none' );
 386  
 387                  $Form->begin_form( 'inline' );
 388  
 389                  $Form->hidden_ctrl();
 390                  $Form->hidden( 'action', 'delete' );
 391                  $Form->hidden( 'blog', $edited_Blog->ID );
 392                  $Form->hidden( 'confirm', 1 );
 393  
 394                  if( is_file( $edited_Blog->get('staticfilepath') ) )
 395                  {
 396                      ?>
 397                      <input type="checkbox" id="delete_static_file" name="delete_static_file" value="1" />
 398                      <label for="delete_static_file"><?php printf( T_('Also try to delete static file [<strong><a %s>%s</a></strong>]'), 'href="'.$edited_Blog->dget('staticurl').'"', $edited_Blog->dget('staticfilepath') ); ?></label><br />
 399                      <br />
 400                      <?php
 401                  }
 402  
 403                  $Form->submit( array( '', T_('I am sure!'), 'DeleteButton' ) );
 404  
 405                  $Form->end_form();
 406  
 407  
 408                  $Form->begin_form( 'inline' );
 409                      $Form->hidden_ctrl();
 410                      $Form->hidden( 'blog', 0 );
 411                      $Form->submit( array( '', T_('CANCEL'), 'CancelButton' ) );
 412                  $Form->end_form();
 413              ?>
 414  
 415              </p>
 416  
 417              </div>
 418          <?php
 419          break;
 420  
 421  
 422      default:
 423          // List the blogs:

 424          $AdminUI->displayed_sub_begin = 1;    // DIRTY HACK :/ replacing an even worse hack...

 425          $AdminUI->disp_payload_begin();
 426          // Display VIEW:

 427          $AdminUI->disp_view( 'collections/views/_coll_list.view.php' );
 428          $AdminUI->disp_payload_end();
 429  
 430  }
 431  
 432  
 433  // Display body bottom, debug info and close </html>:

 434  $AdminUI->disp_global_footer();
 435  
 436  
 437  /*

 438   * $Log: collections.ctrl.php,v $

 439   * Revision 1.5  2007/11/02 02:46:27  fplanque

 440   * refactored blog settings / UI

 441   *

 442   * Revision 1.4  2007/11/01 19:50:28  fplanque

 443   * minor

 444   *

 445   * Revision 1.3  2007/09/28 02:17:49  fplanque

 446   * Menu widgets

 447   *

 448   * Revision 1.2  2007/07/01 03:55:05  fplanque

 449   * category plugin replaced by widget

 450   *

 451   * Revision 1.1  2007/06/25 10:59:30  fplanque

 452   * MODULES (refactored MVC)

 453   *

 454   * Revision 1.25  2007/06/21 00:44:36  fplanque

 455   * linkblog now a widget

 456   *

 457   * Revision 1.24  2007/05/28 01:35:23  fplanque

 458   * fixed static page generation

 459   *

 460   * Revision 1.23  2007/05/15 18:49:32  blueyed

 461   * trans todo

 462   *

 463   * Revision 1.22  2007/05/13 18:49:54  fplanque

 464   * made autoselect_blog() more robust under PHP4

 465   *

 466   * Revision 1.21  2007/05/09 01:58:57  fplanque

 467   * Widget to display other blogs from same owner

 468   *

 469   * Revision 1.20  2007/05/08 19:36:06  fplanque

 470   * automatic install of public blog list widget on new blogs

 471   *

 472   * Revision 1.19  2007/05/07 23:26:19  fplanque

 473   * public blog list as a widget

 474   *

 475   * Revision 1.18  2007/04/26 00:11:07  fplanque

 476   * (c) 2007

 477   *

 478   * Revision 1.17  2007/03/25 13:20:51  fplanque

 479   * cleaned up blog base urls

 480   * needs extensive testing...

 481   *

 482   * Revision 1.16  2007/01/15 18:48:06  fplanque

 483   * cleanup

 484   *

 485   * Revision 1.15  2007/01/15 16:59:57  fplanque

 486   * create default widgets with each new blog

 487   *

 488   * Revision 1.14  2007/01/15 03:54:36  fplanque

 489   * pepped up new blog creation a little more

 490   *

 491   * Revision 1.13  2007/01/15 00:38:06  fplanque

 492   * pepped up "new blog" creation a little. To be continued.

 493   *

 494   * Revision 1.12  2007/01/14 22:09:52  fplanque

 495   * attempt to display the list of blogs in a modern way.

 496   *

 497   * Revision 1.11  2006/12/18 03:20:21  fplanque

 498   * _header will always try to set $Blog.

 499   * controllers can use valid_blog_requested() to make sure we have one

 500   * controllers should call set_working_blog() to change $blog, so that it gets memorized in the user settings

 501   *

 502   * Revision 1.10  2006/12/17 23:42:38  fplanque

 503   * Removed special behavior of blog #1. Any blog can now aggregate any other combination of blogs.

 504   * Look into Advanced Settings for the aggregating blog.

 505   * There may be side effects and new bugs created by this. Please report them :]

 506   *

 507   * Revision 1.9  2006/12/17 02:42:21  fplanque

 508   * streamlined access to blog settings

 509   *

 510   * Revision 1.8  2006/12/13 18:17:39  blueyed

 511   * Fixed header_redirect() which would only work if b2evo is installed in DOCUMENT_ROOT and would not have been RFC-compliant anyway

 512   *

 513   * Revision 1.7  2006/12/11 16:53:47  fplanque

 514   * controller name cleanup

 515   *

 516   * Revision 1.6  2006/12/11 00:32:26  fplanque

 517   * allow_moving_chapters stting moved to UI

 518   * chapters are now called categories in the UI

 519   *

 520   * Revision 1.5  2006/11/26 02:30:38  fplanque

 521   * doc / todo

 522   *

 523   * Revision 1.4  2006/11/24 18:27:22  blueyed

 524   * Fixed link to b2evo CVS browsing interface in file docblocks

 525   *

 526   * Revision 1.3  2006/11/24 18:06:02  blueyed

 527   * Handle saving of $Messages centrally in header_redirect()

 528   */
 529  ?>


Généré le : Thu Nov 29 23:58:50 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics