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: 128

<?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:
TGI Fridays to go public through merger with its U.K. franchisee
Volkswagen union vote in Tennessee to test UAW's power after victories in Detroit
Pacific Crest Trail cotton-free material t-shirt?
How to screen mirror from Windows 11 to TV (perhaps via AirPlay)
Stocks making the biggest moves midday: UnitedHealth, SolarEdge, Bank of America, Tesla and more
Potential Trump trial jurors dismissed because of bias against former president
Dr. Martens shares plunge 30% to all-time low, trading briefly halted on weak outlook
Healthy Returns: U.S. drug shortages reach record high, hitting Wegovy, ADHD medications
S&P 500 wavers, UnitedHealth lifts Dow: Live updates
IMF upgrades global growth forecast as economy proves 'surprisingly resilient' despite downside risks