This file is part of YSM libagregator.
YSM libagregator is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
YSM libagregator is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with YSM libagregator. If not, see .
*/
/**
* @author Yan Morin
* @license AGPL
* @creation 2008-06-09
*/
/**
* List of define constant
* @var array
*/
$GLOBALS['agregatorConfDefineArray'] = array(
'MAX_NEWS_DISPLAYED'=>30,
'OUTPUT_FILE'=>'',
'OUTPUT_RSS_FILE'=>'',
'OUTPUT_HTML_FORMAT'=>'HTML',
'HTML_TITLE'=>'titre',
'HTML_DESCRIPTION'=>'description',
'HTML_LINK'=>'link',
'AGREGATOR_SHOULD_REWRITECONF'=>'0'
);
/**
* @param string $fileName output filename
* @param array $defineArray list of defineName => defineValue array
* @param array $tabFilArray tabFilInfo array of array
*/
function agregatorWriteConf($fileName, &$defineArray, &$tabFilArray) {
$fp = fopen($fileName,'wt');
fwrite($fp, " $defineValue) {
fwrite($fp, getPHPDefineString($defineName, $defineValue));
}
fwrite($fp, getPHPAffectationString('$tabFilInfo', $tabFilArray));
fwrite($fp, "?>\n");
fclose($fp);
}
function getPHPAffectationString($varName, &$mixed) {
return $varName . ' = ' . getPHPValueString($mixed).";\n";
}
function getPHPDefineString($defineName, $value) {
return 'define(\''.addslashes($defineName).'\',\''.addslashes($value).'\');'."\n";
}
/**
* function to create an array from PHP code
*/
function getPHPArrayString(&$arrayFrom) {
$returnString = 'array(';
$isFirst = true;
foreach($arrayFrom as $key => $value) {
if ($isFirst) { $isFirst = false; } else { $returnString .= ','; }
if (is_integer($key)) {
$returnString .= $key . ' => ' . getPHPValueString($value) . "\n";
} else {
$returnString .= '\''.stripslashes($key).'\' => '.getPHPValueString($value) . "\n";
}
}
$returnString .= ')';
return $returnString;
}
function getPHPValueString(&$mixed) {
$returnString = '';
if (is_array($mixed)) {
$returnString .= getPHPArrayString($mixed);
} elseif (is_integer($mixed)) {
$returnString .= $mixed;
} elseif (is_bool($mixed)) {
$returnString .= ($mixed) ? 'true' : 'false';
} else {
$returnString .= '\'' . addslashes($mixed). '\'';
}
return $returnString;
}
if (array_key_exists('gLang', $GLOBALS)) { $GLOBALS['gLang'] = $GLOBALS['agregatorDefaultLang']; }
if (array_key_exists('gLang', $GLOBALS) && in_array($gLang, array('en','fr'))) {
require_once 'lang_'.$gLang.'.php';
} else {
$GLOBALS['agregatorTrStrings'] = array();
}
function agregatorTr($string, $args = null) {
global $agregatorTrStrings;
if (array_key_exists($string, $agregatorTrStrings)) {
$string = $agregatorTrStrings[$string];
}
if ($args !== null) {
if (!is_array($args)) {
$args = array($args);
}
foreach($args as $index=>$value) {
// echo ($index+1) . ' ' . $value;
$string = str_replace('$'.($index+1), $value, $string);
}
}
return $string;
}
/**
* Echo a Define variable
* @param $str DEFINE name string (constant)
*/
function echoDefineHTMLInput($str, $default='') {
$value = defined($str) ? constant($str) : $default;
echo '
' . $str . '=
'."\n";
}
/**
* Get the list of configuration file
* @param string $dirpath dir where configuration file are written
* @return array configuration filenames or null on error
*/
function getConfigFileList($dirpath) {
$returnArray = array();
if (is_dir($dirpath)) {
if ($dh = opendir($dirpath)) {
while (($file = readdir($dh)) !== false) {
if ( is_writable($dirpath.'/'.$file) && substr($file,-4)=='.php' ) {
$returnArray[] = $file;
}
}
closedir($dh);
}
} else {
return FALSE;
}
return $returnArray;
}
?>