예제 #1
0
 } else {
     wp_slimstat::$options['can_view'] = '';
 }
 if (!empty($_POST['options']['capability_can_view'])) {
     if (isset($GLOBALS['wp_roles']->role_objects['administrator']->capabilities) && array_key_exists($_POST['options']['capability_can_view'], $GLOBALS['wp_roles']->role_objects['administrator']->capabilities)) {
         wp_slimstat::$options['capability_can_view'] = $_POST['options']['capability_can_view'];
     } else {
         wp_slimstat_admin::$faulty_fields[] = __('Invalid minimum capability. Please check <a href="http://codex.wordpress.org/Roles_and_Capabilities" target="_new">this page</a> for more information', 'wp-slimstat');
     }
 } else {
     wp_slimstat::$options['capability_can_view'] = '';
 }
 if (!empty($_POST['options']['can_admin'])) {
     // Make sure all the users exist in the system
     $post_data = trim($_POST['options']['can_admin']);
     $user_array = wp_slimstat::string_to_array($_POST['options']['can_admin']);
     if (is_array($user_array) && !empty($post_data)) {
         $sql_user_placeholders = implode(', ', array_fill(0, count($user_array), '%s COLLATE utf8_bin'));
         if ($GLOBALS['wpdb']->get_var($GLOBALS['wpdb']->prepare("SELECT COUNT(*) FROM {$GLOBALS['wpdb']->users} WHERE user_login IN ({$sql_user_placeholders})", $user_array)) == count($user_array)) {
             wp_slimstat::$options['can_admin'] = $_POST['options']['can_admin'];
         } else {
             wp_slimstat_admin::$faulty_fields[] = __('Config access: username not found', 'wp-slimstat');
         }
     }
 } else {
     wp_slimstat::$options['can_admin'] = '';
 }
 if (!empty($_POST['options']['capability_can_admin'])) {
     if (isset($GLOBALS['wp_roles']->role_objects['administrator']->capabilities) && array_key_exists($_POST['options']['capability_can_admin'], $GLOBALS['wp_roles']->role_objects['administrator']->capabilities)) {
         wp_slimstat::$options['capability_can_admin'] = $_POST['options']['capability_can_admin'];
     } else {
 /**
  * Updates the DB schema as needed
  */
 public static function update_tables_and_options()
 {
     $my_wpdb = apply_filters('slimstat_custom_wpdb', $GLOBALS['wpdb']);
     // --- Updates for version 3.8.4 ---
     if (version_compare(wp_slimstat::$options['version'], '3.8.4', '<')) {
         $my_wpdb->query("CREATE TABLE {$GLOBALS['wpdb']->prefix}slim_stats_archive LIKE {$GLOBALS['wpdb']->prefix}slim_stats");
     }
     // --- END: Updates for version 3.8.4 ---
     // --- Updates for version 3.9.6 ---
     if (version_compare(wp_slimstat::$options['version'], '3.9.6', '<')) {
         // Consolidate some settings
         $classes = wp_slimstat::string_to_array(wp_slimstat::$options['ignore_outbound_classes']);
         $rel = wp_slimstat::string_to_array(wp_slimstat::$options['ignore_outbound_rel']);
         $href = wp_slimstat::string_to_array(wp_slimstat::$options['ignore_outbound_href']);
         wp_slimstat::$options['ignore_outbound_classes_rel_href'] = implode(',', array_merge($classes, $rel, $href));
         $classes = wp_slimstat::string_to_array(wp_slimstat::$options['do_not_track_outbound_classes']);
         $rel = wp_slimstat::string_to_array(wp_slimstat::$options['do_not_track_outbound_rel']);
         $href = wp_slimstat::string_to_array(wp_slimstat::$options['do_not_track_outbound_href']);
         wp_slimstat::$options['do_not_track_outbound_classes_rel_href'] = implode(',', array_merge($classes, $rel, $href));
         // More secure secret key
         wp_slimstat::$options['secret'] = wp_hash(uniqid(time(), true));
     }
     // --- END: Updates for version 3.9.6 ---
     // --- Updates for version 3.9.8.2 ---
     if (version_compare(wp_slimstat::$options['version'], '3.9.8.2', '<')) {
         // The GeoLite DB is already installed, let's unzip it to improve the tracker's performance
         if (file_exists(wp_slimstat::$maxmind_path . '.gz')) {
             @unlink(wp_slimstat::$maxmind_path . '.gz');
             wp_slimstat::download_maxmind_database();
         }
     }
     // --- END: Updates for version 3.9.8.2 ---
     // --- Updates for version 4.0 ---
     if (version_compare(wp_slimstat::$options['version'], '4.0', '<')) {
         $GLOBALS['wpdb']->query("DELETE FROM {$GLOBALS['wpdb']->prefix}usermeta WHERE meta_key LIKE 'meta-box-order_slimstat%'");
         $have_innodb = $GLOBALS['wpdb']->get_results("SHOW VARIABLES LIKE 'have_innodb'", ARRAY_A);
         $use_innodb = !empty($have_innodb[0]) && $have_innodb[0]['Value'] == 'YES' ? 'ENGINE=InnoDB' : '';
         // Create the new table
         self::_create_table("\n\t\t\t\tCREATE TABLE IF NOT EXISTS {$GLOBALS['wpdb']->prefix}slim_stats_4 (\n\t\t\t\t\tid INT UNSIGNED NOT NULL auto_increment,\n\t\t\t\t\tip INT UNSIGNED DEFAULT 0,\n\t\t\t\t\tother_ip INT UNSIGNED DEFAULT 0,\n\t\t\t\t\tusername VARCHAR(255) DEFAULT NULL,\n\t\t\t\t\tcountry VARCHAR(16) DEFAULT NULL,\n\t\t\t\t\treferer VARCHAR(2048) DEFAULT NULL,\n\t\t\t\t\tresource VARCHAR(2048) DEFAULT NULL,\n\t\t\t\t\tsearchterms VARCHAR(2048) DEFAULT NULL,\n\t\t\t\t\tplugins VARCHAR(255) DEFAULT NULL,\n\t\t\t\t\tnotes VARCHAR(2048) DEFAULT NULL,\n\t\t\t\t\tvisit_id INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t\tserver_latency INT(10) UNSIGNED DEFAULT 0,\n\t\t\t\t\tpage_performance INT(10) UNSIGNED DEFAULT 0,\n\n\t\t\t\t\tbrowser VARCHAR(40) DEFAULT NULL,\n\t\t\t\t\tbrowser_version VARCHAR(15) DEFAULT NULL,\n\t\t\t\t\tbrowser_type TINYINT UNSIGNED DEFAULT 0,\n\t\t\t\t\tplatform VARCHAR(15) DEFAULT NULL,\n\t\t\t\t\tlanguage VARCHAR(5) DEFAULT NULL,\n\t\t\t\t\tuser_agent VARCHAR(2048) DEFAULT NULL,\n\n\t\t\t\t\tresolution VARCHAR(12) DEFAULT NULL,\n\t\t\t\t\tscreen_width SMALLINT UNSIGNED DEFAULT 0,\n\t\t\t\t\tscreen_height SMALLINT UNSIGNED DEFAULT 0,\n\n\t\t\t\t\tcontent_type VARCHAR(64) DEFAULT NULL,\n\t\t\t\t\tcategory VARCHAR(256) DEFAULT NULL,\n\t\t\t\t\tauthor VARCHAR(64) DEFAULT NULL,\n\t\t\t\t\tcontent_id BIGINT(20) UNSIGNED DEFAULT 0,\n\t\t\t\t\t\n\t\t\t\t\toutbound_resource VARCHAR(2048) DEFAULT NULL,\n\n\t\t\t\t\tdt INT(10) UNSIGNED DEFAULT 0,\n\t\t\t\t\tCONSTRAINT PRIMARY KEY (id),\n\t\t\t\t\tINDEX idx_{$GLOBALS['wpdb']->prefix}slim_stats_dt (dt)\n\t\t\t\t) COLLATE utf8_general_ci {$use_innodb}", $GLOBALS['wpdb']->prefix . 'slim_stats_4', $my_wpdb);
         // Create the archive table
         $my_wpdb->query("CREATE TABLE IF NOT EXISTS {$GLOBALS['wpdb']->prefix}slim_stats_archive_4 LIKE {$GLOBALS['wpdb']->prefix}slim_stats_4");
         // Rename old and new tables
         $my_wpdb->query("RENAME TABLE {$GLOBALS['wpdb']->prefix}slim_stats TO {$GLOBALS['wpdb']->prefix}slim_stats_3");
         $my_wpdb->query("RENAME TABLE {$GLOBALS['wpdb']->prefix}slim_stats_4 TO {$GLOBALS['wpdb']->prefix}slim_stats");
         $my_wpdb->query("RENAME TABLE {$GLOBALS['wpdb']->prefix}slim_stats_archive TO {$GLOBALS['wpdb']->prefix}slim_stats_archive_3");
         $my_wpdb->query("RENAME TABLE {$GLOBALS['wpdb']->prefix}slim_stats_archive_4 TO {$GLOBALS['wpdb']->prefix}slim_stats_archive");
         // Create the new events table
         $my_wpdb->query("\n\t\t\t\tCREATE TABLE IF NOT EXISTS {$GLOBALS['wpdb']->prefix}slim_events (\n\t\t\t\t\tevent_id INT(10) NOT NULL AUTO_INCREMENT,\n\t\t\t\t\ttype TINYINT UNSIGNED DEFAULT 0,\n\t\t\t\t\tevent_description VARCHAR(64) DEFAULT NULL,\n\t\t\t\t\tnotes VARCHAR(256) DEFAULT NULL,\n\t\t\t\t\tposition VARCHAR(32) DEFAULT NULL,\n\t\t\t\t\tid INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t\tdt INT(10) UNSIGNED DEFAULT 0,\n\t\t\t\t\t\n\t\t\t\t\tCONSTRAINT PRIMARY KEY (event_id),\n\t\t\t\t\tINDEX idx_{$GLOBALS['wpdb']->prefix}slim_events (dt),\n\t\t\t\t\tCONSTRAINT fk_{$GLOBALS['wpdb']->prefix}id FOREIGN KEY (id) REFERENCES {$GLOBALS['wpdb']->prefix}slim_stats(id) ON UPDATE CASCADE ON DELETE CASCADE\n\t\t\t\t) COLLATE utf8_general_ci {$use_innodb}");
         // Copy the data if less than 750k records
         $count_records = $my_wpdb->get_var("SELECT COUNT(*) FROM {$GLOBALS['wpdb']->prefix}slim_stats");
         if ($count_records <= 750000) {
             $my_wpdb->query("\n\t\t\t\t\tINSERT INTO {$GLOBALS['wpdb']->prefix}slim_stats (\n\t\t\t\t\t\tid,\n\t\t\t\t\t\tip,\n\t\t\t\t\t\tother_ip,\n\t\t\t\t\t\tusername,\n\t\t\t\t\t\tcountry,\n\t\t\t\t\t\treferer,\n\t\t\t\t\t\tresource,\n\t\t\t\t\t\tsearchterms,\n\t\t\t\t\t\tplugins,\n\t\t\t\t\t\tnotes,\n\t\t\t\t\t\tvisit_id,\n\t\t\t\t\t\tserver_latency,\n\t\t\t\t\t\tpage_performance,\n\n\t\t\t\t\t\tbrowser,\n\t\t\t\t\t\tbrowser_version,\n\t\t\t\t\t\tbrowser_type,\n\t\t\t\t\t\tplatform,\n\t\t\t\t\t\tlanguage,\n\t\t\t\t\t\tuser_agent,\n\n\t\t\t\t\t\tscreen_width,\n\t\t\t\t\t\tscreen_height,\n\n\t\t\t\t\t\tcontent_type,\n\t\t\t\t\t\tcategory,\n\t\t\t\t\t\tauthor,\n\t\t\t\t\t\tcontent_id,\n\n\t\t\t\t\t\toutbound_resource,\n\n\t\t\t\t\t\tdt\n\t\t\t\t\t)\n\t\t\t\t\tSELECT \n\t\t\t\t\t\tt1.id,\n\t\t\t\t\t\tt1.ip,\n\t\t\t\t\t\tt1.other_ip,\n\t\t\t\t\t\tNULLIF(t1.user, ''),\n\t\t\t\t\t\tNULLIF(t1.country, ''),\n\t\t\t\t\t\tNULLIF(t1.referer, ''),\n\t\t\t\t\t\tNULLIF(t1.resource, ''),\n\t\t\t\t\t\tNULLIF(t1.searchterms, ''),\n\t\t\t\t\t\tNULLIF(t1.plugins, ''),\n\t\t\t\t\t\tNULLIF(t1.notes, ''),\n\t\t\t\t\t\tt1.visit_id,\n\t\t\t\t\t\tt1.server_latency,\n\t\t\t\t\t\tt1.page_performance,\n\n\t\t\t\t\t\tNULLIF(tb.browser, ''),\n\t\t\t\t\t\tNULLIF(tb.version, ''),\n\t\t\t\t\t\ttb.type,\n\t\t\t\t\t\tNULLIF(tb.platform, ''),\n\t\t\t\t\t\tNULLIF(t1.language, ''),\n\t\t\t\t\t\tNULLIF(tb.user_agent, ''),\n\n\t\t\t\t\t\t9812,\n\t\t\t\t\t\t9812,\n\n\t\t\t\t\t\tNULLIF(tci.content_type, ''),\n\t\t\t\t\t\tNULLIF(tci.category, ''),\n\t\t\t\t\t\tNULLIF(tci.author, ''),\n\t\t\t\t\t\ttci.content_id,\n\n\t\t\t\t\t\tNULL,\n\n\t\t\t\t\t\tt1.dt\n\n\t\t\t\t\tFROM {$GLOBALS['wpdb']->prefix}slim_stats_3 AS t1\n\t\t\t\t\tINNER JOIN {$GLOBALS['wpdb']->base_prefix}slim_browsers AS tb ON t1.browser_id = tb.browser_id\n\t\t\t\t\tINNER JOIN {$GLOBALS['wpdb']->base_prefix}slim_content_info AS tci ON t1.content_info_id = tci.content_info_id");
             // Copy the events
             $my_wpdb->query("\n\t\t\t\t\tINSERT INTO {$GLOBALS['wpdb']->prefix}slim_events (\n\t\t\t\t\t\ttype,\n\t\t\t\t\t\tevent_description,\n\t\t\t\t\t\tnotes,\n\t\t\t\t\t\tposition,\n\t\t\t\t\t\tid,\n\t\t\t\t\t\tdt\n\t\t\t\t\t)\n\t\t\t\t\tSELECT\n\t\t\t\t\t\ttob.type,\n\t\t\t\t\t\tSUBSTRING(tob.notes, LOCATE('Event:', tob.notes)+6, LOCATE(',', tob.notes, LOCATE('Event:', tob.notes)+6) - LOCATE('Event:', tob.notes)-6),\n\t\t\t\t\t\tSUBSTRING(tob.notes, 1, LOCATE('Event:', tob.notes) - 3),\n\t\t\t\t\t\ttob.position,\n\t\t\t\t\t\ttob.id,\n\t\t\t\t\t\ttob.dt\n\t\t\t\t\tFROM {$GLOBALS['wpdb']->prefix}slim_outbound AS tob");
         }
     }
     // --- END: Updates for version 4.0 ---
     // Now we can update the version stored in the database
     wp_slimstat::$options['version'] = wp_slimstat::$version;
     return true;
 }
예제 #3
0
 public static function slimstat_shortcode($_attributes = '', $_content = '')
 {
     extract(shortcode_atts(array('f' => '', 'w' => '', 's' => ' ', 'o' => 0), $_attributes));
     $output = $where = '';
     $s = "<span class='slimstat-item-separator'>{$s}</span>";
     // Load the database library
     include_once dirname(__FILE__) . '/admin/view/wp-slimstat-db.php';
     // Load the localization files (for languages, operating systems, etc)
     load_plugin_textdomain('wp-slimstat', WP_PLUGIN_DIR . '/wp-slimstat/admin/lang', '/wp-slimstat/admin/lang');
     // Look for required fields
     if (empty($f) || empty($w)) {
         return '<!-- Slimstat Shortcode Error: missing parameter -->';
     }
     if (strpos($_content, 'WHERE:') !== false) {
         $where = html_entity_decode(str_replace('WHERE:', '', $_content), ENT_QUOTES, 'UTF-8');
         wp_slimstat_db::init();
     } else {
         wp_slimstat_db::init(html_entity_decode($_content, ENT_QUOTES, 'UTF-8'));
     }
     switch ($f) {
         case 'count':
         case 'count-all':
             $output = wp_slimstat_db::count_records($w, $where, strpos($f, 'all') === false) + $o;
             break;
         case 'recent':
         case 'recent-all':
         case 'top':
         case 'top-all':
             $function = 'get_' . str_replace('-all', '', $f);
             if ($w == '*') {
                 $w = 'id';
             }
             $w = wp_slimstat::string_to_array($w);
             // Some columns are 'special' and need be removed from the list
             $w_clean = array_diff($w, array('count', 'hostname', 'post_link', 'dt'));
             // The special value 'post_list' requires the permalink to be generated
             if (in_array('post_link', $w)) {
                 $w_clean[] = 'resource';
             }
             // Retrieve the data
             $results = wp_slimstat_db::$function(implode(', ', $w_clean), $where, '', strpos($f, 'all') === false);
             // No data? No problem!
             if (empty($results)) {
                 return '<!--  Slimstat Shortcode: No Data -->';
             }
             // Are nice permalinks enabled?
             $permalinks_enabled = get_option('permalink_structure');
             // Format results
             $output = array();
             foreach ($results as $result_idx => $a_result) {
                 foreach ($w as $a_column) {
                     $output[$result_idx][$a_column] = "<span class='col-{$a_column}'>";
                     if ($permalinks_enabled) {
                         $a_result['resource'] = strtok($a_result['resource'], '?');
                     }
                     switch ($a_column) {
                         case 'post_link':
                             $post_id = url_to_postid($a_result['resource']);
                             if ($post_id > 0) {
                                 $output[$result_idx][$a_column] .= "<a href='{$a_result['resource']}'>" . get_the_title($post_id) . '</a>';
                             } else {
                                 $output[$result_idx][$a_column] .= $a_result['resource'];
                             }
                             break;
                         case 'dt':
                             $output[$result_idx][$a_column] .= date_i18n(wp_slimstat::$options['date_format'] . ' ' . wp_slimstat::$options['time_format'], $a_result['dt']);
                             break;
                         case 'hostname':
                             $output[$result_idx][$a_column] .= gethostbyaddr($a_result['ip']);
                             break;
                         case 'count':
                             $output[$result_idx][$a_column] .= $a_result['counthits'];
                             break;
                         case 'language':
                             $output[$result_idx][$a_column] .= __('l-' . $a_result[$a_column], 'wp-slimstat');
                             break;
                         case 'platform':
                             $output[$result_idx][$a_column] .= __($a_result[$a_column], 'wp-slimstat');
                         default:
                             $output[$result_idx][$a_column] .= $a_result[$a_column];
                             break;
                     }
                     $output[$result_idx][$a_column] .= '</span>';
                 }
                 $output[$result_idx] = '<li>' . implode($s, $output[$result_idx]) . '</li>';
             }
             $output = '<ul class="slimstat-shortcode ' . $f . implode('-', $w) . '">' . implode('', $output) . '</ul>';
             break;
         default:
             break;
     }
     return $output;
 }