コード例 #1
0
ファイル: cp.admin.php プロジェクト: jlleblanc/ConnectBoom
 function Admin()
 {
     global $IN, $LANG, $SESS, $LOG, $DSP;
     // This flag determines if a user can edit categories from the publish page.
     $category_exception = ($IN->GBL('M') == 'blog_admin' and in_array($IN->GBL('P'), array('category_editor', 'edit_category', 'update_category', 'del_category_conf', 'del_category', 'cat_order')) and $IN->GBL('Z') == 1) ? TRUE : FALSE;
     if ($category_exception == FALSE and !$DSP->allowed_group('can_access_admin') and $IN->GBL('P', 'GET') != 'save_ping_servers') {
         return $DSP->no_access_message();
     }
     switch ($IN->GBL('M')) {
         case 'config_mgr':
             if (!$DSP->allowed_group('can_admin_preferences')) {
                 return $DSP->no_access_message();
             }
             switch ($IN->GBL('P')) {
                 case 'update_cfg':
                     $this->update_config_prefs();
                     break;
                 case 'member_cfg':
                     $this->member_config_manager();
                     break;
                 default:
                     $this->config_manager();
                     break;
             }
             break;
         case 'members':
             // Instantiate the member administration class
             require PATH_CP . 'cp.members' . EXT;
             $MBR = new Members();
             switch ($IN->GBL('P')) {
                 case 'view_members':
                     $MBR->view_all_members();
                     break;
                 case 'mbr_conf':
                     $MBR->member_confirm();
                     break;
                 case 'mbr_del_conf':
                     $MBR->member_delete_confirm();
                     break;
                 case 'mbr_delete':
                     $MBR->member_delete();
                     break;
                 case 'resend_act_email':
                     $MBR->resend_activation_emails();
                     break;
                 case 'member_reg_form':
                     $MBR->new_member_profile_form();
                     break;
                 case 'register_member':
                     $MBR->create_member_profile();
                     break;
                 case 'mbr_group_manager':
                     $MBR->member_group_manager();
                     break;
                 case 'edit_mbr_group':
                     $MBR->edit_member_group_form();
                     break;
                 case 'update_mbr_group':
                     $MBR->update_member_group();
                     break;
                 case 'mbr_group_del_conf':
                     $MBR->delete_member_group_conf();
                     break;
                 case 'delete_mbr_group':
                     $MBR->delete_member_group();
                     break;
                 case 'member_banning':
                     $MBR->member_banning_forms();
                     break;
                 case 'save_ban_data':
                     $MBR->update_banning_data();
                     break;
                 case 'profile_fields':
                     $MBR->custom_profile_fields();
                     break;
                 case 'edit_field':
                     $MBR->edit_profile_field_form();
                     break;
                 case 'del_field_conf':
                     $MBR->delete_profile_field_conf();
                     break;
                 case 'delete_field':
                     $MBR->delete_profile_field();
                     break;
                 case 'edit_field_order':
                     $MBR->edit_field_order_form();
                     break;
                 case 'update_field_order':
                     $MBR->update_field_order();
                     break;
                 case 'update_profile_fields':
                     $MBR->update_profile_fields();
                     break;
                 case 'member_search':
                     $MBR->member_search_form();
                     break;
                 case 'do_member_search':
                     $MBR->do_member_search();
                     break;
                 case 'ip_search':
                     $MBR->ip_search_form();
                     break;
                 case 'do_ip_search':
                     $MBR->do_ip_search();
                     break;
                 case 'member_validation':
                     $MBR->member_validation();
                     break;
                 case 'validate_members':
                     $MBR->validate_members();
                     break;
                 case 'email_console_logs':
                     $MBR->email_console_logs();
                     break;
                 case 'view_email':
                     $MBR->view_email();
                     break;
                 case 'delete_email_console':
                     $MBR->delete_email_console_messages();
                     break;
                 case 'profile_templates':
                     $MBR->profile_templates();
                     break;
                 case 'list_templates':
                     $MBR->list_templates();
                     break;
                 case 'edit_template':
                     $MBR->edit_template();
                     break;
                 case 'save_template':
                     $MBR->save_template();
                     break;
                 case 'login_as_member':
                     $MBR->login_as_member();
                     break;
                 case 'do_login_as_member':
                     $MBR->do_login_as_member();
                     break;
                 default:
                     return FALSE;
                     break;
             }
             break;
         case 'sp_templ':
             // Instantiate the specialty templates class
             require PATH_CP . 'cp.specialty_tmp' . EXT;
             $SP = new Specialty_Templates();
             switch ($IN->GBL('P')) {
                 case 'mbr_notification_tmpl':
                     $SP->mbr_notification_tmpl();
                     break;
                 case 'edit_notification_tmpl':
                     $SP->edit_notification_tmpl();
                     break;
                 case 'update_notification_tmpl':
                     $SP->update_notification_tmpl();
                     break;
                 case 'offline_tmpl':
                     $SP->offline_template();
                     break;
                 case 'update_offline_template':
                     $SP->update_offline_template();
                     break;
                 case 'user_messages_tmpl':
                     $SP->user_messages_template();
                     break;
                 case 'update_user_messages_tmpl':
                     $SP->update_user_messages_template();
                     break;
             }
             break;
         case 'site_admin':
             if (!$DSP->allowed_group('can_admin_sites')) {
                 return $DSP->no_access_message();
             }
             // Instantiate the site administration class
             require PATH_CP . 'cp.sites' . EXT;
             $SA = new SitesAdmin();
             switch ($IN->GBL('P')) {
                 case 'sites_list':
                     $SA->sites_list();
                     break;
                 case 'new_site':
                     $SA->new_site_form();
                     break;
                 case 'edit_site':
                     $SA->edit_site_form();
                     break;
                 case 'update_site':
                     $SA->update_site();
                     break;
                 case 'delete_site':
                     $SA->delete_site();
                     break;
                 case 'delete_site_confirm':
                     $SA->delete_site_confirm();
                     break;
                 default:
                     $SA->sites_list();
                     break;
             }
             break;
         case 'blog_admin':
             if ($category_exception == FALSE and !$DSP->allowed_group('can_admin_weblogs') and $IN->GBL('P', 'GET') != 'save_ping_servers') {
                 return $DSP->no_access_message();
             }
             // Instantiate the publish administration class
             require PATH_CP . 'cp.publish_ad' . EXT;
             $PA = new PublishAdmin();
             switch ($IN->GBL('P')) {
                 case 'blog_list':
                     $PA->weblog_overview();
                     break;
                 case 'new_weblog':
                     $PA->new_weblog_form();
                     break;
                 case 'blog_prefs':
                     $PA->edit_blog_form();
                     break;
                 case 'group_prefs':
                     $PA->edit_group_form();
                     break;
                 case 'create_blog':
                     $PA->update_weblog_prefs();
                     break;
                 case 'update_preferences':
                     $PA->update_weblog_prefs();
                     break;
                 case 'delete_conf':
                     $PA->delete_weblog_conf();
                     break;
                 case 'delete':
                     $PA->delete_weblog();
                     break;
                 case 'categories':
                     $PA->category_overview();
                     break;
                 case 'cat_group_editor':
                     $PA->edit_category_group_form();
                     break;
                 case 'update_cat_group':
                     $PA->update_category_group();
                     break;
                 case 'cat_group_del_conf':
                     $PA->delete_category_group_conf();
                     break;
                 case 'delete_group':
                     $PA->delete_category_group();
                     break;
                 case 'category_editor':
                     $PA->category_manager();
                     break;
                 case 'update_category':
                     $PA->update_category();
                     break;
                 case 'edit_category':
                     $PA->edit_category_form();
                     break;
                 case 'cat_order':
                     $PA->change_category_order();
                     break;
                 case 'global_cat_order':
                     $PA->global_category_order();
                     break;
                 case 'del_category_conf':
                     $PA->delete_category_confirm();
                     break;
                 case 'del_category':
                     $PA->delete_category();
                     break;
                 case 'cat_field_group_edit':
                     $PA->category_field_group_manager();
                     break;
                 case 'del_cat_field_conf':
                     $PA->delete_category_field_confirm();
                     break;
                 case 'del_cat_field':
                     $PA->delete_category_field();
                     break;
                 case 'edit_cat_field':
                     $PA->edit_category_field_form();
                     break;
                 case 'edit_cat_field_order':
                     $PA->edit_category_field_order_form();
                     break;
                 case 'ud_cat_field_order':
                     $PA->update_category_field_order();
                     break;
                 case 'update_cat_fields':
                     $PA->update_category_fields();
                     break;
                 case 'statuses':
                     $PA->status_overview();
                     break;
                 case 'status_group_editor':
                     $PA->edit_status_group_form();
                     break;
                 case 'update_status_group':
                     $PA->update_status_group();
                     break;
                 case 'status_group_del_conf':
                     $PA->delete_status_group_conf();
                     break;
                 case 'delete_status_group':
                     $PA->delete_status_group();
                     break;
                 case 'status_editor':
                     $PA->status_manager();
                     break;
                 case 'update_status':
                     $PA->update_status();
                     break;
                 case 'edit_status':
                     $PA->edit_status_form();
                     break;
                 case 'del_status_conf':
                     $PA->delete_status_confirm();
                     break;
                 case 'del_status':
                     $PA->delete_status();
                     break;
                 case 'edit_status_order':
                     $PA->edit_status_order();
                     break;
                 case 'update_status_order':
                     $PA->update_status_order();
                     break;
                 case 'custom_fields':
                     $PA->field_overview();
                     break;
                 case 'update_field_group':
                     $PA->update_field_group();
                     break;
                 case 'del_field_group_conf':
                     $PA->delete_field_group_conf();
                     break;
                 case 'delete_field_group':
                     $PA->delete_field_group();
                     break;
                 case 'field_editor':
                     $PA->field_manager();
                     break;
                 case 'edit_field':
                     $PA->edit_field_form();
                     break;
                 case 'update_weblog_fields':
                     $PA->update_weblog_fields();
                     break;
                 case 'field_group_editor':
                     $PA->edit_field_group_form();
                     break;
                 case 'del_field_conf':
                     $PA->delete_field_conf();
                     break;
                 case 'delete_field':
                     $PA->delete_field();
                     break;
                 case 'edit_field_order':
                     $PA->edit_field_order_form();
                     break;
                 case 'update_field_order':
                     $PA->update_field_order();
                     break;
                 case 'edit_fmt_buttons':
                     $PA->edit_formatting_buttons();
                     break;
                 case 'update_fmt_buttons':
                     $PA->update_formatting_buttons();
                     break;
                 case 'html_buttons':
                     $PA->html_buttons();
                     break;
                 case 'save_html_buttons':
                     $PA->save_html_buttons();
                     break;
                 case 'ping_servers':
                     $PA->ping_servers();
                     break;
                 case 'save_ping_servers':
                     $PA->save_ping_servers();
                     break;
                 case 'upload_prefs':
                     $PA->file_upload_preferences();
                     break;
                 case 'edit_upload_pref':
                     $PA->edit_upload_preferences_form();
                     break;
                 case 'update_upload_prefs':
                     $PA->update_upload_preferences();
                     break;
                 case 'del_upload_pref_conf':
                     $PA->delete_upload_preferences_conf();
                     break;
                 case 'del_upload_pref':
                     $PA->delete_upload_preferences();
                     break;
                 default:
                     return FALSE;
                     break;
             }
             break;
         case 'utilities':
             if (!$DSP->allowed_group('can_admin_utilities')) {
                 return $DSP->no_access_message();
             }
             // We handle the pMachine import via a different class,
             // so we'll test for that separately
             if ($IN->GBL('P') == 'pm_import') {
                 require PATH_CP . 'cp.pm_import' . EXT;
                 $PMI = new PM_Import();
                 return;
             }
             if ($IN->GBL('P') == 'mt_import') {
                 require PATH_CP . 'cp.mt_import' . EXT;
                 $MT = new MT_Import();
                 return;
             }
             if ($IN->GBL('P') == 'member_import') {
                 require PATH_CP . 'cp.member_import' . EXT;
                 $MI = new Member_Import();
                 return;
             }
             require PATH_CP . 'cp.utilities' . EXT;
             switch ($IN->GBL('P')) {
                 case 'view_logs':
                     $LOG->view_logs();
                     break;
                 case 'clear_cplogs':
                     $LOG->clear_cp_logs();
                     break;
                 case 'view_search_log':
                     $LOG->view_search_log();
                     break;
                 case 'view_throttle_log':
                     $LOG->view_throttle_log();
                     break;
                 case 'blacklist_ips':
                     $LOG->blacklist_ips();
                     break;
                 case 'clear_search_log':
                     $LOG->clear_search_log();
                     break;
                 case 'clear_cache_form':
                     Utilities::clear_cache_form();
                     break;
                 case 'clear_caching':
                     Utilities::clear_caching();
                     break;
                 case 'run_query':
                     Utilities::sql_manager('run_query');
                     break;
                 case 'sql_query':
                     Utilities::sql_query_form();
                     break;
                     //case 'sql_backup'			: Utilities::sql_backup();
                     //	break;
                     //case 'do_sql_backup'		: Utilities::do_sql_backup();
                     //	break;
                 //case 'sql_backup'			: Utilities::sql_backup();
                 //	break;
                 //case 'do_sql_backup'		: Utilities::do_sql_backup();
                 //	break;
                 case 'view_database':
                     Utilities::view_database();
                     break;
                 case 'table_action':
                     Utilities::run_table_action();
                     break;
                 case 'sandr':
                     Utilities::search_and_replace_form();
                     break;
                 case 'recount_stats':
                     Utilities::recount_statistics();
                     break;
                 case 'recount_prefs':
                     Utilities::recount_preferences_form();
                     break;
                 case 'set_recount_prefs':
                     Utilities::set_recount_prefs();
                     break;
                 case 'do_recount':
                     Utilities::do_recount();
                     break;
                 case 'do_stats_recount':
                     Utilities::do_stats_recount();
                     break;
                 case 'prune':
                     Utilities::data_pruning();
                     break;
                 case 'member_pruning':
                     Utilities::member_pruning();
                     break;
                 case 'prune_member_conf':
                     Utilities::prune_member_confirm();
                     break;
                 case 'prune_members':
                     Utilities::prune_members();
                     break;
                 case 'entry_pruning':
                     Utilities::entry_pruning();
                     break;
                 case 'prune_entry_conf':
                     Utilities::prune_entry_confirm();
                     break;
                 case 'prune_entries':
                     Utilities::prune_entries();
                     break;
                 case 'comment_pruning':
                     Utilities::comment_pruning();
                     break;
                 case 'prune_comment_conf':
                     Utilities::prune_comment_confirmation();
                     break;
                 case 'prune_comments':
                     Utilities::prune_comments();
                     break;
                 case 'trackback_pruning':
                     Utilities::trackback_pruning();
                     break;
                 case 'prune_trackback_conf':
                     Utilities::prune_trackback_confirmation();
                     break;
                 case 'prune_trackbacks':
                     Utilities::prune_trackbacks();
                     break;
                     /* Someday, oh someday...
                     		 case 'pm_pruning'			: Utilities::pm_pruning();
                     			break;
                     		 case 'prune_pm_conf'		: Utilities::prune_pm_confirmation();
                     			break;
                     		 case 'prune_pms'			: Utilities::prune_pms();
                     			break;
                     		 */
                 /* Someday, oh someday...
                 		 case 'pm_pruning'			: Utilities::pm_pruning();
                 			break;
                 		 case 'prune_pm_conf'		: Utilities::prune_pm_confirmation();
                 			break;
                 		 case 'prune_pms'			: Utilities::prune_pms();
                 			break;
                 		 */
                 case 'topic_pruning':
                     Utilities::topic_pruning();
                     break;
                 case 'prune_topic_conf':
                     Utilities::prune_topic_confirmation();
                     break;
                 case 'prune_topics':
                     Utilities::prune_topics();
                     break;
                 case 'run_sandr':
                     Utilities::search_and_replace();
                     break;
                 case 'php_info':
                     Utilities::php_info();
                     break;
                 case 'sql_manager':
                     Utilities::sql_info();
                     break;
                 case 'sql_status':
                     Utilities::sql_manager('status');
                     break;
                 case 'sql_sysvars':
                     Utilities::sql_manager('sysvars');
                     break;
                 case 'sql_plist':
                     Utilities::sql_manager('plist');
                     break;
                 case 'plugin_manager':
                     Utilities::plugin_manager();
                     break;
                 case 'plugin_info':
                     Utilities::plugin_info();
                     break;
                 case 'plugin_remove_conf':
                     Utilities::plugin_remove_confirm();
                     break;
                 case 'plugin_remove':
                     Utilities::plugin_remove();
                     break;
                 case 'plugin_install':
                     Utilities::plugin_install('file');
                     break;
                 case 'import_utilities':
                     Utilities::import_utilities();
                     break;
                 case 'trans_menu':
                     Utilities::translate_select();
                     break;
                 case 'translate':
                     Utilities::translate();
                     break;
                 case 'save_translation':
                     Utilities::save_translation();
                     break;
                 case 'extensions_manager':
                     Utilities::extensions_manager();
                     break;
                 case 'toggle_extension_confirm':
                     Utilities::toggle_extension_confirm();
                     break;
                 case 'toggle_extension':
                     Utilities::toggle_extension();
                     break;
                 case 'extension_settings':
                     Utilities::extension_settings();
                     break;
                 case 'save_extension_settings':
                     Utilities::save_extension_settings();
                     break;
                 default:
                     return FALSE;
                     break;
             }
             break;
         default:
             $this->admin_home_page();
             break;
     }
 }
