Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest sNews - sNews 1.7 - with its own forums - for discussion and user mods.

Author Topic: Extra content form - Bug / logical errors  (Read 615 times)

infomix

  • Newbie
  • *
  • Karma: 7
  • Posts: 19
Extra content form - Bug / logical errors
« on: May 30, 2012, 12:14:37 AM »

In the administration section, go to "Extra Contents' and click 'Add new', you will not need much time to observe the following situations:


1) By saying that you want the "extra content" appears on the whole site, is completely unnecessary to select a "page" or a "subcategory" (note that this is a bug in the code, because by selecting another option, and returning to "all", everything is solved)

2) Show in the subcategories of a page?

3) Hey, the option to show in the subcategories disappeared just when it is needed?

Solution:

snews.php
Comment ('//') the lines 2045 and 2058 ( just search for: $none_display to find both lines) and ADD the lines marked below with "<<< ADD" (also note the lines to be commented).

Code: [Select]
<?php
if ($contents == 'extra_new' || $edit_option == 2) {
// $none_display = $article_category == -1 ? 'none' : 'inline';
$none_display $article_category == -'inline' 'none'// <<< ADD this line
echo '<div id="def_page" style="display:'.$none_display.';"><p><label for="dp">'.l('appear_page').':</label>
<br /><select name="define_page" id="dp">'
;
echo '<option value="0"'.($edit_option != '2' ' selected="selected"' '').'>'.l('all').'</option>';
$query 'SELECT id,title FROM '._PRE.'articles'.' WHERE position = 3 ORDER BY id ASC';
$result mysql_query($query);
while ($r mysql_fetch_array($result)) {
echo '<option value="'.$r['id'].'"';
if ($edit_page == $r['id']) {
echo ' selected="selected"';
}
echo '>'.$r['title'].'</option>';
}
// echo '</select><br />'.
$none_display $article_category 'inline' 'none'// <<< ADD this line
echo '</select></p></div><div id="sw_sub" style="display:'.$none_display.';"><p>'.  // <<< ADD this line (don't forget the dot)
html_input('checkbox''show_in_subcats''asc''YES'l('show_in_subcats'), ''''''''$show_in_subcats'''''''''').'</p></div>';
}
?>

js/admin.js
In the javascript function "dependancy" (line 209), just add the two lines marked with // ADD this line below;

Code: [Select]
        // dependancy limiter
function dependancy(extra) {
var category = document.forms['post']['define_category'];
var page = document.getElementById('def_page');
var swsub = document.getElementById('sw_sub'); // ADD this line
// extra edit
if (extra=='extra') {
page.style.display = category.options[category.selectedIndex].value == '-3' ? 'inline' : 'none';
swsub.style.display = category.options[category.selectedIndex].value > '0' ? 'inline' : 'none'; // ADD this line
}
}

Result:




Additional cases

Applying the above solution, the function add/edit extra content will work normally, but some cases still need to be resolved, such as:


4) Show in subcategories of a "subcategory" ?

5) Ok, the css does the job hiding the checkbox, but anyway the option will remain checked, and the value ('YES') will be stored in the database.

Additional solution:

snews.php

Search: $show_in_subcats = 'ok'; (line 1985)
Change to: $show_in_subcats = '';
Code: [Select]
<?php
$frm_publish 
'ok'
$show_in_subcats ''// Line 1985
$frm_showonhome s('display_new_on_home') == 'on' 'ok' '';
?>

Search: <option value="'.$s['id'].'"'; (line 2036)
Change to: <option class="iamsub" value="'.$s['id'].'"';
And add the line marked with "ADD this line" below:
Code: [Select]
<?php
while ($r mysql_fetch_array($result)) {
echo '<option class="iamsub" value="'.$s['id'].'"'// Line 2036
if ($edit_page == $r['id']) {
$iamsub true// ADD this line
echo ' selected="selected"';
}
echo '>'.$r['title'].'</option>';
}
?>

At last modify the line below (2058 ~ 2060 already modified in the first solution):

From: $none_display = $article_category > 0 ? 'inline' : 'none';
To: $none_display = $article_category > 0 && !$iamsub ? 'inline' : 'none';
Code: [Select]
<?php
$none_display 
$article_category && !$iamsub 'inline' 'none'// <<< Modify this line, added in the first solution.
?>


js/admin.js

Replace the function dependancy, with the reworked function below:
Code: [Select]
        // dependancy limiter
function dependancy(extra) {
var category = document.forms['post']['define_category'];
var page = document.getElementById('def_page');
// extra edit
if (extra=='extra') {
var swsub = document.getElementById('sw_sub');
var cmb_cat = category.options[category.selectedIndex];
var chk_sub = document.getElementById("asc");
page.style.display = cmb_cat.value == '-3' ? 'inline' : 'none';
if (cmb_cat.value > '0' && cmb_cat.className != 'iamsub') {
swsub.style.display = 'inline';
chk_sub.checked = true;
} else {
swsub.style.display = 'none';
chk_sub.checked = false;
}
}
}

Result:
« Last Edit: June 30, 2012, 04:07:03 PM by infomix »
Logged

sibas

  • Sr. Member
  • ****
  • Karma: 23
  • Posts: 451
    • www.simply4all.net
Re: Extra content form - Bug / logical errors
« Reply #1 on: May 30, 2012, 09:28:02 AM »

Hey infomix
Nice catch and nice fix, need to test it further.
karma ++
Logged

mosh

  • Hero Member
  • *****
  • Karma: 77
  • Posts: 510
  • Awesome day :)
    • cms-zen
Re: Extra content form - Bug / logical errors
« Reply #2 on: May 30, 2012, 09:35:15 AM »

Hi infomix,
karma ++ for your fix and time.

after test, if a subcategory selected from the list,
the "show in subcategories?" checkbox should be hidden.

sibas

  • Sr. Member
  • ****
  • Karma: 23
  • Posts: 451
    • www.simply4all.net
Re: Extra content form - Bug / logical errors
« Reply #3 on: May 30, 2012, 09:56:32 AM »

I test it in modified snews, I play with "show in subcategories" check/uncheck and although in db writes YES/NO display always the "extra" in subcategories,
does working in original snews?
Logged

mosh

  • Hero Member
  • *****
  • Karma: 77
  • Posts: 510
  • Awesome day :)
    • cms-zen
Re: Extra content form - Bug / logical errors
« Reply #4 on: May 30, 2012, 10:06:09 AM »

Hi sibas,
the show in subcategories works only if you select a category,
it will not do anything for subcategory.

sibas

  • Sr. Member
  • ****
  • Karma: 23
  • Posts: 451
    • www.simply4all.net
Re: Extra content form - Bug / logical errors
« Reply #5 on: May 30, 2012, 10:14:44 AM »

Hey mosh, whats up?
Aaa OK I see! thanks.
Logged

sibas

  • Sr. Member
  • ****
  • Karma: 23
  • Posts: 451
    • www.simply4all.net
Re: Extra content form - Bug / logical errors
« Reply #6 on: May 30, 2012, 10:49:51 AM »

pitty that is not works in articles like the pages

I mean when you select one subcategory to display another one "select" with the articles that exist in subcategory
Logged

infomix

  • Newbie
  • *
  • Karma: 7
  • Posts: 19
Re: Extra content form - Bug / logical errors
« Reply #7 on: May 30, 2012, 12:16:06 PM »

I'll edit the post to include some more illogical situations, as already spoken, if you select a subcategory in the combobox, the checkbox "show in sub" need not be shown (and can't be selected, even if invisible).

« Last Edit: May 30, 2012, 12:17:39 PM by infomix »
Logged

mosh

  • Hero Member
  • *****
  • Karma: 77
  • Posts: 510
  • Awesome day :)
    • cms-zen
Re: Extra content form - Bug / logical errors
« Reply #8 on: May 30, 2012, 02:07:25 PM »

with the new additional solution it is working perfect,
thank you infomix  8)

like sibas added, it will be useful if articles can be selected for the extra.

blankspace

  • Newbie
  • *
  • Karma: 3
  • Posts: 22
Re: Extra content form - Bug / logical errors
« Reply #9 on: June 23, 2012, 01:51:40 PM »

Hello infomix. Thank you for this fix, I find very useful. Just, small error in code in Additional Cases

Quote
<?php
while ($r = mysql_fetch_array($result)) {
      echo '<option class="iamsub" value="'.$s['id'].'"'; // Line 2036
      if ($edit_page == $r['id']) {
         iamsub = true; // ADD this line
         echo ' selected="selected"';
      }
      echo '>'.$r['title'].'</option>';
   }
?>

The line in bold should say: $iamsub = true;
else page go empty...

Ciao
/Pax
Logged
All your internets are belong to us

infomix

  • Newbie
  • *
  • Karma: 7
  • Posts: 19
Re: Extra content form - Bug / logical errors
« Reply #10 on: June 30, 2012, 04:20:45 PM »

Thanks, little mistake when I was writing the original post (the code was tested by me before posting), is now fixed.  :)
Logged