Viewing file: module.php (11.68 KB) -rwxrwxrwx Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<? function rss($str) { return htmlspecialchars(html_entity_decode($str, ENT_QUOTES, 'UTF-8')); } class News { var $UserMode = true; var $UserAsynchMode = true; var $AdminMode = true; var $SearchMode = true; var $PanelMode = true; var $Table; var $Directory; var $CountOfNews; var $ClassName = 'News'; var $AdminAsynchMode = true; var $Photomanager; function News() { $this->Directory = dirname(__FILE__); $this->Table = new AMTable2('AMCMS_news'); $this->Table->AddIndexField('news_id'); $this->Table->AddPositionField("news_position"); $this->Table->Module($this->ClassName); $this->CountOfNews = GetParam('NewsCount'); $params['main'] = GetParam("NewsMainPhotoSize"); $params['text']['small'] = GetParam("NewsSmallPhotoSize"); $params['text']['big'] = GetParam("NewsBigPhotoSize"); $this->Photomanager = new AMPhotomanager($params); } function User() { global $ULANG, $ulang; if (isset($_GET['news'])) { $where = ""; $html = ""; if (GetParam("NewsDisplayYearNavigator") == "Y") { $year = GetCurrentYear(); if (isset($_GET['year']) && ($_GET['year'] >= 2000) && ($_GET['year'] <= 2050)) $year = $_GET['year']; $date1 = "{$year}-01-01"; $year2 = $year + 1; $date2 = "{$year2}-01-01"; $where = "(news_date >= '$date1') AND (news_date < '$date2')"; $html = "<table align=\"center\" class=\"year-selector\"><tr>"; if (GetParam("NewsDisplayMonthNavigator") == "Y") { $month = GetCurrentMonth(); if (isset($_GET['month']) && ($_GET['month'] >= 1) && ($_GET['month'] <= 12)) $month = $_GET['month']; } for($i = GetParam("StartYear"); $i <= GetCurrentYear(); $i++) { $sel = ""; if ($i == $year) $sel = "class=\"selected\""; $link = "/news/$i/$month"; $html .= "<td {$sel}><a href=\"$link\">{$i}</a></td>"; } $html .= "</tr></table>"; } if (GetParam("NewsDisplayMonthNavigator") == "Y") { $month = GetCurrentMonth(); if (isset($_GET['month']) && ($_GET['month'] >= 1) && ($_GET['month'] <= 12)) $month = $_GET['month']; $date1 = "{$year}-{$month}-01"; $month2 = $month + 1; $year2 = $year; if ($month2 > 12) { $month2 = 1; $year2++; } $date2 = "{$year2}-{$month2}-01"; $where = "(news_date >= '$date1') AND (news_date < '$date2')"; $html .= "<table align=\"center\" class=\"month-selector\"><tr>"; for($i = 1; $i <= 12; $i++) { if ($i == 7) $html .= "</tr><tr>"; $sel = ""; if ($i == $month) $sel = "class=\"selected\""; $link = "/news/$year/$i"; $html .= "<td {$sel}><a href=\"$link\">".$ULANG['CoreMonth'.$i]."</a></td>"; } $html .= "</tr></table>"; } $rows = $this->Table->GetRows("news_date DESC", $where); $smarty = GetUserSmarty($this->ClassName); $smarty->assign('rows', $rows); $smarty->assign('Photomanager', $this->Photomanager); $smarty->assign('mod', $this->ClassName); $title = GetParam("Module{$this->ClassName}", $ulang); $result['Title'] = $title; $result['Content'] = $html.$smarty->fetch("user-row.tpl"); $navigator = new AMNavigator(); $navigator->AddLink($title, "/news"); $result['GlobalParams']['Navigator'] = $navigator->Fetch(); $result['GlobalParams']['PageTitle'] = $navigator->GetTitleForPage(); $result['Module'] = $this->ClassName; $result['Print'] = true; return $result; } if (isset($_GET['news_id'])) { $row = $this->Table->GetRowById($_GET['news_id']); if ($row == null) return; $result['Title'] = $row['news_title_'.$ulang]; $smarty = GetUserSmarty($this->ClassName); $smarty->assign('row', $row); $smarty->assign('Photomanager', $this->Photomanager); $smarty->assign('mod', $this->ClassName); $result['Content'] = $smarty->fetch("user-page.tpl"); $navigator = new AMNavigator(); $date = DateExplode($row['news_date']); $link = "/news/{$date[0]}/{$date[1]}"; $title = GetParam("Module{$this->ClassName}", $ulang); $navigator->AddLink($title, $link); $navigator->AddLink($row['news_title_'.$ulang], "#"); $result['GlobalParams']['Navigator'] = $navigator->Fetch(); $result['GlobalParams']['PageTitle'] = $navigator->GetTitleForPage(); $result['GlobalParams']['Title'] = $navigator->GetTitle(); $img = $this->Photomanager->GetMainPhoto('News', "news_id={$row['news_id']}"); $result['GlobalParams']['MetaImage'] = $img['photo_filename_big']; $result['Module'] = $this->ClassName; $result['Print'] = true; return $result; } } function Menu() { global $ALANG; return array( array('title' => $ALANG['NewsMenuAdd'], 'link' => '?mod='.$this->ClassName.'&add'), array('title' => $ALANG['NewsMenuList'], 'link' => '?mod='.$this->ClassName.'&list'), ); } function Admin() { global $ALANG, $alang; $smarty = GetAdminSmarty($this->ClassName); if (isset($_GET['list'])) { $smarty = GetAdminSmarty($this->ClassName); $year = GetCurrentYear(); $month = (int)GetCurrentMonth(); if (isset($_GET['month'])) $month = $_GET['month']; if (isset($_GET['year'])) $year = $_GET['year']; if (isset($_POST['month'])) $month = $_POST['month']; if (isset($_POST['year'])) $year = $_POST['year']; if (isset($_POST['news_date_month'])) $month = $_POST['news_date_month']; if (isset($_POST['news_date_year'])) $year = $_POST['news_date_year']; $smarty->assign("year", $year); $smarty->assign("month", $month); $selectorHtml = $smarty->fetch("month.tpl"); $date1 = "{$year}-{$month}-01"; $month2 = $month + 1; $year2 = $year; if ($month2 > 12) { $month2 = 1; $year2++; } $date2 = "{$year2}-{$month2}-01"; $fields = array("news_date", "news_title_".GetParam("DefaultLanguage")); $captions = array($ALANG['News_news_date'], $ALANG['News_news_title']); $conditions = array("(news_date >= '{$date1}')", "(news_date < '{$date2}')"); $order = "news_date DESC"; $links = array("checkbox", "delete", "edit"); $multiple = array("delete"); $params = array("id" => "news"); $html = $this->Table->GetAdminTable($fields, $captions, $conditions, $order, $links, $multiple, $params); $result['Title'] = $ALANG['NewsList']; $result['Content'] = $selectorHtml.$html; return $result; } if (isset($_GET['add'])) { if (isset($_POST['add'])) { $_POST['news_date_of_creation'] = GetCurrentDateAndTime(); $_POST['news_date_of_edition'] = GetCurrentDateAndTime(); $_POST['news_date'] = DateConvert($_POST['news_date_year'], $_POST['news_date_month'], $_POST['news_date_day'], $_POST['news_date_hours'], $_POST['news_date_minutes']); $id = $this->Table->Insert($_POST); $this->Photomanager->Run($_POST, $_FILES, $this->ClassName, ($this->Table->IndexField."=".$id)); header("Location: ?mod=".$this->ClassName."&list&month=".$_POST['news_date_month']."&year=".$_POST['news_date_year']); die; } foreach($_POST as $key => $value) $smarty->assign($key, $value); $smarty->assign('oper', 'add'); $smarty->assign('news_date', GetCurrentDateAndTime()); $smarty->assign('news_show_title', 'Y'); $smarty->assign('news_show_read_more_link', 'Y'); $smarty->assign('news_show_date', 'Y');
$photo_admin_table1 = $this->Photomanager->GetAdminTable( $this->ClassName, ($this->Table->IndexField."=".$id),'main'); $photo_admin_table2 = $this->Photomanager->GetAdminTable( $this->ClassName, ($this->Table->IndexField."=".$id),'photos'); $smarty->assign('photo_admin_table1', $photo_admin_table1); $smarty->assign('photo_admin_table2', $photo_admin_table2); $result['Title'] = $ALANG['NewsAdd']; $result['Content'] = $smarty->fetch('news.tpl'); return $result; } if (isset($_GET['edit']) && isset($_GET['news_id'])) { if (isset($_POST['edit'])) { $_POST['news_date_of_edition'] = GetCurrentDateAndTime(); $_POST['news_date'] = DateConvert($_POST['news_date_year'], $_POST['news_date_month'], $_POST['news_date_day'], $_POST['news_date_hours'], $_POST['news_date_minutes']); $id = $_GET['news_id']; $error = $this->Table->Update($_POST, $id); $this->Photomanager->Run($_POST, $_FILES, $this->ClassName, ($this->Table->IndexField."=".$id)); $index = 1; header("Location: ?mod=".$this->ClassName."&list&month=".$_POST['news_date_month']."&year=".$_POST['news_date_year']); die; } $id = $_GET['news_id']; $row = $this->Table->GetRowById($id); foreach($row as $key => $value) $smarty->assign($key, $value); $smarty->assign($key, $value); $smarty->assign('oper', 'edit'); $photo_admin_table1 = $this->Photomanager->GetAdminTable( $this->ClassName, ($this->Table->IndexField."=".$id),'main'); $photo_admin_table2 = $this->Photomanager->GetAdminTable( $this->ClassName, ($this->Table->IndexField."=".$id),'photos'); $smarty->assign('photo_admin_table1', $photo_admin_table1); $smarty->assign('photo_admin_table2', $photo_admin_table2); $result['Title'] = $ALANG['NewsEdit']; $result['Content'] = $smarty->fetch('news.tpl'); return $result; } } function Panel() { global $ULANG, $ulang; $rows = $this->Table->GetRows("news_date DESC", "", "0,{$this->CountOfNews}"); $smarty = GetUserSmarty($this->ClassName); $smarty->assign('rows', $rows); $smarty->assign('Photomanager', $this->Photomanager); $smarty->assign('mod', $this->ClassName); $result['News'] = array( 'Title' => GetParam("Module{$this->ClassName}Panel", $ulang), 'Content' => $smarty->fetch("user-row.tpl"), 'Module' => $this->ClassName, 'Link' => array("Address" => "/news", "Title" => $ULANG['NewsArchiveLinkTitle'], "Class" => "archive")); return $result; } function Search($words) { global $ulang, $ULANG; $fields = array("news_title_".$ulang, "news_short_text_".$ulang, "news_description_".$ulang, "news_text_".$ulang, "news_keywords_".$ulang); $rows = SearchOnSite($words, array('news_title_'.$ulang, "news_date_of_creation"), 'news_id', $fields, 'AMCMS_news'); $searchRows = array(); if ($rows) foreach($rows as $key => $value) { $row['Module'] = $this->ClassName; $row['Date'] = $value['news_date_of_creation']; $row['Title'] = $value['news_title_'.$ulang]; $row['Link'] = "/news/{$value['news_id']}"; $row['Relev'] = $value['relev']; $row['NewWindowLink'] = $link; $searchRows [] = $row; } return $searchRows; } function AdminAsynch() { global $alang, $ALANG; $this->Table->Run($_POST); } function UserAsynch() { if (isset($_GET['rss'])) { $sql = "SELECT * FROM AMCMS_news ORDER BY news_date DESC LIMIT 0, 12"; $res = mysql_query($sql); $rows = array(); while($row = mysql_fetch_assoc($res)) { if ($row['news_id'] > 235) $images = $this->Photomanager->GetPhotos($this->ClassName, "news_id={$row['news_id']}"); else $images = array(); $rows [] = array('title' => ( rss(strip_tags($row['news_title_ukr']),ENT_QUOTES)), 'link' => 'http://zt-rada.gov.ua/news/p'.$row['news_id'], 'images' => $images, 'description' => ( rss(strip_tags($row['news_short_text_ukr']))), 'date' => date("r", rss(strtotime($row['news_date']),ENT_QUOTES)), 'fulltext' => ( rss(strip_tags($row['news_text_ukr']),ENT_QUOTES))); } $smarty = GetUserSmarty($this->ClassName); $smarty->assign('rows', $rows); header("Content-Type: application/rss+xml"); echo $smarty->fetch('rss.xml'); die; }
} } $Modules ["News"] = new News(); ?>
|