[ 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/model/ -> _blog.class.php (source)

   1  <?php
   2  /**

   3   * This file implements the Blog class.

   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   * Parts of this file are copyright (c)2005 by Jason Edgecombe.

  11   *

  12   * {@internal License choice

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

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

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

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

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

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

  19   * }}

  20   *

  21   * {@internal Open Source relicensing agreement:

  22   * Daniel HAHLER grants Francois PLANQUE the right to license

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

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

  25   *

  26   * Jason EDGECOMBE grants Francois PLANQUE the right to license

  27   * Jason EDGECOMBE's contributions to this file and the b2evolution project

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

  29   * }}

  30   *

  31   * @package evocore

  32   *

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

  34   * @author blueyed: Daniel HAHLER.

  35   * @author fplanque: Francois PLANQUE.

  36   * @author gorgeb: Bertrand GORGE / EPISTEMA

  37   * @author jeffbearer: Jeff BEARER

  38   * @author edgester: Jason EDGECOMBE

  39   *

  40   * @version $Id: _blog.class.php,v 1.14 2007/11/04 17:55:12 fplanque Exp $

  41   */
  42  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  43  
  44  load_class('_core/model/dataobjects/_dataobject.class.php');
  45  
  46  /**

  47   * Blog

  48   *

  49   * Blog object with params

  50   *

  51   * @package evocore

  52   */
  53  class Blog extends DataObject
  54  {
  55      /**

  56       * Short name for use in navigation menus

  57       * @var string

  58       */
  59      var $shortname;
  60  
  61      /**

  62       * Complete name

  63       * @var string

  64       */
  65      var $name;
  66  
  67      /**

  68       * Tagline to be displayed on template

  69       * @var string

  70       */
  71      var $tagline;
  72  
  73      var $shortdesc; // description

  74      var $longdesc;
  75  
  76      var $owner_user_ID;
  77  
  78      /**

  79       * Lazy filled

  80       * @var User

  81       */
  82      var $owner_User = NULL;
  83  
  84      var $advanced_perms = 0;
  85  
  86      var $locale;
  87      var $access_type;
  88  
  89      /*

  90     * ?> TODO: we should have an extra DB column that either defines type of blog_siteurl

  91     * OR split blog_siteurl into blog_siteurl_abs and blog_siteurl_rel (where blog_siteurl_rel could be "blog_sitepath")

  92     */
  93      var $siteurl;
  94      var $stub;     // stub file (can be empty/virtual)

  95      var $urlname;  // used to identify blog in URLs

  96      var $links_blog_ID = 0;
  97      var $notes;
  98      var $keywords;
  99      var $allowcomments = 'post_by_post';
 100      var $allowtrackbacks = 0;
 101      var $allowblogcss = 0;
 102      var $allowusercss = 0;
 103      var $skin_ID;
 104      var $in_bloglist = 1;
 105      var $UID;
 106      var $media_location = 'default';
 107      var $media_subdir = '';
 108      var $media_fullpath = '';
 109      var $media_url = '';
 110  
 111      /**

 112       * Additional settings for the collection.  lazy filled.

 113        *

 114       * @see Blog::get_setting()

 115       * @see Blog::set_setting()

 116       * @see Blog::load_CollectionSettings()

 117       * Any non vital params should go into there (this includes many of the above).

 118       *

 119       * @var CollectionSettings

 120       */
 121      var $CollectionSettings;
 122  
 123  
 124      /**

 125       * Lazy filled

 126       *

 127       * @var integer

 128       */
 129      var $default_cat_ID;
 130  
 131  
 132      /**

 133       * Constructor

 134       *

 135       * @param object DB row

 136       */
 137  	function Blog( $db_row = NULL )
 138      {
 139          global $basepath;
 140  
 141          // Call parent constructor:

 142          parent::DataObject( 'T_blogs', 'blog_', 'blog_ID' );
 143  
 144          $this->delete_restrictions = array(
 145                  array( 'table'=>'T_categories', 'fk'=>'cat_blog_ID', 'msg'=>T_('%d related categories') ),
 146              );
 147  
 148          $this->delete_cascades = array(
 149                  array( 'table'=>'T_coll_user_perms', 'fk'=>'bloguser_blog_ID', 'msg'=>T_('%d user permission definitions') ),
 150                  array( 'table'=>'T_coll_group_perms', 'fk'=>'bloggroup_blog_ID', 'msg'=>T_('%d group permission definitions') ),
 151                  array( 'table'=>'T_subscriptions', 'fk'=>'sub_coll_ID', 'msg'=>T_('%d subscriptions') ),
 152                  array( 'table'=>'T_widget', 'fk'=>'wi_coll_ID', 'msg'=>T_('%d widgets') ),
 153                  array( 'table'=>'T_hitlog', 'fk'=>'hit_blog_ID', 'msg'=>T_('%d hits') ),
 154              );
 155  
 156          if( $db_row == NULL )
 157          {
 158              global $default_locale;
 159              // echo 'Creating blank blog';

 160              $this->owner_user_ID = 1; // DB default

 161              $this->set( 'locale', $default_locale );
 162              $this->set( 'access_type', 'index.php' );
 163              $this->skin_ID = 1;    // TODO: this is the DB default, but it will fail if skin #1 does not exist

 164          }
 165          else
 166          {
 167              $this->ID = $db_row->blog_ID;
 168              $this->shortname = $db_row->blog_shortname;
 169              $this->name = $db_row->blog_name;
 170              $this->owner_user_ID = $db_row->blog_owner_user_ID;
 171              $this->advanced_perms = $db_row->blog_advanced_perms;
 172              $this->tagline = $db_row->blog_tagline;
 173              $this->shortdesc = $db_row->blog_description;    // description

 174              $this->longdesc = $db_row->blog_longdesc;
 175              $this->locale = $db_row->blog_locale;
 176              $this->access_type = $db_row->blog_access_type;
 177              $this->siteurl = $db_row->blog_siteurl;
 178              $this->urlname = $db_row->blog_urlname;
 179              $this->links_blog_ID = $db_row->blog_links_blog_ID;
 180              $this->notes = $db_row->blog_notes;
 181              $this->keywords = $db_row->blog_keywords;
 182              $this->allowcomments = $db_row->blog_allowcomments;
 183              $this->allowtrackbacks = $db_row->blog_allowtrackbacks;
 184              $this->allowblogcss = $db_row->blog_allowblogcss;
 185              $this->allowusercss = $db_row->blog_allowusercss;
 186              $this->skin_ID = $db_row->blog_skin_ID;
 187              $this->in_bloglist = $db_row->blog_in_bloglist;
 188              $this->media_location = $db_row->blog_media_location;
 189              $this->media_subdir = $db_row->blog_media_subdir;
 190              $this->media_fullpath = $db_row->blog_media_fullpath;
 191              $this->media_url = $db_row->blog_media_url;
 192              $this->UID = $db_row->blog_UID;
 193          }
 194      }
 195  
 196  
 197      /**

 198       * @param string

 199       */
 200  	function init_by_kind( $kind )
 201      {
 202          switch( $kind )
 203          {
 204              case 'photo':
 205                  $this->set( 'name', T_('My photoblog') );
 206                  $this->set( 'shortname', T_('Photoblog') );
 207                  $this->set( 'urlname', 'photo' );
 208                  $this->set_setting( 'posts_per_page', 1 );
 209                  $this->set_setting( 'archive_mode', 'postbypost' );
 210                  break;
 211  
 212              case 'group':
 213                  $this->set( 'name', T_('Our blog') );
 214                  $this->set( 'shortname', T_('Group') );
 215                  $this->set( 'urlname', 'group' );
 216                  $this->set_setting( 'use_workflow', 1 );
 217                  break;
 218  
 219              case 'std':
 220              default:
 221                  $this->set( 'name', T_('My weblog') );
 222                  $this->set( 'shortname', T_('Blog') );
 223                  $this->set( 'urlname', 'blog' );
 224                  break;
 225          }
 226      }
 227  
 228  
 229      /**

 230       * @static

 231       *

 232       * @param string

 233       * @return string

 234       */
 235  	function kind_name( $kind )
 236      {
 237        switch( $kind )
 238          {
 239              case 'photo':
 240                  return T_('Photoblog');
 241  
 242              case 'group':
 243                  return T_('Group blog');
 244  
 245              case 'std':
 246              default:
 247                  return T_('Standard blog');
 248          }
 249      }
 250  
 251      /**

 252       * Load data from Request form fields.

 253       *

 254       * @param array groups of params to load

 255       * @return boolean true if loaded data seems valid.

 256       */
 257  	function load_from_Request( $groups = array() )
 258      {
 259          global $Messages, $default_locale, $DB;
 260  
 261          /**

 262           * @var User

 263           */
 264          global $current_User;
 265  
 266          if( param( 'blog_name', 'string', NULL ) !== NULL )
 267          { // General params:
 268              $this->set_from_Request( 'name' );
 269              $this->set( 'shortname',     param( 'blog_shortname',     'string', true ) );
 270              $this->set( 'locale',        param( 'blog_locale',        'string', $default_locale ) );
 271          }
 272  
 273  
 274          if( param( 'archive_links',   'string', NULL ) !== NULL )
 275          { // Archive link type:
 276              $this->set_setting( 'archive_links', get_param( 'archive_links' ) );
 277          }
 278  
 279          if( param( 'chapter_links',   'string', NULL ) !== NULL )
 280          { // Chapter link type:
 281              $this->set_setting( 'chapter_links', get_param( 'chapter_links' ) );
 282          }
 283  
 284          if( param( 'category_prefix', 'string', NULL) !== NULL )
 285          {
 286              $category_prefix = get_param( 'category_prefix' );
 287              if( ! preg_match( '|^([A-Za-z0-9\-_]+(/[A-Za-z0-9\-_]+)*)?$|', $category_prefix) )
 288              {
 289                  param_error( 'category_prefix', T_('Invalid category prefix.') );
 290              }
 291              $this->set_setting( 'category_prefix', $category_prefix);
 292          }
 293  
 294          if( param( 'single_links',   'string', NULL ) !== NULL )
 295          { // Single post link type:
 296              $this->set_setting( 'single_links', get_param( 'single_links' ) );
 297          }
 298  
 299  
 300          if( param( 'blog_skin_ID', 'integer', NULL ) !== NULL )
 301          {    // Default blog:
 302              $this->set_from_Request( 'skin_ID' );
 303          }
 304  
 305  
 306          if( param( 'what_to_show',   'string', NULL ) !== NULL )
 307          { // Show x days or x posts?:
 308              $this->set_setting( 'what_to_show', get_param( 'what_to_show' ) );
 309  
 310              param_integer_range( 'posts_per_page', 1, 9999, T_('Items/days per page must be between %d and %d.') );
 311              $this->set_setting( 'posts_per_page', get_param( 'posts_per_page' ) );
 312  
 313              $this->set_setting( 'archive_mode', param( 'archive_mode', 'string', true ) );
 314  
 315               $this->set_setting( 'orderby', param( 'orderby', 'string', true ) );
 316               $this->set_setting( 'orderdir', param( 'orderdir', 'string', true ) );
 317          }
 318  
 319          if( param( 'feed_content',   'string', NULL ) !== NULL )
 320          { // How much content in feeds?
 321              $this->set_setting( 'feed_content', get_param( 'feed_content' ) );
 322  
 323              param_integer_range( 'posts_per_feed', 1, 9999, T_('Items per feed must be between %d and %d.') );
 324              $this->set_setting( 'posts_per_feed', get_param( 'posts_per_feed' ) );
 325          }
 326  
 327          if( param( 'blog_links_blog_ID',  'integer', -1 ) != -1 )
 328          {    // Default display options:
 329              $this->set_from_Request( 'links_blog_ID' );
 330          }
 331  
 332  
 333          if( param( 'blog_description', 'string', NULL ) !== NULL )
 334          {    // Description:
 335              $this->set_from_Request( 'shortdesc', 'blog_description' );
 336          }
 337  
 338          if( param( 'blog_keywords', 'string', NULL ) !== NULL )
 339          {    // Keywords:
 340              $this->set_from_Request( 'keywords' );
 341          }
 342  
 343          if( param( 'blog_tagline',   'html', NULL ) !== NULL )
 344          {    // HTML tagline:
 345              $this->set( 'tagline', format_to_post( get_param( 'blog_tagline' ), 0, 0 ) );
 346          }
 347  
 348          if( param( 'blog_longdesc',   'html', NULL ) !== NULL )
 349          {    // HTML long description:
 350              $this->set( 'longdesc', format_to_post( get_param( 'blog_longdesc' ), 0, 0 ) );
 351          }
 352  
 353          if( param( 'blog_notes',   'html', NULL ) !== NULL )
 354          {    // HTML notes:
 355              $this->set( 'notes', format_to_post( get_param( 'blog_notes' ), 0, 0 ) );
 356          }
 357  
 358  
 359          if( in_array( 'pings', $groups ) )
 360          { // we want to load the ping checkboxes:
 361              $blog_ping_plugins = param( 'blog_ping_plugins', 'array', array() );
 362              $blog_ping_plugins = array_unique($blog_ping_plugins);
 363              $this->set_setting('ping_plugins', implode(',', $blog_ping_plugins));
 364          }
 365  
 366          if( in_array( 'features', $groups ) )
 367          { // we want to load the workflow checkboxes:
 368              $this->set_setting( 'allow_subscriptions',  param( 'allow_subscriptions', 'integer', 0 ) );
 369              $this->set( 'advanced_perms',  param( 'advanced_perms', 'integer', 0 ) );
 370              $this->set_setting( 'use_workflow',  param( 'blog_use_workflow', 'integer', 0 ) );
 371          }
 372  
 373          if( param( 'blog_allowcomments',   'string', NULL ) !== NULL )
 374          { // Feedback options:
 375              $this->set_from_Request( 'allowcomments' );
 376              $this->set_setting( 'new_feedback_status', param( 'new_feedback_status', 'string', 'draft' ) );
 377              $this->set_setting( 'allow_rating', param( 'allow_rating', 'string', 'never' ) );
 378              $this->set( 'allowtrackbacks', param( 'blog_allowtrackbacks', 'integer', 0 ) );
 379  
 380              // Public blog list

 381              $this->set( 'in_bloglist',   param( 'blog_in_bloglist',   'integer', 0 ) );
 382          }
 383  
 384  
 385          if( in_array( 'seo', $groups ) )
 386          { // we want to load the workflow checkboxes:
 387              $this->set_setting( 'canonical_item_urls',  param( 'canonical_item_urls', 'integer', 0 ) );
 388              $this->set_setting( 'canonical_cat_urls',  param( 'canonical_cat_urls', 'integer', 0 ) );
 389              $this->set_setting( 'default_noindex',  param( 'default_noindex', 'integer', 0 ) );
 390              $this->set_setting( 'paged_noindex',  param( 'paged_noindex', 'integer', 0 ) );
 391              $this->set_setting( 'archive_noindex',  param( 'archive_noindex', 'integer', 0 ) );
 392              $this->set_setting( 'category_noindex',  param( 'category_noindex', 'integer', 0 ) );
 393              $this->set_setting( 'filtered_noindex',  param( 'filtered_noindex', 'integer', 0 ) );
 394              $this->set_setting( 'arcdir_noindex',  param( 'arcdir_noindex', 'integer', 0 ) );
 395              $this->set_setting( 'catdir_noindex',  param( 'catdir_noindex', 'integer', 0 ) );
 396              $this->set_setting( 'feedback-popup_noindex',  param( 'feedback-popup_noindex', 'integer', 0 ) );
 397              $this->set_setting( 'msgform_noindex',  param( 'msgform_noindex', 'integer', 0 ) );
 398              $this->set_setting( 'special_noindex',  param( 'special_noindex', 'integer', 0 ) );
 399              $this->set_setting( 'title_link_type',  param( 'title_link_type', 'string', '' ) );
 400              $this->set_setting( 'permalinks',  param( 'permalinks', 'string', '' ) );
 401          }
 402  
 403  
 404      /*

 405           * ADVANCED ADMIN SETTINGS

 406           */
 407          if( $current_User->check_perm( 'blog_admin', 'edit', false, $this->ID ) )
 408          {    // We have permission to edit advanced admin settings:
 409  
 410              if( param( 'owner_login', 'string', NULL ) !== NULL )
 411              { // Permissions:
 412                  $UserCache = & get_Cache( 'UserCache' );
 413                  $owner_User = & $UserCache->get_by_login( get_param('owner_login'), false, false );
 414                  if( empty( $owner_User ) )
 415                  {
 416                      param_error( 'owner_login', sprintf( T_('User &laquo;%s&raquo; does not exist!'), get_param('owner_login') ) );
 417                  }
 418                  else
 419                  {
 420                      $this->set( 'owner_user_ID', $owner_User->ID );
 421                      $this->owner_User = & $owner_User;
 422                  }
 423              }
 424  
 425  
 426              if( param( 'blog_urlname',   'string', NULL ) !== NULL )
 427              {    // check urlname
 428                  if( param_check_not_empty( 'blog_urlname', T_('You must provide an URL blog name!') ) )
 429                  {
 430                      $this->set_from_Request( 'urlname' );
 431  
 432                      if( ! preg_match( '|^[A-Za-z0-9\-]+$|', $this->urlname ) )
 433                      {
 434                          param_error( 'blog_urlname', T_('The url name is invalid.') );
 435                      }
 436  
 437                      if( $DB->get_var( 'SELECT COUNT(*)
 438                                                               FROM T_blogs
 439                                                              WHERE blog_urlname = '.$DB->quote($this->get( 'urlname' )).'
 440                                                                AND blog_ID <> '.$this->ID
 441                                                              ) )
 442                      { // urlname is already in use
 443                          param_error( 'blog_urlname', T_('This URL name is already in use by another blog. Please choose another name.') );
 444                      }
 445                  }
 446              }
 447  
 448  
 449              if( ($access_type = param( 'blog_access_type', 'string', NULL )) !== NULL )
 450              { // Blog URL parameters:
 451                  $this->set( 'access_type', $access_type );
 452  
 453                  if( $access_type == 'absolute' )
 454                  {
 455                      $blog_siteurl = param( 'blog_siteurl_absolute', 'string', true );
 456                      if( !preg_match( '#^https?://.+#', $blog_siteurl ) )
 457                      {
 458                          $Messages->add( T_('Blog Folder URL').': '
 459                                                          .T_('You must provide an absolute URL (starting with <code>http://</code> or <code>https://</code>)!'), 'error' );
 460                      }
 461                      $this->set( 'siteurl', $blog_siteurl );
 462                  }
 463                  elseif( $access_type == 'relative' )
 464                  { // relative siteurl
 465                      $blog_siteurl = param( 'blog_siteurl_relative', 'string', true );
 466                      if( preg_match( '#^https?://#', $blog_siteurl ) )
 467                      {
 468                          $Messages->add( T_('Blog Folder URL').': '
 469                                                          .T_('You must provide a relative URL (without <code>http://</code> or <code>https://</code>)!'), 'error' );
 470                      }
 471                    $this->set( 'siteurl', $blog_siteurl );
 472                  }
 473                  else
 474                  {
 475                    $this->set( 'siteurl', '' );
 476                  }
 477              }
 478  
 479  
 480              if( get_param( 'blog_links_blog_ID' ) != -1 )
 481              { // checkboxes (will not get send, if unchecked)
 482                  $this->set( 'allowblogcss', param( 'blog_allowblogcss', 'integer', 0 ) );
 483                  $this->set( 'allowusercss', param( 'blog_allowusercss', 'integer', 0 ) );
 484              }
 485  
 486  
 487              if( param( 'aggregate_coll_IDs', 'string', NULL ) !== NULL )
 488              { // Aggregate list:
 489                  // fp> TODO: check perms on each aggregated blog (if changed)

 490                  // fp> TODO: better interface

 491                  if( !preg_match( '#^([0-9]+(,[0-9]+)*)?$#', get_param( 'aggregate_coll_IDs' ) ) )
 492                  {
 493                      param_error( 'aggregate_coll_IDs', T_('Invalid aggregate blog ID list!') );
 494                  }
 495                  $this->set_setting( 'aggregate_coll_IDs', get_param( 'aggregate_coll_IDs' ) );
 496              }
 497  
 498              if( param( 'source_file', 'string', NULL ) !== NULL )
 499              {    // Static file:
 500                  $this->set_setting( 'source_file', get_param( 'source_file' ) );
 501                  $this->set_setting( 'static_file', param( 'static_file', 'string', '' ) );
 502              }
 503  
 504  
 505              if( param( 'blog_media_location',  'string', NULL ) !== NULL )
 506              {    // Media files location:
 507                  $this->set_from_Request(   'media_location' );
 508                  $this->set_media_subdir(    param( 'blog_media_subdir',    'string', '' ) );
 509                  $this->set_media_fullpath(  param( 'blog_media_fullpath',  'string', '' ) );
 510                  $this->set_media_url(       param( 'blog_media_url',       'string', '' ) );
 511  
 512                  // check params

 513                  switch( $this->get( 'media_location' ) )
 514                  {
 515                      case 'custom': // custom path and URL
 516                          if( $this->get( 'media_fullpath' ) == '' )
 517                          {
 518                              param_error( 'blog_media_fullpath', T_('Media dir location').': '.T_('You must provide the full path of the media directory.') );
 519                          }
 520                          if( !preg_match( '#^https?://#', $this->get( 'media_url' ) ) )
 521                          {
 522                              param_error( 'blog_media_url', T_('Media dir location').': '
 523                                                              .T_('You must provide an absolute URL (starting with <code>http://</code> or <code>https://</code>)!') );
 524                          }
 525                          break;
 526  
 527                      case 'subdir':
 528                          if( $this->get( 'media_subdir' ) == '' )
 529                          {
 530                              param_error( 'blog_media_subdir', T_('Media dir location').': '.T_('You must provide the media subdirectory.') );
 531                          }
 532                          break;
 533                  }
 534              }
 535  
 536  
 537          }
 538  
 539          return ! param_errors_detected();
 540  
 541      }
 542  
 543  
 544      /**

 545       * Set the media folder's subdir

 546       *

 547       * @param string the subdirectory

 548       */
 549  	function set_media_subdir( $path )
 550      {
 551          parent::set_param( 'media_subdir', 'string', trailing_slash( $path ) );
 552      }
 553  
 554  
 555      /**

 556       * Set the full path of the media folder

 557       *

 558       * @param string the full path

 559       */
 560  	function set_media_fullpath( $path )
 561      {
 562          parent::set_param( 'media_fullpath', 'string', trailing_slash( $path ) );
 563      }
 564  
 565  
 566      /**

 567       * Set the full URL of the media folder

 568       *

 569       * @param string the full URL

 570       */
 571  	function set_media_url( $url )
 572      {
 573          parent::set_param( 'media_url', 'string', trailing_slash( $url ) );
 574      }
 575  
 576  
 577      /**

 578       * Set param value

 579       *

 580       * @param string Parameter name

 581       * @return boolean true, if a value has been set; false if it has not changed

 582       */
 583  	function set( $parname, $parvalue )
 584      {
 585          global $Settings;
 586  
 587          switch( $parname )
 588          {
 589              case 'ID':
 590              case 'allowtrackbacks':
 591              case 'blog_in_bloglist':
 592                  return parent::set_param( $parname, 'number', $parvalue );
 593                  break;
 594  
 595              case 'shortdesc':
 596                  $this->shortdesc = $parvalue;
 597                  return parent::set_param( 'description', 'string', $parvalue );
 598                  break;
 599  
 600              default:
 601                  return parent::set_param( $parname, 'string', $parvalue );
 602          }
 603      }
 604  
 605  
 606      /**

 607       * Generate blog URL

 608       *

 609       * @param string default|dynamic|static

 610       */
 611  	function gen_blogurl( $type = 'default' )
 612      {
 613          global $baseurl, $basedomain, $Settings;
 614  
 615          if( $type == 'static' )
 616          { // We want the static page, there is no access type option here:
 617              debug_die( 'static page currently not supported' );
 618          }
 619  
 620          if( $type == 'dynamic' )
 621          { // We want to force a dynamic page
 622              debug_die( 'dynamic page currently not supported' );
 623          }
 624  
 625          switch( $this->access_type )
 626          {
 627              case 'default':
 628                  // Access through index.php: match absolute URL or call default blog

 629                  if( ( $Settings->get('default_blog_ID') == $this->ID )
 630                      || preg_match( '#^https?://#', $this->siteurl ) )
 631                  { // Safety check! We only do that kind of linking if this is really the default blog...
 632                      // or if we call by absolute URL

 633                      return $baseurl.$this->siteurl.'index.php';
 634                  }
 635                  // ... otherwise, we add the blog ID:

 636  
 637              case 'index.php':
 638                  // Access through index.php + blog qualifier

 639                  return $baseurl.$this->siteurl.'index.php?blog='.$this->ID;
 640  
 641              case 'extrapath':
 642                  // We want to use extra path info, use the blog urlname:

 643                  return $baseurl.$this->siteurl.'index.php/'.$this->urlname.'/';
 644  
 645              case 'relative':
 646                  return $baseurl.$this->siteurl;
 647  
 648              case 'subdom':
 649                  return 'http://'.$this->urlname.'.'.$basedomain.'/';
 650  
 651              case 'absolute':
 652                  return $this->siteurl;
 653  
 654              default:
 655                  debug_die( 'Unhandled Blog access type ['.$this->access_type.']' );
 656          }
 657      }
 658  
 659  
 660    /**

 661       * Generate the baseurl of the blog (URL of the folder where the blog lives)

 662       *

 663       * @todo test

 664       */
 665  	function gen_baseurl()
 666      {
 667          global $baseurl, $basedomain;
 668  
 669          switch( $this->access_type )
 670          {
 671              case 'default':
 672              case 'index.php':
 673                  return $baseurl.$this->siteurl;
 674  
 675              case 'extrapath':
 676                  // We want to use extra path info, use the blog urlname:

 677                  return $baseurl.$this->siteurl.'index.php/'.$this->urlname.'/';
 678  
 679              case 'relative':
 680                  $url = $baseurl.$this->siteurl;
 681                  break;
 682  
 683              case 'subdom':
 684                  return 'http://'.$this->urlname.'.'.$basedomain.'/';
 685  
 686              case 'absolute':
 687                  $url = $this->siteurl;
 688                  break;
 689  
 690              default:
 691                  debug_die( 'Unhandled Blog access type ['.$this->access_type.']' );
 692          }
 693  
 694          // For case relative and absolute:

 695          return preg_replace( '¤^(.+)/[^/]$¤', '$1/', $url );
 696  
 697      }
 698  
 699  
 700    /**

 701       * Generate archive page URL

 702       *

 703       * Note: there ate two similar functions here.

 704       * @see Blog::get_archive_url()

 705       *

 706       * @param string year

 707       * @param string month

 708       * @param string day

 709       * @param string week

 710       */
 711  	function gen_archive_url( $year, $month = NULL, $day = NULL, $week = NULL, $glue = '&amp;' )
 712      {
 713          $blogurl = $this->gen_blogurl();
 714  
 715          $archive_links = $this->get_setting('archive_links');
 716  
 717          if( $archive_links == 'param' )
 718          {    // We reference by Query
 719              $separator = '';
 720          }
 721          else
 722          {    // We reference by extra path info
 723              $separator = '/';
 724          }
 725  
 726          $datestring = $separator.$year.$separator;
 727  
 728          if( !empty( $month ) )
 729          {
 730              $datestring .= zeroise($month,2).$separator;
 731              if( !empty( $day ) )
 732              {
 733                  $datestring .= zeroise($day,2).$separator;
 734              }
 735          }
 736          elseif( $week !== '' )  // Note: week # can be 0 !
 737          {
 738              if( $archive_links == 'param' )
 739              {    // We reference by Query
 740                  $datestring .= $glue.'w='.$week;
 741              }
 742              else
 743              {    // extra path info
 744                  $datestring .= 'w'.zeroise($week,2).'/';
 745              }
 746          }
 747  
 748          if( $archive_links == 'param' )
 749          {    // We reference by Query
 750              $link = url_add_param( $blogurl, 'm='.$datestring, $glue );
 751          }
 752          else
 753          {    // We reference by extra path info
 754              $link = url_add_tail( $blogurl, $datestring ); // there may already be a slash from a siteurl like 'http://example.com/'

 755          }
 756  
 757          return $link;
 758      }
 759  
 760  
 761    /**

 762       * Get archive page URL

 763       *

 764       * Note: there ate two similar functions here.

 765       *

 766       * @uses Blog::gen_archive_url()

 767       *

 768       * @param string monthly, weekly, daily

 769       */
 770  	function get_archive_url( $date, $glue = '&amp;' )
 771      {
 772          switch( $this->get_setting('archive_mode') )
 773          {
 774              case 'weekly':
 775                  global $cacheweekly, $DB;
 776                  if((!isset($cacheweekly)) || (empty($cacheweekly[$date])))
 777                  {
 778                      $cacheweekly[$date] = $DB->get_var( 'SELECT '.$DB->week( $DB->quote($date), locale_startofweek() ) );
 779                  }
 780                  return $this->gen_archive_url( substr( $date, 0, 4 ), NULL, NULL, $cacheweekly[$date], $glue );
 781                  break;
 782  
 783              case 'daily':
 784                  return $this->gen_archive_url( substr( $date, 0, 4 ), substr( $date, 5, 2 ), substr( $date, 8, 2 ), NULL, $glue );
 785                  break;
 786  
 787              case 'monthly':
 788              default:
 789                  return $this->gen_archive_url( substr( $date, 0, 4 ), substr( $date, 5, 2 ), NULL, NULL, $glue );
 790          }
 791      }
 792  
 793  
 794      /**

 795       * Get allowed post status for current user in this blog

 796       *

 797       * @todo make default a Blog param

 798       *

 799       * @param string status to start with. Empty to use default.

 800       * @return string authorized status; NULL if none

 801       */
 802  	function get_allowed_item_status( $status = NULL )
 803      {
 804      /**

 805           * @var User

 806           */
 807          global $current_User;
 808          global $default_post_status;
 809  
 810          if( empty( $status ) )
 811          {
 812              $status = $default_post_status;
 813          }
 814          if( ! $current_User->check_perm( 'blog_post!'.$status, 'edit', false, $this->ID ) )
 815          { // We need to find another one:
 816              $status = NULL;
 817  
 818              if( $current_User->check_perm( 'blog_post!published', 'edit', false, $this->ID ) )
 819                  $status = 'published';
 820              elseif( $current_User->check_perm( 'blog_post!protected', 'edit', false, $this->ID ) )
 821                  $status = 'protected';
 822              elseif( $current_User->check_perm( 'blog_post!private', 'edit', false, $this->ID ) )
 823                  $status = 'private';
 824              elseif( $current_User->check_perm( 'blog_post!draft', 'edit', false, $this->ID ) )
 825                  $status = 'draft';
 826              elseif( $current_User->check_perm( 'blog_post!deprecated', 'edit', false, $this->ID ) )
 827                  $status = 'deprecated';
 828              elseif( $current_User->check_perm( 'blog_post!redirected', 'edit', false, $this->ID ) )
 829                  $status = 'redirected';
 830          }
 831          return $status;
 832      }
 833  
 834  
 835      /**

 836       * Get default category for current blog

 837       *

 838       * @todo fp> this is a super lame stub, but it's still better than nothing. Should be user configurable.

 839       *

 840       */
 841  	function get_default_cat_ID()
 842      {
 843          if( !isset( $this->default_cat_ID ) )
 844          {
 845              global $DB;
 846  
 847              $sql = 'SELECT cat_ID
 848                        FROM T_categories
 849                       WHERE cat_blog_ID = '.$this->ID.'
 850                       ORDER BY cat_ID
 851                       LIMIT 1';
 852  
 853              $this->default_cat_ID = $DB->get_var( $sql, 0, 0, 'Get default category' );
 854          }
 855  
 856          return $this->default_cat_ID;
 857      }
 858  
 859  
 860      /**

 861       * Get the blog's media directory (and create it if necessary).

 862       *

 863       * If we're {@link is_admin_page() on an admin page}, it adds status messages.

 864       * @todo These status messages should rather go to a "syslog" and not be displayed to a normal user

 865       *

 866       * @param boolean Create the directory, if it does not exist yet?

 867       * @return string path string on success, false if the dir could not be created

 868       */
 869  	function get_media_dir( $create = true )
 870      {
 871          global $basepath, $media_subdir, $Messages, $Settings, $Debuglog;
 872  
 873          if( ! $Settings->get( 'fm_enable_roots_blog' ) )
 874          { // User directories are disabled:
 875              $Debuglog->add( 'Attempt to access blog media dir, but this feature is globally disabled', 'files' );
 876              return false;
 877          }
 878  
 879          switch( $this->media_location )
 880          {
 881              case 'default':
 882                  $mediadir = get_canonical_path( $basepath.$media_subdir.'blogs/'.$this->urlname.'/' );
 883                  break;
 884  
 885              case 'subdir':
 886                  $mediadir = get_canonical_path( $basepath.$media_subdir.$this->media_subdir );
 887                  break;
 888  
 889              case 'custom':
 890                  $mediadir = get_canonical_path( $this->media_fullpath );
 891                  break;
 892  
 893              case 'none':
 894              default:
 895                  $Debuglog->add( 'Attempt to access blog media dir, but this feature is disabled for this blog', 'files' );
 896                  return false;
 897          }
 898  
 899          // TODO: use a File object here (to access perms, ..) when FileCache::get_by_path() is provided.

 900          if( $create && ! is_dir( $mediadir ) )
 901          {
 902              // TODO: Link to some help page(s) with errors!

 903              if( ! is_writable( dirname($mediadir) ) )
 904              { // add error
 905                  if( is_admin_page() )
 906                  {
 907                      $Messages->add( sprintf( T_("The blog's media directory &laquo;%s&raquo; could not be created, because the parent directory is not writable or does not exist."), rel_path_to_base($mediadir) ), 'error' );
 908                  }
 909                  return false;
 910              }
 911              elseif( !@mkdir( $mediadir ) )
 912              { // add error
 913                  if( is_admin_page() )
 914                  {
 915                      $Messages->add( sprintf( T_("The blog's media directory &laquo;%s&raquo; could not be created."), rel_path_to_base($mediadir) ), 'error' );
 916                  }
 917                  return false;
 918              }
 919              else
 920              { // chmod and add note:
 921                  $chmod = $Settings->get('fm_default_chmod_dir');
 922                  if( !empty($chmod) )
 923                  {
 924                      @chmod( $mediadir, octdec($chmod) );
 925                  }
 926                  if( is_admin_page() )
 927                  {
 928                      $Messages->add( sprintf( T_("The blog's media directory &laquo;%s&raquo; has been created with permissions %s."), rel_path_to_base($mediadir), substr( sprintf('%o', fileperms($mediadir)), -3 ) ), 'success' );
 929                  }
 930              }
 931          }
 932  
 933          return $mediadir;
 934      }
 935  
 936  
 937      /**

 938       * Get the URL to the media folder

 939       *

 940       * @return string the URL

 941       */
 942  	function get_media_url()
 943      {
 944          global $media_url, $Settings, $Debuglog;
 945  
 946          if( ! $Settings->get( 'fm_enable_roots_blog' ) )
 947          { // User directories are disabled:
 948              $Debuglog->add( 'Attempt to access blog media URL, but this feature is disabled', 'files' );
 949              return false;
 950          }
 951  
 952          switch( $this->media_location )
 953          {
 954              case 'default':
 955                  return $media_url.'blogs/'.$this->urlname.'/';
 956  
 957              case 'subdir':
 958                  return $media_url.$this->media_subdir;
 959                  break;
 960  
 961              case 'custom':
 962                  return $this->media_url;
 963  
 964              case 'none':
 965              default:
 966                  $Debuglog->add( 'Attempt to access blog media url, but this feature is disabled for this blog', 'files' );
 967                  return false;
 968          }
 969      }
 970  
 971  
 972      /**

 973        * Get link to edit files

 974        *

 975        * @param string link (false on error)

 976       */
 977  	function get_filemanager_link()
 978      {
 979          load_class('/files/model/_fileroot.class.php');
 980          return 'admin.php?ctrl=files&amp;root='.FileRoot::gen_ID( 'collection', $this->ID );
 981      }
 982  
 983  
 984      /**

 985       * Get URL to display the blog with a temporary skin.

 986       *

 987       * @param string

 988       * @param string

 989       * @param boolean

 990       */
 991  	function get_tempskin_url( $skin_folder_name, $additional_params = '', $halt_on_error = false )
 992      {
 993          /**

 994           * @var SkinCache

 995           */
 996           $SkinCache = & get_Cache( 'SkinCache' );
 997          if( ! $Skin = & $SkinCache->get_by_folder( $skin_folder_name, $halt_on_error ) )
 998          {
 999              return NULL;
1000          }
1001  
1002          return url_add_param( $this->gen_blogurl( 'default' ), 'tempskin='.$skin_folder_name );
1003      }
1004  
1005  
1006      /**

1007       * Get URL to display the blog posts in an XML feed.

1008       *

1009       * @param string

1010       */
1011  	function get_item_feed_url( $skin_folder_name )
1012      {
1013          return $this->get_tempskin_url( $skin_folder_name );
1014      }
1015  
1016  
1017      /**

1018       * Get URL to display the blog comments in an XML feed.

1019       *

1020       * @param string

1021       */
1022  	function get_comment_feed_url( $skin_folder_name )
1023      {
1024          return url_add_param( $this->get_tempskin_url( $skin_folder_name ), 'disp=comments' );
1025      }
1026  
1027  
1028      /**

1029       * Get a param.

1030       *

1031       * @param string Parameter name

1032       * @return false|string The value as string or false in case of error (e.g. media dir is disabled).

1033       */
1034  	function get( $parname )
1035      {
1036          global $xmlsrv_url, $baseurl, $basepath, $media_url, $current_User, $Settings, $Debuglog;
1037  
1038          switch( $parname )
1039          {
1040              case 'blogurl':        // Deprecated
1041              case 'link':          // Deprecated
1042              case 'url':
1043                  return $this->gen_blogurl( 'default' );
1044  
1045              case 'dynurl':
1046                  return $this->gen_blogurl( 'dynamic' );
1047  
1048              case 'staticurl':
1049                  return $this->gen_blogurl( 'static' );
1050  
1051              case 'dynfilepath':
1052                  // Source file for static page:

1053                  return $basepath.$this->get_setting('source_file');
1054  
1055              case 'staticfilepath':
1056                  // Destiantion file for static page:

1057                  return $basepath.$this->get_setting('static_file');
1058  
1059              case 'baseurl':
1060                  return $this->gen_baseurl();
1061  
1062              case 'baseurlroot':
1063                  // fp>> TODO: cleanup

1064                  if( preg_match( '#^(https?://(.+?)(:.+?)?)/#', $this->gen_baseurl(), $matches ) )
1065                  {
1066                      // TODO: shouldn't that include a trailing slash?:

1067                      return $matches[1];
1068                  }
1069                  debug_die( 'Blog::get(baseurl)/baseurlroot - assertion failed [baseurl: '.$this->gen_baseurl().'].' );
1070  
1071              case 'lastcommentsurl':
1072                  return url_add_param( $this->gen_blogurl(), 'disp=comments' );
1073  
1074              case 'arcdirurl':
1075                  return url_add_param( $this->gen_blogurl(), 'disp=arcdir' );
1076  
1077              case 'catdirurl':
1078                  return url_add_param( $this->gen_blogurl(), 'disp=catdir' );
1079  
1080              case 'msgformurl':
1081                  return url_add_param( $this->gen_blogurl(), 'disp=msgform' );
1082  
1083              case 'description':            // RSS wording
1084              case 'shortdesc':
1085                  return $this->shortdesc;
1086  
1087              case 'rdf_url':
1088                  return $this->get_item_feed_url( '_rdf' );
1089  
1090              case 'rss_url':
1091                  return $this->get_item_feed_url( '_rss' );
1092  
1093              case 'rss2_url':
1094                  return $this->get_item_feed_url( '_rss2' );
1095  
1096              case 'atom_url':
1097                  return $this->get_item_feed_url( '_atom' );
1098  
1099              case 'comments_rdf_url':
1100                  return $this->get_comment_feed_url( '_rdf' );
1101  
1102              case 'comments_rss_url':
1103                  return $this->get_comment_feed_url( '_rss' );
1104  
1105              case 'comments_rss2_url':
1106                  return $this->get_comment_feed_url( '_rss2' );
1107  
1108              case 'comments_atom_url':
1109                  return $this->get_comment_feed_url( '_atom' );
1110  
1111  
1112              /* Add the html for a blog-specified stylesheet

1113               * All stylesheets will be included if the blog settings allow it

1114               * and the file "style.css" exists. CSS rules say that the latter style sheets can

1115               * override earlier stylesheets.

1116               */
1117              case 'blog_css':
1118                  if( $this->allowblogcss
1119                      && file_exists( $this->get_media_dir(false).'style.css' ) )
1120                  {
1121                      return '<link rel="stylesheet" href="'.$this->get_media_url().'style.css" type="text/css" />';
1122                  }
1123                  else
1124                  {
1125                      return '';
1126                  }
1127  
1128              /* Add the html for a user-specified stylesheet

1129               * All stylesheets will be included if the blog settings allow it

1130               * and the file "style.css" exists. CSS rules say that the latter style sheets can

1131               * override earlier stylesheets. A user-specified stylesheet will

1132               * override a blog-specified stylesheet which will override a skin stylesheet.

1133               */
1134              case 'user_css':
1135                  if( $this->allowusercss
1136                      && isset( $current_User )
1137                      && file_exists( $current_User->get_media_dir(false).'style.css' ) )
1138                  {
1139                      return '<link rel="stylesheet" href="'.$current_User->get_media_url().'style.css" type="text/css" />';
1140                  }
1141                  else
1142                  {
1143                      return '';
1144                  }
1145  
1146  
1147              default:
1148                  // All other params:

1149                  return parent::get( $parname );
1150          }
1151      }
1152  
1153  
1154       /**

1155       * Get a setting.

1156       *

1157       * @return string|false|NULL value as string on success; NULL if not found; false in case of error

1158       */
1159  	function get_setting( $parname )
1160      {
1161          $this->load_CollectionSettings();
1162  
1163          return $this->CollectionSettings->get( $this->ID, $parname );
1164      }
1165  
1166  
1167       /**

1168       * Set a setting.

1169       *

1170       * @return boolean true, if the value has been set, false if it has not changed.

1171       */
1172  	function set_setting( $parname, $value )
1173      {
1174           // Make sure collection settings are loaded

1175          $this->load_CollectionSettings();
1176  
1177          return $this->CollectionSettings->set( $this->ID, $parname, $value );
1178      }
1179  
1180  
1181      /**

1182       * Make sure collection settings are loaded

1183       */
1184  	function load_CollectionSettings()
1185      {
1186          if( ! isset( $this->CollectionSettings ) )
1187          {
1188              load_class('collections/model/_collsettings.class.php');
1189              $this->CollectionSettings = new CollectionSettings(); // COPY (function)

1190          }
1191      }
1192  
1193  
1194       /**

1195       * Insert into the DB

1196       */
1197  	function dbinsert()
1198      {
1199          global $DB;
1200  
1201          $DB->begin();
1202  
1203          if( parent::dbinsert() )
1204          {
1205              if( isset( $this->CollectionSettings ) )
1206              {
1207                  // So far all settings have been saved to collection #0 !

1208                  // Update the settings: hackish but the base class should not even store this value actually...

1209                  // dh> what do you mean? What "base class"? Is there a problem with CollectionSettings?

1210                  $this->CollectionSettings->cache[$this->ID] = $this->CollectionSettings->cache[0];
1211                  unset( $this->CollectionSettings->cache[0] );
1212  
1213                  $this->CollectionSettings->dbupdate();
1214              }
1215          }
1216  
1217          $DB->commit();
1218      }
1219  
1220  
1221      /**

1222       * Update the DB based on previously recorded changes

1223       */
1224  	function dbupdate()
1225      {
1226          global $DB;
1227  
1228          $DB->begin();
1229  
1230          parent::dbupdate();
1231  
1232          if( isset( $this->CollectionSettings ) )
1233          {
1234              $this->CollectionSettings->dbupdate();
1235          }
1236  
1237          $DB->commit();
1238      }
1239  
1240  
1241      /**

1242       * Delete a blog and dependencies from database

1243       *

1244       * Includes WAY TOO MANY requests because we try to be compatible with MySQL 3.23, bleh!

1245       *

1246       * @param boolean true if you want to try to delete the static file

1247       * @param boolean true if you want to echo progress

1248       */
1249  	function dbdelete($delete_static_file = false, $echo = false )
1250      {
1251          global $DB, $Messages;
1252  
1253          // Note: No need to localize the status messages...

1254          if( $echo ) echo '<p>MySQL 3.23 compatibility mode!';
1255  
1256          // Get list of cats that are going to be deleted (3.23)

1257          if( $echo ) echo '<br />Getting category list to delete... ';
1258          $cat_list = implode( ',', $DB->get_col( "
1259                  SELECT cat_ID
1260                    FROM T_categories
1261                   WHERE cat_blog_ID = $this->ID" ) );
1262  
1263          if( empty( $cat_list ) )
1264          { // There are no cats to delete
1265              if( $echo ) echo 'None!';
1266          }
1267          else
1268          { // Delete the cats & dependencies
1269  
1270              // Get list of posts that are going to be deleted (3.23)

1271              if( $echo ) echo '<br />Getting post list to delete... ';
1272              $post_list = implode( ',', $DB->get_col( "
1273                      SELECT postcat_post_ID
1274                        FROM T_postcats
1275                       WHERE postcat_cat_ID IN ($cat_list)" ) );
1276  
1277              if( empty( $post_list ) )
1278              { // There are no posts to delete
1279                  if( $echo ) echo 'None!';
1280              }
1281              else
1282              { // Delete the posts & dependencies
1283  
1284                  // TODO: There's also a constraint FK_post_parent_ID..

1285  
1286                  // Delete postcats

1287                  if( $echo ) echo '<br />Deleting post-categories... ';
1288                  $ret = $DB->query(    "DELETE FROM T_postcats
1289                                                              WHERE postcat_cat_ID IN ($cat_list)" );
1290                  if( $echo ) printf( '(%d rows)', $ret );
1291                  $Messages->add( T_('Deleted post-categories'), 'success' );
1292  
1293                  // Delete comments

1294                  if( $echo ) echo '<br />Deleting comments on blog\'s posts... ';
1295                  $ret = $DB->query( "DELETE FROM T_comments
1296                                                          WHERE comment_post_ID IN ($post_list)" );
1297                  if( $echo ) printf( '(%d rows)', $ret );
1298                  $Messages->add( T_('Deleted comments on blog\'s posts'), 'success' );
1299  
1300  
1301                  // Delete posts

1302                  if( $echo ) echo '<br />Deleting blog\'s posts... ';
1303                  $ret = $DB->query(    "DELETE FROM T_items__item
1304                                                              WHERE post_ID IN ($post_list)" );
1305                  if( $echo ) printf( '(%d rows)', $ret );
1306                  $Messages->add( T_('Deleted blog\'s posts'), 'success' );
1307  
1308              } // / are there posts?

1309  
1310              // Delete categories

1311              if( $echo ) echo '<br />Deleting blog\'s categories... ';
1312              $ret = $DB->query( "DELETE FROM T_categories
1313                                                      WHERE cat_blog_ID = $this->ID" );
1314              if( $echo ) printf( '(%d rows)', $ret );
1315              $Messages->add( T_('Deleted blog\'s categories'), 'success' );
1316  
1317          } // / are there cats?

1318  
1319  
1320          if( $delete_static_file )
1321          { // Delete static file
1322              if( $echo ) echo '<br />Trying to delete static file... ';
1323              if( ! @unlink( $this->get('staticfilepath') ) )
1324              {
1325                  if( $echo )
1326                  {
1327                      echo '<span class="error">';
1328                      printf(    T_('ERROR! Could not delete! You will have to delete the file [%s] by hand.'),
1329                                      $this->get('staticfilepath') );
1330                      echo '</span>';
1331                  }
1332                  $Messages->add( sprintf( T_('Could not delete static file [%s]'), $this->get('staticfilepath') ), 'error' );
1333              }
1334              else
1335              {
1336                  if( $echo ) echo 'OK.';
1337                  $Messages->add( T_('Deleted blog\'s static file'), 'success' );
1338              }
1339          }
1340  
1341          // Unset cache entry:

1342          // TODO

1343  
1344          // Delete main (blog) object:

1345          parent::dbdelete();
1346  
1347          if( $echo ) echo '<br />Done.</p>';
1348      }
1349  
1350  
1351      /*

1352       * Template function: display name of blog

1353       *

1354       * Template tag

1355       */
1356  	function name( $params = array() )
1357      {
1358          // Make sure we are not missing any param:

1359          $params = array_merge( array(
1360                  'before'      => ' ',
1361                  'after'       => ' ',
1362                  'format'      => 'htmlbody',
1363              ), $params );
1364  
1365          if( !empty( $this->name ) )
1366          {
1367              echo $params['before'];
1368              $this->disp( 'name', $params['format'] );
1369              echo $params['after'];
1370          }
1371      }
1372  
1373  
1374      /*

1375       * Template function: display name of blog

1376       *

1377       * Template tag

1378       */
1379  	function tagline( $params = array() )
1380      {
1381          // Make sure we are not missing any param:

1382          $params = array_merge( array(
1383                  'before'      => ' ',
1384                  'after'       => ' ',
1385                  'format'      => 'htmlbody',
1386              ), $params );
1387  
1388          if( !empty( $this->tagline ) )
1389          {
1390              echo $params['before'];
1391              $this->disp( 'tagline', $params['format'] );
1392              echo $params['after'];
1393          }
1394      }
1395  
1396  
1397      /*

1398       * Template function: display name of blog

1399       *

1400       * Template tag

1401       */
1402  	function longdesc( $params = array() )
1403      {
1404          // Make sure we are not missing any param:

1405          $params = array_merge( array(
1406                  'before'      => ' ',
1407                  'after'       => ' ',
1408                  'format'      => 'htmlbody',
1409              ), $params );
1410  
1411          if( !empty( $this->longdesc ) )
1412          {
1413              echo $params['before'];
1414              $this->disp( 'longdesc', $params['format'] );
1415              echo $params['after'];
1416          }
1417      }
1418  
1419  
1420  
1421      /**

1422       * Get the name of the blog

1423       *

1424       * @return string

1425       */
1426  	function get_name()
1427      {
1428          return $this->name;
1429      }
1430  
1431  
1432      /**

1433       * Resolve user ID of owner

1434       *

1435       * @return User

1436       */
1437      function & get_owner_User()
1438      {
1439          if( !isset($this->owner_User) )
1440          {
1441              $UserCache = & get_Cache( 'UserCache' );
1442              $this->owner_User = & $UserCache->get_by_ID($this->owner_user_ID);
1443          }
1444  
1445          return $this->owner_User;
1446      }
1447  
1448  
1449      /**

1450       * Template tag: display a link leading to the contact form for the owner of the current Blog.

1451       */
1452  	function contact_link( $params )
1453      {
1454          $this->get_owner_User();
1455          if( ! $this->owner_User->allow_msgform )
1456          {
1457              return false;
1458          }
1459  
1460          // Make sure we are not missing any param:

1461          $params = array_merge( array(
1462                  'before'      => ' ',
1463                  'after'       => ' ',
1464                  'text'        => 'Contact', // Note: left untranslated, should be translated in skin anyway
1465                  'title'       => 'Send a message to the owner of this blog...',
1466              ), $params );
1467  
1468  
1469          echo $params['before'];
1470          echo '<a href="'.$this->get_contact_url(true).'" title="'.$params['title'].'" class="contact_link">'
1471                      .$params['text'].'</a>';
1472          echo $params['after'];
1473  
1474          return true;
1475      }
1476  
1477  
1478    /**

1479       * @param boolean do we want to redirect back to where we came from after message?

1480       */
1481  	function get_contact_url( $with_redirect = true )
1482      {
1483          $r = url_add_param( $this->get('msgformurl'), 'recipient_id='.$this->owner_user_ID );
1484  
1485          if( $with_redirect )
1486          {
1487              $r .= '&amp;redirect_to='
1488                      // The URL will be made relative on the next page (this is needed when $htsrv_url is on another domain! -- multiblog situation )

1489                      .rawurlencode( regenerate_url('','','','&') );
1490          }
1491  
1492          return $r;
1493      }
1494  
1495  }
1496  
1497  /*

1498   * $Log: _blog.class.php,v $

1499   * Revision 1.14  2007/11/04 17:55:12  fplanque

1500   * More cleanup

1501   *

1502   * Revision 1.13  2007/11/04 01:10:57  fplanque

1503   * skin cleanup continued

1504   *

1505   * Revision 1.12  2007/11/03 04:56:03  fplanque

1506   * permalink / title links cleanup

1507   *

1508   * Revision 1.11  2007/11/02 01:44:29  fplanque

1509   * comment ratings

1510   *

1511   * Revision 1.10  2007/10/09 02:10:50  fplanque

1512   * URL fixes

1513   *

1514   * Revision 1.9  2007/10/06 21:17:25  fplanque

1515   * cleanup

1516   *

1517   * Revision 1.8  2007/10/05 00:09:23  blueyed

1518   * Nuked unnecessary global statement

1519   *

1520   * Revision 1.7  2007/10/01 13:41:07  waltercruz

1521   * Category prefix, trying to make the code more b2evo style

1522   *

1523   * Revision 1.6  2007/09/29 01:50:50  fplanque

1524   * temporary rollback; waiting for new version

1525   *

1526   * Revision 1.5  2007/09/28 09:28:36  fplanque

1527   * per blog advanced SEO settings

1528   *

1529   * Revision 1.4  2007/09/28 02:25:00  fplanque

1530   * Menu widgets

1531   *

1532   * Revision 1.2  2007/09/10 13:24:13  waltercruz

1533   * Mispelled word correction

1534   *

1535   * Revision 1.1  2007/06/25 10:59:31  fplanque

1536   * MODULES (refactored MVC)

1537   *

1538   * Revision 1.85  2007/05/31 03:02:22  fplanque

1539   * Advanced perms now disabled by default (simpler interface).

1540   * Except when upgrading.

1541   * Enable advanced perms in blog settings -> features

1542   *

1543   * Revision 1.84  2007/05/30 01:18:56  fplanque

1544   * blog owner gets all permissions except advanced/admin settings

1545   *

1546   * Revision 1.83  2007/05/29 01:17:19  fplanque

1547   * advanced admin blog settings are now restricted by a special permission

1548   *

1549   * Revision 1.82  2007/05/28 15:18:30  fplanque

1550   * cleanup

1551   *

1552   * Revision 1.81  2007/05/28 01:35:22  fplanque

1553   * fixed static page generation

1554   *

1555   * Revision 1.80  2007/05/14 02:43:04  fplanque

1556   * Started renaming tables. There probably won't be a better time than 2.0.

1557   *

1558   * Revision 1.79  2007/05/13 22:53:31  fplanque

1559   * allow feeds restricted to post excerpts

1560   *

1561   * Revision 1.78  2007/05/09 00:58:54  fplanque

1562   * massive cleanup of old functions

1563   *

1564   * Revision 1.77  2007/05/08 00:54:31  fplanque

1565   * public blog list as a widget

1566   *

1567   * Revision 1.76  2007/04/26 00:11:05  fplanque

1568   * (c) 2007

1569   *

1570   * Revision 1.75  2007/04/25 18:47:41  fplanque

1571   * MFB 1.10: groovy links

1572   *

1573   * Revision 1.74  2007/03/25 15:18:57  fplanque

1574   * cleanup

1575   *

1576   * Revision 1.73  2007/03/25 15:07:38  fplanque

1577   * multiblog fixes

1578   *

1579   * Revision 1.72  2007/03/25 13:20:52  fplanque

1580   * cleaned up blog base urls

1581   * needs extensive testing...

1582   *

1583   * Revision 1.71  2007/03/25 10:20:02  fplanque

1584   * cleaned up archive urls

1585   *

1586   * Revision 1.70  2007/03/24 20:41:16  fplanque

1587   * Refactored a lot of the link junk.

1588   * Made options blog specific.

1589   * Some junk still needs to be cleaned out. Will do asap.

1590   *

1591   * Revision 1.69  2007/03/11 23:57:06  fplanque

1592   * item editing: allow setting to 'redirected' status

1593   *

1594   * Revision 1.68  2007/03/08 00:17:42  blueyed

1595   * More info in assertion for "baseurlroot" and "basehost" and more strict pattern

1596   *

1597   * Revision 1.67  2007/03/04 21:42:49  fplanque

1598   * category directory / albums

1599   *

1600   * Revision 1.66  2007/03/02 00:44:43  fplanque

1601   * various small fixes

1602   *

1603   * Revision 1.65  2007/02/25 01:31:34  fplanque

1604   * minor

1605   *

1606   * Revision 1.64  2007/02/17 21:12:14  blueyed

1607   * Removed magic in Plugin::get_htsrv_url() which used the blog url and assumed that "htsrv" was available in there

1608   *

1609   * Revision 1.63  2007/01/23 09:25:40  fplanque

1610   * Configurable sort order.

1611   *

1612   * Revision 1.62  2007/01/23 08:07:16  fplanque

1613   * Fixed blog URLs including urlnames

1614   *

1615   * Revision 1.61  2007/01/23 07:31:22  fplanque

1616   * "fixed" as per todo

1617   *

1618   * Revision 1.60  2007/01/23 05:30:20  fplanque

1619   * "Contact the owner"

1620   *

1621   * Revision 1.59  2007/01/23 04:19:50  fplanque

1622   * handling of blog owners

1623   *

1624   * Revision 1.58  2007/01/23 03:45:56  fplanque

1625   * bugfix

1626   *

1627   * Revision 1.57  2007/01/16 00:44:42  fplanque

1628   * don't use $admin_email in  the app

1629   *

1630   * Revision 1.56  2007/01/15 19:28:39  blueyed

1631   * doc

1632   *

1633   * Revision 1.55  2007/01/15 03:54:36  fplanque

1634   * pepped up new blog creation a little more

1635   *

1636   * Revision 1.54  2007/01/15 00:38:06  fplanque

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

1638   *

1639   * Revision 1.53  2007/01/14 01:33:34  fplanque

1640   * losely restrict to *installed* XML feed skins

1641   *

1642   * Revision 1.52  2007/01/08 02:11:55  fplanque

1643   * Blogs now make use of installed skins

1644   * next step: make use of widgets inside of skins

1645   *

1646   * Revision 1.51  2006/12/23 23:37:35  fplanque

1647   * refactoring / Blog::get_default_cat_ID()

1648   *

1649   * Revision 1.50  2006/12/23 23:15:19  fplanque

1650   * refactoring / Blog::get_allowed_item_status()

1651   *

1652   * Revision 1.49  2006/12/22 00:50:33  fplanque

1653   * improved path cleaning

1654   *

1655   * Revision 1.48  2006/12/21 22:25:43  fplanque

1656   * Removed restricting constraint. (It may have been good for hiding a bug, but it restricts the purpose)

1657   *

1658   * Revision 1.47  2006/12/19 21:40:17  blueyed

1659   * Test if baseurl is valid by testing if "htsrv/" is accessible below it; see http://forums.b2evolution.net/viewtopic.php?p=48707#48707 et seqq.

1660   *

1661   * Revision 1.46  2006/12/17 23:42:38  fplanque

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

1663   * Look into Advanced Settings for the aggregating blog.

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

1665   *

1666   * Revision 1.45  2006/12/16 01:30:46  fplanque

1667   * Setting to allow/disable email subscriptions on a per blog basis

1668   *

1669   * Revision 1.44  2006/12/14 21:41:15  fplanque

1670   * Allow different number of items in feeds than on site

1671   *

1672   * Revision 1.43  2006/12/14 00:01:49  fplanque

1673   * land in correct collection when opening FM from an Item

1674   *

1675   * Revision 1.42  2006/12/13 18:23:36  blueyed

1676   * doc

1677   *

1678   * Revision 1.41  2006/12/10 23:56:26  fplanque

1679   * Worfklow stuff is now hidden by default and can be enabled on a per blog basis.

1680   *

1681   * Revision 1.40  2006/12/07 23:13:10  fplanque

1682   * @var needs to have only one argument: the variable type

1683   * Otherwise, I can't code!

1684   *

1685   * Revision 1.39  2006/12/04 23:49:49  blueyed

1686   * Normalized: setMediaUrl() => set_media_url(); setMediaFullPath() => set_media_fullpath(); setMediaSubDir() => set_media_subdir()

1687   *

1688   * Revision 1.38  2006/12/04 21:25:18  fplanque

1689   * removed user skin switching

1690   *

1691   * Revision 1.37  2006/12/04 19:41:11  fplanque

1692   * Each blog can now have its own "archive mode" settings

1693   *

1694   * Revision 1.36  2006/12/04 18:16:50  fplanque

1695   * Each blog can now have its own "number of page/days to display" settings

1696   *

1697   * Revision 1.35  2006/11/28 00:33:01  blueyed

1698   * Removed DB::compString() (never used) and DB::get_list() (just a macro and better to have in the 4 used places directly; Cleanup/normalization; no extended regexp, when not needed!

1699   *

1700   * Revision 1.34  2006/11/24 18:27:23  blueyed

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

1702   *

1703   * Revision 1.33  2006/11/13 20:49:52  fplanque

1704   * doc/cleanup :/

1705   *

1706   * Revision 1.32  2006/10/23 22:19:02  blueyed

1707   * Fixed/unified encoding of redirect_to param. Use just rawurlencode() and no funky &amp; replacements

1708   *

1709   * Revision 1.31  2006/10/14 04:43:35  blueyed

1710   * Removed last allowpingbacks references

1711   *

1712   * Revision 1.30  2006/10/10 23:24:41  blueyed

1713   * Fixed duplication of ping plugins from hidden values

1714   *

1715   * Revision 1.29  2006/10/01 22:11:42  blueyed

1716   * Ping services as plugins.

1717   */
1718  ?>


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