Skip to content

Commit

Permalink
adding filter disable option and adding filter to preview pane
Browse files Browse the repository at this point in the history
git-svn-id: http://plugins.svn.wordpress.org/slickquiz/trunk@1020411 b8457f37-d9ea-0310-8a92-e5e31aec5664
  • Loading branch information
jewlofthelotus committed Nov 5, 2014
1 parent 7f56906 commit 4656bf3
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 52 deletions.
47 changes: 0 additions & 47 deletions php/slickquiz-front.php
Expand Up @@ -387,53 +387,6 @@ protected function current_page_url()

return $pageURL;
}

/**
* Apply WordPress filters to SlickQuiz JSON on output.
*
* @link http://codex.wordpress.org/Data_Validation
* @link http://codex.wordpress.org/Plugin_API/Filter_Reference
* @link https://github.com/jewlofthelotus/SlickQuiz/blob/master/js/slickQuiz-config.js
*/
protected function filter_quiz( $quiz_json )
{
// Double negative!
if ( $this->get_admin_option( 'no_filter_quizzes' ) ) {
return $quiz_json;
}

$quiz = json_decode( $quiz_json );
$this->filter_short( $quiz->info->name );
$this->filter_body( $quiz->info->main );
$this->filter_body( $quiz->info->results );

foreach ( $quiz->questions as $question ) {
$this->filter_body( $question->q );
$this->filter_body( $question->correct );
$this->filter_body( $question->incorrect );

foreach ( $question->a as $answer ) {
$this->filter_short( $answer->option );
}
}

return json_encode( $quiz );
}

// Filter "body"-type/ <textarea> content in a quiz.
protected function filter_body( & $data )
{
$data = wp_kses_post( $data );
$data = apply_filters( 'the_content', $data );
return $data;
}

// Filter "title"/ short content in a quiz.
protected function filter_short( & $data )
{
$data = wp_kses_data( $data );
}

}
}

Expand Down
3 changes: 2 additions & 1 deletion php/slickquiz-helper.php
Expand Up @@ -56,7 +56,8 @@ function get_admin_options()
'email_label' => '',
'share_links' => '0',
'share_message' => 'I\'m a [RANK]! I just scored [SCORE] on the [NAME] quiz!',
'twitter_account' => ''
'twitter_account' => '',
'no_filter_quizzes' => '1'
) );

$pluginOptions = get_option( $this->adminOptionsName );
Expand Down
45 changes: 45 additions & 0 deletions php/slickquiz-model.php
Expand Up @@ -114,6 +114,51 @@ function get_question_count()
return count( $data->questions );
}

/**
* Apply WordPress filters to SlickQuiz JSON on output.
*
* @link http://codex.wordpress.org/Data_Validation
* @link http://codex.wordpress.org/Plugin_API/Filter_Reference
*/
protected function filter_quiz( $quiz_json )
{
// Double negative!
if ( $this->get_admin_option( 'no_filter_quizzes' ) != 1 ) {
return $quiz_json;
}

$quiz = json_decode( $quiz_json );
$this->filter_short( $quiz->info->name );
$this->filter_body( $quiz->info->main );
$this->filter_body( $quiz->info->results );

foreach ( $quiz->questions as $question ) {
$this->filter_body( $question->q );
$this->filter_body( $question->correct );
$this->filter_body( $question->incorrect );

foreach ( $question->a as $answer ) {
$this->filter_short( $answer->option );
}
}

return json_encode( $quiz );
}

// Filter "body"-type/ <textarea> content in a quiz.
protected function filter_body( & $data )
{
$data = wp_kses_post( $data );
$data = apply_filters( 'the_content', $data );
return $data;
}

// Filter "title"/ short content in a quiz.
protected function filter_short( & $data )
{
$data = wp_kses_data( $data );
}


