Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: MOD compatability issue  (Read 5025 times)

piXelatedEmpire

  • MIA
  • ULTIMATE member
  • ******
  • Karma: 37
  • Posts: 1401
  • currently MIA
MOD compatability issue
« on: June 20, 2007, 01:41:17 am »

I'm having trouble getting bakercad's Change Order of Pages MOD to function correctly with philmoz's Admin - Article Categorisation MOD.

The problem I believe lies within the function admin_articles under the // ARTICLES - ADMIN LIST - modified section of philmoz's MOD.
Below is how I have modified this 'new' function, that I believe is causing issues:
(NOTE: MOD1 is philmoz's Hidden Articles MOD and MOD13 is bakercad's Change Order of Pages MOD)
Quote
// ARTICLES - ADMIN LIST - modified
function admin_articles($contents) {
   $showAdminLinks = 0;
    $home= l('home');
    $xt=1;
    $catNAMES[$xt-2] = $contents == 'extra_view' ? l('all') : l('uncategorised');
    $catNAMES[0]= $home;
    $query1 = "SELECT * FROM ".db('prefix')."categories ORDER BY id ASC";
    $result1 = mysql_query($query1);
    while($ct = mysql_fetch_array($result1)) {
        $catNAMES[$ct['id']]= $ct['name'];
        $catSEF[$ct['id']] = $ct['seftitle'];
        $xt++;
    }
    switch ($contents) {
       ### MOD start [MOD13] ###
      //case 'article_view': $title = l('articles'); $subquery = "WHERE position = 1";
      case 'article_view': $title = l('articles'); $subquery = "WHERE position = 1 ORDER BY date DESC";
       ### MOD end [MOD13]  ###
      break;
       ### MOD start [MOD13] ###
        //case 'extra_view': $title = l('extra_contents'); $subquery = "WHERE SUBSTRING(position,1,1) = '2'";
      case 'extra_view': $title = l('extra_contents'); $subquery = "WHERE SUBSTRING(position,1,1) = '2' ORDER BY date DESC";
       ### MOD end [MOD13]  ###
      break;
       ### MOD start [MOD13] ###
        //case 'page_view': $title = l('pages'); $subquery = "WHERE position = 3";
      case 'page_view': $title = l('pages'); $subquery = "WHERE position = 3 ORDER BY pageorder ASC"; $pageorder = 'YES';
       ### MOD end [MOD13]  ###
      break;
    }

echo new_admin_links($showAdminLinks)."\n";
   foreach ($catNAMES as $catkey => $catvalue) {
      $subsubQuery = "AND category = $catkey ";
       ### MOD start [MOD13] ###
      //$query = "SELECT * FROM ".db('prefix')."articles $subquery AND category = $catkey ORDER BY category,date DESC";
      $query = "SELECT * FROM ".db('prefix')."articles $subquery AND category = $catkey";
       ### MOD end [MOD13]  ###
      $result = mysql_query($query);
      $numrows = mysql_num_rows($result);
      if ((!$result || !mysql_num_rows($result)) && $numrows !==0) {
         echo '

'.l('article_not_exist').'

';
      }
      else {
         if ($numrows) {
            $catSEF[$catkey] = $catkey==0?l('home_sef'):$catSEF[$catkey];
            echo '
'."\n".''.$catvalue.' '.$title.''.' '."\n";
            echo '
'."\n";
         }
      }
   }
}

// NEW ADMIN LINKS
function new_admin_links($offon) {
    if ($offon == 1) {
      $divider = "-".l('divider')."-";
      $new_links = '';
      return $new_links;
   }
}
I have highlighted in red the areas of code I believe are causing the issue.  I'm not sure how to correctly modify these lines to match bakercads modified lines:
Quote
STEP 4 - function admin_articles($contents) (snews.php)
change to: ADD the blue, REMOVE the red
Quote
function admin_articles($contents) {
   switch ($contents) {
      case 'article_view': $title = l('articles'); $subquery = "WHERE position = 1  ORDER BY date DESC"; break;
      case 'extra_view': $title = l('extra_contents'); $subquery = "WHERE SUBSTRING(position,1,1) = '2' ORDER BY date DESC"; break;
      case 'page_view': $title = l('pages'); $subquery = "WHERE position = 3 ORDER BY pageorder ASC"; $pageorder = 'YES'; break;
   }
   echo '
'.$title.'';
   $query = "SELECT * FROM ".db('prefix')."articles $subquery ORDER BY date DESC";
   $result = mysql_query($query);
   if (!$result || !mysql_num_rows($result)) {echo '

'.l('article_not_exist').'

';}
   else {
      $i = 0;
        while ($r = mysql_fetch_array($result)) {
         $articleSEF = $contents != 'extra_view' ? $r['seftitle'].'/' : '';
         
         if ($pageorder == 'YES') {
            $up_down =  ''.l('up').' | '.l('down').' '.l('divider');
         }
         

         echo '

'.$up_down.' '.date(s('date_format'), strtotime($r['date'])).' '.$r['title'].' '.l('divider').' '.l('view').' ';
         echo  l('divider').' '.l('edit').' ';
          if ($r['published'] == 2) {echo  l('divider').' ['.l('status').' '.l('future_posting').']';}
         if ($r['published'] == 0) {echo  l('divider').' ['.l('status').' '.l('unpublished').']';}
         echo '

';
         $i++;
      }
      echo '
';
}}
STEP 5 - function processing($contents) under case 'admin_article'; (snews.php)
find
Quote
case(isset($_POST['add_article'])):
                  mysql_query("INSERT INTO ".db('prefix')."articles(title, seftitle, text, date, category, position, displaytitle, displayinfo, commentable, published, description_meta, keywords_meta) VALUES('$title', '$seftitle', '$text', '$date', '$category', '$position', '$display_title', '$display_info', '$commentable', '$publish_article', '$description_meta', '$keywords_meta')");
                  $pos = substr($position, 0, 1);
                  switch ($pos) {case 1: $link = 'articles/'; break; case 2: $link = 'extra_contents/'; break; case 3: $link = 'pages/'; break;}
                  break;
change to
Quote
case(isset($_POST['add_article'])):
                  
                  if ($position == 3) {
                     $order = get_order(DESC) +1;
                     $ins_order = ", pageorder";
                     $value_order = ", '$order'";
                  }
                  

                  mysql_query("INSERT INTO ".db('prefix')."articles(title, seftitle, text, date, category, position, displaytitle, displayinfo, commentable, published, description_meta, keywords_meta".$ins_order.") VALUES('$title', '$seftitle', '$text', '$date', '$category', '$position', '$display_title', '$display_info', '$commentable', '$publish_article', '$description_meta', '$keywords_meta'".$value_order.")");
                  $pos = substr($position, 0, 1);
                  switch ($pos) {case 1: $link = 'articles/'; break; case 2: $link = 'extra_contents/'; break; case 3: $link = 'pages/'; break;}
                  break;
Now, I *think the placement of the $up_down variable in my code is causing the issue, or at least contributing to it.
Quote from: my modified code
echo '

'.$up_down.''.$r['id'].' - '.$r['title'].' '.l('divider').' '.l('view').' '."\n";

Quote from: bakercads MOD code
echo '

'.$up_down.' '.date(s('date_format'), strtotime($r['date'])).' '.$r['title'].' '.l('divider').' '.l('view').' ';

However I'm not entirely sure.  Little help? :/
Logged
my apologies to the sNews crew, but I will be MIA for the forseeable future

codetwist

  • Hero Member
  • *****
  • Karma: 50
  • Posts: 940
MOD compatability issue
« Reply #1 on: June 20, 2007, 08:22:24 am »

And what is nature of problems? Blank page or unfinished page or just incorrect action? Or You want us come up with more guesses on this one :P
Logged

piXelatedEmpire

  • MIA
  • ULTIMATE member
  • ******
  • Karma: 37
  • Posts: 1401
  • currently MIA
MOD compatability issue
« Reply #2 on: June 20, 2007, 08:54:31 am »

heh I edited the post so many times I forgot to post the error message and the actual issue i'm having :/
Basically, when i click the 'View' link in the admin panel to view my Pages, the page loads and I receive the same MySQL error twice.  I'll post the exact error message and a screenshot when I get home.
Logged
my apologies to the sNews crew, but I will be MIA for the forseeable future

codetwist

  • Hero Member
  • *****
  • Karma: 50
  • Posts: 940
MOD compatability issue
« Reply #3 on: June 20, 2007, 09:25:15 am »

Ok, few ideas to consider ;)

First this excerpt from code:
Code: [Select]
   switch ($contents) {
        ### MOD start [MOD13] ###
        //case 'article_view': $title = l('articles'); $subquery = "WHERE position = 1";
        case 'article_view': $title = l('articles'); $subquery = "WHERE position = 1 ORDER BY date DESC";
        ### MOD end [MOD13]  ###
        break;
As You can see before MOD13 $subquery variable standed exclusively for WHERE condition; not so after this modification ;)

MOD1 didn't changed this - it still treated $subquery as WHERE condition only - meaning that using it later You can append more conditions to it when building final query. I guess You will have to elaborate a little on MOD13 front - like split $subquery into two components - (1) for WHERE conditions and (2) for ORDER conditions so You can use them later to build queries properly ;)

The place in merged code where first SHTF is this:
Code: [Select]
        ### MOD start [MOD13] ###
        //$query = "SELECT * FROM ".db('prefix')."articles $subquery AND category = $catkey ORDER BY category,date DESC";
        $query = "SELECT * FROM ".db('prefix')."articles $subquery AND category = $catkey";
        ### MOD end [MOD13]  ###
        $result = mysql_query($query);
