Loading...

Can someone help me in this plugin ? I am trying to show images in random question plugin

Post date: 2021-02-23 15:33:01
Views: 14

<?php

class q2a_random_question_images {

    function allow_template($template) {

        $allow = false;

        switch ($template) {

            case 'account':

            case'activity':

            case'admin':

            case'ask' :

            case'categories' :

            case'custom' :

            case'favorites':

            case'feedback' :

            case'hot' :

            case'ip' :

            case'login':

            case'message':

            case'qa' :

            case'question':

            case'questions':

            case'register' :

            case'search' :

            case'tag' :

            case'tags' :

            case'unanswered':

            case'updates' :

            case'user' :

            case'users' :

                $allow = true;

                break;

        }

        return $allow;

    }

    function allow_region($region) {

        return true;

    }

    function output_widget($q_list) {

$random_question = qa_db_read_one_assoc( qa_db_query_sub('SELECT * FROM ^posts q INNER JOIN ^posttags t ON q.postid=t.postid INNER JOIN ^words w ON t.wordid=w.wordid WHERE q.type="Q" AND w.word=$ ORDER BY rand() LIMIT 1', "funny-images" ));

echo "<h2>Random Images</h2>";

//replace yourwebsite with your website

          echo "<div class='qa-q-list-item' ><div class='qa-q-item-title'><a href='https://website.com/" . $random_question'postid'] . "'>" . $random_question'title'] . "</a></div><br></div>";

          if (!empty($q_list'qs'])) { // first check it is not an empty list and the feature is turned on

        // Collect the question ids of all items in the question list (so we can do this in one DB query)

        $postids = array();

        foreach ($q_list'qs'] as $question)

        {

            if (isset($question'raw']'postid']))

                $postids] = $question'raw']'postid'];

        }

        if (!empty($postids)) {

            // Retrieve the content for these questions from the database and put into an array fetching

            // the minimal amount of characters needed to determine the string should be shortened or not

            $result   = qa_db_query_sub('SELECT postid, content, format FROM ^posts WHERE postid IN (#)', $postids);

            $postinfo = qa_db_read_all_assoc($result, 'postid');

            // Get the regular expression fragment to use for blocked words and the maximum length of content to show

            $blockwordspreg = qa_get_block_words_preg();

            // Now add the popup to the title for each question

            foreach ($q_list'qs'] as $index => $question)

            {

                if (isset($postinfo$question'raw']'postid']])) {

                    $thispost = $postinfo$question'raw']'postid']];

                    $text     = qa_viewer_html($thispost'content'], $thispost'format'], array('blockwordspreg' => $blockwordspreg));

                    // Extract image source from content

                    preg_match_all('/<img^>]+src='"](^'"]+)'"]^>]*>/i', $text, $matches);

                    // If content has image than show it!

                    if (!empty($matches0])) {

                        // assign image to the variable

                        $image                           = '<img src="' . $matches1]0] . '" alt="image" class="q-list-image" />'; // change the size using attr or css

                        $q_list'qs']$index]'content'] = '<a href="/'.$question'raw']'postid'].'" >'.$image.'</a>';

                    }

                }

            }

        }

    }

         

}

}

Please click Here to read the full story.
 
Other Top and Latest Questions:
I don't want long comments
Hiro Capital puts $2.3M into team sports tracking platform PlayerData — as does Sir Terry Leahy
How should I deal with shady/stupid house sellers?
How to add an email address in Google Sheets/Excel?
Looking for stories where characters talk about hardship
Opening old Macwrite files
My nth question about cat ownership
Half-baked
Keycaps for obscure William Gibson novel heroines?
Justification for arresting George Floyd