Herself's Webtools

Scripts, HowTos, Templates, Plugins, Widgets, Tips

Archive for the ‘php’ Category

How to add ‘Twitter This’ links to your WordPress Posts

without comments

Twitter seems to be the preferred social network now so I decided I needed some ‘Twitter This’ links on my WordPress Blogs.

You’ll want to add this link to both the index.php and the single.php pages in your theme. Every theme is different so I can’t tell you exactly where to add it. I find the comments section in those pages and work my way up to where the date, tags or other miscellany is stored and added them there on my themes.

The link you’ll want is:
<p><a href=”http://twitter.com/home?status=Reading:<?php echo urlencode(get_permalink(get_the_ID())); ?>&title=<?php echo urlencode(get_the_title(get_the_ID())); ?>”>Twitter this</a></p>

You might also check out James Wilkes Design version of the link He is pickier than I about the encoding.

Many thanks to:
Jamie Huskisson and to James Wilkes Design who gave me the pieces I needed to put the link together correctly.

Written by Linda MacPhee-Cobb

March 21st, 2010 at 9:18 am

Check for altered files on webhost

without comments

Every time I change webhosts I have to dust off files and slightly re-arrange the way I do security.

Instead of running the file check through a WP plugin I decided to run it from a command line and email myself the results.

The following PHP code will check for altered files in the previous 7 days ( $days = 7 ) and email you the files altered.

You should give this code a random file name and place it somewhere off the beaten path on your server. I set permissions to r–r–r–.

<?php

/*
Tripwire for webserver to tell when files altered or have 777 permissions
Author: Linda MacPhee-Cobb
Author URI: http://timestocome.com
Support URI: http://herselfswebtools.com
*/

// date
date_default_timezone_set('UTC');

// info we need
$date = time();                        // current date+time
$one_day = 86400;                    // number of seconds in one day
$days = 7;                            // user selected number of days back to check files
$dir_count = 0;                        // init loop

$directories_to_read[0] = getcwd() . "/";    // start at the beginning
$i = 0;                                // loop counter

// time diff
$go_back = $one_day * $days;
$diff = $date - $go_back;

//email
$to = 'you@gmail.com';
$subject = 'file check';
$headers = "From: webmaster@your_domain.com";

$message = "";

while ( $i <= $dir_count ){

// get file info
$current_directory = $directories_to_read[$i];
$read_path = opendir( $directories_to_read[$i] );

while ( $file_name = readdir( $read_path)){

if (( $file_name != '.' )&&( $file_name != '..' )){

if ( is_dir( $current_directory . "/"  . $file_name ) == "dir" ){

// need to grab files from each directory all the way down to leaves
$d_file_name = "$current_directory" . "$file_name";
$dir_count++;
$directories_to_read[$dir_count] = $d_file_name . "/";

}else{

$file_name = "$current_directory" . "$file_name";

// if time modified newer than x days print - else skip
if ( (filemtime( $file_name)) > $diff  ){
$message .= "\nFILE ALTERED $file_name";

$date_changed = filectime( $file_name );
$pretty_date = date( "F j, Y g:i a", $date_changed);
$message .=  " ::: $pretty_date " ;
}

}
}
}

closedir ( $read_path );
$i++;

}

$mail_sent = @mail( $to, $subject, $message, $headers );

?>

Written by Linda MacPhee-Cobb

September 13th, 2009 at 11:59 am

Posted in php,security,tools