pearweb_manual
[ class tree: pearweb_manual ] [ index: pearweb_manual ] [ all elements ]

Source for file add-note.php

Documentation is available at add-note.php

  1. <?php
  2. require_once 'Services/ReCaptcha.php';
  3.  
  4. $captcha = new Services_ReCaptcha(PEAR_RECAPTCHA_PUBLIC_KEYPEAR_RECAPTCHA_PRIVATE_KEY);
  5.  
  6.  
  7. $post $_POST;
  8.  
  9.  
  10. $loggedin = isset($auth_user&& $auth_user->registered;
  11.  
  12. if ($loggedin{
  13.     /**
  14.      * These are the keys that have to be set
  15.      * in order to get no errors. If someone is
  16.      * missing one of them, then something is
  17.      * totally wrong.
  18.      */
  19.     $keys = array(
  20.             'noteUrl'  => 'Note Address',
  21.             'redirect' => 'Original Manual Page',
  22.             'note'     => 'User note',
  23.     );
  24.     $post['user'$auth_user->name;
  25. else {
  26.     /**
  27.      * These are the keys that have to be set
  28.      * in order to get no errors. If someone is
  29.      * missing one of them, then something is
  30.      * totally wrong.
  31.      */
  32.     $keys = array(
  33.             'noteUrl'  => 'Note Address',
  34.             'redirect' => 'Original Manual Page',
  35.             'user'     => 'Username/Email',
  36.             'note'     => 'User note',
  37.             'answer'   => 'Captcha Answer'
  38.     );
  39. }
  40.  
  41.  
  42. $errors = array();
  43.  
  44. /**
  45.  * Check if the spam check is passed.
  46.  * @todo Use real cpatchas as this is
  47.  *  going to be highly used.
  48.  *
  49.  *  If the captcha is wrong, then regenerate it.
  50.  */
  51. if (!$loggedin{
  52.     if (!$captcha->validate()) {
  53.         $errors['Incorrect Captcha';       
  54.     }
  55.     /**
  56.      * @todo Check akismet here aswell ?
  57.      */
  58. }
  59.  
  60. /**
  61.  * Check if the keys are set, if not
  62.  * then set an error..
  63.  */
  64. foreach ($keys as $key => $message{
  65.     if (!isset($post[$key]|| empty($post[$key])) {
  66.         $errors['Error occured, missing: ' $message;
  67.     }
  68. }
  69.  
  70. $redirect $post['redirect'];
  71.  
  72. if (empty($errors)) {
  73.  
  74.     require_once 'notes/ManualNotes.class.php';
  75.  
  76.     $manualNote = new Manual_Notes;
  77.  
  78.     $added $manualNote->addComment($post['noteUrl']$post['user']$post['note']);
  79.  
  80.     if (PEAR::isError($added)) {
  81.         if (isset($post['noteUrl'])) {
  82.             /**
  83.              * If someone tries to access this page
  84.              * without a noteUrl then it's his problem
  85.              * to get the comment template without
  86.              * a noteUrl.. this is recursivly not
  87.              * going to be working however this check
  88.              * should not have to be done because
  89.              * in order to get to this point.. you need
  90.              * to have.
  91.              */
  92.             $noteUrl strip_tags($post['noteUrl']);
  93.         }
  94.         $errors[$added->getMessage(' please contact <a href="mailto:' . PEAR_WEBMASTER_EMAIL . '">Webmaster</a> , Thanks';
  95.     }
  96.     /**
  97.      * We need no further answers
  98.      */
  99.     if (isset($_SESSION['answer'])) {
  100.         unset($_SESSION['answer']);
  101.     }
  102.     require PEARWEB_TEMPLATEDIR . '/notes/add-note.tpl.php';
  103. else {
  104.     $email $post['user'];
  105.     $note $post['note'];
  106.     $noteUrl $post['noteUrl'];
  107.     require PEARWEB_TEMPLATEDIR . '/notes/add-note-form.tpl.php';
  108. }

Documentation generated on Mon, 11 Mar 2019 16:04:25 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.