1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-17 20:58:30 +01:00

News render-type malfunction fixed.

This commit is contained in:
CaMer0n 2011-07-06 23:37:49 +00:00
parent ea40b6fd28
commit a31f89b589
2 changed files with 48 additions and 174 deletions

View File

@ -271,7 +271,7 @@ class admin_newspost
'news_datestamp' => array('title' => LAN_NEWS_32, 'type' => 'datestamp', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false, 'parms' => 'mask=%A %d %B %Y'),
'category_name' => array('title' => NWSLAN_6, 'type' => 'text', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false),
'news_class' => array('title' => NWSLAN_22, 'type' => 'userclass', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false),
'news_render_type' => array('title' => LAN_NEWS_49, 'type' => 'dropdown', 'width' => 'auto', 'thclass' => 'center', 'class' => null, 'nosort' => false),
'news_render_type' => array('title' => LAN_NEWS_49, 'type' => 'number', 'width' => 'auto', 'thclass' => 'center', 'class' => null, 'nosort' => false),
'news_thumbnail' => array('title' => LAN_NEWS_22, 'type' => 'text', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false),
'news_sticky' => array('title' => LAN_NEWS_28, 'type' => 'boolean', 'width' => 'auto', 'thclass' => 'center', 'class' => 'center', 'nosort' => false),
'news_allow_comments' => array('title' => NWSLAN_15, 'type' => 'boolean', 'width' => 'auto', 'thclass' => 'center', 'class' => 'center', 'nosort' => false),
@ -465,7 +465,7 @@ class admin_newspost
function show_page()
{
print_a($POST);
// print_a($POST);
switch ($this->getAction()) {
case 'savepreset':
@ -647,6 +647,9 @@ class admin_newspost
$tmp = explode(chr(35), $_POST['news_author']);
$_POST['news_author'] = $tmp[0];
$ret = $ix->submit_item($_POST, !vartrue($_POST['create_edit_stay']));
if($ret['error'])
{
@ -738,36 +741,7 @@ class admin_newspost
if($id)
{
$inserta['data']['category_id'] = $id;
//Manage rewrite
if(!empty($_POST['news_rewrite_string']))
{
$rwinserta = array();
$rwinserta['data']['news_rewrite_source'] = $id;
$rwinserta['_FIELD_TYPES']['news_rewrite_source'] = 'int';
$rwinserta['data']['news_rewrite_string'] = $_POST['news_rewrite_string'];
$rwinserta['_FIELD_TYPES']['news_rewrite_string'] = 'todb';
$rwinserta['data']['news_rewrite_type'] = 2;
$rwinserta['_FIELD_TYPES']['news_rewrite_type'] = 'int';
$rid = e107::getDb()->db_Insert('news_rewrite', $rwinserta);
$rwinserta['data']['news_rewrite_id'] = $rid;
if(e107::getDb()->getLastErrorNumber())
{
$this->error = true;
$this->show_message('Category friendly URL string related problem detected!', E_MESSAGE_ERROR);
if(1052 == e107::getDb()->getLastErrorNumber())
{
$this->show_message('Category friendly URL string should be unique! ', E_MESSAGE_ERROR);
}
$this->show_message('mySQL error #'.e107::getDb()->getLastErrorNumber().': '.e107::getDb()->getLastErrorText(), E_MESSAGE_DEBUG);
return;
}
$this->set_rwcache($_POST['news_rewrite_string'], $rwinserta['data']);
e107::getAdminLog()->log_event('NEWS_10', $rwinserta, E_LOG_INFORMATIVE, '');
}
//admin log now supports DB array and method chaining
e107::getAdminLog()->log_event('NEWS_04', $inserta, E_LOG_INFORMATIVE, '');
@ -813,11 +787,6 @@ class admin_newspost
$this->error = true;
}
if(!empty($_POST['news_rewrite_string']) && preg_match('#[^\w\pL\-]#u', $_POST['news_rewrite_string']))
{
$this->show_message('Validation Error: Bad value for Category friendly URL', E_MESSAGE_ERROR);
$this->error = true;
}
if (!$this->error)
{
@ -843,69 +812,13 @@ class admin_newspost
$updatea['WHERE'] = 'category_id='.$this->getId();
$inserta = array();
$rid = isset($_POST['news_rewrite_id']) ? $_POST['news_rewrite_id'] : 0;
$rid = 0;
$inserta['data']['news_rewrite_id'] = $rid;
$inserta['_FIELD_TYPES']['news_rewrite_id'] = 'int';
$inserta['data']['news_rewrite_source'] = $this->getId();
$inserta['_FIELD_TYPES']['news_rewrite_source'] = 'int';
$inserta['data']['news_rewrite_string'] = $_POST['news_rewrite_string'];
$inserta['_FIELD_TYPES']['news_rewrite_string'] = 'todb';
$inserta['data']['news_rewrite_type'] = 2;
$inserta['_FIELD_TYPES']['news_rewrite_type'] = 'int';
$oldsef = array();
//'news_rewrite_source='.intval($this->getId()).' AND news_rewrite_type=2'
if(e107::getDb()->db_Select('news_rewrite', '*', 'news_rewrite_id='.intval($rid)))
{
$oldsef = e107::getDb()->db_Fetch();
}
$upcheck = e107::getDb()->db_Update("news_category", $updatea);
$rwupcheck = false;
if($upcheck || !e107::getDb()->getLastErrorNumber())
{
//Manage rewrite
if(!empty($_POST['news_rewrite_string']))
{
if($rid)
{
$inserta['WHERE'] = 'news_rewrite_id='.intval($rid);
$rwupcheck = e107::getDb()->db_Update('news_rewrite', $inserta);
}
else
{
$rwupcheck = e107::getDb()->db_Insert('news_rewrite', $inserta);
$inserta['data']['news_rewrite_id'] = $rwupcheck;
}
if(e107::getDb()->getLastErrorNumber())
{
$this->error = true;
$this->setSubAction('edit');
$this->show_message('Category friendly URL string related problem detected!', E_MESSAGE_ERROR);
if(1062 == e107::getDb()->getLastErrorNumber()) //detect duplicate mysql errnum
{
$this->show_message('Category friendly URL string should be unique! ', E_MESSAGE_ERROR);
}
$this->show_message('mySQL error #'.e107::getDb()->getLastErrorNumber().': '.e107::getDb()->getLastErrorText(), E_MESSAGE_DEBUG);
return;
}
}
else
{
//remove SEF if required
if($oldsef)
{
$this->clear_rwcache($oldsef['news_rewrite_string']);
e107::getDb()->db_Delete('news_rewrite', 'news_rewrite_id='.$oldsef['news_rewrite_id']);
e107::getAdminLog()->log_event('NEWS_11', $oldsef, E_LOG_INFORMATIVE, '');
$inserta = array( 'data' => array());
$rwupcheck = true;
}
}
if ($upcheck || $rwupcheck)
{
@ -925,8 +838,6 @@ class admin_newspost
$this->show_message(LAN_NO_CHANGE);
}
if(varset($oldsef['news_rewrite_string'])) $this->clear_rwcache($oldsef['news_rewrite_string']);
if($_POST['news_rewrite_string']) $this->set_rwcache($_POST['news_rewrite_string'], $inserta['data']);
$this->setId(0);
}
@ -1078,11 +989,8 @@ class admin_newspost
else
{
$ordfield = 'n.news_datestamp';
if($this->getSubAction() == 'news_rewrite_string')
{
$ordfield = "nr.news_rewrite_string";
}
elseif($this->getSubAction() == 'user_name')
if($this->getSubAction() == 'user_name')
{
$ordfield = "u.user_name";
}
@ -1112,7 +1020,7 @@ class admin_newspost
".$frm->thead($this->fields, $this->fieldpref, 'main.[FIELD].[ASC].[FROM]')."
<tbody>";
$ren_type = array("default","title","other-news","other-news 2");
$ren_type = array("default","title","other-news","other-news 2"); // Shortened
foreach($newsarray as $row)
{
@ -1122,16 +1030,13 @@ class admin_newspost
$row['news_title'] = "<a href='".e107::getUrl()->createCoreNews("action=extend&id={$row['news_id']}&sef={$row['news_rewrite_string']}")."'>".$e107->tp->toHTML($row['news_title'], false, 'TITLE')."</a>";
$row['category_name'] = "<a href='".e107::getUrl()->createCoreNews('action=list&id='.$row['category_id'].'&sef='.$row['news_category_rewrite_string'])."'>".$row['category_name']."</a>";
$row['news_render_type'] = $ren_type[$row['news_render_type']];
$row['news_allow_comments'] = !$row['news_allow_comments'] ? true : false; // old reverse logic
$row['options'] = "
<a class='action' href='".e_SELF."?create.edit.{$row['news_id']}' tabindex='".$frm->getNext()."'>".ADMIN_EDIT_ICON."</a>
".$frm->submit_image("delete[main_{$row['news_id']}]", LAN_DELETE, 'delete', NWSLAN_39." [ID: {$row['news_id']}]")."
";
$row['checkboxes'] = $row['news_id'];
if(!varset($row['news_rewrite_string']))
{
$row['news_rewrite_string'] = ''; //prevent 'Not found' message
}
// AUTO RENDER
$text .= $frm->renderTableRow($this->fields, $this->fieldpref, $row, 'news_id');
@ -1319,7 +1224,7 @@ class admin_newspost
$_POST['news_start'] = $row['news_start'];
$_POST['news_end'] = $row['news_end'];
$_POST['comment_total'] = e107::getDb()->db_Count("comments", "(*)", " WHERE comment_item_id={$row['news_id']} AND comment_type='0'");
$_POST['news_rendertype'] = $row['news_render_type'];
$_POST['news_render_type'] = $row['news_render_type'];
$_POST['news_thumbnail'] = $row['news_thumbnail'];
$_POST['news_meta_keywords'] = $row['news_meta_keywords'];
$_POST['news_meta_description'] = $row['news_meta_description'];
@ -1721,7 +1626,7 @@ class admin_newspost
$text .= "
".$frm->radio_multi('news_rendertype', $this->news_renderTypes, $_POST['news_rendertype'], true)."
".$frm->radio_multi('news_render_type', $this->news_renderTypes, $_POST['news_render_type'], true)."
<div class='field-help'>
".NWSLAN_74."
</div>

View File

@ -38,6 +38,7 @@ class news {
//TODO - synch WIKI docs, add rewrite data to the event data
function submit_item($news, $smessages = false)
{
global $e107cache, $e_event, $pref, $admin_log;
$tp = e107::getParser();
@ -140,14 +141,12 @@ class news {
//$vals = "news_datestamp = '".intval($news['news_datestamp'])."', ".$author_insert." news_title='".$news['news_title']."', news_body='".$news['news_body']."', news_extended='".$news['news_extended']."', news_category='".intval($news['cat_id'])."', news_allow_comments='".intval($news['news_allow_comments'])."', news_start='".intval($news['news_start'])."', news_end='".intval($news['news_end'])."', news_class='".$tp->toDB($news['news_class'])."', news_render_type='".intval($news['news_rendertype'])."' , news_summary='".$news['news_summary']."', news_thumbnail='".$tp->toDB($news['news_thumbnail'])."', news_sticky='".intval($news['news_sticky'])."' WHERE news_id='".intval($news['news_id'])."' ";
if ($sql->db_Update('news', $data))
{
e107::getAdminLog()->logArrayAll('NEWS_09', $logData);
//manage rewrites
$data['data']['news_id'] = $news['news_id'];
if('error' === $this->handleRewriteSubmit('update', $data['data'], $datarw, $smessages))
{
$error = true;
}
e107::getEvent()->trigger('newsupd', $data['data']);
$message = LAN_NEWS_21;
@ -171,21 +170,10 @@ class news {
else
{
$data['data']['news_id'] = $news['news_id'];
$check = $this->handleRewriteSubmit('update', $data['data'], $datarw, $smessages);
if ($check === true)
{
$message = LAN_NEWS_21;
$emessage->add(LAN_NEWS_21, E_MESSAGE_SUCCESS, $smessages);
}
elseif ($check === 'error')
{
$error = true;
}
else
{
$emessage->add(LAN_NEWS_46, E_MESSAGE_INFO, $smessages);
$message = "<strong>".LAN_NEWS_46."</strong>";
}
//FIXME - triggerHook should return array(message, message_type)
$evdata = array('method'=>'update', 'table'=>'news', 'id'=>$news['news_id'], 'plugin'=>'news', 'function'=>'submit_item');
@ -209,13 +197,6 @@ class news {
//moved down - prevent wrong mysql_insert_id
e107::getAdminLog()->logArrayAll('NEWS_08', $logData);
//manage rewrites
if('error' === $this->handleRewriteSubmit('insert', $data['data'], $datarw, $smessages))
{
$error = true;
}
e107::getEvent()->trigger('newspost', $data['data']);
//XXX - triggerHook after trigger?
@ -295,8 +276,11 @@ class news {
return $data;
}
// DEPRECATED - NOT TO BE USED. Way too many changes required to make it work.
/**
* Manage SEF URL string for current news
* Manage SEF URL string for current news // Deprecated.
* FIXME - news rewrites should go to different handler
*
* @param string $action insert|update
@ -305,8 +289,13 @@ class news {
* @param boolean $session_message [optional] default false
* @return mixed true|false for data has been[not] changed; 'error' for DB error
*/
/*
function handleRewriteSubmit($action, $news_data, $rewrite_data, $session_message = false)
{
return TRUE;
// Deprecated.
$rewrite_data['data']['news_rewrite_source'] = $news_data['news_id'];
$rewrite_data['_FIELD_TYPES']['news_rewrite_source'] = 'int';
@ -401,9 +390,12 @@ class news {
break;
}
return false;
}
*/
/*
public static function retrieveRewriteString($news_id, $type = 1)
{
//XXX - Best way we have now, discuss
@ -448,6 +440,7 @@ class news {
return (isset(self::$_rewrite_map[$type][$news_id]) ? self::$_rewrite_map[$type][$news_id] : '');
}
public static function retrieveRewriteData($sefstr, $force = true)
{
//check runtime cache
@ -481,7 +474,8 @@ class news {
return self::$_rewrite_data[$sefstr];
}
*/
/*
public static function getRewriteCache($sefstr, $toArray = true)
{
$sefstr = md5($sefstr);
@ -507,6 +501,7 @@ class news {
if(is_array($data)) $data = e107::getArrayStorage()->WriteArray($data, false);
ecache::set_sys("news_sefurl".$sefstr, $data, true);
}
*/
function render_newsitem($news, $mode = 'default', $n_restrict = '', $NEWS_TEMPLATE = '', $param = array())
{
@ -1143,19 +1138,7 @@ class e_news_category_tree extends e_model
return $this;
}
$sef = (e107::getUrl()->getProfileId('news') !== 'main');
if($sef)
{
$qry = "
SELECT nc.*, ncr.news_rewrite_string AS category_rewrite_string, ncr.news_rewrite_id AS category_rewrite_id FROM #news_category AS nc
LEFT JOIN #news_rewrite AS ncr ON nc.category_id=ncr.news_rewrite_source AND ncr.news_rewrite_type=2
ORDER BY nc.category_order ASC
";
}
else
{
$qry = "SELECT * FROM #news_category ORDER BY category_order ASC";
}
$tree = array();
$sql = e107::getDb();
@ -1186,23 +1169,9 @@ class e_news_category_tree extends e_model
return $this;
}
$sef = (e107::getUrl()->getProfileId('news') !== 'main');
$nobody_regexp = "'(^|,)(".str_replace(",", "|", e_UC_NOBODY).")(,|$)'";
$time = time();
if($sef)
{
$qry = "
SELECT COUNT(n.news_id) AS category_news_count, nc.*, ncr.news_rewrite_string AS category_rewrite_string, ncr.news_rewrite_id AS category_rewrite_id FROM #news_category AS nc
LEFT JOIN #news_rewrite AS ncr ON nc.category_id=ncr.news_rewrite_source AND ncr.news_rewrite_type=2
LEFT JOIN #news AS n ON n.news_category=nc.category_id
WHERE n.news_class REGEXP '".e_CLASS_REGEXP."' AND NOT (n.news_class REGEXP ".$nobody_regexp.")
AND n.news_start < ".$time." AND (n.news_end=0 || n.news_end>".$time.")
GROUP BY nc.category_id
ORDER BY nc.category_order ASC
";
}
else
{
$qry = "
SELECT COUNT(n.news_id) AS category_news_count, nc.* FROM #news_category AS nc
LEFT JOIN #news AS n ON n.news_category=nc.category_id
@ -1211,7 +1180,7 @@ class e_news_category_tree extends e_model
GROUP BY nc.category_id
ORDER BY nc.category_order ASC
";
}
$tree = array();
$sql = e107::getDb();