/**
* Database Methods
Expand Down
19 changes: 19 additions & 0 deletions php/slickquiz-options.php
Expand Up @@ -410,6 +410,25 @@ function show_alert_messages()
</tbody>
</table>

<h3 class="title">Other</h3>
<table class="form-table">
<tbody>
<tr valign="top">
<th scope="row" style="width: 250px;">
<label for="slickQuizOptions[no_filter_quizzes]">Enable WordPress Filters on quiz content?</label>
</th>
<td>
<input type="radio" name="slickQuizOptions[no_filter_quizzes]" value="0"
<?php $slickQuizOptions->get_admin_option( 'no_filter_quizzes' ) == '0' ? print_r('checked="checked"') : ''; ?> /> No &nbsp;
<input type="radio" name="slickQuizOptions[no_filter_quizzes]" value="1"
<?php $slickQuizOptions->get_admin_option( 'no_filter_quizzes' ) == '1' ? print_r('checked="checked"') : ''; ?> /> Yes
<br /><small><em>Enabling fitlers allows for the inclusion of shortcodes and other plugin hooks.<br/>
You should disable this if you're seeing strange output in your quiz.</em></small>
</td>
</tr>
</tbody>
</table>

<?php do_action( 'slickquiz_after_options', $slickQuizOptions ); ?>

<p class="submit">
Expand Down
6 changes: 4 additions & 2 deletions php/slickquiz-preview.php
Expand Up @@ -23,9 +23,11 @@ function __construct()

function get_quiz_json()
{
$quiz = $this->get_quiz_by_id( $_GET['id'] );
$quiz = $this->get_quiz_by_id( $_GET['id'] );
$published = $this->get_quiz_status( $quiz ) == self::NOT_PUBLISHED ? false : true;
echo !isset( $_GET['readOnly'] ) || !$published ? $quiz->workingJson : $quiz->publishedJson;
$json = !isset( $_GET['readOnly'] ) || !$published ? $quiz->workingJson : $quiz->publishedJson;
$json = $this->filter_quiz( $json );
echo $json;
}

}
Expand Down
10 changes: 9 additions & 1 deletion readme.txt
Expand Up @@ -4,7 +4,7 @@ Donate link: http://www.gofundme.com/slickquiz
Tags: quiz, test, jquery, javascript, education, elearning, generator, manager, question, answer, score, rank
Requires at least: 3.0
Tested up to: 4.0
Stable tag: 1.3.6.1
Stable tag: 1.3.7
License: GPLv3 or later
License URI: http://www.gnu.org/licenses/gpl.html

Expand Down Expand Up @@ -171,6 +171,10 @@ Also, see the [SlickQuiz Issues](https://github.com/jewlofthelotus/SlickQuiz-Wor

== Changelog ==

= 1.3.7 =
* NEW option to disable WordPress filters on SlickQuiz content areas
* NEW added WordPress filter setup to quiz preview

= 1.3.6.1 =
* BUG FIX: Answer toggling should not animate
* BUG FIX: When "Display score as percentage", ranking should still work
Expand Down Expand Up @@ -353,6 +357,10 @@ This is the initial setup of the plugin.

== Upgrade Notice ==

= 1.3.7 =
* NEW option to disable WordPress filters on SlickQuiz content areas
* NEW added WordPress filter setup to quiz preview

= 1.3.6.1 =
* BUG FIX: Answer toggling should not animate
* BUG FIX: When "Display score as percentage", ranking should still work
Expand Down
2 changes: 1 addition & 1 deletion slickquiz.php
Expand Up @@ -4,7 +4,7 @@
Plugin Name: SlickQuiz
Plugin URI: http://github.com/jewlofthelotus/SlickQuiz-WordPress
Description: Plugin for displaying and managing pretty, dynamic quizzes.
Version: 1.3.6.1
Version: 1.3.7
Author: Julie Cameron
Author URI: http://juliecameron.com
License: GPLv3 or later
Expand Down

0 comments on commit 4656bf3

Please sign in to comment.