Forum Replies Created

Viewing 9 replies - 1 through 9 (of 9 total)
  • I know that this thread is not about features, but since I have started to write down everything into this thread I have some feature requests:

    A function to pull a random poll/quiz/survey
    A function to pull the latest poll/quiz/survey
    A poll/quiz/survey archive page ( with possibility to modifie dates )

    Also I have seen that there is a possibility to limit submission by IP, but this is a problem when people come from shared IP connections ( tons of providers share one IP to 100s customers) . Would be nice if there is also a Cookie + IP combination.

    All from me for today.
    Thanx
    Stefan

    Me again. I think I keep answering to my questions ??

    So after small research I found out that the first number is the blog_id .. in my case its numero 1. And also it works also for polls ( great news ) and also that the number is the poll ID. But that is not really usable when I want a generic new layout for all of my polls that wont change after update. So I have changed the pageView function in Core.php to this:

    public static function pageView($file){
    
    	global $blog_id;
    
    	$quizPath = ( isset($_SESSION['wpsqt']['item_id'])
    		&& ctype_digit($_SESSION['wpsqt']['item_id']) ) ?
    		$blog_id.'/'.$_SESSION['wpsqt']['current_type'].'-'.$_SESSION['wpsqt']['item_id'].'/' : '';
    
    	$quizPathGeneral = 	$quizPath = ( isset($_SESSION['wpsqt']['item_id'])
    		&& ctype_digit($_SESSION['wpsqt']['item_id']) ) ?
    		$blog_id.'/'.$_SESSION['wpsqt']['current_type'].'/' : '';
    
    	if ( file_exists(WPSQT_DIR.'pages/custom/'.$quizPath.$file) ){
    		return WPSQT_DIR.'pages/custom/'.$quizPath.$file;
    	} elseif ( file_exists(WPSQT_DIR.'pages/custom/'.$quizPathGeneral.$file) ){
    		return WPSQT_DIR.'pages/custom/'.$quizPathGeneral.$file;
    	} elseif (file_exists(WPSQT_DIR.'pages/custom/'.$blog_id.'/shared/'.$file)) {
    		return WPSQT_DIR.'pages/custom/'.$blog_id.'/shared/'.$file;
    	}
    	return WPSQT_DIR.'pages/'.$file;
    }

    So now the new layout will be applied for each quiz, poll or survey and directory for new template will look like this:
    /var/ww/wp-content/plugins/wp-survey-and-quiz-tool/pages/custom/0/poll.

    If you like it, you can add it into the new release. Also have been thinking to remove the blog ID but it probably plays its role in multisite wordpress installations.

    Stefan

    Hi Ollie,

    I have one more question. Can this be applied also to polls? https://catn.com/wordpress/plugins/wpsqt-creating-custom-pages/

    Does the 0 in the directory structure mean something? And also the number after the number after the quiz = “quiz-1” .. does it mean that it will be applied to quiz with ID 1??

    Thanx.
    Stefan

    Never mind now, got it working. I am not sure if this is the right way so here is the code I have added:

    Into Core.php I have added this at the end of the __construct function

    add_action('wp_ajax_ajax_poll', array($this, '_ajax_result') );	//line: 46
    	add_action('wp_ajax_nopriv_ajax_poll', array($this, '_ajax_result') );	//line: 47

    And right after the end of __construct function in Core.php I have created a new functions called _ajax_result()

    public function _ajax_result(){
    	require_once WPSQT_DIR.'lib/Wpsqt/Shortcode.php';
    	$identifer = $_POST['identifier']; $type = $_POST['type'];
    	$objShortcode = new Wpsqt_Shortcode($identifer, $type);
    	die( $objShortcode->display() );
    	return false;
    }

    The funny part is that when I called finishQuiz() the result has not been counted the right way. Now with display() function it works.

    Also have added into pages/site/poll/section.php I have added these lines after line 10

    <input type="hidden" name="type" value="<?php echo ( $_SESSION['wpsqt']['current_type'] ); ?>">
    <input type="hidden" name="identifier" value="<?php echo ( $quizName ); ?>">
    <input type="hidden" name="name" value="<?php echo ( $quizName ); ?>">

    And finally the ajax call in the single template looks like this:

    <script type="text/javascript">
    /* <![CDATA[ */
    	jQuery(document).ready(function($){
    
    		$('.button-secondary').click(function() {
    			;
    			jQuery.post(
    				'<?php bloginfo('wpurl'); ?>/wp-admin/admin-ajax.php',
    		   		$('.poll form').serialize() + '&action=ajax_poll',
    				function(response){
    
    					$('.wpst_question').html(response);
    				}
    			);
    			return false;
    		});
    
    	});
    /* ]]> */
    </script>

    This is probably not a complex solution but I hope it will help you to get started and youll try to implement ajax call at least for polls. Let me know if it worked for you.

    Stefan

    After further examination I have discovered that I am missing some variables from SESSION that is submited trough AJAX. And those are probably the ones I need to setup before I can proceed.

    Dont you know where these are getting inserted into the SESSION?

    [answers] => Array
                            (
                                [2] => Array
                                    (
                                        [mark] => incorrect
                                        [given] => Array
                                            (
                                                [0] => 0
                                            )
                                    )
                            )
                        [stats] => Array
                            (
                                [correct] => 0
                                [incorrect] => 1
                            )
                        [can_automark] => 1

    Thanx

    Hey Ollie,

    I am somewhere on the half way more at the end ??

    I got everything working but one thing .. ANSWERS .. it never takes the correct answer

    Check: https://smemladi.smertv.sk/testy/test-autoskola/

    Try it and see the ajax call in firebug. I cant set it up to show the correct answer in result. Can you just tell me, what should I change or adjust or .. where in the code it is determined that which answer has been selected for the exact question.

    Until now, I have only made few changes (15 lines of code maybe) in the code so if we fix this issue, will be awesome.

    Hey Ollie, if it wont work for the first time try to do it this way:

    1) I guess you have an existing function and lets call it POLL_RESULTS() .. in my case, I could not connect AJAX directly to this function so I had to create a functions called AJAX_POLL_RESULTS() and it looked like this:

    function ajax_poll_results(){
     die( poll_results() );
    }

    2) Now you can create the ajax hooks like this:

    add_action('wp_ajax_ajax_poll', 'ajax_poll_results');
    add_action('wp_ajax_nopriv_ajax_poll', 'ajax_poll_results');

    Where ajax_poll in the ajax hook is the parameter, that needs to in AJAX call when called from the template. So now, the ajax call needs to look like this:

    $('#poll-submit').click(function() {
    	jQuery.post(
    		'<?php bloginfo('wpurl'); ?>/wp-admin/admin-ajax.php',
    		{ 'action':'ajax_poll' }, // this is the action name
    		function(response){
    			$('#poll-holder').html( response );
    		}
    	);
    	return false;
    });

    Hope this helps .. I have spent few hours until I got this clear the last time I tried to convert one of my WP functions into ajax.

    If I can help with anything just let me know.

    Thanx.
    Stefan

    That would be awesome. You rock.

    Also one more thing. I would the functionality to pull poll results right after submission with AJAX. Maybe adding

    add_action('wp_ajax_POLL_RESULT_FUNCTION', 'POLL_RESULT_FUNCTION');
    add_action('wp_ajax_nopriv_POLL_RESULT_FUNCTION', 'POLL_RESULT_FUNCTION');

    would do the trick without a big code change.

    Let me know. Thanx.
    Stefan

    Hi Ollie,

    great job with the plugin. Have been trying to make it work from yesterday and thanx good I have found this thread. Your new 2.5.4 upgrade is working fine now. I only have one issue. I am using characters like “?????yáí” and those are being replaced everytime I edit my question or anything and after that they are not readable. I found out, that this is caused by htmlentities() functions. I had to insert two options at the end so the functions looks like this: htmlentities(stripslashes($option[“value”]), ENT_COMPAT, ‘utf-8’). I guess that this way we are forcing UTF-8 encoding and that probably wont work for everyone, but is there a way to make it optional. You could make it like this: htmlentities(stripslashes($option[“value”]), ENT_COMPAT, DB_CHARSET) — which is wordpress database installation encoding.

    Or if you have a better solution please let me know. I just dont want to constantly overwrite your files after upgrade.

    Stefan

Viewing 9 replies - 1 through 9 (of 9 total)