fix bug: force scrollbar to the bottom while scrolling in chat when new
message pops up new rss added : cat = news
This commit is contained in:
106
inc/databap.php
106
inc/databap.php
@@ -7,7 +7,7 @@
|
||||
class Databap extends PhpObject
|
||||
{
|
||||
//Common Constants
|
||||
const VERSION = '1.0.0-RC2'; //Versioning: <Main_Version>.<Enhancement_Package>.<Patch>-<Release_Candidate>
|
||||
const VERSION = '1.0.0-RC3'; //Versioning: <Main_Version>.<Enhancement_Package>.<Patch>-<Release_Candidate>
|
||||
const VERSION_DATE = '02/07/2014';
|
||||
const EXPECTED_PAGE_COOKIE = 'exp_page';
|
||||
const MAIN_SEPARATOR = ' ';
|
||||
@@ -96,6 +96,7 @@ class Databap extends PhpObject
|
||||
const CHAT_IMG_MAX_WIDTH = 700;
|
||||
const CHAT_IMG_MAX_HEIGHT = 1080;
|
||||
const JSON_PREFIX = '[\-JSON-/]';
|
||||
const MAX_NB_NEWS = 3;
|
||||
|
||||
//Options Name Id Constants
|
||||
const LANG_FR = 'FR';
|
||||
@@ -413,43 +414,68 @@ class Databap extends PhpObject
|
||||
$oFeed = new Feed($asDesc);
|
||||
|
||||
//Building items
|
||||
switch(mb_strtolower($sCat))
|
||||
if($sCat=='news')
|
||||
{
|
||||
case '9gag':
|
||||
$sRegEx = '(https?://|www\\.)(.*)9gag\\.com';
|
||||
break;
|
||||
case 'youtube':
|
||||
$sRegEx = '(https?://|www\\.)(.*)youtube\\.com';
|
||||
break;
|
||||
case '':
|
||||
$sRegEx = '(https?://|www\\.)[\.A-Za-z0-9\-]+\\.[a-zA-Z]{2,4}';
|
||||
break;
|
||||
default:
|
||||
$sRegEx = '(https?://|www\\.)(.*)'.$sCat.'(.*)\\.[a-zA-Z]{2,4}';
|
||||
break;
|
||||
$asNews = $this->getNews(false);
|
||||
$iLinkId = count($asNews);
|
||||
foreach($asNews as $iMsgId=>$asRow)
|
||||
{
|
||||
//TODO mutualiser avec le reste
|
||||
$sChatlink = $this->getInternalLink('chat', $iMsgId);
|
||||
$asItem = array
|
||||
(
|
||||
'title'=>'Lien'.($sCat==''?'':' - '.$sCat).' #'.$iLinkId,
|
||||
'category'=>$sCat,
|
||||
'description'=>$asRow['message'],
|
||||
'author'=>$asRow['nickname'],
|
||||
'link'=>$sChatlink,
|
||||
'pub_date'=>$asRow['time'],
|
||||
'guid'=>$sChatlink
|
||||
);
|
||||
$oFeed->addItem($asItem);
|
||||
$iLinkId -= 1;
|
||||
}
|
||||
}
|
||||
$asResult = $this->oMySql->selectRows(array('select'=>array('id_message', 'nickname', 'message', 'led'), 'from'=>'messages', 'constraint'=>array('message'=>$sRegEx), 'constOpe'=>array('message'=>' REGEXP ')));
|
||||
$sPattern = '/(https?\:\/\/|www\.)[\S]+\.[a-zA-Z]{2,4}([\S]*)/ui';
|
||||
|
||||
foreach($asResult as $iLinkId=>$asRow)
|
||||
else
|
||||
{
|
||||
//get link out of message
|
||||
preg_match($sPattern, $asRow['message'], $asMatches);
|
||||
$asRow['link'] = (substr($asMatches[0], 0, 4)=='http')?$asMatches[0]:'http://'.$asMatches[0];
|
||||
|
||||
//add item
|
||||
$sChatlink = $this->getInternalLink('chat', $asRow['id_message']);
|
||||
$asItem = array
|
||||
(
|
||||
'title'=>'Lien'.($sCat==''?'':' - '.$sCat).' #'.($iLinkId+1),
|
||||
'category'=>$sCat,
|
||||
'description'=>'Lien posté par '.self::getNickNameFormat($asRow['nickname']).' à '.self::getDateFormat($asRow['led']).' : <a href="'.$asRow['link'].'" target="_blank">'.$asRow['message'].'</a>',
|
||||
'author'=>$asRow['nickname'],
|
||||
'link'=>$sChatlink,
|
||||
'pub_date'=>$asRow['led'],
|
||||
'guid'=>$sChatlink
|
||||
);
|
||||
$oFeed->addItem($asItem);
|
||||
switch($sCat)
|
||||
{
|
||||
case '9gag':
|
||||
$sRegEx = '(https?://|www\\.)(.*)9gag\\.com';
|
||||
break;
|
||||
case 'youtube':
|
||||
$sRegEx = '(https?://|www\\.)(.*)youtube\\.com';
|
||||
break;
|
||||
case '':
|
||||
$sRegEx = '(https?://|www\\.)[\.A-Za-z0-9\-]+\\.[a-zA-Z]{2,4}';
|
||||
break;
|
||||
default:
|
||||
$sRegEx = '(https?://|www\\.)(.*)'.$sCat.'(.*)\\.[a-zA-Z]{2,4}';
|
||||
break;
|
||||
}
|
||||
$asResult = $this->oMySql->selectRows(array('select'=>array('id_message', 'nickname', 'message', 'led'), 'from'=>'messages', 'constraint'=>array('message'=>$sRegEx), 'constOpe'=>array('message'=>' REGEXP ')));
|
||||
|
||||
$sPattern = '/(https?\:\/\/|www\.)[\S]+\.[a-zA-Z]{2,4}([\S]*)/ui';
|
||||
foreach($asResult as $iLinkId=>$asRow)
|
||||
{
|
||||
//get link out of message
|
||||
preg_match($sPattern, $asRow['message'], $asMatches);
|
||||
$asRow['link'] = (substr($asMatches[0], 0, 4)=='http')?$asMatches[0]:'http://'.$asMatches[0];
|
||||
|
||||
//add item
|
||||
$sChatlink = $this->getInternalLink('chat', $asRow['id_message']);
|
||||
$asItem = array
|
||||
(
|
||||
'title'=>'Lien'.($sCat==''?'':' - '.$sCat).' #'.($iLinkId+1),
|
||||
'category'=>$sCat,
|
||||
'description'=>'Lien posté par '.self::getNickNameFormat($asRow['nickname']).' à '.self::getDateFormat($asRow['led']).' : <a href="'.$asRow['link'].'" target="_blank">'.$asRow['message'].'</a>',
|
||||
'author'=>$asRow['nickname'],
|
||||
'link'=>$sChatlink,
|
||||
'pub_date'=>$asRow['led'],
|
||||
'guid'=>$sChatlink
|
||||
);
|
||||
$oFeed->addItem($asItem);
|
||||
}
|
||||
}
|
||||
|
||||
return $oFeed->getFeed();
|
||||
@@ -462,7 +488,8 @@ class Databap extends PhpObject
|
||||
|
||||
//Update and spread the news
|
||||
$asResult = array();
|
||||
if(date('N')>5 || date('G')>19) $asResult[] = "Pas de mise-à-jour pendant le week end ou en soirée.";
|
||||
$iTimeStamp = time();
|
||||
if(date('N', $iTimeStamp)>5 || date('G', $iTimeStamp)>19) $asResult[] = "Pas de mise-à-jour pendant le week end ou en soirée.";
|
||||
else
|
||||
{
|
||||
foreach($asArticles as $asArticle)
|
||||
@@ -1833,7 +1860,7 @@ class Databap extends PhpObject
|
||||
return $this->jsonExport($asMessages);
|
||||
}
|
||||
|
||||
public function getNews()
|
||||
public function getNews($bExport=true)
|
||||
{
|
||||
$sMsgIdCol = MySqlManager::getId(self::MSG_TABLE);
|
||||
$sMsgTxtCol = MySqlManager::getText(self::MSG_TABLE);
|
||||
@@ -1860,20 +1887,21 @@ class Databap extends PhpObject
|
||||
{
|
||||
if($asNews[$iKey]['type']==self::MESSAGE_STATUS) $asNews[$iKey][$sMsgTxtCol] = $asNews[$iKey]['nickname'].' '.$asNews[$iKey][$sMsgTxtCol];
|
||||
$asNews2[] = $asNews[$iKey];
|
||||
if(count($asNews2)==3) break;
|
||||
if(count($asNews2)==self::MAX_NB_NEWS) break;
|
||||
}
|
||||
|
||||
$asFormatNews = array();
|
||||
foreach($asNews2 as $asNew)
|
||||
{
|
||||
$iMsgId = '-'.$asNew[$sMsgIdCol];
|
||||
$asFormatNews[$iMsgId]['time'] = $asNew['led'];
|
||||
$asFormatNews[$iMsgId]['time_desc'] = ToolBox::getDateTimeDesc($asNew['led']);
|
||||
$asFormatNews[$iMsgId]['message'] = self::getDescriptionFormat($asNew['message']);
|
||||
$asFormatNews[$iMsgId]['nickname'] = self::getNickNameFormat($asNew['nickname']);
|
||||
}
|
||||
|
||||
$sSuccess = (count($asFormatNews)>0);
|
||||
return $this->getJsonPostResult($sSuccess, $sSuccess?'':'Aucune news', array('news'=>$asFormatNews));
|
||||
return $bExport?$this->getJsonPostResult($sSuccess, $sSuccess?'':'Aucune news', array('news'=>$asFormatNews)):$asFormatNews;
|
||||
}
|
||||
|
||||
private function getConnectedChans($iuserId=0)
|
||||
|
||||
Reference in New Issue
Block a user