<?php

    class qa_random_questions {

        function allow_template($template)
        {

            $allow=true;
            
            return $allow;
        }

        function allow_region($region)
        {
            return true;
        }

       	function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
        {
			$widget_title = qa_opt('random_widget_title');
			$max_show_num = qa_opt('random_question_number');
			$get_rand_sql = '^posts.postid > (SELECT floor( RAND() * ((SELECT MAX(^posts.postid) FROM ^posts)-(SELECT MIN(^posts.postid) FROM ^posts)) + (SELECT MIN(^posts.postid) FROM ^posts)))';
			$random_sql = 'SELECT * FROM ^posts WHERE type=$ and ' . $get_rand_sql.' limit '.$max_show_num;
            $queryed_questions = qa_db_query_sub($random_sql,'Q');
            $themeobject->output('<div class="widget-title"><span class="fal fa-list-music"></span> Random Music</div>');
			$index = 1; 
			//pus cod random
		foreach($queryed_questions as $row) {
  $furl = qa_path_absolute(qa_q_request($row['postid'], $row['title']), null, null);
 
				if ($row['postformat'] == 'V'){ 
				$getFileId = qa_db_read_one_assoc(qa_db_query_sub("SELECT * FROM qa_postmetas WHERE postid = ".((int)trim($row['postid']))), true);
					$file_id = (int)trim($getFileId['content']);
					$getThefile = qa_db_read_one_assoc(qa_db_query_sub("SELECT * FROM qa_uploads WHERE id = ".$file_id), true);
					$protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
					$website_url = $protocol . $_SERVER['HTTP_HOST'];
 
		$themeobject->output('  <div class="sect-content">
		<div style="width: 100%;">
	<div class="track-bgx track-item fx-row fx-middle js-itemx"> 
	<div class="track-img img-fit">
		<img src="/dle2/96.png" alt="download extern">
	</div>
	<a class="track-desc fx-1" href="'.qa_html($furl).'">
		<div class="track-title nowrap"> ' . $row['title'] . '</div>
		<div class="track-subtitle nowrap"><i class="fas fa-headphones-alt"></i> ' . $row['views'] . ' Hits
	|	<span><i class="far fa-thumbs-up"></i> ' . $row['netvotes'] . ' Votes</span> |
		<span><i class="fa fa-comment" aria-hidden="true"></i> ' . $row['acount'] . ' Comments</span>
		</div>
	</a>
<div class="track-time"><span style="margin: 25px;background: #57d616; border-radius: 2px; color: white;font-weight: bold; font-size: 13px;"> 
<b style="margin: 3px;">EXTERN</b>
<img style="bottom: 1px; position: absolute; width:23px;" src="/dle2/rdr.png" title="icon mp3"></span> </div>
 </div>		 
</div>
</div>  ');
		 
				}
				elseif($row['postformat'] == 'music')
				{	
 
  // The file ID
                $file_id = unserialize(get_poll($row['postid'], 'music', true)['content'])[1]['music'] ?? null;
                // The file URL
                $mp3 = king_get_uploads($file_id)['furl'] ?? null;
				$question_url = qa_path_html(qa_q_request($row['postid'], $row['title']));
				$title_sub = ''.$row['title'];
				$themeobject->output(' 
		<div class="sect-content">
		<div style="width: 100%;">
	<div class="track-bgx track-item fx-row fx-middle js-item" 
data-track="'.$mp3.'" data-title="'.$title_sub.'" data-artist="'.$title_sub.'" data-img="/music.png"> 
	<div class="track-img img-fit">
		<img src="/dle2/no_image2.jpg" alt="{title}">
		<div class="track-play fx-col fx-center anim js-play"><span class="fas fa-play-circle"></span></div>
	</div>
	<a class="track-desc fx-1" href="'.$question_url.'">
		<div class="track-title nowrap">'.$title_sub.'</div>
		<div class="track-subtitle nowrap"><i class="fas fa-headphones-alt"></i> ' .format_views($row['views']) . ' Hits
		| <span><i class="far fa-thumbs-up"></i> Votest ' .format_views($row['netvotes']) . '</span> |
		<span><i class="fa fa-comment" aria-hidden="true"></i> Comments ' .format_views($row['acount']) . '</span>
		
		</div>
	</a> 
	<a class="track-dl" href="'.$question_url.'" title="'.$title_sub.'"><span  style="margin-left: -15px;"  class="fa-solid fa-cloud-arrow-down"></span></a>
</div>		 
</div>
</div> ');
 $index++;
 
				} 
				else
				{	
					$img = king_get_uploads($row['content']); 
					if ($img) { 
			 
		$themeobject->output(' empty ');
			 
			 
					}	
				}
			}
		 
//end pus cod random		 
            foreach($queryed_questions as $row){
               
			}
            
        }
    };

