Location: PHPKode > scripts > GigKalender > news/functions.php
<?php
/*
    CREATIVE COMMONS - Attribution-No Derivative Works 3.0 Germany:
    - You may not alter, transform, or build upon this work.
    - Dieses Werk darf nicht bearbeitet oder in anderer Weise verändert werden.
*/
function NewsBackendNavigation ()
  {
    global $AnzahlSeiten;
    if ( $AnzahlSeiten>'1' )
    {
      global $aktuelleSeite;
      global $L_111;

      $temp = '<div class="GigNavigation">'.$L_111.': ';
      $i = '1';
      while ($i <= $AnzahlSeiten)
      {
        if ($aktuelleSeite == $i) { $temp = $temp.'<b>'.$i.'</b> '; }
        else { $temp = $temp.'<a href="index.php?submenu=news&amp;page=backend_showAllNews&amp;page='.$i.'">'.$i.'</a> '; }
        $i++;
      }
     $temp = $temp.'</div>';
    }
    else $temp = '';
    return $temp;
  }
  
function convertString ( $String )
{
  $String = str_replace("<","&lt;",$String);
  $String = str_replace(">","&gt;",$String);
  $String = str_replace("&","&amp;",$String);
  $String = str_replace('"','&quot;',$String);
  $String = str_replace("'","&apos;",$String);
  return $String;
}
  
function getTimeStringRFC3339 ($Timestamp)
{
  // get TimeZone
  $timeZone = date('O', $Timestamp);
  // create first part of AtomTime
  $atomTime[0] = date('Y-m-d\TH:i:s', $Timestamp );
  // build second part of AtomTime
  $atomTime[1] = substr($timeZone,0,3). ':' .substr($timeZone,3,2);
  // merge the 2 parts to one
  $atomTimeString = implode('', $atomTime);
  return $atomTimeString;
}
  
function writeAllFeeds ()
{
  writeAtomFeed();
  writeRSSFeed();
}
  
function writeAtomFeed ()
{
  
  global $prefix;
  global $GigKalenderPath;
  global $GigKalenderVersion;
  $SetupNewsChannelURL = getSetup('SetupNewsChannelURL');
  $path = str_replace("\\","/",dirname(__FILE__));
  $path = str_replace("/news","/news",$path);
  $aktuellerEintrag = AnzahlVeroeffentlichterNewsInDatenbank();

  $String = '<?xml version="1.0" encoding="utf-8"?>
  <feed xmlns="http://www.w3.org/2005/Atom">
  <title>'.getSetup('SetupNewsChannelTitle').'</title>
  <subtitle type="text">'.getSetup('SetupNewsChannelDescription').'</subtitle>
  <updated>'.getTimeStringRFC3339(time()).'</updated>
  <link href="'.$GigKalenderPath.'news/news.atom" rel="self" />
  <generator>GigKalender '.$GigKalenderVersion.'</generator>
  <rights>'.getSetup('SetupNewsChannelCopyright').'</rights>
  <id>'.getSetup('SetupNewsChannelURL').'</id>';
  

  // NewsFeed schreiben
    $sql = "SELECT * FROM ".$prefix."news order by Date DESC";
    $result = mysql_query($sql);
    $datei = $path."/news.atom";
    $fp=fopen($datei,"w+");

    while ($row = mysql_fetch_array($result))
    {
      extract($row);
      if ( $Publish=='1' )
      {
        if ( substr_count($SetupNewsChannelURL, '?')) $URL = $SetupNewsChannelURL.'&amp;';
        else $URL = $SetupNewsChannelURL.'?';
        $URL = $URL.'NewsID='.$aktuellerEintrag.'#news'.$aktuellerEintrag;

        $AuthorEmailadress = getUserVar ($AddedFrom, 'UserEmailadress');
        if ( $AuthorEmailadress!='' ) $Email = '<email>'.$AuthorEmailadress.'</email>';
        else $Email = '';
        
        $Title = convertString ( $Title );
        
        $String = $String.'
  <entry>
    <title>'.$Title.'</title>
    <content type="xhtml" xml:lang="'.getSetup('SetupNewsChannelLanguage').'">
      <div xmlns="http://www.w3.org/1999/xhtml">'.$Text.'</div>
    </content>
    <author>
      <name>'.$AddedFrom.'</name>
      <uri>'.getSetup('SetupNewsChannelURL').'</uri>
      '.$Email.'
    </author>
    <id>'.$URL.'</id>
    <updated>'.getTimeStringRFC3339($Date).'</updated>
  </entry>';
      $aktuellerEintrag--;
      }
    }
    $String = $String.'
</feed>';
    fwrite($fp,$String);
}
  
