Advertisement
ajayver

Q2A Mouseover plugin latest

Feb 24th, 2016
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.18 KB | None | 0 0
  1. <?php
  2. /*
  3.     Question2Answer by Gideon Greenspan and contributors
  4.     http://www.question2answer.org/
  5.  
  6.     File: qa-plugin/mouseover-layer/qa-mouseover-layer.php
  7.     Description: Theme layer class for mouseover layer plugin
  8.  
  9.  
  10.     This program is free software; you can redistribute it and/or
  11.     modify it under the terms of the GNU General Public License
  12.     as published by the Free Software Foundation; either version 2
  13.     of the License, or (at your option) any later version.
  14.  
  15.     This program is distributed in the hope that it will be useful,
  16.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.     GNU General Public License for more details.
  19.  
  20.     More about this license: http://www.question2answer.org/license.php
  21. */
  22.  
  23. class qa_html_theme_layer extends qa_html_theme_base
  24. {
  25.     public function q_list($q_list)
  26.     {
  27.         if (!empty($q_list['qs']) && qa_opt('mouseover_content_on')) { // first check it is not an empty list and the feature is turned on
  28.  
  29.             // Collect the question ids of all items in the question list (so we can do this in one DB query)
  30.  
  31.             $postids = array();
  32.             foreach ($q_list['qs'] as $question) {
  33.                 if (isset($question['raw']['postid']))
  34.                     $postids[] = $question['raw']['postid'];
  35.             }
  36.  
  37.             if (!empty($postids)) {
  38.  
  39.                 // Retrieve the content for these questions from the database
  40.  
  41.                 $maxlength = qa_opt('mouseover_content_max_len');
  42.                 $result = qa_db_query_sub('SELECT postid, content, format FROM ^posts WHERE postid IN (#)', $postids);
  43.                 $postinfo = qa_db_read_all_assoc($result, 'postid');
  44.  
  45.                 // Get the regular expression fragment to use for blocked words and the maximum length of content to show
  46.  
  47.                 $blockwordspreg = qa_get_block_words_preg();
  48.  
  49.                 // Now add the popup to the title for each question
  50.  
  51.                 foreach ($q_list['qs'] as $index => $question) {
  52.                     if (isset($postinfo[$question['raw']['postid']])) {
  53.                         $thispost = $postinfo[$question['raw']['postid']];
  54.                         ///////
  55.                         $q_list['qs'][$index]['content'] = $thispost['content']; //Added by ajayver for displaying question content on the main page 24.02.2016
  56.                         ///////
  57.                         $text = qa_viewer_text($thispost['content'], $thispost['format'], array('blockwordspreg' => $blockwordspreg));
  58.                         $text = preg_replace('/\s+/', ' ', $text);  // Remove duplicated blanks, new line characters, tabs, etc
  59.                         $text = qa_shorten_string_line($text, $maxlength);
  60.                         $title = isset($question['title']) ? $question['title'] : '';
  61.                         $q_list['qs'][$index]['title'] = $this->getHtmlTitle(qa_html($text), $title);
  62.  
  63.                     }
  64.                 }
  65.             }
  66.         }
  67.  
  68.         parent::q_list($q_list); // call back through to the default function
  69.     }
  70.  
  71.     /**
  72.      * Returns the needed HTML to display the tip. Depending on the theme in use, this might need to be
  73.      * tuned in order for the tip to be displayed properly
  74.      *
  75.      * @access private
  76.      * @param string $mouseOverText Text of the tip
  77.      * @param string $questionTitle Question title
  78.      * @return string HTML needed to display the tip and the question title
  79.      */
  80.     private function getHtmlTitle($mouseOverText, $questionTitle)
  81.     {
  82.         return sprintf('<span title="%s">%s</span>', $mouseOverText, $questionTitle);
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement