2015-05-05 03:00:01 +02:00
|
|
|
<?php defined('BLUDIT') or die('Bludit CMS.');
|
|
|
|
|
|
|
|
class fileContent
|
|
|
|
{
|
|
|
|
public $vars;
|
|
|
|
|
2015-06-30 05:23:29 +02:00
|
|
|
function __construct($path)
|
2015-05-05 03:00:01 +02:00
|
|
|
{
|
2015-06-30 05:23:29 +02:00
|
|
|
if($this->build($path)===false) {
|
2015-05-05 03:00:01 +02:00
|
|
|
$this->vars = false;
|
2015-06-26 06:31:53 +02:00
|
|
|
}
|
2015-05-05 03:00:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return true if valid
|
|
|
|
public function isValid()
|
|
|
|
{
|
|
|
|
return($this->vars!==false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getField($field)
|
|
|
|
{
|
|
|
|
if(isset($this->vars[$field])) {
|
|
|
|
return $this->vars[$field];
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// $notoverwrite true if you don't want to replace the value if are set previusly
|
|
|
|
public function setField($field, $value, $overwrite=true)
|
|
|
|
{
|
|
|
|
if($overwrite || empty($this->vars[$field])) {
|
|
|
|
$this->vars[$field] = $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-30 05:23:29 +02:00
|
|
|
private function build($path)
|
2015-05-05 03:00:01 +02:00
|
|
|
{
|
2015-06-30 05:23:29 +02:00
|
|
|
if( !Sanitize::pathFile($path, 'index.txt') ) {
|
2015-05-05 03:00:01 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$tmp = 0;
|
2015-06-30 05:23:29 +02:00
|
|
|
$lines = file($path.'index.txt');
|
2015-05-05 03:00:01 +02:00
|
|
|
foreach($lines as $lineNumber=>$line)
|
|
|
|
{
|
|
|
|
$parts = array_map('trim', explode(':', $line, 2));
|
|
|
|
|
|
|
|
// Lowercase variable
|
2015-05-31 03:06:55 +02:00
|
|
|
$parts[0] = Text::lowercase($parts[0]);
|
2015-05-05 03:00:01 +02:00
|
|
|
|
|
|
|
// If variables is content then break the foreach and process the content after.
|
|
|
|
if($parts[0]==='content')
|
|
|
|
{
|
|
|
|
$tmp = $lineNumber;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !empty($parts[0]) && !empty($parts[1]) ) {
|
|
|
|
// Sanitize all fields, except Content.
|
|
|
|
$this->vars[$parts[0]] = Sanitize::html($parts[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Process the content.
|
|
|
|
if($tmp!==0)
|
|
|
|
{
|
|
|
|
// Next line after "Content:" variable
|
|
|
|
$tmp++;
|
|
|
|
|
|
|
|
// Remove lines after Content
|
|
|
|
$output = array_slice($lines, $tmp);
|
|
|
|
|
|
|
|
if(!empty($parts[1])) {
|
|
|
|
array_unshift($output, "\n");
|
|
|
|
array_unshift($output, $parts[1]);
|
|
|
|
}
|
|
|
|
|
2015-06-26 06:31:53 +02:00
|
|
|
$implode = implode($output);
|
2015-06-28 01:28:22 +02:00
|
|
|
$this->vars['content'] = $implode;
|
2015-06-26 06:31:53 +02:00
|
|
|
|
|
|
|
// Sanitize content.
|
2015-06-28 01:28:22 +02:00
|
|
|
//$this->vars['content'] = Sanitize::html($implode);
|
2015-05-05 03:00:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-05-31 03:06:55 +02:00
|
|
|
}
|