Source Code For author.php

Turn Line Numbers Off
  1. <?php
  2. /*
  3. Plugin Name: Author page
  4. Version: 0.3
  5. Plugin URI: http://jfoucher.info/2004/10/03/author-page-wordpress-plugin/
  6. 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>.
  7. Author: Jonathan Foucher
  8. Author URI: http://jfoucher.info
  9. This plugin supports Automatic Update : http://wiki.wordpress.org/AutomaticUpdate
  10. Update: http://jfoucher.info/plugin-update.php?p=31
  11. To use put the author() function in you index.php template,
  12. where it normally shows the message that there are no posts.
  13. In the default template, it looks like this:
  14. <?php endforeach; else: ?>
  15. <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
  16. <?php endif; ?>
  17. </div>
  18. Replace this by :
  19. <?php endforeach; else: ?>
  20. <p><?php author(true,5,false); ?></p>
  21. <?php endif; ?>
  22. </div>
  23. The optionnal boolean parameter gives you the opportunity to show or hide
  24. a contact form for the author. defaults to 'true' (show the form).
  25. You may want to change some of the text in there to your own language.
  26. Copyright (c) 2004
  27. Released under the GPL license
  28. http://www.gnu.org/licenses/gpl.txt
  29.     This program is distributed in the hope that it will be useful,
  30.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  31.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  32.     GNU General Public License for more details.
  33.     You should have received a copy of the GNU General Public License
  34.     along with this program; if not, write to the Free Software
  35.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  36. */
  37. /************************************
  38. ** TO TAKE ADVANTAGE OF UPDATE **
  39. ** DETECTION, PLEASE CONSIDER **
  40.  ** MAKING THE FOLLOWING ADDITION **
  41.   ** TO YOUR WORDPRESS INSTALL **
  42.   ** **
  43.    *************************************
  44.     OPEN FOR EDITING : wp-admin/plugins.php
  45.     FIND
  46.             if ( preg_match("|Version:(.*)|i", $plugin_data, $version) )
  47.                     $version = $version1?;
  48.                 else
  49.                     $version ='';
  50.     ADD THE FOLLOWING CODE AFTERWARDS
  51.                 // BEGIN PLUGIN UPDATE ADD-ON
  52.     if ( preg_match("|Update:(.*)|i", $plugin_data, $update) )
  53.     {
  54.       $update = $update[1];
  55.       $update = trim($update);
  56.         if ($u = @file("$update")) {
  57.           $u = implode('',$u);
  58.           $u = trim($u);
  59.           $v = trim($version);
  60.           if($u != $v){
  61.             $updatelink = '<a href="';
  62.             $updatelink .= $plugin_uri[1];
  63.             $updatelink .= '">';
  64.             $updatelink .= '<em><strong>Update Available:</strong> (';
  65.             $updatelink .= $u;
  66.             $updatelink .= ')</em></a>';
  67.             $description[1] .= '<br />';
  68.             $description[1] .= $updatelink;
  69.                       }
  70.           else
  71.           {
  72.           $updatelink = '';
  73.           }
  74.         
  75.         }
  76.         else{
  77.           $updatelink = '';
  78.         }
  79.     }
  80.     else
  81.     {  $update ='';}
  82.     //END PLUGIN UPDATE ADD-ON
  83.              */
  84. function author($form=true,$art=0,$email=false){
  85.    global $wpdb$tableusers,$authordata;
  86. if ($_GET['author_name']!=''){
  87. $author=$_GET['author_name'];
  88. $authordata $wpdb->get_row("SELECT * FROM $tableusers WHERE user_login='$author'");
  89. if ($_POST['email']!=''){
  90. $email$_POST['email'];
  91. $name$_POST['name'];
  92. $subject$_POST['subject'];
  93. $message$_POST['message'];
  94. $author$_POST['author'];
  95. send($email,$name,$subject,$message,$author);
  96. }
  97. author_info($form,$art,$email);
  98. }else{
  99. ?>
  100. <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
  101. <?php
  102. }
  103. }
  104. function author_info($form=true,$art=0,$email=false) {
  105.    global $wpdb$tableusers,$tableposts,$author,$authordata;
  106.    $article_count$wpdb->get_row("SELECT COUNT(*) as cnt FROM $tableposts WHERE post_author='$authordata->ID'");
  107.    if ($authordata){
  108.    ?>
  109.    <h3 class="storytitle"><a href="<?php the_author_url()?>"><?php the_author_firstname()?> <?php the_author_lastname()?> </a></h3>
  110.    <?php
  111.    echo "<p>$article_count->cnt articles</p>";
  112.    if ($email?><p>Email address: <a href="mailto:<?php the_author_email()?>"><?php the_author_email()?></a>
  113.    <?php
  114.    the_author_description();
  115. ?>
  116. <?php if ($authordata->user_icq!='' && $authordata->user_icq!='0') { ?><p>ICQ: <?php the_author_icq() ?></p> <?php ?>
  117. <?php if ($authordata->user_aim!='' && $authordata->user_aim!='0') { ?><p>AIM: <?php the_author_aim() ?></p><?php ?>
  118. <?php if ($authordata->user_msn!='' && $authordata->user_msn!='0') { ?><p>MSN: <?php the_author_msn() ?></p><?php ?>
  119. <?php if ($authordata->user_yim!='' && $authordata->user_yim!='0') { ?><p>YIM: <?php the_author_yim() ?></p><?php ?>
  120. <?php
  121.    if ($art && $art!=0){
  122.        $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");
  123.        ?>
  124.        <h4><?php echo $art ?> Latest articles</h4>
  125.        <? echo"
  126.        <ul id=\"author-articles\">";
  127.               global $post;
  128.        foreach($posts as $post){
  129.        echo"
  130.        <li>
  131.        <strong><a href=\"".get_permalink($post->ID)."\">".the_title('','',false)."</a></strong>
  132.        <span>".$post->post_date."</span>
  133.        </li>";
  134.        }
  135.        echo "</ul>";
  136.    }
  137.    if ($form==truecontact_form($author);
  138.    }else{
  139.    echo "Aucun auteur avec ce nom...";
  140.    }
  141. }
  142. function contact_form($author=''){
  143.  ?>
  144. <h4>Contact</h4>
  145. <form action="<? echo $PHP_SELF?>" method="post">
  146. <p>
  147. <input type="text" name="name" size="40" id="name" />
  148. <label for="name"><?php _e("Name"); ?></label>
  149. </p>
  150. <p>
  151. <input type="text" name="email" size="40" id="email" /> 
  152. <label for="email"><?php _e("E-mail"); ?></label>
  153. </p>
  154. <p>
  155. <input type="text" name="subject" size="40" id="subject" />
  156. <label for="subject">Message subject</label>
  157. </P>
  158. <p>
  159. <label for="message">Your message</label>
  160. <br />
  161. <textarea name="message" cols="50" rows="10" id="message">
  162. </textarea>
  163. </p>
  164. <p>
  165. <input type="submit" name="Submit" value="ok" class="button" />
  166. <input type="hidden" name="author" value="<?php echo $author?>" id="author" />
  167. </form>
  168.  <?php
  169. }
  170. function send($email='',$name='',$subject='',$message='',$author=''){
  171. global $wpdb$tableusers,$authordata;
  172. if ($email=='' || !$email$email$_POST['email'];
  173. if ($name=='' || !$name$name$_POST['name'];
  174. if ($subject=='' || !$subject$subject$_POST['subject'];
  175. if ($message=='' || !$message$message$_POST['message'];
  176. if ($author=='' || !$author$author$_POST['author'];
  177.   $message=strip_tags(stripslashes($message));
  178.   $subject=strip_tags($subject);
  179.   $name=strip_tags($name);
  180.   $email=strip_tags($email);
  181.   /* Checking email */
  182.   if(!ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'.'@'.'[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.'.'[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$',$email))
  183.   {
  184.   ?>
  185.   <h4>Wrong email</h4>
  186.   <p><a href="javascript:history.go(-1);">
  187. Try again
  188. </a>
  189.   </p>
  190.   <?php
  191.   }else{
  192.   if (ereg("^en",$_SERVER["HTTP_ACCEPT_LANGUAGE"])){
  193.   echo "<p>Thank you for contacting <strong>$authordata->user_firstname $authordata->user_lastname</strong>.<br />";
  194.   echo "We'll get back to you as soon as possible.</p>";
  195.   echo "<a href=\"javascript:history.go(-2);\">Back</a> <br>";
  196.   }else{
  197.     echo "<p>Merci d'avoir contact&eacute; <strong>$authordata->user_firstname $authordata->user_lastname</strong>.<br />";
  198.   echo "Nous r&eacute;pondrons d&egrave;s que possible.</p>";
  199.   echo "<a href=\"javascript:history.go(-2);\">Retour</a> <br>";
  200.   }
  201.   /*
  202.   Send me the mail
  203.   */
  204.   $entetedate  date("r"); // avec offset horaire
  205.   $entetemail .= "X-Mailer: PHP/" phpversion() . "\n" ;
  206.   $entetemail .= "X-email-sender: ".$email."\n" ;
  207.   $entetemail .= "X-name-sender: ".$name."\n" ;
  208.   $entetemail .= "Date: $entetedate\n";
  209.   $entetemail .= "From: $name <$email>\n";
  210.   mail($authordata->user_email,$subject,$message,$entetemail);
  211.   }
  212. }
  213. ?>