Skip to content

Commit

Permalink
Merge branch 'master' into 1.3b
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel DOUAT committed Jul 5, 2013
2 parents 0fad115 + b88af94 commit f884686
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 23 deletions.
19 changes: 18 additions & 1 deletion admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,23 @@
require_once 'libs/timply.php';
require_once 'libs/smartypants.php';

function writeConfigFile($newOptions)
{
$fileName = 'config.php';
$fileUri = '';
$configContent = file_get_contents($fileUri . $fileName);
foreach ($newOptions as $key => $value) {
list($type, $option) = explode(">", $key);
if (is_string($value)) {
$value = "'" . str_replace("'", "\'", $value) . "'";
}
$pattern = '/\$' . $type . '\[\'' . $option . '\'\]\s*=\s*[\'"]{0,1}.*[\'"]{0,1};/i';
$replace = '$' . $type . '[\'' . $option . '\'] = ' .$value . ';';
$configContent = preg_replace($pattern, $replace, $configContent);
}
file_put_contents($fileUri . $fileName, $configContent, LOCK_EX);
}

function editConfig($newConfig)
{
//on récupere config.php dans un tableau
Expand Down Expand Up @@ -55,7 +72,7 @@ function getUpdate()

if ($GLOBALS['system']['lastUpdate'] < $currentDate) {
$update = file_get_contents('http://q.uote.me/checkupdate.php?cliv=' . $GLOBALS['config']['appVers']);
editConfig(array('lastVersion' => $update, 'lastUpdate' => $currentDate));
writeConfigFile(array('system>lastVersion' => $update, 'system>lastUpdate' => $currentDate));
}

}
Expand Down
7 changes: 4 additions & 3 deletions installer/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,13 @@ function writeConfigFile($newOptions)
$fileUri = '../';
$configContent = file_get_contents($fileUri . $fileName);
foreach ($newOptions as $key => $value) {
$keys = explode(">", $key);
list($type, $option) = explode(">", $key);
//$keys = explode(">", $key);
if (is_string($value)) {
$value = "'" . str_replace("'", "\'", $value) . "'";
}
$pattern = '/\$' . $keys[0] . '\[\'' . $keys[1] . '\'\]\s*=\s*[\'"]{0,1}.*[\'"]{0,1};/i';
$replace = '$' . $keys[0] . '[\'' . $keys[1] . '\'] = ' .$value . ';';
$pattern = '/\$' . $type . '\[\'' . $option . '\'\]\s*=\s*[\'"]{0,1}.*[\'"]{0,1};/i';
$replace = '$' . $type . '[\'' . $option . '\'] = ' .$value . ';';
$configContent = preg_replace($pattern, $replace, $configContent);
}
file_put_contents($fileUri . $fileName, $configContent, LOCK_EX);
Expand Down
35 changes: 17 additions & 18 deletions libs/quoteme.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,19 +341,18 @@ private function selElements($opt = "")
}
if (!empty($opt['limit'])) {
if (strpos($opt['limit'], ',') !== FALSE) {
$limit = explode(',', $opt['limit']);
$limit[1] = ',' . $limit[1];
list($limitMin, $limitMax) = explode(',', $limit);
}
else {
$limit[0] = $opt['limit'];
$limitMin = $opt['limit'];
}
$limit = ' LIMIT ' . $limit[0] . $limit[1];
$limit = ' LIMIT ' . rtrim($limitMin . ',' .$limitMax, ',');
}
if (!empty($opt['sort'])) {
if ($opt['sort'] === 'random') $rand = ' JOIN ( SELECT FLOOR( COUNT( * ) * RAND( ) ) AS ValeurAleatoire FROM ' . self::$table . ' ) AS V ON ' . self::$table . '.id >= V.ValeurAleatoire';
if (strpos($opt['sort'], ',')) {
$sOpt = explode(',', $opt['sort']);
$sort = ' ORDER BY ' . $sOpt[0] . ' ' .$sOpt[1];
list($field, $order) = explode(',', $opt['sort']);
$sort = ' ORDER BY ' . $field . ' ' .$order;
}
}
$query = 'SELECT id, quote, author, source, tags, permalink, date FROM ' . self::$table . $rand . $where . $sort . $limit . ';';
Expand Down Expand Up @@ -439,23 +438,23 @@ private function editElements($elements)

/**
* Return WHERE of AND sql structure
* @param string $where sql field
* @param string $whereOpt where condition (ex like,lorem)
* @param string $field sql field
* @param string $string where condition (ex like,lorem)
* @param boolean $and if AND condition, set TRUE
* @return string sql structure
*/
private function constructWhere($where, $whereOpt, $and = FALSE)
private function constructWhere($field, $string, $and = FALSE)
{
$cond = ($and) ? 'AND' : 'WHERE';
$opt = explode(',', $whereOpt);
$opt[0] = str_replace('minus', '<', $opt[0]);
$opt[0] = str_replace('plus', '>', $opt[0]);
$opt[0] = str_replace('equal', '=', $opt[0]);
if ($opt[0] === 'like') {
$opt[0] = strtoupper($opt[0]);
$opt[1] = '%' . $opt[1] . '%';
$cond = ($and) ? 'AND' : 'WHERE';
list($test, $string) = explode(',', $string);
$test = str_replace('minus', '<', $test);
$test = str_replace('plus', '>', $test);
$test = str_replace('equal', '=', $test);
if ($test === 'like') {
$test = strtoupper($test);
$string = '%' . $string . '%';
}
return ' ' . $cond . ' ' .$where . ' ' .$opt[0] . ' "' . $opt[1] . '"';
return ' ' . $cond . ' ' .$field . ' ' .$test . ' "' . $string . '"';
}
/**
* SmallHash via shaarli (sebsauvage)
Expand Down
4 changes: 3 additions & 1 deletion parser/rss2.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ class rss2Parser

function __construct()
{
$this->timply = new timply('rss2.rss');
timply::setUri($GLOBALS['config']['themeDir']);
timply::setFileName('rss2.rss');
$this->timply = new timply();
}

public function parse($elements)
Expand Down

0 comments on commit f884686

Please sign in to comment.