function writeRSSFeed ()
{
  
  global $prefix;
  global $GigKalenderPath;
  global $GigKalenderVersion;
  $SetupNewsChannelURL = getSetup('SetupNewsChannelURL');
  $path = str_replace("\\","/",dirname(__FILE__));
  $path = str_replace("/news","/news",$path);
  $aktuellerEintrag = AnzahlVeroeffentlichterNewsInDatenbank();
  
  $String = '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
      <title>'.getSetup('SetupNewsChannelTitle').'</title>
      <link>'.getSetup('SetupNewsChannelURL').'</link>
      <atom:link href="'.$GigKalenderPath.'news/news.rss" rel="self" type="application/rss+xml" />
      <description>'.getSetup('SetupNewsChannelDescription').'</description>
      <language>'.getSetup('SetupNewsChannelLanguage').'</language>
      <copyright>'.getSetup('SetupNewsChannelCopyright').'</copyright>
      <pubDate>'.gmdate ( "D, d M Y H:i:s" ).' GMT</pubDate>
      <lastBuildDate>'.gmdate ( "D, d M Y H:i:s" ).' GMT</lastBuildDate>
      <generator>GigKalender '.$GigKalenderVersion.'</generator>';
  
  // NewsFeed schreiben
    $sql = "SELECT * FROM ".$prefix."news order by Date DESC";
    $result = mysql_query($sql);
    $datei = $path."/news.rss";
    $fp=fopen($datei,"w+");

    while ($row = mysql_fetch_array($result))
    {
      extract($row);
      if ( substr_count($SetupNewsChannelURL, '?')) $URL = $SetupNewsChannelURL.'&amp;';
      else $URL = $SetupNewsChannelURL.'?';
      $URL = $URL.'NewsID='.$aktuellerEintrag.'#news'.$aktuellerEintrag;
      
      $AuthorEmailadress = getUserVar ($AddedFrom, 'UserEmailadress');
      if ( $AuthorEmailadress!='' ) $Email = '<author>'.$AuthorEmailadress.' ('.$AddedFrom.')</author>';
      else $Email = '';
      
      $Title = convertString ( $Title );
      
      if ( $Publish=='1' )
      {
        $String = $String.'
        <item>
          <guid>'.$URL.'</guid>
          <title>'.$Title.'</title>
          <link>'.$URL.'</link>
          <description><![CDATA['.$Text.']]></description>
          '.$Email.'
          <pubDate>'.gmdate ( "D, d M Y H:i:s", $Date ).' GMT</pubDate>
        </item>';
        $aktuellerEintrag--;
      }
    }
    $String = $String.'</channel>
    </rss>';
    fwrite($fp,$String);
}
  
function importNewsEntry ($Date, $AddedFrom, $Title, $Text, $DateOfLastEdit, $LastEditor, $Publish)
  {
    global $prefix;
    
    
    // HTML-Tags entfernen
      $Title = strip_tags($Title);
    $Text = str_replace("&","&amp;",$Text);
    // Maskieren spezieller Zeichen für die Verwendung in einer SQL-Anweisung
      $Title = mysql_real_escape_string($Title);
      $Text = mysql_real_escape_string($Text);
    // Leere numerische Variablen als NULL definieren
      if ( $Date=='' ) $Date="NULL";
      if ( $DateOfLastEdit=='' ) $DateOfLastEdit="NULL";
      if ( $Publish=='' ) $Publish="NULL";

    $sql = "INSERT INTO ".$prefix."news (Date, AddedFrom, Title, Text, DateOfLastEdit, LastEditor, Publish)     
      VALUES ($Date, '$AddedFrom', '$Title', '$Text', $DateOfLastEdit, '$LastEditor', $Publish)";
    $resultat = mysql_query($sql);
    if ($resultat) { return true; }
    else {return false;}
}   
  
function AnzahlVeroeffentlichterNewsInDatenbank ()
  {
    global $prefix;
    

    $sql = "SELECT count(*) as zahl FROM ".$prefix."news WHERE Publish= '1'";
    $result = mysql_query($sql);
    $row = mysql_fetch_array($result);
    return $row['zahl'];
  }
  