Put an
Code: [Select]
echo $query;right before line with '$result = mysql_query($query);' Should be incorrect SQL statement ;)

And Your highlights are pretty correct IMHO. So, go for splitting that $subquery into 2 variables to use them for building correct $query content.
Logged

piXelatedEmpire

  • MIA
  • ULTIMATE member
  • ******
  • Karma: 37
  • Posts: 1401
  • currently MIA
MOD compatability issue
« Reply #4 on: June 20, 2007, 10:50:51 am »

Ok thanks for your assistance codie :)
NOTE: whenever I attempt to 'View' (click the View button) on any of Articles, Extras and Pages, I receive a similar error as posted below.

Quote from: codetwist
The place in merged code where first SHTF is this:
Code: [Select]
        ### MOD start [MOD13] ###
        //$query = "SELECT * FROM ".db('prefix')."articles $subquery AND category = $catkey ORDER BY category,date DESC";
        $query = "SELECT * FROM ".db('prefix')."articles $subquery AND category = $catkey";
        ### MOD end [MOD13]  ###
        $result = mysql_query($query);
Put an
Code: [Select]
echo $query;right before line with '$result = mysql_query($query);' Should be incorrect SQL statement ;)
Did that, produced the following:
Quote
SELECT * FROM articles WHERE position = 3 ORDER BY pageorder ASC AND category = -1
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\Xampp\xampp\htdocs\sNews16DE\snews.php on line 2339
No contents yet

SELECT * FROM articles WHERE position = 3 ORDER BY pageorder ASC AND category = 0
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\Xampp\xampp\htdocs\sNews16DE\snews.php on line 2339
No contents yet
Here's a screenshot if it helps:

For your information, line 2339 has the following:
Quote
2330 echo new_admin_links($showAdminLinks)."\n";
2331   foreach ($catNAMES as $catkey => $catvalue) {
2332      $subsubQuery = "AND category = $catkey ";
2333      ### MOD start [MOD13] ###
2334      //$query = "SELECT * FROM ".db('prefix')."articles $subquery AND category = $catkey ORDER BY category,date DESC";
2335      $query = "SELECT * FROM ".db('prefix')."articles $subquery AND category = $catkey";
2336      ### MOD end [MOD13]  ###
2337      echo $query;      
2338      $result = mysql_query($query);
2339      $numrows = mysql_num_rows($result);
Quote from: codetwist
First this excerpt from code:
Code: [Select]
   switch ($contents) {
        ### MOD start [MOD13] ###
        //case 'article_view': $title = l('articles'); $subquery = "WHERE position = 1";
        case 'article_view': $title = l('articles'); $subquery = "WHERE position = 1 ORDER BY date DESC";
        ### MOD end [MOD13]  ###
        break;
MOD1 didn't changed this - it still treated $subquery as WHERE condition only - meaning that using it later You can append more conditions to it when building final query. I guess You will have to elaborate a little on MOD13 front - like split $subquery into two components - (1) for WHERE conditions and (2) for ORDER conditions so You can use them later to build queries properly ;)
So, for example, you're suggesting something along the lines of:
Code: [Select]
$subquery1 = "WHERE position = 1";
$subquery2 = "ORDER BY date DESC";
and repeat this process for all 3 of:
Code: [Select]
case 'article_view':
case 'extra_view':
case 'page_view':
?
Logged
my apologies to the sNews crew, but I will be MIA for the forseeable future

codetwist

  • Hero Member
  • *****
  • Karma: 50
  • Posts: 940
MOD compatability issue
« Reply #5 on: June 20, 2007, 11:36:45 am »

Ok, now, that SQL statement is wrong.

So, proceed with those variables for all three cases; only I suggest name them and fill them like this (leading space):
Code: [Select]
  $subqueryWhere = " WHERE position = 1";
   $subqueryOrder = " ORDER BY date DESC";
Will be easier to read the code further on ;)

And change $query building statement like this:
Code: [Select]
  $query = "SELECT * FROM ".db('prefix')."articles $subqueryWhere AND category = $catkey $subqueryOrder";
Logged

piXelatedEmpire

  • MIA
  • ULTIMATE member
  • ******
  • Karma: 37
  • Posts: 1401
  • currently MIA
MOD compatability issue
« Reply #6 on: June 20, 2007, 02:02:07 pm »

Mr Twist, you are indeed a treasure to this community!  Worked an absolute treat!  Thank you every so much!  This is for you:



and there's plenty more where that came from! :D

Not only did you get the MODs to work in harmony, you taught me a thing or 2 about creating variables with MySQL statements.  Cheers :D
Logged
my apologies to the sNews crew, but I will be MIA for the forseeable future