Статьи на тему рулевых реек
<?php
/*####
#
# Name: news (snippet) for Rnews Module
# Version: 0.1
# Author: RioGod & ma1oy
# E-mail: riogod@gmail.com & kol_vladimir@mail.ru
# Date: 2007 - 2009
#
####*/
$nidid = $_GET[nid];
define(rnews_PATH, "assets/snippets/rmod_news/");
$output = "";
include($modx->config['base_path'].rnews_PATH.'rnewsconf.php');
$rn_config['show_cats'] = (isset($show_cats)) ? $show_cats : ""; // [ category_ids "1,2,3,4" or "1")
$rn_config['list_limit'] = (isset($list_limit)) ? $list_limit : ""; // [ number | empty ]
$rn_config['allow_pages'] = (isset($allow_pages)) ? $allow_pages : "0"; // [ 1 | 0 ]
$rn_config['CategoryTpl'] = (isset($CategoryTpl)) ? $CategoryTpl : '@FILE:'.rnews_PATH.'templates/rnews_category.html'; // [ path | chunkname | text ]
$rn_config['NewsTpl'] = (isset($NewsTpl)) ? $NewsTpl : '@FILE:'.rnews_PATH.'templates/rnews_news.html'; // [ path | chunkname | text ]
$rn_config['NewsListTpl'] = (isset($NewsListTpl)) ? $NewsListTpl : '@FILE:'.rnews_PATH.'templates/rnews_list.html'; // [ path | chunkname | text ]
if (!class_exists('mgChunkie')) {
$chunkieclass = $modx->config['base_path'].rnews_PATH.'chunkie/chunkie.class.inc.php';
if (file_exists($chunkieclass))
{
include_once $chunkieclass;
}
else
{
$output = 'Cannot find chunkie class file! ('.$chunkieclass.')';
return;
}
}
if(!isset($nidid))
{
//echo "получили nid";
if(isset($rn_config['show_cats']) && $rn_config['show_cats'] != 'list_all')
{
$sortpar = "AND (".$modx->getFullTableName(rmod_news).".catid IN (".$rn_config['show_cats']."))";
}
$sql = "SELECT
".$modx->getFullTableName(rmod_news).".id,
".$modx->getFullTableName(rmod_news).".title,
".$modx->getFullTableName(rmod_news).".show_preview,
".$modx->getFullTableName(rmod_news).".news_body,
".$modx->getFullTableName(rmod_news).".news_date,
".$modx->getFullTableName(rmod_news).".autor,
".$modx->getFullTableName(rmod_news).".full_link,
".$modx->getFullTableName(rmod_news).".publish,
".$modx->getFullTableName(rmod_news).".catid,
".$modx->getFullTableName(rmod_newscat).".cat_name
FROM
".$modx->getFullTableName(rmod_newscat).",
".$modx->getFullTableName(rmod_news)."
WHERE
(".$modx->getFullTableName(rmod_news).".catid = ".$modx->getFullTableName(rmod_newscat).".id)
AND
(".$modx->getFullTableName(rmod_news).".publish = 1)
ORDER by news_date DESC";
$sqlResult = $modx->db->query($sql);
while ($row = $modx->db->getRow($sqlResult))
{
$ddate = explode("/", $row['news_date']);
$narr[] = array(
'id' => $row['id'],
'news_name' => $row['title'],
'cat_name' => $row['cat_name'],
'autor' => $row['autor'],
'news_date' => $ddate[0],
'news_link' => $modx->makeUrl($modx->documentIdentifier).'?nid='.$row['id'],
'news_descr' => $row['show_preview'],
'full_link' => $row['full_link'],
);
}
$tpl = new mgChunkie($rn_config['NewsListTpl']);
foreach ($narr as $valr)
{
$tpl->addVar('rnews', $valr);
$output .= $tpl->Render();
}
}
else
{
$tb_prefix = $modx->db->config['table_prefix'];
$get_news = $modx->db->select('*', $modx->getFullTableName(rmod_news), 'id=\''.intval($nidid).'\'', '');
$news = $modx->db->getRow($get_news);
$tpl = new mgChunkie($rn_config['NewsTpl']);
$pageinfo=$modx->getPageInfo($_REQUEST['gal_id'],0, "id, pagetitle, longtitle, description, alias, createdby");
$isModer = intval($modx->isMemberOfWebGroup($this->config["permissions"]["moderate"] ) || $modx->checkSession());
if ($isModer)
{
$edurl = $modx->makeUrl($modx->documentIdentifier).'?nid='.$nidid.'&mode=edit';
$news['m_editnews'] = '<a href="'.$edurl.'" title="Редактировать" style="color:#333333;">« Редактировать новость</a><br><br><hr>';
}
if($_GET[mode] != 'edit')
{
$tpl->addVar('rnews', $news);
$output .= $tpl->Render();
}
else
{
if($isModer)
{
if(!isset($_POST['doedit']))
{
$output .= '<br><br><hr><form method="post" action="">';
include_once($modx->config['base_path'].'/manager/includes/tmplvars.inc.php');
$event_output = $modx->invokeEvent("OnRichTextEditorInit", array(
'editor'=>$modx->config['which_editor'],
'elements'=>array('tvxNews'),
'height' => '500',
'frontend' => 0,
'webtheme' => 'custom'
));
if(is_array($event_output))
{
$editor_html = implode("",$event_output);
}
// Get HTML for the textarea, last parameters are default_value, elements, value
$rte_html = renderFormElement('richtext', 'xNews', '', '', $news['news_body']);
$output .= $rte_html;
print($_lang);
$output .= $editor_html.'<div align="center"><input name="doedit" type="submit" value="Сохранить"> <input name="back" type="button" value="Отмена" onclick="javascript:window.location=\''.$modx->makeUrl($modx->documentIdentifier).'?nid='.$nidid
.'\';">
</form>';
}
else
{
if(isset($nidid) and $nidid != '0')
{
$fields = array ('news_body' => addslashes($_POST['tvxNews']));
//print($fields);
$modx->db->update($fields, $modx->getFullTableName(rmod_news), 'id="' . intval($nidid) . '"');
echo '<br><br><br><div align="center"><a href="'.$modx->makeUrl($modx->documentIdentifier).'?nid='.$nidid
.'">Редактирование законченно, просмотреть новость.</a></div>';
}
else
{
echo 'error';
}
}
}
}
}
return $output;
?>
|