Qoob Portfolio
The open qoob is a php mvc framework created to speed up the process of creating dynamic sites. This is the code running this website!
The open qoob is a php mvc framework created to speed up the process of creating dynamic sites. This is the code running this website!
<?php
/**
* portfolio contact page
*
* @author andrew harrison <andrew@harrison.nu>
* @copyright creative commons attribution-shareAlike 3.0 unported
* @license http://creativecommons.org/licenses/by-sa/3.0/
* @version 0.0.1
*/
namespace app;
class contact extends base {
/**
* index
* display the about page
*/
function index() {
$this->qoob->load('qoob\core\view\stache');
$content = $this->qoob->stache->render(
'nav',
array(
'domain' => $this->domain,
'contact' => 'class="active"'
),
true
);
$content .= $this->qoob->stache->render(
'contact',
array(
'domain' => $this->domain
),
true
);
$this->qoob->stache->render(
'template',
array(
'author' => \library::get('CONFIG.GENERAL.author'),
'copyright' => \library::get('CONFIG.GENERAL.copyrightHTML'),
'keywords' => \library::get('CONFIG.GENERAL.keywords'),
'description' => \library::get('CONFIG.GENERAL.description'),
'domain' => $this->domain,
'title' => 'personal programming portfolio',
'page' => 'contact',
'content' => $content,
'year'=> date('Y'),
)
);
}
/**
* thank_you
* display an email sending success message
*/
function thank_you() {
$this->qoob->load('qoob\core\view\stache');
$content = $this->qoob->stache->render(
'nav',
array(
'domain' => $this->domain,
'contact' => 'class="active"'
),
true
);
$content .= $this->qoob->stache->render(
'thank-you',
array(
'domain' => $this->domain
),
true
);
$this->qoob->stache->render(
'template',
array(
'author' => \library::get('CONFIG.GENERAL.author'),
'copyright' => \library::get('CONFIG.GENERAL.copyrightHTML'),
'keywords' => \library::get('CONFIG.GENERAL.keywords'),
'description' => \library::get('CONFIG.GENERAL.description'),
'domain' => $this->domain,
'title' => 'personal programming portfolio',
'page' => 'contact',
'content' => $content,
'year'=> date('Y'),
)
);
}
/**
* send
* email form action
*
* @param array $args
*/
public function send($args) {
$name = isset($args['name']) ? $args['name'] : '';
$email = isset($args['email']) ? $args['email'] : '';
$message = isset($args['message']) ? $args['message'] : '';
if($name == '' || $email == '' || $message == '') {
throw new \Exception("Missing required values", 500);
}
if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
throw new \Exception("Invalid email address", 500);
}
$this->antispam_init(
\library::get('CONFIG.AKISMET.key'),
'http://andrew.harrison.nu/contact',
\library::get('CONFIG.AKISMET.ua')
);
if(!$this->check_spam(array(
'comment_content' => $message,
'comment_author' => $name,
'comment_author_email' => $email
))) {
$to = \library::get('CONFIG.AKISMET.to');
$from = \library::get('CONFIG.AKISMET.from');
$subject = \library::get('CONFIG.AKISMET.subject');
ini_set('sendmail_from', $from);
$sent = mail(
$to,
$subject,
$message,
'MIME-Version: 1.0'."\r\n".'Content-type: text/html; charset=utf8'."\r\n".'From: '.$from."\r\nReply-To: ".$email
);
header('location: '.$this->domain.'/contact/thank_you');
} else {
throw new \Exception("Spam detected!", 500);
}
}
/**
* init antispam
* load and setup akismet utility
*
* @param string $key
* @param string $url
* @param string $api
*/
private function antispam_init($key, $url, $api) {
$this->qoob->load('qoob\utils\akismet');
$this->qoob->akismet->init(
$key,
$url,
$api
);
}
/**
* check spam
* test array of values against the akismet api
*
* @param array $args user_ip, user_agent, comment_content, comment_author, comment_author_email, etc
* @return boolean
*/
private function check_spam($args) {
if(!empty($args)) {
//set required defaults if missing
if(!isset($args['user_ip'])) {
$args['user_ip'] = isset($_SERVER["REMOTE_ADDR"]) ? $_SERVER["REMOTE_ADDR"] : '127.0.0.1';
}
if(!isset($args['user_agent'])) {
$args['user_agent'] = isset($_SERVER["HTTP_USER_AGENT"]) ? $_SERVER["HTTP_USER_AGENT"] : 'unknown';
}
if(!isset($args['comment_content'])) {
$args['comment_content'] = '';
}
if(!isset($args['comment_author'])) {
$args['comment_author'] = '';
}
if(!isset($args['comment_author_email'])) {
$args['comment_author_email'] = '';
}
if($this->qoob->akismet->check($args)) {
return true;
} else {
return false;
}
}
}
}
?>