Source Code For author.php
Turn Line Numbers On
<?php
/*
Plugin Name: Author page
Version: 0.3
Plugin URI: http://jfoucher.info/2004/10/03/author-page-wordpress-plugin/
Description: This plugin shows a page giving some information about the author. Supports <a href="http://wiki.wordpress.org/AutomaticUpdate" title="Automatic Update">Automatic Update</a>.
Author: Jonathan Foucher
Author URI: http://jfoucher.info
This plugin supports Automatic Update : http://wiki.wordpress.org/AutomaticUpdate
Update: http://jfoucher.info/plugin-update.php?p=31
To use put the author() function in you index.php template,
where it normally shows the message that there are no posts.
In the default template, it looks like this:
<?php endforeach; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
</div>
Replace this by :
<?php endforeach; else: ?>
<p><?php author(true,5,false); ?></p>
<?php endif; ?>
</div>
The optionnal boolean parameter gives you the opportunity to show or hide
a contact form for the author. defaults to 'true' (show the form).
You may want to change some of the text in there to your own language.
Copyright (c) 2004
Released under the GPL license
http://www.gnu.org/licenses/gpl.txt
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/************************************
** TO TAKE ADVANTAGE OF UPDATE **
** DETECTION, PLEASE CONSIDER **
** MAKING THE FOLLOWING ADDITION **
** TO YOUR WORDPRESS INSTALL **
** **
*************************************
OPEN FOR EDITING : wp-admin/plugins.php
FIND
if ( preg_match("|Version:(.*)|i", $plugin_data, $version) )
$version = $version1?;
else
$version ='';
ADD THE FOLLOWING CODE AFTERWARDS
// BEGIN PLUGIN UPDATE ADD-ON
if ( preg_match("|Update:(.*)|i", $plugin_data, $update) )
{
$update = $update[1];
$update = trim($update);
if ($u = @file("$update")) {
$u = implode('',$u);
$u = trim($u);
$v = trim($version);
if($u != $v){
$updatelink = '<a href="';
$updatelink .= $plugin_uri[1];
$updatelink .= '">';
$updatelink .= '<em><strong>Update Available:</strong> (';
$updatelink .= $u;
$updatelink .= ')</em></a>';
$description[1] .= '<br />';
$description[1] .= $updatelink;
}
else
{
$updatelink = '';
}
}
else{
$updatelink = '';
}
}
else
{ $update ='';}
//END PLUGIN UPDATE ADD-ON
*/
function author($form=true,$art=0,$email=false){
global $wpdb, $tableusers,$authordata;
if ($_GET['author_name']!=''){
$author=$_GET['author_name'];
$authordata = $wpdb->get_row("SELECT * FROM $tableusers WHERE user_login='$author'");
if ($_POST['email']!=''){
$email= $_POST['email'];
$name= $_POST['name'];
$subject= $_POST['subject'];
$message= $_POST['message'];
$author= $_POST['author'];
send($email,$name,$subject,$message,$author);
}
author_info($form,$art,$email);
}else{
?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php
}
}
function author_info($form=true,$art=0,$email=false) {
global $wpdb, $tableusers,$tableposts,$author,$authordata;
$article_count= $wpdb->get_row("SELECT COUNT(*) as cnt FROM $tableposts WHERE post_author='$authordata->ID'");
if ($authordata){
?>
<h3 class="storytitle"><a href="<?php the_author_url()?>"><?php the_author_firstname()?> <?php the_author_lastname()?> </a></h3>
<?php
echo "<p>$article_count->cnt articles</p>";
if ($email) ?><p>Email address: <a href="mailto:<?php the_author_email()?>"><?php the_author_email()?></a>
<?php
the_author_description();
?>
<?php if ($authordata->user_icq!='' && $authordata->user_icq!='0') { ?><p>ICQ: <?php the_author_icq() ?></p> <?php } ?>
<?php if ($authordata->user_aim!='' && $authordata->user_aim!='0') { ?><p>AIM: <?php the_author_aim() ?></p><?php } ?>
<?php if ($authordata->user_msn!='' && $authordata->user_msn!='0') { ?><p>MSN: <?php the_author_msn() ?></p><?php } ?>
<?php if ($authordata->user_yim!='' && $authordata->user_yim!='0') { ?><p>YIM: <?php the_author_yim() ?></p><?php } ?>
<?php
if ($art && $art!=0){
$posts=$wpdb->get_results("SELECT post_title, post_date,ID FROM $tableposts WHERE post_author='$authordata->ID' ORDER BY post_date DESC LIMIT 0,$art");
?>
<h4><?php echo $art ?> Latest articles</h4>
<? echo"
<ul id=\"author-articles\">";
global $post;
foreach($posts as $post){
echo"
<li>
<strong><a href=\"".get_permalink($post->ID)."\">".the_title('','',false)."</a></strong>
<span>".$post->post_date."</span>
</li>";
}
echo "</ul>";
}
if ($form==true) contact_form($author);
}else{
echo "Aucun auteur avec ce nom...";
}
}
function contact_form($author=''){
?>
<h4>Contact</h4>
<form action="<? echo $PHP_SELF?>" method="post">
<p>
<input type="text" name="name" size="40" id="name" />
<label for="name"><?php _e("Name"); ?></label>
</p>
<p>
<input type="text" name="email" size="40" id="email" />
<label for="email"><?php _e("E-mail"); ?></label>
</p>
<p>
<input type="text" name="subject" size="40" id="subject" />
<label for="subject">Message subject</label>
</P>
<p>
<label for="message">Your message</label>
<br />
<textarea name="message" cols="50" rows="10" id="message">
</textarea>
</p>
<p>
<input type="submit" name="Submit" value="ok" class="button" />
<input type="hidden" name="author" value="<?php echo $author; ?>" id="author" />
</form>
<?php
}
function send($email='',$name='',$subject='',$message='',$author=''){
global $wpdb, $tableusers,$authordata;
if ($email=='' || !$email) $email= $_POST['email'];
if ($name=='' || !$name) $name= $_POST['name'];
if ($subject=='' || !$subject) $subject= $_POST['subject'];
if ($message=='' || !$message) $message= $_POST['message'];
if ($author=='' || !$author) $author= $_POST['author'];
$message=strip_tags(stripslashes($message));
$subject=strip_tags($subject);
$name=strip_tags($name);
$email=strip_tags($email);
/* Checking email */
if(!ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'.'@'.'[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.'.'[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$',$email))
{
?>
<h4>Wrong email</h4>
<p><a href="javascript:history.go(-1);">
Try again
</a>
</p>
<?php
}else{
if (ereg("^en",$_SERVER["HTTP_ACCEPT_LANGUAGE"])){
echo "<p>Thank you for contacting <strong>$authordata->user_firstname $authordata->user_lastname</strong>.<br />";
echo "We'll get back to you as soon as possible.</p>";
echo "<a href=\"javascript:history.go(-2);\">Back</a> <br>";
}else{
echo "<p>Merci d'avoir contacté <strong>$authordata->user_firstname $authordata->user_lastname</strong>.<br />";
echo "Nous répondrons dès que possible.</p>";
echo "<a href=\"javascript:history.go(-2);\">Retour</a> <br>";
}
/*
Send me the mail
*/
$entetedate = date("r"); // avec offset horaire
$entetemail .= "X-Mailer: PHP/" . phpversion() . "\n" ;
$entetemail .= "X-email-sender: ".$email."\n" ;
$entetemail .= "X-name-sender: ".$name."\n" ;
$entetemail .= "Date: $entetedate\n";
$entetemail .= "From: $name <$email>\n";
mail($authordata->user_email,$subject,$message,$entetemail);
}
}
?>