Adding to SP3 : fixing images and others
This commit is contained in:
128
inc/databap.php
128
inc/databap.php
@@ -512,28 +512,38 @@ class Databap extends PhpObject
|
||||
$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 ')));
|
||||
$sMessageIdCol = MySqlManager::getId(self::MSG_TABLE);
|
||||
$sChanIdCol = MySqlManager::getId(self::CHAN_TABLE);
|
||||
$asResult = $this->oMySql->selectRows(array('select'=>array($sMessageIdCol, 'nickname', $sChanIdCol, 'message', 'led'),
|
||||
'from'=>self::MSG_TABLE,
|
||||
'constraint'=>array('message'=>$sRegEx),
|
||||
'constOpe'=>array('message'=>' REGEXP ')));
|
||||
$asChans = $this->oMySql->selectRows(array('select'=>array($sChanIdCol, 'safe_name'), 'from'=>self::CHAN_TABLE), true, $sChanIdCol);
|
||||
|
||||
$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);
|
||||
//filter on authorized chans
|
||||
if($this->checkChanAuth($asChans[$asRow[$sChanIdCol]], $this->getUserId()))
|
||||
{
|
||||
//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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -944,32 +954,38 @@ class Databap extends PhpObject
|
||||
//Add record in Search Table
|
||||
$this->oSearchEngine->buildIndex($iDbDocId, self::DOC_TYPE);
|
||||
|
||||
return self::jsonExport(array('result'=>'success','doc_id'=>$iDbDocId));
|
||||
//TODO add error handling
|
||||
return $this->getJsonPostResult(self::SUCCESS, '', array('doc_id'=>$iDbDocId));
|
||||
}
|
||||
|
||||
public function getDoc($iDocId)
|
||||
{
|
||||
//Extract doc data
|
||||
$asDoc = $this->oMySql->selectRow(self::DOC_TABLE, $iDocId);
|
||||
$asDoc['description'] = self::getDescriptionFormat($asDoc['description']);
|
||||
$asDoc['title'] = self::getDescriptionFormat($asDoc['title']);
|
||||
$asDoc['led'] = self::getDateFormat($asDoc['led']);
|
||||
|
||||
//Extract extra data
|
||||
$asUser = $this->getUserInfo($asDoc[MySqlManager::getId(self::USER_TABLE)]);
|
||||
$asDoc['name'] = $asUser['name'];
|
||||
$asDoc['company'] = $asUser['company'];
|
||||
|
||||
//Extract doc files
|
||||
$sFileIdCol = MySqlManager::getId(self::FILE_TABLE);
|
||||
$asFiles = $this->oMySql->selectRows(array('from'=>self::FILE_TABLE, 'constraint'=>array('id_item'=>$iDocId, 'type'=>self::DOC_TYPE)));
|
||||
foreach($asFiles as $asFile)
|
||||
$bSuccess = !empty($asDoc);
|
||||
$sDesc = '';
|
||||
if(!$bSuccess) $sDesc = self::NOT_FOUND;
|
||||
else
|
||||
{
|
||||
$asDoc['files'][$asFile[$sFileIdCol]] = array( 'description' => self::getDescriptionFormat($asFile['description']),
|
||||
'ext' => $asFile['extension']);
|
||||
$asDoc['description'] = self::getDescriptionFormat($asDoc['description']);
|
||||
$asDoc['title'] = self::getDescriptionFormat($asDoc['title']);
|
||||
$asDoc['led'] = self::getDateFormat($asDoc['led']);
|
||||
|
||||
//Extract extra data
|
||||
$asUser = $this->getUserInfo($asDoc[MySqlManager::getId(self::USER_TABLE)]);
|
||||
$asDoc['name'] = $asUser['name'];
|
||||
$asDoc['company'] = $asUser['company'];
|
||||
|
||||
//Extract doc files
|
||||
$sFileIdCol = MySqlManager::getId(self::FILE_TABLE);
|
||||
$asFiles = $this->oMySql->selectRows(array('from'=>self::FILE_TABLE, 'constraint'=>array('id_item'=>$iDocId, 'type'=>self::DOC_TYPE)));
|
||||
foreach($asFiles as $asFile)
|
||||
{
|
||||
$asDoc['files'][$asFile[$sFileIdCol]] = array( 'description' => self::getDescriptionFormat($asFile['description']),
|
||||
'ext' => $asFile['extension']);
|
||||
}
|
||||
}
|
||||
|
||||
return self::jsonExport($asDoc);
|
||||
return $this->getJsonPostResult($bSuccess, $sDesc, $asDoc);
|
||||
}
|
||||
|
||||
public function addTable($sSystem, $sTitle, $sDescription, $sKeyWords, $iPrevTableId, $bSimul=false)
|
||||
@@ -1102,19 +1118,16 @@ class Databap extends PhpObject
|
||||
return $sResult;
|
||||
}
|
||||
|
||||
public function uploadImage()
|
||||
public function uploadFile($sFileType)
|
||||
{
|
||||
switch($sFileType)
|
||||
{
|
||||
case 'image': $asAuthorizedTypes = self::$UPLOAD_IMG_EXTS; break;
|
||||
case 'doc' : $asAuthorizedTypes = self::$UPLOAD_DOC_EXTS; break;
|
||||
default : $asAuthorizedTypes = array();
|
||||
}
|
||||
$this->oClassManagement->incClass('fileuploader');
|
||||
$oFileUploader = new fileUploader(Procedure::IMAGE_FOLDER_TMP, self::$UPLOAD_IMG_EXTS);
|
||||
$asResult = $oFileUploader->handleUpload();
|
||||
|
||||
return $this->jsonConvert($asResult);
|
||||
}
|
||||
|
||||
public function uploadDoc()
|
||||
{
|
||||
$this->oClassManagement->incClass('fileuploader');
|
||||
$oFileUploader = new fileUploader(self::DOC_TMP_FOLDER, self::$UPLOAD_DOC_EXTS);
|
||||
$oFileUploader = new fileUploader(self::DOC_TMP_FOLDER, $asAuthorizedTypes);
|
||||
$asResult = $oFileUploader->handleUpload();
|
||||
|
||||
return $this->jsonConvert($asResult);
|
||||
@@ -1179,8 +1192,7 @@ class Databap extends PhpObject
|
||||
private function getTableInfo($iTableId, $bFormatting=true)
|
||||
{
|
||||
$asTable = $this->oMySql->selectRow(self::TABL_TABLE, $iTableId);
|
||||
if(!$asTable) $asTable = array(); //return false on empty
|
||||
else
|
||||
if(!empty($asTable))
|
||||
{
|
||||
$asTable['timestamp'] = strtotime($asTable['led']);
|
||||
if($bFormatting)
|
||||
@@ -1852,10 +1864,8 @@ class Databap extends PhpObject
|
||||
|
||||
private function downloadToTmp($sUrl)
|
||||
{
|
||||
$sFileInfo = pathinfo($sUrl);
|
||||
$sImageExt = mb_strtolower($sFileInfo['extension']);
|
||||
$sFilePath = self::DOC_TMP_FOLDER.uniqid().'.'.$sImageExt;
|
||||
return ToolBox::createThumbnail($sUrl, self::CHAT_IMG_MAX_WIDTH, self::CHAT_IMG_MAX_HEIGHT, $sFilePath, false, Databap::$UPLOAD_IMG_EXTS);
|
||||
$sFilePath = self::DOC_TMP_FOLDER.uniqid();
|
||||
return ToolBox::createThumbnail($sUrl, self::CHAT_IMG_MAX_WIDTH, self::CHAT_IMG_MAX_HEIGHT, $sFilePath, false, self::$UPLOAD_IMG_EXTS);
|
||||
}
|
||||
|
||||
private function sendPM($iUserIdTo, $sMessage)
|
||||
@@ -2344,11 +2354,6 @@ class Databap extends PhpObject
|
||||
return $oMask->getMask();
|
||||
}
|
||||
|
||||
public static function checkNoAuthCookieResetAction($sAction)
|
||||
{
|
||||
return in_array($sAction, array('messages', 'upload_image', 'user_info', 'rss'));
|
||||
}
|
||||
|
||||
public function logMeIn($sToken, $sAction)
|
||||
{
|
||||
$iUserId = 0;
|
||||
@@ -2384,7 +2389,7 @@ class Databap extends PhpObject
|
||||
$asUserInfo = $this->oMySql->selectRow(self::USER_TABLE, $asConstraints, array($sUserTableId, 'led'));
|
||||
$iUserId = $asUserInfo[$sUserTableId];
|
||||
|
||||
//Check pass reset necessity
|
||||
//Reset pass once a day
|
||||
$bResetPass = (mb_substr($asUserInfo['led'], 0, 10) != date(Databap::DATE_SQL_FORMAT));
|
||||
}
|
||||
}
|
||||
@@ -2398,10 +2403,7 @@ class Databap extends PhpObject
|
||||
if($iUserId>0)
|
||||
{
|
||||
$this->setUserId($iUserId);
|
||||
if(!self::checkNoAuthCookieResetAction($sAction) && $bResetPass)
|
||||
{
|
||||
$this->resetAuthCookie();
|
||||
}
|
||||
if($bResetPass) $this->resetAuthCookie();
|
||||
|
||||
//Post-Redirect-Get if user manually logging from logon page
|
||||
if($sNameToken!='')
|
||||
|
||||
Reference in New Issue
Block a user