Ignore:
Timestamp:
Jan 18, 2012, 8:48:26 AM (13 years ago)
Author:
chronos
Message:
  • Upraveno: Soubor pro zobrazení výpisu záznamu operací uživatelů přidružen k modulu Log.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/News/NewsPage.php

    r350 r353  
    11<?php
     2
     3include_once('Common/rss_generator.php');
    24
    35class NewsPage extends Page
     
    255257    Header('Content-Type: text/xml');
    256258
    257 include_once('rss_generator.php');
    258 
    259 $NewsCount = 15;
    260 
    261 $Items = array();
    262 $Category = '';
    263 $CategoryOption = '';
    264 $CategoryOptionURL = '';
    265 $CategoryName = '';
    266 
    267 // Prepare WHERE condition
    268 if(array_key_exists('select', $_GET))
    269 {
    270   $Where = '';
    271   $Parts = explode('-', $_GET['select']);
    272   foreach($Parts as $Part)
    273   {
    274     $Where .= 'OR (category='.($Part * 1).')';
    275   }
    276   $Where = substr($Where, 2);
    277 } else $Where = 1;
    278 
    279 // Get category names
    280 $Categories = array();
    281 $DbResult = $Database->select('NewsCategory', '*');
    282 while($Category = $DbResult->fetch_array())
    283 {
    284   $Categories[$Category['Id']] = $Category['Caption'];
     259    $NewsCount = 15;
     260
     261    $Items = array();
     262    $Category = '';
     263    $CategoryOption = '';
     264    $CategoryOptionURL = '';
     265    $CategoryName = '';
     266
     267    // Prepare WHERE condition
     268    if(array_key_exists('select', $_GET))
     269    {
     270      $Where = '';
     271      $Parts = explode('-', $_GET['select']);
     272      foreach($Parts as $Part)
     273      {
     274        $Where .= 'OR (category='.($Part * 1).')';
     275      }
     276      $Where = substr($Where, 2);
     277    } else $Where = 1;
     278
     279    // Get category names
     280    $Categories = array();
     281    $DbResult = $this->Database->select('NewsCategory', '*');
     282    while($Category = $DbResult->fetch_array())
     283    {
     284      $Categories[$Category['Id']] = $Category['Caption'];
     285    }
     286
     287    // Update news from discussion forum
     288    /*
     289    $ForumCategory = 4;   
     290    $Database->select_db('forum');
     291    $DbResult = $Database->query('SELECT posts.post_time, posts_text.post_subject, posts_text.post_text, users.username, topics.topic_title FROM posts JOIN posts_text ON posts.post_id = posts_text.post_id JOIN users ON users.user_id = posts.poster_id JOIN topics ON topics.topic_id= posts.topic_id ORDER BY post_time DESC LIMIT '.$NewsCount);
     292    $Index = 0;
     293    //echo(DB_NumRows().',');
     294    while($Row = $DbResult->fetch_array())
     295    {
     296      $Row['post_text'] = StrTr($Row['post_text'], "\x8A\x8D\x8E\x9A\x9D\x9E", "\xA9\xAB\xAE\xB9\xBB\xBE");
     297      $Row['post_text'] = str_replace("\n","<br>", $Row['post_text']);
     298      $Row['post_subject'] = StrTr($Row['post_subject'], "\x8A\x8D\x8E\x9A\x9D\x9E", "\xA9\xAB\xAE\xB9\xBB\xBE");
     299      $Row['topic_title'] = StrTr($Row['topic_title'], "\x8A\x8D\x8E\x9A\x9D\x9E", "\xA9\xAB\xAE\xB9\xBB\xBE");
     300      $Index = $Index + 1;   
     301     
     302      $Title = $Row['topic_title'].'-'.$Row['post_subject'];
     303      $Content = $Row['post_text'];
     304      $Date = date('Y-m-d H:i:s', $Row['post_time']);
     305      $Author = $Row['username'];
     306      $Database->select_db('is');
     307      //echo('category='.$ForumCategory.' AND title="'.addslashes($Title).'" AND content="'.addslashes($Content).'" AND author="'.addslashes($Author).'" AND date="'.$Date.'"');
     308      $DbResult2 = $Database->select('news', '*', 'category='.$ForumCategory.' AND title="'.addslashes($Title).'" AND content="'.addslashes($Content).'" AND author="'.addslashes($Author).'" AND date="'.$Date.'"');
     309      if($DbResult2->num_rows == 0) //echo('.'); else echo('x');
     310        $Database->insert('news', array('category' => $ForumCategory, 'title' => $Title, 'content' => $Content, 'author' => $Author, 'date' => $Date));
     311        //echo($Date); 
     312      $Database->select_db('forum');
     313    }
     314    $Database->select_db('is');
     315    */
     316
     317    // Get news from database by selected categories
     318    $UploadedFilesFolder = 'uploads/';
     319    $DbResult = $this->Database->query('SELECT *, UNIX_TIMESTAMP(Date) FROM News LEFT JOIN `User` ON `User`.`Id`=`News`.`User` WHERE '.$Where.' ORDER BY News.Date DESC LIMIT 0,'.$NewsCount);
     320    while($Row = $DbResult->fetch_assoc())
     321    {
     322      $EnclosuresText = '';
     323      if($Row['Enclosure'] != '')
     324      {
     325        $EnclosuresText .= '<br />Přílohy: ';
     326        $Enclosures = explode(';', $Row['Enclosure']);
     327        foreach($Enclosures as $Enclosure)
     328        {
     329          if(file_exists($UploadedFilesFolder.$Enclosure)) $EnclosuresText .= ' <a href="http://centrala.zdechov.net/aktuality/'.$UploadedFilesFolder.$Enclosure.'">'.$Enclosure.'</a>';
     330        }
     331      }
     332      if($Row['Name'] == '') $Author = $Row['Author'];
     333        else $Author = $Row['Name'];
     334      $Items[] = array(
     335        'Title' => $Categories[$Row['Category']].' - '.$Row['Title'],
     336        'Link' => 'http://'.$this->System->Config['Web']['Host'].'/aktuality/index.php?category='.$Row['Category'],
     337        'Description' => $Row['Content'].' ('.$Author.')'.$EnclosuresText,
     338        'Time' => $Row['UNIX_TIMESTAMP(Date)'],
     339      );
     340    }
     341
     342    return(GenerateRSS(array(
     343      'Title' => $this->System->Config['Web']['Title'].' - Aktuality',
     344      'Link' => 'http://'.$this->System->Config['Web']['Host'].'/',
     345      'Description' => 'Aktuality komunitní počítačové sítě ZděchovNET',
     346      'WebmasterEmail' => $this->System->Config['Web']['AdminEmail'],
     347      'Items' => $Items)));     
     348  } 
    285349}
    286350
    287 // Update news from discussion forum
    288 /*
    289 $ForumCategory = 4;   
    290 $Database->select_db('forum');
    291 $DbResult = $Database->query('SELECT posts.post_time, posts_text.post_subject, posts_text.post_text, users.username, topics.topic_title FROM posts JOIN posts_text ON posts.post_id = posts_text.post_id JOIN users ON users.user_id = posts.poster_id JOIN topics ON topics.topic_id= posts.topic_id ORDER BY post_time DESC LIMIT '.$NewsCount);
    292 $Index = 0;
    293 //echo(DB_NumRows().',');
    294 while($Row = $DbResult->fetch_array())
    295 {
    296   $Row['post_text'] = StrTr($Row['post_text'], "\x8A\x8D\x8E\x9A\x9D\x9E", "\xA9\xAB\xAE\xB9\xBB\xBE");
    297   $Row['post_text'] = str_replace("\n","<br>", $Row['post_text']);
    298   $Row['post_subject'] = StrTr($Row['post_subject'], "\x8A\x8D\x8E\x9A\x9D\x9E", "\xA9\xAB\xAE\xB9\xBB\xBE");
    299   $Row['topic_title'] = StrTr($Row['topic_title'], "\x8A\x8D\x8E\x9A\x9D\x9E", "\xA9\xAB\xAE\xB9\xBB\xBE");
    300   $Index = $Index + 1;   
    301  
    302   $Title = $Row['topic_title'].'-'.$Row['post_subject'];
    303   $Content = $Row['post_text'];
    304   $Date = date('Y-m-d H:i:s', $Row['post_time']);
    305   $Author = $Row['username'];
    306   $Database->select_db('is');
    307   //echo('category='.$ForumCategory.' AND title="'.addslashes($Title).'" AND content="'.addslashes($Content).'" AND author="'.addslashes($Author).'" AND date="'.$Date.'"');
    308   $DbResult2 = $Database->select('news', '*', 'category='.$ForumCategory.' AND title="'.addslashes($Title).'" AND content="'.addslashes($Content).'" AND author="'.addslashes($Author).'" AND date="'.$Date.'"');
    309   if($DbResult2->num_rows == 0) //echo('.'); else echo('x');
    310     $Database->insert('news', array('category' => $ForumCategory, 'title' => $Title, 'content' => $Content, 'author' => $Author, 'date' => $Date));
    311     //echo($Date); 
    312   $Database->select_db('forum');
    313 }
    314 $Database->select_db('is');
    315 */
    316 
    317 // Get news from database by selected categories
    318 $UploadedFilesFolder = 'uploads/';
    319 $DbResult = $Database->query('SELECT *, UNIX_TIMESTAMP(Date) FROM News LEFT JOIN `User` ON `User`.`Id`=`News`.`User` WHERE '.$Where.' ORDER BY News.Date DESC LIMIT 0,'.$NewsCount);
    320 while($Row = $DbResult->fetch_assoc())
    321 {
    322   $EnclosuresText = '';
    323   if($Row['Enclosure'] != '')
    324   {
    325     $EnclosuresText .= '<br />Přílohy: ';
    326     $Enclosures = explode(';', $Row['Enclosure']);
    327     foreach($Enclosures as $Enclosure)
    328     {
    329       if(file_exists($UploadedFilesFolder.$Enclosure)) $EnclosuresText .= ' <a href="http://centrala.zdechov.net/aktuality/'.$UploadedFilesFolder.$Enclosure.'">'.$Enclosure.'</a>';
    330     }
    331   }
    332   if($Row['Name'] == '') $Author = $Row['Author'];
    333     else $Author = $Row['Name'];
    334   $Items[] = array(
    335     'Title' => $Categories[$Row['Category']].' - '.$Row['Title'],
    336     'Link' => 'http://centrala.zdechov.net/aktuality/index.php?category='.$Row['Category'],
    337     'Description' => $Row['Content'].' ('.$Author.')'.$EnclosuresText,
    338     'Time' => $Row['UNIX_TIMESTAMP(Date)'],
    339   );
    340 }
    341 
    342 return(GenerateRSS(array(
    343   'Title' => $Config['Web']['Title'].' - Aktuality',
    344   'Link' => 'http://'.$Config['Web']['Host'].'/',
    345   'Description' => 'Aktuality komunitní počítačové sítě ZděchovNET',
    346   'WebmasterEmail' => $Config['Web']['AdminEmail'],
    347   'Items' => $Items)));
    348      
    349   }
    350  
    351 }
    352 
    353351?>
Note: See TracChangeset for help on using the changeset viewer.