Beispiel #1
0
 /**
  * hook: module_output_bottom
  * Show comments and comments form
  *
  * @param array $msc
  * @param int $contentType
  * @param string $sector
  * @param string $title
  * @return mixed
  */
 public function hookModuleOutputBottom(array $mcs, $contentType, $sector, $title)
 {
     if ($sector == 'SC' && $contentType & Zula_ControllerBase::_OT_CONTENT_DYNAMIC && !($contentType & Zula_ControllerBase::_OT_CONFIG)) {
         $requestPath = $this->_router->getRequestPath(Router::_TRIM_ALL);
         $view = new View('display/linear.html', 'comments');
         $view->assign(array('TITLE' => $title));
         $view->assignHtml(array('COMMENTS' => $this->_model('comments', 'comments')->get($requestPath)));
         if ($this->_acl->check('comments_post')) {
             /**
              * Store the hash path as a valid comment path, then build the
              * form view and output both views
              */
             $hashPath = zula_hash($requestPath);
             $_SESSION['mod']['comments'][$hashPath] = array('path' => $requestPath, 'siteType' => $this->_router->getSiteType());
             $form = new View('form.html', 'comments');
             $form->assign(array('comments' => array('hash' => $hashPath, 'name' => $this->_session->getUser('username'), 'website' => null, 'body' => null)));
             // Antispam/Captcha
             $antispam = new Antispam();
             $form->assignHtml(array('CSRF' => $this->_input->createToken(true), 'ANTISPAM' => $antispam->create()));
             return $view->getOutput() . $form->getOutput();
         } else {
             return $view->getOutput();
         }
     }
 }
