b2evolution PHP Cross Reference Blogging Systems

Source: /inc/collections/model/_blog.funcs.php - 1303 lines - 40697 bytes - Summary - Text - Print

Description: This file implements Blog handling functions. This file is part of the evoCore framework - {@link http://evocore.net/} See also {@link http://sourceforge.net/projects/evocms/}.

   1  <?php
   2  /**
   3   * This file implements Blog handling functions.
   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-2014 by Francois Planque - {@link http://fplanque.com/}
   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 evocore
  27   *
  28   * {@internal Below is a list of authors who have contributed to design/coding of this file: }}
  29   * @author blueyed: Daniel HAHLER.
  30   * @author fplanque: Francois PLANQUE.
  31   *
  32   * @version $Id: _blog.funcs.php 6136 2014-03-08 07:59:48Z manuel $
  33   */
  34  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  35  
  36  
  37  /**
  38   * Update the advanced user/group permissions for edited blog
  39   *
  40   * @param int Blog ID
  41   * @param string 'user' or 'group'
  42   */
  43  function blog_update_perms( $blog, $context = 'user' )
  44  {
  45      global $DB;
  46  
  47       /**
  48       * @var User
  49       */
  50      global $current_User;
  51  
  52      if( $context == 'user' )
  53      {
  54          $table = 'T_coll_user_perms';
  55          $prefix = 'bloguser_';
  56          $ID_field = 'bloguser_user_ID';
  57      }
  58      else
  59      {
  60          $table = 'T_coll_group_perms';
  61          $prefix = 'bloggroup_';
  62          $ID_field = 'bloggroup_group_ID';
  63      }
  64  
  65      // Get affected user/group IDs:
  66      $IDs = param( $context.'_IDs', '/^[0-9]+(,[0-9]+)*$/', '' );
  67      $ID_array = explode( ',', $IDs );
  68      // pre_dump( $ID_array );
  69  
  70      // Can the current user touch advanced admin permissions?
  71      if( ! $current_User->check_perm( 'blog_admin', 'edit', false, $blog ) )
  72      {    // We have no permission to touch advanced admins!
  73          // echo 'restrict';
  74  
  75          // Get the users/groups which are adavnced admins
  76          $admins_ID_array = $DB->get_col( "SELECT {$ID_field}
  77                                                                                  FROM $table
  78                                                                               WHERE {$ID_field} IN (".implode(',',$ID_array).")
  79                                                                                              AND {$prefix}blog_ID = $blog
  80                                                                                              AND {$prefix}perm_admin <> 0" );
  81  
  82          // Take the admins out of the list:
  83          $ID_array = array_diff( $ID_array, $admins_ID_array );
  84          // pre_dump( $ID_array );
  85      }
  86      // else echo 'adv admin';
  87  
  88      if( empty( $ID_array ) )
  89      {
  90          return;
  91      }
  92  
  93      // Delete old perms for this blog:
  94      $DB->query( "DELETE FROM $table
  95                                  WHERE {$ID_field} IN (".implode(',',$ID_array).")
  96                                              AND {$prefix}blog_ID = ".$blog );
  97  
  98      $inserted_values = array();
  99      foreach( $ID_array as $loop_ID )
 100      { // Check new permissions for each user:
 101          // echo "<br/>getting perms for $ID_field : $loop_ID <br />";
 102  
 103          // Use checkboxes
 104          $perm_post = array();
 105  
 106          $ismember = param( 'blog_ismember_'.$loop_ID, 'integer', 0 );
 107  
 108          $perm_published = param( 'blog_perm_published_'.$loop_ID, 'string', '' );
 109          if( !empty($perm_published) ) $perm_post[] = 'published';
 110  
 111          $perm_community = param( 'blog_perm_community_'.$loop_ID, 'string', '' );
 112          if( !empty($perm_community) ) $perm_post[] = 'community';
 113  
 114          $perm_protected = param( 'blog_perm_protected_'.$loop_ID, 'string', '' );
 115          if( !empty($perm_protected) ) $perm_post[] = 'protected';
 116  
 117          $perm_private = param( 'blog_perm_private_'.$loop_ID, 'string', '' );
 118          if( !empty($perm_private) ) $perm_post[] = 'private';
 119  
 120          $perm_review = param( 'blog_perm_review_'.$loop_ID, 'string', '' );
 121          if( !empty($perm_review) ) $perm_post[] = 'review';
 122  
 123          $perm_draft = param( 'blog_perm_draft_'.$loop_ID, 'string', '' );
 124          if( !empty($perm_draft) ) $perm_post[] = 'draft';
 125  
 126          $perm_deprecated = param( 'blog_perm_deprecated_'.$loop_ID, 'string', '' );
 127          if( !empty($perm_deprecated) ) $perm_post[] = 'deprecated';
 128  
 129          $perm_redirected = param( 'blog_perm_redirected_'.$loop_ID, 'string', '' );
 130          if( !empty($perm_redirected) ) $perm_post[] = 'redirected';
 131  
 132          $perm_page    = param( 'blog_perm_page_'.$loop_ID, 'integer', 0 );
 133          $perm_intro   = param( 'blog_perm_intro_'.$loop_ID, 'integer', 0 );
 134          $perm_podcast = param( 'blog_perm_podcast_'.$loop_ID, 'integer', 0 );
 135          $perm_sidebar = param( 'blog_perm_sidebar_'.$loop_ID, 'integer', 0 );
 136  
 137          $perm_edit = param( 'blog_perm_edit_'.$loop_ID, 'string', 'no' );
 138  
 139          $perm_delpost = param( 'blog_perm_delpost_'.$loop_ID, 'integer', 0 );
 140          $perm_edit_ts = param( 'blog_perm_edit_ts_'.$loop_ID, 'integer', 0 );
 141  
 142          $perm_delcmts = param( 'blog_perm_delcmts_'.$loop_ID, 'integer', 0 );
 143          $perm_recycle_owncmts = param( 'blog_perm_recycle_owncmts_'.$loop_ID, 'integer', 0 );
 144          $perm_vote_spam_comments = param( 'blog_perm_vote_spam_cmts_'.$loop_ID, 'integer', 0 );
 145          $perm_cmtstatuses = 0;
 146          $perm_cmtstatuses += param( 'blog_perm_published_cmt_'.$loop_ID, 'integer', 0 ) ? get_status_permvalue( 'published' ) : 0;
 147          $perm_cmtstatuses += param( 'blog_perm_community_cmt_'.$loop_ID, 'integer', 0 ) ? get_status_permvalue( 'community' ) : 0;
 148          $perm_cmtstatuses += param( 'blog_perm_protected_cmt_'.$loop_ID, 'integer', 0 ) ? get_status_permvalue( 'protected' ) : 0;
 149          $perm_cmtstatuses += param( 'blog_perm_private_cmt_'.$loop_ID, 'integer', 0 ) ? get_status_permvalue( 'private' ) : 0;
 150          $perm_cmtstatuses += param( 'blog_perm_review_cmt_'.$loop_ID, 'integer', 0 ) ? get_status_permvalue( 'review' ) : 0;
 151          $perm_cmtstatuses += param( 'blog_perm_draft_cmt_'.$loop_ID, 'integer', 0 ) ? get_status_permvalue( 'draft' ) : 0;
 152          $perm_cmtstatuses += param( 'blog_perm_deprecated_cmt_'.$loop_ID, 'integer', 0 ) ? get_status_permvalue( 'deprecated' ) : 0;
 153          $perm_edit_cmt = param( 'blog_perm_edit_cmt_'.$loop_ID, 'string', 'no' );
 154  
 155          $perm_cats = param( 'blog_perm_cats_'.$loop_ID, 'integer', 0 );
 156          $perm_properties = param( 'blog_perm_properties_'.$loop_ID, 'integer', 0 );
 157  
 158          if( $current_User->check_perm( 'blog_admin', 'edit', false, $blog ) )
 159          {    // We have permission to give advanced admins perm!
 160              $perm_admin = param( 'blog_perm_admin_'.$loop_ID, 'integer', 0 );
 161          }
 162          else
 163          {
 164              $perm_admin = 0;
 165          }
 166  
 167          $perm_media_upload = param( 'blog_perm_media_upload_'.$loop_ID, 'integer', 0 );
 168          $perm_media_browse = param( 'blog_perm_media_browse_'.$loop_ID, 'integer', 0 );
 169          $perm_media_change = param( 'blog_perm_media_change_'.$loop_ID, 'integer', 0 );
 170  
 171          // Update those permissions in DB:
 172  
 173          if( $ismember || count($perm_post) || $perm_delpost || $perm_edit_ts || $perm_delcmts || $perm_recycle_owncmts || $perm_vote_spam_comments || $perm_cmtstatuses ||
 174              $perm_cats || $perm_properties || $perm_admin || $perm_media_upload || $perm_media_browse || $perm_media_change )
 175          { // There are some permissions for this user:
 176              $ismember = 1;    // Must have this permission
 177  
 178              // insert new perms:
 179              $inserted_values[] = " ( $blog, $loop_ID, $ismember, ".$DB->quote(implode(',',$perm_post)).",
 180                                                                  ".$DB->quote($perm_edit).",
 181                                                                  $perm_delpost, $perm_edit_ts, $perm_delcmts, $perm_recycle_owncmts, $perm_vote_spam_comments, $perm_cmtstatuses,
 182                                                                  ".$DB->quote( $perm_edit_cmt ).",
 183                                                                  $perm_cats, $perm_properties, $perm_admin, $perm_media_upload,
 184                                                                  $perm_media_browse, $perm_media_change, $perm_page,    $perm_intro, $perm_podcast,
 185                                                                  $perm_sidebar )";
 186          }
 187      }
 188  
 189      // Proceed with insertions:
 190      if( count( $inserted_values ) )
 191      {
 192          $DB->query( "INSERT INTO $table( {$prefix}blog_ID, {$ID_field}, {$prefix}ismember,
 193                                              {$prefix}perm_poststatuses, {$prefix}perm_edit, {$prefix}perm_delpost, {$prefix}perm_edit_ts,
 194                                              {$prefix}perm_delcmts, {$prefix}perm_recycle_owncmts, {$prefix}perm_vote_spam_cmts, {$prefix}perm_cmtstatuses, {$prefix}perm_edit_cmt,
 195                                              {$prefix}perm_cats, {$prefix}perm_properties, {$prefix}perm_admin,
 196                                              {$prefix}perm_media_upload, {$prefix}perm_media_browse, {$prefix}perm_media_change,
 197                                              {$prefix}perm_page, {$prefix}perm_intro, {$prefix}perm_podcast, {$prefix}perm_sidebar )
 198                                      VALUES ".implode( ',', $inserted_values ) );
 199      }
 200  }
 201  
 202  
 203  /**
 204   * Check permissions on a given blog (by ID) and autoselect an appropriate blog
 205   * if necessary.
 206   *
 207   * For use in admin
 208   *
 209   * NOTE: we no longer try to set $Blog inside of the function because later global use cannot be safely guaranteed in PHP4.
 210   *
 211   * @param string Permission name that must be given to the {@link $current_User} object.
 212   * @param string Permission level that must be given to the {@link $current_User} object.
 213   * @return integer new selected blog
 214   */
 215  function autoselect_blog( $permname, $permlevel = 'any' )
 216  {
 217      global $blog;
 218  
 219    /**
 220       * @var User
 221       */
 222      global $current_User;
 223  
 224      $autoselected_blog = $blog;
 225  
 226      if( $autoselected_blog )
 227      { // a blog is already selected
 228          if( !$current_User->check_perm( $permname, $permlevel, false, $autoselected_blog ) )
 229          { // invalid blog
 230               // echo 'current blog was invalid';
 231              $autoselected_blog = 0;
 232          }
 233      }
 234  
 235      if( !$autoselected_blog )
 236      { // No blog is selected so far (or selection was invalid)...
 237          // Let's try to find another one:
 238  
 239      /**
 240           * @var BlogCache
 241           */
 242          $BlogCache = & get_BlogCache();
 243  
 244          // Get first suitable blog
 245          $blog_array = $BlogCache->load_user_blogs( $permname, $permlevel, $current_User->ID, 'ID', 'ASC', 1 );
 246          if( !empty($blog_array) )
 247          {
 248              $autoselected_blog = $blog_array[0];
 249          }
 250      }
 251  
 252      return $autoselected_blog;
 253  }
 254  
 255  
 256  /**
 257   * Check that we have received a valid blog param
 258   *
 259   * For use in admin
 260   */
 261  function valid_blog_requested()
 262  {
 263      global $Blog, $Messages;
 264      if( empty( $Blog ) )
 265      {    // The requested blog does not exist
 266          $Messages->add( T_('The requested blog does not exist (any more?)'), 'error' );
 267          return false;
 268      }
 269      return true;
 270  }
 271  
 272  
 273  /**
 274   * Set working blog to a new value and memorize it in user settings if needed.
 275   *
 276   * For use in admin
 277   *
 278   * @return boolean $blog changed?
 279   */
 280  function set_working_blog( $new_blog_ID )
 281  {
 282      global $blog, $UserSettings;
 283  
 284      if( $new_blog_ID != (int)$UserSettings->get('selected_blog') )
 285      {    // Save the new default blog.
 286          // fp> Test case 1: dashboard without a blog param should go to last selected blog
 287          // fp> Test case 2: uploading to the default blog may actually upload into another root (sev)
 288          $UserSettings->set( 'selected_blog', $blog );
 289          $UserSettings->dbupdate();
 290      }
 291  
 292      if( $new_blog_ID == $blog )
 293      {
 294          return false;
 295      }
 296  
 297      $blog = $new_blog_ID;
 298  
 299      return true;
 300  }
 301  
 302  
 303  /**
 304   * @param string
 305   * @return array|string
 306   */
 307  function get_collection_kinds( $kind = NULL )
 308  {
 309      global $Plugins;
 310  
 311      $kinds = array(
 312          'std' => array(
 313                  'name' => T_('Standard blog'),
 314                  'desc' => T_('A standard blog with the most common features.'),
 315              ),
 316          'photo' => array(
 317                  'name' => T_('Photoblog'),
 318                  'desc' => T_('A blog optimized to publishing photos.'),
 319              ),
 320          'group' => array(
 321                  'name' => T_('Group blog'),
 322                  'desc' => T_('A blog optimized for team/collaborative editing. Posts can be assigned to different reviewers before being published. Look for the workflow properties at the bottom of the post editing form.'),
 323              ),
 324          'forum' => array(
 325                  'name' => T_('Forum'),
 326                  'desc' => T_('A collection optimized to be used as a forum. (This should be used with a forums skin)'),
 327              ),
 328          'manual' => array(
 329                  'name' => T_('Manual'),
 330                  'desc' => T_('A collection optimized to be used as an online manual, book or guide. (This should be used with a manual skin)'),
 331              ),
 332          );
 333  
 334      // Define blog kinds, their names and description.
 335      $plugin_kinds = $Plugins->trigger_collect( 'GetCollectionKinds', array('kinds' => & $kinds) );
 336  
 337      foreach( $plugin_kinds as $l_kinds )
 338      {
 339          $kinds = array_merge( $l_kinds, $kinds );
 340      }
 341  
 342      if( is_null($kind) )
 343      {    // Return kinds array
 344          return $kinds;
 345      }
 346  
 347      if( array_key_exists( $kind, $kinds ) && !empty($kinds[$kind]['name']) )
 348      {
 349          return $kinds[$kind]['name'];
 350      }
 351      else
 352      {    // Use default collection kind
 353          return $kinds['std']['name'];
 354      }
 355  }
 356  
 357  
 358  /**
 359   * Enable/Disable the given cache
 360   *
 361   * @param string cache key name, 'general_cache_enabled', blogs 'cache_enabled'
 362   * @param boolean status to set
 363   * @param integer the id of the blog, if we want to set a blog's cache. Let it NULL to set general caching.
 364   * @param boolean true to save db changes, false if db update will be called outside from this function
 365   */
 366  function set_cache_enabled( $cache_key, $new_status, $coll_ID = NULL, $save_setting = true )
 367  {
 368      load_class( '_core/model/_pagecache.class.php', 'PageCache' );
 369      global $Settings;
 370  
 371      if( empty( $coll_ID ) )
 372      { // general cache
 373          $Blog = NULL;
 374          $old_cache_status = $Settings->get( $cache_key );
 375      }
 376      else
 377      { // blog page cache
 378          $BlogCache = & get_BlogCache();
 379          $Blog = $BlogCache->get_by_ID( $coll_ID );
 380          $old_cache_status = $Blog->get_setting( $cache_key );
 381      }
 382  
 383      $PageCache = new PageCache( $Blog );
 384      if( $old_cache_status == false && $new_status == true )
 385      { // Caching has been turned ON:
 386          if( $PageCache->cache_create( false ) )
 387          { // corresponding cache folder was created
 388              if( empty( $coll_ID ) )
 389              { // general cache
 390                  $result = array( 'success', T_( 'General caching has been enabled.' ) );
 391              }
 392              else
 393              { // blog page cache
 394                  $result = array( 'success', T_( 'Page caching has been enabled.' ) );
 395              }
 396          }
 397          else
 398          { // error creating cache folder
 399              if( empty( $coll_ID ) )
 400              { // general cache
 401                  $result = array( 'error', T_( 'General caching could not be enabled. Check /cache/ folder file permissions.' ) );
 402              }
 403              else
 404              { // blog page cache
 405                  $result = array( 'error', T_( 'Page caching could not be enabled. Check /cache/ folder file permissions.' ) );
 406              }
 407              $new_status = false;
 408          }
 409      }
 410      elseif( $old_cache_status == true && $new_status == false )
 411      { // Caching has been turned OFF:
 412          $PageCache->cache_delete();
 413          if( empty( $coll_ID ) )
 414          { // general cache
 415              $result = array( 'note',  T_( 'General caching has been disabled. Cache contents have been purged.' ) );
 416          }
 417          else
 418          { // blog page cache
 419              $result = array( 'note',  T_( 'Page caching has been disabled. Cache contents have been purged.' ) );
 420          }
 421      }
 422      else
 423      { // nothing was changed
 424          // check if ajax_form_enabled has correct state after b2evo upgrade
 425          if( ( $Blog != NULL ) && ( $new_status ) && ( !$Blog->get_setting( 'ajax_form_enabled' ) ) )
 426          { // if page cache is enabled, ajax form must be enabled to
 427              $Blog->set_setting( 'ajax_form_enabled', true );
 428              $Blog->dbupdate();
 429          }
 430          return NULL;
 431      }
 432  
 433      // set db changes
 434      if( $Blog == NULL )
 435      {
 436          $Settings->set( 'general_cache_enabled', $new_status );
 437          if( $save_setting )
 438          { // save
 439              $Settings->dbupdate();
 440          }
 441      }
 442      else
 443      {
 444          $Blog->set_setting( $cache_key, $new_status );
 445          if( ( $cache_key == 'cache_enabled' ) && $new_status )
 446          { // if page cache is enabled, ajax form must be enabled to
 447              $Blog->set_setting( 'ajax_form_enabled', true );
 448          }
 449          if( $save_setting )
 450          { // save
 451              $Blog->dbupdate();
 452          }
 453      }
 454      return $result;
 455  }
 456  
 457  
 458  /**
 459   * Initialize global $blog variable to the requested blog
 460   *
 461   * @return boolean true if $blog was initialized successful, false otherwise
 462   */
 463  function init_requested_blog()
 464  {
 465      global $blog, $ReqHost, $ReqPath;
 466      global $Settings;
 467      global $Debuglog;
 468  
 469      if( !empty( $blog ) )
 470      { // blog was already initialized
 471          return true;
 472      }
 473  
 474      // Check if a specific blog has been requested in the URL:
 475      $blog = param( 'blog', 'integer', '', true );
 476  
 477      if( !empty($blog) )
 478      { // a specific blog has been requested in the URL
 479          return true;
 480      }
 481  
 482      // No blog requested by URL param, let's try to match something in the URL
 483      $Debuglog->add( 'No blog param received, checking extra path...', 'detectblog' );
 484      $BlogCache = & get_BlogCache();
 485      if( preg_match( '#^(.+?)index.php/([^/]+)#', $ReqHost.$ReqPath, $matches ) )
 486      { // We have an URL blog name:
 487          $Debuglog->add( 'Found a potential URL blog name: '.$matches[2], 'detectblog' );
 488          if( (($Blog = & $BlogCache->get_by_urlname( $matches[2], false )) !== false) )
 489          { // We found a matching blog:
 490              $blog = $Blog->ID;
 491              return true;
 492          }
 493      }
 494  
 495      // No blog identified by URL name, let's try to match the absolute URL
 496      if( preg_match( '#^(.+?)index.php#', $ReqHost.$ReqPath, $matches ) )
 497      { // Remove what's not part of the absolute URL
 498          $ReqAbsUrl = $matches[1];
 499      }
 500      else
 501      {
 502          $ReqAbsUrl = $ReqHost.$ReqPath;
 503      }
 504      $Debuglog->add( 'Looking up absolute url : '.$ReqAbsUrl, 'detectblog' );
 505      if( (($Blog = & $BlogCache->get_by_url( $ReqAbsUrl, false )) !== false) )
 506      { // We found a matching blog:
 507          $blog = $Blog->ID;
 508          $Debuglog->add( 'Found matching blog: '.$blog, 'detectblog' );
 509          return true;
 510      }
 511  
 512      // Still no blog requested, use default
 513      $blog = $Settings->get('default_blog_ID');
 514      if( (($Blog = & $BlogCache->get_by_ID( $blog, false, false )) !== false) )
 515      { // We found a matching blog:
 516          $Debuglog->add( 'Using default blog '.$blog, 'detectblog' );
 517          return true;
 518      }
 519  
 520      $blog = NULL;
 521      return false;
 522  }
 523  
 524  
 525  /**
 526   * Activate the blog locale and the corresponding charset
 527   *
 528   * @param integer the blog Id
 529   */
 530  function activate_blog_locale( $blog )
 531  {
 532      global $current_charset;
 533  
 534      if( empty( $blog ) || ( $blog <= 0 ) )
 535      { // $blog is not a valid blog ID
 536          return;
 537      }
 538  
 539      $BlogCache = & get_BlogCache();
 540      $Blog = $BlogCache->get_by_ID( $blog, false, false );
 541      if( !empty( $Blog ) )
 542      { // Activate the blog locale
 543          locale_activate( $Blog->get('locale') );
 544  
 545          // Re-Init charset handling, in case current_charset has changed:
 546          init_charsets( $current_charset );
 547      };
 548  }
 549  
 550  
 551  /**
 552   * Initialize blog enabled widgets. It will call every enabled widget request_required_files() function.
 553   *
 554   * @param integer blog ID
 555   */
 556  function init_blog_widgets( $blog_id )
 557  {
 558      /**
 559       * @var EnabledWidgetCache
 560       */
 561      $EnabledWidgetCache = & get_EnabledWidgetCache();
 562      $container_Widget_array = & $EnabledWidgetCache->get_by_coll_ID( $blog_id );
 563  
 564      if( !empty($container_Widget_array) )
 565      {
 566          foreach( $container_Widget_array as $container=>$Widget_array )
 567          {
 568              foreach( $Widget_array as $ComponentWidget )
 569              {    // Let the Widget initialize itself:
 570                  $ComponentWidget->request_required_files();
 571              }
 572          }
 573      }
 574  }
 575  
 576  
 577  /**
 578   * Check if user is activated and status allow to display the requested form ($disp).
 579   * Do nothing if status is activated or can't be activated or display is not allowed, add error message to activate the account otherwise.
 580   * asimo>TODO: We may find a better name and a better place for this function ( maybe user.funcs.php )
 581   *
 582   * @param string the requested view name
 583   */
 584  function check_allow_disp( $disp )
 585  {
 586      global $Blog, $Messages, $Settings, $current_User, $secure_htsrv_url;
 587  
 588      if( !check_user_status( 'can_be_validated' ) )
 589      { // we don't have the case when user is logged in and the account is not active
 590          return;
 591      }
 592  
 593      $messages_content = $Messages->get_string( '', '', '', 'raw' );
 594      if( ( strstr( $messages_content, 'disp=activateinfo' ) !== false ) || ( strstr( $messages_content, 'action=req_validatemail' ) !== false ) )
 595      { // If there is already a message to display activateinfo link, then don't add this message again
 596          return;
 597      }
 598  
 599      switch( $disp )
 600      {
 601          case 'activateinfo':
 602              // don't display activate account error notification in activate info page
 603              return;
 604              break; // already exited before this
 605          case 'contacts':
 606              if( !$current_User->check_status( 'can_view_contacts' ) )
 607              { // contacts view display is not allowed
 608                  return;
 609              }
 610              break;
 611          case 'edit':
 612              if( !$current_User->check_status( 'can_edit_post' ) )
 613              { // edit post is not allowed
 614                  return;
 615              }
 616              break;
 617          case 'messages':
 618              if( !$current_User->check_status( 'can_view_messages' ) )
 619              { // messages view display is not allowed
 620                  return;
 621              }
 622              break;
 623          case 'msgform':
 624              if( !$current_User->check_status( 'can_view_msgform' ) )
 625              { // msgform display is not allowed
 626                  return;
 627              }
 628              break;
 629          case 'threads':
 630              if( !$current_User->check_status( 'can_view_threads' ) )
 631              { // threads view display is not allowed
 632                  return;
 633              }
 634              break;
 635          case 'user':
 636              $user_ID = param( 'user_ID', 'integer', '', true );
 637              if( !$current_User->check_status( 'can_view_user', $user_ID ) )
 638              { // user profile display is not allowed
 639                  return;
 640              }
 641              break;
 642          case 'users':
 643              if( !$current_User->check_status( 'can_view_users' ) )
 644              { // not active user can't see users list
 645                  return;
 646              }
 647              break;
 648          default:
 649              break;
 650      }
 651  
 652      // User is allowed to see the requested view, but show an account activation error message
 653      if( $Blog->get_setting( 'in_skin_login' ) )
 654      {
 655          $activateinfo_link = 'href="'.url_add_param( $Blog->gen_blogurl(), 'disp=activateinfo' ).'"';
 656      }
 657      else
 658      {
 659          $activateinfo_link = 'href="'.$secure_htsrv_url.'login.php?action=req_validatemail'.'"';
 660      }
 661      $Messages->add( sprintf( T_( 'IMPORTANT: your account is not active yet! Activate your account now by clicking on the activation link in the email we sent you. <a %s>More info &raquo;</a>' ), $activateinfo_link ) );
 662  }
 663  
 664  
 665  /**
 666   * Get the highest public status and action button label of a new post or comment in the given blog what the current User may create.
 667   * We assume here that the User should be able to create a post/comment with at least the lowest level status.
 668   *
 669   * @param string 'post' or 'comment'
 670   * @param integer blog ID
 671   * @param boolean set false to get only the status without the action button label
 672   * @return mixed string status if with_label is false, array( status, label ) if with_label is true
 673   */
 674  function get_highest_publish_status( $type, $blog, $with_label = true )
 675  {
 676      global $current_User;
 677  
 678      if( ( $type != 'post' ) && ( $type != 'comment' ) )
 679      { // $type is invalid
 680          debug_die( 'Invalid type parameter!' );
 681      }
 682  
 683      $BlogCache = & get_BlogCache();
 684      $requested_Blog = $BlogCache->get_by_ID( $blog );
 685      $default_status = ( $type == 'post' ) ? $requested_Blog->get_setting( 'default_post_status' ) : $requested_Blog->get_setting( 'new_feedback_status' );
 686  
 687      if( empty( $current_User ) || ( ( !$requested_Blog->get( 'advanced_perms' ) ) && ( !$current_User->check_perm_blog_global( $blog, 'editall' ) ) ) )
 688      { // current User is not set or collection advanced perms are not enabled and user has no global perms on the given blog, set status to the default status
 689          return ( $with_label ? array( $default_status, '' ) : $default_status );
 690      }
 691  
 692      $status_order = get_visibility_statuses( 'ordered-array' );
 693      $highest_index = count( $status_order ) - 1;
 694      $default_status_label = '';
 695      $result = false;
 696      for( $index = $highest_index; $index > 0; $index-- )
 697      {
 698          $curr_status = $status_order[$index][0];
 699          if( $curr_status == $default_status )
 700          { // Set default status label for later use
 701              $default_status_label =  $status_order[$index][1];
 702          }
 703          if( $current_User->check_perm( 'blog_'.$type.'!'.$curr_status, 'create', false, $blog ) )
 704          { // The highest available publish status has been found
 705              $result = array( $curr_status, $status_order[$index][1] );
 706              break;
 707          }
 708      }
 709  
 710      if( !$result )
 711      { // There are no available public status
 712          if( $current_User->check_perm( 'blog_'.$type.'!private', 'create', false, $blog ) )
 713          { // Check private status
 714              $result = array( 'private', T_('Make private!') );
 715          }
 716          else
 717          { // None of the statuses were allowed avove the 'draft' status, so we return the lowest level status.
 718              $result = array( 'draft', '' );
 719          }
 720      }
 721  
 722      if( $with_label )
 723      {
 724          return $result;
 725      }
 726  
 727      // Return only the highest available visibility status without label
 728      return $result[0];
 729  }
 730  
 731  
 732  /**
 733   * Retrieves all tags from published posts
 734   *
 735   * @param integer the id of the blog or array of blog ids. Set NULL to use current blog
 736   * @param integer maximum number of returned tags
 737   * @param string a comma separated list of tags to ignore/exclude
 738   * @param bool true to skip tags from pages, intro posts and sidebar stuff
 739   * @return array of tags
 740   */
 741  function get_tags( $blog_ids, $limit = 0, $filter_list = NULL, $skip_intro_posts = false )
 742  {
 743      global $DB, $localtimenow, $posttypes_specialtypes;
 744  
 745      $BlogCache = & get_BlogCache();
 746  
 747      if( is_null($blog_ids) )
 748      {
 749          global $blog;
 750          $blog_ids = $blog;
 751      }
 752  
 753      if( is_array($blog_ids) )
 754      {    // Get quoted ID list
 755          $blog_ids = $DB->quote($blog_ids);
 756          $where_cats = 'cat_blog_ID IN ('.$blog_ids.')';
 757      }
 758      else
 759      {
 760          $Blog = & $BlogCache->get_by_ID($blog_ids);
 761  
 762          // Get list of relevant blogs
 763          $where_cats = trim($Blog->get_sql_where_aggregate_coll_IDs('cat_blog_ID'));
 764      }
 765  
 766      // fp> verrry dirty and params; TODO: clean up
 767      // dh> oddly, this appears to not get cached by the query cache. Have experimented a bit, but not found the reason.
 768      //     It worked locally somehow, but not live.
 769      //     This takes up to ~50% (but more likely 15%) off the total SQL time. With the query being cached, it would be far better.
 770  
 771      // build query, only joining categories, if not using all.
 772      $sql = 'SELECT LOWER(tag_name) AS tag_name, post_datestart, COUNT(DISTINCT itag_itm_ID) AS tag_count, tag_ID, cat_blog_ID
 773              FROM T_items__tag
 774              INNER JOIN T_items__itemtag ON itag_tag_ID = tag_ID';
 775  
 776      if( $where_cats != '1' )
 777      {    // we have to join the cats
 778          $sql .= '
 779           INNER JOIN T_postcats ON itag_itm_ID = postcat_post_ID
 780           INNER JOIN T_categories ON postcat_cat_ID = cat_ID';
 781      }
 782  
 783      $sql .= "
 784           INNER JOIN T_items__item ON itag_itm_ID = post_ID
 785           WHERE $where_cats
 786             AND post_status = 'published' AND post_datestart < '".remove_seconds($localtimenow)."'";
 787  
 788      if( $skip_intro_posts )
 789      {
 790          $sql .= ' AND post_ptyp_ID NOT IN ('.implode(',',$posttypes_specialtypes).')';
 791      }
 792  
 793      if( !empty($filter_list) )
 794      {    // Filter tags
 795          $filter_list = explode( ',', $filter_list ) ;
 796  
 797          $filter_tags = array();
 798          foreach( $filter_list as $l_tag )
 799          {
 800              $filter_tags[] = '"'.$DB->escape(trim($l_tag)).'"';
 801          }
 802  
 803          $sql .= ' AND tag_name NOT IN ('.implode(', ', $filter_tags).')';
 804      }
 805  
 806      $sql .= ' GROUP BY tag_name ORDER BY tag_count DESC';
 807  
 808      if( !empty($limit) )
 809      {
 810          $sql .= ' LIMIT '.$limit;
 811      }
 812  
 813      return $DB->get_results( $sql, OBJECT, 'Get tags' );
 814  }
 815  
 816  
 817  /**
 818   * Get a list of those statuses which can be displayed in the front office
 819   *
 820   * @return array
 821   */
 822  function get_inskin_statuses()
 823  {
 824      return array( 'published', 'community', 'protected', 'private', 'review', 'draft' );
 825  }
 826  
 827  
 828  /**
 829   * Get available post statuses
 830   *
 831   * @param string Statuses format, defaults to translated statuses
 832   * @param array Statuses to exclude. Unused 'trash' status excluded by default
 833   * @return array of statuses
 834   */
 835  function get_visibility_statuses( $format = '', $exclude = array('trash') )
 836  {
 837      switch( $format )
 838      {
 839          case 'notes-array':
 840          case 'notes-string':
 841          case 'radio-options':
 842              // Array notes for visibility_select()
 843              $r = array(
 844                      'published'  => array( T_('Public'),     '('.T_('Everyone').')' ),
 845                      'community'  => array( T_('Community'),  '('.T_('Logged in users only').')' ),
 846                      'protected'  => array( T_('Members'),    '('.T_('Blog members only').')' ),
 847                      'review'     => array( T_('Review'),     '('.T_('Moderators only (+You)').')' ),
 848                      'private'    => array( T_('Private'),    '('.T_('You only').')' ),
 849                      'draft'      => array( T_('Draft'),      '('.T_('You only (+backoffice users)').')' ),
 850                      'deprecated' => array( T_('Deprecated'), '('.T_('Not published!').')' ),
 851                      'redirected' => array( T_('Redirected'), '(301)' ),
 852                      'trash'      => array( T_('Recycled'),   '' )
 853                  );
 854  
 855              if( $format == 'notes-string' )
 856              {    // String notes
 857                  $r = array_map( create_function('$v', 'return implode(" ", $v);'), $r );
 858              }
 859              break;
 860  
 861          case 'moderation-titles':
 862              $change_status = T_('Change status to').': ';
 863              $visible_by = ' ('.T_('Visible by').': ';
 864              $r = array(
 865                      'published'  => $change_status.T_('Public').$visible_by.T_('Everyone').')',
 866                      'community'  => $change_status.T_('Community').$visible_by.T_('Logged in users only').')',
 867                      'protected'  => $change_status.T_('Members').$visible_by.T_('Blog members only').')',
 868                      'review'     => $change_status.T_('Review').$visible_by.T_('Moderators only (+You)').')',
 869                      'private'    => $change_status.T_('Private').$visible_by.T_('You only').')',
 870                      'draft'      => $change_status.T_('Draft').$visible_by.T_('You only (+backoffice users)').')',
 871                      'deprecated' => $change_status.T_('Deprecated').' ('.T_('Not published!').')',
 872                      'redirected' => '',
 873                      'trash'      => ''
 874                  );
 875              break;
 876  
 877          case 'legend-titles':
 878              $r = array(
 879                      'published' => T_('Visible by anyone'),
 880                      'community' => T_('Visible by logged-in users only'),
 881                      'protected' => T_('Visible by members only'),
 882                      'review'    => T_('Waiting for moderator review'),
 883                      'private'   => T_('Visible by you only'),
 884                      'draft'     => T_('Unfinished post'),
 885                  );
 886              break;
 887  
 888          case 'ordered-array': // indexed array, ordered from the lowest to the highest public level
 889              $r = array(
 890                  0 => array( 'deprecated', '', T_('Deprecate!'), 'grey' ),
 891                  1 => array( 'review', T_('Open to moderators!'), T_('Restrict to moderators!'), 'magenta' ),
 892                  2 => array( 'protected', T_('Open to members!'), T_('Restrict to members!'), 'orange' ),
 893                  3 => array( 'community', T_('Open to community!'), T_('Restrict to community!'), 'blue' ),
 894                  4 => array( 'published', T_('Make public!'), '', 'green' )
 895              );
 896              return $r;
 897  
 898          case 'ordered-index': // gives each status index in the statuses ordered array
 899              $r = array(
 900                  'redirected' => 0,
 901                  'trash'      => 0,
 902                  'private'    => 0,
 903                  'draft'      => 0,
 904                  'deprecated' => 0,
 905                  'review'     => 1,
 906                  'protected'  => 2,
 907                  'community'  => 3,
 908                  'published'  => 4,
 909              );
 910              break;
 911  
 912          case 'moderation': // these statuses may need moderation
 913              $r = array( 'community', 'protected', 'review', 'draft' );
 914              return $r;
 915  
 916          case 'raw':
 917          default:
 918              $r = array (
 919                      'published'  => NT_('Public'),
 920                      'community'  => NT_('Community'),
 921                      'protected'  => NT_('Members'),
 922                      'private'    => NT_('Private'),
 923                      'review'     => NT_('Review'),
 924                      'draft'      => NT_('Draft'),
 925                      'deprecated' => NT_('Deprecated'),
 926                      'redirected' => NT_('Redirected'),
 927                      'trash'      => NT_('Recycled'),
 928                  );
 929  
 930              if( $format != 'keys' && $format != 'raw' )
 931              {    // Translate statuses (default format)
 932                  $r = array_map( 'T_', $r );
 933              }
 934      }
 935  
 936      if( !empty($exclude) )
 937      {
 938          // PHP 5.1 array_diff_key( $r, $exclude );
 939          foreach( $exclude as $ex )
 940          {
 941              if( isset($r[$ex]) )
 942              {
 943                  unset($r[$ex]);
 944              }
 945          }
 946      }
 947  
 948      if( $format == 'keys' )
 949      { // Return status keys for 'visibility_array'
 950          $r = array_keys( $r );
 951      }
 952  
 953      if( $format == 'radio-options' )
 954      { // Return options for radio buttons
 955          $radio_options = array();
 956          foreach( $r as $status => $labels )
 957          {
 958              $radio_options[] = array( $status, $labels[0].' <span class="notes">'.$labels[1].'</span>' );
 959          }
 960          return $radio_options;
 961      }
 962  
 963      return $r;
 964  }
 965  
 966  
 967  /**
 968   * Compare two visibility status in the point of public level
 969   *
 970   * @param string first_status
 971   * @param string second_status
 972   * @return integer
 973   *   0 if the two statuses have the same public level
 974   *   1 if the first status has higher public level
 975   *   -1 if it first status has lower public level
 976   */
 977  function compare_visibility_status( $first_status, $second_status )
 978  {
 979      $status_index = get_visibility_statuses( 'ordered-index', array() );
 980      if( !isset( $status_index[$first_status] ) || !isset( $status_index[$second_status] ) )
 981      { // At least one of the given statuses doesn't exist
 982          debug_die( 'Invalid status given to compare!' );
 983      }
 984  
 985      $first_status_index = $status_index[$first_status];
 986      $second_status_index = $status_index[$second_status];
 987      if( $first_status_index == $second_status_index )
 988      { // The two status public level is equal, but note this doesn't mean that the two status must be same!
 989          return 0;
 990      }
 991  
 992      return ( $first_status_index > $second_status_index ) ? 1 : -1;
 993  }
 994  
 995  
 996  /**
 997   * Get restricted visibility statuses for the current User in the given blog in back office
 998   *
 999   * @param integer blog ID
1000   * @param string permission prefix: 'blog_post!' or 'blog_comment!'
1001   * @param string permlevel: 'view'/'edit' depending on where we would like to use it
1002   * @return array of restricted statuses
1003   */
1004  function get_restricted_statuses( $blog_ID, $prefix, $permlevel = 'view' )
1005  {
1006      global $current_User;
1007  
1008      $result = array();
1009  
1010      // This statuses are allowed to view/edit only for those users who may create post/comment with these statuses
1011      $restricted = array( 'review', 'draft', 'deprecated', 'private' );
1012      foreach( $restricted as $status )
1013      {
1014          if( !$current_User->check_perm( $prefix.$status, 'create', false, $blog_ID ) )
1015          { // not allowed
1016              $result[] = $status;
1017          }
1018      }
1019  
1020      // 'redirected' status is allowed to view/edit only in case of posts, and only if user has permission
1021      if( ( $prefix == 'blog_post!' ) && !$current_User->check_perm( $prefix.'redirected', 'create', false, $blog_ID ) )
1022      { // not allowed
1023          $result[] = 'redirected';
1024      }
1025  
1026      // 'trash' status is allowed only in case of comments, and only if user has global editall permission
1027      if( ( $prefix == 'blog_comment!' ) && !$current_User->check_perm( 'blogs', 'editall', false ) )
1028      { // not allowed
1029          $result[] = 'trash';
1030      }
1031  
1032      // The other statuses are always allowed to view in backoffice
1033      if( $permlevel != 'view' )
1034      { // in case of other then 'view' action we must check the permissions
1035          $restricted = array( 'published', 'community', 'protected' );
1036          foreach( $restricted as $status )
1037          {
1038              if( !$current_User->check_perm( $prefix.$status, 'create', false, $blog_ID ) )
1039              { // not allowed
1040                  $result[] = $status;
1041              }
1042          }
1043      }
1044  
1045      return $result;
1046  }
1047  
1048  
1049  /**
1050   * Display blogs results table
1051   *
1052   * @param array Params
1053   */
1054  function blogs_results_block( $params = array() )
1055  {
1056      // Make sure we are not missing any param:
1057      $params = array_merge( array(
1058              'edited_User'          => NULL,
1059              'results_param_prefix' => 'actv_blog_',
1060              'results_title'        => T_('Blogs owned by the user'),
1061              'results_no_text'      => T_('User does not own any blogs'),
1062          ), $params );
1063  
1064      if( !is_logged_in() )
1065      {    // Only logged in users can access to this function
1066          return;
1067      }
1068  
1069      global $current_User;
1070      if( !$current_User->check_perm( 'users', 'edit' ) || !$current_User->check_perm( 'blogs', 'view' ) )
1071      {    // Check minimum permission:
1072          return;
1073      }
1074  
1075      $edited_User = $params['edited_User'];
1076      if( !$edited_User )
1077      {    // No defined User, probably the function is calling from AJAX request
1078          $user_ID = param( 'user_ID', 'integer', 0 );
1079          if( empty( $user_ID ) )
1080          {    // Bad request, Exit here
1081              return;
1082          }
1083          $UserCache = & get_UserCache();
1084          if( ( $edited_User = & $UserCache->get_by_ID( $user_ID, false ) ) === false )
1085          {    // Bad request, Exit here
1086              return;
1087          }
1088      }
1089  
1090      global $DB;
1091  
1092      param( 'user_tab', 'string', '', true );
1093      param( 'user_ID', 'integer', 0, true );
1094  
1095      $SQL = new SQL();
1096      $SQL->SELECT( '*' );
1097      $SQL->FROM( 'T_blogs' );
1098      $SQL->WHERE( 'blog_owner_user_ID = '.$DB->quote( $edited_User->ID ) );
1099  
1100      // Create result set:
1101      $blogs_Results = new Results( $SQL->get(), $params['results_param_prefix'] );
1102      $blogs_Results->Cache = & get_BlogCache();
1103      $blogs_Results->title = $params['results_title'];
1104      $blogs_Results->no_results_text = $params['results_no_text'];
1105  
1106      // Get a count of the blogs which current user can delete
1107      $deleted_blogs_count = count( $edited_User->get_deleted_blogs() );
1108      if( $blogs_Results->total_rows > 0 && $deleted_blogs_count > 0 )
1109      {    // Display action icon to delete all records if at least one record exists & user can delete at least one blog
1110          $blogs_Results->global_icon( sprintf( T_('Delete all blogs owned by %s'), $edited_User->login ), 'delete', '?ctrl=user&amp;user_tab=activity&amp;action=delete_all_blogs&amp;user_ID='.$edited_User->ID.'&amp;'.url_crumb('user'), ' '.T_('Delete all'), 3, 4 );
1111      }
1112  
1113      // Initialize Results object
1114      blogs_results( $blogs_Results, array(
1115              'display_owner' => false,
1116          ) );
1117  
1118      if( is_ajax_content() )
1119      {    // init results param by template name
1120          if( !isset( $params[ 'skin_type' ] ) || ! isset( $params[ 'skin_name' ] ) )
1121          {
1122              debug_die( 'Invalid ajax results request!' );
1123          }
1124          $blogs_Results->init_params_by_skin( $params[ 'skin_type' ], $params[ 'skin_name' ] );
1125      }
1126  
1127      $display_params = array(
1128          'before' => '<div class="results" style="margin-top:25px" id="owned_blogs_result">'
1129      );
1130      $blogs_Results->display( $display_params );
1131  
1132      if( !is_ajax_content() )
1133      {    // Create this hidden div to get a function name for AJAX request
1134          echo '<div id="'.$params['results_param_prefix'].'ajax_callback" style="display:none">'.__FUNCTION__.'</div>';
1135      }
1136  }
1137  
1138  
1139  /**
1140   * Initialize Results object for blogs list
1141   *
1142   * @param object Results
1143   * @param array Params
1144   */
1145  function blogs_results( & $blogs_Results, $params = array() )
1146  {
1147      // Make sure we are not missing any param:
1148      $params = array_merge( array(
1149              'display_id' => true,
1150              'display_name' => true,
1151              'display_fullname' => true,
1152              'display_owner' => true,
1153              'display_url' => true,
1154              'display_locale' => true,
1155              'display_actions' => true,
1156          ), $params );
1157  
1158      if( $params['display_id'] )
1159      {    // Display ID column
1160          $blogs_Results->cols[] = array(
1161                  'th' => T_('ID'),
1162                  'order' => 'blog_ID',
1163                  'th_class' => 'shrinkwrap',
1164                  'td_class' => 'shrinkwrap',
1165                  'td' => '$blog_ID$',
1166              );
1167      }
1168  
1169      if( $params['display_name'] )
1170      {    // Display Name column
1171          $blogs_Results->cols[] = array(
1172                  'th' => T_('Name'),
1173                  'order' => 'blog_shortname',
1174                  'td' => '<strong>%disp_coll_name( #blog_shortname#, #blog_ID# )%</strong>',
1175              );
1176      }
1177  
1178      if( $params['display_name'] )
1179      {    // Display Full Name column
1180          $blogs_Results->cols[] = array(
1181                  'th' => T_('Full Name'),
1182                  'order' => 'blog_name',
1183                  'td' => '%strmaxlen( #blog_name#, 40, NULL, "raw" )%',
1184              );
1185      }
1186  
1187      if( $params['display_owner'] )
1188      {    // Display Owner column
1189          $blogs_Results->cols[] = array(
1190                  'th' => T_('Owner'),
1191                  'order' => 'user_login',
1192                  'td' => '%get_user_identity_link( #user_login# )%',
1193              );
1194      }
1195  
1196      if( $params['display_url'] )
1197      {    // Display Blog URL column
1198          $blogs_Results->cols[] = array(
1199                  'th' => T_('Blog URL'),
1200                  'td' => '<a href="@get(\'url\')@">@get(\'url\')@</a>',
1201              );
1202      }
1203  
1204      if( $params['display_locale'] )
1205      {    // Display Locale column
1206          $blogs_Results->cols[] = array(
1207                  'th' => T_('Locale'),
1208                  'order' => 'blog_locale',
1209                  'th_class' => 'shrinkwrap',
1210                  'td_class' => 'shrinkwrap',
1211                  'td' => '%locale_flag( #blog_locale# )%',
1212              );
1213      }
1214  
1215      if( $params['display_actions'] )
1216      {    // Display Actions column
1217          $blogs_Results->cols[] = array(
1218                  'th' => T_('Actions'),
1219                  'th_class' => 'shrinkwrap',
1220                  'td_class' => 'shrinkwrap',
1221                  'td' => '%disp_actions( #blog_ID# )%',
1222              );
1223      }
1224  }
1225  
1226  
1227  /**
1228   * Helper functions to display Blogs results.
1229   * New ( not display helper ) functions must be created above blogs_results function
1230   */
1231  
1232  /**
1233   * Get a blogs name with link to edit
1234   *
1235   * @param string Blog name
1236   * @param integer Blog ID
1237   * @return string Link
1238   */
1239  function disp_coll_name( $coll_name, $coll_ID )
1240  {
1241      global $current_User, $ctrl;
1242      if( $ctrl == 'dashboard' )
1243      {    // Dashboard
1244          $edit_url = regenerate_url( 'ctrl', 'ctrl=dashboard&amp;blog='.$coll_ID );
1245          $r = '<a href="'.$edit_url.'">';
1246          $r .= $coll_name;
1247          $r .= '</a>';
1248      }
1249      elseif( $current_User->check_perm( 'blog_properties', 'edit', false, $coll_ID ) )
1250      {    // Blog setting & can edit
1251          $edit_url = regenerate_url( 'ctrl', 'ctrl=coll_settings&amp;blog='.$coll_ID );
1252          $r = '<a href="'.$edit_url.'" title="'.T_('Edit properties...').'">';
1253          $r .= $coll_name;
1254          $r .= '</a>';
1255      }
1256      else
1257      {
1258          $r = $coll_name;
1259      }
1260      return $r;
1261  }
1262  
1263  
1264  /**
1265   * Get available actions for current blog
1266   *
1267   * @param integer Blog ID
1268   * @return string Action links
1269   */
1270  function disp_actions( $curr_blog_ID )
1271  {
1272      global $current_User, $admin_url;
1273      $r = '';
1274  
1275      if( $current_User->check_perm( 'blog_properties', 'edit', false, $curr_blog_ID ) )
1276      {
1277          $r .= action_icon( T_('Edit properties...'), 'properties', $admin_url.'?ctrl=coll_settings&amp;blog='.$curr_blog_ID );
1278      }
1279  
1280      if( $current_User->check_perm( 'blog_cats', '', false, $curr_blog_ID ) )
1281      {
1282          $r .= action_icon( T_('Edit categories...'), 'edit', $admin_url.'?ctrl=chapters&amp;blog='.$curr_blog_ID );
1283      }
1284  
1285      if( $current_User->check_perm( 'blog_properties', 'edit', false, $curr_blog_ID ) )
1286      {
1287          $r .= action_icon( T_('Delete this blog...'), 'delete', $admin_url.'?ctrl=collections&amp;action=delete&amp;blog='.$curr_blog_ID.'&amp;'.url_crumb('collection').'&amp;redirect_to='.rawurlencode( regenerate_url( '', '', '', '&' ) ) );
1288      }
1289  
1290      if( empty($r) )
1291      { // for IE
1292          $r = '&nbsp;';
1293      }
1294  
1295      return $r;
1296  }
1297  
1298  /**
1299   * End of helper functions block to display Blogs results.
1300   * New ( not display helper ) functions must be created above blogs_results function
1301   */
1302  
1303  ?>

title

Description

title

Description

title

Description

title

title

Body