Библиотека для cis, online, cms1

This commit is contained in:
Фёдор Подлеснов 2016-06-29 18:51:32 +03:00
commit 3c2e614d87
269 changed files with 39854 additions and 0 deletions

36
core/widgets/dialog.php Normal file
View file

@ -0,0 +1,36 @@
<?php
require_once 'core/widgets/widget.php';
/**
* Êëàññ äëÿ ñîçäàíèÿ äèàëîãîâûõ îêîí, òèïà ïîèñêà è íàñòðîéêè òàáëèöû
*/
class Dialog extends Widget
{
protected $title;
protected $action;
private $friend;
function setFriend(Widget $friend)
{
$this->friend = $friend->getName();
}
function getPostCode()
{
return $this->getName() . ".setFriend(" . $this->friend . ");";
}
function setTitle($title)
{
$this->title = $title;
}
function setAction($action)
{
$this->action = forceUrl($action);
}
}
?>

View file

@ -0,0 +1,39 @@
<?php
require_once 'core/widgets/listtable.php';
/**
* Êëàññ äëÿ ãåíåðàöèè òàáëèöû
*/
class FileBrowser extends ListTable
{
private $friend;
public function setType($type)
{
$this->setData('type', $type);
}
function setHeader($header)
{
$this->setData('table', $header);
}
function setFriend(Widget $friend)
{
$this->friend = $friend->getName();
}
function getPostCode()
{
if ($this->friend) {
return $this->getName() . ".setFriend(" . $this->friend . ");";
}
return "";
}
function postMake() {
$this->view->addScriptRaw($this->getPostCode(), true); // CompositeView
}
}
?>

View file

@ -0,0 +1,71 @@
<?php
require_once 'core/widgets/widget.php';
require_once 'core/functions.php';
/**
* Êëàññ äëÿ ãåíåðàöèè òàáëèöû
*/
class ListTable extends Widget // MenuTable
{
private $visible = null;
private $menu;
function setUp()
{
$this->menu = array();
$this->template = "table";
}
/**
* Óñòàíàâëèâàåò ôîðìàò òàáëèöû, ñòðóêòóðó $header ñì. table.js
*/
function setHeader($header)
{
$this->setData('table', $header);
}
function setView($visible)
{
$this->visible = $visible;
}
function setAction($action)
{
$this->setData('list', forceUrl($action));
}
function addMenuItem($href, $name, $to = 'item')
{
if ($href) {
if ($to === true) $to = 'all';
if (! isset($this->menu[$to])) {
$this->menu[$to] = array('group' => $to, 'all' => ($to == 'all'), 'items' => array());
}
$this->menu[$to]['items'][] = array('href' => $href, 'name' => $name);
}
}
function make(Controller $parent)
{
$view = $this->visible;
if (is_null($view)) {
$view = array('left' => key_values('key', $this->data['table']), 'right' => array());
}
$this->setData('setup', $view);
foreach ($this->menu as &$menu) {
foreach ($menu['items'] as &$item) {
$item['href'] = forceUrl($item['href']);
}
}
$this->setData('menu', array_keys($this->menu));
parent::make($parent);
$this->view->menus = $this->menu;
}
}
?>

38
core/widgets/menu.php Normal file
View file

@ -0,0 +1,38 @@
<?php
/**
* Список ссылок
*/
class SimpleMenu
{
private $items = array();
/**
* Добавление элемента меню
* @param $href Обьект ссылки или строка, ссылка должна быть сгенерирована при генерации страницы, т.к может зависеть от параметров
* которые могут измениться при создании страницы, поэтому передается ссылка на функцию (отложенная/ленивая ссылка)
* @param $name Подпись к ссылке
*/
function addMenuItem(/*. url .*/ $href,/*. string .*/ $name)
{
if($href) { // если ссылка пустая то элемент не добовляется
$this->items[] = array('href' => $href, 'name' => ucfirst($name)); // menu_item
}
}
/**
* Массив ссылок
* @return Массив
*/
function getItems()
{
foreach ($this->items as &$item) {
if (is_callable($item['href'])) {
$item['href'] = call_user_func($item['href']);
}
}
return $this->items;
}
}
?>

30
core/widgets/pagemenu.php Normal file
View file

