<?php
class native {
private $_variables = array();
private $_cycle = array();
/**
* Fetch
* @param string $template
* @return string
*/
public function fetch($template) {
if (!file_exists($template)) {
return "Ошибка. {$template} не сущевствует";
}
if (!is_readable($template)) {
return "Ошибка. {$template} не доступен для чтения";
}
extract($this->_variables);
ob_start();
require($template);
$return = ob_get_contents();
ob_end_clean();
return $return;
}
public function display($template) {
echo $this->fetch($template);
return $this;
}
/**
* Assign a variable
* @return native
*/
public function assign($variable, $value = null) {
if (is_array($variable)) {
foreach ($variable as $akey => $avalue) {
if (array_search($akey, array("template")) !== false) {
continue;
}
$this->$akey = $avalue;
}
return $this;
}
$this->$variable = $value;
return $this;
}
public function fckEditor($name, $value = "", $width = "100%", $height = "450px", $toolbarSet = false) {
$fckForm = new fckEditor($name);
$fckForm->Value = $value;
$fckForm->Width = $width;
$fckForm->Height = $height;
$toolbarSet && $fckForm->ToolbarSet = $toolbarSet;
$return = "<noscript><textarea name=\"{$name}\" style=\"width: {$width}; height: {$height}\">{$value}</textarea></noscript>".$fckForm->createHtml();
return $return;
}
public function cycle(array $values, $name = "_default") {
if (!isset($this->_cycle[$name])) {
$this->_cycle[$name] = 0;
}
echo $values[($this->_cycle[$name] % sizeof($values))];
$this->_cycle[$name]++;
return true;
}
/**
* Set atrributes by assign;
* @param string $variable
* @param mixed $value
*/
function __set($variable, $value) {
$this->_variables[$variable] = $value;
$this->$variable = $value;
}
function __construct() {
$this->currentLanguage = core::getInstance()->languageInterface()->getCurrentLanguage();
$this->currentModule = core::getInstance()->modulesInterface()->currentModule;
$this->isIndex = core::getInstance()->urlInterface()->file() == EASYCMS_DEFAULT_REQUEST_FILE
&& !sizeof(core::getInstance()->urlInterface()->folders())
&& !sizeof(core::getInstance()->urlInterface()->params())
&& core::getInstance()->modulesInterface()->currentModule == EASYCMS_DEFAULT_MODULE;
}
function widget($name, $params = array()) {
// Проверяем наличие параметров
if (!preg_match("/^[a-z0-9_]+$/i",$name)) {
return "widget: 'name' parametr is incorrect";
}
$fNameToInludePlugin = EASYCMS_WIDGETS_DIR.(substr(EASYCMS_WIDGETS_DIR, -1, 1) != "/" ? "/" : "").$name."/index.php";
if (!file_exists($fNameToInludePlugin)) {
return "widget: ".$name." missing";
}
require_once($fNameToInludePlugin);
$pluginClass = $name."_widget";
if (!class_exists($pluginClass)) {
return "widget: broken (no class) [{$pluginClass}]";
}
$plugin = new $pluginClass();
return $plugin->start($params);
}
/* vim: set expandtab: */
}
?>