Version Description
Download this release
Release Info
Developer | Ajay |
Plugin | Top 10 – Popular posts plugin for WordPress |
Version | 1.0 |
Comparing to | |
See all releases |
Version 1.0
- admin.inc.php +131 -0
- readme.txt +52 -0
- top-10-counter.js.php +33 -0
- top-10.php +220 -0
- top-10_ajax.php +34 -0
- uninstall.php +12 -0
admin.inc.php
ADDED
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**********************************************************************
|
3 |
+
* Admin Page *
|
4 |
+
*********************************************************************/
|
5 |
+
function tptn_options() {
|
6 |
+
|
7 |
+
global $wpdb;
|
8 |
+
$poststable = $wpdb->posts;
|
9 |
+
|
10 |
+
$tptn_settings = tptn_read_options();
|
11 |
+
|
12 |
+
if($_POST['tptn_save']){
|
13 |
+
$tptn_settings[title] = ($_POST['title']);
|
14 |
+
$tptn_settings[limit] = ($_POST['limit']);
|
15 |
+
$tptn_settings[before_count] = ($_POST['before_count']);
|
16 |
+
$tptn_settings[after_count] = ($_POST['after_count']);
|
17 |
+
$tptn_settings[add_to_content] = (($_POST['add_to_content']) ? true : false);
|
18 |
+
$tptn_settings[show_credit] = (($_POST['show_credit']) ? true : false);
|
19 |
+
|
20 |
+
update_option('ald_tptn_settings', $tptn_settings);
|
21 |
+
|
22 |
+
$str = '<div id="message" class="updated fade"><p>'. __('Options saved successfully.','ald_tptn_plugin') .'</p></div>';
|
23 |
+
echo $str;
|
24 |
+
}
|
25 |
+
|
26 |
+
if ($_POST['tptn_default']){
|
27 |
+
delete_option('ald_tptn_settings');
|
28 |
+
$tptn_settings = tptn_default_options();
|
29 |
+
update_option('ald_tptn_settings', $tptn_settings);
|
30 |
+
|
31 |
+
$str = '<div id="message" class="updated fade"><p>'. __('Options set to Default.','ald_tptn_plugin') .'</p></div>';
|
32 |
+
echo $str;
|
33 |
+
}
|
34 |
+
?>
|
35 |
+
|
36 |
+
<div class="wrap">
|
37 |
+
<h2>Top 10 </h2>
|
38 |
+
<div style="border: #ccc 1px solid; padding: 10px">
|
39 |
+
<fieldset class="options">
|
40 |
+
<legend>
|
41 |
+
<h3>
|
42 |
+
<?php _e('Support the Development','ald_tptn_plugin'); ?>
|
43 |
+
</h3>
|
44 |
+
</legend>
|
45 |
+
<p>
|
46 |
+
<?php _e('If you find ','ald_tptn_plugin'); ?>
|
47 |
+
<a href="http://ajaydsouza.com/wordpress/plugins/top-10/">Top 10</a>
|
48 |
+
<?php _e('useful, please do','ald_tptn_plugin'); ?>
|
49 |
+
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=donate@ajaydsouza.com&item_name=Top%10%20(From%20WP-Admin)&no_shipping=1&return=http://ajaydsouza.com/wordpress/plugins/top-10/&cancel_return=http://ajaydsouza.com/wordpress/plugins/top-10/&cn=Note%20to%20Author&tax=0&currency_code=USD&bn=PP-DonationsBF&charset=UTF-8" title="Donate via PayPal"><?php _e('drop in your contribution','ald_tptn_plugin'); ?></a>.
|
50 |
+
(<a href="http://ajaydsouza.com/donate/"><?php _e('Some reasons why you should.','ald_tptn_plugin'); ?></a>)</p>
|
51 |
+
</fieldset>
|
52 |
+
</div>
|
53 |
+
<form method="post" id="tptn_options" name="tptn_options" style="border: #ccc 1px solid; padding: 10px">
|
54 |
+
<fieldset class="options">
|
55 |
+
<legend>
|
56 |
+
<h3>
|
57 |
+
<?php _e('Options:','ald_tptn_plugin'); ?>
|
58 |
+
</h3>
|
59 |
+
</legend>
|
60 |
+
<p>
|
61 |
+
<label>
|
62 |
+
<?php _e('Text to display before the post count: ','ald_tptn_plugin'); ?>
|
63 |
+
<input type="textbox" name="before_count" id="before_count" value="<?php echo stripslashes($tptn_settings[before_count]); ?>">
|
64 |
+
</label>
|
65 |
+
</p>
|
66 |
+
<p>
|
67 |
+
<label>
|
68 |
+
<?php _e('Text to display after the post count: ','ald_tptn_plugin'); ?>
|
69 |
+
<input type="textbox" name="after_count" id="after_count" value="<?php echo stripslashes($tptn_settings[after_count]); ?>">
|
70 |
+
</label>
|
71 |
+
</p>
|
72 |
+
<p><?php _e('e.g. the default options displays <code>(Visited 123 times)</code>','ald_tptn_plugin'); ?></p>
|
73 |
+
<p>
|
74 |
+
<label>
|
75 |
+
<?php _e('Number of popular posts to display: ','ald_tptn_plugin'); ?>
|
76 |
+
<input type="textbox" name="limit" id="limit" value="<?php echo stripslashes($tptn_settings[limit]); ?>">
|
77 |
+
</label>
|
78 |
+
</p>
|
79 |
+
<p>
|
80 |
+
<label>
|
81 |
+
<?php _e('Title of popular posts: ','ald_tptn_plugin'); ?>
|
82 |
+
<input type="textbox" name="title" id="title" value="<?php echo stripslashes($tptn_settings[title]); ?>">
|
83 |
+
</label>
|
84 |
+
</p>
|
85 |
+
<p>
|
86 |
+
<label>
|
87 |
+
<input type="checkbox" name="add_to_content" id="add_to_content" <?php if ($tptn_settings[add_to_content]) echo 'checked="checked"' ?> />
|
88 |
+
<?php _e('Add post count to content?','ald_tptn_plugin'); ?>
|
89 |
+
</label>
|
90 |
+
</p>
|
91 |
+
<p>
|
92 |
+
<label>
|
93 |
+
<input type="checkbox" name="show_credit" id="show_credit" <?php if ($tptn_settings[show_credit]) echo 'checked="checked"' ?> />
|
94 |
+
<?php _e('A link to the plugin is added as an extra list item to the list of popular posts. Not mandatory, but thanks if you do it!','ald_tptn_plugin'); ?>
|
95 |
+
</label>
|
96 |
+
</p>
|
97 |
+
<p>
|
98 |
+
<input type="submit" name="tptn_save" id="tptn_save" value="Save Options" style="border:#00CC00 1px solid" />
|
99 |
+
<input name="tptn_default" type="submit" id="tptn_default" value="Default Options" style="border:#FF0000 1px solid" onclick="if (!confirm('<?php _e('Do you want to set options to Default? If you don\'t have a copy of the username, please hit Cancel and copy it first.','ald_tptn_plugin'); ?>')) return false;" />
|
100 |
+
</p>
|
101 |
+
</fieldset>
|
102 |
+
</form>
|
103 |
+
</div>
|
104 |
+
<?php
|
105 |
+
|
106 |
+
}
|
107 |
+
|
108 |
+
|
109 |
+
function tptn_adminmenu() {
|
110 |
+
if (function_exists('current_user_can')) {
|
111 |
+
// In WordPress 2.x
|
112 |
+
if (current_user_can('manage_options')) {
|
113 |
+
$tptn_is_admin = true;
|
114 |
+
}
|
115 |
+
} else {
|
116 |
+
// In WordPress 1.x
|
117 |
+
global $user_ID;
|
118 |
+
if (user_can_edit_user($user_ID, 0)) {
|
119 |
+
$tptn_is_admin = true;
|
120 |
+
}
|
121 |
+
}
|
122 |
+
|
123 |
+
if ((function_exists('add_options_page'))&&($tptn_is_admin)) {
|
124 |
+
add_options_page(__("Top 10", 'myald_tptn_plugin'), __("Top 10", 'myald_tptn_plugin'), 9, 'tptn_options', 'tptn_options');
|
125 |
+
}
|
126 |
+
}
|
127 |
+
|
128 |
+
|
129 |
+
add_action('admin_menu', 'tptn_adminmenu');
|
130 |
+
|
131 |
+
?>
|
readme.txt
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== Top 10 ===
|
2 |
+
Tags: popular posts, top posts, counter
|
3 |
+
Contributors: Ajay, Mark Ghosh
|
4 |
+
Donate link: http://ajaydsouza.com/donate/
|
5 |
+
Stable tag: trunk
|
6 |
+
Requires at least: 2.0
|
7 |
+
Tested up to: 2.7
|
8 |
+
|
9 |
+
|
10 |
+
Count page views on posts and display a list of top posts
|
11 |
+
|
12 |
+
== Description ==
|
13 |
+
|
14 |
+
WordPress doesn't count page views by default. This plugin will count the number of page views on your single posts and store them in the database.
|
15 |
+
|
16 |
+
You can then display the page view count on individual pages as well as display a list of most popular posts based on page views.
|
17 |
+
|
18 |
+
|
19 |
+
== Installation ==
|
20 |
+
|
21 |
+
1. Download the plugin
|
22 |
+
|
23 |
+
2. Extract the contents of top-10.zip to wp-content/plugins/ folder. You should get a folder called top-10.
|
24 |
+
|
25 |
+
3. Activate the Plugin in WP-Admin.
|
26 |
+
|
27 |
+
4. Goto Settings > Top 10 to configure
|
28 |
+
|
29 |
+
|
30 |
+
== Changelog ==
|
31 |
+
|
32 |
+
* 1.0 - Release
|
33 |
+
|
34 |
+
|
35 |
+
== Frequently Asked Questions ==
|
36 |
+
|
37 |
+
= What are the requirements for this plugin? =
|
38 |
+
|
39 |
+
WordPress 2.0 or above
|
40 |
+
|
41 |
+
|
42 |
+
= Can I customize what is displayed? =
|
43 |
+
|
44 |
+
All options can be customized within the Options page in WP-Admin itself
|
45 |
+
|
46 |
+
For more information, please visit http://ajaydsouza.com/wordpress/plugins/top-10/
|
47 |
+
|
48 |
+
= Support =
|
49 |
+
|
50 |
+
All questions need to be redirected at the Support Forum at http://ajaydsouza.org/
|
51 |
+
|
52 |
+
No support questions will be entertained in the comments or via email.
|
top-10-counter.js.php
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
//"top-10-counter.js.php" Display number of page views
|
3 |
+
Header("content-type: application/x-javascript");
|
4 |
+
|
5 |
+
if (!function_exists('add_action')) {
|
6 |
+
$wp_root = '../../..';
|
7 |
+
if (file_exists($wp_root.'/wp-load.php')) {
|
8 |
+
require_once($wp_root.'/wp-load.php');
|
9 |
+
} else {
|
10 |
+
require_once($wp_root.'/wp-config.php');
|
11 |
+
}
|
12 |
+
}
|
13 |
+
|
14 |
+
// Display counter using Ajax
|
15 |
+
function tptn_disp_count() {
|
16 |
+
global $wpdb;
|
17 |
+
|
18 |
+
$table_name = $wpdb->prefix . "top_ten";
|
19 |
+
$tptn_settings = tptn_read_options();
|
20 |
+
$before_count = $tptn_settings['before_count'];
|
21 |
+
$after_count = $tptn_settings['after_count'];
|
22 |
+
|
23 |
+
$id = intval($_GET['top_ten_id']);
|
24 |
+
if($id > 0) {
|
25 |
+
|
26 |
+
$resultscount = $wpdb->get_row("select postnumber, cntaccess from $table_name WHERE postnumber = $id");
|
27 |
+
$cntaccess = (($resultscount) ? $resultscount->cntaccess : 0);
|
28 |
+
|
29 |
+
echo 'document.write("Test: '.$before_count.$cntaccess.$after_count.'")';
|
30 |
+
}
|
31 |
+
}
|
32 |
+
tptn_disp_count();
|
33 |
+
?>
|
top-10.php
ADDED
@@ -0,0 +1,220 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Plugin Name: Top 10
|
4 |
+
Version: 1.0
|
5 |
+
Plugin URI: http://ajaydsouza.com/wordpress/plugins/top-10/
|
6 |
+
Description: Count visits per post and display the top 10 posts. Based on the plugin by <a href="http://weblogtoolscollection.com">Mark Ghosh</a>. <a href="options-general.php?page=tptn_options">Configure...</a>
|
7 |
+
Author: Ajay D'Souza
|
8 |
+
Author URI: http://ajaydsouza.com/
|
9 |
+
*/
|
10 |
+
|
11 |
+
//if (!defined('ABSPATH')) die("Aren't you supposed to come here via WP-Admin?");
|
12 |
+
if (!function_exists('add_action')) {
|
13 |
+
$wp_root = '../../..';
|
14 |
+
if (file_exists($wp_root.'/wp-load.php')) {
|
15 |
+
require_once($wp_root.'/wp-load.php');
|
16 |
+
} else {
|
17 |
+
require_once($wp_root.'/wp-config.php');
|
18 |
+
}
|
19 |
+
}
|
20 |
+
|
21 |
+
$tptn_db_version = "1.0";
|
22 |
+
|
23 |
+
function ald_tptn_init() {
|
24 |
+
load_plugin_textdomain('myald_tptn_plugin', PLUGINDIR.'/'.dirname(plugin_basename(__FILE__)));
|
25 |
+
}
|
26 |
+
add_action('init', 'ald_tptn_init');
|
27 |
+
|
28 |
+
define('ALD_TPTN_DIR', dirname(__FILE__));
|
29 |
+
|
30 |
+
/*********************************************************************
|
31 |
+
* Main Function (Do not edit) *
|
32 |
+
********************************************************************/
|
33 |
+
// Update post views
|
34 |
+
add_action('wp_head','tptn_add_viewed_count');
|
35 |
+
function tptn_add_viewed_count() {
|
36 |
+
global $post, $wpdb, $single;
|
37 |
+
$table_name = $wpdb->prefix . "top_ten";
|
38 |
+
|
39 |
+
if(is_single() || is_page()) {
|
40 |
+
$id = intval($post->ID);
|
41 |
+
if(defined('WP_CACHE') && WP_CACHE) { ?>
|
42 |
+
<!-- Start of Top 10 JS -->
|
43 |
+
<?php wp_print_scripts(array('sack')); ?>
|
44 |
+
<script type="text/javascript">
|
45 |
+
//<![CDATA[
|
46 |
+
top_ten_count = new sack("<?php bloginfo( 'wpurl' ); ?>/wp-content/plugins/top-10/top-10_ajax.php");
|
47 |
+
top_ten_count.setVar( "top_ten_id", <?php echo $id ?> );
|
48 |
+
top_ten_count.method = 'GET';
|
49 |
+
top_ten_count.onError = function() { alert('Ajax error' )};
|
50 |
+
top_ten_count.runAJAX();
|
51 |
+
top_ten_count = null;
|
52 |
+
//]]>
|
53 |
+
</script>
|
54 |
+
<!-- Start of Top 10 JS -->
|
55 |
+
<?php } else {
|
56 |
+
$results = $wpdb->get_results("select postnumber, cntaccess from $table_name where postnumber = '$id'");
|
57 |
+
$test = 0;
|
58 |
+
if ($results) {
|
59 |
+
foreach ($results as $result) {
|
60 |
+
$wpdb->query("update $table_name set cntaccess = cntaccess + 1 where postnumber = $result->postnumber");
|
61 |
+
$test = 1;
|
62 |
+
}
|
63 |
+
}
|
64 |
+
if ($test == 0) {
|
65 |
+
$wpdb->query("insert into $table_name (postnumber, cntaccess) values('$id', '1')");
|
66 |
+
}
|
67 |
+
}
|
68 |
+
}
|
69 |
+
}
|
70 |
+
|
71 |
+
// Function to show post count
|
72 |
+
function tptn_show_post_count() {
|
73 |
+
global $wpdb, $post;
|
74 |
+
$id = intval($post->ID);
|
75 |
+
$table_name = $wpdb->prefix . "top_ten";
|
76 |
+
$tptn_settings = tptn_read_options();
|
77 |
+
$before_count = $tptn_settings['before_count'];
|
78 |
+
$after_count = $tptn_settings['after_count'];
|
79 |
+
|
80 |
+
$resultscount = $wpdb->get_row("select postnumber, cntaccess from $table_name WHERE postnumber = $id");
|
81 |
+
$cntaccess = (($resultscount) ? $resultscount->cntaccess : 0);
|
82 |
+
|
83 |
+
return $before_count.$cntaccess.$after_count;
|
84 |
+
}
|
85 |
+
|
86 |
+
function tptn_pc_content($content) {
|
87 |
+
|
88 |
+
global $single, $post;
|
89 |
+
$tptn_settings = tptn_read_options();
|
90 |
+
$id = intval($post->ID);
|
91 |
+
|
92 |
+
if(($single)&&($tptn_settings['add_to_content'])) {
|
93 |
+
if(defined('WP_CACHE') && WP_CACHE) {
|
94 |
+
$output = '<script type="text/javascript" src="'.get_bloginfo('wpurl').'/wp-content/plugins/top-10/top-10-counter.js.php?top_ten_id='.$id.'"></script>';
|
95 |
+
} else {
|
96 |
+
$output = tptn_show_post_count();
|
97 |
+
}
|
98 |
+
return $content.$output;
|
99 |
+
} else {
|
100 |
+
return $content;
|
101 |
+
}
|
102 |
+
}
|
103 |
+
add_filter('the_content', 'tptn_pc_content');
|
104 |
+
|
105 |
+
function echo_tptn_post_count() {
|
106 |
+
$output = tptn_show_post_count();
|
107 |
+
echo $output;
|
108 |
+
}
|
109 |
+
|
110 |
+
|
111 |
+
// Function to show popular posts
|
112 |
+
function tptn_show_pop_posts() {
|
113 |
+
global $wpdb, $siteurl, $tableposts, $id;
|
114 |
+
$table_name = $wpdb->prefix . "top_ten";
|
115 |
+
$tptn_settings = tptn_read_options();
|
116 |
+
$limit = $tptn_settings['limit'];
|
117 |
+
|
118 |
+
$results = $wpdb->get_results("select postnumber, cntaccess from $table_name ORDER BY cntaccess DESC LIMIT $limit");
|
119 |
+
|
120 |
+
echo '<div id="crp_related">'.$tptn_settings['title'];
|
121 |
+
echo '<ul>';
|
122 |
+
if ($results) {
|
123 |
+
foreach ($results as $result) {
|
124 |
+
echo '<li><a href="'.get_permalink($result->postnumber).'">'.get_the_title($result->postnumber).'</a> ('.$result->cntaccess.')</li>';
|
125 |
+
}
|
126 |
+
}
|
127 |
+
if ($tptn_settings['show_credit']) echo '<li>Popular posts by <a href="http://ajaydsouza.com/wordpress/plugins/top-10/">Top 10 plugin</a></li>';
|
128 |
+
echo '</ul>';
|
129 |
+
echo '</div><br/><br/>';
|
130 |
+
|
131 |
+
}
|
132 |
+
|
133 |
+
// Default Options
|
134 |
+
function tptn_default_options() {
|
135 |
+
$title = __('<h3>Popular Posts:</h3>');
|
136 |
+
|
137 |
+
$tptn_settings = Array (
|
138 |
+
show_credit => true, // Add link to plugin page of my blog in top posts list
|
139 |
+
add_to_content => true, // Add post count to content (only on single pages)
|
140 |
+
before_count => '(Visited ', // Text to display before the count
|
141 |
+
after_count => ' times)', // Text to display after the count
|
142 |
+
title => $title, // Add before the content
|
143 |
+
limit => '10', // How many posts to display?
|
144 |
+
);
|
145 |
+
return $tptn_settings;
|
146 |
+
}
|
147 |
+
|
148 |
+
// Function to read options from the database
|
149 |
+
function tptn_read_options() {
|
150 |
+
|
151 |
+
$tptn_settings_changed = false;
|
152 |
+
|
153 |
+
$defaults = tptn_default_options();
|
154 |
+
|
155 |
+
$tptn_settings = array_map('stripslashes',(array)get_option('ald_tptn_settings'));
|
156 |
+
unset($tptn_settings[0]); // produced by the (array) casting when there's nothing in the DB
|
157 |
+
|
158 |
+
foreach ($defaults as $k=>$v) {
|
159 |
+
if (!isset($tptn_settings[$k]))
|
160 |
+
$tptn_settings[$k] = $v;
|
161 |
+
$tptn_settings_changed = true;
|
162 |
+
}
|
163 |
+
if ($tptn_settings_changed == true)
|
164 |
+
update_option('ald_tptn_settings', $tptn_settings);
|
165 |
+
|
166 |
+
return $tptn_settings;
|
167 |
+
|
168 |
+
}
|
169 |
+
|
170 |
+
// Create tables to store pageviews
|
171 |
+
function tptn_install() {
|
172 |
+
global $wpdb;
|
173 |
+
global $tptn_db_version;
|
174 |
+
|
175 |
+
$table_name = $wpdb->prefix . "top_ten";
|
176 |
+
if($wpdb->get_var("show tables like '$table_name'") != $table_name) {
|
177 |
+
|
178 |
+
$sql = "CREATE TABLE " . $table_name . " (
|
179 |
+
accessedid int NOT NULL AUTO_INCREMENT,
|
180 |
+
postnumber int NOT NULL,
|
181 |
+
cntaccess int NOT NULL,
|
182 |
+
PRIMARY KEY (accessedid)
|
183 |
+
);";
|
184 |
+
|
185 |
+
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
|
186 |
+
dbDelta($sql);
|
187 |
+
|
188 |
+
add_option("tptn_db_version", $tptn_db_version);
|
189 |
+
}
|
190 |
+
|
191 |
+
// Upgrade table code
|
192 |
+
$installed_ver = get_option( "tptn_db_version" );
|
193 |
+
|
194 |
+
if( $installed_ver != $tptn_db_version ) {
|
195 |
+
|
196 |
+
$sql = "CREATE TABLE " . $table_name . " (
|
197 |
+
accessedid int NOT NULL AUTO_INCREMENT,
|
198 |
+
postnumber int NOT NULL,
|
199 |
+
cntaccess int NOT NULL,
|
200 |
+
PRIMARY KEY (accessedid)
|
201 |
+
);";
|
202 |
+
|
203 |
+
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
|
204 |
+
dbDelta($sql);
|
205 |
+
|
206 |
+
update_option( "tptn_db_version", $tptn_db_version );
|
207 |
+
}
|
208 |
+
|
209 |
+
}
|
210 |
+
if (function_exists('register_activation_hook')) {
|
211 |
+
register_activation_hook(__FILE__,'tptn_install');
|
212 |
+
}
|
213 |
+
|
214 |
+
// This function adds an Options page in WP Admin
|
215 |
+
if (is_admin() || strstr($_SERVER['PHP_SELF'], 'wp-admin/')) {
|
216 |
+
require_once(ALD_TPTN_DIR . "/admin.inc.php");
|
217 |
+
}
|
218 |
+
|
219 |
+
|
220 |
+
?>
|
top-10_ajax.php
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
if (!function_exists('add_action')) {
|
4 |
+
$wp_root = '../../..';
|
5 |
+
if (file_exists($wp_root.'/wp-load.php')) {
|
6 |
+
require_once($wp_root.'/wp-load.php');
|
7 |
+
} else {
|
8 |
+
require_once($wp_root.'/wp-config.php');
|
9 |
+
}
|
10 |
+
}
|
11 |
+
|
12 |
+
// Ajax Increment Counter
|
13 |
+
tptn_inc_count();
|
14 |
+
function tptn_inc_count() {
|
15 |
+
global $wpdb;
|
16 |
+
$table_name = $wpdb->prefix . "top_ten";
|
17 |
+
|
18 |
+
$id = intval($_GET['top_ten_id']);
|
19 |
+
if($id > 0) {
|
20 |
+
$results = $wpdb->get_results("select postnumber, cntaccess from $table_name where postnumber = '$id'");
|
21 |
+
$test = 0;
|
22 |
+
if ($results) {
|
23 |
+
foreach ($results as $result) {
|
24 |
+
$wpdb->query("update $table_name set cntaccess = cntaccess + 1 where postnumber = $result->postnumber");
|
25 |
+
$test = 1;
|
26 |
+
}
|
27 |
+
}
|
28 |
+
if ($test == 0) {
|
29 |
+
$wpdb->query("insert into $table_name (postnumber, cntaccess) values('$id', '1')");
|
30 |
+
}
|
31 |
+
}
|
32 |
+
}
|
33 |
+
|
34 |
+
?>
|
uninstall.php
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( !defined('ABSPATH') && !defined('WP_UNINSTALL_PLUGIN') ) {
|
3 |
+
exit();
|
4 |
+
}
|
5 |
+
global $wpdb;
|
6 |
+
$table_name = $wpdb->prefix . "top_ten";
|
7 |
+
|
8 |
+
$sql = "DROP TABLE $table_name";
|
9 |
+
$wpdb->query($sql);
|
10 |
+
delete_option('ald_tptn_settings');
|
11 |
+
delete_option('tptn_db_version');
|
12 |
+
?>
|