b2evolution PHP Cross Reference Blogging Systems

Source: /inc/widgets/_widgets.funcs.php - 274 lines - 15885 bytes - Summary - Text - Print

Description: This file implements additional functional for widgets. This file is part of the b2evolution/evocms project - {@link http://b2evolution.net/}. See also {@link http://sourceforge.net/projects/evocms/}.

   1  <?php
   2  /**
   3   * This file implements additional functional for widgets.
   4   *
   5   * This file is part of the b2evolution/evocms project - {@link http://b2evolution.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-2005 by Daniel HAHLER - {@link http://thequod.de/contact}.
  10   *
  11   * @license http://b2evolution.net/about/license.html GNU General Public License (GPL)
  12   *
  13   * {@internal Open Source relicensing agreement:
  14   * Daniel HAHLER grants Francois PLANQUE the right to license
  15   * Daniel HAHLER's contributions to this file and the b2evolution project
  16   * under any OSI approved OSS license (http://www.opensource.org/licenses/).
  17   * }}
  18   *
  19   * @package evocore
  20   *
  21   * {@internal Below is a list of authors who have contributed to design/coding of this file: }}
  22   *
  23   */
  24  if( !defined('EVO_CONFIG_LOADED') ) die( 'Please, do not access this page directly.' );
  25  
  26  /**
  27   * @todo factorize!
  28   *
  29   * @param integer should never be 0
  30   * @param boolean should be true only when it's called after initial install
  31   * @param string Kind of blog ( 'std', 'photo', 'group', 'forum' )
  32   */
  33  function insert_basic_widgets( $blog_id, $initial_install = false, $kind = '' )
  34  {
  35      global $DB, $test_install_all_features;
  36      global $events_blog_ID;
  37  
  38      $default_blog_param = 's:7:"blog_ID";s:0:"";';
  39      if( $initial_install )
  40      {    // In the case of initial install, we grab photos out of the photoblog (Blog #4)
  41          $default_blog_param = 's:7:"blog_ID";s:1:"4";';
  42      }
  43  
  44      if( false )
  45      {// old code: NOT USED ANYMORE - TO BE REMOVED SOON.
  46          /*$DB->query('INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code )
  47                               SELECT blog_ID, "Page Top", 1, "core", "colls_list_public"
  48                                 FROM T_blogs');
  49          $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code )
  50                               SELECT blog_ID, "Header", 1, "core", "coll_title"
  51                                 FROM T_blogs' );
  52          $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code )
  53                               SELECT blog_ID, "Header", 2, "core", "coll_tagline"
  54                                 FROM T_blogs' );
  55          $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code, wi_params )
  56                               SELECT blog_ID, "Menu", 1, "core", "menu_link", "'.$DB->escape(serialize(array('link_type'=>'home'))).'"
  57                                 FROM T_blogs' );
  58          $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code, wi_params )
  59                               SELECT blog_ID, "Menu", 3, "core", "menu_link", "'.$DB->escape(serialize(array('link_type'=>'ownercontact'))).'"
  60                                 FROM T_blogs' );
  61          $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code )
  62                               SELECT blog_ID, "Menu", 2, "core", "coll_page_list"
  63                                 FROM T_blogs' );
  64          $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code, wi_params )
  65                               SELECT blog_ID, "Menu", 4, "core", "menu_link", "'.$DB->escape(serialize(array('link_type'=>'login'))).'"
  66                                 FROM T_blogs'  );
  67  
  68          $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code )
  69                               SELECT blog_ID, "Menu Top", 1, "core", "coll_search_form"
  70                                 FROM T_blogs'  );
  71  
  72          $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code )
  73                               SELECT blog_ID, "Sidebar", 10, "core", "coll_avatar"
  74                                 FROM T_blogs'  );
  75          $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code )
  76                               SELECT blog_ID, "Sidebar", 20, "plugin", "evo_Calr"
  77                                 FROM T_blogs
  78                                WHERE blog_ID > 1' );
  79          $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code )
  80                               SELECT blog_ID, "Sidebar", 40, "core", "coll_longdesc"
  81                                 FROM T_blogs' );
  82          $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code )
  83                               SELECT blog_ID, "Sidebar", 30, "core", "coll_title"
  84                                 FROM T_blogs' );
  85          $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code )
  86                               SELECT blog_ID, "Sidebar", 50, "core", "coll_common_links"
  87                                 FROM T_blogs' );
  88          $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code )
  89                               SELECT blog_ID, "Sidebar", 60, "core", "coll_search_form"
  90                                 FROM T_blogs' );
  91          $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code )
  92                               SELECT blog_ID, "Sidebar", 70, "core", "coll_category_list"
  93                                 FROM T_blogs' );
  94          $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code, wi_params )
  95                               SELECT blog_ID, "Sidebar", 80, "core", "coll_media_index", \'a:11:{s:5:"title";s:12:"Random photo";s:10:"thumb_size";s:11:"fit-160x120";s:12:"thumb_layout";s:4:"grid";s:12:"grid_nb_cols";s:1:"1";s:5:"limit";s:1:"1";s:8:"order_by";s:4:"RAND";s:9:"order_dir";s:3:"ASC";s:7:"blog_ID";s:1:"4";s:11:"widget_name";s:12:"Random photo";s:16:"widget_css_class";s:0:"";s:9:"widget_ID";s:0:"";}\'
  96                                 FROM T_blogs
  97                                WHERE blog_ID <> 2' );
  98          $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code, wi_params )
  99                               SELECT blog_ID, "Sidebar", 90, "core", "linkblog", "'.$DB->escape(serialize(array('blog_ID'=>3))).'"
 100                                 FROM T_blogs
 101                                WHERE blog_ID <= 2' );
 102          $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code )
 103                               SELECT blog_ID, "Sidebar", 100, "core", "coll_xml_feeds"
 104                                 FROM T_blogs' );
 105          $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code )
 106                                   SELECT blog_ID, "Sidebar 2", 1, "core", "coll_post_list"
 107                                     FROM T_blogs' );
 108  
 109          $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code )
 110                                   SELECT blog_ID, "Sidebar 2", 2, "core", "coll_comment_list"
 111                                     FROM T_blogs' );
 112  
 113          $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code, wi_params )
 114                                   SELECT blog_ID, "Sidebar 2", 3, "core", "coll_media_index", \'a:11:{s:5:"title";s:13:"Recent photos";s:10:"thumb_size";s:10:"crop-80x80";s:12:"thumb_layout";s:4:"grid";s:12:"grid_nb_cols";s:1:"3";s:5:"limit";s:1:"9";s:8:"order_by";s:9:"datestart";s:9:"order_dir";s:4:"DESC";s:7:"blog_ID";s:1:"4";s:11:"widget_name";s:11:"Photo index";s:16:"widget_css_class";s:0:"";s:9:"widget_ID";s:0:"";}\'
 115                                     FROM T_blogs' );
 116  
 117          $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code, wi_params )
 118                                   SELECT blog_ID, "Sidebar 2", 4, "core", "free_html", \'a:5:{s:5:"title";s:9:"Sidebar 2";s:7:"content";s:162:"This is the "Sidebar 2" container. You can place any widget you like in here. In the evo toolbar at the top of this page, select "Customize", then "Blog Widgets".";s:11:"widget_name";s:9:"Free HTML";s:16:"widget_css_class";s:0:"";s:9:"widget_ID";s:0:"";}\'
 119                                     FROM T_blogs' );*/
 120      }
 121      else
 122      { // New code used in all situations:
 123          $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code )
 124                              VALUES( '.$blog_id.', "Page Top", 1, "core", "colls_list_public" )' );
 125  
 126          /* Header */
 127          $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code ) VALUES
 128              ( '.$blog_id.', "Header", 1, "core", "coll_title" ),
 129              ( '.$blog_id.', "Header", 2, "core", "coll_tagline" )' );
 130  
 131          /* Menu */
 132          $wi_params_link_home = array( 'link_type' => 'home' );
 133          if( $kind == 'forum' )
 134          {
 135              $wi_params_link_home['link_text'] = T_('Forums Home');
 136          }
 137          $widgets_insert_sql = 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code, wi_params ) VALUES';
 138          $widgets_insert_sql_rows = array();
 139          $widgets_insert_sql_rows[] = '( '.$blog_id.', "Menu", 10, "core", "menu_link", "'.$DB->escape( serialize( $wi_params_link_home ) ).'" )';
 140          if( $kind == 'forum' )
 141          { // Latest Replies
 142              $widgets_insert_sql_rows[] = '( '.$blog_id.', "Menu", 15, "core", "menu_link", "'.$DB->escape( serialize( array( 'link_type' => 'latestcomments', 'link_text' => T_('Latest Replies') ) ) ).'" )';
 143          }
 144          $widgets_insert_sql_rows[] = '( '.$blog_id.', "Menu", 20, "core", "coll_page_list", NULL )';
 145          if( $kind == 'forum' )
 146          { // My Profile
 147              $widgets_insert_sql_rows[] = '( '.$blog_id.', "Menu", 35, "core", "menu_link", "'.$DB->escape( serialize( array( 'link_type' => 'myprofile' ) ) ).'" )';
 148          }
 149          if( $kind != 'forum' )
 150          { // Blog owner contact form & Log in form
 151              $widgets_insert_sql_rows[] = '( '.$blog_id.', "Menu", 30, "core", "menu_link", "'.$DB->escape( serialize( array( 'link_type' => 'ownercontact' ) ) ).'" )';
 152              $widgets_insert_sql_rows[] = '( '.$blog_id.', "Menu", 40, "core", "menu_link", "'.$DB->escape( serialize( array( 'link_type' => 'login' ) ) ).'" )';
 153          }
 154          $widgets_insert_sql_rows[] = '( '.$blog_id.', "Menu", 50, "core", "msg_menu_link", "'.$DB->escape( serialize( array( 'link_type' => 'messages' ) ) ).'" )';
 155          $widgets_insert_sql_rows[] = '( '.$blog_id.', "Menu", 60, "core", "msg_menu_link", "'.$DB->escape( serialize( array( 'link_type' => 'contacts', 'show_badge' => 0 ) ) ).'" )';
 156          if( $kind == 'forum' )
 157          { // Log in form
 158              $widgets_insert_sql_rows[] = '( '.$blog_id.', "Menu", 63, "core", "menu_link", "'.$DB->escape( serialize( array( 'link_type' => 'login' ) ) ).'" )';
 159              $widgets_insert_sql_rows[] = '( '.$blog_id.', "Menu", 66, "core", "menu_link", "'.$DB->escape( serialize( array( 'link_type' => 'register' ) ) ).'" )';
 160          }
 161          if( $test_install_all_features && $kind != 'forum' )
 162          { // Add menu with User Directory
 163              $widgets_insert_sql_rows[] = '( '.$blog_id.', "Menu", 70, "core", "menu_link", "'.$DB->escape( serialize( array( 'link_type' => 'users' ) ) ).'" )';
 164          }
 165          $DB->query( $widgets_insert_sql.implode( ', ', $widgets_insert_sql_rows ) );
 166  
 167          /* Item Single */
 168          if( ( $blog_id == 1 || ( !empty( $events_blog_ID ) && $blog_id == $events_blog_ID ) ) && $test_install_all_features )
 169          {
 170              $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code)
 171                                  VALUES( '.$blog_id.', "Item Single", 1, "plugin", "evo_Gmaps")' );
 172              // add blog collection setting to activate additional fields
 173  
 174              $DB->query( 'REPLACE INTO T_coll_settings(cset_coll_ID, cset_name, cset_value)
 175                                  VALUES( '.$blog_id.', "show_location_coordinates" , 1)' );
 176          }
 177  
 178          /* Menu Top */
 179          if( $kind == 'forum' )
 180          {    // Set special params for forums blogs
 181              $menu_top_params = array(
 182                      'title' => T_('Search this forum:'),
 183                      'button' => T_('Search')
 184                  );
 185          }
 186          elseif( $kind == 'manual' )
 187          {    // Set special params for manual blogs
 188              $menu_top_params = array(
 189                      'title' => T_('Search this manual:'),
 190                  );
 191          }
 192          $menu_top_params = !empty( $menu_top_params ) ? '"'.$DB->escape( serialize( $menu_top_params ) ).'"' : 'NULL';
 193          $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code, wi_params )
 194                              VALUES( '.$blog_id.', "Menu Top", 1, "core", "coll_search_form", '.$menu_top_params.' )' );
 195  
 196          /* Sidebar */
 197          if( $test_install_all_features )
 198          {    // Add User login widget
 199              $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code )
 200                              VALUES( '.$blog_id.', "Sidebar", 10, "core", "user_login" )' );
 201          }
 202          if( ( !$initial_install || $blog_id != 5 ) && $kind != 'forum' )
 203          {    // Don't install these Sidebar widgets for blog 'Forums'
 204              $widgets_insert_sql = 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code, wi_params ) VALUES
 205                  ( '.$blog_id.', "Sidebar", 20, "core", "user_tools", "'.$DB->escape(serialize(array('title'=>''))).'" ),
 206                  ( '.$blog_id.', "Sidebar", 30, "core", "coll_avatar", NULL )';
 207              if( $blog_id > 1 )
 208              {
 209                  $widgets_insert_sql .= ',
 210                  ( '.$blog_id.', "Sidebar", 40, "plugin", "evo_Calr", NULL )';
 211              }
 212              $widgets_insert_sql .= ',
 213                  ( '.$blog_id.', "Sidebar", 50, "core", "coll_title", NULL ),
 214                  ( '.$blog_id.', "Sidebar", 60, "core", "coll_longdesc", NULL ),
 215                  ( '.$blog_id.', "Sidebar", 70, "core", "coll_common_links", NULL ),
 216                  ( '.$blog_id.', "Sidebar", 80, "core", "coll_search_form", NULL ),
 217                  ( '.$blog_id.', "Sidebar", 90, "core", "coll_category_list", NULL )';
 218              $DB->query( $widgets_insert_sql );
 219  
 220              // Advertisements
 221              $advertisement_params = array(
 222                      'title' => 'Advertisement',
 223                      'item_type' => 4000,
 224                      'blog_ID' => $blog_id,
 225                      'order_by' => 'RAND',
 226                      'limit' => 1,
 227                      'disp_title' => false,
 228                      'item_title_link_type' => 'linkto_url',
 229                      'attached_pics' => 'first',
 230                      'item_pic_link_type' => 'linkto_url',
 231                      'thumb_size' => 'fit-160x160',
 232                  );
 233              $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code, wi_params )
 234                                  VALUES( '.$blog_id.', "Sidebar", 100, "core", "coll_item_list", "'.$DB->escape( serialize( $advertisement_params ) ).'" )' );
 235  
 236              if( $blog_id != 2 )
 237              {
 238                  $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code, wi_params )
 239                                      VALUES( '.$blog_id.', "Sidebar", 110, "core", "coll_media_index", \'a:11:{s:5:"title";s:12:"Random photo";s:10:"thumb_size";s:11:"fit-160x120";s:12:"thumb_layout";s:4:"grid";s:12:"grid_nb_cols";s:1:"1";s:5:"limit";s:1:"1";s:8:"order_by";s:4:"RAND";s:9:"order_dir";s:3:"ASC";'.$default_blog_param.'s:11:"widget_name";s:12:"Random photo";s:16:"widget_css_class";s:0:"";s:9:"widget_ID";s:0:"";}\' )' );
 240              }
 241              if( $blog_id <= 2 )
 242              {
 243                  $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code, wi_params )
 244                                      VALUES( '.$blog_id.', "Sidebar", 120, "core", "linkblog", "'.$DB->escape(serialize(array('blog_ID'=>3))).'" )' );
 245              }
 246          }
 247          $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code )
 248                              VALUES( '.$blog_id.', "Sidebar", 130, "core", "coll_xml_feeds" )' );
 249  
 250          /* Sidebar 2 */
 251          $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code )
 252                              VALUES( '.$blog_id.', "Sidebar 2", 1, "core", "coll_post_list" )' );
 253          if( $blog_id == 2 )
 254          {
 255              $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code, wi_params )
 256                              VALUES( '.$blog_id.', "Sidebar 2", 5, "core", "coll_link_list", "'.$DB->escape( serialize( array( 'title'=>'Sidebar links', 'order_by'=>'RAND' ) ) ).'" )' );
 257          }
 258          $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code )
 259                              VALUES( '.$blog_id.', "Sidebar 2", 10, "core", "coll_comment_list" )' );
 260          $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code, wi_params )
 261                              VALUES( '.$blog_id.', "Sidebar 2", 15, "core", "coll_media_index", \'a:11:{s:5:"title";s:13:"Recent photos";s:10:"thumb_size";s:10:"crop-80x80";s:12:"thumb_layout";s:4:"grid";s:12:"grid_nb_cols";s:1:"3";s:5:"limit";s:1:"9";s:8:"order_by";s:9:"datestart";s:9:"order_dir";s:4:"DESC";'.$default_blog_param.'s:11:"widget_name";s:11:"Photo index";s:16:"widget_css_class";s:0:"";s:9:"widget_ID";s:0:"";}\' )' );
 262          $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code, wi_params )
 263                              VALUES( '.$blog_id.', "Sidebar 2", 20, "core", "free_html", \'a:5:{s:5:"title";s:9:"Sidebar 2";s:7:"content";s:162:"This is the "Sidebar 2" container. You can place any widget you like in here. In the evo toolbar at the top of this page, select "Customize", then "Blog Widgets".";s:11:"widget_name";s:9:"Free HTML";s:16:"widget_css_class";s:0:"";s:9:"widget_ID";s:0:"";}\' )' );
 264          
 265          /* Mobile Footer */
 266          $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code )
 267                              VALUES( '.$blog_id.', "Mobile Footer", 10, "core", "coll_longdesc" )' );
 268          $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code )
 269                              VALUES( '.$blog_id.', "Mobile Footer", 20, "core", "mobile_skin_switcher" )' );
 270      }
 271  
 272  }
 273  
 274  ?>

title

Description

title

Description

title

Description

title

title

Body