Commit 83409a08 by pupi1985

Minor formatting and SQL improvements to mouseover plugin.

parent b311cb1a
...@@ -28,19 +28,18 @@ ...@@ -28,19 +28,18 @@
public function option_default($option) public function option_default($option)
{ {
if ($option=='mouseover_content_max_len') if ($option === 'mouseover_content_max_len')
return 480; return 480;
} }
public function admin_form(&$qa_content) public function admin_form(&$qa_content)
{ {
$saved=false; $saved = qa_clicked('mouseover_save_button');
if (qa_clicked('mouseover_save_button')) { if ($saved) {
qa_opt('mouseover_content_on', (int)qa_post_text('mouseover_content_on_field')); qa_opt('mouseover_content_on', (int) qa_post_text('mouseover_content_on_field'));
qa_opt('mouseover_content_max_len', (int)qa_post_text('mouseover_content_max_len_field')); qa_opt('mouseover_content_max_len', (int) qa_post_text('mouseover_content_max_len_field'));
$saved=true;
} }
qa_set_display_rules($qa_content, array( qa_set_display_rules($qa_content, array(
...@@ -63,7 +62,7 @@ ...@@ -63,7 +62,7 @@
'label' => 'Maximum length of preview:', 'label' => 'Maximum length of preview:',
'suffix' => 'characters', 'suffix' => 'characters',
'type' => 'number', 'type' => 'number',
'value' => (int)qa_opt('mouseover_content_max_len'), 'value' => (int) qa_opt('mouseover_content_max_len'),
'tags' => 'name="mouseover_content_max_len_field"', 'tags' => 'name="mouseover_content_max_len_field"',
), ),
), ),
......
...@@ -28,38 +28,38 @@ ...@@ -28,38 +28,38 @@
public function q_list($q_list) public function q_list($q_list)
{ {
if (count(@$q_list['qs']) && qa_opt('mouseover_content_on')) { // first check it is not an empty list and the feature is turned on if (!empty($q_list['qs']) && qa_opt('mouseover_content_on')) { // 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) // Collect the question ids of all items in the question list (so we can do this in one DB query)
$postids=array(); $postids = array();
foreach ($q_list['qs'] as $question) foreach ($q_list['qs'] as $question)
if (isset($question['raw']['postid'])) if (isset($question['raw']['postid']))
$postids[]=$question['raw']['postid']; $postids[] = $question['raw']['postid'];
if (count($postids)) { if (!empty($postids)) {
// Retrieve the content for these questions from the database and put into an array // 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); $maxlength = qa_opt('mouseover_content_max_len');
$postinfo=qa_db_read_all_assoc($result, 'postid'); $result = qa_db_query_sub('SELECT postid, LEFT(content, #) content, format FROM ^posts WHERE postid IN (#)', $maxlength + 1, $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 // Get the regular expression fragment to use for blocked words and the maximum length of content to show
$blockwordspreg=qa_get_block_words_preg(); $blockwordspreg = qa_get_block_words_preg();
$maxlength=qa_opt('mouseover_content_max_len');
// Now add the popup to the title for each question // Now add the popup to the title for each question
foreach ($q_list['qs'] as $index => $question) { foreach ($q_list['qs'] as $index => $question)
$thispost=@$postinfo[$question['raw']['postid']]; if (isset($postinfo[$question['raw']['postid']])) {
$thispost = $postinfo[$question['raw']['postid']];
if (isset($thispost)) { $text = qa_viewer_text($thispost['content'], $thispost['format'], array('blockwordspreg' => $blockwordspreg));
$text=qa_viewer_text($thispost['content'], $thispost['format'], array('blockwordspreg' => $blockwordspreg)); $text = qa_shorten_string_line($text, $maxlength);
$text=qa_shorten_string_line($text, $maxlength); $title = isset($question['title']) ? $question['title'] : '';
$q_list['qs'][$index]['title']='<span title="'.qa_html($text).'">'.@$question['title'].'</span>'; $q_list['qs'][$index]['title'] = sprintf('<span title="%s">%s</span>', qa_html($text), $title);
} }
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment