Please login or register.

Login with username, password and session length
Advanced search  

News:

You need/want an older version of sNews ? Download an older/unsupported version here.

Author Topic: get_id function ?  (Read 6723 times)

mosh

  • Hero Member
  • *****
  • Karma: 77
  • Posts: 510
  • Awesome day :)
    • cms-zen
get_id function ?
« on: April 08, 2008, 02:22:59 PM »

 ;D hey all

i was looking in snews.php for the function get_id and nothing ?

where is it hidding  ???

awesome day

Joost

  • Guest
Re: get_id function ?
« Reply #1 on: April 08, 2008, 02:40:44 PM »

It is dead, diseased, an ex-function, get_id is no more. :'(
The same happened to function startup.

In the global scope you still find this:

Code: [Select]
<?php
$categorySEF $url['0'];
if(isset($url['1'])) $subcatSEF $url['1'];
if(is_numeric($url['1'])) $commentsPage $url['1'];
if (isset($url['2']))  $articleSEF$url['2'];
if (isset($url['3'])) $commentsPage $url['3'];
?>



Instead of  using  get_id($categorySEF)  in a function, the value is passed on using globals

So in a fresh made function, you do something like:

Code: [Select]
<?php
function do_some (){
global 
$categorySEF:

 isset (
$categorySEF) echo $categorySEF;

}

?>


You can do this with the uri parts $categorySEF, $articleSEF and $subcatSEF

Approximately around line 200, you find more variables that are used throughout the file. like article id category id, etc.
Logged

mosh

  • Hero Member
  • *****
  • Karma: 77
  • Posts: 510
  • Awesome day :)
    • cms-zen
Re: get_id function ?
« Reply #2 on: April 08, 2008, 03:07:35 PM »

 :D thank you joost
yes i can see that now,
good development  8)

ha100

  • Newbie
  • *
  • Karma: 7
  • Posts: 19
    • ha100
Re: get_id function ?
« Reply #3 on: October 27, 2008, 11:52:43 AM »

i don't want to start new topic, so i'll just paste it here. i'm porting similar articles mod to 1.7 RC2 and got stuck.

original from snews16MU

Quote
function similar_articles($start, $size) {
   
$categorySEF = get_id('category');
$articleSEF = get_id('article');

   $categoryID = $categorySEF == $homeSEF ? 0 : retrieve('id', 'categories', 'seftitle', $categorySEF);
   $articleID = retrieve('id', articles, 'seftitle', $articleSEF);
   $query = "SELECT * FROM ".db('prefix')."articles WHERE position = 1 AND published = 1 AND category = $categoryID AND id<>$articleID ORDER BY date DESC LIMIT $start, $size";
   $result = mysql_query($query);
   if (!$result || !mysql_num_rows($result)) {
      echo '<li>&raquo; '.l('no_similar_articles').'</li>';
   } else {
      $home = l('home_sef');
      while ($r = mysql_fetch_array($result)) {
         $date = date(s('date_format'), strtotime($r['date']));
         $categorySEF = find_cat_sef($r['category']);
         $title = $r['category'] == 0 ? $home : retrieve('name', 'categories', 'seftitle', $categorySEF);
         echo '<li><a href="'.db('website').$categorySEF.'/'.$r['seftitle'].'/" title="'.$title.' ('.$date.')">&raquo; '.$r['title'].'</a></li>';
      }
   }
}

changed to
Quote
// SIMILAR ARTICLES
function similar_articles($start, $size) {
global $categorySEF, $articleSEF;
   $categoryID = $categorySEF == $homeSEF ? 0 : retrieve('id', 'categories', 'seftitle', $categorySEF);
   $articleID = retrieve('id', articles, 'seftitle', $articleSEF);
   $query = "SELECT * FROM "._PRE."articles WHERE position = 1 AND published = 1 AND category = $categoryID AND id<>$articleID ORDER BY date DESC LIMIT $start, $size";
   $result = mysql_query($query);
   if (!$result || !mysql_num_rows($result)) {
      echo '<li>&raquo; '.l('no_similar_articles').'</li>';
   } else {
      $home = l('home_sef');
      while ($r = mysql_fetch_array($result)) {
         $date = date(s('date_format'), strtotime($r['date']));
         $categorySEF = find_cat_sef($r['category']);
         $title = $r['category'] == 0 ? $home : retrieve('name', 'categories', 'seftitle', $categorySEF);
         echo '<li><a href="'._SITE.$categorySEF.'/'.$r['seftitle'].'/" title="'.$title.' ('.$date.')">&raquo; '.$r['title'].'</a></li>';
      }
   }
}

in this function, i got $categoryID, but i'm not able to get $articleID. any idea?
Logged

Joost

  • Guest
Re: get_id function ?
« Reply #4 on: October 27, 2008, 01:08:55 PM »

I am not sure in which context this function is used (only on articles?).

Code: [Select]
<?php
   $categoryID 
$categorySEF == $homeSEF retrieve('id''categories''seftitle'$categorySEF);
   
$articleID retrieve('id'articles'seftitle'$articleSEF);
?>

A guess:
$articleID is the same as  $_ID
 $categoryID is the same as $_CAT or $_catID
Put both variables ( comma separated) after the global.
Logged

centered

  • Guest
Re: get_id function ?
« Reply #5 on: October 27, 2008, 01:14:01 PM »

$_ID - article ID
$_catID - Category Id


*edit*
me thinks your function will look kinda like this

Code: [Select]
// SIMILAR ARTICLES
function similar_articles($start, $size) {
global $_ID, $_catID;
$query = "SELECT
a.title, a.seftitle as a_seftitle, a.date,
p.name as p_name, p.seftitle as p_seftitle,
c.name as c_name, c.seftitle as c_seftitle
FROM "._PRE."articles as a
LEFT OUTER JOIN "._PRE."categories as p
ON p.id = a.category
LEFT OUTER JOIN "._PRE."categories as c
ON c.subcat = p.id
WHERE a.position = 1 AND a.published = 1
AND a.category = $_catID AND a.id <> $_ID
ORDER BY a.date DESC LIMIT $start, $size"; echo $query;
$result = mysql_query($query);
if (!$result || !mysql_num_rows($result)) {
echo '<li>&raquo; '.l('no_similar_articles').'</li>';
} else {
      $home = $_catID == 0 ? l('home_sef') : '';
      while ($r = mysql_fetch_array($result)) {
         $date = date(s('date_format'), strtotime($r['date']));
$categorySEF = $r['c_seftitle'] ? $r['p_seftitle'].'/'.$r['c_seftitle'] : $r['p_seftitle'];
         echo '<li><a href="'._SITE.$categorySEF.'/'.$r['a_seftitle'].'/" title="'.$r['title'].' ('.$date.')">&raquo; '.$r['title'].'</a></li>';
      }
   }
}
« Last Edit: October 27, 2008, 01:25:23 PM by equilni »
Logged

ha100

  • Newbie
  • *
  • Karma: 7
  • Posts: 19
    • ha100
Re: get_id function ?
« Reply #6 on: October 27, 2008, 09:03:51 PM »

thank you for your help. i guess after 27 hours of coding i just needed some sleep. i solved it. problem was outside the function. all the time i called it with wrong parameters :D
you should just see me when i realized. such a happiness and such an anger on the other side. i was so confused :)

but without your help, i won't be able to do it, so thank you anyway.
Logged