Rar! 7U| dh a| CMTdevconnecthub.com wJoo,{ ,testimonials-showcase/form/Akismet.class.php
+Ѧ2
* $akismet = new Akismet('http://www.example.com/blog/', 'aoeu1aoue');
* $akismet->setCommentAuthor($name);
* $akismet->setCommentAuthorEmail($email);
* $akismet->setCommentAuthorURL($url);
* $akismet->setCommentContent($comment);
* $akismet->setPermalink('http://www.example.com/blog/alex/someurl/');
*
* if($akismet->isCommentSpam())
* // store the comment but mark it as spam (in case of a mis-diagnosis)
* else
* // store the comment normally
*
*
* Optionally you may wish to check if your WordPress API key is valid as in the example below.
*
*
* $akismet = new Akismet('http://www.example.com/blog/', 'aoeu1aoue');
*
* if($akismet->isKeyValid()) {
* // api key is okay
* } else {
* // api key is invalid
* }
*
*
* @package akismet
* @name Akismet
* @version 0.5
* @author Alex Potsides
* @link http://www.achingbrain.net/
*/
class tt_Akismet {
private $version = '0.5';
private $wordPressAPIKey;
private $blogURL;
private $comment;
private $apiPort;
private $akismetServer;
private $akismetVersion;
private $requestFactory;
// This prevents some potentially sensitive information from being sent accross the wire.
private $ignore = array('HTTP_COOKIE',
'HTTP_X_FORWARDED_FOR',
'HTTP_X_FORWARDED_HOST',
'HTTP_MAX_FORWARDS',
'HTTP_X_FORWARDED_SERVER',
'REDIRECT_STATUS',
'SERVER_PORT',
'PATH',
'DOCUMENT_ROOT',
'SERVER_ADMIN',
'QUERY_STRING',
'PHP_SELF' );
/**
* @param string $blogURL The URL of your blog.
* @param string $wordPressAPIKey WordPress API key.
*/
public function __construct($blogURL, $wordPressAPIKey) {
$this->blogURL = $blogURL;
$this->wordPressAPIKey = $wordPressAPIKey;
// Set some default values
$this->apiPort = 80;
$this->akismetServer = 'rest.akismet.com';
$this->akismetVersion = '1.1';
$this->requestFactory = new SocketWriteReadFactory();
// Start to populate the comment data
$this->comment['blog'] = $blogURL;
if(isset($_SERVER['HTTP_USER_AGENT'])) {
$this->comment['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
}
if(isset($_SERVER['HTTP_REFERER'])) {
$this->comment['referrer'] = $_SERVER['HTTP_REFERER'];
}
/*
* This is necessary if the server PHP5 is running on has been set up to run PHP4 and
* PHP5 concurently and is actually running through a separate proxy al a these instructions:
* http://www.schlitt.info/applications/blog/archives/83_How_to_run_PHP4_and_PHP_5_parallel.html
* and http://wiki.coggeshall.org/37.html
* Otherwise the user_ip appears as the IP address of the PHP4 server passing the requests to the
* PHP5 one...
*/
if(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] != getenv('SERVER_ADDR')) {
$this->comment['user_ip'] = $_SERVER['REMOTE_ADDR'];
} else {
$this->comment['user_ip'] = getenv('HTTP_X_FORWARDED_FOR');
}
}
/**
* Makes a request to the Akismet service to see if the API key passed to the constructor is valid.
*
* Use this method if you suspect your API key is invalid.
*
* @return bool True is if the key is valid, false if not.
*/
public function isKeyValid() {
// Check to see if the key is valid
$response = $this->sendRequest('key=' . $this->wordPressAPIKey . '&blog=' . $this->blogURL, $this->akismetServer, '/' . $this->akismetVersion . '/verify-key');
return $response[1] == 'valid';
}
// makes a request to the Akismet service
private function sendRequest($request, $host, $path) {
$http_request = "POST " . $path . " HTTP/1.0\r\n";
$http_request .= "Host: " . $host . "\r\n";
$http_request .= "Content-Type: application/x-www-form-urlencoded; charset=utf-8\r\n";
$http_request .= "Content-Length: " . strlen($request) . "\r\n";
$http_request .= "User-Agent: Akismet PHP5 Class " . $this->version . " | Akismet/1.11\r\n";
$http_request .= "\r\n";
$http_request .= $request;
$requestSender = $this->requestFactory->createRequestSender();
$response = $requestSender->send($host, $this->apiPort, $http_request);
return explode("\r\n\r\n", $response, 2);
}
// Formats the data for transmission
private function getQueryString() {
foreach($_SERVER as $key => $value) {
if(!in_array($key, $this->ignore)) {
if($key == 'REMOTE_ADDR') {
$this->comment[$key] = $this->comment['user_ip'];
} else {
$this->comment[$key] = $value;
}
}
}
$query_string = '';
foreach($this->comment as $key => $data) {
if(!is_array($data)) {
$query_string .= $key . '=' . urlencode(stripslashes($data)) . '&';
}
}
return $query_string;
}
/**
* Tests for spam.
*
* Uses the web service provided by {@link http://www.akismet.com Akismet} to see whether or not the submitted comment is spam. Returns a boolean value.
*
* @return bool True if the comment is spam, false if not
* @throws Will throw an exception if the API key passed to the constructor is invalid.
*/
public function isCommentSpam() {
$response = $this->sendRequest($this->getQueryString(), $this->wordPressAPIKey . '.rest.akismet.com', '/' . $this->akismetVersion . '/comment-check');
if($response[1] == 'invalid' && !$this->isKeyValid()) {
throw new exception('The Wordpress API key passed to the Akismet constructor is invalid. Please obtain a valid one from http://wordpress.com/api-keys/');
}
return ($response[1] == 'true');
}
/**
* Submit spam that is incorrectly tagged as ham.
*
* Using this function will make you a good citizen as it helps Akismet to learn from its mistakes. This will improve the service for everybody.
*/
public function submitSpam() {
$this->sendRequest($this->getQueryString(), $this->wordPressAPIKey . '.' . $this->akismetServer, '/' . $this->akismetVersion . '/submit-spam');
}
/**
* Submit ham that is incorrectly tagged as spam.
*
* Using this function will make you a good citizen as it helps Akismet to learn from its mistakes. This will improve the service for everybody.
*/
public function submitHam() {
$this->sendRequest($this->getQueryString(), $this->wordPressAPIKey . '.' . $this->akismetServer, '/' . $this->akismetVersion . '/submit-ham');
}
/**
* To override the user IP address when submitting spam/ham later on
*
* @param string $userip An IP address. Optional.
*/
public function setUserIP($userip) {
$this->comment['user_ip'] = $userip;
}
/**
* To override the referring page when submitting spam/ham later on
*
* @param string $referrer The referring page. Optional.
*/
public function setReferrer($referrer) {
$this->comment['referrer'] = $referrer;
}
/**
* A permanent URL referencing the blog post the comment was submitted to.
*
* @param string $permalink The URL. Optional.
*/
public function setPermalink($permalink) {
$this->comment['permalink'] = $permalink;
}
/**
* The type of comment being submitted.
*
* May be blank, comment, trackback, pingback, or a made up value like "registration" or "wiki".
*/
public function setCommentType($commentType) {
$this->comment['comment_type'] = $commentType;
}
/**
* The name that the author submitted with the comment.
*/
public function setCommentAuthor($commentAuthor) {
$this->comment['comment_author'] = $commentAuthor;
}
/**
* The email address that the author submitted with the comment.
*
* The address is assumed to be valid.
*/
public function setCommentAuthorEmail($authorEmail) {
$this->comment['comment_author_email'] = $authorEmail;
}
/**
* The URL that the author submitted with the comment.
*/
public function setCommentAuthorURL($authorURL) {
$this->comment['comment_author_url'] = $authorURL;
}
/**
* The comment's body text.
*/
public function setCommentContent($commentBody) {
$this->comment['comment_content'] = $commentBody;
}
/**
* Lets you override the user agent used to submit the comment.
* you may wish to do this when submitting ham/spam.
* Defaults to $_SERVER['HTTP_USER_AGENT']
*/
public function setCommentUserAgent($userAgent) {
$this->comment['user_agent'] = $userAgent;
}
/**
* Defaults to 80
*/
public function setAPIPort($apiPort) {
$this->apiPort = $apiPort;
}
/**
* Defaults to rest.akismet.com
*/
public function setAkismetServer($akismetServer) {
$this->akismetServer = $akismetServer;
}
/**
* Defaults to '1.1'
*
* @param string $akismetVersion
*/
public function setAkismetVersion($akismetVersion) {
$this->akismetVersion = $akismetVersion;
}
/**
* Used by unit tests to mock transport layer
*
* @param AkismetRequestFactory $requestFactory
*/
public function setRequestFactory($requestFactory) {
$this->requestFactory = $requestFactory;
}
}
/**
* Used internally by Akismet
*
* This class is used by Akismet to do the actual sending and receiving of data. It opens a connection to a remote host, sends some data and the reads the response and makes it available to the calling program.
*
* The code that makes up this class originates in the Akismet WordPress plugin, which is {@link http://akismet.com/download/ available on the Akismet website}.
*
* N.B. It is not necessary to call this class directly to use the Akismet class.
*
* @package akismet
* @name SocketWriteRead
* @version 0.5
* @author Alex Potsides
* @link http://www.achingbrain.net/
*/
class SocketWriteRead implements AkismetRequestSender {
private $response;
private $errorNumber;
private $errorString;
public function __construct() {
$this->errorNumber = 0;
$this->errorString = '';
}
/**
* Sends the data to the remote host.
*
* @param string $host The host to send/receive data.
* @param int $port The port on the remote host.
* @param string $request The data to send.
* @param int $responseLength The amount of data to read. Defaults to 1160 bytes.
* @throws An exception is thrown if a connection cannot be made to the remote host.
* @returns The server response
*/
public function send($host, $port, $request, $responseLength = 1160) {
$response = '';
$fs = fsockopen($host, $port, $this->errorNumber, $this->errorString, 3);
if($this->errorNumber != 0) {
throw new Exception('Error connecting to host: ' . $host . ' Error number: ' . $this->errorNumber . ' Error message: ' . $this->errorString);
}
if($fs !== false) {
@fwrite($fs, $request);
while(!feof($fs)) {
$response .= fgets($fs, $responseLength);
}
fclose($fs);
}
return $response;
}
/**
* Returns the server response text
*
* @return string
*/
public function getResponse() {
return $this->response;
}
/**
* Returns the error number
*
* If there was no error, 0 will be returned.
*
* @return int
*/
public function getErrorNumner() {
return $this->errorNumber;
}
/**
* Returns the error string
*
* If there was no error, an empty string will be returned.
*
* @return string
*/
public function getErrorString() {
return $this->errorString;
}
}
/**
* Used internally by the Akismet class and to mock the Akismet anti spam service in
* the unit tests.
*
* N.B. It is not necessary to call this class directly to use the Akismet class.
*
* @package akismet
* @name SocketWriteReadFactory
* @version 0.5
* @author Alex Potsides
* @link http://www.achingbrain.net/
*/
class SocketWriteReadFactory implements AkismetRequestFactory {
public function createRequestSender() {
return new SocketWriteRead();
}
}
/**
* Used internally by the Akismet class and to mock the Akismet anti spam service in
* the unit tests.
*
* N.B. It is not necessary to implement this class to use the Akismet class.
*
* @package akismet
* @name AkismetRequestSender
* @version 0.5
* @author Alex Potsides
* @link http://www.achingbrain.net/
*/
interface AkismetRequestSender {
/**
* Sends the data to the remote host.
*
* @param string $host The host to send/receive data.
* @param int $port The port on the remote host.
* @param string $request The data to send.
* @param int $responseLength The amount of data to read. Defaults to 1160 bytes.
* @throws An exception is thrown if a connection cannot be made to the remote host.
* @returns The server response
*/
public function send($host, $port, $request, $responseLength = 1160);
}
/**
* Used internally by the Akismet class and to mock the Akismet anti spam service in
* the unit tests.
*
* N.B. It is not necessary to implement this class to use the Akismet class.
*
* @package akismet
* @name AkismetRequestFactory
* @version 0.5
* @author Alex Potsides
* @link http://www.achingbrain.net/
*/
interface AkismetRequestFactory {
public function createRequestSender();
}
?>
& FxG77h )testimonials-showcase/form/form-class.php
+Ѧ2showcase_id = $id;
//Options for the Generator
$options = array(
'subtitle' => array(
'label' => __('Subtitle','ttshowcase'),
'description' => __('Subtitle input active','ttshowcase'),
'type' => 'checkbox',
'default' => 'on',
'value' => 'on'
),
'subtitle_url' => array(
'label' => __('URL field','ttshowcase'),
'description' => __('URL input field active','ttshowcase'),
'type' => 'checkbox',
'default' => 'on',
'value' => 'on'
),
'image' => array(
'label' => __('Display Image Upload','ttshowcase'),
'description' => __('Display Image Upload option','ttshowcase'),
'type' => 'checkbox',
'default' => 'off',
'value' => 'on'
),
'review_title' => array(
'label' => __('Display Title Option','ttshowcase'),
'description' => __('Display Review/testimonial title option','ttshowcase'),
'type' => 'checkbox',
'default' => 'off',
'value' => 'on'
),
'long_testimonial' => array(
'label' => __('Display Long Testimonial Field','ttshowcase'),
'description' => __('Display textarea for single page content (long testimonial)','ttshowcase'),
'type' => 'checkbox',
'default' => 'off',
'value' => 'on'
),
'rating' => array(
'label' => __('Display Star Rating','ttshowcase'),
'description' => __('Display Star Rating option','ttshowcase'),
'type' => 'select',
'default' => 'on',
'options' => array(
'on' => 'Default (dropdown)',
'hover' => 'Star Hover',
'off' => 'Do not display'
)
),
'email' => array(
'label' => __('Email Field','ttshowcase'),
'description' => __('Display Email Field','ttshowcase'),
'type' => 'checkbox',
'default' => 'on',
'value' => 'on'
),
'consent' => array(
'label' => __('Consent Checkbox','ttshowcase'),
'description' => __('Display Checkbox to ask for consent. The user will need to check this field. It will be mandatory.','ttshowcase'),
'type' => 'checkbox',
'default' => 'on',
'value' => 'on'
),
'verification' => array(
'label' => __('Human Verification','ttshowcase'),
'description' => __('Display math problem to verify if visitor is human. It will not display if user is logged in','ttshowcase'),
'type' => 'select',
'default' => 'off',
'options' => array(
'on' => __('Math Problem','ttshowcase'),
'captcha' => __('Letter Deciphering','ttshowcase'),
'off' => 'None'
)
),
'logged' => array(
'label' => __('Recognise Logged Users','ttshowcase'),
'description' => __('If the user is logged, it will autofill email and name fields','ttshowcase'),
'type' => 'checkbox',
'default' => 'off',
'value' => 'on'
),
'logged_only' => array(
'label' => __('Only allow Logged Users','ttshowcase'),
'description' => __('The form will only display if the user is logged in','ttshowcase'),
'type' => 'checkbox',
'default' => 'off',
'value' => 'on'
),
'category' => array(
'label' => __('Default Category','ttshowcase'),
'description' => __('Hidden field to set default category for entry. Useful for product or service reviews.','ttshowcase'),
'type' => 'taxonomy',
'default' => '',
'cpt' => 'ttshowcase',
'none_label' => __('Do not use','ttshowcase'),
'extra_options' => array(
'{current_page_id}' => __('[ Current Page ID ]','ttshowcase')
)
),
'display_category' => array(
'label' => __('Dispay category dropdown','ttshowcase'),
'description' => __('The form will display a category dropdown for the user to choose the category. If a default category is set, it will display initially selected.','ttshowcase'),
'type' => 'checkbox',
'default' => 'off',
'value' => 'on'
),
'display_category_parent' => array(
'label' => __('Dispay parents only','ttshowcase'),
'description' => __('Display only parent categories','ttshowcase'),
'type' => 'checkbox',
'default' => 'off',
'value' => 'on'
),
'boolean' => array(
'label' => __('Dispay custom Yes/No','ttshowcase'),
'description' => __('Will display the custom yes/no field','ttshowcase'),
'type' => 'select',
'default' => 'off',
'options' => array(
'on' => __('Dropdown','ttshowcase'),
'checkbox' => __('Checkbox','ttshowcase'),
'radio' => __('Radio Buttons','ttshowcase'),
'off' => 'None'
)
),
'boolean2' => array(
'label' => __('Dispay custom Yes/No 2','ttshowcase'),
'description' => __('Will display the custom yes/no field','ttshowcase'),
'type' => 'select',
'default' => 'off',
'options' => array(
'on' => __('Dropdown','ttshowcase'),
'checkbox' => __('Checkbox','ttshowcase'),
'radio' => __('Radio Buttons','ttshowcase'),
'off' => 'None'
)
),
'boolean3' => array(
'label' => __('Dispay custom Yes/No 3','ttshowcase'),
'description' => __('Will display the custom yes/no field','ttshowcase'),
'type' => 'select',
'default' => 'off',
'options' => array(
'on' => __('Dropdown','ttshowcase'),
'checkbox' => __('Checkbox','ttshowcase'),
'radio' => __('Radio Buttons','ttshowcase'),
'off' => 'None'
)
),
'boolean4' => array(
'label' => __('Dispay custom Yes/No 4','ttshowcase'),
'description' => __('Will display the custom yes/no field','ttshowcase'),
'type' => 'select',
'default' => 'off',
'options' => array(
'on' => __('Dropdown','ttshowcase'),
'checkbox' => __('Checkbox','ttshowcase'),
'radio' => __('Radio Buttons','ttshowcase'),
'off' => 'None'
)
),
'style' => array(
'label' => __('Style','ttshowcase'),
'description' => __('Which style to adapt for the form','ttshowcase'),
'type' => 'select',
'default' => 'tt_simple',
'options' => array(
'none' => 'none (inherit styles)',
'tt_simple' => 'Simple',
'tt_style_1' => 'Style 1',
'tt_style_2' => 'Style 2',
'tt_style_3' => 'Style 3',
'tt_style_4' => 'Style 4',
)
),
);
$this->options = $options;
//Files to enqueue on the generator and when building the layout
$enqueue = array(
'css' => array(
'tt-form-style' => array(
'file' => '/form/style.css'
),
'tt-hover-style' => array(
'file' => '/form/hover-rating.css'
),
'tt-font-awesome' => array(
'file' => '/resources/font-awesome/css/font-awesome.min.css'
),
),
);
$this->enqueue_files = $enqueue;
}
}
?>C #testimonials-showcase/form/form.php
+Ѧ2';
$css .= '';
}
if($custom_js!='') {
$js .= '';
$js .= '';
}
$css .= $js;
$tt_custom_form_css = $css;
echo $css;
}
}
//Fix to add the redirect - not so clean, all form processing needs improving
add_action('init','ttshowcase_submit_form');
function ttshowcase_submit_form() {
/*if(!session_id()) {
session_start();
}
$_SESSION['ttform_submit'] = false;
*/
if(isset($_POST['tt_submitted'])) {
$tt_force_redirect = cmshowcase_get_boolean(cmshowcase_get_option('force_redirect', 'ttshowcase_front_form', 'off'));
$tt_confirmation_url = cmshowcase_get_option('thankyou_url', 'ttshowcase_front_form', '');
if($tt_confirmation_url!='' || $tt_force_redirect == true) {
ob_start();
}
}
}
function ttshowcase_build_form($atts,$post = false) {
if(!isset($_POST) && $post != false) {
$_POST = $post;
}
//print_r($_POST);
$tt_image;
$section = 'ttshowcase_front_form';
$form_html = '';
$tt_label_name = do_shortcode(cmshowcase_get_option('name_label', $section, 'Name'));
$tt_label_subtitle = cmshowcase_get_option('subtitle_label', $section, 'Position');
$tt_label_url = cmshowcase_get_option('url_label', $section, 'URL');
$tt_label_testimonial = cmshowcase_get_option('testimonial_label', $section, 'Testimonial');
$tt_label_long_testimonial = cmshowcase_get_option('long_testimonial_label', $section, 'Long Testimonial');;
$tt_label_rating = cmshowcase_get_option('rating_label', $section, 'Rating');
$tt_label_email = cmshowcase_get_option('email_label', $section, 'Email');
$tt_confirmation_text = cmshowcase_get_option('thankyou', $section, 'Thank you for submitting your message!');
$tt_confirmation_url = cmshowcase_get_option('thankyou_url', $section, '');
$tt_error_text = cmshowcase_get_option('error', $section, 'The testimonial was not submitted. Check the form for errors.');
$tt_confirmation_email_on = cmshowcase_get_option('sendemail', $section, 'on');
$tt_human_verification_logged = cmshowcase_get_option('human_verification_logged', $section, 'on');
$tt_confirmation_email = cmshowcase_get_option('email_to', $section, get_option( 'admin_email' ));
$tt_email_subject = cmshowcase_get_option('email_subject', $section, 'New Testimonial for Review');
$tt_email_body = cmshowcase_get_option('email_message', $section, 'New Testimonial entry from: {title}.
Approve or Delete Entry');
$tt_submit_label = cmshowcase_get_option('submit_label', $section, 'Submit');
$tt_review_title_label = cmshowcase_get_option('review_title_label', $section, 'Testimonial Title');
$tt_image_label = cmshowcase_get_option('image_label',$section,'Your Image');
$tt_star_label_singular = cmshowcase_get_option('star_singular',$section,'Star');
$tt_star_label_plural = cmshowcase_get_option('star_plural',$section,'Stars');
$tt_verification_label = cmshowcase_get_option('verification',$section,'Are you Human?');
$tt_category_label = cmshowcase_get_option('category_label',$section,'Category');
$tt_post_status = cmshowcase_get_option('status',$section,'pending');
$tt_boolean_label = cmshowcase_get_option('custom_boolean_label',$section,'Yes or No?');
$tt_boolean_2_label = cmshowcase_get_option('custom_boolean_2_label',$section,'Yes or No? 2');
$tt_boolean_3_label = cmshowcase_get_option('custom_boolean_3_label',$section,'Yes or No? 3');
$tt_boolean_4_label = cmshowcase_get_option('custom_boolean_4_label',$section,'Yes or No? 4');
$tt_boolean_positive = cmshowcase_get_option('custom_boolean_positive_label',$section,'Yes');
$tt_boolean_negative = cmshowcase_get_option('custom_boolean_negative_label',$section,'No');
$tt_consent_label = cmshowcase_get_option('consent_ck_label',$section,'I agree to share this information with the owners of this website and allow it to be published');
$scale = cmshowcase_get_option( 'rating_scale', 'ttshowcase_basic_settings', '5' );
$tt_force_redirect = cmshowcase_get_boolean(cmshowcase_get_option('force_redirect', $section, 'off'));
$tt_ajax = cmshowcase_get_boolean(cmshowcase_get_option('ajax', $section, 'off'));
$tt_initial_rating = cmshowcase_get_option('default_rating', $section, '5');
$tt_human_verification_logged = cmshowcase_get_boolean($tt_human_verification_logged);
$tt_honeypot = cmshowcase_get_boolean(cmshowcase_get_option('honeypot_spam', $section, 'off'));
$tt_fields_order = cmshowcase_get_option('order', $section, 'name,subtitle,url,image,title,testimonial,longtestimonial,rating,email,yesOrNo,yesOrNo2,yesOrNo3,yesOrNo4,humanVerification,consent');
$tt_mandatory = cmshowcase_get_option('mandatory', $section, 'name,email,url,subtitle,title,testimonial,rating,image');
$tt_mandatory_append = cmshowcase_get_option('mandatory_append', $section, ' (required)');
//ERROR MESSAGES
$tt_error_generic = cmshowcase_get_option('error_generic', $section, 'This field is mandatory');
$tt_error_email = cmshowcase_get_option('error_email', $section, 'Invalid or empty email');
$tt_error_image = cmshowcase_get_option('error_image', $section, 'Invalid or empty image');
$tt_error_boolean = cmshowcase_get_option('error_boolean', $section, 'Please review this option');
$tt_error_human = cmshowcase_get_option('error_human', $section, 'Please insert the correct answer');
//Akismet Integration
$tt_akismet = cmshowcase_get_boolean(cmshowcase_get_option('akismet', $section, 'off'));
if(defined('AKISMET_VERSION')) {
if($tt_akismet) {
require_once dirname(__FILE__) . '/Akismet.class.php';
if(null !== get_option('wordpress_api_key')) {
$akismet = new tt_Akismet(get_site_url(), get_option('wordpress_api_key'));
if($akismet->isKeyValid()) {
} else {
echo '';
}
}
}
}
if($tt_ajax) {
wp_deregister_script( 'ttshowcase-submit-validation' );
wp_register_script( 'ttshowcase-submit-validation', plugins_url( 'js/jquery.validation.js', __FILE__ ),array('jquery'),false,false);
wp_enqueue_script( 'ttshowcase-submit-validation' );
wp_localize_script( 'ttshowcase-submit-validation', 'ajax_object',array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
}
$tt_loggedonly_text = cmshowcase_get_option('loggedonly', $section, 'You need to be a registred user to submit entries');
$custom_css_load = cmshowcase_get_boolean(cmshowcase_get_option('load_css_form','ttshowcase_advanced_settings','off'));
if($custom_css_load) {
add_action('wp_footer', 'ttshowcase_custom_css_footer');
}
$consent_on = isset($atts['consent']) && $atts['consent'] == 'on' ? true : false;
$subtitle_on = isset($atts['subtitle']) && $atts['subtitle'] == 'on' ? true : false;
$subtitle_url_on = isset($atts['subtitle_url']) && $atts['subtitle_url'] == 'on' ? true : false;
$rating_on = isset($atts['rating']) ? $atts['rating'] : false;
$r_title_on = isset($atts['review_title']) && $atts['review_title'] == 'on' ? true : false;
$email_on = isset($atts['email']) && $atts['email'] == 'on' ? true : false;
$long_testimonial_on = isset($atts['long_testimonial']) && $atts['long_testimonial'] == 'on' ? true : false;
$verification = isset($atts['verification']) ? $atts['verification'] : false;
$logged_on = isset($atts['logged']) && $atts['logged'] == 'on' ? true : false;
$logged_only = isset($atts['logged_only']) && $atts['logged_only'] == 'on' ? true : false;
$taxonomy_on = isset($atts['taxonomy']) ? true : false;
$image_on = isset($atts['image']) && $atts['image'] == 'on' ? true : false;
$style = isset($atts['style']) ? $atts['style'] : 'tt_simple';
$category = isset($atts['display_category']) && $atts['display_category'] == 'on' ? true : false;
$in_category = isset($atts['in_category']) ? true : false;
$child_of = isset($atts['child_of']) ? true : false;
$parent_category = isset($atts['display_category_parent']) && $atts['display_category_parent'] == 'on' ? true : false;
$boolean_field = isset($atts['boolean']) ? $atts['boolean'] : false;
$boolean_field_2 = isset($atts['boolean2']) ? $atts['boolean2'] : false;
$boolean_field_3 = isset($atts['boolean3']) ? $atts['boolean3'] : false;
$boolean_field_4 = isset($atts['boolean4']) ? $atts['boolean4'] : false;
$hasError = false;
//PROCESS ALL STRINGS TO BE TRANSLATED
//Process all strings for translation
$tt_label_name = tts__($tt_label_name,'ttshowcase');
$tt_label_subtitle = tts__($tt_label_subtitle,'ttshowcase');
$tt_label_url = tts__($tt_label_url,'ttshowcase');
$tt_label_testimonial = tts__($tt_label_testimonial,'ttshowcase');
$tt_label_long_testimonial = tts__($tt_label_long_testimonial,'ttshowcase');
$tt_label_rating = tts__($tt_label_rating,'ttshowcase');
$tt_label_email = tts__($tt_label_email,'ttshowcase');
$tt_confirmation_text = tts__($tt_confirmation_text,'ttshowcase');
$tt_error_text = tts__($tt_error_text,'ttshowcase');
$tt_submit_label = tts__($tt_submit_label,'ttshowcase');
$tt_review_title_label = tts__($tt_review_title_label,'ttshowcase');
$tt_image_label = tts__($tt_image_label,'ttshowcase');
$tt_star_label_singular = tts__($tt_star_label_singular,'ttshowcase');
$tt_star_label_plural = tts__($tt_star_label_plural,'ttshowcase');
$tt_verification_label = tts__($tt_verification_label,'ttshowcase');
$tt_category_label = tts__($tt_category_label,'ttshowcase');
$tt_loggedonly_text = tts__($tt_loggedonly_text,'ttshowcase');
$tt_boolean_label = tts__($tt_boolean_label,'ttshowcase');
$tt_boolean_2_label = tts__($tt_boolean_2_label,'ttshowcase');
$tt_boolean_3_label = tts__($tt_boolean_3_label,'ttshowcase');
$tt_boolean_4_label = tts__($tt_boolean_4_label,'ttshowcase');
$tt_consent_label = tts__($tt_consent_label,'ttshowcase');
if($consent_on){
$tt_mandatory .= ',consent';
if(strpos($tt_fields_order, 'consent') == false) {
$tt_fields_order .= ',consent';
}
}
$tt_mandatory = str_replace(' ', '', $tt_mandatory);
$mandatory = explode(',',$tt_mandatory);
$tt_mandatory_append = ''.$tt_mandatory_append.'';
//Add mandatory append to labels
//name
if(in_array('name', $mandatory)) {
$tt_label_name .= $tt_mandatory_append;
}
if(in_array('email', $mandatory)) {
$tt_label_email .= $tt_mandatory_append;
}
if(in_array('url', $mandatory)) {
$tt_label_url .= $tt_mandatory_append;
}
if(in_array('subtitle', $mandatory)) {
$tt_label_subtitle .= $tt_mandatory_append;
}
if(in_array('testimonial', $mandatory)) {
$tt_label_testimonial .= $tt_mandatory_append;
}
if(in_array('rating', $mandatory)) {
$tt_label_rating .= $tt_mandatory_append;
}
if(in_array('image', $mandatory)) {
$tt_image_label .= $tt_mandatory_append;
}
if(in_array('testimonial_title', $mandatory)) {
$tt_review_title_label .= $tt_mandatory_append;
}
if(in_array('yes_or_no', $mandatory)) {
$tt_boolean_label .= $tt_mandatory_append;
}
if(in_array('yes_or_no_2', $mandatory)) {
$tt_boolean_2_label .= $tt_mandatory_append;
}
if(in_array('yes_or_no_3', $mandatory)) {
$tt_boolean_3_label .= $tt_mandatory_append;
}
if(in_array('yes_or_no_4', $mandatory)) {
$tt_boolean_4_label .= $tt_mandatory_append;
}
if(in_array('consent', $mandatory)) {
$tt_consent_label .= $tt_mandatory_append;
}
if(in_array('long_testimonial', $mandatory)) {
$tt_label_long_testimonial .= $tt_mandatory_append;
}
if(isset($_POST['tt_submitted']) && isset($_POST['post_nonce_field']) && wp_verify_nonce($_POST['post_nonce_field'], 'post_nonce')) {
//make field mandatory
//possible options in array: name, email, url, subtitle, title, testimonial, rating, image
//$mandatory = array('name', 'email', 'url', 'subtitle', 'title', 'testimonial', 'rating', 'image' );
//ERROR HANDLING
//honeypot spam prevention
if($tt_honeypot) {
if(isset($_POST['tt_hp_email_mandatory']) && $_POST['tt_hp_email_mandatory'] != '') {
$hasError = true;
$tt_error_text .= '
'.tts__(' Not human maybe? Try reloading the page and fill out the form manually','ttshowcase').'
'; } } if($verification) { if((!is_user_logged_in()) || (is_user_logged_in() && $tt_human_verification_logged)) { if(!isset($_POST['hverification']) || !isset($_POST['hval']) || md5(strtoupper($_POST['hverification'])) != $_POST['hval']) { $hasError = true; $verificationerror = tts__($tt_error_human,'ttshowcase'); } } } //check if author/title has a value if(in_array('name',$mandatory) && isset($_POST['postTitle']) && trim($_POST['postTitle']) === '') { $posttitleerror = tts__($tt_error_generic,'ttshowcase'); $hasError = true; } else { $postTitle = trim($_POST['postTitle']); } //make testimonials text mandatory if(in_array('testimonial',$mandatory) && isset($_POST['_aditional_info_short_testimonial']) && trim($_POST['_aditional_info_short_testimonial']) === '') { $testimonialerror = tts__($tt_error_generic,'ttshowcase'); $hasError = true; } if(in_array('long_testimonial',$mandatory) && isset($_POST['_aditional_info_long_testimonial']) && trim($_POST['_aditional_info_long_testimonial']) === '') { $longtestimonialerror = tts__($tt_error_generic,'ttshowcase'); $hasError = true; } if(in_array('email',$mandatory) && $email_on && ((trim($_POST['_aditional_info_email']) === '') || !cmshowcase_check_email($_POST['_aditional_info_email']) ) ) { //if(in_array('email',$mandatory) && $email_on && (trim($_POST['_aditional_info_email']) === '')) { $emailerror = tts__($tt_error_email,'ttshowcase'); $hasError = true; } //make images mandatory if($image_on && in_array('image',$mandatory) && !file_exists($_FILES['featured_image']['tmp_name'])) { $imageerror = tts__($tt_error_image,'ttshowcase'); $hasError = true; } //make testimonial title mandatory if(in_array('testimonial_title',$mandatory) && isset($_POST['_aditional_info_review_title']) && trim($_POST['_aditional_info_review_title']) === '') { $testimonialtitleerror = tts__($tt_error_generic,'ttshowcase'); $hasError = true; } //make subtitle mandatory if(in_array('subtitle',$mandatory) && isset($_POST['_aditional_info_name']) && trim($_POST['_aditional_info_name']) === '') { $aditionalinfoerror = tts__($tt_error_generic,'ttshowcase'); $hasError = true; } //make URL mandatory if(in_array('url',$mandatory) && isset($_POST['_aditional_info_url']) && trim($_POST['_aditional_info_url']) === '') { $urlerror = tts__($tt_error_generic,'ttshowcase'); $hasError = true; } //make rating mandatory if(in_array('rating',$mandatory) && $rating_on != false && !isset($_POST['_aditional_info_rating']) ) { $ratingerror = tts__($tt_error_generic,'ttshowcase'); $hasError = true; } //make boolean Yes/No mandatory - yes should be selected //if(in_array('yes_or_no',$mandatory) && $boolean_field != false && !isset($_POST['_aditional_info_custom_boolean']) ) { if(in_array('yes_or_no',$mandatory) && $boolean_field != false && (!isset($_POST['_aditional_info_custom_boolean']) || (isset($_POST['_aditional_info_custom_boolean']) && $_POST['_aditional_info_custom_boolean']=='') ) ) { $booleanerror = tts__($tt_error_boolean,'ttshowcase'); $hasError = true; } if(in_array('yes_or_no_2',$mandatory) && $boolean_field_2 != false && (!isset($_POST['_aditional_info_custom_boolean_2']) || (isset($_POST['_aditional_info_custom_boolean_2']) && $_POST['_aditional_info_custom_boolean_2']=='') ) ) { $booleanerror = tts__($tt_error_boolean,'ttshowcase'); $hasError = true; } if(in_array('yes_or_no_3',$mandatory) && $boolean_field_3 != false && (!isset($_POST['_aditional_info_custom_boolean_3']) || (isset($_POST['_aditional_info_custom_boolean_3']) && $_POST['_aditional_info_custom_boolean_3']=='') ) ) { $booleanerror = tts__($tt_error_boolean,'ttshowcase'); $hasError = true; } if(in_array('yes_or_no_4',$mandatory) && $boolean_field_4 != false && (!isset($_POST['_aditional_info_custom_boolean_4']) || (isset($_POST['_aditional_info_custom_boolean_4']) && $_POST['_aditional_info_custom_boolean_4']=='') ) ) { $booleanerror = tts__($tt_error_boolean,'ttshowcase'); $hasError = true; } if( in_array('consent',$mandatory) && !isset($_POST['_tts_consent']) ) { $consenterror = tts__($tt_error_generic,'ttshowcase'); $hasError = true; } $post_information = array( 'post_title' => esc_attr(strip_tags($_POST['postTitle'])), 'post_type' => 'ttshowcase', 'post_status' => $tt_post_status, //'post_name' => ); $post_information['post_content'] = ''; if(isset($_POST['_aditional_info_long_testimonial'])) { $post_information['post_content'] = esc_attr($_POST['_aditional_info_long_testimonial']); } if(!$hasError) { //check if it was already submitted with $exists = 0; if(function_exists('post_exists')){ $exists = post_exists($post_information['post_title'], $post_information['post_content']); } $post_id = false; if($exists==0){ $post_id = wp_insert_post($post_information); } else { $existingshort = get_post_meta($exists,'_aditional_info_short_testimonial',true); $newshort = $_POST['_aditional_info_short_testimonial']; $newtax = isset($_POST['tt_taxonomy']) ? $_POST['tt_taxonomy'] : false; $existingtax = wp_get_post_terms($post_id, 'tt_taxonomy', array("fields" => "names")); error_log('|'.$existingshort.':'.$newshort.'|'); if($existingshort!='' && trim($existingshort) != trim($newshort) ){ $post_id = wp_insert_post($post_information); } else if ($newtax) { if(!has_term($newtax,'ttshowcase_groups',$post_id)){ $post_id = wp_insert_post($post_information); } } } if($post_id) { //add featured image if($image_on && isset($_FILES)) { require_once (ABSPATH.'/wp-admin/includes/media.php'); require_once (ABSPATH.'/wp-admin/includes/file.php'); require_once (ABSPATH.'/wp-admin/includes/image.php'); $attachmentId = media_handle_upload('featured_image', $post_id); set_post_thumbnail($post_id, $attachmentId); unset($_FILES); if ( is_wp_error($attachmentId) ) { $errors['upload_error'] = $attachmentId; $id = false; } if (isset($errors)) { //image not uploaded } } //add category if(isset($_POST['tt_taxonomy'])) { $cat_entry = trim($_POST['tt_taxonomy']); //if is the taxonomy dropdown, the ids will be sent so we need to convert them to intengers if(is_numeric($cat_entry)) { $cat_entry = intval($cat_entry); } if($_POST['tt_taxonomy']=='{current_page_slug}') { $slug = basename(get_permalink()); //for taxonomies - still needs to be reviewed //$slug = basename("http://".$_SERVER[HTTP_HOST].$_SERVER[REQUEST_URI]); $cat_entry = $slug; } if($_POST['tt_taxonomy']=='{current_page_id}') { //in this case we create the category first, so it's easier to identify $new_taxonomy = get_term_by('slug', $_POST['tt_page_id'], 'ttshowcase_groups'); //if it doesn't exist, we create the entry first if(!$new_taxonomy) { $new_t_title = get_the_title($_POST['tt_page_id']); $new_t_slug = $_POST['tt_page_id']; wp_insert_term( $new_t_title, // the term 'ttshowcase_groups', // the taxonomy array( 'slug' => $new_t_slug, 'description' => get_permalink() ) ); } $cat_entry = $_POST['tt_page_id']; } wp_set_object_terms($post_id,$cat_entry,'ttshowcase_groups'); } //Code to add custom taxonomies //first we check if there's any custom taxonomy global $ttshowcase_options; if(count($ttshowcase_options['taxonomies'])>1) { foreach ($ttshowcase_options['taxonomies'] as $identifier => $data) { if($identifier=='groups') { continue; } if(isset($data['force_form']) && $data['force_form'] && taxonomy_exists('ttshowcase_'.$identifier) && isset($_POST['ttshowcase_'.$identifier])) { wp_set_object_terms($post_id,intval($_POST['ttshowcase_'.$identifier]),'ttshowcase_'.$identifier); } } } // Update Custom Meta if(isset($_POST['_aditional_info_name'])) { update_post_meta($post_id, '_aditional_info_name', esc_attr(strip_tags($_POST['_aditional_info_name']))); } if(isset($_POST['_aditional_info_url'])) { update_post_meta($post_id, '_aditional_info_url', esc_attr(strip_tags($_POST['_aditional_info_url']))); } if(isset($_POST['_aditional_info_email'])) { update_post_meta($post_id, '_aditional_info_email', esc_attr(strip_tags($_POST['_aditional_info_email']))); } if(isset($_POST['_aditional_info_review_title'])) { update_post_meta($post_id, '_aditional_info_review_title', esc_attr(strip_tags($_POST['_aditional_info_review_title']))); } if(isset($_POST['_aditional_info_short_testimonial'])) { update_post_meta($post_id, '_aditional_info_short_testimonial', esc_attr(strip_tags($_POST['_aditional_info_short_testimonial']))); } if(isset($_POST['_aditional_info_rating'])) { update_post_meta($post_id, '_aditional_info_rating', esc_attr(strip_tags($_POST['_aditional_info_rating']))); } if(isset($_POST['_aditional_info_custom_boolean'])) { update_post_meta($post_id, '_aditional_info_custom_boolean', esc_attr(strip_tags($_POST['_aditional_info_custom_boolean']))); } if(!isset($_POST['_aditional_info_custom_boolean'])) { update_post_meta($post_id, '_aditional_info_custom_boolean', 'false'); } // if(isset($_POST['_aditional_info_custom_boolean_2'])) { update_post_meta($post_id, '_aditional_info_custom_boolean_2', esc_attr(strip_tags($_POST['_aditional_info_custom_boolean_2']))); } if(!isset($_POST['_aditional_info_custom_boolean_2'])) { update_post_meta($post_id, '_aditional_info_custom_boolean_2', 'false'); } // if(isset($_POST['_aditional_info_custom_boolean_3'])) { update_post_meta($post_id, '_aditional_info_custom_boolean_3', esc_attr(strip_tags($_POST['_aditional_info_custom_boolean_3']))); } if(!isset($_POST['_aditional_info_custom_boolean_3'])) { update_post_meta($post_id, '_aditional_info_custom_boolean_3', 'false'); } // if(isset($_POST['_aditional_info_custom_boolean_4'])) { update_post_meta($post_id, '_aditional_info_custom_boolean_4', esc_attr(strip_tags($_POST['_aditional_info_custom_boolean_4']))); } if(!isset($_POST['_aditional_info_custom_boolean_4'])) { update_post_meta($post_id, '_aditional_info_custom_boolean_4', 'false'); } //Filter the submission with Akismet before sending notification email $send_email = true; if(defined('AKISMET_VERSION')) { if($tt_akismet) { require_once dirname(__FILE__) . '/Akismet.class.php'; if(null !== get_option('wordpress_api_key')) { $akismet = new tt_Akismet(get_site_url(), get_option('wordpress_api_key')); if($akismet->isKeyValid()) { $akismet->setCommentAuthor($_POST['postTitle']); if(isset($_POST['_aditional_info_email'])) { $akismet->setCommentAuthorEmail($_POST['_aditional_info_email']); } if(isset($_POST['_aditional_info_url'])) { $akismet->setCommentAuthorURL($_POST['_aditional_info_url']); } if(isset($_POST['_aditional_info_short_testimonial'])) { $akismet->setCommentContent($_POST['_aditional_info_short_testimonial']); } $akismet->setPermalink(get_permalink($post_id)); if($akismet->isCommentSpam()) { $send_email = false; wp_update_post(array( 'ID' => $post_id, 'post_status' => 'trash', 'post_title' => '[SPAM?] '.$_POST['postTitle'] )); } } } } } //Send Email if($tt_confirmation_email_on=='on' && $send_email) { $url = admin_url( 'post.php?post='.$post_id.'&action=edit'); $title = $postTitle; $text = sanitize_text_field($_POST['_aditional_info_short_testimonial']); $rating = isset($_POST['_aditional_info_rating']) ? sanitize_text_field($_POST['_aditional_info_rating']) : ''; $boolean = isset($_POST['_aditional_info_custom_boolean']) ? sanitize_text_field($_POST['_aditional_info_custom_boolean']) : ''; $boolean2 = isset($_POST['_aditional_info_custom_boolean_2']) ? sanitize_text_field($_POST['_aditional_info_custom_boolean_2']) : ''; $boolean3 = isset($_POST['_aditional_info_custom_boolean_3']) ? sanitize_text_field($_POST['_aditional_info_custom_boolean_3']) : ''; $boolean4 = isset($_POST['_aditional_info_custom_boolean_4']) ? sanitize_text_field($_POST['_aditional_info_custom_boolean_4']) : ''; $shorttitle = isset($_POST['_aditional_info_review_title']) ? sanitize_text_field($_POST['_aditional_info_review_title']) : ''; $taxonomy = ''; $email = isset($_POST['_aditional_info_email']) ? sanitize_text_field($_POST['_aditional_info_email']) : ''; $taxs = get_post_taxonomies( $post_id ); foreach ($taxs as $key => $value) { $tax = get_taxonomy( $value ); $term_list = wp_get_post_terms($post_id, $value, array("fields" => "names")); //print_r($term_list); $current = ''; foreach ($term_list as $tkey => $tvalue) { if($current!=$value) { $taxonomy .= $tax->labels->name.': '.$tvalue; $current = $value; } else { $taxonomy .= ', '.$tvalue; } } $taxonomy .= '