Einzelnen Beitrag anzeigen
Alt 15.05.2008, 00:05   #7 (permalink)
allucinox
PostRank: 1
 
Benutzerbild von allucinox
 
Registriert seit: 28.12.2007
Ort: Zürich, Schweiz
Beiträge: 43
so sieht ja der code aus (plugin):


<?php

/*
Plugin Name: Visitor Counter Widget
Plugin URI: Lumières dans la nuit » Wordpress-Widget: Besucherzähler
Description: A simple visitor counter for WordPress. It is a simple widget I missed in the plugin databases.
Author: Elias Schwerdtfeger
Version: 1.1
Author URI: Lumières dans la nuit
*/



/*
** Copyright 2007 Elias Schwerdtfeger Lumières dans la nuit
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/


load_plugin_textdomain('visitorcounter', 'wp-content/plugins/visitorcounter');


if(!function_exists('get_ipaddress')) {
function get_ipaddress() {
if (empty($_SERVER["HTTP_X_FORWARDED_FOR"])) {
$ip_address = $_SERVER["REMOTE_ADDR"];
} else {
$ip_address = $_SERVER["HTTP_X_FORWARDED_FOR"];
}
if(strpos($ip_address, ',') !== false) {
$ip_address = explode(',', $ip_address);
$ip_address = $ip_address[0];
}
return $ip_address;
}
}


function wpvc_remove_oldentries ($var)
{
global $wpvc_global_keepfrom;
return $var > $wpvc_global_keepfrom;
}


function wpvc_count ($p_keepfor)
{
global $wpvc_global_keepfrom;
$now_ip = get_ipaddress ();
$now_time = time ();
$keepfor = $p_keepfor ? $p_keepfor : get_option ('visitorcounter_keepfor');
$count = get_option ('visitorcounter_count');
$array = get_option ('visitorcounter_blocked');
if ($count == FALSE)
{
$count = 0;
}
if ($keepfor == FALSE)
{
$keepfor = 10 * 60;
}
if ($array == FALSE)
{
$array = array ();
}
$wpvc_global_keepfrom = $now_time - $keepfor;
$array = array_filter ($array, 'wpvc_remove_oldentries');
if (!array_key_exists ($now_ip, $array))
{
$count++;
update_option ('visitorcounter_count', $count);
$array[$now_ip] = $now_time;
update_option ('visitorcounter_blocked', $array);
}
return $count;
}


function wpvc_sidebar_count ($title = FALSE, $before = FALSE, $after = FALSE, $showtitle = FALSE, $listitem = FALSE, $keepfor = 600)
{
$count = wpvc_count ($keepfor);
if (!$title)
{
$title = __('Counter', 'visitorcounter');
}
if (!$after)
{
$after = __('Visitors', 'visitorcounter');
}
echo '<li>';
if ($showtitle)
{
echo '<h2>' . stripslashes($title) . "</h2>\n";
}
echo $listitem ? '<ul><li>' : '<p>';
if ($before)
{
echo stripslashes($before) . ' ';
}
echo "<span class=\"visitorcount\">$count</span>";
if ($after)
{
echo ' ' . stripslashes($after);
}
echo $listitem ? '</li></ul>' : '</p>';
echo "</li>\n";
}


function wpvc_sidebar_widget ()
{
$opt = get_option ('visitorcounter_widget_options');
wpvc_sidebar_count ($opt['title'], $opt['before'], $opt['after'], $opt['showtitle'], $opt['listitem']);
}


function wpvc_widget_options ()
{
$opt = get_option ('visitorcounter_widget_options');
$cnt = get_option ('visitorcounter_count');
$kf = get_option ('visitorcounter_keepfor');
if (!is_array ($opt))
{
$opt = array (
'title' => __('Counter', 'visitorcounter'),
'before' => '',
'after' => __('Visitors', 'visitorcounter'),
'showtitle' => 1,
'listitem' => 0
);
}
if (!$cnt)
{
$cnt = 0;
}
if (!kf)
{
$kf = 600;
}
if ($_POST['visitorcounter_submit'])
{
$opt['title'] = $_POST['visitorcounter_title'];
$opt['before'] = $_POST['visitorcounter_before'];
$opt['after'] = $_POST['visitorcounter_after'];
$opt['showtitle'] = $_POST['visitorcounter_showtitle'];
$opt['listitem'] = $_POST['visitorcounter_listitem'];
$cnt = intval ($_POST['visitorcounter_count']);
$kf = intval ($_POST['visitorcounter_keepfor']);
update_option ('visitorcounter_widget_options', $opt);
if ($cnt > 0 && $cnt != $_POST['visitorcounter_oldcount'])
{
update_option ('visitorcounter_count', $cnt);
}
update_option ('visitorcounter_keepfor', $kf);
}
?>
<p style="text-align:left">
<label
for="visitorcounter_title"
title="<?php _e('This text will appear as widget title in the sidebar, if you activate the option for displaying the title.', 'visitorcounter'); ?>"
><?php _e('Widget Title:', 'visitorcounter'); ?></label><br />
<input
style="width:100%"
type="text"
id="visitorcounter_title"
name="visitorcounter_title"
value="<?php echo htmlspecialchars (stripslashes ($opt['title'])); ?>"
title="<?php _e('This text will appear as widget title in the sidebar, if you activate the option for displaying the title.', 'visitorcounter'); ?>"
/>
</p>
<p style="text-align:left">
<label
for="visitorcounter_before"
title="<?php _e('This text will appear before the number of visitors', 'visitorcounter'); ?>"
><?php _e('Text before the count (with HTML markup):', 'visitorcounter'); ?></label><br />
<input
style="width:100%"
type="text"
id="visitorcounter_before"
name="visitorcounter_before"
value="<?php echo htmlspecialchars (stripslashes ($opt['before'])); ?>"
title="<?php _e('This text will appear before the number of visitors', 'visitorcounter'); ?>"
/>
</p>
<p style="text-align:left">
<label
for="visitorcounter_after"
title="<?php _e('This text will appear after the number of visitors', 'visitorcounter'); ?>"
><?php _e('Text after the count (with HTML markup):', 'visitorcounter'); ?></label><br />
<input
style="width:100%"
type="text"
id="visitorcounter_after"
name="visitorcounter_after"
value="<?php echo htmlspecialchars (stripslashes ($opt['after'])); ?>"
title="<?php _e('This text will appear after the number of visitors', 'visitorcounter'); ?>"
/>
</p>
<p style="text-align:left">
<label
for="visitorcounter_keepfor"
title="<?php _e('For this number of seconds a visitor\'s IP address will be blocked for counting again', 'visitorcounter'); ?>"
><?php _e('Seconds to block counting the IP again:', 'visitorcounter'); ?></label><br />
<input
style="width:100%"
type="text"
id="visitorcounter_keepfor"
name="visitorcounter_keepfor"
value="<?php echo $kf; ?>"
title="<?php _e('For this number of seconds a visitor\'s IP address will be blocked for counting again', 'visitorcounter'); ?>"
/>
</p>
<p style="text-align:left">
<label
for="visitorcounter_count"
title="<?php _e('This is the actual number of visitors, you can edit it to let your site look more popular than it is', 'visitorcounter'); ?>"
><?php _e('Edit counter value:', 'visitorcounter'); ?></label><br />
<input
style="width:100%"
type="text"
id="visitorcounter_count"
name="visitorcounter_count"
value="<?php echo $cnt; ?>"
title="<?php _e('This is the actual number of visitors, you can edit it to let your site look more popular than it is', 'visitorcounter'); ?>"
/>
</p>
<p style="text-align:left">
<input
type="checkbox"
id="visitorcounter_showtitle"
name="visitorcounter_showtitle"
<?php if($opt['showtitle']) { ?>checked="checked"<?php } ?>
title="<?php _e('If you check this box, the title of the widget will be displayed in the sidebar', 'visitorcounter'); ?>"
/>
<label
for="visitorcounter_showtitle"
title="<?php _e('If you check this box, the title of the widget will be displayed in the sidebar', 'visitorcounter'); ?>"
><?php _e('Show the widget\'s title', 'visitorcounter'); ?></label>
</p>
<p style="text-align:left">
<input
type="checkbox"
id="visitorcounter_listitem"
name="visitorcounter_listitem"
<?php if($opt['listitem']) { ?>checked="checked"<?php } ?>
title="<?php _e('If you check this box, the display will be shown in a HTML list, which is the standard in many themes. Checking this can make the widget\'s appearence more consistent in your theme.', 'visitorcounter'); ?>"
/>
<label
for="visitorcounter_listitem"
title="<?php _e('If you check this box, the display will be shown in a HTML list, which is the standard in many themes. Checking this can make the widget\'s appearence more consistent in your theme.', 'visitorcounter'); ?>"
><?php _e('Display as a list item', 'visitorcounter'); ?></label>
</p>
<p style="text-align:left; font-size:85%;">
<?php _e("This <b>visitor counter</b> widget was developed for you by <a href=\"http://www.tamagothi.de\">Elias Schwerdtfeger</a>. If you like it, please make a little donation in my blog.", 'visitorcounter'); ?>
</p>
<input type="hidden" id="visitorcounter_submit" name="visitorcounter_submit" value="1" />
<input type="hidden" id="visitorcounter_oldcount" name="visitorcounter_oldcount" value="<?php echo $cnt; ?>" />
<?php
}


function wpvc_add_widget ()
{
if (function_exists ('register_sidebar_widget'))
{
register_sidebar_widget (__('Visitor Counter', 'visitorcounter'), 'wpvc_sidebar_widget');
register_widget_control (__('Visitor Counter', 'visitorcounter'), 'wpvc_widget_options', 300, 440);
}
}


add_action ('init', 'wpvc_add_widget');


/*
** It must be a starving man
** Who likes to hear
** These crippled minds talk...
** Greetings from me
** Following the wind.
**
** Wolfsheim, Elias
*/

?>
__________________
http://www.piball.ch
allucinox ist offline   Mit Zitat antworten