PageRenderTime 62ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/kernel.admin.php

http://litepublisher.googlecode.com/
PHP | 1595 lines | 1508 code | 76 blank | 11 comment | 61 complexity | 95f14b6d38fe054d1c259104224e5f6f MD5 | raw file
Possible License(s): AGPL-1.0, GPL-3.0
  1. <?php
  2. /**
  3. * Lite Publisher
  4. * Copyright (C) 2010, 2011, 2012, 2013 Vladimir Yushko http://litepublisher.com/
  5. * Dual licensed under the MIT (mit.txt)
  6. * and GPL (gpl.txt) licenses.
  7. **/
  8. //menu.admin.class.php
  9. class tadminmenus extends tmenus {
  10. public static function i() {
  11. return getinstance(__class__);
  12. }
  13. protected function create() {
  14. parent::create();
  15. $this->basename = 'adminmenu';
  16. $this->addevents('onexclude');
  17. $this->data['heads'] = '';
  18. }
  19. public function settitle($id, $title) {
  20. if ($id && isset($this->items[$id])) {
  21. $this->items[$id]['title'] = $title;
  22. $this->save();
  23. litepublisher::$urlmap->clearcache();
  24. }
  25. }
  26. public function getdir() {
  27. return litepublisher::$paths->data . 'adminmenus' . DIRECTORY_SEPARATOR;
  28. }
  29. public function getadmintitle($name) {
  30. $lang = tlocal::i();
  31. $ini = &$lang->ini;
  32. if (isset($ini[$name]['title'])) return $ini[$name]['title'];
  33. tlocal::usefile('install');
  34. if (!in_array('adminmenus', $lang->searchsect)) array_unshift($lang->searchsect, 'adminmenus');
  35. if ($result = $lang->__get($name)) return $result;
  36. return $name;
  37. }
  38. public function createurl($parent, $name) {
  39. return $parent == 0 ? "/admin/$name/" : $this->items[$parent]['url'] . "$name/";
  40. }
  41. public function createitem($parent, $name, $group, $class) {
  42. $title = $this->getadmintitle($name);
  43. $url = $this->createurl($parent, $name);
  44. return $this->additem(array(
  45. 'parent' => $parent,
  46. 'url' => $url,
  47. 'title' => $title,
  48. 'name' => $name,
  49. 'class' => $class,
  50. 'group' => $group
  51. ));
  52. }
  53. public function additem(array $item) {
  54. if (empty($item['group'])) {
  55. $groups = tusergroups::i();
  56. $item['group'] = $groups->items[$groups->defaults[0]]['name'];
  57. }
  58. return parent::additem($item);
  59. }
  60. public function addfakemenu(tmenu $menu) {
  61. $this->lock();
  62. $id = parent::addfakemenu($menu);
  63. if (empty($this->items[$id]['group'])) {
  64. $groups = tusergroups::i();
  65. $this->items[$id]['group'] = $groups->items[$groups->defaults[0]]['name'];
  66. }
  67. $this->unlock();
  68. return $id;
  69. }
  70. public function getchilds($id) {
  71. if ($id == 0) {
  72. $result = array();
  73. $options = litepublisher::$options;
  74. foreach ($this->tree as $iditem => $items) {
  75. if ($options->hasgroup($this->items[$iditem]['group']))
  76. $result[] = $iditem;
  77. }
  78. return $result;
  79. }
  80. $parents = array($id);
  81. $parent = $this->items[$id]['parent'];
  82. while ($parent != 0) {
  83. array_unshift ($parents, $parent);
  84. $parent = $this->items[$parent]['parent'];
  85. }
  86. $tree = $this->tree;
  87. foreach ($parents as $parent) {
  88. foreach ($tree as $iditem => $items) {
  89. if ($iditem == $parent) {
  90. $tree = $items;
  91. break;
  92. }
  93. }
  94. }
  95. return array_keys($tree);
  96. }
  97. public function exclude($id) {
  98. if (!litepublisher::$options->hasgroup($this->items[$id]['group'])) return true;
  99. return $this->onexclude($id);
  100. }
  101. }//class
  102. class tadminmenu extends tmenu {
  103. public static $adminownerprops = array('title', 'url', 'idurl', 'parent', 'order', 'status', 'name', 'group');
  104. public $arg;
  105. public static function getinstancename() {
  106. return 'adminmenu';
  107. }
  108. public static function getowner() {
  109. return tadminmenus::i();
  110. }
  111. protected function create() {
  112. parent::create();
  113. $this->cache = false;
  114. }
  115. public function get_owner_props() {
  116. return self::$adminownerprops;
  117. }
  118. public function load() { return true; }
  119. public function save() { return true; }
  120. public function gethead() {
  121. return tadminmenus::i()->heads;
  122. }
  123. public function getidview() {
  124. return tviews::i()->defaults['admin'];
  125. }
  126. public static function auth($group) {
  127. if (litepublisher::$options->cookieenabled) {
  128. if ($s = tguard::checkattack()) return $s;
  129. if (!litepublisher::$options->user) {
  130. return litepublisher::$urlmap->redir('/admin/login/' . litepublisher::$site->q . 'backurl=' . urlencode(litepublisher::$urlmap->url));
  131. }
  132. }else {
  133. $auth = tauthdigest::i();
  134. if (!$auth->Auth()) return $auth->headers();
  135. }
  136. if (!litepublisher::$options->hasgroup($group)) {
  137. $url = tusergroups::i()->gethome(litepublisher::$options->group);
  138. return litepublisher::$urlmap->redir($url);
  139. //return 403;
  140. }
  141. }
  142. public function request($id) {
  143. error_reporting(E_ALL | E_NOTICE | E_STRICT | E_WARNING );
  144. ini_set('display_errors', 1);
  145. if (is_null($id)) $id = $this->owner->class2id(get_class($this));
  146. $this->data['id'] = (int)$id;
  147. if ($id > 0) {
  148. $this->basename = $this->parent == 0 ? $this->name : $this->owner->items[$this->parent]['name'];
  149. }
  150. if ($s = self::auth($this->group)) return $s;
  151. tlocal::usefile('admin');
  152. $this->arg = litepublisher::$urlmap->argtree;
  153. if ($s = $this->canrequest()) return $s;
  154. $this->doprocessform();
  155. }
  156. public function canrequest() { }
  157. protected function doprocessform() {
  158. if (tguard::post()) {
  159. litepublisher::$urlmap->clearcache();
  160. }
  161. return parent::doprocessform();
  162. }
  163. public function getcont() {
  164. if (litepublisher::$options->admincache) {
  165. $id = isset($_POST['id']) ? (int) $_POST['id'] : 0;
  166. $filename = 'adminmenu.' . litepublisher::$options->user . '.' .md5($_SERVER['REQUEST_URI'] . '&id=' . $id) . '.php';
  167. if ($result = litepublisher::$urlmap->cache->get($filename)) return $result;
  168. $result = parent::getcont();
  169. litepublisher::$urlmap->cache->set($filename, $result);
  170. return $result;
  171. } else {
  172. return parent::getcont();
  173. }
  174. }
  175. public static function idget() {
  176. return (int) tadminhtml::getparam('id', 0);
  177. }
  178. public function getaction() {
  179. return isset($_REQUEST['action']) ? $_REQUEST['action'] : false;
  180. }
  181. public function gethtml($name = '') {
  182. $result = tadminhtml::i();
  183. if ($name == '') $name = $this->basename;
  184. if (!isset($result->ini[$name]) && $this->parent) {
  185. $name = $this->owner->items[$this->parent]['name'];
  186. }
  187. $result->section = $name;
  188. $lang = tlocal::i($name);
  189. return $result;
  190. }
  191. public function getlang() {
  192. return tlocal::i($this->name);
  193. }
  194. public function getadminlang() {
  195. return tlocal::inifile($this, '.admin.ini');
  196. }
  197. public function inihtml($name = '') {
  198. $html = $this->gethtml($name);
  199. $html->iniplugin(get_class($this));
  200. return $html;
  201. }
  202. public function getconfirmed() {
  203. return isset($_REQUEST['confirm']) && ($_REQUEST['confirm'] == 1);
  204. }
  205. public function getnotfound() {
  206. return $this->html->h4->notfound;
  207. }
  208. public function getadminurl() {
  209. return litepublisher::$site->url .$this->url . litepublisher::$site->q . 'id';
  210. }
  211. public function getfrom($perpage, $count) {
  212. if (litepublisher::$urlmap->page <= 1) return 0;
  213. return min($count, (litepublisher::$urlmap->page - 1) * $perpage);
  214. }
  215. }//class
  216. class tauthor_rights extends tevents {
  217. public static function i() {
  218. return getinstance(__class__);
  219. }
  220. protected function create() {
  221. parent::create();
  222. $this->addevents('gethead', 'getposteditor', 'editpost', 'changeposts', 'canupload', 'candeletefile');
  223. $this->basename = 'authorrights';
  224. }
  225. }//class
  226. //htmlresource.class.php
  227. class thtmltag {
  228. public $tag;
  229. public function __construct($tag) { $this->tag = $tag; }
  230. public function __get($name) {
  231. return sprintf('<%1$s>%2$s</%1$s>', $this->tag, tlocal::i()->$name);
  232. }
  233. }//class
  234. class redtag extends thtmltag {
  235. public function __get($name) {
  236. return sprintf('<%1$s class="red">%2$s</%1$s>', $this->tag, tlocal::i()->$name);
  237. }
  238. }//class
  239. class tadminhtml {
  240. public static $tags = array('h1', 'h2', 'h3', 'h4', 'p', 'li', 'ul', 'strong', 'div', 'span');
  241. public $section;
  242. public $searchsect;
  243. public $ini;
  244. private $map;
  245. private $section_stack;
  246. public static function i() {
  247. $self = getinstance(__class__);
  248. if (count($self->ini) == 0) $self->load();
  249. return $self;
  250. }
  251. public static function getinstance($section) {
  252. $self = self::i();
  253. $self->section = $section;
  254. tlocal::i($section);
  255. return $self;
  256. }
  257. public function __construct() {
  258. $this->ini = array();
  259. $this->searchsect = array('common');
  260. tlocal::usefile('admin');
  261. }
  262. public function __get($name) {
  263. if (isset($this->ini[$this->section][$name])) return $this->ini[$this->section][$name];
  264. foreach ($this->searchsect as $section) {
  265. if (isset($this->ini[$section][$name])) return $this->ini[$section][$name];
  266. }
  267. if (in_array($name, self::$tags)) return new thtmltag($name);
  268. if (strend($name, 'red') && in_array(substr($name, 0, -3), self::$tags)) return new redtag($name);
  269. throw new Exception("the requested $name item not found in $this->section section");
  270. }
  271. public function __call($name, $params) {
  272. $s = $this->__get($name);
  273. if (is_object($s) && ($s instanceof thtmltag)) return sprintf('<%1$s>%2$s</%1$s>', $name, $params[0]);
  274. if ($name == 'h4error') return sprintf('<h4 class="red">%s</h4>', $params[0]);
  275. $args = isset($params[0]) && $params[0] instanceof targs ? $params[0] : new targs();
  276. return $this->parsearg($s, $args);
  277. }
  278. public function parsearg($s, targs $args) {
  279. if (!is_string($s)) $s = (string) $s;
  280. $theme = ttheme::i();
  281. // parse tags [form] .. [/form]
  282. if (is_int($i = strpos($s, '[form]'))) {
  283. $form = $theme->templates['content.admin.form'];
  284. $replace = substr($form, 0, strpos($form, '$items'));
  285. $s = substr_replace($s, $replace, $i, strlen('[form]'));
  286. }
  287. if ($i = strpos($s, '[/form]')) {
  288. $replace = substr($form, strrpos($form, '$items') + strlen('$items'));
  289. $s = substr_replace($s, $replace, $i, strlen('[/form]'));
  290. }
  291. if (preg_match_all('/\[(editor|checkbox|text|password|combo|hidden|submit|button|calendar|upload)(:|=)(\w*+)\]/i', $s, $m, PREG_SET_ORDER)) {
  292. foreach ($m as $item) {
  293. $type = $item[1];
  294. $name = $item[3];
  295. $varname = '$' . $name;
  296. //convert spec charsfor editor
  297. if (!in_array($type, array('checkbox', 'combo', 'calendar', 'upload'))) {
  298. if (isset($args->data[$varname])) {
  299. $args->data[$varname] = self::specchars($args->data[$varname]);
  300. } else {
  301. $args->data[$varname] = '';
  302. }
  303. }
  304. if ($type == 'calendar') {
  305. $tag = $this->getcalendar($name, $args->data[$varname]);
  306. } else {
  307. $tag = strtr($theme->templates["content.admin.$type"], array(
  308. '$name' => $name,
  309. '$value' => $varname
  310. ));
  311. }
  312. $s = str_replace($item[0], $tag, $s);
  313. }
  314. }
  315. $s = strtr($s, $args->data);
  316. return $theme->parse($s);
  317. }
  318. public function addsearch() {
  319. $a = func_get_args();
  320. foreach ($a as $sect) {
  321. if (!in_array($sect, $this->searchsect)) $this->searchsect[] = $sect;
  322. }
  323. }
  324. public function push_section($section) {
  325. if (!isset($this->section_stack)) $this->section_stack = array();
  326. $lang = tlocal::i();
  327. $this->section_stack[] = array(
  328. $this->section,
  329. $lang->section
  330. );
  331. $this->section = $section;
  332. $lang->section = $section;
  333. }
  334. public function pop_section() {
  335. $a = array_pop($this->section_stack);
  336. $this->section = $a[0];
  337. tlocal::i()->section = $a[1];
  338. }
  339. public static function specchars($s) {
  340. return strtr( htmlspecialchars($s), array(
  341. '"' => '&quot;',
  342. "'" =>'&#39;',
  343. '$' => '&#36;',
  344. '%' => '&#37;',
  345. '_' => '&#95;'
  346. ));
  347. }
  348. public function fixquote($s) {
  349. $s = str_replace("\\'", '\"', $s);
  350. $s = str_replace("'", '"', $s);
  351. return str_replace('\"', "'", $s);
  352. }
  353. public function load() {
  354. $filename = tlocal::getcachedir() . 'adminhtml';
  355. if (tfilestorage::loadvar($filename, $v) && is_array($v)) {
  356. $this->ini = $v + $this->ini;
  357. } else {
  358. $merger = tlocalmerger::i();
  359. $merger->parsehtml();
  360. }
  361. }
  362. public function loadinstall() {
  363. if (isset($this->ini['installation'])) return;
  364. tlocal::usefile('install');
  365. if( $v = parse_ini_file(litepublisher::$paths->languages . 'install.ini', true)) {
  366. $this->ini = $v + $this->ini;
  367. }
  368. }
  369. public static function getparam($name, $default) {
  370. return !empty($_GET[$name]) ? $_GET[$name] : (!empty($_POST[$name]) ? $_POST[$name] : $default);
  371. }
  372. public static function idparam() {
  373. return (int) self::getparam('id', 0);
  374. }
  375. public static function getadminlink($path, $params) {
  376. return litepublisher::$site->url . $path . litepublisher::$site->q . $params;
  377. }
  378. public static function getlink($url, $title) {
  379. return sprintf('<a href="%s%s">%s</a>', litepublisher::$site->url, $url, $title);
  380. }
  381. public static function array2combo(array $items, $selected) {
  382. $result = '';
  383. foreach ($items as $i => $title) {
  384. $result .= sprintf('<option value="%s" %s>%s</option>', $i, $i == $selected ? 'selected' : '', self::specchars($title));
  385. }
  386. return $result;
  387. }
  388. public static function getcombobox($name, array $items, $selected) {
  389. return sprintf('<select name="%1$s" id="%1$s">%2$s</select>', $name,
  390. self::array2combo($items, $selected));
  391. }
  392. public function adminform($tml, targs $args) {
  393. $args->items = $this->parsearg($tml, $args);
  394. return $this->parsearg(ttheme::i()->templates['content.admin.form'], $args);
  395. }
  396. public function inline($s) {
  397. return sprintf($this->ini['common']['inline'], $s);
  398. }
  399. public function getupload($name) {
  400. return $this->getinput('upload', $name, '', '');
  401. }
  402. public function getcheckbox($name, $value) {
  403. return $this->getinput('checkbox', $name, $value ? 'checked="checked"' : '', '$lang.' . $name);
  404. }
  405. public function getradioitems($name, array $items, $selected) {
  406. $result = '';
  407. $theme = ttheme::i();
  408. $tml = $theme->templates['content.admin.radioitems'];
  409. foreach ($items as $index => $value) {
  410. $result .= strtr($tml, array(
  411. '$index' => $index,
  412. '$checked' => $value == $selected ? 'checked="checked"' : '',
  413. '$name' => $name,
  414. '$value' => self::specchars($value)
  415. ));
  416. }
  417. return $result;
  418. }
  419. public function getinput($type, $name, $value, $title) {
  420. $theme = ttheme::i();
  421. return strtr($theme->templates['content.admin.' . $type], array(
  422. '$lang.$name' => $title,
  423. '$name' => $name,
  424. '$value' => $value
  425. ));
  426. }
  427. public function getsubmit() {
  428. $result = '';
  429. $a = func_get_args();
  430. foreach ($a as $name) {
  431. $result .= strtr(ttheme::i()->templates['content.admin.button'], array(
  432. '$lang.$name' => tlocal::i()->__get($name),
  433. '$name' => $name,
  434. ));
  435. }
  436. return $result;
  437. }
  438. public function getedit($name, $value, $title) {
  439. return $this->getinput('text', $name, $value, $title);
  440. }
  441. public function getcombo($name, $value, $title) {
  442. return $this->getinput('combo', $name, $value, $title);
  443. }
  444. public function cleandate($date) {
  445. if (is_numeric($date)) {
  446. $date = intval($date);
  447. } else if ($date == '0000-00-00 00:00:00') {
  448. $date = 0;
  449. } elseif ($date == '0000-00-00') {
  450. $date = 0;
  451. } elseif (trim($date)) {
  452. $date = strtotime($date);
  453. } else {
  454. $date = 0;
  455. }
  456. return $date;
  457. }
  458. public function getcalendar($name, $date) {
  459. $date = $this->cleandate($date);
  460. $lang = tlocal::i();
  461. $controls = $this->getinput('text', $name, $date? date('d.m.Y', $date) : '', $lang->date);
  462. $controls .= $this->getinput('text', "$name-time", $date ?date('H:i', $date) : '', $lang->time);
  463. $controls .= $this->getinput('button', "calendar-$name", '', $lang->calendar);
  464. return sprintf($this->ini['common']['calendar'], $lang->__get($name), $this->inline($controls));
  465. }
  466. public function getdaterange($from, $to) {
  467. $from = $this->cleandate($from);
  468. $to = $this->cleandate($to);
  469. $lang = tlocal::i();
  470. $controls = $this->getinput('text', 'from', $from ? date('d.m.Y', $from) : '', $lang->from);
  471. $controls .= $this->getinput('button', "calendar-from", '', $lang->calendar);
  472. $controls .= $this->getinput('text', 'to', $to ? date('d.m.Y', $to) : '', $lang->to);
  473. $controls .= $this->getinput('button', "calendar-to", '', $lang->calendar);
  474. return sprintf($this->ini['common']['daterange'], $controls);
  475. }
  476. public static function getdatetime($name) {
  477. if (!empty($_POST[$name]) && @sscanf(trim($_POST[$name]), '%d.%d.%d', $d, $m, $y)) {
  478. $h = 0;
  479. $min = 0;
  480. if (!empty($_POST[$name . '-time'])) @sscanf(trim($_POST[$name . '-time']), '%d:%d', $h, $min);
  481. return mktime($h,$min,0, $m, $d, $y);
  482. }
  483. return 0;
  484. }
  485. public function gettable($head, $body) {
  486. return strtr($this->ini['common']['table'], array(
  487. '$tableclass' => ttheme::i()->templates['content.admin.tableclass'],
  488. '$tablehead' => $head,
  489. '$tablebody' => $body));
  490. }
  491. public function tablestruct(array $tablestruct) {
  492. $head = '';
  493. $tml = '<tr>';
  494. foreach ($tablestruct as $elem) {
  495. if (!$elem || !count($elem)) continue;
  496. $head .= sprintf('<th align="%s">%s</th>', $elem[0], $elem[1]);
  497. $tml .= sprintf('<td align="%s">%s</td>', $elem[0], $elem[2]);
  498. }
  499. $tml .= '</tr>';
  500. return array($head, $tml);
  501. }
  502. public function buildtable(array $items, array $tablestruct) {
  503. $body = '';
  504. list($head, $tml) = $this->tablestruct($tablestruct);
  505. $theme = ttheme::i();
  506. $args = new targs();
  507. foreach ($items as $id => $item) {
  508. ttheme::$vars['item'] = $item;
  509. $args->add($item);
  510. if (!isset($item['id'])) $args->id = $id;
  511. $body .= $theme->parsearg($tml, $args);
  512. }
  513. unset(ttheme::$vars['item']);
  514. $args->tablehead = $head;
  515. $args->tablebody = $body;
  516. return $theme->parsearg($this->ini['common']['table'], $args);
  517. }
  518. public function items2table($owner, array $items, array $struct) {
  519. $head = '';
  520. $body = '';
  521. $tml = '<tr>';
  522. foreach ($struct as $elem) {
  523. $head .= sprintf('<th align="%s">%s</th>', $elem[0], $elem[1]);
  524. $tml .= sprintf('<td align="%s">%s</td>', $elem[0], $elem[2]);
  525. }
  526. $tml .= '</tr>';
  527. $theme = ttheme::i();
  528. $args = new targs();
  529. foreach ($items as $id) {
  530. $item = $owner->getitem($id);
  531. $args->add($item);
  532. $args->id = $id;
  533. $body .= $theme->parsearg($tml, $args);
  534. }
  535. $args->tablehead = $head;
  536. $args->tablebody = $body;
  537. return $theme->parsearg($this->ini['common']['table'], $args);
  538. }
  539. public function tableposts(array $items, array $struct) {
  540. $body = '';
  541. $head = sprintf('<th align="center">%s</th>', $this->invertcheckbox );
  542. $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>';
  543. foreach ($struct as $elem) {
  544. $head .= sprintf('<th align="%s">%s</th>', $elem[0], $elem[1]);
  545. $tml .= sprintf('<td align="%s">%s</td>', $elem[0], $elem[2]);
  546. }
  547. $tml .= '</tr>';
  548. $theme = ttheme::i();
  549. $args = new targs();
  550. foreach ($items as $id) {
  551. $post = tpost::i($id);
  552. ttheme::$vars['post'] = $post;
  553. $args->id = $id;
  554. $body .= $theme->parsearg($tml, $args);
  555. }
  556. $args->tablehead = $head;
  557. $args->tablebody = $body;
  558. return $theme->parsearg($this->ini['common']['table'], $args);
  559. }
  560. public function getitemscount($from, $to, $count) {
  561. return sprintf($this->h4->itemscount, $from, $to, $count);
  562. }
  563. public function get_table_checkbox($name) {
  564. return array('center', $this->invertcheckbox, str_replace('$checkboxname', $name, $this->checkbox));
  565. }
  566. public function get_table_item($name) {
  567. return array('left', tlocal::i()->$name, "\$$name");
  568. }
  569. public function get_table_link($action, $adminurl) {
  570. return array('left', tlocal::i()->$action, strtr($this->actionlink , array(
  571. '$action' => $action,
  572. '$lang.action' => tlocal::i()->$action,
  573. '$adminurl' => $adminurl
  574. )));
  575. }
  576. public function tableprops($item) {
  577. $body = '';
  578. $lang = tlocal::i();
  579. foreach ($item as $k => $v) {
  580. if (($k === false) || ($v === false)) continue;
  581. $k2 = $lang->__get($k);
  582. if (!$k2) $k2 = $k;
  583. $body .= sprintf('<tr><td>%s</td><td>%s</td></tr>', $k2, $v);
  584. }
  585. return $this->gettable("<th>$lang->name</th> <th>$lang->property</th>", $body);
  586. }
  587. public function tablevalues(array $a) {
  588. $body = '';
  589. foreach ($a as $k => $v) {
  590. $body .= sprintf('<tr><td>%s</td><td>%s</td></tr>', $k, $v);
  591. }
  592. $lang = tlocal::i();
  593. return $this->gettable("<th>$lang->name</th> <th>$lang->value</th>", $body);
  594. }
  595. public function singlerow(array $a) {
  596. $head = '';
  597. $body = '<tr>';
  598. foreach ($a as $k => $v) {
  599. $head .= sprintf('<th>%s</th>', $k);
  600. $body .= sprintf('<td>%s</td>', $v);
  601. }
  602. $body .= '</tr>';
  603. return $this->gettable($head, $body);
  604. }
  605. public function confirmdelete($id, $adminurl, $mesg) {
  606. $args = targs::i();
  607. $args->id = $id;
  608. $args->action = 'delete';
  609. $args->adminurl = $adminurl;
  610. $args->confirm = $mesg;
  611. return $this->confirmform($args);
  612. }
  613. public function confirm_delete($owner, $adminurl) {
  614. $id = (int) self::getparam('id', 0);
  615. if (!$owner->itemexists($id)) return $this->h4->notfound;
  616. if (isset($_REQUEST['confirm']) && ($_REQUEST['confirm'] == 1)) {
  617. $owner->delete($id);
  618. return $this->h4->successdeleted;
  619. } else {
  620. $args = new targs();
  621. $args->id = $id;
  622. $args->adminurl = $adminurl;
  623. $args->action = 'delete';
  624. $args->confirm = tlocal::i()->confirmdelete;
  625. return $this->confirmform($args);
  626. }
  627. }
  628. public static function check2array($prefix) {
  629. $result = array();
  630. foreach ($_POST as $key => $value) {
  631. if (strbegin($key, $prefix)) {
  632. $result[] = is_numeric($value) ? (int) $value : $value;
  633. }
  634. }
  635. return $result;
  636. }
  637. public function toggle($title, $target, $second = '') {
  638. return strtr($this->ini['common']['toggle'], array(
  639. '$title' => $title,
  640. '$target' => $target,
  641. '$second' => $second,
  642. "'" => '"',
  643. ));
  644. }
  645. public function inidir($dir) {
  646. $filename = $dir . 'html.ini';
  647. if (!isset(ttheme::$inifiles[$filename])) {
  648. $html_ini = ttheme::cacheini($filename);
  649. if (is_array($html_ini)) {
  650. $this->ini = $html_ini + $this->ini;
  651. $keys = array_keys($html_ini);
  652. $this->section = array_shift($keys);
  653. $this->searchsect[] = $this->section;
  654. }
  655. }
  656. tlocal::inicache($dir . litepublisher::$options->language . '.admin.ini');
  657. return $this;
  658. }
  659. public function iniplugin($class) {
  660. return $this->inidir(litepublisher::$classes->getresourcedir($class));
  661. }
  662. }//class
  663. class tautoform {
  664. const editor = 'editor';
  665. const text = 'text';
  666. const checkbox = 'checkbox';
  667. const hidden = 'hidden';
  668. public $obj;
  669. public $props;
  670. public $section;
  671. public $_title;
  672. public static function i() {
  673. return getinstance(__class__);
  674. }
  675. public function __construct(tdata $obj, $section, $titleindex) {
  676. $this->obj = $obj;
  677. $this->section = $section;
  678. $this->props = array();
  679. $lang = tlocal::i($section);
  680. $this->_title = $lang->$titleindex;
  681. }
  682. public function __set($name, $value) {
  683. $this->props[] = array(
  684. 'obj' => $this->obj,
  685. 'propname' => $name,
  686. 'type' => $value
  687. );
  688. }
  689. public function __get($name) {
  690. if (isset($this->obj->$name)) {
  691. return array(
  692. 'obj' => $this->obj,
  693. 'propname' => $name
  694. );
  695. }
  696. //tlogsubsystem::error(sprintf('The property %s not found in class %s', $name, get_class($this->obj));
  697. }
  698. public function __call($name, $args) {
  699. if (isset($this->obj->$name)) {
  700. $result = array(
  701. 'obj' => $this->obj,
  702. 'propname' => $name,
  703. 'type' => $args[0]
  704. );
  705. if (($result['type'] == 'combo') && isset($args[1])) $result['items'] = $args[1];
  706. return $result;
  707. }
  708. }
  709. public function add() {
  710. $a = func_get_args();
  711. foreach ($a as $prop) {
  712. $this->addprop($prop);
  713. }
  714. }
  715. public function addsingle($obj, $propname, $type) {
  716. return $this->addprop(array(
  717. 'obj' => $obj,
  718. 'propname' => $propname,
  719. 'type' => $type
  720. ));
  721. }
  722. public function addeditor($obj, $propname) {
  723. return $this->addsingle($obj, $propname, 'editor');
  724. }
  725. public function addprop(array $prop) {
  726. if (isset($prop['type'])) {
  727. $type = $prop['type'];
  728. } else {
  729. $type = 'text';
  730. $value = $prop['obj']->{$prop['propname']};
  731. if (is_bool($value)) {
  732. $type = 'checkbox';
  733. } elseif(strpos($value, "\n")) {
  734. $type = 'editor';
  735. }
  736. }
  737. $item = array(
  738. 'obj' => $prop['obj'],
  739. 'propname' => $prop['propname'],
  740. 'type' => $type,
  741. 'title' => isset($prop['title']) ? $prop['title'] : ''
  742. );
  743. if (($type == 'combo') && isset($prop['items'])) $item['items'] = $prop['items'];
  744. $this->props[] = $item;
  745. return count($this->props) - 1;
  746. }
  747. public function getcontent() {
  748. $result = '';
  749. $lang = tlocal::i();
  750. $theme = ttheme::i();
  751. foreach ($this->props as $prop) {
  752. $value = $prop['obj']->{$prop['propname']};
  753. switch ($prop['type']) {
  754. case 'text':
  755. case 'editor':
  756. $value = tadminhtml::specchars($value);
  757. break;
  758. case 'checkbox':
  759. $value = $value ? 'checked="checked"' : '';
  760. break;
  761. case 'combo':
  762. $value = tadminhtml ::array2combo($prop['items'], $value);
  763. break;
  764. }
  765. $result .= strtr($theme->templates['content.admin.' . $prop['type']], array(
  766. '$lang.$name' => empty($prop['title']) ? $lang->{$prop['propname']} : $prop['title'],
  767. '$name' => $prop['propname'],
  768. '$value' => $value
  769. ));
  770. }
  771. return $result;
  772. }
  773. public function getform() {
  774. $args = targs::i();
  775. $args->formtitle = $this->_title;
  776. $args->items = $this->getcontent();
  777. $theme = ttheme::i();
  778. return $theme->parsearg($theme->templates['content.admin.form'], $args);
  779. }
  780. public function processform() {
  781. foreach ($this->props as $prop) {
  782. if (method_exists($prop['obj'], 'lock')) $prop['obj']->lock();
  783. }
  784. foreach ($this->props as $prop) {
  785. $name = $prop['propname'];
  786. if (isset($_POST[$name])) {
  787. $value = trim($_POST[$name]);
  788. if ($prop['type'] == 'checkbox') $value = true;
  789. } else {
  790. $value = false;
  791. }
  792. $prop['obj']->$name = $value;
  793. }
  794. foreach ($this->props as $prop) {
  795. if (method_exists($prop['obj'], 'unlock')) $prop['obj']->unlock();
  796. }
  797. }
  798. }//class
  799. class ttablecolumns {
  800. public $style;
  801. public $head;
  802. public $checkboxes;
  803. public $checkbox_tml;
  804. public $item;
  805. public $changed_hidden;
  806. public $index;
  807. public function __construct() {
  808. $this->index = 0;
  809. $this->style = '';
  810. $this->checkboxes = array();
  811. $this->checkbox_tml = '<input type="checkbox" name="checkbox-showcolumn-%1$d" value="%1$d" %2$s />
  812. <label for="checkbox-showcolumn-%1$d"><strong>%3$s</strong></label>';
  813. $this->head = '';
  814. $this->body = '';
  815. $this->changed_hidden = 'changed_hidden';
  816. }
  817. public function addcolumns(array $columns) {
  818. foreach ($columns as $column) {
  819. list($tml, $title, $align, $show) = $column;
  820. $this->add($tml, $title, $align, $show);
  821. }
  822. }
  823. public function add($tml, $title, $align, $show) {
  824. $class = 'col_' . ++$this->index;
  825. //if (isset($_POST[$this->changed_hidden])) $show = isset($_POST["checkbox-showcolumn-$this->index"]);
  826. $display = $show ? 'block' : 'none';
  827. $this->style .= ".$class { text-align: $align; display: $display; }\n";
  828. $this->checkboxes[]= sprintf($this->checkbox_tml, $this->index, $show ? 'checked="checked"' : '', $title);
  829. $this->head .= sprintf('<th class="%s">%s</th>', $class, $title);
  830. $this->body .= sprintf('<td class="%s">%s</td>', $class, $tml);
  831. return $this->index;
  832. }
  833. public function build($body, $buttons) {
  834. $args = new targs();
  835. $args->style = $this->style;
  836. $args->checkboxes = implode("\n", $this->checkboxes);
  837. $args->head = $this->head;
  838. $args->body = $body;
  839. $args->buttons = $buttons;
  840. $tml = tfilestorage::getfile(litepublisher::$paths->languages . 'tablecolumns.ini');
  841. $theme = ttheme::i();
  842. return $theme->parsearg($tml, $args);
  843. }
  844. }//class
  845. class tuitabs {
  846. public $head;
  847. public $body;
  848. public $tabs;
  849. public $customdata;
  850. private static $index = 0;
  851. private $tabindex;
  852. private $items;
  853. public function __construct() {
  854. $this->tabindex = ++self::$index;
  855. $this->items = array();
  856. $this->head = '<li><a href="%s" role="tab"><span>%s</span></a></li>';
  857. $this->body = '<div id="tab-' . self::$index . '-%d" role="tabpanel">%s</div>';
  858. $this->tabs = '<div id="tabs-' . self::$index . '" class="admintabs" %s>
  859. <ul role="tablist">%s</ul>
  860. %s
  861. </div>';
  862. $this->customdata = false;
  863. }
  864. public function get() {
  865. $head= '';
  866. $body = '';
  867. foreach ($this->items as $i => $item) {
  868. if (isset($item['url'])) {
  869. $head .= sprintf($this->head, $item['url'], $item['title']);
  870. } else {
  871. $head .= sprintf($this->head, "#tab-$this->tabindex-$i", $item['title']);
  872. $body .= sprintf($this->body, $i, $item['body']);
  873. }
  874. }
  875. $data = $this->customdata? sprintf('data-custom="%s"', str_replace('"', '&quot;', json_encode($this->customdata))) : '';
  876. return sprintf($this->tabs, $data, $head, $body);
  877. }
  878. public function add($title, $body) {
  879. $this->items[] = array(
  880. 'title' => $title,
  881. 'body' => $body
  882. );
  883. }
  884. public function ajax($title, $url) {
  885. $this->items[] = array(
  886. 'url' => $url,
  887. 'title' => $title,
  888. );
  889. }
  890. public static function gethead() {
  891. return ttemplate::i()->getready('$($("div.admintabs").get().reverse()).tabs({ beforeLoad: litepubl.uibefore})');
  892. }
  893. }//class
  894. class adminform {
  895. public $args;
  896. public$title;
  897. public $items;
  898. public $action;
  899. public $method;
  900. public $enctype;
  901. public $id;
  902. public $class;
  903. public $target;
  904. public $submit;
  905. public $inlineclass;
  906. public function __construct($args = null) {
  907. $this->args = $args;
  908. $this->title = '';
  909. $this->items = '';
  910. $this->action = '';
  911. $this->method = 'post';
  912. $this->enctype = '';
  913. $this->id = '';
  914. $this->class = '';
  915. $this->target = '';
  916. $this->submit = 'update';
  917. $this->inlineclass = 'form-inline';
  918. }
  919. public function line($s) {
  920. return "<div class=\"$this->inlineclass\">$s</div>";
  921. }
  922. public function __set($k, $v) {
  923. switch ($k) {
  924. case 'upload':
  925. if ($v) {
  926. $this->enctype = 'multipart/form-data';
  927. $this->submit = 'upload';
  928. } else {
  929. $this->enctype = '';
  930. $this->submit = 'update';
  931. }
  932. break;
  933. case 'inline':
  934. $this->class = $v ? $this->inlineclass : '';
  935. break;
  936. }
  937. }
  938. public function __tostring() {
  939. return $this->get();
  940. }
  941. public function gettml() {
  942. $result = '<div class="form-holder">';
  943. if ($this->title) $result .= "<h4>$this->title</h4>\n";
  944. $attr = "action=\"$this->action\"";
  945. foreach (array('method', 'enctype', 'target', 'id', 'class') as $k) {
  946. if ($v = $this->$k) $attr .= sprintf(' %s="%s"', $k, $v);
  947. }
  948. $result .= "<form $attr role=\"form\">";
  949. $result .= $this->items;
  950. if ($this->submit) $result .= $this->class == $this->inlineclass ? "[button=$this->submit]" : "[submit=$this->submit]";
  951. $result .= "\n</form>\n</div>\n";
  952. return $result;
  953. }
  954. public function get() {
  955. return tadminhtml::i()->parsearg($this->gettml(), $this->args);
  956. }
  957. }//class
  958. //admin.posteditor.ajax.class.php
  959. class tajaxposteditor extends tevents {
  960. public $idpost;
  961. private $isauthor;
  962. public static function i() {
  963. return getinstance(__class__);
  964. }
  965. protected function create() {
  966. parent::create();
  967. $this->basename = 'ajaxposteditor';
  968. $this->addevents('onhead', 'oneditor');
  969. $this->data['head'] = '';
  970. $this->data['visual'] = '';
  971. //'/plugins/tiny_mce/init.js';
  972. //'/plugins/ckeditor/init.js';
  973. $this->data['ajaxvisual'] = true;
  974. }
  975. public function setvisual($url) {
  976. if ($url == $this->visual) return;
  977. $js = tjsmerger::i();
  978. $js->lock();
  979. $js->deletefile('posteditor', $this->visual);
  980. $js->deletetext('posteditor', 'visual');
  981. if ($url) {
  982. if ($this->ajaxvisual) {
  983. $js->addtext('posteditor', 'visual', sprintf(
  984. '$(document).ready(function() {
  985. litepubl.posteditor.init_visual_link("%s", %s);
  986. });', litepublisher::$site->files . $url, json_encode(tlocal::get('editor', 'loadvisual')))
  987. );
  988. }else {
  989. $js->add('posteditor', $url);
  990. }
  991. }
  992. $js->unlock();
  993. $this->data['visual'] = $url;
  994. $this->save();
  995. }
  996. public function gethead() {
  997. $result = $this->data['head'];
  998. if ($this->visual) {
  999. $template = ttemplate::i();
  1000. if ($this->ajaxvisual) {
  1001. $result .= $template->getready('$("a[rel~=\'loadvisual\']").one("click", function() {
  1002. $("#loadvisual").remove();
  1003. $.load_script("' . litepublisher::$site->files . $this->visual . '");
  1004. return false;
  1005. });');
  1006. } else {
  1007. $result .= $template->getjavascript($this->visual);
  1008. }
  1009. }
  1010. $this->callevent('onhead', array(&$result));
  1011. return $result;
  1012. }
  1013. protected static function error403() {
  1014. return '<?php header(\'HTTP/1.1 403 Forbidden\', true, 403); ?>' . turlmap::htmlheader(false) . 'Forbidden';
  1015. }
  1016. public function getviewicon($idview, $icon) {
  1017. $result = tadminviews::getcomboview($idview);
  1018. if ($icons = tadminicons::getradio($icon)) {
  1019. $html = tadminhtml ::i();
  1020. if ($html->section == '') $html->section = 'editor';
  1021. $result .= $html->h2->icons;
  1022. $result .= $icons;
  1023. }
  1024. return $result;
  1025. }
  1026. public static function auth() {
  1027. $options = litepublisher::$options;
  1028. if (!$options->cookieenabled) return self::error403();
  1029. if (!$options->user) return self::error403();
  1030. if (!$options->hasgroup('editor')) {
  1031. if (!$options->hasgroup('author')) return self::error403();
  1032. }
  1033. }
  1034. public function request($arg) {
  1035. $this->cache = false;
  1036. //tfiler::log(var_export($_GET, true) . var_export($_POST, true) . var_export($_FILES, true));
  1037. if ($err = self::auth()) return $err;
  1038. $this->idpost = tadminhtml::idparam();
  1039. $this->isauthor = litepublisher::$options->ingroup('author');
  1040. if ($this->idpost > 0) {
  1041. $posts = tposts::i();
  1042. if (!$posts->itemexists($this->idpost)) return self::error403();
  1043. if (!litepublisher::$options->hasgroup('editor')) {
  1044. if (litepublisher::$options->hasgroup('author')) {
  1045. $this->isauthor = true;
  1046. $post = tpost::i($this->idpost);
  1047. if (litepublisher::$options->user != $post->author) return self::error403();
  1048. }
  1049. }
  1050. }
  1051. return $this->getcontent();
  1052. }
  1053. public function getcontent() {
  1054. $theme = tview::i(tviews::i()->defaults['admin'])->theme;
  1055. $html = tadminhtml ::i();
  1056. $html->section = 'editor';
  1057. $lang = tlocal::i('editor');
  1058. $post = tpost::i($this->idpost);
  1059. ttheme::$vars['post'] = $post;
  1060. switch ($_GET['get']) {
  1061. case 'tags':
  1062. $result = $html->getedit('tags', $post->tagnames, $lang->tags);
  1063. $lang->section = 'editor';
  1064. $result .= $html->h4->addtags;
  1065. $items = array();
  1066. $tags = $post->factory->tags;
  1067. $list = $tags->getsorted(-1, 'name', 0);
  1068. foreach ($list as $id ) {
  1069. $items[] = '<a href="" class="posteditor-tag">' . $tags->items[$id]['title'] . "</a>";
  1070. }
  1071. $result .= sprintf('<p>%s</p>', implode(', ', $items));
  1072. break;
  1073. case 'status':
  1074. $args = new targs();
  1075. $args->comstatus= tadminhtml::array2combo(array(
  1076. 'closed' => $lang->closed,
  1077. 'reg' => $lang->reg,
  1078. 'guest' => $lang->guest,
  1079. 'comuser' => $lang->comuser
  1080. ), $post->comstatus);
  1081. $args->pingenabled = $post->pingenabled;
  1082. $args->status= tadminhtml::array2combo(array(
  1083. 'published' => $lang->published,
  1084. 'draft' => $lang->draft
  1085. ), $post->status);
  1086. $args->perms = tadminperms::getcombo($post->idperm);
  1087. $args->password = $post->password;
  1088. $result = $html->parsearg(
  1089. '[combo=comstatus]
  1090. [checkbox=pingenabled]
  1091. [combo=status]
  1092. $perms
  1093. [password=password]
  1094. <p>$lang.notepassword</p>',
  1095. $args);
  1096. break;
  1097. case 'view':
  1098. $result = $this->getviewicon($post->idview, $post->icon);
  1099. break;
  1100. default:
  1101. $result = var_export($_GET, true);
  1102. }
  1103. //tfiler::log($result);
  1104. return turlmap::htmlheader(false) . $result;
  1105. }
  1106. public function geteditor($name, $value, $visual) {
  1107. $html = tadminhtml ::i();
  1108. $hsect = $html->section;
  1109. $html->section = 'editor';
  1110. $lang = tlocal::i();
  1111. $lsect = $lang->section;
  1112. $lang->section = 'editor';
  1113. $title = $lang->$name;
  1114. if ($visual && $this->ajaxvisual && $this->visual) $title .= $html->loadvisual();
  1115. $result = $html->getinput('editor', $name, tadminhtml::specchars($value), $title);
  1116. $lang->section = $lsect;
  1117. $html->section = $hsect;
  1118. return $result;
  1119. }
  1120. }//class
  1121. //admin.posteditor.class.php
  1122. class tposteditor extends tadminmenu {
  1123. public $idpost;
  1124. protected $isauthor;
  1125. public static function i($id = 0) {
  1126. return parent::iteminstance(__class__, $id);
  1127. }
  1128. public function gethtml($name = '') {
  1129. if (!$name) $name = 'editor';
  1130. return parent::gethtml($name);
  1131. }
  1132. public function gethead() {
  1133. $result = parent::gethead();
  1134. $template = ttemplate::i();
  1135. $template->ltoptions['idpost'] = $this->idget();
  1136. $result .= $template->getjavascript($template->jsmerger_posteditor);
  1137. if ($this->isauthor &&($h = tauthor_rights::i()->gethead())) $result .= $h;
  1138. return $result;
  1139. }
  1140. protected static function getsubcategories($parent, array $postitems, $exclude = false) {
  1141. $result = '';
  1142. $categories = tcategories::i();
  1143. $html = tadminhtml::getinstance('editor');
  1144. $tml = str_replace('$checkbox', $html->getinput('checkbox', 'category-$id', 'value="$id" $checked', '$title'), $html->category);
  1145. $args = new targs();
  1146. foreach ($categories->items as $id => $item) {
  1147. if ($parent != $item['parent']) continue;
  1148. if ($exclude && in_array($id, $exclude)) continue;
  1149. $args->add($item);
  1150. $args->checked = in_array($item['id'], $postitems);
  1151. $args->subcount = '';
  1152. $args->subitems = self::getsubcategories($id, $postitems);
  1153. $result .= $html->parsearg($tml, $args);
  1154. }
  1155. if ($result == '') return '';
  1156. return sprintf($html->categories(), $result);
  1157. }
  1158. public static function getcategories(array $items) {
  1159. $categories = tcategories::i();
  1160. $categories->loadall();
  1161. $html = tadminhtml::i();
  1162. $html->push_section('editor');
  1163. $result = $html->categorieshead();
  1164. $result .= self::getsubcategories(0, $items);
  1165. $html->pop_section();
  1166. return str_replace("'", '"', $result);
  1167. }
  1168. public static function getcombocategories(array $items, $idselected) {
  1169. $result = '';
  1170. $categories = tcategories::i();
  1171. $categories->loadall();
  1172. if (count($items) == 0) $items = array_keys($categories->items);
  1173. foreach ($items as $id) {
  1174. $result .= sprintf('<option value="%s" %s>%s</option>', $id, $id == $idselected ? 'selected' : '', tadminhtml::specchars($categories->getvalue($id, 'title')));
  1175. }
  1176. return $result;
  1177. }
  1178. protected function getpostcategories(tpost $post) {
  1179. $postitems = $post->categories;
  1180. $categories = tcategories::i();
  1181. if (count($postitems) == 0) $postitems = array($categories->defaultid);
  1182. return self::getcategories($postitems);
  1183. }
  1184. public function getfileperm() {
  1185. return litepublisher::$options->show_file_perm ? tadminperms::getcombo(0, 'idperm_upload') : '';
  1186. }
  1187. // $posteditor.files in template editor
  1188. public function getfilelist() {
  1189. $html = tadminhtml::i();
  1190. $html->push_section('editor');
  1191. $args = new targs();
  1192. $args->fileperm = $this->getfileperm();
  1193. $post = ttheme::$vars['post'];
  1194. $files = tfiles::i();
  1195. $where = litepublisher::$options->ingroup('editor') ? '' : ' and author = ' . litepublisher::$options->user;
  1196. $args->pages = (int) ceil($files->db->getcount(" parent = 0 $where") / 20);
  1197. $args->jsitems = '{}';
  1198. $args->files = '';
  1199. if ($post->id) {
  1200. $list = $files->itemsposts->getitems($post->id);
  1201. if (count($list)) {
  1202. $items = implode(',', $list);
  1203. $args->files = $items;
  1204. if (defined('JSON_NUMERIC_CHECK')) {
  1205. $jsattr = JSON_NUMERIC_CHECK | (defined('JSON_UNESCAPED_UNICODE') ? JSON_UNESCAPED_UNICODE : 0);
  1206. $args->jsitems = json_encode($files->db->res2items($files->db->query("select * from $files->thistable where id in ($items) or parent in ($items)")), $jsattr);
  1207. } else {
  1208. $args->jsitems = json_encode($files->db->res2items($files->db->query("select * from $files->thistable where id in ($items) or parent in ($items)")));
  1209. }
  1210. }
  1211. }
  1212. $result = $html->filelist($args);
  1213. $html->pop_section();
  1214. return $result;
  1215. }
  1216. public function canrequest() {
  1217. tlocal::admin()->searchsect[] = 'editor';
  1218. $this->isauthor = false;
  1219. $this->basename = 'editor';
  1220. $this->idpost = $this->idget();
  1221. if ($this->idpost > 0) {
  1222. $posts = tposts::i();
  1223. if (!$posts->itemexists($this->idpost)) return 404;
  1224. }
  1225. $post = tpost::i($this->idpost);
  1226. if (!litepublisher::$options->hasgroup('editor')) {
  1227. if (litepublisher::$options->hasgroup('author')) {
  1228. $this->isauthor = true;
  1229. if (($post->id != 0) && (litepublisher::$options->user != $post->author)) return 403;
  1230. }
  1231. }
  1232. }
  1233. public function gettitle() {
  1234. if ($this->idpost == 0){
  1235. return parent::gettitle();
  1236. } else {
  1237. if (isset(tlocal::admin()->ini[$this->name]['editor'])) return tlocal::get($this->name, 'editor');
  1238. return tlocal::get('editor', 'editor');
  1239. }
  1240. }
  1241. public function getexternal() {
  1242. $this->basename = 'editor';
  1243. $this->idpost = 0;
  1244. return $this->getcontent();
  1245. }
  1246. public function getpostargs(tpost $post, targs $args) {
  1247. $args->id = $post->id;
  1248. $args->ajax = tadminhtml::getadminlink('/admin/ajaxposteditor.htm', "id=$post->id&get");
  1249. $args->title = tcontentfilter::unescape($post->title);
  1250. $args->categories = $this->getpostcategories($post);
  1251. $args->date = $post->posted;
  1252. $args->url = $post->url;
  1253. $args->title2 = $post->title2;
  1254. $args->keywords = $post->keywords;
  1255. $args->description = $post->description;
  1256. $args->head = $post->rawhead;
  1257. $args->raw = $post->rawcontent;
  1258. $args->filtered = $post->filtered;
  1259. $args->excerpt = $post->excerpt;
  1260. $args->rss = $post->rss;
  1261. $args->more = $post->moretitle;
  1262. $args->upd = '';
  1263. }
  1264. public function getcontent() {
  1265. $html = $this->html;
  1266. $post = tpost::i($this->idpost);
  1267. ttheme::$vars['post'] = $post;
  1268. ttheme::$vars['posteditor'] = $this;
  1269. $args = new targs();
  1270. $this->getpostargs($post, $args);
  1271. $result = $post->id == 0 ? '' : $html->h4($this->lang->formhead . ' ' . $post->bookmark);
  1272. if ($this->isauthor &&($r = tauthor_rights::i()->getposteditor($post, $args))) return $r;
  1273. $result .= $html->form($args);
  1274. unset(ttheme::$vars['post'], ttheme::$vars['posteditor']);
  1275. return $html->fixquote($result);
  1276. }
  1277. public static function processcategories() {
  1278. return tadminhtml::check2array('category-');
  1279. }
  1280. protected function set_post(tpost $post) {
  1281. extract($_POST, EXTR_SKIP);
  1282. $post->title = $title;
  1283. $cats = self::processcategories();
  1284. $cats = array_unique($cats);
  1285. array_delete_value($cats, 0);
  1286. array_delete_value($cats, '');
  1287. array_delete_value($cats, false);
  1288. array_delete_value($cats, null);
  1289. $post->categories= $cats;
  1290. if (($post->id == 0) && (litepublisher::$options->user >1)) $post->author = litepublisher::$options->user;
  1291. if (isset($tags)) $post->tagnames = $tags;
  1292. if (isset($icon)) $post->icon = (int) $icon;
  1293. if (isset($idview)) $post->idview = $idview;
  1294. if (isset($files)) {
  1295. $files = trim($files, ', ');
  1296. $post->files = tdatabase::str2array($files);
  1297. }
  1298. if (isset($date) && $date) {
  1299. $post->posted = tadminhtml::getdatetime('date');
  1300. }
  1301. if (isset($status)) {
  1302. $post->status = $status == 'draft' ? 'draft' : 'published';
  1303. $post->comstatus = $comstatus;
  1304. $post->pingenabled = isset($pingenabled);
  1305. $post->idperm = (int) $idperm;
  1306. if ($password != '') $post->password = $password;
  1307. }
  1308. if (isset($url)) {
  1309. $post->url = $url;
  1310. $post->title2 = $title2;
  1311. $post->keywords = $keywords;
  1312. $post->description = $description;
  1313. $post->rawhead = $head;
  1314. }
  1315. $post->content = $raw;
  1316. if (isset($excerpt)) $post->excerpt = $excerpt;
  1317. if (isset($rss)) $post->rss = $rss;
  1318. if (isset($more)) $post->moretitle = $more;
  1319. if (isset($filtered)) $post->filtered = $filtered;
  1320. if (isset($upd)) {
  1321. $update = sprintf($this->lang->updateformat, tlocal::date(time()), $upd);
  1322. $post->content = $post->rawcontent . "\n\n" . $update;
  1323. }
  1324. }
  1325. public function processform() {
  1326. //dumpvar($_POST);
  1327. $this->basename = 'editor';
  1328. $html = $this->html;
  1329. if (empty($_POST['title'])) return $html->h2->emptytitle;
  1330. $id = (int)$_POST['id'];
  1331. $post = tpost::i($id);
  1332. if ($this->isauthor &&($r = tauthor_rights::i()->editpost($post))) {
  1333. $this->idpost = $post->id;
  1334. return $r;
  1335. }
  1336. $this->set_post($post);
  1337. $posts = tposts::i();
  1338. if ($id == 0) {
  1339. $this->idpost = $posts->add($post);
  1340. $_POST['id'] = $this->idpost;
  1341. } else {
  1342. $posts->edit($post);
  1343. }
  1344. $_GET['id'] = $this->idpost;
  1345. return sprintf($html->p->success,$post->bookmark);
  1346. }
  1347. }//class
  1348. class poststatus {
  1349. public function __get($name) {
  1350. $post = ttheme::$vars['post'];
  1351. $value = $post->{$name};
  1352. $lang = tlocal::i();
  1353. return $lang->{$value};
  1354. }
  1355. }
  1356. ?>