PageRenderTime 30ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/post.php

http://lazycms.googlecode.com/
PHP | 690 lines | 631 code | 9 blank | 50 comment | 23 complexity | 9de33c0f07c44c9e8fd604c723e3a9f1 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1
  1. <?php
  2. /**
  3. * +---------------------------------------------------------------------------+
  4. * | LL LLLL LL L LLLL LLLL |
  5. * | LL LL L LLL LL LL L LL LL |
  6. * | LL LLLL LLLLL LL LL LL LLLL LLL LL LL LL LL |
  7. * | LL LL LL LL LL LL L LLL LL LLLLL LL LL LL |
  8. * | LL LLLLL LL LLLL LL L L LL LLLLL LL LL LL |
  9. * | LL LL LL LL LLLL LL L LL LL LLLL LL |
  10. * | LL LL LL LL LL LL L L LL L LL LLLL LL |
  11. * | LLLLLL LLLLL LLLLL LL LLLL L LL LLLL LL LLLLLL |
  12. * | LL |
  13. * | LL |
  14. * +---------------------------------------------------------------------------+
  15. * | Copyright (C) 2007-2010 LazyCMS.com All rights reserved. |
  16. * +---------------------------------------------------------------------------+
  17. * | LazyCMS is free software. See LICENSE for copyright notices and details. |
  18. * +---------------------------------------------------------------------------+
  19. */
  20. // ???
  21. $php_file = isset($php_file) ? $php_file : 'post.php';
  22. // ??????
  23. include dirname(__FILE__).'/admin.php';
  24. // ???????
  25. $_USER = user_current();
  26. // ??
  27. $method = isset($_REQUEST['method'])?$_REQUEST['method']:null;
  28. switch ($method) {
  29. // ????
  30. case 'new':
  31. if ('page.php' == $php_file) {
  32. system_head('title',__('Add New Page'));
  33. current_user_can('page-new');
  34. } else {
  35. system_head('title',__('Add New Post'));
  36. current_user_can('post-new');
  37. }
  38. system_head('styles', array('css/post','css/xheditor','css/datePicker'));
  39. system_head('scripts',array('js/post','js/xheditor','js/datePicker'));
  40. system_head('jslang',system_editor_lang());
  41. system_head('jslang',array(
  42. 'Please enter the title or content!' => __('Please enter the title or content!'),
  43. ));
  44. system_head('loadevents', 'post_manage_init');
  45. include ADMIN_PATH.'/admin-header.php';
  46. post_manage_page('add');
  47. include ADMIN_PATH.'/admin-footer.php';
  48. break;
  49. // ??
  50. case 'edit':
  51. if ('page.php' == $php_file) {
  52. // ??
  53. $parent_file = 'page.php';
  54. // ????
  55. system_head('title',__('Edit Page'));
  56. // ????
  57. current_user_can('page-edit');
  58. } else {
  59. // ??
  60. $parent_file = 'post.php';
  61. // ????
  62. system_head('title',__('Edit Post'));
  63. // ????
  64. current_user_can('post-edit');
  65. }
  66. system_head('styles', array('css/post','css/xheditor','css/datePicker'));
  67. system_head('scripts',array('js/post','js/xheditor','js/datePicker'));
  68. system_head('jslang',system_editor_lang());
  69. system_head('jslang',array(
  70. 'Please enter the title or content!' => __('Please enter the title or content!'),
  71. ));
  72. system_head('loadevents', 'post_manage_init');
  73. include ADMIN_PATH.'/admin-header.php';
  74. post_manage_page('edit');
  75. include ADMIN_PATH.'/admin-footer.php';
  76. break;
  77. // ????
  78. case 'bulk':
  79. $action = isset($_POST['action'])?$_POST['action']:null;
  80. $listids = isset($_POST['listids'])?$_POST['listids']:null;
  81. if (empty($listids)) {
  82. ajax_error(__('Did not select any item.'));
  83. }
  84. switch ($action) {
  85. case 'create':
  86. foreach ($listids as $postid) {
  87. post_create($postid);
  88. }
  89. ajax_success(__('Posts created.'),"LazyCMS.redirect('".referer()."');");
  90. break;
  91. case 'delete':
  92. current_user_can('post-delete');
  93. foreach ($listids as $postid) {
  94. post_delete($postid);
  95. }
  96. ajax_success(__('Posts deleted.'),"LazyCMS.redirect('".referer()."');");
  97. break;
  98. default:
  99. ajax_alert(__('Parameter is invalid.'));
  100. break;
  101. }
  102. break;
  103. // ??
  104. case 'save':
  105. $postid = isset($_POST['postid'])?$_POST['postid']:0;
  106. current_user_can($postid?'post-edit':'post-new');
  107. if (validate_is_post()) {
  108. $referer = referer(PHP_FILE,false);
  109. $mcode = isset($_POST['model'])?$_POST['model']:null;
  110. $model = model_get_bycode($mcode);
  111. $create = isset($_POST['create'])?$_POST['create']:array();
  112. $comments = isset($_POST['comments'])?$_POST['comments']:'No';
  113. $listid = isset($_POST['listid'])?$_POST['listid']:0;
  114. $type = isset($_POST['type'])?$_POST['type']:'page';
  115. $category = isset($_POST['category'])?$_POST['category']:array();
  116. $title = isset($_POST['title'])?$_POST['title']:null;
  117. $autokeys = isset($_POST['autokeys'])?$_POST['autokeys']:null;
  118. $path = isset($_POST['path'])?$_POST['path']:null;
  119. $content = isset($_POST['content'])?$_POST['content']:null;
  120. $template = isset($_POST['template'])?$_POST['template']:null;
  121. $keywords = isset($_POST['keywords'])?$_POST['keywords']:null;
  122. $description = isset($_POST['description'])?$_POST['description']:null;
  123. if ('post.php' == $php_file) {
  124. validate_check('listid',VALIDATE_EMPTY,_x('Please select a main category.','post'));
  125. }
  126. validate_check(array(
  127. array('title',VALIDATE_EMPTY,_x('The title field is empty.','post')),
  128. array('title',VALIDATE_LENGTH,_x('The title field length must be %d-%d characters.','post'),1,255),
  129. ));
  130. // ????
  131. $path_exists = post_path_exists($postid,path_format($path,array('PY'=>$title)));
  132. validate_check(array(
  133. array('path',VALIDATE_EMPTY,_x('The path field is empty.','post')),
  134. array('path',VALIDATE_IS_PATH,sprintf(_x('The path can not contain any of the following characters %s','post'),esc_html('* : < > | \\'))),
  135. array('path',(!$path_exists),_x('The path already exists.','post')),
  136. ));
  137. // ??????
  138. if (empty($description)) {
  139. $description = mb_substr(clear_space(strip_tags($content)),0,250,'UTF-8');
  140. } else {
  141. validate_check(array(
  142. array('description',VALIDATE_LENGTH,__('Description the field up to 255 characters.'),0,255),
  143. ));
  144. }
  145. // ????????
  146. if ($model['fields']) {
  147. foreach($model['fields'] as $field) {
  148. if (empty($field['v'])) continue;
  149. $last_rules = array();
  150. $rules = explode("\n",$field['v']);
  151. foreach($rules as $rule) {
  152. if (strpos($rule,'|')===false) continue;
  153. $VRS = explode('|',rtrim($rule,';')); array_unshift($VRS,$field['_n']);
  154. $last_rules[] = $VRS;
  155. }
  156. validate_check($last_rules);
  157. }
  158. }
  159. // ?????????????
  160. if (validate_is_ok()) {
  161. // ??????
  162. if (isset($_POST['LocalizedImages'])) {
  163. // ????????
  164. if (isset($_POST['LocalizedImages']['content']) && $_POST['LocalizedImages']['content']) {
  165. $content = media_localized_images($content); unset($_POST['LocalizedImages']['content']);
  166. }
  167. // ?????????
  168. foreach((array)$_POST['LocalizedImages'] as $field=>$v) {
  169. if ($v) {
  170. $_POST[$field] = media_localized_images($_POST[$field]);
  171. }
  172. }
  173. }
  174. // ????
  175. $path = esc_html(rtrim($path,'/'));
  176. // ???????
  177. if ($autokeys && empty($keywords)) {
  178. $keywords = term_gets($title, $content);
  179. }
  180. // ?????
  181. if ($listid > 0) {
  182. array_unshift($category,$listid);
  183. }
  184. // ????
  185. $data = array(
  186. 'listid' => $listid,
  187. 'type' => $type,
  188. 'category' => $category,
  189. 'model' => esc_html($mcode),
  190. 'template' => esc_html($template),
  191. 'keywords' => esc_html($keywords),
  192. 'comments' => $comments,
  193. 'description' => esc_html($description),
  194. );
  195. $post_data = $content;
  196. // ???????
  197. if ($model['fields']) {
  198. foreach($model['fields'] as $field) {
  199. // ????????
  200. if (isset($_POST[$field['_n']]) && $_POST[$field['_n']]) {
  201. $data['meta'][$field['n']] = instr($field['t'],'basic,editor') ? $_POST[$field['_n']] : esc_html($_POST[$field['_n']]);
  202. if (is_scalar($data['meta'][$field['n']]) && strlen($data['meta'][$field['n']]) > 40)
  203. $post_data.= $data['meta'][$field['n']];
  204. }
  205. }
  206. }
  207. // ?????????
  208. if (preg_match_all('/([a-z\d]{40})\.[a-zA-Z\d]+/', $post_data, $matchs)) {
  209. $data['meta']['__medias__'] = array();
  210. foreach ($matchs[1] as $sha1) {
  211. if ($media = media_get($sha1)) {
  212. $data['meta']['__medias__'][] = $media['mediaid'];
  213. }
  214. }
  215. // ????
  216. $data['meta']['__medias__'] = array_unique($data['meta']['__medias__']);
  217. }
  218. // ??
  219. if ($postid) {
  220. $data['path'] = esc_html($path);
  221. $data['title'] = esc_html($title);
  222. $data['content'] = $content;
  223. post_edit($postid,$data);
  224. $result = __('Post updated.');
  225. }
  226. // ????
  227. else {
  228. $data['author'] = esc_html($_USER['name']);
  229. $data['userid'] = $_USER['userid'];
  230. if ($post = post_add($title,$content,$path,$data)) {
  231. $postid = $post['postid'];
  232. }
  233. $result = __('Post created.');
  234. }
  235. // ????
  236. if (instr('lists',$create)) {
  237. publish_add(sprintf(__('Create Lists:%s'),taxonomy_get_names($category)),'publish_lists',array($category,false));
  238. }
  239. // ???????
  240. if (instr('pages',$create)) {
  241. publish_add(__('Create all Pages'),'publish_posts',array('pages'));
  242. }
  243. // ????
  244. if (post_create($postid,$preid)) {
  245. // ???????
  246. if ($preid) post_create($preid);
  247. // ???? sitemaps
  248. if ('page.php' == $php_file) {
  249. publish_page_sitemaps();
  250. }
  251. $result = sprintf('<p>%s</p><p>%s</p>', $result, _x('[Submit] to Add New<br />[Cancel] to Back list','post'));
  252. ajax_confirm($result, "LazyCMS.redirect('".PHP_FILE."?method=new&category={$listid}');", "LazyCMS.redirect('".$referer."');");
  253. } else {
  254. ajax_alert($result.__('File create failed.'),"LazyCMS.redirect('".$referer."');");
  255. }
  256. }
  257. }
  258. break;
  259. // ??????
  260. case 'extend-attr':
  261. $model = null; $hl = '';
  262. $mcode = isset($_REQUEST['model'])?$_REQUEST['model']:null;
  263. $postid = isset($_REQUEST['postid'])?$_REQUEST['postid']:0;
  264. $suffix = C('HTML-Ext');
  265. if ($postid) {
  266. $post = post_get($postid);
  267. }
  268. if ($mcode) {
  269. $model = model_get_bycode($mcode);
  270. $path = isset($post['path'])?$post['path']:$model['path'];
  271. } else {
  272. $path = isset($post['path'])?$post['path']:'%PY'.$suffix;
  273. }
  274. header('X-LazyCMS-Path: '.$path);
  275. if ($model) {
  276. foreach ($model['fields'] as $field) {
  277. if (isset($post['meta'][$field['n']])) {
  278. $field['d'] = $post['meta'][$field['n']];
  279. }
  280. $hl.= '<tr>';
  281. $hl.= '<th><label for="'.$field['_n'].'">'.$field['l'];
  282. if (!empty($field['h'])) {
  283. $hl.= '<span class="resume">'.$field['h'].'</span>';
  284. }
  285. $hl.= '</label>';
  286. $hl.= '</th>';
  287. $hl.= '<td>'.model_field2html($field).'</td>';
  288. $hl.= '</tr>';
  289. }
  290. }
  291. ajax_return($hl);
  292. break;
  293. default:
  294. if ('page.php' == $php_file) {
  295. system_head('title', __('Pages'));
  296. current_user_can('page-list');
  297. $add_new = _x('Add New','page');
  298. } else {
  299. system_head('title', __('Posts'));
  300. current_user_can('post-list');
  301. $add_new = _x('Add New','post');
  302. }
  303. system_head('styles', array('css/post'));
  304. system_head('scripts',array('js/post'));
  305. system_head('loadevents','post_list_init');
  306. $model = isset($_REQUEST['model'])?$_REQUEST['model']:'';
  307. $search = isset($_REQUEST['query'])?$_REQUEST['query']:'';
  308. $category = isset($_REQUEST['category'])?$_REQUEST['category']:null;
  309. $query = array('page' => '$');
  310. $add_args = array('method' => 'new');
  311. // ????
  312. $order = 'page.php'==$php_file ? 'ASC' : 'DESC';
  313. $conditions = array();
  314. // ??????
  315. if ($search || $category) {
  316. if ('page.php' == $php_file) {
  317. $where = "WHERE `p`.`type`='page'";
  318. } else {
  319. $where = "WHERE `p`.`type`='post'";
  320. }
  321. if ($category) {
  322. $query['category'] = $category; $add_args['category'] = $category;
  323. $where.= sprintf(" AND (`tr`.`taxonomyid`=%d)", esc_sql($category));
  324. }
  325. if ($search) {
  326. $query['query'] = $search;
  327. $fields = array('title','content','description');
  328. foreach($fields as $field) {
  329. $conditions[] = sprintf("BINARY UCASE(`p`.`%s`) LIKE UCASE('%%%s%%')",$field,esc_sql($search));
  330. }
  331. $where.= ' AND ('.implode(' OR ', $conditions).')';
  332. }
  333. $sql = "SELECT DISTINCT(`p`.`postid`) FROM `#@_post` AS `p` LEFT JOIN `#@_term_relation` AS `tr` ON `p`.`postid`=`tr`.`objectid` {$where} ORDER BY `p`.`postid` {$order}";
  334. } else {
  335. if ('page.php' == $php_file) {
  336. $conditions[] = "`type`='page'";
  337. } else {
  338. $conditions[] = "`type`='post'";
  339. }
  340. // ??????
  341. if ($model) {
  342. $query['model'] = $model;
  343. $conditions[] = sprintf("`model` = '%s'",esc_sql($model));
  344. }
  345. // ????????
  346. $where = ' WHERE '.implode(' AND ' , $conditions);
  347. $sql = "SELECT `postid` FROM `#@_post` {$where} ORDER BY `postid` {$order}";
  348. }
  349. $result = pages_query($sql);
  350. // ????
  351. $page_url = PHP_FILE.'?'.http_build_query($query);
  352. include ADMIN_PATH.'/admin-header.php';
  353. echo '<div class="wrap">';
  354. echo '<h2>'.system_head('title').'<a class="button" href="'.PHP_FILE.'?'.http_build_query($add_args).'">'.$add_new.'</a></h2>';
  355. echo '<form header="POST '.PHP_FILE.'?method=bulk" action="'.PHP_FILE.'" method="get" name="postlist" id="postlist">';
  356. table_nav('top',$page_url);
  357. echo '<table class="data-table" cellspacing="0">';
  358. echo '<thead>';
  359. table_thead();
  360. echo '</thead>';
  361. echo '<tfoot>';
  362. table_thead();
  363. echo '</tfoot>';
  364. echo '<tbody>';
  365. if ($result) {
  366. while ($data = pages_fetch($result)) {
  367. $post = post_get($data['postid']);
  368. $edit_url = PHP_FILE.'?method=edit&postid='.$post['postid'];
  369. $post['count'] = comment_count($post['postid']);
  370. // ?????????
  371. $post['path'] = post_get_path($post['listid'],$post['path']);
  372. if (is_file(ABS_PATH.'/'.$post['path'])) {
  373. $browse = get_icon('b6').'<a href="'.ROOT.$post['path'].'" target="_blank">'.ROOT.$post['path'].'</a>';
  374. } else {
  375. $browse = get_icon('b7').'<a href="javascript:;" onclick="post_create('.$post['postid'].')">'.ROOT.$post['path'].'</a>';
  376. }
  377. $actions = '<span class="edit"><a href="'.$edit_url.'">'.__('Edit').'</a> | </span>';
  378. $actions.= '<span class="create"><a href="javascript:;" onclick="post_create('.$post['postid'].')">'.__('Create').'</a> | </span>';
  379. $actions.= '<span class="delete"><a href="javascript:;" onclick="post_delete('.$post['postid'].')">'.__('Delete').'</a> | </span>';
  380. $actions.= '<span class="browse">'.$browse.'</span>';
  381. echo '<tr>';
  382. echo '<td class="check-column"><input type="checkbox" name="listids[]" value="'.$post['postid'].'" /></td>';
  383. echo '<td><strong><a href="'.$edit_url.'">'.$post['title'].'</a></strong><br/><div class="row-actions">'.$actions.'</div></td>';
  384. if (empty($post['model'])) {
  385. echo '<td>'.__('None').'</td>';
  386. } else {
  387. $post['model'] = model_get_bycode($post['model']);
  388. echo '<td><a href="'.PHP_FILE.'?model='.$post['model']['langcode'].'">'.$post['model']['name'].'</a></td>';
  389. }
  390. if ('post.php' == $php_file) {
  391. $categories = array();
  392. foreach(post_get_taxonomy($post['category']) as $taxonomyid=>$category) {
  393. $categories[] = '<a href="'.PHP_FILE.'?category='.$taxonomyid.'">'.$category.'</a>';
  394. }
  395. echo empty($categories) ? '<td>'.__('None').'</td>' : '<td>'.implode(',' , $categories).'</td>';
  396. }
  397. $tags = array();
  398. foreach(post_get_taxonomy($post['keywords']) as $keyid=>$keyword) {
  399. $tags[] = '<a href="'.PHP_FILE.'?category='.$keyid.'">'.$keyword.'</a>';
  400. }
  401. echo empty($tags) ? '<td>'.__('None').'</td>' : '<td>'.implode(',' , $tags).'</td>';
  402. echo '<td><a class="comment-count'.($post['count']?' exist':'').'" href="'.ADMIN.'comment.php?p='.$post['postid'].'"><span>'.$post['count'].'</span></a></td>';
  403. echo '<td><div title="'.date('Y-m-d H:i:s',$post['datetime']).'">'.date('Y-m-d',$post['datetime']).'</div></td>';//'.get_icon($post['approved']).'
  404. echo '</tr>';
  405. }
  406. } else {
  407. echo '<tr><td colspan="7" class="tc">'.__('No record!').'</td></tr>';
  408. }
  409. echo '</tbody>';
  410. echo '</table>';
  411. table_nav('bottom',$page_url);
  412. echo '</form>';
  413. echo '</div>';
  414. include ADMIN_PATH.'/admin-footer.php';
  415. break;
  416. }
  417. /**
  418. * ????
  419. *
  420. * @param $side top|bottom
  421. * @param $url
  422. * @return void
  423. */
  424. function table_nav($side,$url) {
  425. global $php_file, $category, $search;
  426. echo '<div class="table-nav">';
  427. echo '<select name="actions">';
  428. echo '<option value="">'.__('Bulk Actions').'</option>';
  429. echo '<option value="create">'.__('Create').'</option>';
  430. echo '<option value="delete">'.__('Delete').'</option>';
  431. echo '</select>';
  432. echo '<button type="button">'.__('Apply').'</button>';
  433. if ($side == 'top') {
  434. echo '<span class="filter">';
  435. if ('post.php' == $php_file) {
  436. echo '<select name="category">';
  437. echo '<option value="">'.__('View all categories').'</option>';
  438. echo dropdown_categories($category);
  439. echo '</select>';
  440. }
  441. echo '<input class="text" type="text" size="20" name="query" value="'.esc_html($search).'" />';
  442. echo '<button type="submit">'.__('Filter').'</button>';
  443. echo '</span>';
  444. }
  445. if ($side == 'bottom') {
  446. echo pages_list($url);
  447. }
  448. echo '</div>';
  449. }
  450. /**
  451. * ??
  452. *
  453. */
  454. function table_thead() {
  455. global $php_file;
  456. echo '<tr>';
  457. echo '<th class="check-column"><input type="checkbox" name="select" value="all" /></th>';
  458. echo '<th>'._x('Title','post').'</th>';
  459. echo '<th class="w100">'._x('Model','post').'</th>';
  460. if ('post.php' == $php_file) {
  461. echo '<th class="wp15">'._x('Categories','post').'</th>';
  462. }
  463. echo '<th class="wp15">'._x('Tags','post').'</th>';
  464. echo '<th class="w50">'.get_icon('c9').'</th>';
  465. echo '<th class="w100">'._x('Date','post').'</th>';
  466. echo '</tr>';
  467. }
  468. /**
  469. * ????
  470. *
  471. * @param string $action
  472. */
  473. function post_manage_page($action) {
  474. global $php_file; $trees = null;
  475. $referer = referer(PHP_FILE);
  476. if ('post.php' == $php_file) {
  477. $trees = taxonomy_get_trees();
  478. if (empty($trees)) {
  479. echo '<div class="wrap">';
  480. echo '<h2>'.system_head('title').'</h2>';
  481. echo '<fieldset>';
  482. echo '<table class="form-table">';
  483. echo '<tbody>';
  484. echo '<tr><td>'.__('Please Add Category!').'</td></tr>';
  485. echo '<tr><td class="buttons"><button type="button" onclick="LazyCMS.redirect(\''.ADMIN.'categories.php?method=new\')">'._x('Add New','sort').'</button><button type="button" onclick="LazyCMS.redirect(\''.$referer.'\')">'.__('Back').'</button></td></tr>';
  486. echo '</tbody>';
  487. echo '</table>';
  488. echo '</fieldset>';
  489. echo '</div>';
  490. return true;
  491. }
  492. }
  493. $postid = isset($_GET['postid'])?$_GET['postid']:0;
  494. $models = model_gets('Post', 'enabled');
  495. $suffix = C('HTML-Ext');
  496. if ($action=='add') {
  497. $mcode = isset($_GET['model'])?$_GET['model']:null;
  498. $listid = isset($_GET['category'])?$_GET['category']:null;
  499. } else {
  500. $_DATA = post_get($postid);
  501. $mcode = $_DATA['model'];
  502. $listid = isset($_DATA['listid'])?$_DATA['listid']:null;
  503. }
  504. $model = $mcode ? model_get_bycode($mcode) : ('post.php'==$php_file ? array_pop(array_slice($models,0,1)) : null);
  505. $title = isset($_DATA['title'])?$_DATA['title']:null;
  506. $path = isset($_DATA['path'])?$_DATA['path']:$model['path'];
  507. $content = isset($_DATA['content'])?$_DATA['content']:null;
  508. $comments = isset($_DATA['comments'])?$_DATA['comments']:'Yes';
  509. $template = isset($_DATA['template'])?$_DATA['template']:null;
  510. $keywords = isset($_DATA['keywords'])?post_get_taxonomy($_DATA['keywords'], true):null;
  511. $categories = isset($_DATA['category'])?$_DATA['category']:array();
  512. $description = isset($_DATA['description'])?$_DATA['description']:null;
  513. echo '<div class="wrap">';
  514. echo '<h2>'.system_head('title').'</h2>';
  515. echo '<form action="'.PHP_FILE.'?method=save" method="post" name="postmanage" id="postmanage">';
  516. echo '<fieldset>';
  517. echo '<table class="form-table">';
  518. echo '<tbody>';
  519. if ($models) {
  520. echo '<tr>';
  521. echo '<th><label for="model">'._x('Model','post').'</label></th>';
  522. echo '<td><select name="model" id="model"'.($action=='add' ? ' cookie="true"' : '').'>';
  523. echo 'page.php'==$php_file ? '<option value="">' . __('&mdash; No Model &mdash;') . '</option>' : '';
  524. foreach ($models as $m) {
  525. $selected = isset($model['langcode']) && $m['langcode']==$model['langcode']?' selected="selected"':'';
  526. echo '<option value="'.$m['langcode'].'"'.$selected.'>'.$m['name'].'</option>';
  527. }
  528. echo '</select></td>';
  529. echo '</tr>';
  530. }
  531. $hidden = '';
  532. if ('page.php' == $php_file) {
  533. $hidden = '<input type="hidden" name="type" value="page" />';
  534. } else {
  535. $hidden = '<input type="hidden" name="type" value="post" />';
  536. echo '<tr class="taxonomyid">';
  537. echo '<th><label for="taxonomyid">'._x('Categories','post').'</label></th>';
  538. echo '<td>';
  539. echo display_ul_categories($listid,$categories,$trees);
  540. echo '</td>';
  541. echo '</tr>';
  542. }
  543. echo '<tr>';
  544. echo '<th><label for="title">'._x('Title','post').'<span class="resume">'.__('(required)').'</span></label></th>';
  545. echo '<td>';
  546. echo '<input class="text" id="title" name="title" type="text" size="70" value="'.$title.'" />';
  547. echo '&nbsp;<label for="autokeys"><input type="checkbox" value="1" id="autokeys" name="autokeys" checked="checked" cookie="true">'.__('Auto get keywords').'</label>';
  548. echo '</td>';
  549. echo '</tr>';
  550. echo '<tr>';
  551. echo '<th><label for="content">'._x('Content','post').'</label></th>';
  552. echo '<td>'.editor('content', $content).'</td>';
  553. echo '</tr>';
  554. echo '</tbody>';
  555. echo '<tbody class="extend-attr"></tbody>';
  556. echo '<tbody>';
  557. echo '<tr>';
  558. echo '<th><label for="path">'._x('Path','post').'<span class="resume">'.__('(required)').'</span></label></th>';
  559. echo '<td><input class="text" id="path" name="path" type="text" size="80" value="'.$path.'" /><div class="rules">';
  560. echo '<a href="#%ID'.$suffix.'">['.__('Post ID').']</a>';
  561. echo '<a href="#%MD5'.$suffix.'">['.__('MD5 Value').']</a>';
  562. echo '<a href="#%PY'.$suffix.'">['.__('Pinyin').']</a>';
  563. echo '<a href="#%Y" title="%Y">['.strftime('%Y').']</a>';
  564. echo '<a href="#%m" title="%m">['.strftime('%m').']</a>';
  565. echo '<a href="#%d" title="%d">['.strftime('%d').']</a>';
  566. echo '<a href="#%a" title="%a">['.strftime('%a').']</a>';
  567. echo '</div></td>';
  568. echo '</tr>';
  569. echo '</tbody>';
  570. echo '</table>';
  571. echo '</fieldset>';
  572. echo '<fieldset cookie="true">';
  573. echo '<a href="javascript:;" class="toggle" title="'.__('Click to toggle').'"><br/></a>';
  574. echo '<h3>'.__('More attribute').'</h3>';
  575. echo '<table class="form-table">';
  576. echo '<tbody>';
  577. echo '<tr>';
  578. echo '<th><label for="template">'._x('Page Template','post').'</label></th>';
  579. echo '<td>';
  580. echo '<select id="template" name="template">';
  581. echo $trees ? '<option value="">'.__('Use the category set').'</option>' : '';
  582. echo $models && 'page.php'==$php_file ? '<option value="">'.__('Use the model set').'</option>' : '';
  583. echo options(system_themes_path(),C('TPL-Exts'),'<option value="#value#"#selected#>#name#</option>',$template);
  584. echo '</select>';
  585. echo '</td>';
  586. echo '</tr>';
  587. echo '<tr>';
  588. echo '<th><label for="keywords">'._x('Keywords','post').'</label></th>';
  589. echo '<td><input class="text" type="text" size="70" name="keywords" id="keywords" value="'.$keywords.'" />&nbsp;<button type="button" rel="keywords">'.__('Get').'</button></td>';
  590. echo '</tr>';
  591. echo '<tr>';
  592. echo '<th><label for="description">'._x('Description','post').'<br /><span class="resume">'.__('(Maximum of 250)').'</span></label></th>';
  593. echo '<td><textarea class="text" cols="70" rows="5" id="description" name="description">'.$description.'</textarea></td>';
  594. echo '</tr>';
  595. echo '<tr>';
  596. echo '<th><label>'._x('Other','post').'</label></th>';
  597. echo '<td>';
  598. echo '<label for="comments"><input type="checkbox" name="comments" value="Yes" id="comments"'.($comments=='Yes'?' checked="checked"':'').' />'.__('Allow Comments').'</label>';
  599. if ('post.php' == $php_file) {
  600. echo '<label for="createpages"><input type="checkbox" name="create[]" value="pages" id="createpages" cookie="true" />'.__('Update all Pages').'</label>';
  601. echo '<label for="createlists"><input type="checkbox" name="create[]" value="lists" id="createlists" cookie="true" />'.__('Update Category Lists').'</label>';
  602. }
  603. echo '</td>';
  604. echo '</tr>';
  605. echo '</tbody>';
  606. echo '</table>';
  607. echo '</fieldset>';
  608. echo '<p class="submit">';
  609. if ($action=='add') {
  610. echo '<button type="submit">'.__('Add Post').'</button>'.$hidden;
  611. } else {
  612. $hidden.= '<input type="hidden" name="postid" value="'.$postid.'" />';
  613. $hidden.= '<input type="hidden" name="referer" value="'.referer().'" />';
  614. echo '<button type="submit">'.__('Update Post').'</button>'.$hidden;
  615. }
  616. echo '<button type="button" onclick="LazyCMS.redirect(\''.$referer.'\')">'.__('Back').'</button>';
  617. echo '</p>';
  618. echo '</form>';
  619. echo '</div>';
  620. }
  621. /**
  622. * ?????
  623. *
  624. * @param int $listid
  625. * @param array $categories
  626. * @param array $trees
  627. * @return string
  628. */
  629. function display_ul_categories($listid,$categories=array(),$trees=null) {
  630. static $func = null;
  631. $hl = sprintf('<ul %s>',is_null($func) ? 'id="listid" class="categories"' : 'class="children"');
  632. if (!$func) $func = __FUNCTION__;
  633. if ($trees === null) $trees = taxonomy_get_trees();
  634. foreach ($trees as $i=>$tree) {
  635. $checked = instr($tree['taxonomyid'],$categories) && $listid!=$tree['taxonomyid'] ? ' checked="checked"' : '';
  636. $main_checked = $tree['taxonomyid']==$listid?' checked="checked"':'';
  637. $hl.= sprintf('<li><input type="radio" name="listid" value="%d"%s />',$tree['taxonomyid'],$main_checked);
  638. $hl.= sprintf('<label class="selectit" for="category-%d">',$tree['taxonomyid']);
  639. $hl.= sprintf('<input type="checkbox" id="category-%1$d" name="category[]" value="%1$d"%3$s />%2$s</label>',$tree['taxonomyid'],$tree['name'],$checked);
  640. if (isset($tree['subs'])) {
  641. $hl.= $func($listid,$categories,$tree['subs']);
  642. }
  643. $hl.= '</li>';
  644. }
  645. $hl.= '</ul>';
  646. return $hl;
  647. }
  648. /**
  649. * ?????
  650. *
  651. * @param int $taxonomyid ????ID
  652. * @param int $selected ??????ID
  653. * @param int $n
  654. * @param array $trees
  655. * @return string
  656. */
  657. function dropdown_categories($selected=0, $trees=null) {
  658. static $n = 0; $func = __FUNCTION__;
  659. if ($trees===null) $trees = taxonomy_get_trees();
  660. $hl = ''; $space = str_repeat('&nbsp; &nbsp; ',$n); $n++;
  661. foreach ($trees as $tree) {
  662. $sel = $selected==$tree['taxonomyid']?' selected="selected"':null;
  663. $hl.= '<option value="'.$tree['taxonomyid'].'"'.$sel.' path="'.$tree['path'].'/">'.$space.'? '.$tree['name'].'</option>';
  664. if (isset($tree['subs'])) {
  665. $hl.= $func($selected,$tree['subs']);
  666. }
  667. }
  668. return $hl;
  669. }