Commit f9667892 by Scott

Merge branch 'pr/51' into dev

parents 22095853 bbbbd6bb
...@@ -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,36 +28,38 @@ ...@@ -28,36 +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);
} }
} }
} }
......
...@@ -28,24 +28,26 @@ ...@@ -28,24 +28,26 @@
public function option_default($option) public function option_default($option)
{ {
if ($option=='tag_cloud_count_tags') if ($option === 'tag_cloud_count_tags')
return 100; return 100;
if ($option=='tag_cloud_font_size') if ($option === 'tag_cloud_font_size')
return 24; return 24;
if ($option=='tag_cloud_size_popular') if ($option === 'tag_cloud_minimal_font_size')
return 8;
if ($option === 'tag_cloud_size_popular')
return true; return true;
} }
public function admin_form() public function admin_form()
{ {
$saved=false; $saved = qa_clicked('tag_cloud_save_button');
if (qa_clicked('tag_cloud_save_button')) { if ($saved) {
qa_opt('tag_cloud_count_tags', (int)qa_post_text('tag_cloud_count_tags_field')); qa_opt('tag_cloud_count_tags', (int) qa_post_text('tag_cloud_count_tags_field'));
qa_opt('tag_cloud_font_size', (int)qa_post_text('tag_cloud_font_size_field')); qa_opt('tag_cloud_font_size', (int) qa_post_text('tag_cloud_font_size_field'));
qa_opt('tag_cloud_size_popular', (int)qa_post_text('tag_cloud_size_popular_field')); qa_opt('tag_cloud_minimal_font_size', (int) qa_post_text('tag_cloud_minimal_font_size_field'));
$saved=true; qa_opt('tag_cloud_size_popular', (int) qa_post_text('tag_cloud_size_popular_field'));
} }
return array( return array(
...@@ -55,20 +57,28 @@ ...@@ -55,20 +57,28 @@
array( array(
'label' => 'Maximum tags to show:', 'label' => 'Maximum tags to show:',
'type' => 'number', 'type' => 'number',
'value' => (int)qa_opt('tag_cloud_count_tags'), 'value' => (int) qa_opt('tag_cloud_count_tags'),
'suffix' => 'tags', 'suffix' => 'tags',
'tags' => 'name="tag_cloud_count_tags_field"', 'tags' => 'name="tag_cloud_count_tags_field"',
), ),
array( array(
'label' => 'Starting font size:', 'label' => 'Biggest font size:',
'suffix' => 'pixels', 'suffix' => 'pixels',
'type' => 'number', 'type' => 'number',
'value' => (int)qa_opt('tag_cloud_font_size'), 'value' => (int) qa_opt('tag_cloud_font_size'),
'tags' => 'name="tag_cloud_font_size_field"', 'tags' => 'name="tag_cloud_font_size_field"',
), ),
array( array(
'label' => 'Smallest allowed font size:',
'suffix' => 'pixels',
'type' => 'number',
'value' => (int) qa_opt('tag_cloud_minimal_font_size'),
'tags' => 'name="tag_cloud_minimal_font_size_field"',
),
array(
'label' => 'Font size represents tag popularity', 'label' => 'Font size represents tag popularity',
'type' => 'checkbox', 'type' => 'checkbox',
'value' => qa_opt('tag_cloud_size_popular'), 'value' => qa_opt('tag_cloud_size_popular'),
...@@ -98,39 +108,39 @@ ...@@ -98,39 +108,39 @@
public function allow_region($region) public function allow_region($region)
{ {
return ($region=='side'); return ($region === 'side');
} }
public function output_widget($region, $place, $themeobject, $template, $request, $qa_content) public function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
{ {
require_once QA_INCLUDE_DIR.'qa-db-selects.php'; require_once QA_INCLUDE_DIR . 'qa-db-selects.php';
$populartags=qa_db_single_select(qa_db_popular_tags_selectspec(0, (int)qa_opt('tag_cloud_count_tags'))); $populartags = qa_db_single_select(qa_db_popular_tags_selectspec(0, (int) qa_opt('tag_cloud_count_tags')));
reset($populartags); $maxcount = reset($populartags);
$maxcount=current($populartags);
$themeobject->output( $themeobject->output(sprintf('<h2 style="margin-top: 0; padding-top: 0;">%s</h2>', qa_lang_html('main/popular_tags')));
'<h2 style="margin-top:0; padding-top:0;">',
qa_lang_html('main/popular_tags'),
'</h2>'
);
$themeobject->output('<div style="font-size:10px;">'); $themeobject->output('<div style="font-size: 10px;">');
$maxsize=qa_opt('tag_cloud_font_size'); $maxsize = qa_opt('tag_cloud_font_size');
$scale=qa_opt('tag_cloud_size_popular'); $minsize = qa_opt('tag_cloud_minimal_font_size');
$blockwordspreg=qa_get_block_words_preg(); $scale = qa_opt('tag_cloud_size_popular');
$blockwordspreg = qa_get_block_words_preg();
foreach ($populartags as $tag => $count) { foreach ($populartags as $tag => $count) {
if (count(qa_block_words_match_all($tag, $blockwordspreg))) $matches = qa_block_words_match_all($tag, $blockwordspreg);
continue; // skip censored tags if (empty($matches)) {
if ($scale) {
$size=number_format(($scale ? ($maxsize*$count/$maxcount) : $maxsize), 1); $size = number_format($maxsize * $count / $maxcount, 1);
if ($size < $minsize)
if (($size>=5) || !$scale) $size = $minsize;
$themeobject->output('<a href="'.qa_path_html('tag/'.$tag).'" style="font-size:'.$size.'px; vertical-align:baseline;">'.qa_html($tag).'</a>'); } else
$size = $maxsize;
$themeobject->output(sprintf('<a href="%s" style="font-size: %dpx; vertical-align: baseline;">%s</a>', qa_path_html('tag/' . $tag), $size, qa_html($tag)));
}
} }
$themeobject->output('</div>'); $themeobject->output('</div>');
......
...@@ -126,7 +126,7 @@ h2 {font-size:22px; color:#c659ab; padding-top:12px; clear:both;} ...@@ -126,7 +126,7 @@ h2 {font-size:22px; color:#c659ab; padding-top:12px; clear:both;}
.qa-nav-main-item {float:left; padding-left:10px;} .qa-nav-main-item {float:left; padding-left:10px;}
.qa-nav-main-item-opp {float:right; padding-right:10px;} .qa-nav-main-item-opp {float:right; padding-right:10px;}
.qa-nav-main-link {background:#efeb9c url(nav-main-bg.png) repeat-x left top; color:#597700; display:block; padding:14px 10px;} .qa-nav-main-link {background:#efeb9c url(nav-main-bg.png) repeat-x left top; color:#597700; display:block; padding:14px 10px;}
.qa-nav-main-link:hover,.qa-nav-main-selected {url(nav-main-sel-bg.png) repeat-x left top; border-left:1px solid #e9e697; border-right:1px solid #e9e697; color:#8d006a; padding:14px 9px; text-decoration:none;} .qa-nav-main-link:hover,.qa-nav-main-selected {background: url(nav-main-sel-bg.png) repeat-x left top; border-left:1px solid #e9e697; border-right:1px solid #e9e697; color:#8d006a; padding:14px 9px; text-decoration:none;}
.qa-nav-main-hot .qa-nav-main-link {color:#c33;} .qa-nav-main-hot .qa-nav-main-link {color:#c33;}
.qa-nav-sub {clear:both; background:url(nav-sub-bg.png) repeat-x left top;} .qa-nav-sub {clear:both; background:url(nav-sub-bg.png) repeat-x left top;}
...@@ -446,7 +446,7 @@ h2 {font-size:22px; color:#c659ab; padding-top:12px; clear:both;} ...@@ -446,7 +446,7 @@ h2 {font-size:22px; color:#c659ab; padding-top:12px; clear:both;}
.qa-nav-footer-link {color:#FFF; text-decoration:underline !important;} .qa-nav-footer-link {color:#FFF; text-decoration:underline !important;}
.qa-nav-footer-link:hover {color:#f5d495;} .qa-nav-footer-link:hover {color:#f5d495;}
.qa-attribution {float:right;} .qa-attribution {float:right;}
.qa-attribution a {color:#FFF; text-decoration:underline; !important;} .qa-attribution a {color:#FFF; text-decoration:underline !important;}
.qa-attribution a:hover {color:#f5d495;} .qa-attribution a:hover {color:#f5d495;}
/* Classes passed to theme */ /* Classes passed to theme */
......
...@@ -415,7 +415,7 @@ h2 {font-size:16px; padding-top:12px; clear:both;} ...@@ -415,7 +415,7 @@ h2 {font-size:16px; padding-top:12px; clear:both;}
.qa-nav-footer-link {color:#FFF; text-decoration:underline !important;} .qa-nav-footer-link {color:#FFF; text-decoration:underline !important;}
.qa-nav-footer-link:hover {color:#f5d495;} .qa-nav-footer-link:hover {color:#f5d495;}
.qa-attribution {float:right;} .qa-attribution {float:right;}
.qa-attribution a {color:#FFF; text-decoration:underline; !important;} .qa-attribution a {color:#FFF; text-decoration:underline !important;}
.qa-attribution a:hover {color:#f5d495;} .qa-attribution a:hover {color:#f5d495;}
/* Classes in HTML passed to theme class */ /* Classes in HTML passed to theme class */
......
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