Beispiel #2
0
 public function get_contact_form()
 {
     $antispam = new Antispam();
     $configs = array('img_path' => './captcha/', 'img_url' => 'http://' . $_SERVER['SERVER_NAME'] . '/captcha/', 'font_path' => $_SERVER['DOCUMENT_ROOT'] . '/application/fonts/', 'img_height' => '50', 'font_size' => 16);
     $cap = $antispam->get_antispam_image($configs);
     $data = array('captcha_time' => $cap['time'], 'ip_address' => $this->input->ip_address(), 'word' => $cap['word']);
     $query = $this->db->insert_string('mdl_captcha', $data);
     $this->db->query($query);
     $programs_list = $this->get_programs_list();
     $list = "";
     $list .= "<br/><div  class='form_div'>";
     $list .= "<div class='panel panel-default' id='program_section' style='margin-bottom:0px;'>";
     $list .= "<div class='panel-heading' style='text-align:left;'><h5 class='panel-title'>Contact US</h5></div>";
     $list .= "<div class='panel-body'>";
     $list .= $this->get_contact_page_data();
     $list .= "<div class='container-fluid'>";
     $list .= "<span class='span9'>&nbsp;</span>";
     $list .= "</div>";
     $list .= "<div>";
     $list .= "<div class='container-fluid' style='text-align:center;'>";
     $list .= "<span class='span9'>&nbsp;</span>";
     $list .= "</div>";
     $list .= "<div class='container-fluid'>";
     $list .= "<span class='span2'>First name*</span>";
     $list .= "<span class='span2'><input type='text' id='firstname' name='firstname'></span>";
     $list .= "<span class='span2' >Last name*</span>";
     $list .= "<span class='span2'><input type='text' id='lastname' name='lastname'></span>";
     $list .= "</div>";
     $list .= "<div class='container-fluid'>";
     $list .= "<span class='span2' >Email*</span>";
     $list .= "<span class='span2'><input type='text' id='email' name='email'></span>";
     $list .= "<span class='span2' >Phone*</span>";
     $list .= "<span class='span2'><input type='text' id='phone' name='phone'></span>";
     $list .= "</div>";
     $list .= "<div class='container-fluid'>";
     $list .= "<span class='span2'>Program*</span>";
     $list .= "<span class='span2'>{$programs_list}</span>";
     $list .= "<span class='span2'>Message*</span>";
     $list .= "<span  class='span2'><textarea id='message' name='message' rows='4' ></textarea></span>";
     $list .= "</div>";
     $list .= "<div class='container-fluid'>";
     $list .= "<span class='span2'>Please submit the captcha*:</span>";
     $list .= "<span class='span2'>" . $cap['image'] . "</span>";
     $list .= "<span class='span2'><input type='text' id='captcha' name='captcha' value=''></span>";
     $list .= "</div>";
     $list .= "<div class='container-fluid'>";
     $list .= "<span class='span2'><button class='btn btn-primary' id='contact_button'>Submit</button></span>";
     $list .= "<span class='span6' id='contact_result'></span>";
     $list .= "</div>";
     $list .= "</div>";
     // end of panel-body
     $list .= "</div>";
     // end of panel panel-default
     $list .= "</div></div>";
     // end of form div
     return $list;
 }
 /**
  *	@fn send
  *	@short Sends the contact email if validation passes.
  *	@details This method creates a contact email with the post data submitted by the user
  *	and delivers it to the website owner. Cookies are set for the user details if the <tt>remember_me</tt>
  *	flag has been set.
  *	If any of the validation steps fails, it performs a redirection to the action <tt>index</tt>.
  *	A redirection to the action <tt>thank_you</tt> is performed on success.
  */
 public function send()
 {
     if (!$this->request->is_post()) {
         $this->redirect_to(array('action' => 'index'));
     }
     if (!Email::is_valid($_POST['email'])) {
         $this->flash(l('Please enter a valid email address'), 'error');
         $this->redirect_to(array('action' => 'index'));
     }
     if (!Antispam::check_math()) {
         $this->flash(Antispam::random_comment(), 'error');
         $this->redirect_to(array('action' => 'index'));
     }
     // A static class method would be infinitely better...
     $contact_email = new ContactEmail($_POST);
     $contact_email->send();
     if (isset($_POST['remember_me'])) {
         $this->set_credentials($_POST['name'], $_POST['email'], $_POST['URL']);
     }
     $this->redirect_to(array('action' => 'thank_you'));
 }
 /**
  * Handles the paste password submission
  *
  * @param  string  $urlkey
  * @param  string  $hash
  * @return \Illuminate\Support\Facades\Redirect|null
  */
 public function postComment()
 {
     if (Site::config('general')->comments) {
         // Define validation rules
         $validator = Validator::make(Input::all(), array('comment' => 'required|auth|min:5|max:1024'));
         // Generate anti-spam modules
         $antispam = Antispam::make('comment', 'comment');
         // Run validations
         $resultValidation = $validator->passes();
         // Execute antispam services
         $resultAntispam = $antispam->passes();
         if ($resultValidation and $resultAntispam) {
             // Get the associated paste
             $paste = Paste::findOrFail(Input::get('id'));
             // Insert the new comment
             if (!is_null($paste)) {
                 $comment = new Comment();
                 $comment->paste_id = $paste->id;
                 $comment->data = nl2br(strip_tags(Input::get('comment')));
                 $comment->author = Auth::check() ? Auth::user()->username : Lang::get('global.anonymous');
                 $comment->timestamp = time();
                 $comment->save();
             }
             return Redirect::to(URL::previous());
         } else {
             // Set the error message as flashdata
             if (!$resultValidation) {
                 Session::flash('messages.error', $validator->messages()->all('<p>:message</p>'));
             } else {
                 if (!$resultAntispam) {
                     Session::flash('messages.error', $antispam->message());
                 }
             }
             return Redirect::to(URL::previous())->withInput();
         }
     } else {
         App::abort(401);
         // Unauthorized
     }
 }
 /**
  * Handles POST requests to the antispam config form
  *
  * @access public
  * @return \Illuminate\Support\Facades\Redirect
  */
 public function postAntispam()
 {
     // Define Akismet key validation logic
     Validator::extend('akismet_key', function ($attribute, $value, $parameters) {
         $akismet = new Akismet(Request::url(), $value);
         return $akismet->isKeyValid();
     });
     // Define validation rules
     $validator = Validator::make(Input::all(), array('php_key' => 'required_if:flag_php,1', 'php_days' => 'required_if:flag_php,1|integer|between:0,255', 'php_score' => 'required_if:flag_php,1|integer|between:0,255', 'php_type' => 'required_if:flag_php,1|integer|between:0,255', 'flood_threshold' => 'required_if:flag_noflood,1|integer|between:0,60', 'akismet_key' => 'required_if:flag_akismet,1|akismet_key'));
     // Run the validator
     if ($validator->passes()) {
         $services = Antispam::services();
         $flags = array();
         // Convert the service flags to CSV
         foreach ($services as $service) {
             if (Input::has('flag_' . $service)) {
                 $flags[] = $service;
             }
         }
         // Inject flag data to the configuration
         $config = array_merge(Input::all(), array('services' => implode('|', $flags)));
         Site::config('antispam', $config);
         Session::flash('messages.success', Lang::get('admin.antispam_updated'));
         return Redirect::to('admin/antispam');
     } else {
         Session::flash('messages.error', $validator->messages()->all('<p>:message</p>'));
         return Redirect::to('admin/antispam')->withInput();
     }
 }
Beispiel #6
0
 /**
  *	@fn request_password
  *	@short Action method to send a new password to a registered user.
  */
 function request_password()
 {
     if (!Antispam::check_math()) {
         $this->flash(Antispam::random_comment(), 'error');
         $this->redirect_to(array('action' => 'lost_password'));
     }
     $user_factory = new User();
     $users = $user_factory->find_all(array('where_clause' => "`email` = '{$_POST['email']}'", 'limit' => 1));
     if (count($users) > 0) {
         $user = $users[0];
         $request = new PasswordRequest();
         $request->user_id = $user->id;
         $request->created_at = date("Y-m-d H:i:s");
         $request->hash = md5($request->created_at . $request->user_id . 'Questa non la sai');
         $request->save();
         $this->redirect_to(array('action' => 'request_sent'));
     }
     $this->flash(l('No such user'), 'error');
     $this->redirect_to(array('action' => 'lost_password'));
 }
Beispiel #7
0
 /**
  * แทรก tag ลงใน element เหมือนการใช้งาน innerHTML
  *
  * @param string $tag
  * @param array $attributes
  * @return \static
  */
 public function add($tag, $attributes = array())
 {
     $tag = strtolower($tag);
     if ($tag == 'groups' || $tag == 'groups-table') {
         $prop = array('class' => isset($attributes['class']) ? $attributes['class'] : 'item');
         if (isset($attributes['id'])) {
             $prop['id'] = $attributes['id'];
         }
         if (isset($attributes['label'])) {
             if (isset($attributes['for'])) {
                 $item = new static('div', $prop);
                 $item->add('label', array('innerHTML' => $attributes['label'], 'for' => $attributes['for']));
             } else {
                 $prop['title'] = $attributes['label'];
                 $item = self::fieldset($prop);
             }
         } else {
             $item = new static('div', $prop);
         }
         $this->rows[] = $item;
         $obj = $item->add('div', array('class' => 'input-' . $tag));
         $rows = array();
         $comment = array();
         if (empty($attributes['id'])) {
             $id = '';
             $name = '';
         } else {
             $id = ' id=' . $attributes['id'];
             $name = ' name=' . $attributes['id'] . '[]';
             $comment['id'] = 'result_' . $attributes['id'];
         }
         foreach ($attributes as $key => $value) {
             if ($key == 'comment') {
                 $comment['class'] = 'comment';
                 $comment['innerHTML'] = $value;
             } elseif ($key == 'checkbox' || $key == 'radio') {
                 foreach ($value as $v => $text) {
                     $chk = isset($attributes['value']) && in_array($v, $attributes['value']) ? ' checked' : '';
                     $rows[] = '<label>' . $text . '&nbsp;<input type=' . $key . $id . $name . $chk . ' value="' . $v . '"></label>';
                     $id = '';
                 }
             }
         }
         if (!empty($rows)) {
             $obj->appendChild(implode('&nbsp; ', $rows));
         }
         if (isset($attributes['comment'])) {
             $item->add('div', $comment);
         }
     } elseif ($tag == 'row') {
         $obj = new static('div', array('class' => 'row'));
         $this->rows[] = $obj;
     } elseif ($tag == 'radiogroups' || $tag == 'checkboxgroups') {
         $prop = array('class' => 'item');
         if (!empty($attributes['itemId'])) {
             $prop['id'] = $attributes['itemId'];
         }
         $obj = new static('div', $prop);
         $this->rows[] = $obj;
         if (isset($attributes['name'])) {
             $name = $attributes['name'];
         } elseif (isset($attributes['id'])) {
             $name = $tag == 'checkboxgroups' ? $attributes['id'] . '[]' : $attributes['id'];
         } else {
             $name = false;
         }
         if (isset($attributes['label']) && isset($attributes['id'])) {
             $obj->add('label', array('innerHTML' => $attributes['label'], 'for' => $attributes['id']));
         }
         $div = $obj->add('div', array('class' => $tag . (isset($attributes['labelClass']) ? ' ' . $attributes['labelClass'] : '') . (empty($attributes['multiline']) ? '' : ' multiline')));
         if (!empty($attributes['options']) && is_array($attributes['options'])) {
             foreach ($attributes['options'] as $v => $label) {
                 if (isset($attributes['value'])) {
                     if (is_array($attributes['value'])) {
                         $checked = isset($attributes['value']) && in_array($v, $attributes['value']);
                     } else {
                         $checked = isset($attributes['value']) && $v == $attributes['value'];
                     }
                 } else {
                     $checked = false;
                 }
                 $item = array('label' => $label, 'value' => $v, 'checked' => $checked);
                 if ($name) {
                     $item['name'] = $name;
                 }
                 if (isset($attributes['id'])) {
                     $item['id'] = $attributes['id'];
                     $result_id = $attributes['id'];
                     unset($attributes['id']);
                 }
                 if (isset($attributes['comment'])) {
                     $item['title'] = $attributes['comment'];
                 }
                 $div->add($tag == 'radiogroups' ? 'radio' : 'checkbox', $item);
             }
         }
         if (!empty($attributes['comment'])) {
             $obj->add('div', array('id' => 'result_' . $result_id, 'class' => 'comment', 'innerHTML' => $attributes['comment']));
         }
     } elseif ($tag == 'antispam') {
         $antispam = new Antispam();
         $attributes['antispamid'] = $antispam->getId();
         if (isset($attributes['value']) && $attributes['value'] === true) {
             $attributes['value'] = $antispam->getValue();
         }
         $obj = self::create($tag, $attributes);
         $this->rows[] = $obj;
         $this->rows[] = self::create('hidden', array('id' => $attributes['id'] . 'id', 'value' => $attributes['antispamid']));
     } elseif ($tag == 'ckeditor') {
         if (isset($attributes[$tag])) {
             $tag = $attributes[$tag];
             unset($attributes[$tag]);
         } else {
             $tag = 'textarea';
         }
         if (class_exists('Kotchasan\\CKEditor')) {
             $obj = new \Kotchasan\CKEditor($tag, $attributes);
         } else {
             $obj = self::create($tag, $attributes);
         }
         $this->rows[] = $obj;
     } else {
         $obj = self::create($tag, $attributes);
         $this->rows[] = $obj;
     }
     return $obj;
 }
 /**
  * Creates a new paste revision
  *
  * @return \Illuminate\Support\Facades\Redirect
  */
 public function postRevision()
 {
     $oldId = Input::get('id');
     // First and foremost, validate the ID of the revision
     if (Session::get('paste.revision') != $oldId) {
         App::abort(401);
         // Unauthorized
     }
     // Define validation rules. We don't validate the title and language
     // here as we don't allow to change that for a revision. Instead, we
     // will use the data from the old paste
     $validator = Validator::make(Input::all(), array('data' => 'required|auth', 'expire' => 'in:' . Paste::getExpiration('create', TRUE)));
     // Generate anti-spam modules
     $antispam = Antispam::make('paste', 'data');
     // Run validations
     $resultValidation = $validator->passes();
     // Execute antispam services
     $resultAntispam = $antispam->passes();
     if ($resultValidation and $resultAntispam) {
         // Get the paste being revised
         $oldPaste = Paste::findOrFail($oldId);
         // If the old paste's content is same as the revision,
         // we simply redirect to the old paste itself
         if (crc32($oldPaste->data) == crc32(Input::get('data'))) {
             return Redirect::to($oldPaste->urlkey);
         }
         // We use some data from the old paste
         $data = array('project' => $oldPaste->project, 'title' => $oldPaste->title, 'language' => $oldPaste->language, 'private' => NULL, 'password' => NULL, 'attachment' => NULL);
         // Merge it with the input to override the values the user submitted
         Input::merge($data);
         // All set, create the new revision
         $newPaste = Paste::createNew('web', Input::all());
         // We now need to update the revisions table. One entry will be
         // created for this revision. We will also create entries for
         // any past revisions and link it to this new paste
         $revData = array(array('paste_id' => $newPaste->id, 'urlkey' => $oldPaste->urlkey, 'author' => $oldPaste->author, 'timestamp' => $oldPaste->timestamp));
         foreach ($oldPaste->revisions as $revision) {
             $revData[] = array('paste_id' => $newPaste->id, 'urlkey' => $revision->urlkey, 'author' => $revision->author, 'timestamp' => $revision->timestamp);
         }
         // Now insert this batch data to the revisions table
         Revision::insert($revData);
         // Whoa, finally we are done, take the user to the shiny new
         // paste. Since this is a public paste, we don't need the url
         // hash or password shebang
         return Redirect::to($newPaste->urlkey);
     } else {
         // Set the error message as flashdata
         if (!$resultValidation) {
             Session::flash('messages.error', $validator->messages()->all('<p>:message</p>'));
         } else {
             if (!$resultAntispam) {
                 Session::flash('messages.error', $antispam->message());
             }
         }
     }
     return Redirect::to(URL::previous())->withInput();
 }
Beispiel #9
0
 /**
  *	@fn init_math_test
  *	@short Filter method that initializes the Antispam math test for commenting articles.
  */
 protected function init_math_test()
 {
     Antispam::init_math_test();
 }
Beispiel #10
0
 /**
  *	@fn test_get_spam_signature
  *	@short Test method for get_spam_signature.
  */
 public function test_get_spam_signature()
 {
     $this->assertEquals(FIXTURE_ANTISPAM_SPAM_TEXT_SIGNATURE, Antispam::get_spam_signature(FIXTURE_ANTISPAM_SPAM_TEXT), 'Bad signature');
 }
Beispiel #11
0
					</div>
				</div>
				<p class="form-left">
					<label class="left-aligned required" for="f_text"><?php 
echo l("Message");
?>
</label>
					<textarea name="text" id="f_text" rows="10" cols="48"></textarea>
				</p>
				<p class="form-left padded-to-label">
					<label for="f_antispam_math_result" class="required">
						<?php 
echo l("Antispam question:");
?>
						<?php 
Antispam::init_math_test();
echo Antispam::$first_operand;
?>
 +
						<?php 
echo Antispam::$second_operand;
?>
 = ?
					</label>
					<input type="text" aria-required="true" name="antispam_math_result" id="f_antispam_math_result" size="3" />
				</p>
				<p class="lighter padded-to-label">
					<?php 
