5e93141b28
- barra de loading funcional - criação de diretorios e arquivos apontados pela estrutura do módulo selecionado
167 linhas
5.2 KiB
PHP
167 linhas
5.2 KiB
PHP
<?php
|
|
/**
|
|
* Created on 01/09/2009
|
|
*
|
|
* Class that contains the methods to manipulate Modules
|
|
* @author Felipe Nascimento (felipenmoura@gmail.com)
|
|
* @author Jaydson Gomes (jaydson@thewebmind.org)
|
|
* @version 1.0.0
|
|
*
|
|
*/
|
|
|
|
class Module
|
|
{
|
|
public $name;
|
|
public $version;
|
|
public $fullName;
|
|
public $language;
|
|
public $details;
|
|
public $authors;
|
|
public $description;
|
|
public $date;
|
|
public $thumb;
|
|
public $license;
|
|
private $module;
|
|
public $dependences; // scripts, styles and options the current module has/needs
|
|
public $configPage;
|
|
private $moduleData; // the options or additional information added to the loaded module
|
|
|
|
protected function load($m)
|
|
{
|
|
GLOBAL $_MIND;
|
|
if($this->moduleExists($m))
|
|
{
|
|
$m= $_MIND['rootDir'].$_MIND['moduleDir'].'/'.$m.'/';
|
|
if(($confXML= @simplexml_load_file($m.'conf.xml')) && $infoXML= @simplexml_load_file($m.'info.xml'))
|
|
{
|
|
// creating the info array
|
|
$ar= Array();
|
|
$ar['name']= (string)$infoXML->name['value'];
|
|
$ar['fullName']= (string)$infoXML->fullName['value'];
|
|
$ar['language']= (string)$infoXML->language['value'];
|
|
$ar['details']= Array();
|
|
foreach($infoXML->details->detail as $d)
|
|
array_push($ar['details'], Array('name'=>(string)$d['name'], 'value'=>(string)$d['value']));
|
|
$ar['authors']= Array();
|
|
foreach($infoXML->authors->author as $d)
|
|
array_push($ar['authors'], Array('name'=>(string)$d['value'], 'email'=>(string)$d['email']));
|
|
//$ar['details']= $infoXML->details['value'];
|
|
|
|
$ar['version']= (string)$infoXML->version['value'];
|
|
$ar['description']= (string)$infoXML->description['value'];
|
|
$ar['date']= (string)$infoXML->date['value'];
|
|
$ar['thumb']= (string)$infoXML->thumb['value'];
|
|
$ar['license']= (string)$infoXML->license['value'];
|
|
$ar['configPage']= (string)$confXML->config['src'];
|
|
|
|
// creating the config array
|
|
$ar['dependences']= Array();
|
|
$ar['dependences']['scripts']= Array();
|
|
$ar['dependences']['styles']= Array();
|
|
|
|
foreach($confXML->scripts->js as $d)
|
|
array_push($ar['dependences']['scripts'],
|
|
(string)$d['src']);
|
|
foreach($confXML->styles->css as $d)
|
|
array_push($ar['dependences']['styles'],
|
|
(string)$d['src']);
|
|
|
|
$this->populate($ar);
|
|
//$this->populate($_MIND['fw']->objectToArray($infoXML));
|
|
}else{
|
|
echo "Mind.Dialog.ShowError(".JSON_encode($_MIND['fw']->errorOutput(7)).")";
|
|
}
|
|
}else{
|
|
echo "Mind.Dialog.ShowError(".JSON_encode($_MIND['fw']->errorOutput(7)).")";
|
|
}
|
|
return $this;
|
|
}
|
|
public function populate($ar)
|
|
{
|
|
GLOBAL $_MIND;
|
|
$this->name = $_MIND['fw']->getEncoded($ar['name']);
|
|
$d= $_MIND['moduleDir'].'/'.$this->name.'/data/';
|
|
$this->version = $ar['version'];
|
|
$this->fullName = $_MIND['fw']->filter($ar['fullName']);
|
|
$this->language = $_MIND['fw']->filter($ar['language']);
|
|
$this->description = $_MIND['fw']->filter($ar['description']);
|
|
$this->date = $ar['date'];
|
|
$this->thumb = $d.$_MIND['fw']->getEncoded($ar['thumb']);
|
|
$this->license = $d.$_MIND['fw']->getEncoded($ar['license']);
|
|
$this->authors = Array();
|
|
for($i=0; $i<sizeof($ar['authors']); $i++)
|
|
{
|
|
$this->authors[$i]= $ar['authors'][$i];
|
|
}
|
|
$this->details = Array();
|
|
for($i=0; $i<sizeof($ar['details']); $i++)
|
|
{
|
|
$this->details[$i]= Array('name'=>$ar['details'][$i]['name'], 'value'=>$ar['details'][$i]['value']);
|
|
}
|
|
$this->dependences = Array();
|
|
if(isset($ar['dependences']))
|
|
{
|
|
if(isset($ar['dependences']['scripts']))
|
|
for($i=0; $i<sizeof($ar['dependences']['scripts']); $i++)
|
|
{
|
|
$this->dependences['scripts'][$i]= $d.$_MIND['fw']->getEncoded($ar['dependences']['scripts'][$i]);
|
|
}
|
|
if(isset($ar['dependences']['styles']))
|
|
for($i=0; $i<sizeof($ar['dependences']['styles']); $i++)
|
|
{
|
|
$this->dependences['styles'][$i]= $d.$_MIND['fw']->getEncoded($ar['dependences']['styles'][$i]);
|
|
}
|
|
}
|
|
$this->configPage= $ar['configPage'];
|
|
return $this;
|
|
}
|
|
public function moduleExists($m)
|
|
{
|
|
GLOBAL $_MIND;
|
|
return file_exists($_MIND['rootDir'].$_MIND['moduleDir'].'/'.$m.'/conf.xml');
|
|
}
|
|
|
|
public function loadModule($k)
|
|
{
|
|
GLOBAL $_MIND;
|
|
$mDir= $_MIND['rootDir'].$_MIND['moduleDir'].'/';
|
|
include($mDir.'module_interface.php');
|
|
include($mDir.strtolower($this->name).'/'.$this->name.'.php');
|
|
$this->module= new $this->name($k);
|
|
}
|
|
|
|
public function __construct($module= false)
|
|
{
|
|
GLOBAL $_MIND;
|
|
$this->authors = Array();
|
|
$this->details = Array();
|
|
$this->dependences = Array();
|
|
if($module)
|
|
{
|
|
$this->load($module);
|
|
}
|
|
}
|
|
|
|
|
|
/***********************/
|
|
|
|
public function structure($m, $p)
|
|
{
|
|
GLOBAL $_MIND;
|
|
$x= $this->module->structure();
|
|
|
|
if(!file_exists($_MIND['rootDir'].$p.$x))
|
|
mkdir($_MIND['rootDir'].$p.$x, 0777);
|
|
|
|
$m= $_MIND['rootDir'].$m.$x;
|
|
$p= $_MIND['rootDir'].$p.$x;
|
|
|
|
if(!$_MIND['fw']->copyDir($m, $p, true))
|
|
return false;
|
|
}
|
|
public function neededFiles($d)
|
|
{
|
|
$m= $this->module->neededFiles();
|
|
}
|
|
}
|
|
?>
|