@ -0,0 +1,30 @@
<?php
require_once 'core/widgets/widget.php';
require_once 'core/widgets/menu.php';
/**
* Êîìïîíåíò äëÿ ãåíåðàöèè ìåíþ
*/
class PageMenu extends Widget
{
private $menu;
function setUp()
{
$this->menu = new SimpleMenu();
$this->template = "menu";
}
function addMenuItem($name, $value)
{
$this->menu->addMenuItem($name, $value);
}
function postMake()
{
$this->view->items = $this->menu->getItems();
}
}
?>

16
core/widgets/pages.php Normal file
View file

@ -0,0 +1,16 @@
<?php
require_once 'core/widgets/widget.php';
/**
* Îòîáðàæåíèå ïîñòðàíè÷íîñòè
*/
class Pages extends Widget // Selector
{
function setUp()
{
$this->template = "pages";
}
}
?>

32
core/widgets/search.php Normal file
View file

@ -0,0 +1,32 @@
<?php
require_once 'core/widgets/dialog.php';
class SearchDialog extends Dialog
{
private $fields;
function setUp()
{
$this->template = "search";
}
function addFields($fields)
{
$this->fields = $fields;
}
function postMake()
{
$form = new TForm (); // Ïîêàçûâåì ôîðìó
$form->addFieldList ($this->fields); // Ðàçäåëèòü ôîðìó ïîèñêà è ðåäàêòèðîâàíèÿ
$this->view->form = $form;
$this->view->action = $this->action;
$this->view->title = $this->title;
$this->view->addScriptRaw($this->getPostCode(), true); // CompositeView
}
}
?>

20
core/widgets/setup.php Normal file
View file

@ -0,0 +1,20 @@
<?php
require_once 'core/widgets/dialog.php';
class SetupDialog extends Dialog
{
function setUp()
{
$this->template = "setup";
}
function postMake()
{
$this->view->action = $this->action;
$this->view->title = $this->title;
$this->view->addScriptRaw($this->getPostCode(), true); // CompositeView
}
}
?>

17
core/widgets/tree.php Normal file
View file

@ -0,0 +1,17 @@
<?php
require_once 'core/widgets/widget.php';
/**
* Êîìïîíåíò äëÿ ãåíåðàöèè Äåðåâà
*/
class Tree extends Widget
{
public function setUp()
{
$this->template = "tree";
}
// Äîáàâëåíèå âåòêè äåðåâà
}
?>

87
core/widgets/widget.php Normal file
View file

@ -0,0 +1,87 @@
<?php
require_once 'core/json.php';
function forceUrl($name)
{
if(is_callable($name)) {
return call_user_func($name);
}
return $name;
}
/**
* Êëàññ äëÿ ãåíåðàöèè è óïðàâëåíèÿ àêòèâíûìè êîìïîíåíòàìè ñòðàíèöû
* Êîìïîíåíò ñîñòîèò èç ñëåäóþùèõ ÷àñòåé
* PHP - Óïðàâëåíèå êîìïîíåíòîì (Ãåíåðàöèÿ, Èíèöèàëèçàöèÿ, Îáðàáîòêà ñîáûòèé)
* HTML - Íåîáõîäèìûå øàáëîíû
* CSS - Ñòèëè
* Javascript - Êëèåíòñêàÿ ÷àñòü óïðàâëåíèÿ êîìïîíåíòîì
*/
class Widget
{
private static $prefix = "_g";
private static $idx = 0;
private $id;
public $data = array();
public $view;
protected $template;
public function __construct()
{
$this->id = self::$idx ++;
$this->setUp();
}
function setUp()
{
}
public function getName()
{
return self::$prefix . intval($this->id);
}
/**
* Ãåíåðàöèÿ êîäà èíèöèàëèçàöèè êîìïîíåíòà íà ñòîðîíå êëèåíòà
*/
public function getCodeBefore()
{
$result =
// "alert('".$this->getName()."');" .
"var " . $this->getName() . " = new " . get_class($this) . "("
. json::encode($this->data) . ");";
return $result;
}
public function setData($name, $value)
{
$this->data[$name] = $value;
}
public function getCodeAfter()
{
return $this->getName() . ".appendTo(document.getElementById('" . $this->getName() . "'));\n";
}
public function postMake()
{
}
/**
* Ãåíåðàöèÿ êîìïîíåíòà
*/
function make(Controller $parent)
{
$this->view = $parent->getView($this->template); // Controller
$this->view->index = $this->getName();
foreach ($this->data as $name => $value) {
$this->view->set($name, $value);
}
$this->view->addScriptRaw($this->getCodeBefore(), true);
$this->postMake();
$this->view->addScriptRaw($this->getCodeAfter(), true);
}
}
?>