echo l("An asterisk (*) denotes a required field.");
?>
				</p>
Beispiel #12
0
 /**
  *	@fn software_comment_mark_as_spam
  *	@short Action method to mark a software comment as spam.
  */
 public function software_comment_mark_as_spam()
 {
     if ($this->request->is_post()) {
         if (!empty($_POST['id'])) {
             $comment = new SoftwareComment();
             $comment->find_by_id($_REQUEST['id']);
             if (!Antispam::check_spam_signature($comment->text)) {
                 Antispam::store_spam_signature($comment->text);
             }
         }
         $this->render(NULL);
     }
 }
Beispiel #13
0
 /**
  *	@fn init_math_test
  *	@short Initializes the mathematical test to tell humans and machines apart.
  */
 public static function init_math_test()
 {
     self::$first_operand = rand(0, 10);
     self::$second_operand = rand(0, 10);
     $_SESSION['antispam_math'] = array(self::$first_operand, self::$second_operand);
 }
Beispiel #14
0
 /**
  * Runs all of the validation checks on the elements using the
  * validatiors that are stored
  *
  * @return bool
  */
 public function isValid()
 {
     if ($this->csrfToken === true && !$this->_input->checkToken()) {
         // CSRF protection failed!
         if ($this->storeErrors === true) {
             $this->_event->error(Input::csrfMsg());
         }
         return false;
     }
     foreach ($this->elements as $element) {
         try {
             $value = $this->_input->get($element['input_name'], $element['source']);
         } catch (Input_KeyNoExist $e) {
             if ($element['required'] === true) {
                 throw $e;
             } else {
                 continue;
             }
         }
         // Store the input names value correclty as a multi-dimensional array
         $tmpVal = $value;
         foreach (array_reverse(preg_split('#(?<!\\\\)/#', trim($element['input_name'], '/'))) as $v) {
             $tmpVal = array($v => $tmpVal);
         }
         $this->values = zula_merge_recursive($this->values, $tmpVal);
         $count = is_array($value) ? count($value) : strlen($value);
         if ($element['required'] === false && $count == 0) {
             continue;
         }
         // Check if it is valid
         $validator = new Validator($value, $element['title']);
         foreach (array_filter($element['validators']) as $tmpValidator) {
             $validator->add($tmpValidator);
         }
         if ($validator->validate() === false) {
             $this->valid = false;
             if ($this->storeErrors === true) {
                 // Store all errors (if any)
                 foreach ($validator->getErrors() as $error) {
                     $this->_event->error($error);
                 }
             }
         }
     }
     // Check if the antispam was successful, if enabled
     if ($this->valid && $this->antispam === true) {
         $antispam = new Antispam();
         if (!$antispam->check()) {
             $this->valid = false;
             if ($this->storeErrors === true) {
                 $this->_event->error(t('Sorry, incorrect answer to the captcha', I18n::_DTD));
             }
         }
     }
     return $this->valid;
 }
