Location: PHPKode > projects > Absolut Engine > absolut-engine-33870/admin/classarticles.php
<?

class CArticles extends CEngine
{

   function CArticles()
   {
   $this->CEngine();
   }

   function GetSectionID()
   {
   return $this->access["ID"];
   }

   function GetSection()
   {
   echo $this->access["section"];
   }

   function GetSectionList($sectionname="",$sectionID=0)
   {
   if ($sectionname) $this->DBQuery("SELECT * FROM ".$this->table[0]." WHERE section='".$sectionname."'");
   if ($sectionID) $this->DBQuery("SELECT * FROM ".$this->table[0]." WHERE ID='".$sectionID."'");
   if (!$sectionname AND !$sectionID) $this->DBQuery("SELECT * FROM ".$this->table[0]." ORDER BY section");
   }

   // Updates statistics for the article, $default=0 if views incrementation is not required (e.g. from admin part)
   function UpdateArticleStats($default=1)
   {
   if (!$default) return;
   $this->DBQuery("UPDATE ".$this->table[4]." SET views=views+1 WHERE articleID='".$this->articleID."'");
   }

   function GetArticleID()
   {
   return $this->articleID;
   }

   function GetArticleTitle()
   {
   echo $this->title;
   }

   function GetArticleBeginning()
   {
   $this->beginning=nl2br($this->beginning);
   echo $this->beginning;
   }

   function GetArticleText()
   {
   echo $this->text;
   }

   function GetArticleAuthor()
   {
   echo $this->author;
   }

   function GetAuthorID()
   {
   return $this->authorID;
   }

   function GetAuthorName() // alias of GetArticleAuthor
   {
   echo $this->author;
   }

   // Gets author's photo if exists
   // $link=0 nolink, 1 links to author's profile
   function GetAuthorPhoto($before="",$after="",$link=0)
   {
   $outcome2=$this->outcome;
   $this->DBQuery("SELECT photo FROM ".$this->table[5]." WHERE ID='".$this->authorID."'");
   $this->DBGetRow();
   $photo=$this->access["photo"];
   $photothumb=$this->GetThumbnail($photo);
   $fullname=$this->pathimages.$this->access["fullname"]; // change to function
   if ($photo)
   {
   $this->authorphoto=TRUE;
   if (!$link) echo $before,'<img src="',$this->pathimages,$photothumb,'" alt="',$fullname,'" />',$after;
   else echo $before,'<a href="showauthor.php?authorID=',$this->GetAuthorID(),'"><img src="',$this->pathimages,$photothumb,'" alt="',$this->fullname,'" /></a>',$after;
   }
   $this->outcome=$outcome2;
   }

   function GetArticleDate()
   {
   echo $this->adate;
   }

   function GetArticleTime()
   {
   echo $this->atime;
   }

   function GetArticleSection()
   {
   echo $this->section;
   }

   function GetArticleStats()
   {
   echo $this->views;
   }

   function GetArticleFilename()
   {
   return $this->filename;
   }

