Ignore:
Timestamp:
Jan 18, 2012, 7:44:38 AM (13 years ago)
Author:
chronos
Message:
  • Upraveno: Aktuality převedeny na systémový modul.
Location:
trunk/Modules/News
Files:
2 copied

Legend:

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

    r348 r350  
    11<?php
    2 
    3 include_once('../global.php');
    42
    53class NewsPage extends Page
     
    108
    119  function Show()
     10  {
     11    if(count($this->System->PathItems) > 1)
     12    {
     13      if($this->System->PathItems[1] == 'subscription') return($this->ShowSubscription());
     14        else if($this->System->PathItems[1] == 'rss') return($this->ShowRSS());
     15        else return(PAGE_NOT_FOUND);
     16    } else return($this->ShowMain());
     17  }
     18 
     19  function ShowMain()
    1220  {
    1321    $Output = '';
     
    3038        else
    3139        {
    32           $News = new News($this->Database);
     40          $News = new News($this->Database, $this->System);
    3341          if(array_key_exists('id', $_GET)) $Id = $_GET['id'] * 1;
    3442          $DbResult = $this->Database->query('SELECT `News`.*, `User`.`Name` FROM `News` LEFT JOIN `User` ON `User`.`Id`=`News`.`User` WHERE  `News`.`Id`='.$Id);
     
    4250            {
    4351              $Output .= '<div class="Action">';
    44               $Output .= '&nbsp;<a href="index.php?action=del&amp;category='.$Category.'&amp;id='.$Row['Id'].'">Smazat</a>';
    45               $Output .= '&nbsp;<a href="index.php?action=edit&amp;category='.$Category.'&amp;id='.$Row['Id'].'">Editovat</a>';
     52              $Output .= '&nbsp;<a href="?action=del&amp;category='.$Category.'&amp;id='.$Row['Id'].'">Smazat</a>';
     53              $Output .= '&nbsp;<a href="?action=edit&amp;category='.$Category.'&amp;id='.$Row['Id'].'">Editovat</a>';
    4654              $Output .= '</div>';
    4755            }
     
    112120          $this->Database->insert('News', array('Category' => $Category, 'Title' => $_POST['title'], 'Content' => $_POST['content'], 'Date' => 'NOW()', 'IP' => $RemoteAddr, 'Enclosure' => $Enclosures, 'Author' => $this->System->Models['User']->User['Name'], 'User' => $this->System->Models['User']->User['Id'], 'Link' => $_POST['link']));
    113121          $Output .= 'Aktualita přidána!<br />Pokud budete chtít vaši aktualitu smazat, klikněte na odkaz Smazat v seznamu všech aktualit v kategorii.<br /><br />';
    114           $Output .= '<a href="index.php?category='.$_POST['category'].'">Zpět na seznam aktualit</a>';
     122          $Output .= '<a href="?category='.$_POST['category'].'">Zpět na seznam aktualit</a>';
    115123          $this->System->Modules['Log']->NewRecord('News', 'Aktualita přidána', $this->Database->insert_id);
    116124        } else $Output .= 'Do této kategorie nemůžete vkládat aktuality!';
     
    123131          $Row['Content'] = str_replace('<br />', '', $Row['Content']);
    124132          $Output .= '<strong>Editace aktuality v kategorii '.$CategoryName.':</strong><br />';
    125           $Output .= '<form action="index.php?action=update" method="post">'.
     133          $Output .= '<form action="?action=update" method="post">'.
    126134          '<input type="hidden" value="'.$_GET['id'].'" name="id">'.
    127135          'Nadpis:<br /><input type="text" size="54" name="title" value="'.$Row['Title'].'"><br />'.
     
    164172          }
    165173          $this->Database->query('DELETE FROM News WHERE Id='.$_GET['id']);
    166           $Output .= 'Aktualita smazána!<br /><a href="index.php?category='.$Category.'">Zpět na seznam aktualit</a>';
     174          $Output .= 'Aktualita smazána!<br /><a href="?category='.$Category.'">Zpět na seznam aktualit</a>';
    167175        } else $Output .= 'Nemáte oprávnění.';
    168176        break;
     
    170178        if($this->System->Models['User']->CheckPermission('News', 'Display', 'Group', $Category))
    171179        {
    172           $News = new News($this->Database);
     180          $News = new News($this->Database, $this->System);
    173181          $PerPage = 20;
    174182          $DbResult = $this->Database->select('News', 'COUNT(*)', ' Category='.$Category);
     
    190198            {
    191199              $Output .= '<div class="Action">';
    192               $Output .= '&nbsp;<a href="index.php?action=del&amp;category='.$Category.'&amp;id='.$Row['Id'].'">Smazat</a>';
    193               $Output .= '&nbsp;<a href="index.php?action=edit&amp;category='.$Category.'&amp;id='.$Row['Id'].'">Editovat</a>';
     200              $Output .= '&nbsp;<a href="?action=del&amp;category='.$Category.'&amp;id='.$Row['Id'].'">Smazat</a>';
     201              $Output .= '&nbsp;<a href="?action=edit&amp;category='.$Category.'&amp;id='.$Row['Id'].'">Editovat</a>';
    194202              $Output .= '</div>';
    195203            }
     
    213221    return($Output);
    214222  }
     223 
     224  function ShowSubscription()
     225  {     
     226    if(array_key_exists('build', $_GET))
     227    {
     228      $Select = '';
     229      foreach($_POST as $Index => $Item)
     230      {
     231        if(substr($Index, 0, 8) == 'category') $Select .= '-'.substr($Index, 8);
     232      }
     233      $Select = $this->System->Config['Web']['RootFolder'].'/aktuality/rss/?select='.substr($Select, 1);
     234      $Output = 'Výsledný RSS kanál: <a href="'.$Select.'">'.$Select.'</a>';
     235    } else
     236    {
     237      $Output = 'Vytvořte si vlastní RSS kanál, díky kterému budete moci automaticky sledovat novinky pomocí vaší RSS čtečky. Informace o technologii RSS a programech pro čtení kanálů najdete např. <a href="http://www.lupa.cz/clanky/prehled-rss-ctecek/">zde</a><br />'.
     238      '<br />Kategorie:<br />';
     239      $Output .= '<form action="?build=1" method="post">';
     240      $DbResult = $this->Database->select('NewsCategory', '*', '1 ORDER BY Caption');
     241      while($Category = $DbResult->fetch_array())
     242      {
     243        $Output .= '<input type="checkbox" name="category'.$Category['Id'].'" />'.$Category['Caption'].'<br />';
     244      }
     245      $Output.= '<input type="submit" value="Sestavit " />'.
     246        '</form>';
     247    } 
     248    return($Output);
     249  }
     250 
     251  function ShowRSS()
     252  {
     253    $this->SimplePage = true;
     254    $this->FormatHTML = false;
     255    Header('Content-Type: text/xml');
     256
     257include_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
     268if(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', '*');
     282while($Category = $DbResult->fetch_array())
     283{
     284  $Categories[$Category['Id']] = $Category['Caption'];
    215285}
    216286
    217 $System->AddModule(new NewsPage());
    218 $System->Modules['NewsPage']->GetOutput();
     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().',');
     294while($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);
     320while($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
     342return(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}
    219352
    220353?>
Note: See TracChangeset for help on using the changeset viewer.