function  NewsNavigation ( $Locator )
  {
    global $AnzahlSeiten;
    global $aktuelleSeite;
    global $L_111;
    global $L_112;
    global $NewsID;

    $temp = '<div class="NewsNavigation">'.$L_111.': ';
    $Seitenzahl = $AnzahlSeiten;

    // $FormActionURL = str_replace("?NewsID=".$NewsID, "", $_SERVER['REQUEST_URI']);
    // $FormActionURL = getSetup('SetupNewsChannelURL');
    $URL = getSetup('SetupNewsChannelURL');
    $URL = str_replace("&","&amp;",$URL);
    if ( ereg ( '\?', $URL ) ) $URL = $URL.'&amp;';
      else $URL = $URL.'?';
    
    while ($Seitenzahl >= 1)
    { 
      $FormActionURL = $URL.'page='.$Seitenzahl;
      if ($aktuelleSeite == $Seitenzahl) { $temp = $temp.'<b>'.$Seitenzahl.'</b> '; }
      else { $temp = $temp.'<form style="display:inline" id="form'.$Seitenzahl.$Locator.'" method="post" action="'.$FormActionURL.'">
                              <p style="display:inline">
                                <input type="hidden" name="page" value="'.$Seitenzahl.'" />
                                <a href="'.$FormActionURL.'" onclick="javascript:document.forms[\'form'.$Seitenzahl.$Locator.'\'].submit()">'.$Seitenzahl.'</a>
                              </p>
                            </form>&nbsp;'; }
      $Seitenzahl--;
    }
    $temp = $temp.'</div>';
    $temp = ereg_replace("(\r\n|\n|\r)", "", $temp);
    $temp = str_replace("  ", "", $temp);
    return $temp;
  }
  
function editNews ($NewsID, $Title, $Text, $Publish)
{
  global $prefix;
  
  
  // HTML-Tags entfernen
    $Title = strip_tags($Title);
  $DateOfLastEdit = date("U");
  // Maskieren spezieller Zeichen für die Verwendung in einer SQL-Anweisung
    $Title = mysql_real_escape_string($Title);
    $Text = mysql_real_escape_string($Text);
  
  $sql = "UPDATE ".$prefix."news SET
        Title = '".$Title."',
        Text = '".$Text."',
        Publish = '".$Publish."',
        DateOfLastEdit = '".$DateOfLastEdit."',
        LastEditor = '".getCurrentUserVar('UserName')."'
        WHERE NewsID = '".$NewsID."'
        LIMIT 1";
      $resultat = mysql_query($sql);
      if ($resultat) { writeAllFeeds(); return true; }
      else {return false;}
}

function  changePublishing ( $Date )
{
  global $prefix;
  
  
  // aktuellen Status abfragen
  $sql = "SELECT Publish
    FROM ".$prefix."news
    WHERE Date='".$Date."'
    LIMIT 1";
  $result = mysql_query($sql);
  if ( mysql_num_rows($result)==1)
  {
    $temp=mysql_fetch_assoc($result);
    $aktuellerStatus = $temp['Publish'];
  }
  // neuen Status setzen
  if ( $aktuellerStatus=='0' ) $neuerStatus = '1';
  if ( $aktuellerStatus=='1' ) $neuerStatus = '0';
  $DateOfLastEdit = date("U");
  // Leere numerische Variablen als NULL definieren
    if ( $DateOfLastEdit=='' ) $DateOfLastEdit="NULL";
    if ( $Publish=='' ) $Publish="NULL";
  $sql = "UPDATE ".$prefix."news SET 
    Publish = ".$neuerStatus.",
    DateOfLastEdit = ".$DateOfLastEdit.",
    LastEditor = '".getCurrentUserVar('UserName')."'
    WHERE Date = '".$Date."' LIMIT 1";
  $resultat = mysql_query($sql);
  if ($resultat) { writeAllFeeds(); return true; }
    else {return false;}
}  
  
function addNews ($Title, $Text, $Publish)
  {
    global $prefix;
    
    
    // HTML-Tags entfernen
      $Title = strip_tags($Title);
    // Sonderzeichen umwandeln
      //$Title = htmlspecialchars($Title, ENT_QUOTES);
      //$Text = htmlspecialchars($Text, ENT_QUOTES);
    $Text = str_replace("&","&amp;",$Text);
    $Date = date("U");
    // Maskieren spezieller Zeichen für die Verwendung in einer SQL-Anweisung
      $Title = mysql_real_escape_string($Title);
      $Text = mysql_real_escape_string($Text);
    // Leere numerische Variablen als NULL definieren
      if ( $Date=='' ) $Date="NULL";
      if ( $Publish=='' ) $Publish="NULL";
    $sql = "INSERT INTO ".$prefix."news (Date, AddedFrom, Title, Text, DateOfLastEdit, Publish)      
      VALUES ($Date, '".getCurrentUserVar('UserName')."', '$Title', '$Text', '', $Publish)";
    $resultat = mysql_query($sql);
    if ($resultat) { writeAllFeeds(); return true; }
    else {return false;}
}  

function AnzahlAllerNewsInDatenbank ()
  {
    global $prefix;
    

    $sql = "SELECT count(*) as zahl FROM ".$prefix."news";
    $result = mysql_query($sql);
    $row = mysql_fetch_array($result);
    return $row['zahl'];
  }
?>
Return current item: GigKalender