   // Print out article images
   // Puts image in between $before and $after (HTML tags or text)
   // Search beginning and text of the article for replace tag and replaces it with images
   // $link - link thumbnail either to image itself (2) or to article (1 - e.g. in showarchive.php)
   // if $link=0, image is not linked (by default)
   // $imagenumber - no. of image in set
   function GetArticleImages($before="",$after="",$number=10,$link=0,$imagenumber=0)
   {
   if (!$this->image[0]) return;
   if ($this->replaced[0]) return; // Images have been replaced in text, no need to print them
   if (!$imagenumber)
      {
      for ($i=0;$i<=$number-1;$i++)
          {
          if ($this->image[$i])
             {
             $this->thumbnail[$i]=$this->GetThumbnail($this->image[$i]);
             if (!$link) echo $before,'<img src="',$this->pathimages,$this->thumbnail[$i],'" alt="',$this->imagedescription[$i],'" />',$after;
             elseif ($link==1 AND !$this->cleanurls) echo $before,'<a href="showarticle.php?articleID=',$this->GetArticleID(),'"><img src="',$this->pathimages,$this->thumbnail[$i],'" alt="',$this->filedescription[$i],'" /></a>',$after;
             elseif ($link==1 AND $this->cleanurls) echo $before,'<a href="',$this->filename,'"><img src="',$this->pathimages,$this->thumbnail[$i],'" alt="',$this->filedescription[$i],'" /></a>',$after;
             elseif ($link==2) echo $before,'<a href="',$this->pathimages,$this->image[$i],'"><img src="',$this->pathimages,$this->thumbnail[$i],'" alt="',$this->imagedescription[$i],'" /></a>',$after;
             }
          }
      }
   else
      {
      $imagenumber=$imagenumber-1;
      if ($this->image[$imagenumber])
             {
             $this->thumbnail[$imagenumber]=$this->GetThumbnail($this->image[$imagenumber]);
             if (!$link) echo $before,'<img src="',$this->pathimages,$this->thumbnail[$imagenumber],'" alt="',$this->imagedescription[$imagenumber],'" />',$after;
             elseif ($link==1 AND !$this->cleanurls) echo $before,'<a href="showarticle.php?articleID=',$this->GetArticleID(),'"><img src="',$this->pathimages,$this->thumbnail[$imagenumber],'" alt="',$this->filedescription[$imagenumber],'" /></a>',$after;
             elseif ($link==1 AND $this->cleanurls) echo $before,'<a href="',$this->filename,'"><img src="',$this->pathimages,$this->thumbnail[$imagenumber],'" alt="',$this->filedescription[$imagenumber],'" /></a>',$after;
             elseif ($link==2) echo $before,'<a href="',$this->pathimages,$this->image[$imagenumber],'"><img src="',$this->pathimages,$this->thumbnail[$imagenumber],'" alt="',$this->imagedescription[$imagenumber],'" /></a>',$after;
             }
      }
   }

   // Replaces image tags in the article for thumbnails linked to images
   // Replace file tags? $replace=0 no, 1 yes
   // $link=0 - thumbnails are not linked, if $link=1 thumbnails are linked to image
   function ReplaceImageTags($replace=0,$link=1)
   {
   if (!$replace) return;
   if (!$this->image[0]) return;
   for ($i=0;$i<=10;$i++) if ($this->image[$i]) $this->thumbnail[$i]=$this->GetThumbnail($this->image[$i]);
   if (!$link)
      {
      for ($i=1;$i<=10;$i++)
          {
          // Backward compatibility (no align/float defined)
          $this->text=str_replace('[img'.$i.']','<img src="'.$this->pathimages.$this->thumbnail[$i-1].'" alt="'.$this->imagedescription[$i-1].'" class="ae_image" />',$this->text);
          // Left or right image float / align
          $this->text=str_replace('[img'.$i.' left]','<img src="'.$this->pathimages.$this->thumbnail[$i-1].'" alt="'.$this->imagedescription[$i-1].'" class="imgleft" />',$this->text);
          $this->text=str_replace('[img'.$i.' right]','<img src="'.$this->pathimages.$this->thumbnail[$i-1].'" alt="'.$this->imagedescription[$i-1].'" class="imgright" />',$this->text);
          }
      }
   if ($link)
      {
      for ($i=1;$i<=10;$i++)
          {
          // Backward compatibility (no align/float defined)
          $this->text=str_replace('[img'.$i.']','<a href="'.$this->pathimages.$this->image[$i-1].'"><img src="'.$this->pathimages.$this->thumbnail[$i-1].'" alt="'.$this->imagedescription[$i-1].'" class="ae_image" /></a>',$this->text);
          // Left or right image float / align
          $this->text=str_replace('[img'.$i.' left]','<a href="'.$this->pathimages.$this->image[$i-1].'"><img src="'.$this->pathimages.$this->thumbnail[$i-1].'" alt="'.$this->imagedescription[$i-1].'" class="imgleft" /></a>',$this->text);
          $this->text=str_replace('[img'.$i.' right]','<a href="'.$this->pathimages.$this->image[$i-1].'"><img src="'.$this->pathimages.$this->thumbnail[$i-1].'" alt="'.$this->imagedescription[$i-1].'" class="imgright" /></a>',$this->text);
          }
      }
   $this->replaced[0]=TRUE; // Images have been replaced
   }

