fix link replacement (table / one-letter replacement)
This commit is contained in:
109
inc/databap.php
109
inc/databap.php
@@ -7,8 +7,8 @@
|
|||||||
class Databap extends PhpObject
|
class Databap extends PhpObject
|
||||||
{
|
{
|
||||||
//Common Constants
|
//Common Constants
|
||||||
const VERSION = '1.0.0-RC5'; //Versioning: <Main_Version>.<Enhancement_Package>.<Patch>-<Release_Candidate>
|
const VERSION = '1.0.0-RC6'; //Versioning: <Main_Version>.<Enhancement_Package>.<Patch>-<Release_Candidate>
|
||||||
const VERSION_DATE = '20/08/2014';
|
const VERSION_DATE = '28/08/2014';
|
||||||
const EXPECTED_PAGE_COOKIE = 'exp_page';
|
const EXPECTED_PAGE_COOKIE = 'exp_page';
|
||||||
const MAIN_SEPARATOR = ' ';
|
const MAIN_SEPARATOR = ' ';
|
||||||
const DATE_FORMAT = 'd/m/Y';
|
const DATE_FORMAT = 'd/m/Y';
|
||||||
@@ -130,15 +130,10 @@ class Databap extends PhpObject
|
|||||||
const ART_TYPE = 'a';
|
const ART_TYPE = 'a';
|
||||||
const DOC_TYPE = 'd';
|
const DOC_TYPE = 'd';
|
||||||
const TABLE_TYPE = 't';
|
const TABLE_TYPE = 't';
|
||||||
public static $TYPES = array( self::CODE_TYPE =>array('table' => self::CODE_TABLE, 'title' => 'Code'),
|
|
||||||
self::PROC_TYPE =>array('table' => self::PROC_TABLE, 'title' => 'Procédure'),
|
|
||||||
self::ART_TYPE =>array('table' => self::ART_TABLE, 'title' => 'Article'),
|
|
||||||
self::DOC_TYPE =>array('table' => self::DOC_TABLE, 'title' => 'Documentation'),
|
|
||||||
self::TABLE_TYPE=>array('table' => self::TABL_TABLE, 'title' => 'Table'));
|
|
||||||
public static $HASH_TO_PAGE = array(self::CODE_TYPE=>'code', 'code'=>'code',
|
public static $HASH_TO_PAGE = array(self::CODE_TYPE=>'code', 'code'=>'code',
|
||||||
self::PROC_TYPE=>'proc', 'proc'=>'proc', 'procedure'=>'proc',
|
self::PROC_TYPE=>'procedure', 'proc'=>'procedure', 'procedure'=>'procedure',
|
||||||
self::TABLE_TYPE=>'table', 'table'=>'table',
|
self::TABLE_TYPE=>'table', 'table'=>'table',
|
||||||
self::DOC_TYPE=>'doc', 'doc'=>'doc', 'documentation'=>'doc',
|
self::DOC_TYPE=>'doc', 'documentation'=>'doc', 'doc'=>'doc',
|
||||||
self::ART_TYPE=>'article', 'art'=>'article', 'article'=>'article',
|
self::ART_TYPE=>'article', 'art'=>'article', 'article'=>'article',
|
||||||
'list'=>'list', 'liste'=>'list',
|
'list'=>'list', 'liste'=>'list',
|
||||||
'chat'=>'chat',
|
'chat'=>'chat',
|
||||||
@@ -148,7 +143,16 @@ class Databap extends PhpObject
|
|||||||
'accueil'=>'welcome',
|
'accueil'=>'welcome',
|
||||||
'erreur'=>'error',
|
'erreur'=>'error',
|
||||||
'logout'=>'logout');
|
'logout'=>'logout');
|
||||||
|
public static $TYPES = array( self::CODE_TYPE =>array('table' => self::CODE_TABLE, 'title' => 'Code'),
|
||||||
|
self::PROC_TYPE =>array('table' => self::PROC_TABLE, 'title' => 'Procédure'),
|
||||||
|
self::ART_TYPE =>array('table' => self::ART_TABLE, 'title' => 'Article'),
|
||||||
|
self::DOC_TYPE =>array('table' => self::DOC_TABLE, 'title' => 'Documentation'),
|
||||||
|
self::TABLE_TYPE=>array('table' => self::TABL_TABLE, 'title' => 'Table'));
|
||||||
|
public static $PAGE_TITLES = array( 'code'=>'Code', 'chat'=>'Chat', 'doc'=>'Documentation', 'error'=>'Page introuvable',
|
||||||
|
'list'=>'La liste', 'options'=>'Paramètres', 'procedure'=>'Procédure', 'profile'=>'Profil',
|
||||||
|
'search'=>'Recherche', 'welcome'=>'Bienvenue', 'table'=>'Table', 'article'=>'Article de blog',
|
||||||
|
'logout'=>'Déconnexion');
|
||||||
|
|
||||||
//Doc constants
|
//Doc constants
|
||||||
const DOC_FOLDER = 'docs/';
|
const DOC_FOLDER = 'docs/';
|
||||||
const DOC_TMP_FOLDER = 'docs/tmp/';
|
const DOC_TMP_FOLDER = 'docs/tmp/';
|
||||||
@@ -274,32 +278,38 @@ class Databap extends PhpObject
|
|||||||
return $asOptions;
|
return $asOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getTypeInfo($sInfo='', $sType='')
|
public static function getTypeInfo($oInfo=array(), $sType='')
|
||||||
{
|
{
|
||||||
if($sType!='')
|
if($sType!='')
|
||||||
{
|
{
|
||||||
if($sType!='' && !array_key_exists($sType, self::$TYPES)) $this->addError('Type "'.$sType.'" inconnu');
|
if($sType!='' && !array_key_exists($sType, self::$TYPES)) $this->addError('Type "'.$sType.'" inconnu');
|
||||||
else $asTypeInfo = array($sType=>self::$TYPES[$sType]);
|
else $asResult = array($sType=>self::$TYPES[$sType]);
|
||||||
}
|
}
|
||||||
else $asTypeInfo = self::$TYPES;
|
else $asResult = self::$TYPES;
|
||||||
|
|
||||||
if($sInfo!='')
|
//info
|
||||||
|
if(is_string($oInfo)) $oInfo = array($oInfo);
|
||||||
|
$bUnique = (count($oInfo)==1);
|
||||||
|
if(!empty($oInfo))
|
||||||
{
|
{
|
||||||
foreach($asTypeInfo as $sType => $asInfo)
|
foreach($asResult as $sType=>$asTypeInfo)
|
||||||
{
|
{
|
||||||
if(!array_key_exists($sInfo, $asInfo)) $this->addError('Info "'.$sInfo.'" inconnue');
|
$asResult[$sType] = array();
|
||||||
else $asTypeInfo[$sType] = $asInfo[$sInfo];
|
foreach($oInfo as $sInfo)
|
||||||
|
{
|
||||||
|
if(!array_key_exists($sInfo, $asTypeInfo)) $this->addError('Info "'.$sInfo.'" inconnue');
|
||||||
|
else $asResult[$sType][$sInfo] = $asTypeInfo[$sInfo];
|
||||||
|
}
|
||||||
|
if($bUnique) $asResult[$sType] = $asResult[$sType][$sInfo];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $asTypeInfo;
|
return $asResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getPageTitles($sPage='')
|
private function getPageTitles($sPage='')
|
||||||
{
|
{
|
||||||
$asPageTitles = array( 'code'=>'Code', 'chat'=>'Chat', 'doc'=>'Documentation', 'error'=>'Page introuvable',
|
$asPageTitles = self::$PAGE_TITLES;
|
||||||
'list'=>'La liste', 'options'=>'Paramètres', 'proc'=>'Procédure', 'profile'=>'Profil',
|
|
||||||
'search'=>'Recherche', 'welcome'=>'Bienvenue', 'table'=>'Table ECC / BW', 'article'=>'Blog SAP', 'logout'=>'Déconnexion');
|
|
||||||
if($sPage!='' && !array_key_exists($sPage, $asPageTitles)) $this->addError('Page "'.$sPage.'" inconnu');
|
if($sPage!='' && !array_key_exists($sPage, $asPageTitles)) $this->addError('Page "'.$sPage.'" inconnu');
|
||||||
return $sPage==''?$asPageTitles:$asPageTitles[$sPage];
|
return $sPage==''?$asPageTitles:$asPageTitles[$sPage];
|
||||||
}
|
}
|
||||||
@@ -841,7 +851,7 @@ class Databap extends PhpObject
|
|||||||
public function addDoc($asPost)
|
public function addDoc($asPost)
|
||||||
{
|
{
|
||||||
//Previous Doc Id
|
//Previous Doc Id
|
||||||
$iPrevDocId = $asPost['doc_id'];
|
$iPrevDocId = array_key_exists('doc_id', $asPost)?$asPost['doc_id']:0;
|
||||||
$bCreation = ($iPrevDocId==0);
|
$bCreation = ($iPrevDocId==0);
|
||||||
|
|
||||||
//User
|
//User
|
||||||
@@ -856,7 +866,7 @@ class Databap extends PhpObject
|
|||||||
foreach($asPost as $sFormId=>$sValue)
|
foreach($asPost as $sFormId=>$sValue)
|
||||||
{
|
{
|
||||||
preg_match($sImagePattern, $sFormId, $asMatches);
|
preg_match($sImagePattern, $sFormId, $asMatches);
|
||||||
if($asMatches['doc_info'] == 'name' || $asMatches['doc_info'] == 'desc')
|
if(!empty($asMatches) && ($asMatches['doc_info'] == 'name' || $asMatches['doc_info'] == 'desc'))
|
||||||
{
|
{
|
||||||
$asDocs[$asMatches['doc_id']][$asMatches['doc_info']] = $sValue;
|
$asDocs[$asMatches['doc_id']][$asMatches['doc_info']] = $sValue;
|
||||||
}
|
}
|
||||||
@@ -1106,7 +1116,7 @@ class Databap extends PhpObject
|
|||||||
return $asCode;
|
return $asCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getProcInfo($iProcId)
|
private function getProcedureInfo($iProcId)
|
||||||
{
|
{
|
||||||
$asProc = $this->oMySql->selectRow(self::PROC_TABLE, $iProcId);
|
$asProc = $this->oMySql->selectRow(self::PROC_TABLE, $iProcId);
|
||||||
$asProc['title'] = self::getDescriptionFormat($asProc['title']);
|
$asProc['title'] = self::getDescriptionFormat($asProc['title']);
|
||||||
@@ -1896,7 +1906,7 @@ class Databap extends PhpObject
|
|||||||
break;
|
break;
|
||||||
case self::MESSAGE_ADD_PROC:
|
case self::MESSAGE_ADD_PROC:
|
||||||
case self::MESSAGE_EDIT_PROC:
|
case self::MESSAGE_EDIT_PROC:
|
||||||
$asProc = $this->getProcInfo($asMessages['messages'][$iMessageId]['message']);
|
$asProc = $this->getProcedureInfo($asMessages['messages'][$iMessageId]['message']);
|
||||||
$asMessages['messages'][$iMessageId]['description'] = $asProc['title'];
|
$asMessages['messages'][$iMessageId]['description'] = $asProc['title'];
|
||||||
break;
|
break;
|
||||||
case self::MESSAGE_ADD_DOC:
|
case self::MESSAGE_ADD_DOC:
|
||||||
@@ -2223,46 +2233,21 @@ class Databap extends PhpObject
|
|||||||
$sIdUserColFull = MySqlManager::getId(self::USER_TABLE, true);
|
$sIdUserColFull = MySqlManager::getId(self::USER_TABLE, true);
|
||||||
$sLedColFull = MySqlManager::getFullColumnName(self::CODE_TABLE, 'led') ;
|
$sLedColFull = MySqlManager::getFullColumnName(self::CODE_TABLE, 'led') ;
|
||||||
|
|
||||||
//Get code Ids
|
|
||||||
$asInfo = array('select'=>array("MAX($sIdCodeCol) AS id_item"), //selecting last version among codes having the same refer_id
|
|
||||||
'from'=>self::CODE_TABLE,
|
|
||||||
'groupBy'=>array('refer_id'),
|
|
||||||
'orderBy'=>array('id_item'=>'desc'));
|
|
||||||
$asItemIds[Databap::CODE_TYPE] = $this->oMySql->selectRows($asInfo);
|
|
||||||
|
|
||||||
//get Proc Ids
|
|
||||||
$asInfo = array('select'=>array("MAX($sIdProcCol) AS id_item"),
|
|
||||||
'from'=>self::PROC_TABLE,
|
|
||||||
'groupBy'=>array('refer_id'),
|
|
||||||
'orderBy'=>array('id_item'=>'desc'));
|
|
||||||
$asItemIds[Databap::PROC_TYPE] = $this->oMySql->selectRows($asInfo);
|
|
||||||
|
|
||||||
//get Article Ids
|
|
||||||
$asInfo = array('select'=>array($sIdArtCol." AS id_item"),
|
|
||||||
'from'=>self::ART_TABLE,
|
|
||||||
'orderBy'=>array('id_item'=>'desc'));
|
|
||||||
$asItemIds[Databap::ART_TYPE] = $this->oMySql->selectRows($asInfo);
|
|
||||||
|
|
||||||
//Get documentation
|
|
||||||
$asInfo = array('select'=>array("MAX($sIdDocCol) AS id_item"), //selecting last version among docs having the same refer_id
|
|
||||||
'from'=>self::DOC_TABLE,
|
|
||||||
'groupBy'=>array('refer_id'),
|
|
||||||
'orderBy'=>array('id_item'=>'desc'));
|
|
||||||
$asItemIds[Databap::DOC_TYPE] = $this->oMySql->selectRows($asInfo);
|
|
||||||
|
|
||||||
//Get tables
|
|
||||||
$asInfo = array('select'=>array("MAX($sIdTableCol) AS id_item"), //selecting last version among tables having the same refer_id
|
|
||||||
'from'=>self::TABL_TABLE,
|
|
||||||
'groupBy'=>array('refer_id'),
|
|
||||||
'orderBy'=>array('id_item'=>'desc'));
|
|
||||||
$asItemIds[Databap::TABLE_TYPE] = $this->oMySql->selectRows($asInfo);
|
|
||||||
|
|
||||||
//Build code info structure
|
|
||||||
//TODO phrases for all item types?
|
//TODO phrases for all item types?
|
||||||
$asUsers = $asCode = $asItemList = array();
|
$asUsers = $asCode = $asItemList = array();
|
||||||
foreach($asItemIds as $sType=>$asTypedItemIds)
|
$asTypes = $this->getTypeInfo('table');
|
||||||
|
foreach($asTypes as $sType=>$sTable)
|
||||||
{
|
{
|
||||||
$asTypedItemIds = array_filter($asTypedItemIds); //null value returned from query (MAX(...))
|
$sTableIdCol = MySqlManager::getId($sTable);
|
||||||
|
|
||||||
|
//selecting last version among codes having the same refer_id
|
||||||
|
$asInfo = array('select' => array("MAX({$sTableIdCol}) AS id_item"),
|
||||||
|
'from' => $sTable,
|
||||||
|
'groupBy' => array(($sType==self::ART_TYPE)?$sTableIdCol:'refer_id'), //except for articles
|
||||||
|
'orderBy' => array('id_item'=>'desc'));
|
||||||
|
|
||||||
|
//Build code info structure
|
||||||
|
$asTypedItemIds = array_filter($this->oMySql->selectRows($asInfo)); //null value returned from query (MAX(...))
|
||||||
foreach($asTypedItemIds as $iItemId)
|
foreach($asTypedItemIds as $iItemId)
|
||||||
{
|
{
|
||||||
$asItem = call_user_func(array($this, 'get'.ucfirst($this->getPagesFromHash($sType)).'Info'), $iItemId);
|
$asItem = call_user_func(array($this, 'get'.ucfirst($this->getPagesFromHash($sType)).'Info'), $iItemId);
|
||||||
|
|||||||
@@ -247,9 +247,9 @@ class ToolBox
|
|||||||
|
|
||||||
//Phase 1 : Identify internal links : merge cases /#code-1 and code 1, destroy link.
|
//Phase 1 : Identify internal links : merge cases /#code-1 and code 1, destroy link.
|
||||||
$asPatterns = array();
|
$asPatterns = array();
|
||||||
foreach(Databap::$HASH_TO_PAGE as $sAlt=>$sFinal)
|
foreach(Databap::$HASH_TO_PAGE as $sAlt=>$sPage)
|
||||||
{
|
{
|
||||||
$asPatterns['`(^|\ )(https?://|)'.$sServerPath.'/?\#'.$sAlt.'\-([\d]+)`sui'] = '$1$4'.$sFinal.' $3';
|
$asPatterns['`(^|\ )(https?://|)'.$sServerPath.'/?\#'.$sAlt.'\-([\d]+)`sui'] = '$1$4'.$sPage.' $3';
|
||||||
}
|
}
|
||||||
$sText = preg_replace(array_keys($asPatterns), array_values($asPatterns), $sText);
|
$sText = preg_replace(array_keys($asPatterns), array_values($asPatterns), $sText);
|
||||||
|
|
||||||
@@ -260,9 +260,14 @@ class ToolBox
|
|||||||
|
|
||||||
//Phase 3: rebuild link
|
//Phase 3: rebuild link
|
||||||
$asPatterns = array();
|
$asPatterns = array();
|
||||||
foreach(Databap::$HASH_TO_PAGE as $sAlt=>$sFinal)
|
foreach(Databap::$HASH_TO_PAGE as $sAlt=>$sPage)
|
||||||
{
|
{
|
||||||
$asPatterns['`(^|\ )'.$sAlt.'\ ([\d]+)(\ |$)`sui'] = '$1<a href="#'.$sFinal.'-$2" target="_blank" class="internal_link round"><i class="fa fa-inline fa-c-'.$sFinal.'"></i>'.$sFinal.' $2</a>$3';
|
if(mb_strlen($sAlt)>1)
|
||||||
|
{
|
||||||
|
$sTitle = Databap::$PAGE_TITLES[$sPage];
|
||||||
|
$asPatterns['`(^|\ )'.$sAlt.'\ ([\d]+)(\ |$)`sui'] = '$1<a href="#'.$sPage.'-$2" target="_blank" class="internal_link round"><i class="fa fa-inline fa-c-'.$sPage.'"></i>'.$sTitle.' n°$2</a>$3';
|
||||||
|
if($sPage=='table') $asPatterns['`(^|\ )'.$sAlt.'\ ([_A-Z0-9]+)(\ |$)`su'] = '$1<a href="#'.$sPage.'-$2" target="_blank" class="internal_link round"><i class="fa fa-inline fa-c-'.$sPage.'"></i>'.$sTitle.' $2</a>$3';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$sText = preg_replace(array_keys($asPatterns), array_values($asPatterns), $sText);
|
$sText = preg_replace(array_keys($asPatterns), array_values($asPatterns), $sText);
|
||||||
|
|
||||||
|
|||||||
1
jquery/databap.js
vendored
1
jquery/databap.js
vendored
@@ -653,6 +653,7 @@ function Databap()
|
|||||||
this.getInternalLink = function(sPage, iItemId, bAbsolute)
|
this.getInternalLink = function(sPage, iItemId, bAbsolute)
|
||||||
{
|
{
|
||||||
bAbsolute = bAbsolute || false;
|
bAbsolute = bAbsolute || false;
|
||||||
|
if(sPage.length==1) sPage = self.vars.hash_to_page[sPage]; //if hash is provided instead of page
|
||||||
return (bAbsolute?self.vars.serv_name:'')+'#'+sPage+((iItemId>0 || iItemId!='')?'-'+escape($.trim(iItemId)):'');
|
return (bAbsolute?self.vars.serv_name:'')+'#'+sPage+((iItemId>0 || iItemId!='')?'-'+escape($.trim(iItemId)):'');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -109,7 +109,6 @@ function loadDoc(iDocId, fOnSuccess)
|
|||||||
{id:iDocId},
|
{id:iDocId},
|
||||||
'json'
|
'json'
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveDoc()
|
function saveDoc()
|
||||||
@@ -122,7 +121,11 @@ function saveDoc()
|
|||||||
databap.getMainElem('#doc_form'),
|
databap.getMainElem('#doc_form'),
|
||||||
function(data)
|
function(data)
|
||||||
{
|
{
|
||||||
if(data.result == 'success') databap.goToInternalLink('doc', data.doc_id);
|
if(data.result == 'success')
|
||||||
|
{
|
||||||
|
databap.tmp('started', false);
|
||||||
|
databap.goToInternalLink('doc', data.doc_id);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
'json'
|
'json'
|
||||||
|
|||||||
@@ -65,10 +65,7 @@ function Table(oTable)
|
|||||||
$('#validation').addButton('dummy', '', function(){}, this.ACTION_BTN_ID, '', this.ACTION_BTN_ID);
|
$('#validation').addButton('dummy', '', function(){}, this.ACTION_BTN_ID, '', this.ACTION_BTN_ID);
|
||||||
this.$Button = databap.tmp(this.ACTION_BTN_ID);
|
this.$Button = databap.tmp(this.ACTION_BTN_ID);
|
||||||
|
|
||||||
if(this.iTableId>0 || this.sTableName!='')
|
if(this.iTableId>0 || this.sTableName!='') this.applyTableInfo();
|
||||||
{
|
|
||||||
this.applyTableInfo();
|
|
||||||
}
|
|
||||||
else this.setDisplay(this.DISPLAY_EDIT);
|
else this.setDisplay(this.DISPLAY_EDIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user