$Item2['Index'] ? -1 : 1; } class ModuleNews extends Module { public int $NewsCountPerCategory = 3; public string $UploadedFilesFolder = 'files/news/'; public array $NewsSetting; function __construct(System $System) { parent::__construct($System); $this->Name = 'News'; $this->Version = '1.0'; $this->Creator = 'Chronos'; $this->License = 'GNU/GPLv3'; $this->Description = 'News and news groups management'; $this->Dependencies = array(ModuleUser::GetName(), ModuleLog::GetName(), ModuleFile::GetName()); $this->Models = array(NewsCategory::GetClassName(), News::GetClassName()); } function DoStart(): void { $this->System->RegisterPage(['aktuality'], 'PageNews'); $this->System->RegisterPage(['aktuality', 'subscription'], 'PageNewsSubscription'); $this->System->RegisterPage(['aktuality', 'rss'], 'PageNewsRss'); $this->System->RegisterPage(['aktuality', 'aktualizace'], 'PageNewsUpdate'); Core::Cast($this->System)->FormManager->RegisterClass('News', array( 'Title' => 'Aktualita', 'Table' => 'News', 'DefaultSortColumn' => 'Date', 'DefaultSortOrder' => 1, 'Items' => array( 'Category' => array('Type' => 'TNewsCategory', 'Caption' => 'Kategorie', 'Default' => 0), 'Title' => array('Type' => 'String', 'Caption' => 'Nadpis', 'Default' => ''), 'Content' => array('Type' => 'Text', 'Caption' => 'Obsah', 'Default' => ''), 'Date' => array('Type' => 'Date', 'Caption' => 'Datum', 'Default' => ''), 'Author' => array('Type' => 'String', 'Caption' => 'Autor', 'Default' => ''), 'Enclosure' => array('Type' => 'String', 'Caption' => 'Přílohy', 'Default' => ''), 'User' => array('Type' => 'TUser', 'Caption' => 'Uživatel', 'Default' => ''), 'IP' => array('Type' => 'IPv4Address', 'Caption' => 'IP adresa', 'Default' => '', 'ReadOnly' => true), 'Link' => array('Type' => 'Hyperlink', 'Caption' => 'Odkaz', 'Default' => ''), ), )); Core::Cast($this->System)->FormManager->RegisterClass('NewsCategory', array( 'Title' => 'Kategorie aktualit', 'Table' => 'NewsCategory', 'Items' => array( 'Caption' => array('Type' => 'String', 'Caption' => 'Titulek', 'Default' => ''), 'RSS' => array('Type' => 'Hyperlink', 'Caption' => 'Zdroj RSS', 'Default' => ''), 'Permission' => array('Type' => 'Boolean', 'Caption' => 'Veřejné upravitelné', 'Default' => ''), 'Sequence' => array('Type' => 'Integer', 'Caption' => 'Pořadí', 'Default' => ''), 'Group' => array('Type' => 'Integer', 'Caption' => 'Skupina', 'Default' => ''), 'News' => array('Type' => 'TNewsList', 'Caption' => 'Aktuality', 'Default' => ''), ), )); Core::Cast($this->System)->FormManager->RegisterFormType('TNewsCategory', array( 'Type' => 'Reference', 'Table' => 'NewsCategory', 'Id' => 'Id', 'Name' => 'Caption', 'Filter' => '1', )); Core::Cast($this->System)->FormManager->RegisterFormType('TNewsList', array( 'Type' => 'ManyToOne', 'Table' => 'News', 'Id' => 'Id', 'Ref' => 'Category', 'Filter' => '1', )); if ($this->System->ModuleManager->ModulePresent('Search')) { ModuleSearch::Cast($this->System->GetModule('Search'))->RegisterSearch('Novinky', 'News', array('Title', 'Content')); } } function GetIntranetCondition(): string { if (IsInternetAddr()) return ' AND (`Intranet`=0)'; else return ''; } function ShowNews(string $Category, int $ItemCount, int $DaysAgo): string { $ItemCount = abs($ItemCount); $DaysAgo = abs($DaysAgo); $DbResult = $this->Database->select('NewsCategory', '*', 'Id='.$Category); $Row = $DbResult->fetch_array(); $Output = '
'.
'
'.$this->ModifyContent($Row['Content']);
if ($Row['Link'] != '') $Output .= ' Odkaz'; if ($Row['Enclosure'] != '') { $Output .= ' Přílohy: '; $Enclosures = explode(';', $Row['Enclosure']); foreach ($Enclosures as $Enclosure) { if (file_exists($this->UploadedFilesFolder.$Enclosure)) $Output .= ' '.$Enclosure.''; } } $Output .= ' |
'; foreach ($this->NewsSetting as $SettingItem) if (($SettingItem['Enabled'] == 1) and ($SettingItem['Group'] == $Column)) $Output .= $this->ShowNews($SettingItem['CategoryId'], $SettingItem['ItemCount'], $SettingItem['DaysAgo']); $Output .= ' | '; } $Output .= '