   // Print out article files
   function GetArticleFiles($before="",$after="",$number=5,$filenumber=0)
   {
   if ($this->replaced[1]) return; // Files have been replaced in text, no need to print them
   if (!$this->file[0]) return;
   if (!$filenumber)
      {
      for ($i=0;$i<=$number-1;$i++)
          {
          if ($this->file[$i])
             {
             echo $before,'<a href="',$this->pathfiles,$this->file[$i],'">'.$this->file[$i].'</a>',$after;
             }
          }
      }
   if ($filenumber)
      {
      $filenumber=$filenumber-1;
      if ($this->file[$filenumber])
         {
         echo $before,'<a href="',$this->pathfiles,$this->file[$filenumber],'">'.$this->file[$filenumber].'</a>',$after;
         }
      }
   $this->replaced[1]=TRUE; // Files have been replaced
   }

   // Replaces file tags in text of the article for file links
   // Replace file tags? $replace=0 no, 1 yes
   function ReplaceFileTags($replace=0)
   {
   if (!$replace) return;
   if (!$this->file[0]) return;
   $this->text=str_replace('[file1]','<a href="'.$this->pathfiles.$this->file[0].'">'.$this->file[0].'</a>',$this->text);
   $this->text=str_replace('[file2]','<a href="'.$this->pathfiles.$this->file[1].'">'.$this->file[1].'</a>',$this->text);
   $this->text=str_replace('[file3]','<a href="'.$this->pathfiles.$this->file[2].'">'.$this->file[2].'</a>',$this->text);
   $this->text=str_replace('[file4]','<a href="'.$this->pathfiles.$this->file[3].'">'.$this->file[3].'</a>',$this->text);
   $this->text=str_replace('[file5]','<a href="'.$this->pathfiles.$this->file[4].'">'.$this->file[4].'</a>',$this->text);
   $this->replaced[1]=TRUE; // Files have been replaced
   }

   // Gets article content
   function GetArticle()
   {
   $outcome2=$this->outcome;
   $this->replaced[0]=FALSE;
   $this->replaced[1]=FALSE;
   unset($this->thumbnail);
   unset($this->image);
   unset($this->imagedescription);
   unset($this->file);
   $this->articleID=$this->access["ID"];
   $this->title=stripslashes($this->access["title"]);
   $this->beginning=stripslashes($this->access["beginning"]);
   $this->text=stripslashes($this->access["text"]);
   $this->authorID=$this->access["authorID"];
   $this->adate=$this->access["adate"];
   $this->adate=$this->DateConversion($this->adate,2);
   $this->atime=$this->access["atime"];
   $this->sectionID=$this->access["sectionID"];
   $this->imagesetID=$this->access["imagesetID"];
   $this->filesetID=$this->access["filesetID"];
   $this->priority=$this->access["priority"];
   $this->status=$this->access["status"];
   $this->filename=$this->access["filename"];
   $this->DBQuery("SELECT fullname FROM ".$this->table[5]." WHERE ID='".$this->authorID."'");
   $this->DBGetRow();
   $this->author=$this->access["fullname"];
   $this->DBQuery("SELECT section FROM ".$this->table[0]." WHERE ID='".$this->sectionID."'");
   $this->DBGetRow();
   $this->section=$this->access["section"];
   $this->DBQuery("SELECT views FROM ".$this->table[4]." WHERE articleID='".$this->articleID."'");
   $this->DBGetRow();
   $this->views=$this->access["views"];
   if ($this->imagesetID)
      {
      $this->DBQuery("SELECT * FROM ".$this->table[1]." WHERE ID='".$this->imagesetID."'");
      $this->DBGetRow();
      for ($i=0;$i<=9;$i++)
          {
          $this->image[$i]=$this->access["file".($i+1)];
          $this->imagedescription[$i]=$this->access["filedescription".($i+1)];
          if ($this->image[$i]) $this->thumbnail[$i]=$this->GetThumbnail($this->image[$i]);
          }
      }
   if ($this->filesetID)
      {
      $this->DBQuery("SELECT * FROM ".$this->table[2]." WHERE ID='".$this->filesetID."'");
      $this->DBGetRow();
      $this->file[0]=$this->access["file1"]; $this->file[1]=$this->access["file2"];
      $this->file[2]=$this->access["file3"]; $this->file[3]=$this->access["file4"];
      $this->file[4]=$this->access["file5"];
      }
   $this->outcome=$outcome2;
   }