Beispiel #15
0
<?php

require_once 'connexion.class.php';
require_once 'antispam.class.php';
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
    $ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
    $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
    $ip = $_SERVER['REMOTE_ADDR'];
}
$spamm = new Antispam();
$return_arr["status"] = $spamm->antispam($ip) ? "success" : "fail";
$return_arr["timeleft"] = $spamm->timeLeft($ip);
echo json_encode($return_arr);
exit;
Beispiel #16
0
<?php

require_once 'connexion.class.php';
require_once 'antispam.class.php';
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
    $ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
    $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
    $ip = $_SERVER['REMOTE_ADDR'];
}
$spamm = new Antispam();
$return_arr["status"] = $spamm->antispam($ip) ? "success" : "fail";
echo json_encode($return_arr);
exit;
 /**
  * Searches for a paste by its content
  *
  * @access public
  * @param  string  $term
  * @return \Illuminate\Support\Facades\View
  */
 public function getSearch()
 {
     $term = Input::get('q');
     $config = Site::config('general');
     // Initialize the antispam filters
     $antispam = Antispam::make('search', 'q');
     if ($config->pasteSearch and strlen($term) >= 5) {
         if ($antispam->passes() or Session::has('search.exempt')) {
             // Show all pastes to admins
             if (Auth::roles()->admin) {
                 $query = Paste::query();
             } else {
                 $query = Paste::where('private', '<>', 1);
             }
             // Append the search term
             $query = $query->where('data', 'like', "%{$term}%");
             // Filter by project
             if (!empty($this->project)) {
                 $query = $query->where('project', $this->project);
             }
             // Get number of results to show per page
             $perPage = $config->perPage;
             // Query the search results
             $pastes = $query->orderBy('id', 'desc')->paginate($perPage);
             // Append the search term to pagination URLs
             $pastes->appends('q', $term);
             // We will not run antispam if it passed once and there are
             // multiple pages. But we exempt it only for the next request.
             Session::flash('search.exempt', $perPage > $pastes->count());
             return $this->getList($pastes, TRUE);
         } else {
             Session::flash('messages.error', $antispam->message());
         }
     }
     return Redirect::to('all')->withInput();
 }
 /**
  * Creates a new paste via the API
  *
  * @param  string  $mode
  * @return \Illuminate\Support\Facades\View
  */
 public function postCreate($mode)
 {
     $api = API::make($mode);
     // Set custom messages for validation module
     $custom = array('title.max' => 'title_max_30', 'data.required' => 'data_required', 'data.auth' => 'cannot_post', 'data.mbmax' => 'data_too_big', 'language.required' => 'lang_required', 'language.in' => 'lang_invalid', 'expire.integer' => 'expire_integer', 'expire.in' => 'expire_invalid');
     // Define validation rules
     $validator = Validator::make(Input::all(), array('title' => 'max:30', 'data' => 'required|auth|mbmax:' . Site::config('general')->maxPasteSize, 'language' => 'required|in:' . Highlighter::make()->languages(TRUE), 'expire' => 'integer|in:' . Paste::getExpiration('create', TRUE)), $custom);
     // Run validations
     if ($validator->fails()) {
         return $api->error($validator->messages()->first());
     }
     // Set custom messages for the antispam module
     $custom = array('ipban' => 'antispam_ipban', 'stealth' => 'antispam_stealth', 'censor' => 'antispam_censor', 'noflood' => 'antispam_noflood', 'php' => 'antispam_php');
     // Instantiate the antispam module
     $antispam = Antispam::make('api_call', 'data', $custom);
     // Run the anti-spam modules
     if ($antispam->fails()) {
         return $api->error($antispam->message());
     }
     // Create the paste like a boss!
     $paste = Paste::createNew('api', Input::all());
     // All done! Now we need to output the urlkey and hash
     $data = array('urlkey' => $paste->urlkey, 'hash' => $paste->hash);
     // Return the output
     return $api->out('create', $data);
 }
 /**
  *	@fn post_comment
  *	@short Action method that receives a comment for a software product.
  */
 public function post_comment()
 {
     $conn = Db::get_connection();
     if (!$this->request->is_post()) {
         $this->redirect_to(array('action' => 'index'));
     }
     $software = new Software();
     if ($software->find_by_id($_POST['software_id']) === FALSE) {
         $this->flash(l('No such software'), 'error');
         $this->redirect_to(array('action' => 'index'));
     }
     if (!Email::is_valid($_POST['email'])) {
         $this->flash(l('Please enter a valid email address'), 'error');
         $this->redirect_to($software->comments_permalink());
     }
     if (!Antispam::check_math()) {
         $this->flash(Antispam::random_comment(), 'error');
         $this->redirect_to($software->comments_permalink());
     }
     // A static class method would be infinitely better...
     $comment = new SoftwareComment($_POST);
     $comment->created_at = date('Y-m-d H:i:s');
     $comment->save();
     // Send an email to notify this comment
     $email = new SoftwareCommentEmail(array('comment' => $comment, 'name' => $_POST['author'], 'email' => $_POST['email'], 'URL' => $_POST['URL']));
     $email->send();
     if (isset($_POST['remember_me'])) {
         $this->set_credentials($_POST['author'], $_POST['email'], $_POST['URL']);
     }
     // Expires the cache of Comments feed
     $this->expire_cached_page(array('controller' => 'feed', 'action' => 'software_comments', 'id' => $_POST['software_id']));
     $this->redirect_to_software_page(array('id' => $_POST['software_id'], 'subview' => 'comments', 'hash' => 'comment-' . $comment->id));
     Db::close_connection($conn);
 }
Beispiel #20
0
<?php

/**
 * Zula Framework
 * --- Creates the antispam captcha image to be displayed to the user via the
 * hard-coded 'antispam/captcha/{id}' route'
 *
 * @patches submit all patches to patches@tangocms.org
 *
 * @author Alex Cartwright
 * @copyright Copyright (C) 2010 Alex Cartwright
 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html GNU/LGPL 2.1
 * @package Zula
 */
$captchaId = substr($rawRequestPath, 17);
if (isset($_SESSION['antispam']['captcha'][$captchaId])) {
    $antispam = new Antispam('captcha');
    $antispam->outputPng($_SESSION['antispam']['captcha'][$captchaId]);
    return true;
}
// Will only ever occur if something goes wrong up there.
header('HTTP/1.1 404 Not Found', true, 404);
return false;