コード例 #2
0
 /** -----------------------------------
     /**  Update HTML buttons
     /** -----------------------------------*/
 function update_htmlbuttons()
 {
     global $IN, $LANG, $FNS, $DSP;
     if (FALSE === ($id = $this->auth_id())) {
         return $DSP->no_access_message();
     }
     // Is the user authorized to access the publish page?
     // And does the user have at least one blog assigned?
     // If not, show the no access message
     if (!$DSP->allowed_group('can_access_publish') || !count($FNS->fetch_assigned_weblogs()) > 0) {
         return $DSP->no_access_message();
     }
     // validate for unallowed blank values
     if (empty($_POST)) {
         return $DSP->no_access_message();
     }
     require PATH_CP . 'cp.publish_ad' . EXT;
     $PA = new PublishAdmin();
     $title = $LANG->line('html_buttons');
     return $PA->save_html_buttons();
 }
コード例 #3
0
    /**
     * Module Updater
     *
     * @access	public
     * @return	bool
     */
    public function update()
    {
        // --------------------------------------------
        //  ExpressionEngine 2.x attempts to do automatic updates.
        //		- Mitchell questioned clients/customers and discovered
        //		that the majority preferred to update
        //		themselves, especially on higher traffic sites.
        //		So, we forbid EE 2.x from doing updates
        //		unless it comes through our update form.
        // --------------------------------------------
        if (!isset($_POST['run_update']) or $_POST['run_update'] != 'y') {
            return FALSE;
        }
        if ($this->version_compare($this->database_version(TRUE), '==', constant(strtoupper($this->lower_name) . '_VERSION')) and $this->extensions_enabled()) {
            return TRUE;
        }
        if (APP_VER < 2.0 and !$this->extensions_enabled() and !$this->extensions_allowed()) {
            return ee()->output->show_user_error('general', lang('cannot_update_extensions_disabled'));
        }
        // --------------------------------------------
        //  Default Module Update
        // --------------------------------------------
        $this->default_module_update();
        // --------------------------------------------
        //  Do DB work
        // --------------------------------------------
        if (!file_exists($this->addon_path . strtolower($this->lower_name) . '.sql')) {
            return FALSE;
        }
        $sql = preg_split("/;;\\s*(\n+|\$)/", file_get_contents($this->addon_path . strtolower($this->lower_name) . '.sql'), -1, PREG_SPLIT_NO_EMPTY);
        if (count($sql) == 0) {
            return FALSE;
        }
        foreach ($sql as $i => $query) {
            $sql[$i] = trim($query);
        }
        // --------------------------------------------
        //  Database Change
        //  - Added: 1.0.0.a2
        // --------------------------------------------
        if ($this->version_compare($this->database_version(), '<', '1.0.0.a2')) {
            $sql[] = '	ALTER TABLE ' . CALENDAR_TABLE_CALENDARS . '
						ADD COLUMN `tz_offset` CHAR(5) NOT NULL DEFAULT "+0000",
						ADD COLUMN `timezone` VARCHAR(100) NOT NULL DEFAULT "Europe/London",
						ADD COLUMN `time_format` VARCHAR(10) NOT NULL DEFAULT "H:i a"
						';
        }
        // --------------------------------------------
        //  Database Change
        //  - Added: 1.0.0.b2
        // --------------------------------------------
        if ($this->version_compare($this->database_version(), '<', '1.0.0.b2')) {
            // -------------------------------------
            //  Add a new field
            // -------------------------------------
            $query = ee()->db->query('SELECT	group_id
				 FROM	exp_field_groups
				 WHERE	group_name = "' . CALENDAR_CALENDARS_FIELD_GROUP . '"');
            $calendars_field_group = $query->row['group_id'];
            $fields[] = array('site_id' => $this->data->get_site_id(), 'group_id' => $calendars_field_group, 'field_name' => CALENDAR_CALENDARS_FIELD_PREFIX . 'ics_url', 'field_label' => '.ics URL', 'field_instructions' => 'Add one or more URLs to .ics files - separated by newlines - to import to this calendar.', 'field_type' => 'textarea', 'field_list_items' => '', 'field_pre_populate' => 'n', 'field_pre_blog_id' => '0', 'field_pre_field_id' => '0', 'field_related_to' => APP_VER < 2.0 ? 'blog' : 'channel', 'field_related_id' => '0', 'field_related_orderby' => 'date', 'field_related_sort' => 'desc', 'field_related_max' => '0', 'field_ta_rows' => '3', 'field_maxl' => '20', 'field_required' => 'n', 'field_text_direction' => 'ltr', 'field_search' => 'n', 'field_is_hidden' => 'y', 'field_fmt' => 'none', 'field_show_fmt' => 'n', 'field_order' => '');
            // -------------------------------------
            //  Create new fields
            // -------------------------------------
            $PA;
            if (APP_VER < 2.0) {
                if (!class_exists('PublishAdmin')) {
                    require_once PATH_CP . 'cp.publish_ad' . EXT;
                }
                $PA = new PublishAdmin();
            }
            foreach ($fields as $field) {
                $_POST = $field;
                if (APP_VER < 2.0) {
                    $PA->update_weblog_fields();
                } else {
                    $this->update_channel_fields();
                }
            }
            // -------------------------------------
            //  Add a new column
            // -------------------------------------
            $sql[] = '	ALTER TABLE exp_calendar_calendars
						ADD COLUMN ics_url TEXT DEFAULT ""
						';
            // -------------------------------------
            //  Modify a column
            // -------------------------------------
            $sql[] = '	UPDATE exp_calendar_preferences
						SET preferences = "' . ee()->db->escape_str($this->_default_preferences()) . '"
						WHERE preferences = ""
						';
        }
        // --------------------------------------------
        //  Database Change
        //  - Added: 1.0.0.b3
        // --------------------------------------------
        if ($this->version_compare($this->database_version(), '<', '1.0.0.b3')) {
            // -------------------------------------
            // Add a new column
            // -------------------------------------
            $sql[] = '	ALTER TABLE exp_calendar_calendars
						ADD COLUMN ics_updated DATETIME DEFAULT "0000-00-00"
						';
            $sql[] = '	UPDATE exp_calendar_calendars
						SET ics_updated = "0000-00-00"
						WHERE ics_updated IS NULL';
        }
        // --------------------------------------------
        //  Run module SQL - dependent on CREATE TABLE IF NOT EXISTS syntax
        // --------------------------------------------
        foreach ($sql as $query) {
            ee()->db->query($query);
        }
        // --------------------------------------------
        //  Database Change
        //  - Added: 1.0.2.d3
        // --------------------------------------------
        if ($this->version_compare($this->database_version(), '<', '1.0.2.d3')) {
            $asql = '	SELECT cp.*
						FROM exp_calendar_preferences cp';
            $query = ee()->db->query($asql);
            if ($query->num_rows() > 0) {
                foreach ($query->result_array() as $row) {
                    $data = unserialize($row['preferences']);
                    if (!array_key_exists('date_format', $data)) {
                        $data['date_format'] = 'mm/dd/yy';
                    }
                    ee()->db->query(ee()->db->update_string('exp_calendar_preferences', array('preferences' => serialize($data)), 'site_id = ' . ee()->db->escape_str($row['site_id'])));
                }
            }
        }
        // --------------------------------------------
        //  Preferences go wacko before this
        // --------------------------------------------
        if ($this->version_compare($this->database_version(), '<', '1.5.1')) {
            $prefs = $this->data->get_module_preferences(TRUE);
            if (!isset($prefs['calendar_weblog']) or $prefs['calendar_weblog'] === '') {
                $query = ee()->db->query("SELECT {$this->sc->db->channel_id}\n\t\t\t\t\t FROM \t{$this->sc->db->channels}\n\t\t\t\t\t WHERE \t{$this->sc->db->channel_name} = '" . ee()->db->escape_str(CALENDAR_CALENDARS_CHANNEL_NAME_DEFAULT) . "'");
                $prefs['calendar_weblog'] = $query->num_rows() > 0 ? $query->row($this->sc->db->channel_id) : '';
            }
            if (!isset($prefs['event_weblog']) or $prefs['event_weblog'] === '') {
                $query = ee()->db->query("SELECT {$this->sc->db->channel_id}\n\t\t\t\t\t FROM \t{$this->sc->db->channels}\n\t\t\t\t\t WHERE \t{$this->sc->db->channel_name} = '" . ee()->db->escape_str(CALENDAR_EVENTS_CHANNEL_NAME_DEFAULT) . "'");
                $prefs['event_weblog'] = $query->num_rows() > 0 ? $query->row($this->sc->db->channel_id) : '';
            }
            $this->data->update_preferences($prefs);
        }
        //seems that we did not properly set default_entry_title and that causes all heck with
        //liveUrlTitle() in the publish area.
        if ($this->version_compare($this->database_version(), '<', '1.5.2')) {
            $prefs = $this->data->get_module_preferences(TRUE);
            $where = implode(',', ee()->db->escape_str(array($prefs['calendar_weblog'], $prefs['event_weblog'])));
            ee()->db->query("UPDATE {$this->sc->db->channels}\n\t\t\t\t SET \tdefault_entry_title = ''\n\t\t\t\t WHERE \t{$this->sc->db->channel_id}\n\t\t\t\t IN\t\t({$where})");
        }
        //Update the tables to have a default status_group of one
        //the default for the table is 0, and everything _should_
        //work fine, but it seems like this might come to a head
        //at some point, so extra protection.
        if ($this->version_compare($this->database_version(), '<', '1.5.5')) {
            $prefs = $this->data->get_module_preferences(TRUE);
            $where = implode(',', ee()->db->escape_str(array($prefs['calendar_weblog'], $prefs['event_weblog'])));
            ee()->db->query("UPDATE {$this->sc->db->channels}\n\t\t\t\t SET \tstatus_group = 1\n\t\t\t\t WHERE \t{$this->sc->db->channel_id}\n\t\t\t\t IN\t\t({$where})\n\t\t\t\t AND\t( status_group IS NULL OR status_group = 0 )");
        }
        if ($this->version_compare($this->database_version(), '<', '1.6.4')) {
            ee()->db->query("UPDATE exp_extensions\n\t\t\t\t SET \thook = 'calendar_calendars_channel_query'\n\t\t\t\t WHERE \thook = 'calendar_calendars_weblog_query'");
        }
        if ($this->version_compare($this->database_version(), '<', '1.7.0')) {
            if (APP_VER >= 2.0 and ee()->db->table_exists('exp_calendar_permissions_preferences') === FALSE) {
                $newest_prefs = TRUE;
                $module_install_sql = file_get_contents($this->addon_path . strtolower($this->lower_name) . '.sql');
                //gets JUST the tag prefs table from the sql
                $prefs_table = stristr($module_install_sql, "CREATE TABLE IF NOT EXISTS `exp_calendar_permissions_preferences`");
                $prefs_table = substr($prefs_table, 0, stripos($prefs_table, ';;'));
                //install it
                ee()->db->query($prefs_table);
            }
        }
        if ($this->version_compare($this->database_version(), '<', '1.7.1.b1')) {
            $fqiu = ee()->db->where('field_name', CALENDAR_CALENDARS_FIELD_PREFIX . 'ics_url')->where('site_id', $this->data->get_site_id())->limit(1)->get('exp_channel_fields');
            if ($fqiu->num_rows() > 0) {
                ee()->db->query(ee()->db->update_string('exp_channel_fields', array('field_instructions' => $fqiu->row('field_instructions') . ' ' . lang('ics_url_stub')), array('site_id' => $fqiu->row('site_id'), 'field_id' => $fqiu->row('field_id'))));
            }
        }
        // -------------------------------------
        //	Is this going from EE 1.x to EE 2.x?
        // -------------------------------------
        if (APP_VER >= 2.0) {
            // -------------------------------------
            //	If the calendar fieldtype isn't installed
            //	we can assume that this is EE 1.x -> 2.x
            // -------------------------------------
            $ft_query = ee()->db->where('name', 'calendar')->get('exp_fieldtypes');
            if ($ft_query->num_rows() == 0) {
                //install calendar fieldtype
                ee()->load->library('addons/addons_installer');
                ee()->load->model('addons_model');
                if (!ee()->addons_model->fieldtype_installed($this->lower_name)) {
                    ee()->addons_installer->install($this->lower_name, 'fieldtype', FALSE);
                }
                //update field_related_to
                ee()->db->where_in('field_name', array(CALENDAR_CALENDARS_FIELD_PREFIX . 'summary', CALENDAR_CALENDARS_FIELD_PREFIX . 'tz_offset', CALENDAR_CALENDARS_FIELD_PREFIX . 'time_format', CALENDAR_CALENDARS_FIELD_PREFIX . 'ics_url', CALENDAR_EVENTS_FIELD_PREFIX . 'dates_and_options', CALENDAR_EVENTS_FIELD_PREFIX . 'summary', CALENDAR_EVENTS_FIELD_PREFIX . 'location'))->update('exp_channel_fields', array('field_related_to' => 'channel'));
                //update fieldtypes for
                ee()->db->where_in('field_name', array(CALENDAR_CALENDARS_FIELD_PREFIX . 'tz_offset', CALENDAR_EVENTS_FIELD_PREFIX . 'dates_and_options'))->update('exp_channel_fields', array('field_type' => 'calendar'));
            }
        }
        // --------------------------------------------
        //  Version Number Update - LAST!
        // --------------------------------------------
        $data = array('module_version' => CALENDAR_VERSION);
        //for EE 1.x -> 2.x update
        if (APP_VER >= 2.0) {
            $data['has_publish_fields'] = 'n';
        }
        ee()->db->query(ee()->db->update_string('exp_modules', $data, array('module_name' => $this->class_name)));
        return TRUE;
    }
コード例 #4
0
 /** -------------------------------------------
     /**  Import File and Find category info
     /** -------------------------------------------*/
 function perform_import()
 {
     global $DSP, $IN, $FNS, $LANG, $PREFS, $DB;
     global $STAT, $IN, $LOC, $REGX, $SESS;
     /** --------------------------
         /**  MT Import Settings
         /** --------------------------*/
     $file_location = $PREFS->ini('mt_file_location');
     $weblog_selection = $PREFS->ini('mt_weblog_selection');
     $category_selection = $PREFS->ini('mt_category_selection');
     $summary_selection = $PREFS->ini('mt_excerpt_selection');
     $body_selection = $PREFS->ini('mt_body_selection');
     $extended_selection = $PREFS->ini('mt_extended_selection');
     $keywords_selection = $PREFS->ini('mt_keywords_selection');
     $status_default = $PREFS->ini('mt_status_default');
     $use_status = $PREFS->ini('mt_use_status');
     $format_default = $PREFS->ini('mt_format_default');
     $use_format = $PREFS->ini('mt_use_format');
     $member_id = $PREFS->ini('mt_member_id');
     $use_author = $PREFS->ini('mt_use_author');
     $create_comment_members = $PREFS->ini('mt_create_comment_members');
     $member_group_id = $PREFS->ini('mt_member_group_id');
     $members_created = 0;
     /** --------------------------
         /**  Create Categories defaults
         /** --------------------------*/
     $auto_sub = 'n';
     $auto_nosub = 'n';
     if (strpos($category_selection, 'auto_sub') !== false) {
         $auto_sub = 'y';
     } elseif (strpos($category_selection, 'auto_nosub') !== false) {
         $auto_nosub = 'y';
     }
     /** ---------------------------------
     		/**  At Least One Field Must Be Used
     		/** ---------------------------------*/
     $fields = array('summary', 'body', 'extended', 'keywords');
     $set = 'n';
     foreach ($fields as $field) {
         $name = $field . '_selection';
         if (${$name} != '' && ${$name} != 'none') {
             $set = 'y';
         }
     }
     if ($set == 'n') {
         return $this->mt_import_main_page($LANG->line('unable_to_import'));
     }
     /** ---------------------------------
     		/**  Extra Fields
     		/** ---------------------------------*/
     if ($this->extra_fields > 0) {
         $i = 1;
         while (TRUE) {
             // Preference
             $name = 'extra_field_' . $i . '_selection';
             ${$name} = $PREFS->ini('mt_extra_field_' . $i . '_selection');
             // Storage Array for Data
             $name = 'extra_field_' . $i;
             ${$name} = array();
             // Fields List for Processing
             $fields[] = $name;
             $i++;
             if ($i > $this->extra_fields) {
                 break;
             }
         }
     }
     /** -----------------------------
         /**  Valid Member Group Check
         /** -----------------------------*/
     if ($create_comment_members == 'y') {
         if ($SESS->userdata['group_id'] != 1) {
             $sql = "SELECT COUNT(*) AS count \n\t\t\t\t\t\tFROM exp_member_groups \n\t\t\t\t\t\tWHERE is_locked = 'n' \n\t\t\t\t\t\tAND group_id = '{$member_group_id}'\n\t\t\t\t\t\tAND site_id = '" . $DB->escape_str($PREFS->ini('site_id')) . "'\n\t\t\t\t\t\tORDER BY group_title";
             $query = $DB->query($sql);
             if ($query->row['count'] == 0 || $member_group_id == '') {
                 return $this->mt_import_main_page($LANG->line('unable_to_import'));
             }
         }
     }
     /** --------------------------
     		/**  Valid Stati for Weblog
     		/** --------------------------*/
     $query = $DB->query("SELECT status FROM exp_statuses, exp_weblogs\n\t\t\t\t\t\t\t WHERE exp_weblogs.status_group = exp_statuses.group_id\n\t\t\t\t\t\t\t AND exp_weblogs.weblog_id = '{$weblog_selection}'");
     if ($query->num_rows > 0) {
         foreach ($query->result as $row) {
             $this->status_array[] = strtolower($row['status']);
         }
     } else {
         $this->status_array = array('open', 'closed');
     }
     /** ----------------------------
     		/**  Valid Formatting Options
     		/** ----------------------------*/
     if (!class_exists('PublishAdmin')) {
         require PATH_CP . 'cp.publish_ad' . EXT;
     }
     $PA = new PublishAdmin();
     $plugins = $PA->fetch_plugins();
     $LANG->fetch_language_file('publish_ad');
     /** --------------------------------------
         /**  MT IMPORT BEGINS
         /** --------------------------------------*/
     if (!function_exists('file_get_contents')) {
         $lines = file($file_location);
         $data = implode('', $lines);
         unset($lines);
     } else {
         $data = file_get_contents($file_location);
     }
     // All tabs into spaces.
     $data = preg_replace("/(\t)/", ' ', $data);
     // Make all line breaks into one type of identifiable line break marker.
     $LB = '9serLBR3ngti';
     $data = preg_replace("/(\r\n|\n|\r)/", $LB, $data);
     if (strpos($data, $LB . '--------' . $LB) === false) {
         return $this->mt_import_main_page($LANG->line('invalid_file'));
     }
     // Break it up by entries.
     $entries = explode($LB . '--------' . $LB, $data);
     unset($data);
     // Our various data arrays
     $titles = array();
     $dates = array();
     $body = array();
     $extended = array();
     $summary = array();
     $keywords = array();
     $author = array();
     // Author of entry
     $screen_names = array();
     // Screen names used
     $usernames = array();
     // Usernames used
     $ip_addresses = array();
     // IP addresses used
     $no_screen_names = array();
     // Confirmed screen name with no member
     $no_usernames = array();
     // Confirmed username with no member
     $comments = array();
     $trackbacks = array();
     $allow_comments = array();
     $allow_pings = array();
     $convert_breaks = array();
     $status = array();
     $primary_categories = array();
     $categories = array();
     $comment_members = array();
     $comment_members_data = array();
     $comment_members_email = array();
     $id = 0;
     foreach ($entries as $entry) {
         if (trim($entry) == '') {
             continue;
         }
         $sections = explode($LB . "-----" . $LB, $entry);
         unset($entry);
         // We expect at least two sections
         if (!isset($sections['1'])) {
             unset($sections);
             continue;
         }
         /** -----------------------------------
            	/**  Grab entry data and put into arrays 
            	/** -----------------------------------*/
         $first_section = explode($LB, $sections['0']);
         $allow_comments[$id] = 1;
         $allow_pings[$id] = 0;
         $convert_breaks[$id] = $format_default;
         $status[$id] = $status_default;
         $member[$id] = $member_id;
         for ($i = 0; $i < sizeof($first_section); $i++) {
             if (trim($first_section[$i]) == '') {
                 continue;
             }
             $parts = explode(':', $first_section[$i]);
             if (sizeof($parts) < 2) {
                 continue;
             }
             // TITLE
             if (strpos($parts['0'], 'TITLE') !== false) {
                 $titles[$id] = trim(str_replace('TITLE:', '', $first_section[$i]));
             }
             // DATE - keep in format, change later
             if (strpos($parts['0'], 'DATE') !== false) {
                 $dates[$id] = trim(str_replace('DATE:', '', $first_section[$i]));
             }
             // STATUS
             if (strpos($parts['0'], 'STATUS') !== false && $use_status == 'y') {
                 $temp_status = trim(str_replace('STATUS:', '', $first_section[$i]));
                 if ($temp_status == 'Publish') {
                     $status[$id] = 'open';
                 } elseif ($temp_status == 'Draft') {
                     $status[$id] = 'closed';
                 } elseif (in_array(strtolower($temp_status), $this->status_array)) {
                     $which = array_search(strtolower($temp_status), $this->status_array);
                     $status[$id] = $this->status_array[$which];
                 }
             }
             // AUTHOR
             if (strpos($parts['0'], 'AUTHOR') !== false && $use_author == 'y') {
                 $author[$id] = trim(str_replace('AUTHOR:', '', $first_section[$i]));
             }
             // META DATA
             if (strpos($parts['0'], 'ALLOW COMMENTS') !== false) {
                 $allow_comments[$id] = trim(str_replace('ALLOW COMMENTS:', '', $first_section[$i]));
             }
             if (strpos($parts['0'], 'ALLOW PINGS') !== false) {
                 $allow_pings[$id] = trim(str_replace('ALLOW PINGS:', '', $first_section[$i]));
             }
             if (strpos($parts['0'], 'CONVERT BREAKS') !== false && $use_format == 'y') {
                 $temp_format = trim(str_replace('CONVERT BREAKS:', '', $first_section[$i]));
                 if ($temp_format == '1') {
                     $convert_breaks[$id] = 'br';
                 } elseif ($temp_format == '0') {
                     $convert_breaks[$id] = 'none';
                 } elseif ($temp_format == '__default__') {
                     $convert_breaks[$id] = $format_default;
                 } else {
                     foreach ($plugins as $val) {
                         if ($temp_format == $val) {
                             $convert_breaks[$id] = $val;
                             break;
                         }
                         $name = ucwords(str_replace('_', ' ', $val));
                         if ($name == 'Br') {
                             $name = $LANG->line('auto_br');
                         } elseif ($name == 'Xhtml') {
                             $name = $LANG->line('xhtml');
                         }
                         if ($temp_format == $val) {
                             $convert_breaks[$id] = $val;
                             break;
                         }
                     }
                 }
             }
             // PRIMARY CATEGORY
             if (strpos($parts['0'], 'PRIMARY CATEGORY') !== false) {
                 $primary_categories[$id] = trim(str_replace('PRIMARY CATEGORY:', '', $first_section[$i]));
             } elseif (strpos($parts['0'], 'CATEGORY') !== false) {
                 // Catch for people who make primary and category equal to each other.
                 if (isset($primary_categories[$id]) && trim($parts['1']) == $primary_categories[$id]) {
                     continue;
                 }
                 $categories[$id][] = trim(str_replace('CATEGORY:', '', $first_section[$i]));
             }
         }
         // End section 1
         // More MT logic:
         // If no primary category and there is a single category, then category becomes primary category
         if (!isset($primary_categories[$id]) && isset($categories[$id]) && sizeof($categories[$id]) > 0) {
             $primary_categories[$id] = $categories[$id]['0'];
             unset($categories[$id]['0']);
         }
         // Data Check
         if (!isset($dates[$id]) || !isset($titles[$id]) || str_replace($LB, '', trim($titles[$id])) == '' || str_replace($LB, '', trim($dates[$id])) == '') {
             continue;
         }
         // Go through the rest of the sections
         for ($i = 1; $i < sizeof($sections); $i++) {
             // EXTENDED BODY
             preg_match("/EXTENDED BODY:(.*)/", $sections[$i], $meta_info);
             if (isset($meta_info['1'])) {
                 $extended[$id] = trim($meta_info['1']);
                 continue;
             }
             // EXTRA FIELD
             preg_match("/EXTRA FIELD\\-(\\d+?):(.*)/", $sections[$i], $meta_info);
             if (isset($meta_info['2'])) {
                 $name = 'extra_field_' . $meta_info['1'];
                 ${$name}[$id] = trim($meta_info['2']);
                 continue;
             }
             // BODY
             preg_match("/BODY:(.*)/", $sections[$i], $meta_info);
             if (isset($meta_info['1'])) {
                 $body[$id] = trim($meta_info['1']);
                 continue;
             }
             // EXCERPT
             preg_match("/EXCERPT:(.*)/", $sections[$i], $meta_info);
             if (isset($meta_info['1'])) {
                 $summary[$id] = trim($meta_info['1']);
                 continue;
             }
             // KEYWORDS
             preg_match("/KEYWORDS:(.*)/", $sections[$i], $meta_info);
             if (isset($meta_info['1'])) {
                 $keywords[$id] = trim($meta_info['1']);
                 continue;
             }
             // COMMENTS
             preg_match("/COMMENT:(.*)/", $sections[$i], $meta_info);
             if (isset($meta_info['1'])) {
                 if (!isset($c)) {
                     $c = 0;
                 }
                 $cparts = explode($LB, $meta_info['1']);
                 foreach ($cparts as $cpart) {
                     if (strpos($cpart, 'AUTHOR:') !== false) {
                         $comments[$id][$c]['author'] = trim(str_replace('AUTHOR:', '', $cpart));
                         $meta_info['1'] = str_replace($cpart . $LB, '', $meta_info['1']);
                     } elseif (strpos($cpart, 'DATE:') !== false) {
                         $comments[$id][$c]['date'] = trim(str_replace('DATE:', '', $cpart));
                         $meta_info['1'] = str_replace($cpart . $LB, '', $meta_info['1']);
                     } elseif (strpos($cpart, 'EMAIL:') !== false) {
                         $comments[$id][$c]['email'] = trim(str_replace('EMAIL:', '', $cpart));
                         $meta_info['1'] = str_replace($cpart . $LB, '', $meta_info['1']);
                     } elseif (strpos($cpart, 'URL:') !== false) {
                         $comments[$id][$c]['url'] = trim(str_replace('URL:', '', $cpart));
                         $meta_info['1'] = str_replace($cpart . $LB, '', $meta_info['1']);
                     } elseif (strpos($cpart, 'IP:') !== false) {
                         $comments[$id][$c]['ip'] = trim(str_replace('IP:', '', $cpart));
                         $meta_info['1'] = str_replace($cpart . $LB, '', $meta_info['1']);
                     }
                 }
                 // Required
                 if (!isset($comments[$id][$c]['author']) || !isset($comments[$id][$c]['date'])) {
                     unset($comments[$id][$c]);
                     continue;
                 }
                 // Clean up comment body
                 $meta_info['1'] = str_replace('COMMENT:' . $LB, '', $meta_info['1']);
                 while (substr($meta_info['1'], 0, strlen($LB)) == $LB) {
                     $meta_info['1'] = substr($meta_info['1'], strlen($LB));
                 }
                 while (substr($meta_info['1'], -strlen($LB)) == $LB) {
                     $meta_info['1'] = substr($meta_info['1'], 0, -strlen($LB));
                 }
                 /** -------------------------
                 				/**  Store comment body
                 				/** -------------------------*/
                 $comments[$id][$c]['body'] = trim($meta_info['1']);
                 /** ------------------------
                 				/**  Store Comment User
                 				/** ------------------------*/
                 if ($create_comment_members == 'y' && isset($comments[$id][$c]['email'])) {
                     if (!in_array(strtolower($comments[$id][$c]['author']), $comment_members) && !in_array(strtolower($comments[$id][$c]['email']), $comment_members_email)) {
                         $comment_members[] = $comments[$id][$c]['author'];
                         // Unique authors
                         $comment_members_email[] = $comments[$id][$c]['email'];
                         // Unique emails
                         $comment_members_data[] = $comments[$id][$c];
                     }
                 }
                 $c++;
                 // C++, get it? Ha!
                 continue;
             }
             // TRACKBACKS
             preg_match("/PING:(.*)/", $sections[$i], $meta_info);
             if (isset($meta_info['1'])) {
                 if (!isset($t)) {
                     $t = 0;
                 }
                 $tparts = explode($LB, $meta_info['1']);
                 foreach ($tparts as $tpart) {
                     if (strpos($tpart, 'TITLE:') !== false) {
                         $trackbacks[$id][$t]['title'] = trim(str_replace('TITLE:', '', $tpart));
                         $meta_info['1'] = str_replace($tpart, '', $meta_info['1']);
                     } elseif (strpos($tpart, 'DATE:') !== false) {
                         $trackbacks[$id][$t]['date'] = trim(str_replace('DATE:', '', $tpart));
                         $meta_info['1'] = str_replace($tpart, '', $meta_info['1']);
                     } elseif (strpos($tpart, 'URL:') !== false) {
                         $trackbacks[$id][$t]['url'] = trim(str_replace('URL:', '', $tpart));
                         $meta_info['1'] = str_replace($tpart, '', $meta_info['1']);
                     } elseif (strpos($tpart, 'IP:') !== false) {
                         $trackbacks[$id][$t]['ip'] = trim(str_replace('IP:', '', $tpart));
                         $meta_info['1'] = str_replace($tpart, '', $meta_info['1']);
                     } elseif (strpos($tpart, 'BLOG NAME:') !== false) {
                         $trackbacks[$id][$t]['blog_name'] = trim(str_replace('BLOG NAME', '', $tpart));
                         $meta_info['1'] = str_replace($tpart, '', $meta_info['1']);
                     }
                 }
                 // Required fields is four
                 // Only IP is not required.
                 if (sizeof($trackbacks[$id][$t]) < 4 && isset($trackbacks[$id][$t]['ip'])) {
                     unset($trackbacks[$id][$t]);
                     continue;
                 }
                 // Clean up Trackback body
                 $meta_info['1'] = str_replace('PING:' . $LB, '', $meta_info['1']);
                 while (substr($meta_info['1'], 0, strlen($LB)) == $LB) {
                     $meta_info['1'] = substr($meta_info['1'], strlen($LB));
                 }
                 while (substr($meta_info['1'], -strlen($LB)) == $LB) {
                     $meta_info['1'] = substr($meta_info['1'], 0, -strlen($LB));
                 }
                 // Store trackback body
                 $trackbacks[$id][$t]['body'] = trim($meta_info['1']);
                 $t++;
             }
         }
         // End of all sections
         // Data Check
         if (!isset($body[$id]) || str_replace($LB, '', trim($body[$id]) == '')) {
             continue;
         }
         $id++;
         $c = 0;
         $t = 0;
     }
     /** -----------------------------
         /**  Category Creation
         /** -----------------------------*/
     // Find category group for this weblog
     $query = $DB->query("SELECT cat_group, site_id FROM exp_weblogs WHERE weblog_id = '{$weblog_selection}'");
     $weblog_cat_id = $query->row['cat_group'];
     $site_id = $query->row['site_id'];
     if ($auto_sub == 'y' || $auto_nosub == 'y') {
         $cleaned_primary_categories = array_unique($primary_categories);
         $cleaned_categories = array();
         // Find Unique Categories, store via primary category name
         foreach ($categories as $eid => $cat_array) {
             foreach ($cat_array as $cat) {
                 $pim = isset($primary_categories[$eid]) && $primary_categories[$eid] != $cat ? $primary_categories[$eid] : 0;
                 $pim = $IN->clean_input_data($pim);
                 if (!isset($cleaned_categories[$pim])) {
                     $cleaned_categories[$pim][] = $cat;
                     continue;
                 }
                 if (!in_array($cat, $cleaned_categories[$pim])) {
                     $cleaned_categories[$pim][] = $cat;
                 }
             }
         }
         // Category ID Arrays
         $primary_cat_ids = array();
         $regular_cat_ids = array();
         // Check for these primary categories.  If not there, create
         if (sizeof($cleaned_primary_categories) > 0) {
             foreach ($cleaned_primary_categories as $key => $prim) {
                 $name = $IN->clean_input_data($prim);
                 if ($name == '') {
                     continue;
                 }
                 $query = $DB->query("SELECT cat_id\n\t\t\t    \t                   \tFROM exp_categories\n\t\t\t    \t                   \tWHERE exp_categories.cat_name = '" . $DB->escape_str($name) . "'\n\t\t\t    \t                   \tAND exp_categories.site_id = '" . $DB->escape_str($PREFS->ini('site_id')) . "'\n\t\t\t    \t                   \tAND exp_categories.parent_id = '0'\n\t\t\t    \t                   \tAND exp_categories.group_id IN ('" . str_replace('|', "','", $DB->escape_str($weblog_cat_id)) . "')");
                 if ($query->num_rows == 0) {
                     // Create primary category
                     $insert_array = array('group_id' => $weblog_cat_id, 'cat_name' => $name, 'cat_url_title' => $REGX->create_url_title($name, TRUE), 'cat_image' => '', 'parent_id' => '0', 'site_id' => $site_id);
                     $DB->query($DB->insert_string('exp_categories', $insert_array));
                     $primary_cat_ids[$name] = $DB->insert_id;
                     // Create category_field_data
                     $insert_array = array('cat_id' => $primary_cat_ids[$name], 'site_id' => $site_id, 'group_id' => $weblog_cat_id);
                     $DB->query($DB->insert_string('exp_category_field_data', $insert_array));
                 } else {
                     $primary_cat_ids[$name] = $query->row['cat_id'];
                     unset($cleaned_primary_categories[$key]);
                 }
             }
         }
         // End creation of primary categories
         // Check for these categories.  If not there, create.
         if (sizeof($cleaned_categories) > 0) {
             foreach ($cleaned_categories as $parent_name => $cat_array) {
                 if ($parent_name == '' || sizeof($cat_array) == 0) {
                     continue;
                 }
                 $pid = 0;
                 if ($auto_sub == 'y') {
                     $sql = "SELECT cat_id \n\t\t\t\t    \t\t\tFROM exp_categories\n\t\t\t\t    \t\t\tWHERE exp_categories.cat_name = '" . $DB->escape_str($parent_name) . "'\n\t\t\t\t    \t\t\tAND exp_categories.group_id = '{$weblog_cat_id}'\n\t\t\t\t    \t\t\tAND exp_categories.parent_id = '0'\n\t\t\t\t    \t\t\tAND exp_categories.site_id = '" . $DB->escape_str($PREFS->ini('site_id')) . "'";
                     $query = $DB->query($sql);
                     $pid = $query->num_rows > 0 ? $query->row['cat_id'] : '0';
                 }
                 foreach ($cat_array as $cid => $cat) {
                     $cat = $IN->clean_input_data($cat);
                     $query = $DB->query("SELECT cat_id\n\t\t\t    \t\t\t\t\t\t\tFROM exp_categories\n\t\t\t    \t\t\t\t\t\t\tWHERE exp_categories.cat_name = '" . $DB->escape_str($cat) . "'\n\t\t\t    \t\t\t\t\t\t\tAND exp_categories.group_id = '{$weblog_cat_id}'\n\t\t\t    \t\t\t\t\t\t\tAND exp_categories.parent_id = '{$pid}'\n\t\t\t    \t\t\t\t\t\t\tAND exp_categories.site_id = '" . $DB->escape_str($PREFS->ini('site_id')) . "'");
                     if ($query->num_rows == 0) {
                         // Create category
                         $insert_array = array('group_id' => $weblog_cat_id, 'cat_name' => $cat, 'cat_url_title' => $REGX->create_url_title($cat, TRUE), 'cat_image' => '', 'parent_id' => $pid, 'site_id' => $site_id);
                         $sql = $DB->insert_string('exp_categories', $insert_array);
                         $DB->query($sql);
                         $cat_insert_id = $DB->insert_id;
                         $regular_cat_ids[$cat_insert_id] = array($cat, $pid);
                         // Create category_field_data
                         $insert_array = array('cat_id' => $cat_insert_id, 'site_id' => $site_id, 'group_id' => $weblog_cat_id);
                         $DB->query($DB->insert_string('exp_category_field_data', $insert_array));
                     } else {
                         $regular_cat_ids[$query->row['cat_id']] = array($cat, $pid);
                         unset($cleaned_categories[$parent_name][$cid]);
                     }
                 }
             }
         }
     }
     /** ----------------------------
     		/**  Create Comment Memberships
     		/** ----------------------------*/
     if ($create_comment_members == 'y' && sizeof($comment_members_data) > 0) {
         /** -------------------------------------
         			/**  Instantiate validation class
         			/** -------------------------------------*/
         if (!class_exists('Validate')) {
             require PATH_CORE . 'core.validate' . EXT;
         }
         $members_data = array();
         foreach ($comment_members_data as $comment_data) {
             $com_name = !isset($comment_data['author']) ? 'Anonymous' : stripslashes($comment_data['author']);
             $com_email = !isset($comment_data['email']) ? '' : stripslashes($comment_data['email']);
             $com_url = !isset($comment_data['url']) ? '' : stripslashes($comment_data['url']);
             $com_ip = !isset($comment_data['ip']) ? '' : stripslashes($comment_data['ip']);
             $username = preg_replace("/[\\||\\'|\"|\\!]/", '', $com_name);
             $password = $FNS->random('alpha', 5);
             $VAL = new Validate(array('member_id' => '', 'val_type' => 'new', 'fetch_lang' => FALSE, 'require_cpw' => FALSE, 'enable_log' => TRUE, 'username' => $username, 'cur_username' => '', 'screen_name' => $com_name, 'cur_screen_name' => '', 'password' => $password, 'password_confirm' => $password, 'cur_password' => '', 'email' => $com_email, 'cur_email' => ''));
             $VAL->validate_username();
             $VAL->validate_screen_name();
             $VAL->validate_password();
             $VAL->validate_email();
             if (count($VAL->errors) > 0) {
                 continue;
             }
             $data['username'] = $username;
             $data['password'] = $password;
             $data['ip_address'] = $com_ip;
             $data['unique_id'] = $FNS->random('encrypt');
             $data['join_date'] = $LOC->now;
             $data['email'] = $com_email;
             $data['screen_name'] = $com_name;
             $data['url'] = $com_url;
             $data['group_id'] = $member_group_id;
             $DB->query($DB->insert_string('exp_members', $data));
             $new_member_id = $DB->insert_id;
             $members_data[] = "('{$new_member_id}')";
             $members_created++;
             $usernames[$new_member_id] = $username;
             $screen_names[$new_member_id] = $com_name;
             $ip_addresses[$new_member_id] = $com_ip;
         }
         if (sizeof($members_data) > 0) {
             // Create records in the custom field table
             $DB->query("INSERT INTO exp_member_data (member_id) VALUES " . implode(',', $members_data));
             // Create records in the member homepage table
             $DB->query("INSERT INTO exp_member_homepage (member_id) VALUES " . implode(',', $members_data));
         }
         $STAT->update_member_stats();
     }
     // END Comment Memberships
     /** ----------------------------
     		/**  Data Arrays
     		/** ----------------------------*/
     // Get our default member's IP address
     $result = $DB->query("SELECT member_id, ip_address FROM exp_members WHERE member_id = '{$member_id}'");
     $ip_addresses[$member_id] = $result->num_rows == 0 ? '0.0.0.0' : $result->row['ip_address'];
     $total = $id;
     $comments_entered = 0;
     $trackbacks_entered = 0;
     for ($id = 0; $id < $total; $id++) {
         // Function to create MT Export Date format to gmt
         $entry_date = $this->convert_mt_date_to_gmt($dates[$id]);
         $titles[$id] = $PREFS->ini('auto_convert_high_ascii') == 'y' ? $REGX->ascii_to_entities($titles[$id]) : $titles[$id];
         $url_title = $REGX->create_url_title($titles[$id], TRUE);
         $results = $DB->query("SELECT count(*) AS count FROM exp_weblog_titles WHERE url_title = '" . $DB->escape_str($url_title) . "' AND weblog_id = '{$weblog_selection}'");
         // Already have default title
         if ($results->row['count'] > 0) {
             /** ------------------------------------------------
             				/**  Check for multiple instances like default title
             				/** ------------------------------------------------*/
             $results = $DB->query("SELECT count(*) AS count FROM exp_weblog_titles WHERE url_title LIKE '" . $DB->escape_like_str($url_title) . "%' AND weblog_id = '{$weblog_selection}'");
             $url_title .= $results->row['count'] + 1;
         }
         $comments_allowed = $allow_comments[$id] == 1 ? 'y' : 'n';
         $trackbacks_allowed = $allow_pings[$id] == 1 ? 'y' : 'n';
         /** -----------------------------
         			/**  Recent Comment date
         			/** -----------------------------*/
         if (isset($comments[$id]) && sizeof($comments[$id]) > 0) {
             $recent_comment_date = time();
             for ($c = 0; $c < sizeof($comments[$id]); $c++) {
                 $date = $this->convert_mt_date_to_gmt(stripslashes($comments[$id][$c]['date']));
                 if ($date < $recent_comment_date) {
                     $recent_comment_date = $date;
                 }
             }
         } else {
             $recent_comment_date = 0;
         }
         /** --------------------------------
         			/**  Recent Trackback date
         			/** --------------------------------*/
         if (isset($trackbacks[$id]) && sizeof($trackbacks[$id]) > 0) {
             $recent_trackback_date = time();
             for ($t = 0; $t < sizeof($trackbacks[$id]); $t++) {
                 $date = $this->convert_mt_date_to_gmt(stripslashes($trackbacks[$id][$t]['date']));
                 if ($date < $recent_trackback_date) {
                     $recent_trackback_date = $date;
                 }
             }
         } else {
             $recent_trackback_date = 0;
         }
         $comment_total = !isset($comments[$id]) ? 0 : sizeof($comments[$id]);
         $trackback_total = !isset($trackbacks[$id]) ? 0 : sizeof($trackbacks[$id]);
         /** -------------------------------
         			/**  Determine Author?
         			/** -------------------------------*/
         if ($use_author == 'y' && isset($author[$id])) {
             $temp_author = $author[$id];
             $temp_username = preg_replace("/[\\||\\'|\"|\\!]/", '', $temp_author);
             if (in_array($temp_author, $no_screen_names) || in_array($temp_username, $no_usernames)) {
                 // Nothing
                 // Check already done, not found, so it is default
             } elseif (in_array($temp_username, $usernames)) {
                 $which = array_search($temp_author, $usernames);
                 $member[$id] = $which;
             } elseif (in_array($temp_author, $screen_names)) {
                 $which = array_search($temp_author, $screen_names);
                 $member[$id] = $which;
             } else {
                 // Darn! Time for a query
                 $query = $DB->query("SELECT member_id, screen_name, username, ip_address FROM exp_members \n\t\t\t\t\t\t\t\t\t\t WHERE screen_name = '{$temp_author}' OR username = '******'");
                 if ($query->num_rows == 1) {
                     $member[$id] = $query->row['member_id'];
                     $usernames[$query->row['member_id']] = $query->row['username'];
                     $screen_names[$query->row['member_id']] = $query->row['screen_name'];
                     $ip_addresses[$query->row['member_id']] = $query->row['ip_address'];
                 } elseif ($query->num_rows > 1) {
                     foreach ($query->result as $row) {
                         if ($row['username'] == $temp_username) {
                             $member[$id] = $row['member_id'];
                         }
                         $usernames[$row['member_id']] = $row['username'];
                         $screen_names[$row['member_id']] = $row['screen_name'];
                         $ip_addresses[$row['member_id']] = $row['ip_address'];
                     }
                 } else {
                     $no_screen_names[] = $temp_author;
                     $no_usernames[] = $temp_username;
                 }
             }
         }
         if (!isset($ip_addresses[$member[$id]])) {
             $result = $DB->query("SELECT member_id, ip_address FROM exp_members WHERE member_id = '" . $DB->escape_str($member[$id]) . "'");
             $ip_addresses[$member[$id]] = $result->num_rows == 0 ? '0.0.0.0' : $result->row['ip_address'];
         }
         /** -------------------------
            	/**  Weblog Entry's Data
            	/** -------------------------*/
         $data = array('entry_id' => '', 'weblog_id' => $weblog_selection, 'author_id' => $member[$id], 'ip_address' => $ip_addresses[$member[$id]], 'title' => $titles[$id], 'url_title' => $url_title, 'status' => $status[$id], 'allow_comments' => $comments_allowed, 'allow_trackbacks' => $trackbacks_allowed, 'entry_date' => $entry_date, 'year' => date("Y", $entry_date), 'month' => date("m", $entry_date), 'day' => date("d", $entry_date), 'expiration_date' => 0, 'recent_comment_date' => $recent_comment_date, 'recent_trackback_date' => $recent_trackback_date, 'comment_total' => $comment_total, 'trackback_total' => $trackback_total, 'site_id' => $site_id);
         $DB->query($DB->insert_string('exp_weblog_titles', $data));
         $entry_id = $DB->insert_id;
         /** ------------------------------------
         			/**  Insert the custom field data
         			/** ------------------------------------*/
         $cust_fields = array('entry_id' => $entry_id, 'weblog_id' => $weblog_selection, 'site_id' => $site_id);
         // $summary_selection, $body_selection, $extended_selection, $keywords_selection
         foreach ($fields as $field) {
             $name = $field . '_selection';
             if (${$name} != '' && ${$name} != 'none' && isset(${$field}[$id])) {
                 $field_data = trim(str_replace($LB, "\n", ${$field}[$id]));
                 $key = 'field_id_' . ${$name};
                 // Make sure the field data was not just some line breaks
                 if (strlen($field_data) > 0) {
                     $field_data = $PREFS->ini('auto_convert_high_ascii') == 'y' ? $REGX->ascii_to_entities($field_data) : $field_data;
                     $cust_fields[$key] = !isset($cust_fields[$key]) ? $field_data : $cust_fields[$key] . "\n" . $field_data;
                     $key2 = str_replace('field_id_', 'field_ft_', $key);
                     $cust_fields[$key2] = $convert_breaks[$id];
                 }
                 unset(${$field}[$id]);
                 unset($field_data);
             }
         }
         $DB->query($DB->insert_string('exp_weblog_data', $cust_fields));
         unset($cust_fields);
         if ($auto_sub == 'y' || $auto_nosub == 'y') {
             /** --------------------------------
             				/**  Insert primary categories
             				/** --------------------------------*/
             if (isset($primary_categories[$id])) {
                 if (isset($primary_cat_ids[$primary_categories[$id]])) {
                     $parent_id = $primary_cat_ids[$primary_categories[$id]];
                     $DB->query("INSERT INTO exp_category_posts (entry_id, cat_id) VALUES ('{$entry_id}', '{$parent_id}')");
                 }
             }
             /** ------------------------------
             				/**  Insert categories
             				/** ------------------------------*/
             if (isset($categories[$id]) && sizeof($categories[$id]) > 0) {
                 $cats_insert = '';
                 foreach ($categories[$id] as $cat) {
                     $parent_id = !isset($parent_id) ? '0' : $parent_id;
                     foreach ($regular_cat_ids as $cat_id => $cat_id_array) {
                         if (is_array($cat_id_array) && $cat_id_array['0'] == $cat) {
                             if (isset($cat_id_array['1']) && ($parent_id == $cat_id_array['1'] || $auto_nosub == 'y' && $cat_id_array['1'] == '0')) {
                                 $cats_insert .= "('{$entry_id}', '{$cat_id}'),";
                             }
                         }
                     }
                 }
                 if ($cats_insert != '') {
                     $DB->query("INSERT INTO exp_category_posts (entry_id, cat_id) VALUES " . substr($cats_insert, 0, -1));
                 }
             }
         }
         /** --------------------------------------------
         			/**  Additional Selected Categories for Entries
         			/** --------------------------------------------*/
         // Note, these are possible, even if a user has chosen to
         // auto create categories for the imported entries.
         // This way an admin can have the categories inserted for these
         // entries and still assign them to a new EE category or two
         if ($category_selection != '' && $category_selection != 'none') {
             $cat_inserts = explode('|', $category_selection);
             if (sizeof($cat_inserts) > 0) {
                 $vsql = '';
                 foreach ($cat_inserts as $cat_insert) {
                     if ($cat_insert != '' && is_numeric($cat_insert)) {
                         $vsql .= "('{$entry_id}', '" . $DB->escape_str($cat_insert) . "'),";
                     }
                 }
                 if (strlen($vsql) > 0) {
                     $DB->query("INSERT INTO exp_category_posts (entry_id, cat_id) VALUES " . substr($vsql, 0, -1));
                 }
             }
         }
         /** ---------------------------------
         			/**  Insert the comment data
         			/** -------------------------------*/
         if (isset($comments[$id]) && sizeof($comments[$id]) > 0) {
             // $comments[$id][$c]['body'], ['ip'], ['author'], ['url'], ['email'], ['date']
             $comments_insert = '';
             for ($c = 0; $c < sizeof($comments[$id]); $c++) {
                 $com_name = !isset($comments[$id][$c]['author']) ? 'Anonymous' : stripslashes($comments[$id][$c]['author']);
                 $com_email = !isset($comments[$id][$c]['email']) ? '' : stripslashes($comments[$id][$c]['email']);
                 $com_url = !isset($comments[$id][$c]['url']) ? '' : stripslashes($comments[$id][$c]['url']);
                 $com_ip = !isset($comments[$id][$c]['ip']) ? '' : stripslashes($comments[$id][$c]['ip']);
                 $com_body = str_replace($LB, "\n", stripslashes($comments[$id][$c]['body']));
                 $com_date = $this->convert_mt_date_to_gmt($comments[$id][$c]['date']);
                 $com_username = preg_replace("/[\\||\\'|\"|\\!]/", '', $com_name);
                 if (in_array($com_username, $usernames)) {
                     $author_id = array_search($com_username, $usernames);
                 } elseif (in_array($com_name, $screen_names)) {
                     $author_id = array_search($com_name, $screen_names);
                 } else {
                     $author_id = 0;
                 }
                 $data = array('weblog_id' => $weblog_selection, 'entry_id' => $entry_id, 'author_id' => $author_id, 'name' => $com_name, 'email' => $com_email, 'url' => $com_url, 'location' => '', 'comment' => $com_body, 'comment_date' => $com_date, 'ip_address' => $com_ip, 'notify' => 'n', 'site_id' => $site_id);
                 $DB->query($DB->insert_string('exp_comments', $data));
                 $comments_entered++;
             }
         }
         /** ---------------------------------
         			/**  Insert the trackback data
         			/** ---------------------------------*/
         if (isset($trackbacks[$id]) && sizeof($trackbacks[$id]) > 0) {
             // $trackbacks[$id][$t]['title'], ['date'], ['url'], ['ip'],['blog_name'], ['body']
             for ($t = 0; $t < sizeof($trackbacks[$id]); $t++) {
                 $ping_title = stripslashes($trackbacks[$id][$t]['title']);
                 $blog_name = stripslashes($trackbacks[$id][$t]['blog_name']);
                 $ping_url = stripslashes($trackbacks[$id][$t]['url']);
                 $ping_ip = !isset($trackbacks[$id][$t]['ip']) ? '' : stripslashes($trackbacks[$id][$t]['ip']);
                 $ping_body = str_replace($LB, "\n", stripslashes($trackbacks[$id][$t]['body']));
                 $ping_date = $this->convert_mt_date_to_gmt($trackbacks[$id][$t]['date']);
                 $data = array('weblog_id' => $weblog_selection, 'entry_id' => $entry_id, 'title' => $ping_title, 'content' => $ping_body, 'weblog_name' => $blog_name, 'trackback_url' => $ping_url, 'trackback_date' => $ping_date, 'trackback_ip' => $ping_ip, 'site_id' => $site_id);
                 $DB->query($DB->insert_string('exp_trackbacks', $data));
                 $trackbacks_entered++;
             }
         }
     }
     // END of importing entries
     /** --------------------------
     		/**  OPTIMIZE
     		/** --------------------------*/
     $DB->query("OPTIMIZE TABLE exp_comments");
     $DB->query("OPTIMIZE TABLE exp_members");
     $DB->query("OPTIMIZE TABLE exp_trackbacks");
     $DB->query("OPTIMIZE TABLE exp_weblogs");
     $DB->query("OPTIMIZE TABLE exp_weblog_titles");
     $DB->query("OPTIMIZE TABLE exp_weblog_data");
     /** --------------------------
     		/**  Clear out config.php
     		/** --------------------------*/
     $this->clear_config_prefs();
     /** ---------------------------
     		/**  Display Success Message
     		/** ---------------------------*/
     if ($auto_sub == 'y' || $auto_nosub == 'y') {
         $cats = 0;
         foreach ($cleaned_categories as $parent_name => $cats_array) {
             $cats = $cats + sizeof($cats_array);
         }
         $categories_entered = sizeof($cleaned_primary_categories) + $cats;
     }
     $DSP->title = $LANG->line('mt_import_utility');
     $DSP->crumb = $DSP->anchor(BASE . AMP . 'C=admin' . AMP . 'M=utilities' . AMP . 'P=mt_import', $LANG->line('mt_import_utility')) . $DSP->crumb_item($LANG->line('import_complete'));
     $r = $DSP->qdiv('tableHeading', $LANG->line('import_complete'));
     $r .= $DSP->div('box');
     $r .= $DSP->qdiv('success', $LANG->line('you_are_done_importing'));
     $r .= $DSP->qdiv('itemWrapper', $LANG->line('total_weblog_entries') . NBS . $id);
     $r .= $DSP->qdiv('itemWrapper', $LANG->line('total_weblog_comments') . NBS . $comments_entered);
     $r .= $DSP->qdiv('itemWrapper', $LANG->line('total_weblog_trackbacks') . NBS . $trackbacks_entered);
     if (isset($categories_entered) && $categories_entered > 0) {
         $r .= $DSP->qdiv('itemWrapper', $LANG->line('total_categories_entered') . NBS . $categories_entered);
     }
     if ($members_created > 0) {
         $r .= $DSP->qdiv('itemWrapper', $LANG->line('members_created') . NBS . $members_created);
     }
     $r .= $DSP->qdiv('itemWrapper', BR . $DSP->qdiv('highlight', $LANG->line('more_importing_info')));
     $r .= $DSP->qdiv('itemWrapper', $DSP->anchor(BASE . AMP . 'C=admin' . AMP . 'M=utilities' . AMP . 'P=mt_import', $LANG->line('return_to_import')));
     $r .= $DSP->heading($LANG->line('recalculate_statistics'), 2);
     $r .= $DSP->qdiv('itemWrapper', $DSP->anchor(BASE . AMP . 'C=admin' . AMP . 'M=utilities' . AMP . 'P=recount_stats', $LANG->line('click_to_reset_statistics')));
     $r .= $DSP->div_c();
     $DSP->body = $r;
 }