[ Index ]

PHP Cross Reference of zeList

title

Body

[close]

/ -> zelist.php (source)

   1  <?php
   2  /*
   3   Plugin Name: zeList
   4   Plugin URI: http://www.zelist.net/
   5   Description: Wordpress as a directory script. <a href="http://www.zelist.net/support/">Forum</a>. <a href="http://www.zelist.net/bugs/">Bugs</a>.
   6   Author: Malaiac
   7   Version: 0.8.56
   8   Author URI: http://www.malaiac.com/
   9  
  10   Copyright (C) 2008  Malaiac
  11  
  12   This program is free software; you can redistribute it and/or
  13   modify it under the terms of the GNU General Public License
  14   as published by the Free Software Foundation; either version 2
  15   of the License, or (at your option) any later version.
  16  
  17   This program is distributed in the hope that it will be useful,
  18   but WITHOUT ANY WARRANTY; without even the implied warranty of
  19   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20   GNU General Public License for more details.
  21   */
  22  
  23  define('ZELIST_CURRENT_VERSION','0.8.56');
  24  define('ZELIST_MAX_TAGS',20);
  25  define('ZELIST_MAX_IMAGES',10);
  26  
  27  define('ZELIST_PATH',dirname(__FILE__));
  28  define('ZELIST_ADMIN_PATH',ZELIST_PATH.'/admin');
  29  define('ZELIST_INCLUDES',ZELIST_PATH.'/includes');
  30  define('ZELIST_URL',WP_PLUGIN_URL.'/zelist');
  31  
  32  require(ZELIST_INCLUDES.'/hooks.php');
  33  require(ZELIST_INCLUDES.'/functions.php');
  34  require(ZELIST_INCLUDES.'/duplicate.php');
  35  require(ZELIST_INCLUDES.'/query.php');
  36  require(ZELIST_INCLUDES.'/link.php');
  37  require(ZELIST_INCLUDES.'/link-category.php');
  38  require(ZELIST_INCLUDES.'/link-tags.php');
  39  require(ZELIST_INCLUDES.'/metas.php');
  40  require(ZELIST_INCLUDES.'/notifications.php');
  41  require(ZELIST_INCLUDES.'/bridges.php');
  42  
  43  
  44  define('ZELIST_ADMIN_URL_ADD',admin_url('admin.php?page=zelist/admin/link-add.php'));
  45  define('ZELIST_ADMIN_URL_LINK',admin_url('admin.php?page=zelist/admin/link.php'));
  46  
  47  if(is_admin()) {
  48    require(ZELIST_INCLUDES.'/admin-hooks.php');
  49    require(ZELIST_INCLUDES.'/admin-template.php');
  50    require(ZELIST_INCLUDES.'/admin-functions.php');
  51    require(ZELIST_INCLUDES.'/admin-submit.php');
  52    require(ZELIST_INCLUDES.'/api.php');
  53    require(ZELIST_INCLUDES.'/api-template.php');
  54  
  55    define('ZELIST_ADMIN_URL_MANAGER',admin_url('admin.php?page=zelist/admin/link-manager.php'));
  56    define('ZELIST_ADMIN_URL_SETTINGS',admin_url('admin.php?page=zelist/admin/settings.php'));
  57    define('ZELIST_ADMIN_URL_META',admin_url('admin.php?page=zelist/admin/meta.php'));
  58    define('ZELIST_ADMIN_URL_METAS',admin_url('admin.php?page=zelist/admin/metas.php'));
  59    define('ZELIST_ADMIN_URL_CATEGORIES_PAGE','zelist/admin/link-categories.php');
  60    define('ZELIST_ADMIN_URL_CATEGORIES',admin_url('admin.php?page='.ZELIST_ADMIN_URL_CATEGORIES_PAGE));
  61  
  62    define('ZELIST_ADMIN_URL_CATEGORY',admin_url('admin.php?page=zelist/admin/link-category.php'));
  63    define('ZELIST_ADMIN_URL_TAGS',admin_url('admin.php?page=zelist/admin/tags.php'));
  64    define('ZELIST_ADMIN_URL_API',admin_url('admin.php?page=zelist/admin/api.php'));
  65  
  66    define('ZELIST_ADMIN_PATH_LINK',ZELIST_PATH.'/admin/link.php');
  67    define('ZELIST_ADMIN_PATH_EDIT_LINK_FORM',ZELIST_PATH.'/admin/edit-link-form.php');
  68    define('ZELIST_ADMIN_PATH_EDIT_TAG_FORM',ZELIST_PATH.'/admin/edit-tag-form.php');
  69    define('ZELIST_ADMIN_PATH_EDIT_CATEGORY_FORM',ZELIST_PATH.'/admin/edit-link-category-form.php');
  70  }
  71  
  72  require(ZELIST_INCLUDES.'/template.php');
  73  require(ZELIST_INCLUDES.'/template-hooks.php');
  74  require(ZELIST_INCLUDES.'/template-functions.php');
  75  
  76  
  77  /**
  78   * zeList installation
  79   * @return unknown_type
  80   */
  81  if(!function_exists('zelist_install')) {
  82    function zelist_install() {
  83      // adding/updating version number
  84      $version = get_option('zelist_version');
  85      if(!$version) add_option('zelist_version',ZELIST_CURRENT_VERSION);
  86      elseif($version != ZELIST_CURRENT_VERSION) update_option('zelist_version',ZELIST_CURRENT_VERSION);
  87      //else return;
  88  
  89      zelist_add_taxonomies();
  90      global $wp_rewrite;
  91      $wp_rewrite->flush_rules();
  92  
  93      if(!get_option('zelist_description_min_length'))  add_option('zelist_description_min_length',50);
  94      if(!get_option('zelist_description_max_length'))  add_option('zelist_description_max_length',300);
  95      if(!get_option('zelist_rewrite'))  add_option('zelist_rewrite',0);
  96      if(!get_option('zelist_allow_multiple_categories')) add_option('zelist_allow_multiple_categories',0);
  97      if(!get_option('zelist_rewrite_prefix_link')) add_option('zelist_rewrite_prefix_link','site');
  98      if(!get_option('zelist_rewrite_prefix_link_tag')) add_option('zelist_rewrite_prefix_link_tag','site_tag');
  99  
 100      if(!get_option('zelist_rewrite_prefix_link_category')) add_option('zelist_rewrite_prefix_link_category','sites');
 101      if(!get_option('links_per_page')) add_option('links_per_page',10);
 102  
 103      if(!get_option('zelist_cc_admin')) add_option('zelist_cc_admin',1);
 104  
 105      // creating the directory page if needed
 106      if(!get_option('zelist_root') || !get_post(get_option('zelist_root'))) {
 107        $postarray = array(
 108              'post_status' => 'publish',
 109              'post_type' => 'page',
 110              'post_title' => __('Directory','zelist'),
 111        );
 112        if($zelist_root = wp_insert_post($postarray)) {
 113          update_post_meta($zelist_root, 'zelist',  1);
 114          add_option('zelist_root',$zelist_root);
 115          add_post_meta($zelist_root,'aiosp_disable',1);
 116        }
 117      }
 118      // creating the submit page if needed
 119      if(!get_option('zelist_submit_page') || !get_post(get_option('zelist_submit_page'))) {
 120        $postarray = array(
 121        'post_status' => 'publish',
 122        'post_type' => 'page',
 123        'post_title' => __('Submit a link','zelist'),
 124        'post_content' => '<!--[zelist_submit]-->',
 125        'ping_status' => 0,
 126        'comment_status' => 'closed',
 127        );
 128        if($zelist_submit_page = wp_insert_post($postarray)) {
 129          update_post_meta($zelist_submit_page, 'zelist',  1);
 130          add_option('zelist_submit_page',$zelist_submit_page);
 131        }
 132      }
 133  
 134      // altering the database
 135      global $wpdb;
 136  
 137      // @TODO WAITING for WordPress to have a generic meta architecture
 138      // link meta table
 139      $wpdb->linkmeta = $wpdb->prefix.'linkmeta';
 140  
 141      // TABLE CREATION
 142      if($wpdb->linkmeta != $wpdb->get_var("SHOW TABLES like '$wpdb->linkmeta'")) {
 143        $charset_collate = '';
 144        if ( $wpdb->has_cap( 'collation' ) ) {
 145          if ( ! empty($wpdb->charset) )
 146          $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
 147          if ( ! empty($wpdb->collate) )
 148          $charset_collate .= " COLLATE $wpdb->collate";
 149        }
 150        $wpdb->query("CREATE TABLE $wpdb->linkmeta ( "
 151        ."meta_id bigint(20) NOT NULL auto_increment, "
 152        ."link_id bigint(20) NOT NULL default '0', "
 153        ."meta_key varchar(255) default NULL, "
 154        ."meta_value longtext, "
 155        ."PRIMARY KEY  (meta_id), "
 156        ."KEY link_id (link_id), "
 157        ."KEY meta_key (meta_key) "
 158        .") $charset_collate ");
 159      }
 160  
 161      // FIELDS
 162      $fields = array();
 163      $columns = $wpdb->get_results("SHOW COLUMNS FROM $wpdb->links;");
 164      foreach($columns as $column) {
 165        $fields[$column->Field] = $column;
 166      }
 167  
 168      if(!isset($fields['link_status'])) {
 169        $wpdb->query("ALTER TABLE `$wpdb->links` ADD `link_status` VARCHAR( 20 ) NOT NULL DEFAULT 'pending' AFTER `link_visible` ;");
 170      }
 171      elseif($fields['link_status']['Default'] != 'pending') {
 172        $wpdb->query("ALTER TABLE  `$wpdb->links` CHANGE  `link_status`  `link_status` DEFAULT  'pending'");
 173      }
 174  
 175      if(!isset($fields['link_added'])) { // submit date
 176        $wpdb->query("ALTER TABLE `$wpdb->links` ADD `link_added` DATETIME NOT NULL AFTER `link_rating`");
 177        $wpdb->query("UPDATE $wpdb->links SET link_added = NOW() WHERE link_added = '0000-00-00'");
 178      }
 179  
 180      if(!isset($fields['link_published'])) { // publish date
 181        $wpdb->query("ALTER TABLE `$wpdb->links` ADD `link_published` DATETIME NULL AFTER `link_added`");
 182      }
 183  
 184      $wpdb->query("UPDATE $wpdb->links SET link_updated = NOW() WHERE link_updated = '0000-00-00'");
 185  
 186      foreach($fields as $field => $field_data) {
 187        switch ($field) {
 188          case 'link_description' :
 189            if($field_data->Type != 'text')
 190            $wpdb->query("ALTER TABLE `$wpdb->links` CHANGE `link_description` `link_description` TEXT NOT NULL;");
 191            break;
 192            // olds fields
 193          case 'link_pagerank' :
 194            $wpdb->query("ALTER TABLE `$wpdb->links` DROP `link_pagerank` ?");
 195            break;
 196          case 'link_hits' :
 197            $wpdb->query("ALTER TABLE `$wpdb->links` DROP `link_hits` ?");
 198            break;
 199          case 'link_checked' :
 200            $wpdb->query("ALTER TABLE `$wpdb->links` DROP `link_checked` ?");
 201            break;
 202          case 'link_alive' :
 203            $wpdb->query("ALTER TABLE `$wpdb->links` DROP `link_alive` ?");
 204            break;
 205        }
 206      }
 207  
 208      // INDEX (full_text index on link_name + link_description
 209      $results = $wpdb->get_results("SHOW INDEXES FROM $wpdb->links");
 210      $indexes = array();
 211      foreach($results as $result) {
 212        if(!isset($indexes[$result->Key_name])) $indexes[$result->Key_name] = array();
 213        $indexes[$result->Key_name][] = $result->Column_name;
 214      }
 215      if(!isset($indexes['link_search']) || $indexes['link_search'] != array('link_name','link_description') ) {
 216        $wpdb->query("ALTER TABLE `$wpdb->links` ADD FULLTEXT `link_search` (`link_name` ,`link_description`)");
 217      }
 218  
 219      if(!$ban_reasons = get_option('zelist_banreasons')) {
 220        foreach(array('notpertinent', 'incomplete', 'spam', 'short_description','noimage') as $reason) {
 221          $ban_reasons[$reason] = banreason_label($reason);
 222          add_option('zelist_banreasons',$ban_reasons);
 223        }
 224      }
 225      if(!get_option('zelist_metas_boxes')) add_option('zelist_metas_boxes',0);
 226      if(!get_option('zelist_installed')) add_option('zelist_installed',1);
 227    }
 228  }
 229  register_activation_hook(__FILE__,'zelist_install');
 230  
 231  /*
 232   * Small hack for __ngettext
 233   **/
 234  if(!function_exists('zelist_text_holder')) {
 235    function zelist_text_holder() {
 236      $array = array(
 237      'All (%s)', 'All (%s)',
 238      'Published (%s)', 'Published (%s)',
 239      'Denied (%s)','Denied (%s)',
 240      'Pending Validation (%s)','Pending Review (%s)',
 241      );
 242    }
 243  }


Generated: Sat May 30 23:51:06 2009 Cross-referenced by PHPXref 0.7