PageRenderTime 59ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/htmlresource.class.php

http://litepublisher.googlecode.com/
PHP | 873 lines | 836 code | 29 blank | 8 comment | 24 complexity | 73b812012369df899066bf91f6fd96f0 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-3.0
  1. <?php
  2. /**
  3. * Lite Publisher
  4. * Copyright (C) 2010 - 2013 Vladimir Yushko http://litepublisher.ru/ http://litepublisher.com/
  5. * Dual licensed under the MIT (mit.txt)
  6. * and GPL (gpl.txt) licenses.
  7. **/
  8. class thtmltag {
  9. public $tag;
  10. public function __construct($tag) { $this->tag = $tag; }
  11. public function __get($name) {
  12. return sprintf('<%1$s>%2$s</%1$s>', $this->tag, tlocal::i()->$name);
  13. }
  14. }//class
  15. class redtag extends thtmltag {
  16. public function __get($name) {
  17. return sprintf('<%1$s class="red">%2$s</%1$s>', $this->tag, tlocal::i()->$name);
  18. }
  19. }//class
  20. class tadminhtml {
  21. public static $tags = array('h1', 'h2', 'h3', 'h4', 'p', 'li', 'ul', 'strong', 'div', 'span');
  22. public $section;
  23. public $searchsect;
  24. public $ini;
  25. private $map;
  26. private $section_stack;
  27. public static function i() {
  28. $self = getinstance(__class__);
  29. if (count($self->ini) == 0) $self->load();
  30. return $self;
  31. }
  32. public static function getinstance($section) {
  33. $self = self::i();
  34. $self->section = $section;
  35. tlocal::i($section);
  36. return $self;
  37. }
  38. public function __construct() {
  39. $this->ini = array();
  40. $this->searchsect = array('common');
  41. tlocal::usefile('admin');
  42. }
  43. public function __get($name) {
  44. if (isset($this->ini[$this->section][$name])) return $this->ini[$this->section][$name];
  45. foreach ($this->searchsect as $section) {
  46. if (isset($this->ini[$section][$name])) return $this->ini[$section][$name];
  47. }
  48. if (in_array($name, self::$tags)) return new thtmltag($name);
  49. if (strend($name, 'red') && in_array(substr($name, 0, -3), self::$tags)) return new redtag($name);
  50. throw new Exception("the requested $name item not found in $this->section section");
  51. }
  52. public function __call($name, $params) {
  53. $s = $this->__get($name);
  54. if (is_object($s) && ($s instanceof thtmltag)) return sprintf('<%1$s>%2$s</%1$s>', $name, $params[0]);
  55. if ($name == 'h4error') return sprintf('<h4 class="red">%s</h4>', $params[0]);
  56. $args = isset($params[0]) && $params[0] instanceof targs ? $params[0] : new targs();
  57. return $this->parsearg($s, $args);
  58. }
  59. public function parsearg($s, targs $args) {
  60. if (!is_string($s)) $s = (string) $s;
  61. $theme = ttheme::i();
  62. // parse tags [form] .. [/form]
  63. if (is_int($i = strpos($s, '[form]'))) {
  64. $form = $theme->templates['content.admin.form'];
  65. $replace = substr($form, 0, strpos($form, '$items'));
  66. $s = substr_replace($s, $replace, $i, strlen('[form]'));
  67. }
  68. if ($i = strpos($s, '[/form]')) {
  69. $replace = substr($form, strrpos($form, '$items') + strlen('$items'));
  70. $s = substr_replace($s, $replace, $i, strlen('[/form]'));
  71. }
  72. if (preg_match_all('/\[(editor|checkbox|text|password|combo|hidden|submit|button|calendar|upload)(:|=)(\w*+)\]/i', $s, $m, PREG_SET_ORDER)) {
  73. foreach ($m as $item) {
  74. $type = $item[1];
  75. $name = $item[3];
  76. $varname = '$' . $name;
  77. //convert spec charsfor editor
  78. if (!in_array($type, array('checkbox', 'combo', 'calendar', 'upload'))) {
  79. if (isset($args->data[$varname])) {
  80. $args->data[$varname] = self::specchars($args->data[$varname]);
  81. } else {
  82. $args->data[$varname] = '';
  83. }
  84. }
  85. if ($type == 'calendar') {
  86. $tag = $this->getcalendar($name, $args->data[$varname]);
  87. } else {
  88. $tag = strtr($theme->templates["content.admin.$type"], array(
  89. '$name' => $name,
  90. '$value' => $varname
  91. ));
  92. }
  93. $s = str_replace($item[0], $tag, $s);
  94. }
  95. }
  96. $s = strtr($s, $args->data);
  97. return $theme->parse($s);
  98. }
  99. public function addsearch() {
  100. $a = func_get_args();
  101. foreach ($a as $sect) {
  102. if (!in_array($sect, $this->searchsect)) $this->searchsect[] = $sect;
  103. }
  104. }
  105. public function push_section($section) {
  106. if (!isset($this->section_stack)) $this->section_stack = array();
  107. $lang = tlocal::i();
  108. $this->section_stack[] = array(
  109. $this->section,
  110. $lang->section
  111. );
  112. $this->section = $section;
  113. $lang->section = $section;
  114. }
  115. public function pop_section() {
  116. $a = array_pop($this->section_stack);
  117. $this->section = $a[0];
  118. tlocal::i()->section = $a[1];
  119. }
  120. public static function specchars($s) {
  121. return strtr( htmlspecialchars($s), array(
  122. '"' => '&quot;',
  123. "'" =>'&#39;',
  124. '$' => '&#36;',
  125. '%' => '&#37;',
  126. '_' => '&#95;'
  127. ));
  128. }
  129. public function fixquote($s) {
  130. $s = str_replace("\\'", '\"', $s);
  131. $s = str_replace("'", '"', $s);
  132. return str_replace('\"', "'", $s);
  133. }
  134. public function load() {
  135. $filename = tlocal::getcachedir() . 'adminhtml';
  136. if (tfilestorage::loadvar($filename, $v) && is_array($v)) {
  137. $this->ini = $v + $this->ini;
  138. } else {
  139. $merger = tlocalmerger::i();
  140. $merger->parsehtml();
  141. }
  142. }
  143. public function loadinstall() {
  144. if (isset($this->ini['installation'])) return;
  145. tlocal::usefile('install');
  146. if( $v = parse_ini_file(litepublisher::$paths->languages . 'install.ini', true)) {
  147. $this->ini = $v + $this->ini;
  148. }
  149. }
  150. public static function getparam($name, $default) {
  151. return !empty($_GET[$name]) ? $_GET[$name] : (!empty($_POST[$name]) ? $_POST[$name] : $default);
  152. }
  153. public static function idparam() {
  154. return (int) self::getparam('id', 0);
  155. }
  156. public static function getadminlink($path, $params) {
  157. return litepublisher::$site->url . $path . litepublisher::$site->q . $params;
  158. }
  159. public static function getlink($url, $title) {
  160. return sprintf('<a href="%s%s">%s</a>', litepublisher::$site->url, $url, $title);
  161. }
  162. public static function array2combo(array $items, $selected) {
  163. $result = '';
  164. foreach ($items as $i => $title) {
  165. $result .= sprintf('<option value="%s" %s>%s</option>', $i, $i == $selected ? 'selected' : '', self::specchars($title));
  166. }
  167. return $result;
  168. }
  169. public static function getcombobox($name, array $items, $selected) {
  170. return sprintf('<select name="%1$s" id="%1$s">%2$s</select>', $name,
  171. self::array2combo($items, $selected));
  172. }
  173. public function adminform($tml, targs $args) {
  174. $args->items = $this->parsearg($tml, $args);
  175. return $this->parsearg(ttheme::i()->templates['content.admin.form'], $args);
  176. }
  177. public function inline($s) {
  178. return sprintf($this->ini['common']['inline'], $s);
  179. }
  180. public function getupload($name) {
  181. return $this->getinput('upload', $name, '', '');
  182. }
  183. public function getcheckbox($name, $value) {
  184. return $this->getinput('checkbox', $name, $value ? 'checked="checked"' : '', '$lang.' . $name);
  185. }
  186. public function getradioitems($name, array $items, $selected) {
  187. $result = '';
  188. $theme = ttheme::i();
  189. $tml = $theme->templates['content.admin.radioitems'];
  190. foreach ($items as $index => $value) {
  191. $result .= strtr($tml, array(
  192. '$index' => $index,
  193. '$checked' => $value == $selected ? 'checked="checked"' : '',
  194. '$name' => $name,
  195. '$value' => self::specchars($value)
  196. ));
  197. }
  198. return $result;
  199. }
  200. public function getinput($type, $name, $value, $title) {
  201. $theme = ttheme::i();
  202. return strtr($theme->templates['content.admin.' . $type], array(
  203. '$lang.$name' => $title,
  204. '$name' => $name,
  205. '$value' => $value
  206. ));
  207. }
  208. public function getsubmit() {
  209. $result = '';
  210. $a = func_get_args();
  211. foreach ($a as $name) {
  212. $result .= strtr(ttheme::i()->templates['content.admin.button'], array(
  213. '$lang.$name' => tlocal::i()->__get($name),
  214. '$name' => $name,
  215. ));
  216. }
  217. return $result;
  218. }
  219. public function getedit($name, $value, $title) {
  220. return $this->getinput('text', $name, $value, $title);
  221. }
  222. public function getcombo($name, $value, $title) {
  223. return $this->getinput('combo', $name, $value, $title);
  224. }
  225. public function cleandate($date) {
  226. if (is_numeric($date)) {
  227. $date = intval($date);
  228. } else if ($date == '0000-00-00 00:00:00') {
  229. $date = 0;
  230. } elseif ($date == '0000-00-00') {
  231. $date = 0;
  232. } elseif (trim($date)) {
  233. $date = strtotime($date);
  234. } else {
  235. $date = 0;
  236. }
  237. return $date;
  238. }
  239. public function getcalendar($name, $date) {
  240. $date = $this->cleandate($date);
  241. $lang = tlocal::i();
  242. $controls = $this->getinput('text', $name, $date? date('d.m.Y', $date) : '', $lang->date);
  243. $controls .= $this->getinput('text', "$name-time", $date ?date('H:i', $date) : '', $lang->time);
  244. $controls .= $this->getinput('button', "calendar-$name", '', $lang->calendar);
  245. return sprintf($this->ini['common']['calendar'], $lang->__get($name), $this->inline($controls));
  246. }
  247. public function getdaterange($from, $to) {
  248. $from = $this->cleandate($from);
  249. $to = $this->cleandate($to);
  250. $lang = tlocal::i();
  251. $controls = $this->getinput('text', 'from', $from ? date('d.m.Y', $from) : '', $lang->from);
  252. $controls .= $this->getinput('button', "calendar-from", '', $lang->calendar);
  253. $controls .= $this->getinput('text', 'to', $to ? date('d.m.Y', $to) : '', $lang->to);
  254. $controls .= $this->getinput('button', "calendar-to", '', $lang->calendar);
  255. return sprintf($this->ini['common']['daterange'], $controls);
  256. }
  257. public static function getdatetime($name) {
  258. if (!empty($_POST[$name]) && @sscanf(trim($_POST[$name]), '%d.%d.%d', $d, $m, $y)) {
  259. $h = 0;
  260. $min = 0;
  261. if (!empty($_POST[$name . '-time'])) @sscanf(trim($_POST[$name . '-time']), '%d:%d', $h, $min);
  262. return mktime($h,$min,0, $m, $d, $y);
  263. }
  264. return 0;
  265. }
  266. public function gettable($head, $body) {
  267. return strtr($this->ini['common']['table'], array(
  268. '$tableclass' => ttheme::i()->templates['content.admin.tableclass'],
  269. '$tablehead' => $head,
  270. '$tablebody' => $body));
  271. }
  272. public function tablestruct(array $tablestruct) {
  273. $head = '';
  274. $tml = '<tr>';
  275. foreach ($tablestruct as $elem) {
  276. if (!$elem || !count($elem)) continue;
  277. $head .= sprintf('<th align="%s">%s</th>', $elem[0], $elem[1]);
  278. $tml .= sprintf('<td align="%s">%s</td>', $elem[0], $elem[2]);
  279. }
  280. $tml .= '</tr>';
  281. return array($head, $tml);
  282. }
  283. public function buildtable(array $items, array $tablestruct) {
  284. $body = '';
  285. list($head, $tml) = $this->tablestruct($tablestruct);
  286. $theme = ttheme::i();
  287. $args = new targs();
  288. foreach ($items as $id => $item) {
  289. ttheme::$vars['item'] = $item;
  290. $args->add($item);
  291. if (!isset($item['id'])) $args->id = $id;
  292. $body .= $theme->parsearg($tml, $args);
  293. }
  294. unset(ttheme::$vars['item']);
  295. $args->tablehead = $head;
  296. $args->tablebody = $body;
  297. return $theme->parsearg($this->ini['common']['table'], $args);
  298. }
  299. public function items2table($owner, array $items, array $struct) {
  300. $head = '';
  301. $body = '';
  302. $tml = '<tr>';
  303. foreach ($struct as $elem) {
  304. $head .= sprintf('<th align="%s">%s</th>', $elem[0], $elem[1]);
  305. $tml .= sprintf('<td align="%s">%s</td>', $elem[0], $elem[2]);
  306. }
  307. $tml .= '</tr>';
  308. $theme = ttheme::i();
  309. $args = new targs();
  310. foreach ($items as $id) {
  311. $item = $owner->getitem($id);
  312. $args->add($item);
  313. $args->id = $id;
  314. $body .= $theme->parsearg($tml, $args);
  315. }
  316. $args->tablehead = $head;
  317. $args->tablebody = $body;
  318. return $theme->parsearg($this->ini['common']['table'], $args);
  319. }
  320. public function tableposts(array $items, array $struct) {
  321. $body = '';
  322. $head = sprintf('<th align="center">%s</th>', $this->invertcheckbox );
  323. $tml = '<tr><td align="center"><label><input type="checkbox" name="checkbox-$post.id" id="id-checkbox-$post.id" value="$post.id"/>$post.id</label><td>';
  324. foreach ($struct as $elem) {
  325. $head .= sprintf('<th align="%s">%s</th>', $elem[0], $elem[1]);
  326. $tml .= sprintf('<td align="%s">%s</td>', $elem[0], $elem[2]);
  327. }
  328. $tml .= '</tr>';
  329. $theme = ttheme::i();
  330. $args = new targs();
  331. foreach ($items as $id) {
  332. $post = tpost::i($id);
  333. ttheme::$vars['post'] = $post;
  334. $args->id = $id;
  335. $body .= $theme->parsearg($tml, $args);
  336. }
  337. $args->tablehead = $head;
  338. $args->tablebody = $body;
  339. return $theme->parsearg($this->ini['common']['table'], $args);
  340. }
  341. public function getitemscount($from, $to, $count) {
  342. return sprintf($this->h4->itemscount, $from, $to, $count);
  343. }
  344. public function get_table_checkbox($name) {
  345. return array('center', $this->invertcheckbox, str_replace('$checkboxname', $name, $this->checkbox));
  346. }
  347. public function get_table_item($name) {
  348. return array('left', tlocal::i()->$name, "\$$name");
  349. }
  350. public function get_table_link($action, $adminurl) {
  351. return array('left', tlocal::i()->$action, strtr($this->actionlink , array(
  352. '$action' => $action,
  353. '$lang.action' => tlocal::i()->$action,
  354. '$adminurl' => $adminurl
  355. )));
  356. }
  357. public function tableprops($item) {
  358. $body = '';
  359. $lang = tlocal::i();
  360. foreach ($item as $k => $v) {
  361. if (($k === false) || ($v === false)) continue;
  362. $k2 = $lang->__get($k);
  363. if (!$k2) $k2 = $k;
  364. $body .= sprintf('<tr><td>%s</td><td>%s</td></tr>', $k2, $v);
  365. }
  366. return $this->gettable("<th>$lang->name</th> <th>$lang->property</th>", $body);
  367. }
  368. public function tablevalues(array $a) {
  369. $body = '';
  370. foreach ($a as $k => $v) {
  371. if (is_array($v)) {
  372. foreach ($v as $vk => $vv) {
  373. $body .= sprintf('<tr><td>%s</td><td>%s</td></tr>', $kv, $vv);
  374. }
  375. } else {
  376. $body .= sprintf('<tr><td>%s</td><td>%s</td></tr>', $k, $v);
  377. }
  378. }
  379. $lang = tlocal::i();
  380. return $this->gettable("<th>$lang->name</th> <th>$lang->value</th>", $body);
  381. }
  382. public function singlerow(array $a) {
  383. $head = '';
  384. $body = '<tr>';
  385. foreach ($a as $k => $v) {
  386. $head .= sprintf('<th>%s</th>', $k);
  387. $body .= sprintf('<td>%s</td>', $v);
  388. }
  389. $body .= '</tr>';
  390. return $this->gettable($head, $body);
  391. }
  392. public function confirmdelete($id, $adminurl, $mesg) {
  393. $args = targs::i();
  394. $args->id = $id;
  395. $args->action = 'delete';
  396. $args->adminurl = $adminurl;
  397. $args->confirm = $mesg;
  398. return $this->confirmform($args);
  399. }
  400. public function confirm_delete($owner, $adminurl) {
  401. $id = (int) self::getparam('id', 0);
  402. if (!$owner->itemexists($id)) return $this->h4->notfound;
  403. if (isset($_REQUEST['confirm']) && ($_REQUEST['confirm'] == 1)) {
  404. $owner->delete($id);
  405. return $this->h4->successdeleted;
  406. } else {
  407. $args = new targs();
  408. $args->id = $id;
  409. $args->adminurl = $adminurl;
  410. $args->action = 'delete';
  411. $args->confirm = tlocal::i()->confirmdelete;
  412. return $this->confirmform($args);
  413. }
  414. }
  415. public static function check2array($prefix) {
  416. $result = array();
  417. foreach ($_POST as $key => $value) {
  418. if (strbegin($key, $prefix)) {
  419. $result[] = is_numeric($value) ? (int) $value : $value;
  420. }
  421. }
  422. return $result;
  423. }
  424. public function toggle($title, $target, $second = '') {
  425. return strtr($this->ini['common']['toggle'], array(
  426. '$title' => $title,
  427. '$target' => $target,
  428. '$second' => $second,
  429. "'" => '"',
  430. ));
  431. }
  432. public function inidir($dir) {
  433. $filename = $dir . 'html.ini';
  434. if (!isset(ttheme::$inifiles[$filename])) {
  435. $html_ini = ttheme::cacheini($filename);
  436. if (is_array($html_ini)) {
  437. $this->ini = $html_ini + $this->ini;
  438. $keys = array_keys($html_ini);
  439. $this->section = array_shift($keys);
  440. $this->searchsect[] = $this->section;
  441. }
  442. }
  443. tlocal::inicache($dir . litepublisher::$options->language . '.admin.ini');
  444. return $this;
  445. }
  446. public function iniplugin($class) {
  447. return $this->inidir(litepublisher::$classes->getresourcedir($class));
  448. }
  449. }//class
  450. class tautoform {
  451. const editor = 'editor';
  452. const text = 'text';
  453. const checkbox = 'checkbox';
  454. const hidden = 'hidden';
  455. public $obj;
  456. public $props;
  457. public $section;
  458. public $_title;
  459. public static function i() {
  460. return getinstance(__class__);
  461. }
  462. public function __construct(tdata $obj, $section, $titleindex) {
  463. $this->obj = $obj;
  464. $this->section = $section;
  465. $this->props = array();
  466. $lang = tlocal::i($section);
  467. $this->_title = $lang->$titleindex;
  468. }
  469. public function __set($name, $value) {
  470. $this->props[] = array(
  471. 'obj' => $this->obj,
  472. 'propname' => $name,
  473. 'type' => $value
  474. );
  475. }
  476. public function __get($name) {
  477. if (isset($this->obj->$name)) {
  478. return array(
  479. 'obj' => $this->obj,
  480. 'propname' => $name
  481. );
  482. }
  483. //tlogsubsystem::error(sprintf('The property %s not found in class %s', $name, get_class($this->obj));
  484. }
  485. public function __call($name, $args) {
  486. if (isset($this->obj->$name)) {
  487. $result = array(
  488. 'obj' => $this->obj,
  489. 'propname' => $name,
  490. 'type' => $args[0]
  491. );
  492. if (($result['type'] == 'combo') && isset($args[1])) $result['items'] = $args[1];
  493. return $result;
  494. }
  495. }
  496. public function add() {
  497. $a = func_get_args();
  498. foreach ($a as $prop) {
  499. $this->addprop($prop);
  500. }
  501. }
  502. public function addsingle($obj, $propname, $type) {
  503. return $this->addprop(array(
  504. 'obj' => $obj,
  505. 'propname' => $propname,
  506. 'type' => $type
  507. ));
  508. }
  509. public function addeditor($obj, $propname) {
  510. return $this->addsingle($obj, $propname, 'editor');
  511. }
  512. public function addprop(array $prop) {
  513. if (isset($prop['type'])) {
  514. $type = $prop['type'];
  515. } else {
  516. $type = 'text';
  517. $value = $prop['obj']->{$prop['propname']};
  518. if (is_bool($value)) {
  519. $type = 'checkbox';
  520. } elseif(strpos($value, "\n")) {
  521. $type = 'editor';
  522. }
  523. }
  524. $item = array(
  525. 'obj' => $prop['obj'],
  526. 'propname' => $prop['propname'],
  527. 'type' => $type,
  528. 'title' => isset($prop['title']) ? $prop['title'] : ''
  529. );
  530. if (($type == 'combo') && isset($prop['items'])) $item['items'] = $prop['items'];
  531. $this->props[] = $item;
  532. return count($this->props) - 1;
  533. }
  534. public function getcontent() {
  535. $result = '';
  536. $lang = tlocal::i();
  537. $theme = ttheme::i();
  538. foreach ($this->props as $prop) {
  539. $value = $prop['obj']->{$prop['propname']};
  540. switch ($prop['type']) {
  541. case 'text':
  542. case 'editor':
  543. $value = tadminhtml::specchars($value);
  544. break;
  545. case 'checkbox':
  546. $value = $value ? 'checked="checked"' : '';
  547. break;
  548. case 'combo':
  549. $value = tadminhtml ::array2combo($prop['items'], $value);
  550. break;
  551. }
  552. $result .= strtr($theme->templates['content.admin.' . $prop['type']], array(
  553. '$lang.$name' => empty($prop['title']) ? $lang->{$prop['propname']} : $prop['title'],
  554. '$name' => $prop['propname'],
  555. '$value' => $value
  556. ));
  557. }
  558. return $result;
  559. }
  560. public function getform() {
  561. $args = targs::i();
  562. $args->formtitle = $this->_title;
  563. $args->items = $this->getcontent();
  564. $theme = ttheme::i();
  565. return $theme->parsearg($theme->templates['content.admin.form'], $args);
  566. }
  567. public function processform() {
  568. foreach ($this->props as $prop) {
  569. if (method_exists($prop['obj'], 'lock')) $prop['obj']->lock();
  570. }
  571. foreach ($this->props as $prop) {
  572. $name = $prop['propname'];
  573. if (isset($_POST[$name])) {
  574. $value = trim($_POST[$name]);
  575. if ($prop['type'] == 'checkbox') $value = true;
  576. } else {
  577. $value = false;
  578. }
  579. $prop['obj']->$name = $value;
  580. }
  581. foreach ($this->props as $prop) {
  582. if (method_exists($prop['obj'], 'unlock')) $prop['obj']->unlock();
  583. }
  584. }
  585. }//class
  586. class ttablecolumns {
  587. public $style;
  588. public $head;
  589. public $checkboxes;
  590. public $checkbox_tml;
  591. public $item;
  592. public $changed_hidden;
  593. public $index;
  594. public function __construct() {
  595. $this->index = 0;
  596. $this->style = '';
  597. $this->checkboxes = array();
  598. $this->checkbox_tml = '<input type="checkbox" name="checkbox-showcolumn-%1$d" value="%1$d" %2$s />
  599. <label for="checkbox-showcolumn-%1$d"><strong>%3$s</strong></label>';
  600. $this->head = '';
  601. $this->body = '';
  602. $this->changed_hidden = 'changed_hidden';
  603. }
  604. public function addcolumns(array $columns) {
  605. foreach ($columns as $column) {
  606. list($tml, $title, $align, $show) = $column;
  607. $this->add($tml, $title, $align, $show);
  608. }
  609. }
  610. public function add($tml, $title, $align, $show) {
  611. $class = 'col_' . ++$this->index;
  612. //if (isset($_POST[$this->changed_hidden])) $show = isset($_POST["checkbox-showcolumn-$this->index"]);
  613. $display = $show ? 'block' : 'none';
  614. $this->style .= ".$class { text-align: $align; display: $display; }\n";
  615. $this->checkboxes[]= sprintf($this->checkbox_tml, $this->index, $show ? 'checked="checked"' : '', $title);
  616. $this->head .= sprintf('<th class="%s">%s</th>', $class, $title);
  617. $this->body .= sprintf('<td class="%s">%s</td>', $class, $tml);
  618. return $this->index;
  619. }
  620. public function build($body, $buttons) {
  621. $args = new targs();
  622. $args->style = $this->style;
  623. $args->checkboxes = implode("\n", $this->checkboxes);
  624. $args->head = $this->head;
  625. $args->body = $body;
  626. $args->buttons = $buttons;
  627. $tml = tfilestorage::getfile(litepublisher::$paths->languages . 'tablecolumns.ini');
  628. $theme = ttheme::i();
  629. return $theme->parsearg($tml, $args);
  630. }
  631. }//class
  632. class tuitabs {
  633. public $head;
  634. public $body;
  635. public $tabs;
  636. public $customdata;
  637. private static $index = 0;
  638. private $tabindex;
  639. private $items;
  640. public function __construct() {
  641. $this->tabindex = ++self::$index;
  642. $this->items = array();
  643. $this->head = '<li><a href="%s" role="tab"><span>%s</span></a></li>';
  644. $this->body = '<div id="tab-' . self::$index . '-%d" role="tabpanel">%s</div>';
  645. $this->tabs = '<div id="tabs-' . self::$index . '" class="admintabs" %s>
  646. <ul role="tablist">%s</ul>
  647. %s
  648. </div>';
  649. $this->customdata = false;
  650. }
  651. public function get() {
  652. $head= '';
  653. $body = '';
  654. foreach ($this->items as $i => $item) {
  655. if (isset($item['url'])) {
  656. $head .= sprintf($this->head, $item['url'], $item['title']);
  657. } else {
  658. $head .= sprintf($this->head, "#tab-$this->tabindex-$i", $item['title']);
  659. $body .= sprintf($this->body, $i, $item['body']);
  660. }
  661. }
  662. $data = $this->customdata? sprintf('data-custom="%s"', str_replace('"', '&quot;', json_encode($this->customdata))) : '';
  663. return sprintf($this->tabs, $data, $head, $body);
  664. }
  665. public function add($title, $body) {
  666. $this->items[] = array(
  667. 'title' => $title,
  668. 'body' => $body
  669. );
  670. }
  671. public function ajax($title, $url) {
  672. $this->items[] = array(
  673. 'url' => $url,
  674. 'title' => $title,
  675. );
  676. }
  677. public static function gethead() {
  678. return ttemplate::i()->getready('$($("div.admintabs").get().reverse()).tabs({ beforeLoad: litepubl.uibefore})');
  679. }
  680. }//class
  681. class adminform {
  682. public $args;
  683. public$title;
  684. public $items;
  685. public $action;
  686. public $method;
  687. public $enctype;
  688. public $id;
  689. public $class;
  690. public $target;
  691. public $submit;
  692. public $inlineclass;
  693. public function __construct($args = null) {
  694. $this->args = $args;
  695. $this->title = '';
  696. $this->items = '';
  697. $this->action = '';
  698. $this->method = 'post';
  699. $this->enctype = '';
  700. $this->id = '';
  701. $this->class = '';
  702. $this->target = '';
  703. $this->submit = 'update';
  704. $this->inlineclass = 'form-inline';
  705. }
  706. public function line($s) {
  707. return "<div class=\"$this->inlineclass\">$s</div>";
  708. }
  709. public function __set($k, $v) {
  710. switch ($k) {
  711. case 'upload':
  712. if ($v) {
  713. $this->enctype = 'multipart/form-data';
  714. $this->submit = 'upload';
  715. } else {
  716. $this->enctype = '';
  717. $this->submit = 'update';
  718. }
  719. break;
  720. case 'inline':
  721. $this->class = $v ? $this->inlineclass : '';
  722. break;
  723. }
  724. }
  725. public function __tostring() {
  726. return $this->get();
  727. }
  728. public function gettml() {
  729. $result = '<div class="form-holder">';
  730. if ($this->title) $result .= "<h4>$this->title</h4>\n";
  731. $attr = "action=\"$this->action\"";
  732. foreach (array('method', 'enctype', 'target', 'id', 'class') as $k) {
  733. if ($v = $this->$k) $attr .= sprintf(' %s="%s"', $k, $v);
  734. }
  735. $result .= "<form $attr role=\"form\">";
  736. $result .= $this->items;
  737. if ($this->submit) $result .= $this->class == $this->inlineclass ? "[button=$this->submit]" : "[submit=$this->submit]";
  738. $result .= "\n</form>\n</div>\n";
  739. return $result;
  740. }
  741. public function get() {
  742. return tadminhtml::i()->parsearg($this->gettml(), $this->args);
  743. }
  744. }//class