GetShopValues('', true); // Make path for back make_back_path(); // Define what to do $action = $_GET['action']; if ( isset($_POST['action']) ) $action = $_POST['action']; switch ( $action ) { case 'rss' : rss(); break; case 'subscribe' : subscribe(); break; case 'unsubscribe' : unsubscribe(); break; case 'view' : view_news(); break; default : news_tree(); } // switch // Echo page compilate time //echo_page_time($gEndPoint); } /** * Function rss * Return news in RSS format **/ function rss() { global $gData, $gOptions, $gTpl; // Start XML file $xml_file = './admin/tmp/'.md5(session_id()).'.xml'; $xml = new XML(SHOP_CHARSET, $xml_file, SHOP_CHARSET, false); $xml->StartTag('rss', array('version' => '2.0')); $xml->StartTag('channel'); // Personal info $url = rtrim($gOptions['attr_base_url'], '/'); $xml->PutTag('title', array(), $gOptions['attr_shop_name']); $xml->PutTag('link', array(), $gOptions['attr_shop_url']); $xml->PutTag('description', array(), $gOptions['attr_shop_descr']); $xml->PutTag('language', array(), 'ru'); $xml->PutTag('generator', array(), 'Melbis Shop v'.SCRIPT_VERSION); $xml->StartTag('image'); $xml->PutTag('url', array(), $url.$gOptions['attr_shop_logo']); $xml->PutTag('title', array(), $gOptions['attr_shop_name']); $xml->PutTag('link', array(), $gOptions['attr_shop_url']); $xml->CloseTag('image'); // Request topic & goods $rss = $gData->GetNewsRSS(); $rows = $gData->GetNumRows($rss); $sign = ( SHOP_GMT > 0 ) ? '+' : '-'; for ( $n = 1; $n <= $rows; $n++ ) { $hash = $gData->FetchRow($rss); $xml->StartTag('item'); $xml->PutTag('title', array(), $hash[2]); $xml->PutTag('link', array(), $url.'/news.php?action=view&cont_id='.$hash[1]); $content = ( strlen($hash[4]) > 0 ) ? $hash[4] : $hash[3]; $content = str_replace('src="', 'src="'.$url.'/', $content); $xml->PutTag('description', array(), $content); $xml->PutTag('author', array(), $gOptions['attr_shop_name']); $xml->PutTag('category', array(), $hash[0]); if ( strlen($hash[5]) > 0 ) { $path_info = pathinfo($hash[5]); $xml->PutTag('enclosure', array('url' => $url.'/files/news_attach'.$hash[1].'.'.$path_info['extension'], 'type' => $path_info['extension'])); } $xml->PutTag('guid', array(), $url.'/news.php?action=view&cont_id='.$hash[1]); $xml->PutTag('pubDate', array(), date("D, j M Y G:i:s ".$sign."0".SHOP_GMT."00", strtotime($hash[6]))); $xml->CloseTag('item'); } $xml->CloseTag('channel'); $xml->CloseTag('rss'); $xml->Free(); header( 'Content-type: text/xml; charset='.SHOP_CHARSET ); echo implode('',file($xml_file)); @unlink($xml_file); } /** * Function subscribe * Subscribe new user or modify exists **/ function subscribe() { global $gData, $gOptions, $gTpl, $gStartPoint, $gEndPoint; // Init templates $gTpl = new FastTemplate('./'.TEMPLATES.'/_news/tree/subscribe'); $gTpl->DefineTemplate(array('main' => 'main.htm', 'error' => 'error.htm', 'ok' => 'ok.htm' )); // Verify E-mail if ( eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@([0-9a-z](-?[0-9a-z])*\.)+[a-z]{2}([zmuvtg]|fo|me)?$", $_GET['email']) ) { $news = explode('I', rtrim($_GET['news'], 'I')); foreach ( $news as $id ) { if ( $id*1 > 0 ) $gData->NewSubscribe($id*1, addslashes($_GET['email']), addslashes($_GET['charset']), get_date() ); } $gTpl->Parse('CONTENT', 'ok'); } else { $gTpl->Parse('CONTENT', 'error'); } // Echo shop variables echo_shop_variables('in_techpage'); // Parse main page $gTpl->Parse('MAIN', 'main'); $gEndPoint = run_time($gStartPoint); $gTpl->FastPrint('MAIN'); } /** * Function unsubscribe * UnSubscribe user or modify news for send **/ function unsubscribe() { global $gData, $gOptions, $gTpl, $gStartPoint, $gEndPoint; // Init templates $gTpl = new FastTemplate('./'.TEMPLATES.'/_news/tree/unsubscribe'); $gTpl->DefineTemplate(array('main' => 'main.htm', 'error' => 'error.htm', 'ok' => 'ok.htm' )); // Verify E-mail if ( eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@([0-9a-z](-?[0-9a-z])*\.)+[a-z]{2}([zmuvtg]|fo|me)?$", $_GET['email']) ) { $news = explode('I', rtrim($_GET['news'], 'I')); $news_list = ''; foreach ( $news as $id ) { if ( $id*1 > 0 ) $news_list .= ($id*1).', '; } if ( $gData->UnSubscribe(addslashes($_GET['email']), rtrim($news_list, ', ')) ) { $gTpl->Parse('CONTENT', 'ok'); } else { $gTpl->Parse('CONTENT', 'error'); } } else { $gTpl->Parse('CONTENT', 'error'); } // Echo shop variables echo_shop_variables('in_techpage'); // Parse main page $gTpl->Parse('MAIN', 'main'); $gEndPoint = run_time($gStartPoint); $gTpl->FastPrint('MAIN'); } /** * Function news_tree * Print news tree with special function if need **/ function news_tree() { global $gData, $gOptions, $gTpl, $gStartPoint, $gEndPoint, $gCharset; // Init templates $gTpl = new FastTemplate('./'.TEMPLATES); $gTpl->DefineTemplate(array('blank' => 'blank.htm', 'main' => '_news/main.htm', 'page_title' => '_news/tree/page_title.htm' )); // Init vars $gTpl->Parse('PAGETITLE', 'page_title'); // Get news $news = $gData->GetNewsTree(); $rows = $gData->GetNumRows($news); // Parse news tree $tpl = new FastTemplate('./'.TEMPLATES.'/_news/tree'); $tpl->DefineTemplate(array('main' => 'main.htm', 'unit' => 'unit.htm', 'elem_file' => 'elem_file.htm', 'elem_folder' => 'elem_folder.htm', 'subscribe' => 'subscribe.htm', 'rss' => 'rss.htm' )); $code = ''; for ( $n = 1; $n <= $rows; $n++ ) { $hash = $gData->FetchRow($news); // common vars $tpl->Assign(array('ID' => $hash[0], 'NAME' => htmlspecialchars($hash[1]), 'DESCR' => $hash[6], 'LEVEL' => $hash[2] )); // if folder if ( $hash[5] == 1) { $tpl->Parse('ELEMENT', 'elem_folder'); } // if not folder else { $tpl->Assign(array('CHECK' => $checked, 'NEWSLINK' => '', 'SUBSCRIBE' => '', 'RSS' => '' )); if ( $hash[14] == 0 && $hash[11] == 0 ) $tpl->Assign('NEWSLINK', 'href=./news.php?action=view&news_id='.$hash[0]); if ( $hash[9] == 1 ) { $tpl->Parse('SUBSCRIBE', 'subscribe'); $code .= $hash[0].'I'; } if ( $hash[14] == 0 && $hash[10] == 1 ) $tpl->Parse('RSS', 'rss'); $tpl->Parse('ELEMENT', 'elem_file'); } $tpl->Parse('UNIT', '.unit'); } if ( $rows == 0) { $gTpl->Assign('CONTENT', ''); } else { $tpl->Assign('CODE', rtrim($code, 'I')); $charset = ''; foreach ( $gCharset as $set ) { $charset .= ''; } $tpl->Assign('CHARSETS', $charset); $tpl->Parse('MAIN', 'main'); $gTpl->Append('CONTENT', $tpl->Fetch('MAIN')); } $gTpl->Parse('CONTENT', 'main'); // Echo shop variables echo_shop_variables('in_techpage', true); // Additional modules use_php_mod('other'); // Parse main page $gTpl->Parse('BLANK', 'blank'); $gEndPoint = run_time($gStartPoint); $gTpl->FastPrint('BLANK'); } /** * Function view_news * View news list and content of selected news **/ function view_news() { global $gData, $gOptions, $gTpl, $gStartPoint, $gEndPoint; // Init templates $gTpl = new FastTemplate('./'.TEMPLATES); $gTpl->DefineTemplate(array('blank' => 'blank.htm', 'main' => '_news/main.htm' )); // Init vars $news_view = false; // View the news $news_content_id = $_GET['cont_id']*1; $hash = $gData->GetNewsContent($news_content_id); if ( $hash['id'] == $news_content_id && $news_content_id > 0 ) { // Init templates $tpl = new FastTemplate('./'.TEMPLATES.'/_news/view'); $tpl->DefineTemplate(array('main' => 'main.htm', 'attach' => 'attach.htm' )); $tpl->Assign(array('NAME' => htmlspecialchars($hash['name']), 'DATE' => date($gOptions['main_fmt_date'], strtotime($hash['date_time'])), 'TIME' => date($gOptions['main_fmt_time'], strtotime($hash['date_time'])), )); $tpl->Assign('CONTENT', ( strlen($hash['content']) > 0 ) ? $hash['content'] : $hash['descr']); if ( strlen($hash['attach']) > 0 ) { $path_info = pathinfo($hash['attach']); $tpl->Assign(array('FILENAME' => htmlspecialchars($hash['attach']), 'FILELINK' => './files/news_attach'.$hash['id'].'.'.$path_info['extension'], 'EXTENSION' => $path_info['extension'], )); $tpl->Parse('ATTACH', 'attach'); } else { $tpl->Assign('ATTACH', ''); } $tpl->Parse('MAIN', 'main'); $gTpl->Assign('PAGETITLE', $hash['name']); $gTpl->Assign('CONTENT', $tpl->Fetch('MAIN')); $news_view = true; } // Parse news block list $news_id = $_GET['news_id']*1; $news_id = ( $news_view ) ? $hash['news_id'] : $news_id; $hash = $gData->GetNews($news_id); $news_list = $gData->GetNewsList($news_id, 50); $news_list_rows = $gData->GetNumRows($news_list); if ( $news_list_rows > 0 ) { // Init templates $tpl = new FastTemplate('./'.TEMPLATES.'/_news/block_list'); $tpl->DefineTemplate(array('main' => 'main.htm', 'unit' => 'unit.htm', 'between_row' => 'between_row.htm', 'more' => 'more.htm' )); for ( $n = 1; $n <= $news_list_rows; $n++ ) { $hash_cont = $gData->FetchRow($news_list); if ( $n == $news_list_rows ) { $tpl->Assign('BETWEENROW', ''); } $tpl->Assign(array('NAME' => htmlspecialchars($hash_cont[1]), 'ID' => $hash_cont[0], 'DATE' => date($gOptions['main_fmt_date'], strtotime($hash_cont[2])), 'TIME' => date($gOptions['main_fmt_time'], strtotime($hash_cont[2])), 'DESCR' => $hash_cont[3] )); if ( strlen($hash_cont[4]) > 0 || strlen($hash_cont[5]) > 0 ) { $tpl->Parse('MORE', 'more'); } else { $tpl->Assign('MORE', ''); } // Parse unit $tpl->Parse('UNIT', '.unit'); } $tpl->Parse('BETWEENROW', 'between_row'); $tpl->Assign('NAME', htmlspecialchars($hash['name'])); $tpl->Parse('MAIN', 'main'); $gTpl->Append('CONTENT', $tpl->Fetch('MAIN')); if ( !$news_view ) $gTpl->Assign('PAGETITLE', $hash['name']); } // if not found news if ( !$news_view && $news_list_rows == 0) { $gTpl->Append('PAGETITLE', implode("", (file('./'.TEMPLATES.'/_news/view/empty.htm')))); $gTpl->Append('CONTENT', ''); } $gTpl->Parse('CONTENT', 'main'); // Echo shop variables echo_shop_variables('in_techpage', true); // Additional modules use_php_mod('other'); // Parse main page $gTpl->Parse('BLANK', 'blank'); $gEndPoint = run_time($gStartPoint); $gTpl->FastPrint('BLANK'); } ?>