   // Gets $articlenumber articles in sectionID (0=all sections)
   // list till $adate with $priority
   // OR article $articleID
   function GetArchive($articlenumber=10,$adate=0,$sectionID="all",$authorID="all",$priority="all",$articleID=0)
   {
   if (!$adate) $adate=date("Y-m-d");
   if ($articlenumber==="all") $articlenumber=999999999;
   if ($sectionID=="all" OR !$sectionID) $sectionID="sectionID>0";
   else $sectionID="sectionID=".$sectionID;
   if ($authorID=="all") $authorID="authorID>0";
   else $authorID="authorID=".$authorID;
   if ($priority=="all") $priority="priority<2";
   else $priority="priority=".$priority;
   $this->DBQuery("SELECT * FROM ".$this->table[3]." WHERE adate<='".$adate."' AND ".$sectionID." AND ".$priority." AND ".$authorID." AND status=1 ORDER BY priority DESC, adate DESC, atime DESC LIMIT ".$articlenumber);
   if ($articleID) $this->DBQuery("SELECT * FROM ".$this->table[3]." WHERE ID='".$articleID."'");
   }

   function GetRelatedArticleID()
   {
   return $this->relatedID;
   }

   // Gets related article content
   function GetRelatedArticle()
   {
   $outcome2=$this->outcome;
   $this->relatedID=$this->access["relatedID"];
   $this->DBQuery("SELECT * FROM ".$this->table[3]." WHERE ID='".$this->relatedID."'");
   $this->DBGetRow();
   $this->title=stripslashes($this->access["title"]);
   $this->beginning=stripslashes($this->access["beginning"]);
   $this->text=stripslashes($this->access["text"]);
   $this->authorID=$this->access["authorID"];
   $this->adate=$this->access["adate"];
   $this->adate=$this->DateConversion($this->adate,2);
   $this->atime=$this->access["atime"];
   $this->filename=$this->access["filename"];
   $this->DBQuery("SELECT fullname FROM ".$this->table[5]." WHERE ID='".$this->authorID."'");
   $this->DBGetRow();
   $this->author=$this->access["fullname"];
   $this->DBQuery("SELECT section FROM ".$this->table[0]." WHERE ID='".$this->sectionID."'");
   $this->DBGetRow();
   $this->section=$this->access["section"];
   $this->DBQuery("SELECT views FROM ".$this->table[4]." WHERE articleID='".$this->articleID."'");
   $this->DBGetRow();
   $this->views=$this->access["views"];
   $this->outcome=$outcome2;
   }

   // Gets related articles for article $articleID
   function GetRelatedArchive($articleID)
   {
   $this->DBQuery("SELECT * FROM ".$this->table[7]." WHERE articleID='".$articleID."'");
   }

   // Searches archive of articles for $searchstring - searches title, beginning, text
   function SearchArchive($searchstring)
   {
   $this->DBQuery("SELECT * FROM ".$this->table[3]." WHERE title LIKE '%".$searchstring."%' OR beginning LIKE '%".$searchstring."%' OR text LIKE '%".$searchstring."%'");
   }

}

?>
Return current item: Absolut Engine