Viewing file: module.php (10.72 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<? class Blog { var $UserMode = true; var $AdminMode = true; var $SearchMode = true; var $PanelMode = true; var $Table; var $Directory; var $CountOfNews; var $ClassName = 'Blog'; var $AdminAsynchMode = true; var $Photomanager; function Blog() { $this->Directory = dirname(__FILE__); $this->Table = new AMTable2('AMCMS_blog'); $this->Table->AddIndexField('news_id'); $this->Table->AddPositionField("news_position"); $this->Table->Module($this->ClassName); $this->CountOfNews = GetParam('NewsCount'); $params['main'] = "380x800"; $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 = ""; $search = false; // $year = GetCurrentYear(); if (isset($_GET['year']) && ($_GET['year'] >= 2000) && ($_GET['year'] <= 2050)) $year = $_GET['year']; if (isset($_GET['month']) && ($_GET['month'] >= 1) && ($_GET['month'] <= 12)) $month = $_GET['month']; if (isset($_GET['day']) && ($_GET['day'] >= 1) && ($_GET['day'] <= 31)) $day = $_GET['day']; if (!empty($year) and empty($month) and empty($day)) { $date1 = "{$year}-01-01"; $year2 = $year + 1; $date2 = "{$year2}-01-01"; $where = "(news_date >= '$date1') AND (news_date < '$date2')"; } if (!empty($year) and !empty($month) and empty($day)) { $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')"; } if (!empty($year) and !empty($month) and !empty($day)) { $date1 = "{$year}-{$month}-{$day} 00:00:00"; $date2 = "{$year}-{$month}-{$day} 23:59:59"; $where = "(news_date >= '$date1') AND (news_date <= '$date2')"; } if (empty($year) and empty($month) and empty($day)) { //$prewweek = date('Y-m-d', strtotime("-5 week")); //$now = date('Y-m-d'); //$where = "(news_date between '{$prewweek} 00:00:00' and '{$now} 23:59:59')"; $where = "true"; } // $rows = $this->Table->GetRows("news_date DESC", $where); if (isset($_GET['text'])) { $text = $_GET['text']; $where = "(news_title_{$ulang} LIKE '%$text%') OR (news_text_{$ulang} LIKE '%$text%')"; $search = true; } $count = mysql_fetch_assoc(mysql_query("SELECT COUNT(*) as count FROM AMCMS_blog WHERE $where ORDER BY news_date DESC")); $count = $count['count']; $page_navigator = new AMPageNavigator($count, $_GET['pageNum'], 10); $limit = $page_navigator->GetLimitStatement();
$sql = "SELECT * FROM AMCMS_blog WHERE $where ORDER BY news_date DESC $limit"; $res = mysql_query($sql); $rows = array(); while ($row = mysql_fetch_assoc($res)) { $rows[] = $row; } $smarty = GetUserSmarty($this->ClassName); $smarty->assign("pnav", $page_navigator->GetNavigator()); $smarty->assign('year', $year); $smarty->assign('month', $month); $smarty->assign('day', $day); $smarty->assign('rows', $rows); $smarty->assign('search', $search); //if (!$search) $smarty->assign('count', $count); $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, "/blog"); $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("comments", Comments::GetComments($this->ClassName, "news", $row['news_id'], $nav)); // $smarty->assign("count", Comments::GetCommentsCount($this->ClassName, "news", $row['news_id'])); $smarty->assign("navigator", $nav); $smarty->assign('row', $row); $smarty->assign('Photomanager', $this->Photomanager); $smarty->assign('mod', $this->ClassName); $result['Content'] = ReplaceImages($smarty->fetch("user-page.tpl")); $navigator = new AMNavigator(); $date = DateExplode($row['news_date']); $link = "/blog/"; $title = GetParam("Module{$this->ClassName}", $ulang);
$navigator->AddLink($title, $link); $navigator->AddLink($row['news_title_'.$ulang], "#"); // $photo = $this->Photomanager->GetMainPhoto($this->ClassName, "news_id={$row['news_id']}"); $result['GlobalParams']['MainImage'] = "/".$photo['photo_filename']; $result['GlobalParams']['Description'] = str_replace('\n',' ',strip_tags($row['news_short_text_'.$ulang])); $result['GlobalParams']['Navigator'] = $navigator->Fetch(); $result['GlobalParams']['PageTitle'] = $navigator->GetTitleForPage(); $result['Module'] = $this->ClassName; $result['Print'] = true; return $result; } } function Menu() { global $ALANG; return array( array('title' => "Додати запис", 'link' => '?mod='.$this->ClassName.'&add'), array('title' => "Список записів", 'link' => '?mod='.$this->ClassName.'&list'), ); } function Admin() { global $ALANG, $alang; $smarty = GetAdminSmarty($this->ClassName); if (isset($_GET['list'])) { $smarty = GetAdminSmarty($this->ClassName); $fields = array("news_date", "news_title_".GetParam("DefaultLanguage")); $captions = array("Дата публікаціїі", "Тема запису"); $conditions = array("true"); $order = "news_date DESC"; $links = array("checkbox", "delete", "edit", "setblog"); $multiple = array("delete"); $params = array("id" => "news"); $html = $this->Table->GetAdminTable($fields, $captions, $conditions, $order, $links, $multiple, $params); $result['Title'] = "Список записів"; $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'] = "Додавання запису"; $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"); 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'] = "Редагування запису"; $result['Content'] = $smarty->fetch('news.tpl'); return $result; } } function Panel() { global $ULANG, $ulang; $rows = $this->Table->GetRows("news_date DESC", "", "0,4"); $smarty = GetUserSmarty($this->ClassName); $smarty->assign('rows', $rows); $smarty->assign('Photomanager', $this->Photomanager); $smarty->assign('mod', $this->ClassName); $result['News'] = array( 'Title' => ($ulang == "ukr" ? "Останні новини" : "Latest News"), 'Content' => "<div class=\"News Panel\">".$smarty->fetch("user-panel.tpl")."</div>", 'Module' => $this->ClassName, 'Link' => array("Address" => "/blog", "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_blog'); $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'] = "/blog/{$value['news_id']}"; $row['Relev'] = $value['relev']; $row['NewWindowLink'] = $row['Link']; $searchRows [] = $row; } return $searchRows; } function AdminAsynch() { global $alang, $ALANG; if ($_POST['oper'] == 'setblog') { $id = $_POST['id']; SetParam("blog", $id); } $this->Table->Run($_POST); } } $Modules ["Blog"] = new Blog(); ?>
|