Просмотр файла htmly-2.9.8/system/htmly.php

Размер файла: 171.36Kb
  1. <?php
  2. if (!defined('HTMLY')) die('HTMLy');
  3.  
  4. // Load the configuration file
  5. config('source', $config_file);
  6.  
  7. // Load the language file
  8. get_language();
  9.  
  10. // Set the timezone
  11. if (config('timezone')) {
  12. date_default_timezone_set(config('timezone'));
  13. } else {
  14. date_default_timezone_set('Asia/Jakarta');
  15. }
  16.  
  17. // Publish scheduled post
  18. publish_scheduled();
  19.  
  20. // The front page of the blog
  21. get('/index', function () {
  22.  
  23. if (isset($_GET['search'])) {
  24. $search = _h($_GET['search']);
  25. $url = site_url() . 'search/' . remove_accent($search);
  26. header("Location: $url");
  27. }
  28.  
  29. if (!login()) {
  30. file_cache($_SERVER['REQUEST_URI']);
  31. }
  32. $vroot = rtrim(config('views.root'), '/');
  33. $lt = $vroot . '/layout--front.html.php';
  34. if (file_exists($lt)) {
  35. $layout = 'layout--front';
  36. } else {
  37. $layout = '';
  38. }
  39. if (config('static.frontpage') == 'true') {
  40. $front = get_frontpage();
  41. $pv = $vroot . '/static--front.html.php';
  42. if (file_exists($pv)) {
  43. $pview = 'static--front';
  44. } else {
  45. $pview = 'static';
  46. }
  47. render($pview, array(
  48. 'title' => generate_title('is_front', null),
  49. 'description' => safe_html(strip_tags(blog_description())),
  50. 'canonical' => site_url(),
  51. 'metatags' => generate_meta(null, null),
  52. 'bodyclass' => 'in-front',
  53. 'breadcrumb' => '',
  54. 'p' => $front,
  55. 'static' => $front,
  56. 'type' => 'is_frontpage',
  57. 'is_front' => true
  58. ), $layout);
  59. } else {
  60. $page = from($_GET, 'page');
  61. $page = $page ? (int)$page : 1;
  62. $perpage = config('posts.perpage');
  63.  
  64. $posts = get_posts(null, $page, $perpage);
  65.  
  66. $total = '';
  67. $pv = $vroot . '/main--front.html.php';
  68. if (file_exists($pv)) {
  69. $pview = 'main--front';
  70. } else {
  71. $pview = 'main';
  72. }
  73.  
  74. if (empty($posts) || $page < 1) {
  75.  
  76. // a non-existing page
  77. render('no-posts', array(
  78. 'title' => generate_title('is_front', null),
  79. 'description' => safe_html(strip_tags(blog_description())),
  80. 'canonical' => site_url(),
  81. 'metatags' => generate_meta(null, null),
  82. 'breadcrumb' => '',
  83. 'bodyclass' => 'no-posts',
  84. 'type' => 'is_frontpage',
  85. 'is_front' => true
  86. ), $layout);
  87.  
  88. die;
  89. }
  90.  
  91. render($pview, array(
  92. 'title' => generate_title('is_front', null),
  93. 'description' => safe_html(strip_tags(blog_description())),
  94. 'canonical' => site_url(),
  95. 'metatags' => generate_meta(null, null),
  96. 'page' => $page,
  97. 'posts' => $posts,
  98. 'bodyclass' => 'in-front',
  99. 'breadcrumb' => '',
  100. 'pagination' => has_pagination($total, $perpage, $page),
  101. 'type' => 'is_frontpage',
  102. 'is_front' => true
  103. ), $layout);
  104. }
  105. });
  106.  
  107. // Get submitted login data
  108. post('/login', function () {
  109.  
  110. $proper = (is_csrf_proper(from($_REQUEST, 'csrf_token')));
  111. $captcha = isCaptcha(from($_REQUEST, 'g-recaptcha-response'));
  112.  
  113. $user = from($_REQUEST, 'user');
  114. $pass = from($_REQUEST, 'password');
  115. if ($proper && $captcha && !empty($user) && !empty($pass)) {
  116.  
  117. session($user, $pass);
  118. $log = session($user, $pass);
  119.  
  120. if (!empty($log)) {
  121.  
  122. config('views.root', 'system/admin/views');
  123.  
  124. render('login', array(
  125. 'title' => generate_title('is_default', i18n('Login')),
  126. 'description' => i18n('Login') . ' ' . blog_title(),
  127. 'canonical' => site_url(),
  128. 'metatags' => generate_meta(null, null),
  129. 'error' => '<ul>' . $log . '</ul>',
  130. 'type' => 'is_login',
  131. 'is_login' => true,
  132. 'bodyclass' => 'in-login',
  133. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Login')
  134. ));
  135. }
  136. } else {
  137. $message['error'] = '';
  138. if (empty($user)) {
  139. $message['error'] .= '<li class="alert alert-danger">' . i18n('User_Error') . '</li>';
  140. }
  141. if (empty($pass)) {
  142. $message['error'] .= '<li class="alert alert-danger">' . i18n('Pass_Error') . '</li>';
  143. }
  144. if (!$proper) {
  145. $message['error'] .= '<li class="alert alert-danger">' . i18n('Token_Error') . '</li>';
  146. }
  147. if (!$captcha) {
  148. $message['error'] .= '<li class="alert alert-danger">' . i18n('Captcha_Error') . '</li>';
  149. }
  150.  
  151. config('views.root', 'system/admin/views');
  152.  
  153. render('login', array(
  154. 'title' => generate_title('is_default', i18n('Login')),
  155. 'description' => i18n('Login') . ' ' . blog_title(),
  156. 'canonical' => site_url(),
  157. 'metatags' => generate_meta(null, null),
  158. 'error' => '<ul>' . $message['error'] . '</ul>',
  159. 'username' => $user,
  160. 'password' => $pass,
  161. 'type' => 'is_login',
  162. 'is_login' => true,
  163. 'bodyclass' => 'in-login',
  164. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Login')
  165. ));
  166. }
  167. });
  168.  
  169. // Show the author page
  170. get('/author/:name', function ($name) {
  171.  
  172. if (isset($_GET['search'])) {
  173. $search = _h($_GET['search']);
  174. $url = site_url() . 'search/' . remove_accent($search);
  175. header("Location: $url");
  176. }
  177.  
  178. if (!login()) {
  179. file_cache($_SERVER['REQUEST_URI']);
  180. }
  181.  
  182. $page = from($_GET, 'page');
  183. $page = $page ? (int)$page : 1;
  184. $perpage = config('profile.perpage');
  185.  
  186. $posts = get_profile_posts($name, $page, $perpage);
  187.  
  188. $total = get_count('/'.$name.'/', 'dirname');
  189.  
  190. if ($total === 0) {
  191. not_found();
  192. }
  193.  
  194. $author = get_author($name);
  195.  
  196. if (isset($author[0])) {
  197. $author = $author[0];
  198. } else {
  199. $author = default_profile($name);
  200. }
  201. $vroot = rtrim(config('views.root'), '/');
  202. $lt = $vroot . '/layout--profile--' . strtolower($name) . '.html.php';
  203. $ls = $vroot . '/layout--profile.html.php';
  204. if (file_exists($lt)) {
  205. $layout = 'layout--profile--' . strtolower($name);
  206. } else if (file_exists($ls)) {
  207. $layout = 'layout--profile';
  208. } else {
  209. $layout = '';
  210. }
  211. $pv = $vroot . '/profile--'. strtolower($name) .'.html.php';
  212. if (file_exists($pv)) {
  213. $pview = 'profile--'. strtolower($name);
  214. } else {
  215. $pview = 'profile';
  216. }
  217.  
  218. if (empty($posts) || $page < 1) {
  219. render($pview, array(
  220. 'title' => generate_title('is_profile', $author),
  221. 'description' => $author->description,
  222. 'canonical' => $author->url,
  223. 'metatags' => generate_meta('is_profile', $author),
  224. 'page' => $page,
  225. 'posts' => null,
  226. 'about' => $author->about,
  227. 'name' => $author->name,
  228. 'author' => $author,
  229. 'type' => 'is_profile',
  230. 'bodyclass' => 'in-profile author-' . $name,
  231. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Profile_for') . ' ' . $author->name,
  232. 'pagination' => has_pagination($total, $perpage, $page),
  233. 'is_profile' => true
  234. ), $layout);
  235. die;
  236. }
  237.  
  238. render($pview, array(
  239. 'title' => generate_title('is_profile', $author),
  240. 'description' => $author->description,
  241. 'canonical' => $author->url,
  242. 'metatags' => generate_meta('is_profile', $author),
  243. 'page' => $page,
  244. 'posts' => $posts,
  245. 'about' => $author->about,
  246. 'name' => $author->name,
  247. 'author' => $author,
  248. 'type' => 'is_profile',
  249. 'bodyclass' => 'in-profile author-' . $name,
  250. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Profile_for') . ' ' . $author->name,
  251. 'pagination' => has_pagination($total, $perpage, $page),
  252. 'is_profile' => true
  253. ), $layout);
  254. });
  255.  
  256. // Show the RSS feed
  257. get('/author/:name/feed', function ($name) {
  258.  
  259. header('Content-Type: application/rss+xml');
  260. $posts = get_profile_posts($name, 1, config('rss.count'));
  261.  
  262. $author = get_author($name);
  263.  
  264. if (isset($author[0])) {
  265. $author = $author[0];
  266. } else {
  267. $author = default_profile($name);
  268. }
  269.  
  270. // Show an RSS feed
  271. echo generate_rss($posts, $author);
  272. });
  273.  
  274. // Edit the profile
  275. get('/edit/profile', function () {
  276. if (login()) {
  277. config('views.root', 'system/admin/views');
  278. render('edit-page', array(
  279. 'title' => generate_title('is_default', i18n('Edit_profile')),
  280. 'description' => safe_html(strip_tags(blog_description())),
  281. 'canonical' => site_url(),
  282. 'metatags' => generate_meta(null, null),
  283. 'type' => 'is_profile',
  284. 'is_admin' => true,
  285. 'bodyclass' => 'edit-profile',
  286. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; '. i18n('Edit_profile'),
  287. ));
  288. } else {
  289. $login = site_url() . 'login';
  290. header("location: $login");
  291. }
  292. });
  293.  
  294. // Get submitted data from edit profile page
  295. post('/edit/profile', function () {
  296. if(!login()) {
  297. $login = site_url() . 'login';
  298. header("location: $login");
  299. }
  300. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  301. $user = $_SESSION[site_url()]['user'];
  302. $title = from($_REQUEST, 'title');
  303. $description = from($_REQUEST, 'description');
  304. $image = from($_REQUEST, 'image');
  305. $content = from($_REQUEST, 'content');
  306. if ($proper && !empty($title) && !empty($content)) {
  307. edit_profile($title, $content, $user, $description, $image);
  308. } else {
  309. $message['error'] = '';
  310. if (empty($title)) {
  311. $message['error'] .= '<li class="alert alert-danger">Title field is required.</li>';
  312. }
  313. if (empty($content)) {
  314. $message['error'] .= '<li class="alert alert-danger">Content field is required.</li>';
  315. }
  316. if (!$proper) {
  317. $message['error'] .= '<li class="alert alert-danger">CSRF Token not correct.</li>';
  318. }
  319. config('views.root', 'system/admin/views');
  320.  
  321. render('edit-page', array(
  322. 'title' => generate_title('is_default', 'Edit profile'),
  323. 'description' => safe_html(strip_tags(blog_description())),
  324. 'canonical' => site_url(),
  325. 'metatags' => generate_meta(null, null),
  326. 'error' => '<ul>' . $message['error'] . '</ul>',
  327. 'postTitle' => $title,
  328. 'postContent' => $content,
  329. 'postImage' => $image,
  330. 'type' => 'is_profile',
  331. 'is_admin' => true,
  332. 'bodyclass' => 'edit-profile',
  333. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; Edit profile'
  334. ));
  335. }
  336. });
  337.  
  338. get('/edit/password', function () {
  339. if (login()) {
  340. config('views.root', 'system/admin/views');
  341. render('edit-password', array(
  342. 'title' => generate_title('is_default', i18n('change_password')),
  343. 'description' => safe_html(strip_tags(blog_description())),
  344. 'canonical' => site_url(),
  345. 'metatags' => generate_meta(null, null),
  346. 'type' => 'is_profile',
  347. 'is_admin' => true,
  348. 'bodyclass' => 'edit-password',
  349. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; '. i18n('change_password'),
  350. ));
  351. } else {
  352. $login = site_url() . 'login';
  353. header("location: $login");
  354. }
  355. });
  356.  
  357. post('/edit/password', function() {
  358. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  359. if (login() && $proper) {
  360. $username = from($_REQUEST, 'username');
  361. $new_password = from($_REQUEST, 'password');
  362. $user = $_SESSION[site_url()]['user'];
  363. $role = user('role', $user);
  364. $old_password = user('password', $username);
  365. if ($user === $username) {
  366. $file = 'config/users/' . $user . '.ini';
  367. if (file_exists($file)) {
  368. if (!empty($new_password)) {
  369. update_user($user, $new_password, $role);
  370. }
  371. }
  372. $redir = site_url() . 'admin';
  373. header("location: $redir");
  374. } else {
  375. $redir = site_url();
  376. header("location: $redir");
  377. }
  378. } else {
  379. $login = site_url() . 'login';
  380. header("location: $login");
  381. }
  382. });
  383.  
  384. // Edit the frontpage
  385. get('/edit/frontpage', function () {
  386. $user = $_SESSION[site_url()]['user'];
  387. $role = user('role', $user);
  388.  
  389. if (login()) {
  390.  
  391. config('views.root', 'system/admin/views');
  392. if ($role === 'editor' || $role === 'admin') {
  393. render('edit-page', array(
  394. 'title' => generate_title('is_default', 'Edit frontpage'),
  395. 'description' => safe_html(strip_tags(blog_description())),
  396. 'canonical' => site_url(),
  397. 'metatags' => generate_meta(null, null),
  398. 'type' => 'is_frontpage',
  399. 'is_admin' => true,
  400. 'bodyclass' => 'edit-frontpage',
  401. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; Edit frontpage',
  402. ));
  403. } else {
  404. render('denied', array(
  405. 'title' => generate_title('is_default', i18n('Denied')),
  406. 'description' => safe_html(strip_tags(blog_description())),
  407. 'canonical' => site_url(),
  408. 'metatags' => generate_meta(null, null),
  409. 'type' => 'is_frontpage',
  410. 'is_admin' => true,
  411. 'bodyclass' => 'denied',
  412. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Denied')
  413. ));
  414. }
  415. } else {
  416. $login = site_url() . 'login';
  417. header("location: $login");
  418. }
  419. });
  420.  
  421. // Get submitted data from edit frontpage
  422. post('/edit/frontpage', function () {
  423. if(!login()) {
  424. $login = site_url() . 'login';
  425. header("location: $login");
  426. }
  427. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  428. $user = $_SESSION[site_url()]['user'];
  429. $role = user('role', $user);
  430. $title = from($_REQUEST, 'title');
  431. $content = from($_REQUEST, 'content');
  432. if ($role === 'editor' || $role === 'admin') {
  433. if ($proper && !empty($title) && !empty($content)) {
  434. edit_frontpage($title, $content);
  435. } else {
  436. $message['error'] = '';
  437. if (empty($title)) {
  438. $message['error'] .= '<li class="alert alert-danger">Title field is required.</li>';
  439. }
  440. if (empty($content)) {
  441. $message['error'] .= '<li class="alert alert-danger">Content field is required.</li>';
  442. }
  443. if (!$proper) {
  444. $message['error'] .= '<li class="alert alert-danger">CSRF Token not correct.</li>';
  445. }
  446. config('views.root', 'system/admin/views');
  447.  
  448. render('edit-page', array(
  449. 'title' => generate_title('is_default', 'Edit frontpage'),
  450. 'description' => safe_html(strip_tags(blog_description())),
  451. 'canonical' => site_url(),
  452. 'metatags' => generate_meta(null, null),
  453. 'error' => '<ul>' . $message['error'] . '</ul>',
  454. 'postTitle' => $title,
  455. 'postContent' => $content,
  456. 'type' => 'is_frontpage',
  457. 'is_admin' => true,
  458. 'bodyclass' => 'edit-frontpage',
  459. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; Edit frontpage'
  460. ));
  461. }
  462. } else {
  463. $redir = site_url();
  464. header("location: $redir");
  465. }
  466. });
  467.  
  468. // Edit the frontpage
  469. get('/front/edit', function () {
  470.  
  471. if (login()) {
  472. $edit = site_url() . 'edit/frontpage';
  473. header("location: $edit");
  474. } else {
  475. $login = site_url() . 'login';
  476. header("location: $login");
  477. }
  478. });
  479.  
  480. // Show the "Add content" page
  481. get('/add/content', function () {
  482.  
  483. if (isset($_GET['type'])) {
  484. $req = _h($_GET['type']);
  485. } else {
  486. $req = 'post';
  487. }
  488.  
  489. $type = 'is_' . $req;
  490.  
  491. if (login()) {
  492.  
  493. config('views.root', 'system/admin/views');
  494.  
  495. render('add-content', array(
  496. 'title' => generate_title('is_default', i18n('Add_new_post')),
  497. 'description' => safe_html(strip_tags(blog_description())),
  498. 'canonical' => site_url(),
  499. 'metatags' => generate_meta(null, null),
  500. 'type' => $type,
  501. 'is_admin' => true,
  502. 'bodyclass' => 'add-content',
  503. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Add_new_post')
  504. ));
  505. } else {
  506. $login = site_url() . 'login';
  507. header("location: $login");
  508. }
  509. });
  510.  
  511. // Submitted add post data
  512. post('/add/content', function () {
  513. if(!login()) {
  514. $login = site_url() . 'login';
  515. header("location: $login");
  516. }
  517. $is_image = from($_REQUEST, 'is_image');
  518. $is_audio = from($_REQUEST, 'is_audio');
  519. $is_video = from($_REQUEST, 'is_video');
  520. $is_quote = from($_REQUEST, 'is_quote');
  521. $is_link = from($_REQUEST, 'is_link');
  522. $is_post = from($_REQUEST, 'is_post');
  523. if (!empty($is_image)) {
  524. $type = 'is_image';
  525. } elseif (!empty($is_video)) {
  526. $type = 'is_video';
  527. } elseif (!empty($is_link)) {
  528. $type = 'is_link';
  529. } elseif (!empty($is_quote)) {
  530. $type = 'is_quote';
  531. } elseif (!empty($is_audio)) {
  532. $type = 'is_audio';
  533. } elseif (!empty($is_post)) {
  534. $type = 'is_post';
  535. }
  536. $link = from($_REQUEST, 'link');
  537. $image = from($_REQUEST, 'image');
  538. $audio = from($_REQUEST, 'audio');
  539. $video = from($_REQUEST, 'video');
  540. $quote = from($_REQUEST, 'quote');
  541.  
  542. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  543.  
  544. $title = from($_REQUEST, 'title');
  545. $tag = from($_REQUEST, 'tag');
  546. $url = from($_REQUEST, 'url');
  547. $content = from($_REQUEST, 'content');
  548. $description = from($_REQUEST, 'description');
  549. $user = $_SESSION[site_url()]['user'];
  550. $draft = from($_REQUEST, 'draft');
  551. $category = from($_REQUEST, 'category');
  552. $date = from($_REQUEST, 'date');
  553. $time = from($_REQUEST, 'time');
  554. $dateTime = null;
  555. if ($date !== null && $time !== null) {
  556. $dateTime = $date . ' ' . $time;
  557. }
  558. if (empty($is_post) && empty($is_image) && empty($is_video) && empty($is_audio) && empty($is_link) && empty($is_quote)) {
  559. $add = site_url() . 'admin/content';
  560. header("location: $add");
  561. }
  562. if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($is_post)) {
  563. if (!empty($url)) {
  564. add_content($title, $tag, $url, $content, $user, $draft, $category, 'post', $description, null, $dateTime);
  565. } else {
  566. $url = $title;
  567. add_content($title, $tag, $url, $content, $user, $draft, $category, 'post', $description, null, $dateTime);
  568. }
  569. } elseif ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($image)) {
  570. if (!empty($url)) {
  571. add_content($title, $tag, $url, $content, $user, $draft, $category, 'image', $description, $image, $dateTime);
  572. } else {
  573. $url = $title;
  574. add_content($title, $tag, $url, $content, $user, $draft, $category, 'image', $description, $image, $dateTime);
  575. }
  576. } elseif ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($video)) {
  577. if (!empty($url)) {
  578. add_content($title, $tag, $url, $content, $user, $draft, $category, 'video', $description, $video, $dateTime);
  579. } else {
  580. $url = $title;
  581. add_content($title, $tag, $url, $content, $user, $draft, $category, 'video', $description, $video, $dateTime);
  582. }
  583. } elseif ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($audio)) {
  584. if (!empty($url)) {
  585. add_content($title, $tag, $url, $content, $user, $draft, $category, 'audio', $description, $audio, $dateTime);
  586. } else {
  587. $url = $title;
  588. add_content($title, $tag, $url, $content, $user, $draft, $category, 'audio', $description, $audio, $dateTime);
  589. }
  590. } elseif ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($quote)) {
  591. if (!empty($url)) {
  592. add_content($title, $tag, $url, $content, $user, $draft, $category, 'quote', $description, $quote, $dateTime);
  593. } else {
  594. $url = $title;
  595. add_content($title, $tag, $url, $content, $user, $draft, $category, 'quote', $description, $quote, $dateTime);
  596. }
  597. } elseif ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($link)) {
  598. if (!empty($url)) {
  599. add_content($title, $tag, $url, $content, $user, $draft, $category, 'link', $description, $link, $dateTime);
  600. } else {
  601. $url = $title;
  602. add_content($title, $tag, $url, $content, $user, $draft, $category, 'link', $description, $link, $dateTime);
  603. }
  604. } else {
  605. $message['error'] = '';
  606. if (empty($title)) {
  607. $message['error'] .= '<li class="alert alert-danger">Title field is required.</li>';
  608. }
  609. if (empty($tag)) {
  610. $message['error'] .= '<li class="alert alert-danger">Tag field is required.</li>';
  611. }
  612. if (empty($content)) {
  613. $message['error'] .= '<li class="alert alert-danger">Content field is required.</li>';
  614. }
  615. if (!$proper) {
  616. $message['error'] .= '<li class="alert alert-danger">CSRF Token not correct.</li>';
  617. }
  618. if (!empty($is_image)) {
  619. if (empty($image)) {
  620. $message['error'] .= '<li class="alert alert-danger">Image field is required.</li>';
  621. }
  622. } elseif (!empty($is_video)) {
  623. if (empty($video)) {
  624. $message['error'] .= '<li class="alert alert-danger">Video field is required.</li>';
  625. }
  626. } elseif (!empty($is_link)) {
  627. if (empty($link)) {
  628. $message['error'] .= '<li class="alert alert-danger">Link field is required.</li>';
  629. }
  630. } elseif (!empty($is_quote)) {
  631. if (empty($quote)) {
  632. $message['error'] .= '<li class="alert alert-danger">Quote field is required.</li>';
  633. }
  634. } elseif (!empty($is_audio)) {
  635. if (empty($audio)) {
  636. $message['error'] .= '<li class="alert alert-danger">Audio field is required.</li>';
  637. }
  638. }
  639. config('views.root', 'system/admin/views');
  640. render('add-content', array(
  641. 'title' => generate_title('is_default', i18n('Add_content')),
  642. 'description' => safe_html(strip_tags(blog_description())),
  643. 'canonical' => site_url(),
  644. 'metatags' => generate_meta(null, null),
  645. 'error' => '<ul>' . $message['error'] . '</ul>',
  646. 'postTitle' => $title,
  647. 'postImage' => $image,
  648. 'postVideo' => $video,
  649. 'postLink' => $link,
  650. 'postQuote' => $quote,
  651. 'postAudio' => $audio,
  652. 'postTag' => $tag,
  653. 'postUrl' => $url,
  654. 'postContent' => $content,
  655. 'type' => $type,
  656. 'is_admin' => true,
  657. 'bodyclass' => 'add-content',
  658. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Add_content')
  659. ));
  660. }
  661. });
  662.  
  663. // Show the static add page
  664. get('/add/page', function () {
  665. $user = $_SESSION[site_url()]['user'];
  666. $role = user('role', $user);
  667.  
  668. if (login()) {
  669. config('views.root', 'system/admin/views');
  670. if ($role === 'editor' || $role === 'admin') {
  671. render('add-page', array(
  672. 'title' => generate_title('is_default', i18n('Add_new_page')),
  673. 'description' => safe_html(strip_tags(blog_description())),
  674. 'canonical' => site_url(),
  675. 'metatags' => generate_meta(null, null),
  676. 'type' => 'is_page',
  677. 'is_admin' => true,
  678. 'bodyclass' => 'add-page',
  679. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Add_new_page')
  680. ));
  681. } else {
  682. render('denied', array(
  683. 'title' => generate_title('is_default', i18n('Denied')),
  684. 'description' => safe_html(strip_tags(blog_description())),
  685. 'canonical' => site_url(),
  686. 'metatags' => generate_meta(null, null),
  687. 'type' => 'is_page',
  688. 'is_admin' => true,
  689. 'bodyclass' => 'denied',
  690. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Denied')
  691. ));
  692. }
  693. } else {
  694. $login = site_url() . 'login';
  695. header("location: $login");
  696. }
  697. });
  698.  
  699. // Submitted static add page data
  700. post('/add/page', function () {
  701.  
  702. if(!login()) {
  703. $login = site_url() . 'login';
  704. header("location: $login");
  705. }
  706. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  707. $title = from($_REQUEST, 'title');
  708. $url = from($_REQUEST, 'url');
  709. $content = from($_REQUEST, 'content');
  710. $description = from($_REQUEST, 'description');
  711. $draft = from($_REQUEST, 'draft');
  712. $user = $_SESSION[site_url()]['user'];
  713. $role = user('role', $user);
  714. if ($role === 'editor' || $role === 'admin') {
  715. if ($proper && !empty($title) && !empty($content) && login()) {
  716. if (!empty($url)) {
  717. add_page($title, $url, $content, $draft, $description);
  718. } else {
  719. $url = $title;
  720. add_page($title, $url, $content, $draft, $description);
  721. }
  722. } else {
  723. $message['error'] = '';
  724. if (empty($title)) {
  725. $message['error'] .= '<li class="alert alert-danger">Title field is required.</li>';
  726. }
  727. if (empty($content)) {
  728. $message['error'] .= '<li class="alert alert-danger">Content field is required.</li>';
  729. }
  730. if (!$proper) {
  731. $message['error'] .= '<li class="alert alert-danger">CSRF Token not correct.</li>';
  732. }
  733. config('views.root', 'system/admin/views');
  734. render('add-page', array(
  735. 'title' => generate_title('is_default', i18n('Add_new_page')),
  736. 'description' => safe_html(strip_tags(blog_description())),
  737. 'canonical' => site_url(),
  738. 'metatags' => generate_meta(null, null),
  739. 'error' => '<ul>' . $message['error'] . '</ul>',
  740. 'postTitle' => $title,
  741. 'postUrl' => $url,
  742. 'postContent' => $content,
  743. 'type' => 'is_page',
  744. 'is_admin' => true,
  745. 'bodyclass' => 'add-page',
  746. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Add_new_page')
  747. ));
  748. }
  749. } else {
  750. $redir = site_url();
  751. header("location: $redir");
  752. }
  753. });
  754.  
  755. // Show the add category
  756. get('/add/category', function () {
  757. $user = $_SESSION[site_url()]['user'];
  758. $role = user('role', $user);
  759. if (login()) {
  760. config('views.root', 'system/admin/views');
  761. if ($role === 'editor' || $role === 'admin') {
  762. render('add-page', array(
  763. 'title' => generate_title('is_default', i18n('Add_category')),
  764. 'description' => safe_html(strip_tags(blog_description())),
  765. 'canonical' => site_url(),
  766. 'metatags' => generate_meta(null, null),
  767. 'type' => 'is_category',
  768. 'is_admin' => true,
  769. 'bodyclass' => 'add-category',
  770. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Add_category')
  771. ));
  772. } else {
  773. render('denied', array(
  774. 'title' => generate_title('is_default', i18n('Denied')),
  775. 'description' => safe_html(strip_tags(blog_description())),
  776. 'canonical' => site_url(),
  777. 'metatags' => generate_meta(null, null),
  778. 'type' => 'is_category',
  779. 'is_admin' => true,
  780. 'bodyclass' => 'denied',
  781. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Denied')
  782. ));
  783. }
  784. } else {
  785. $login = site_url() . 'login';
  786. header("location: $login");
  787. }
  788. });
  789.  
  790. // Submitted add category
  791. post('/add/category', function () {
  792.  
  793. if(!login()) {
  794. $login = site_url() . 'login';
  795. header("location: $login");
  796. }
  797. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  798. $title = from($_REQUEST, 'title');
  799. $url = from($_REQUEST, 'url');
  800. $content = from($_REQUEST, 'content');
  801. $description = from($_REQUEST, 'description');
  802. $user = $_SESSION[site_url()]['user'];
  803. $role = user('role', $user);
  804. if ($role === 'editor' || $role === 'admin') {
  805. if ($proper && !empty($title) && !empty($content)) {
  806. if (!empty($url)) {
  807. add_category($title, $url, $content, $description);
  808. } else {
  809. $url = $title;
  810. add_category($title, $url, $content, $description);
  811. }
  812. } else {
  813. $message['error'] = '';
  814. if (empty($title)) {
  815. $message['error'] .= '<li class="alert alert-danger">Title field is required.</li>';
  816. }
  817. if (empty($content)) {
  818. $message['error'] .= '<li class="alert alert-danger">Content field is required.</li>';
  819. }
  820. if (!$proper) {
  821. $message['error'] .= '<li class="alert alert-danger">CSRF Token not correct.</li>';
  822. }
  823. config('views.root', 'system/admin/views');
  824. render('add-page', array(
  825. 'title' => generate_title('is_default', i18n('Add_category')),
  826. 'description' => safe_html(strip_tags(blog_description())),
  827. 'canonical' => site_url(),
  828. 'metatags' => generate_meta(null, null),
  829. 'error' => '<ul>' . $message['error'] . '</ul>',
  830. 'postTitle' => $title,
  831. 'postUrl' => $url,
  832. 'postContent' => $content,
  833. 'type' => 'is_category',
  834. 'is_admin' => true,
  835. 'bodyclass' => 'add-category',
  836. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Add_category')
  837. ));
  838. }
  839. } else {
  840. $redir = site_url();
  841. header("location: $redir");
  842. }
  843. });
  844.  
  845. // Show admin/posts
  846. get('/admin/posts', function () {
  847.  
  848. $user = $_SESSION[site_url()]['user'];
  849. $role = user('role', $user);
  850. if (login()) {
  851. config('views.root', 'system/admin/views');
  852. if ($role === 'editor' || $role === 'admin') {
  853. config('views.root', 'system/admin/views');
  854. $page = from($_GET, 'page');
  855. $page = $page ? (int)$page : 1;
  856. $perpage = 20;
  857.  
  858. $posts = get_posts(null, $page, $perpage);
  859.  
  860. $total = '';
  861.  
  862. if (empty($posts) || $page < 1) {
  863.  
  864. // a non-existing page
  865. render('no-posts', array(
  866. 'title' => generate_title('is_default', i18n('All_blog_posts')),
  867. 'description' => safe_html(strip_tags(blog_description())),
  868. 'canonical' => site_url(),
  869. 'metatags' => generate_meta(null, null),
  870. 'bodyclass' => 'no-posts',
  871. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('All_blog_posts')
  872. ));
  873.  
  874. die;
  875. }
  876.  
  877. render('posts-list', array(
  878. 'title' => generate_title('is_default', i18n('All_blog_posts')),
  879. 'description' => safe_html(strip_tags(blog_description())),
  880. 'canonical' => site_url(),
  881. 'metatags' => generate_meta(null, null),
  882. 'heading' => i18n('All_blog_posts'),
  883. 'page' => $page,
  884. 'posts' => $posts,
  885. 'bodyclass' => 'all-posts',
  886. 'type' => 'is_admin-posts',
  887. 'is_admin' => true,
  888. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('All_blog_posts'),
  889. 'pagination' => has_pagination($total, $perpage, $page)
  890. ));
  891. } else {
  892. render('denied', array(
  893. 'title' => generate_title('is_default', i18n('All_blog_posts')),
  894. 'description' => safe_html(strip_tags(blog_description())),
  895. 'canonical' => site_url(),
  896. 'metatags' => generate_meta(null, null),
  897. 'type' => 'is_admin-posts',
  898. 'is_admin' => true,
  899. 'bodyclass' => 'denied',
  900. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('All_blog_posts')
  901. ));
  902. }
  903. } else {
  904. $login = site_url() . 'login';
  905. header("location: $login");
  906. }
  907. });
  908.  
  909. // Show admin/popular
  910. get('/admin/popular', function () {
  911.  
  912. $user = $_SESSION[site_url()]['user'];
  913. $role = user('role', $user);
  914. if (login()) {
  915. config('views.root', 'system/admin/views');
  916. if ($role === 'editor' || $role === 'admin') {
  917. config('views.root', 'system/admin/views');
  918. $page = from($_GET, 'page');
  919. $page = $page ? (int)$page : 1;
  920. $perpage = 20;
  921.  
  922. $posts = popular_posts(true,$perpage);
  923.  
  924. $total = '';
  925.  
  926. if (empty($posts) || $page < 1) {
  927.  
  928. // a non-existing page
  929. render('no-posts', array(
  930. 'title' => generate_title('is_default', i18n('Popular_posts')),
  931. 'description' => safe_html(strip_tags(blog_description())),
  932. 'canonical' => site_url(),
  933. 'metatags' => generate_meta(null, null),
  934. 'is_admin' => true,
  935. 'bodyclass' => 'admin-popular',
  936. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Popular_posts')
  937. ));
  938.  
  939. die;
  940. }
  941.  
  942. render('popular-posts', array(
  943. 'title' => generate_title('is_default', i18n('Popular_posts')),
  944. 'description' => safe_html(strip_tags(blog_description())),
  945. 'canonical' => site_url(),
  946. 'metatags' => generate_meta(null, null),
  947. 'heading' => i18n('Popular_posts'),
  948. 'page' => $page,
  949. 'posts' => $posts,
  950. 'is_admin' => true,
  951. 'bodyclass' => 'admin-popular',
  952. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Popular_posts'),
  953. 'pagination' => has_pagination($total, $perpage, $page)
  954. ));
  955. } else {
  956. render('denied', array(
  957. 'title' => generate_title('is_default', i18n('Popular_posts')),
  958. 'description' => safe_html(strip_tags(blog_description())),
  959. 'canonical' => site_url(),
  960. 'metatags' => generate_meta(null, null),
  961. 'is_admin' => true,
  962. 'bodyclass' => 'denied',
  963. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Popular_posts')
  964. ));
  965. }
  966. } else {
  967. $login = site_url() . 'login';
  968. header("location: $login");
  969. }
  970. });
  971.  
  972. // Show admin/mine
  973. get('/admin/mine', function () {
  974.  
  975. if (login()) {
  976.  
  977. config('views.root', 'system/admin/views');
  978.  
  979. $name = $_SESSION[site_url()]['user'];
  980.  
  981. $page = from($_GET, 'page');
  982. $page = $page ? (int)$page : 1;
  983. $perpage = config('profile.perpage');
  984.  
  985. $posts = get_profile_posts($name, $page, $perpage);
  986.  
  987. $total = get_count('/'.$name.'/', 'dirname');
  988.  
  989. $author = get_author($name);
  990.  
  991. if (isset($author[0])) {
  992. $author = $author[0];
  993. } else {
  994. $author = default_profile($name);
  995. }
  996.  
  997. if (empty($posts) || $page < 1) {
  998. render('user-posts', array(
  999. 'title' => generate_title('is_default', i18n('My_posts')),
  1000. 'description' => safe_html(strip_tags(blog_description())),
  1001. 'canonical' => site_url(),
  1002. 'metatags' => generate_meta(null, null),
  1003. 'page' => $page,
  1004. 'heading' => i18n('My_posts'),
  1005. 'posts' => null,
  1006. 'about' => $author->about,
  1007. 'name' => $author->name,
  1008. 'type' => 'is_admin-mine',
  1009. 'is_admin' => true,
  1010. 'bodyclass' => 'admin-mine',
  1011. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('My_posts') . ': '. $author->name,
  1012. 'pagination' => has_pagination($total, $perpage, $page)
  1013. ));
  1014. die;
  1015. }
  1016.  
  1017. render('user-posts', array(
  1018. 'title' => generate_title('is_default', i18n('My_posts')),
  1019. 'description' => safe_html(strip_tags(blog_description())),
  1020. 'canonical' => site_url(),
  1021. 'metatags' => generate_meta(null, null),
  1022. 'heading' => i18n('My_posts'),
  1023. 'page' => $page,
  1024. 'posts' => $posts,
  1025. 'about' => $author->about,
  1026. 'name' => $author->name,
  1027. 'type' => 'is_admin-mine',
  1028. 'is_admin' => true,
  1029. 'bodyclass' => 'admin-mine',
  1030. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('My_posts') . ': '. $author->name,
  1031. 'pagination' => has_pagination($total, $perpage, $page)
  1032. ));
  1033. } else {
  1034. $login = site_url() . 'login';
  1035. header("location: $login");
  1036. }
  1037. });
  1038.  
  1039. // Show admin/draft
  1040. get('/admin/draft', function () {
  1041.  
  1042. if (login()) {
  1043.  
  1044. config('views.root', 'system/admin/views');
  1045.  
  1046. $name = $_SESSION[site_url()]['user'];
  1047.  
  1048. $page = from($_GET, 'page');
  1049. $page = $page ? (int)$page : 1;
  1050. $perpage = config('profile.perpage');
  1051.  
  1052. $posts = get_draft($name, $page, $perpage);
  1053. $draftPages = find_draft_page();
  1054. $draftSubpages = find_draft_subpage();
  1055.  
  1056. $total = get_draftcount($name);
  1057.  
  1058. $author = get_author($name);
  1059.  
  1060. if (isset($author[0])) {
  1061. $author = $author[0];
  1062. } else {
  1063. $author = default_profile($name);
  1064. }
  1065.  
  1066. if (empty($posts) || $page < 1) {
  1067. render('user-draft', array(
  1068. 'title' => generate_title('is_default', i18n('My_draft')),
  1069. 'description' => safe_html(strip_tags(blog_description())),
  1070. 'canonical' => site_url(),
  1071. 'metatags' => generate_meta(null, null),
  1072. 'page' => $page,
  1073. 'heading' => i18n('My_draft'),
  1074. 'posts' => null,
  1075. 'draftPages' => $draftPages,
  1076. 'draftSubpages' => $draftSubpages,
  1077. 'about' => $author->about,
  1078. 'name' => $author->name,
  1079. 'type' => 'is_admin-draft',
  1080. 'is_admin' => true,
  1081. 'bodyclass' => 'admin-draft',
  1082. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('My_draft'). ': ' . $author->name,
  1083. 'pagination' => has_pagination($total, $perpage, $page)
  1084. ));
  1085. die;
  1086. }
  1087. render('user-draft', array(
  1088. 'title' => generate_title('is_default', i18n('My_draft')),
  1089. 'description' => safe_html(strip_tags(blog_description())),
  1090. 'canonical' => site_url(),
  1091. 'metatags' => generate_meta(null, null),
  1092. 'heading' => i18n('My_draft'),
  1093. 'page' => $page,
  1094. 'posts' => $posts,
  1095. 'draftPages' => $draftPages,
  1096. 'draftSubpages' => $draftSubpages,
  1097. 'about' => $author->about,
  1098. 'name' => $author->name,
  1099. 'type' => 'is_admin-draft',
  1100. 'is_admin' => true,
  1101. 'bodyclass' => 'admin-draft',
  1102. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('My_draft') . ': ' . $author->name,
  1103. 'pagination' => has_pagination($total, $perpage, $page)
  1104. ));
  1105. } else {
  1106. $login = site_url() . 'login';
  1107. header("location: $login");
  1108. }
  1109. });
  1110.  
  1111. // Show admin/scheduled
  1112. get('/admin/scheduled', function () {
  1113.  
  1114. if (login()) {
  1115.  
  1116. config('views.root', 'system/admin/views');
  1117.  
  1118. $name = $_SESSION[site_url()]['user'];
  1119.  
  1120. $page = from($_GET, 'page');
  1121. $page = $page ? (int)$page : 1;
  1122. $perpage = config('profile.perpage');
  1123.  
  1124. $posts = get_scheduled($name, $page, $perpage);
  1125.  
  1126. $total = get_scheduledcount($name);
  1127.  
  1128. $author = get_author($name);
  1129.  
  1130. if (isset($author[0])) {
  1131. $author = $author[0];
  1132. } else {
  1133. $author = default_profile($name);
  1134. }
  1135.  
  1136. if (empty($posts) || $page < 1) {
  1137. render('scheduled', array(
  1138. 'title' => generate_title('is_default', i18n('Scheduled_posts')),
  1139. 'description' => safe_html(strip_tags(blog_description())),
  1140. 'canonical' => site_url(),
  1141. 'metatags' => generate_meta(null, null),
  1142. 'page' => $page,
  1143. 'heading' => i18n('Scheduled_posts'),
  1144. 'posts' => null,
  1145. 'about' => $author->about,
  1146. 'name' => $author->name,
  1147. 'type' => 'is_admin-scheduled',
  1148. 'is_admin' => true,
  1149. 'bodyclass' => 'admin-scheduled',
  1150. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Scheduled_posts') . ': ' . $author->name,
  1151. 'pagination' => has_pagination($total, $perpage, $page)
  1152. ));
  1153. die;
  1154. }
  1155.  
  1156. render('scheduled', array(
  1157. 'title' => generate_title('is_default', i18n('Scheduled_posts')),
  1158. 'description' => safe_html(strip_tags(blog_description())),
  1159. 'canonical' => site_url(),
  1160. 'metatags' => generate_meta(null, null),
  1161. 'heading' => i18n('Scheduled_posts'),
  1162. 'page' => $page,
  1163. 'posts' => $posts,
  1164. 'about' => $author->about,
  1165. 'name' => $author->name,
  1166. 'type' => 'is_admin-scheduled',
  1167. 'is_admin' => true,
  1168. 'bodyclass' => 'admin-scheduled',
  1169. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Scheduled_posts') . ': ' . $author->name,
  1170. 'pagination' => has_pagination($total, $perpage, $page)
  1171. ));
  1172. } else {
  1173. $login = site_url() . 'login';
  1174. header("location: $login");
  1175. }
  1176. });
  1177.  
  1178. // Show admin/content
  1179. get('/admin/content', function () {
  1180. if (login()) {
  1181. config('views.root', 'system/admin/views');
  1182. render('content-type', array(
  1183. 'title' => generate_title('is_default', i18n('Add_content')),
  1184. 'description' => safe_html(strip_tags(blog_description())),
  1185. 'canonical' => site_url(),
  1186. 'metatags' => generate_meta(null, null),
  1187. 'type' => 'is_admin-content',
  1188. 'is_admin' => true,
  1189. 'bodyclass' => 'admin-content',
  1190. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Add_content')
  1191. ));
  1192. } else {
  1193. $login = site_url() . 'login';
  1194. header("location: $login");
  1195. }
  1196. });
  1197.  
  1198. // Show admin/pages
  1199. get('/admin/pages', function () {
  1200. $user = $_SESSION[site_url()]['user'];
  1201. $role = user('role', $user);
  1202. if (login()) {
  1203. config('views.root', 'system/admin/views');
  1204. if ($role === 'editor' || $role === 'admin') {
  1205. render('static-pages', array(
  1206. 'title' => generate_title('is_default', i18n('Static_pages')),
  1207. 'description' => safe_html(strip_tags(blog_description())),
  1208. 'canonical' => site_url(),
  1209. 'metatags' => generate_meta(null, null),
  1210. 'type' => 'is_admin-pages',
  1211. 'is_admin' => true,
  1212. 'bodyclass' => 'admin-pages',
  1213. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Static_pages')
  1214. ));
  1215. } else {
  1216. render('denied', array(
  1217. 'title' => generate_title('is_default', i18n('Denied')),
  1218. 'description' => safe_html(strip_tags(blog_description())),
  1219. 'canonical' => site_url(),
  1220. 'metatags' => generate_meta(null, null),
  1221. 'type' => 'is_admin-config',
  1222. 'is_admin' => true,
  1223. 'bodyclass' => 'denied',
  1224. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Denied')
  1225. ));
  1226. }
  1227. } else {
  1228. $login = site_url() . 'login';
  1229. header("location: $login");
  1230. }
  1231. });
  1232.  
  1233. post('/admin/pages', function () {
  1234.  
  1235. if (login()) {
  1236. $user = $_SESSION[site_url()]['user'];
  1237. $role = user('role', $user);
  1238. if ($role === 'editor' || $role === 'admin') {
  1239. $json = $_REQUEST['json'];
  1240. reorder_pages($json);
  1241. echo json_encode(array(
  1242. 'message' => 'Page order saved successfully!',
  1243. ));
  1244. }
  1245. }
  1246. });
  1247.  
  1248. // Show admin/pages
  1249. get('/admin/pages/:static', function ($static)
  1250. {
  1251. $user = $_SESSION[site_url()]['user'];
  1252. $role = user('role', $user);
  1253. if (login()) {
  1254. config('views.root', 'system/admin/views');
  1255. if ($role === 'editor' || $role === 'admin') {
  1256.  
  1257. $post = find_page($static);
  1258.  
  1259. if (!$post) {
  1260. not_found();
  1261. }
  1262. if (array_key_exists('prev', $post)) {
  1263. $prev = $post['prev'];
  1264. } else {
  1265. $prev = array();
  1266. }
  1267.  
  1268. if (array_key_exists('next', $post)) {
  1269. $next = $post['next'];
  1270. } else {
  1271. $next = array();
  1272. }
  1273.  
  1274. $post = $post['current'];
  1275. render('static-subpages', array(
  1276. 'title' => generate_title('is_default', $post->title),
  1277. 'description' => $post->description,
  1278. 'canonical' => $post->url,
  1279. 'metatags' => generate_meta(null, null),
  1280. 'bodyclass' => 'in-page ' . strtolower($static),
  1281. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . '<a href="'. site_url() .'admin/pages">' .i18n('pages').'</a> &#187; ' . $post->title,
  1282. 'p' => $post,
  1283. 'static' => $post,
  1284. 'type' => 'staticSubpage',
  1285. 'prev' => static_prev($prev),
  1286. 'next' => static_next($next),
  1287. 'is_page' => true
  1288. ));
  1289. } else {
  1290. render('denied', array(
  1291. 'title' => generate_title('is_default', 'Pages'),
  1292. 'description' => safe_html(strip_tags(blog_description())),
  1293. 'canonical' => site_url(),
  1294. 'metatags' => generate_meta(null, null),
  1295. 'type' => 'staticSubpage',
  1296. 'is_admin' => true,
  1297. 'bodyclass' => 'denied',
  1298. 'breadcrumb' => '',
  1299. ));
  1300. }
  1301. } else {
  1302. $login = site_url() . 'login';
  1303. }
  1304. });
  1305.  
  1306. post('/admin/pages/:static', function ($static) {
  1307.  
  1308. if (login()) {
  1309. $user = $_SESSION[site_url()]['user'];
  1310. $role = user('role', $user);
  1311. if ($role === 'editor' || $role === 'admin') {
  1312. $json = $_REQUEST['json'];
  1313. reorder_subpages($json);
  1314. echo json_encode(array(
  1315. 'message' => 'Page order saved successfully!',
  1316. ));
  1317. }
  1318. }
  1319. });
  1320.  
  1321. // Show import page
  1322. get('/admin/import', function () {
  1323. $user = $_SESSION[site_url()]['user'];
  1324. $role = user('role', $user);
  1325. if (login()) {
  1326. config('views.root', 'system/admin/views');
  1327. if ($role === 'admin') {
  1328. render('import', array(
  1329. 'title' => generate_title('is_default', i18n('Import_Feed')),
  1330. 'description' => safe_html(strip_tags(blog_description())),
  1331. 'canonical' => site_url(),
  1332. 'metatags' => generate_meta(null, null),
  1333. 'type' => 'is_admin-import',
  1334. 'is_admin' => true,
  1335. 'bodyclass' => 'admin-import',
  1336. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Import_Feed')
  1337. ));
  1338. } else {
  1339. render('denied', array(
  1340. 'title' => generate_title('is_default', i18n('Denied')),
  1341. 'description' => safe_html(strip_tags(blog_description())),
  1342. 'canonical' => site_url(),
  1343. 'metatags' => generate_meta(null, null),
  1344. 'type' => 'is_admin-import',
  1345. 'is_admin' => true,
  1346. 'bodyclass' => 'denied',
  1347. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Denied')
  1348. ));
  1349. }
  1350. } else {
  1351. $login = site_url() . 'login';
  1352. header("location: $login");
  1353. }
  1354. die;
  1355. });
  1356.  
  1357. // Submitted import page data
  1358. post('/admin/import', function () {
  1359. if(!login()) {
  1360. $login = site_url() . 'login';
  1361. header("location: $login");
  1362. }
  1363. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  1364. $url = from($_REQUEST, 'url');
  1365. $credit = from($_REQUEST, 'credit');
  1366. $user = $_SESSION[site_url()]['user'];
  1367. $role = user('role', $user);
  1368. if ($role === 'admin') {
  1369. if (!empty($url) && $proper) {
  1370.  
  1371. get_feed($url, $credit);
  1372. $log = get_feed($url, $credit);
  1373.  
  1374. if (!empty($log)) {
  1375.  
  1376. config('views.root', 'system/admin/views');
  1377.  
  1378. render('import', array(
  1379. 'title' => generate_title('is_default', i18n('Import_Feed')),
  1380. 'description' => safe_html(strip_tags(blog_description())),
  1381. 'canonical' => site_url(),
  1382. 'metatags' => generate_meta(null, null),
  1383. 'error' => '<ul>' . $log . '</ul>',
  1384. 'type' => 'is_admin-import',
  1385. 'is_admin' => true,
  1386. 'bodyclass' => 'admin-import',
  1387. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Import_Feed')
  1388. ));
  1389. }
  1390. } else {
  1391. $message['error'] = '';
  1392. if (empty($url)) {
  1393. $message['error'] .= '<li class="alert alert-danger">You need to specify the feed url.</li>';
  1394. }
  1395. if (!$proper) {
  1396. $message['error'] .= '<li class="alert alert-danger">CSRF Token not correct.</li>';
  1397. }
  1398.  
  1399. config('views.root', 'system/admin/views');
  1400.  
  1401. render('import', array(
  1402. 'title' => generate_title('is_default', i18n('Import_Feed')),
  1403. 'description' => safe_html(strip_tags(blog_description())),
  1404. 'canonical' => site_url(),
  1405. 'metatags' => generate_meta(null, null),
  1406. 'error' => '<ul>' . $message['error'] . '</ul>',
  1407. 'url' => $url,
  1408. 'type' => 'is_admin-import',
  1409. 'is_admin' => true,
  1410. 'bodyclass' => 'admin-import',
  1411. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Import_Feed')
  1412. ));
  1413. }
  1414. } else {
  1415. $redir = site_url();
  1416. header("location: $redir");
  1417. }
  1418. });
  1419.  
  1420. // Show Config page
  1421. get('/admin/config', function () {
  1422.  
  1423. $user = $_SESSION[site_url()]['user'];
  1424. $role = user('role', $user);
  1425.  
  1426. if (login()) {
  1427. config('views.root', 'system/admin/views');
  1428. if ($role === 'admin') {
  1429. render('config', array(
  1430. 'title' => generate_title('is_default', i18n('Config')),
  1431. 'description' => safe_html(strip_tags(blog_description())),
  1432. 'canonical' => site_url(),
  1433. 'metatags' => generate_meta(null, null),
  1434. 'type' => 'is_admin-config',
  1435. 'is_admin' => true,
  1436. 'bodyclass' => 'admin-config',
  1437. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Config')
  1438. ));
  1439. } else {
  1440. render('denied', array(
  1441. 'title' => generate_title('is_default', i18n('Config')),
  1442. 'description' => safe_html(strip_tags(blog_description())),
  1443. 'canonical' => site_url(),
  1444. 'metatags' => generate_meta(null, null),
  1445. 'type' => 'is_admin-config',
  1446. 'is_admin' => true,
  1447. 'bodyclass' => 'denied',
  1448. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Config')
  1449. ));
  1450. }
  1451. } else {
  1452. $login = site_url() . 'login';
  1453. header("location: $login");
  1454. }
  1455. die;
  1456. });
  1457.  
  1458. // Submitted Config page data
  1459. post('/admin/config', function () {
  1460.  
  1461. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  1462. if (login() && $proper) {
  1463. $user = $_SESSION[site_url()]['user'];
  1464. $role = user('role', $user);
  1465. if ($role === 'admin') {
  1466. $new_config = array();
  1467. $new_Keys = array();
  1468. foreach ($_POST as $name => $value) {
  1469. if (substr($name, 0, 8) == "-config-") {
  1470. $name = str_replace("_", ".", substr($name, 8));
  1471. if(!is_null(config($name))) {
  1472. $new_config[$name] = $value;
  1473. } else {
  1474. $new_Keys[$name] = $value;
  1475. }
  1476. }
  1477. }
  1478. save_config($new_config, $new_Keys);
  1479. foreach (glob('cache/widget/archive*.cache', GLOB_NOSORT) as $file) {
  1480. unlink($file);
  1481. }
  1482. $redir = site_url() . 'admin/config';
  1483. header("location: $redir");
  1484. } else {
  1485. $redir = site_url();
  1486. header("location: $redir");
  1487. }
  1488. } else {
  1489. $login = site_url() . 'login';
  1490. header("location: $login");
  1491. }
  1492. });
  1493.  
  1494. // Show Config page
  1495. get('/admin/config/custom', function () {
  1496.  
  1497. $user = $_SESSION[site_url()]['user'];
  1498. $role = user('role', $user);
  1499.  
  1500. if (login()) {
  1501. config('views.root', 'system/admin/views');
  1502. if ($role === 'admin') {
  1503. render('config-custom', array(
  1504. 'title' => generate_title('is_default', i18n('Config')),
  1505. 'description' => safe_html(strip_tags(blog_description())),
  1506. 'canonical' => site_url(),
  1507. 'metatags' => generate_meta(null, null),
  1508. 'type' => 'is_admin-config',
  1509. 'is_admin' => true,
  1510. 'bodyclass' => 'admin-config',
  1511. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Config')
  1512. ));
  1513. } else {
  1514. render('denied', array(
  1515. 'title' => generate_title('is_default', i18n('Config')),
  1516. 'description' => safe_html(strip_tags(blog_description())),
  1517. 'canonical' => site_url(),
  1518. 'metatags' => generate_meta(null, null),
  1519. 'type' => 'is_admin-config',
  1520. 'is_admin' => true,
  1521. 'bodyclass' => 'denied',
  1522. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Config')
  1523. ));
  1524. }
  1525. } else {
  1526. $login = site_url() . 'login';
  1527. header("location: $login");
  1528. }
  1529. });
  1530.  
  1531. // Submitted Config page data
  1532. post('/admin/config/custom', function () {
  1533.  
  1534. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  1535. if (login() && $proper) {
  1536. $user = $_SESSION[site_url()]['user'];
  1537. $role = user('role', $user);
  1538. if ($role === 'admin') {
  1539. $newKey = from($_REQUEST, 'newKey');
  1540. $newValue = from($_REQUEST, 'newValue');
  1541.  
  1542. $new_config = array();
  1543. $new_Keys = array();
  1544. if (!empty($newKey)) {
  1545. $new_Keys[$newKey] = $newValue;
  1546. }
  1547. foreach ($_POST as $name => $value) {
  1548. if (substr($name, 0, 8) == "-config-") {
  1549. $name = str_replace("_", ".", substr($name, 8));
  1550. $new_config[$name] = $value;
  1551. }
  1552. }
  1553. save_config($new_config, $new_Keys);
  1554. $redir = site_url() . 'admin/config/custom';
  1555. header("location: $redir");
  1556. } else {
  1557. $redir = site_url();
  1558. header("location: $redir");
  1559. }
  1560. } else {
  1561. $login = site_url() . 'login';
  1562. header("location: $login");
  1563. }
  1564. });
  1565.  
  1566. // Show Config page
  1567. get('/admin/config/reading', function () {
  1568.  
  1569. $user = $_SESSION[site_url()]['user'];
  1570. $role = user('role', $user);
  1571.  
  1572. if (login()) {
  1573. config('views.root', 'system/admin/views');
  1574. if ($role === 'admin') {
  1575. render('config-reading', array(
  1576. 'title' => generate_title('is_default', i18n('Config')),
  1577. 'description' => safe_html(strip_tags(blog_description())),
  1578. 'canonical' => site_url(),
  1579. 'metatags' => generate_meta(null, null),
  1580. 'type' => 'is_admin-config',
  1581. 'is_admin' => true,
  1582. 'bodyclass' => 'admin-config',
  1583. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Config')
  1584. ));
  1585. } else {
  1586. render('denied', array(
  1587. 'title' => generate_title('is_default', i18n('Config')),
  1588. 'description' => safe_html(strip_tags(blog_description())),
  1589. 'canonical' => site_url(),
  1590. 'metatags' => generate_meta(null, null),
  1591. 'type' => 'is_admin-config',
  1592. 'is_admin' => true,
  1593. 'bodyclass' => 'denied',
  1594. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Config')
  1595. ));
  1596. }
  1597. } else {
  1598. $login = site_url() . 'login';
  1599. header("location: $login");
  1600. }
  1601. });
  1602.  
  1603. // Submitted Config page data
  1604. post('/admin/config/reading', function () {
  1605.  
  1606. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  1607. if (login() && $proper) {
  1608. $new_config = array();
  1609. $new_Keys = array();
  1610. $user = $_SESSION[site_url()]['user'];
  1611. $role = user('role', $user);
  1612. if ($role === 'admin') {
  1613. foreach ($_POST as $name => $value) {
  1614. if (substr($name, 0, 8) == "-config-") {
  1615. $name = str_replace("_", ".", substr($name, 8));
  1616. if(!is_null(config($name))) {
  1617. $new_config[$name] = $value;
  1618. } else {
  1619. $new_Keys[$name] = $value;
  1620. }
  1621. }
  1622. }
  1623. save_config($new_config, $new_Keys);
  1624. $redir = site_url() . 'admin/config/reading';
  1625. header("location: $redir");
  1626. } else {
  1627. $redir = site_url();
  1628. header("location: $redir");
  1629. }
  1630. } else {
  1631. $login = site_url() . 'login';
  1632. header("location: $login");
  1633. }
  1634. });
  1635.  
  1636. // Show Config page
  1637. get('/admin/config/widget', function () {
  1638.  
  1639. $user = $_SESSION[site_url()]['user'];
  1640. $role = user('role', $user);
  1641.  
  1642. if (login()) {
  1643. config('views.root', 'system/admin/views');
  1644. if ($role === 'admin') {
  1645. render('config-widget', array(
  1646. 'title' => generate_title('is_default', i18n('Config')),
  1647. 'description' => safe_html(strip_tags(blog_description())),
  1648. 'canonical' => site_url(),
  1649. 'metatags' => generate_meta(null, null),
  1650. 'type' => 'is_admin-config',
  1651. 'is_admin' => true,
  1652. 'bodyclass' => 'admin-config',
  1653. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Config')
  1654. ));
  1655. } else {
  1656. render('denied', array(
  1657. 'title' => generate_title('is_default', i18n('Config')),
  1658. 'description' => safe_html(strip_tags(blog_description())),
  1659. 'canonical' => site_url(),
  1660. 'metatags' => generate_meta(null, null),
  1661. 'type' => 'is_admin-config',
  1662. 'is_admin' => true,
  1663. 'bodyclass' => 'denied',
  1664. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Config')
  1665. ));
  1666. }
  1667. } else {
  1668. $login = site_url() . 'login';
  1669. header("location: $login");
  1670. }
  1671. });
  1672.  
  1673. // Submitted Config page data
  1674. post('/admin/config/widget', function () {
  1675.  
  1676. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  1677. if (login() && $proper) {
  1678. $new_config = array();
  1679. $new_Keys = array();
  1680. $user = $_SESSION[site_url()]['user'];
  1681. $role = user('role', $user);
  1682. if ($role === 'admin') {
  1683. foreach ($_POST as $name => $value) {
  1684. if (substr($name, 0, 8) == "-config-") {
  1685. $name = str_replace("_", ".", substr($name, 8));
  1686. if(!is_null(config($name))) {
  1687. $new_config[$name] = $value;
  1688. } else {
  1689. $new_Keys[$name] = $value;
  1690. }
  1691. }
  1692. }
  1693. save_config($new_config, $new_Keys);
  1694. foreach (glob('cache/widget/tags*.cache', GLOB_NOSORT) as $file) {
  1695. unlink($file);
  1696. }
  1697. $redir = site_url() . 'admin/config/widget';
  1698. header("location: $redir");
  1699. } else {
  1700. $redir = site_url();
  1701. header("location: $redir");
  1702. }
  1703. } else {
  1704. $login = site_url() . 'login';
  1705. header("location: $login");
  1706. }
  1707. });
  1708.  
  1709. // Show Config page
  1710. get('/admin/config/metatags', function () {
  1711.  
  1712. $user = $_SESSION[site_url()]['user'];
  1713. $role = user('role', $user);
  1714.  
  1715. if (login()) {
  1716. config('views.root', 'system/admin/views');
  1717. if ($role === 'admin') {
  1718. render('config-metatags', array(
  1719. 'title' => generate_title('is_default', i18n('Config')),
  1720. 'description' => safe_html(strip_tags(blog_description())),
  1721. 'canonical' => site_url(),
  1722. 'metatags' => generate_meta(null, null),
  1723. 'type' => 'is_admin-config',
  1724. 'is_admin' => true,
  1725. 'bodyclass' => 'admin-config',
  1726. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Config')
  1727. ));
  1728. } else {
  1729. render('denied', array(
  1730. 'title' => generate_title('is_default', i18n('Config')),
  1731. 'description' => safe_html(strip_tags(blog_description())),
  1732. 'canonical' => site_url(),
  1733. 'metatags' => generate_meta(null, null),
  1734. 'type' => 'is_admin-config',
  1735. 'is_admin' => true,
  1736. 'bodyclass' => 'denied',
  1737. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Config')
  1738. ));
  1739. }
  1740. } else {
  1741. $login = site_url() . 'login';
  1742. header("location: $login");
  1743. }
  1744. die;
  1745. });
  1746.  
  1747. // Submitted Config page data
  1748. post('/admin/config/metatags', function () {
  1749.  
  1750. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  1751. if (login() && $proper) {
  1752. $new_config = array();
  1753. $new_Keys = array();
  1754. $user = $_SESSION[site_url()]['user'];
  1755. $role = user('role', $user);
  1756. if ($role === 'admin') {
  1757. foreach ($_POST as $name => $value) {
  1758. if (substr($name, 0, 8) == "-config-") {
  1759. $name = str_replace("_", ".", substr($name, 8));
  1760. if(!is_null(config($name))) {
  1761. $new_config[$name] = $value;
  1762. } else {
  1763. $new_Keys[$name] = $value;
  1764. }
  1765. }
  1766. }
  1767. save_config($new_config, $new_Keys);
  1768. $redir = site_url() . 'admin/config/metatags';
  1769. header("location: $redir");
  1770. } else {
  1771. $redir = site_url();
  1772. header("location: $redir");
  1773. }
  1774. } else {
  1775. $login = site_url() . 'login';
  1776. header("location: $login");
  1777. }
  1778. });
  1779.  
  1780. // Show Config page
  1781. get('/admin/config/performance', function () {
  1782.  
  1783. $user = $_SESSION[site_url()]['user'];
  1784. $role = user('role', $user);
  1785.  
  1786. if (login()) {
  1787. config('views.root', 'system/admin/views');
  1788. if ($role === 'admin') {
  1789. render('config-performance', array(
  1790. 'title' => generate_title('is_default', i18n('Config')),
  1791. 'description' => safe_html(strip_tags(blog_description())),
  1792. 'canonical' => site_url(),
  1793. 'metatags' => generate_meta(null, null),
  1794. 'type' => 'is_admin-config',
  1795. 'is_admin' => true,
  1796. 'bodyclass' => 'admin-config',
  1797. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Config')
  1798. ));
  1799. } else {
  1800. render('denied', array(
  1801. 'title' => generate_title('is_default', i18n('Config')),
  1802. 'description' => safe_html(strip_tags(blog_description())),
  1803. 'canonical' => site_url(),
  1804. 'metatags' => generate_meta(null, null),
  1805. 'type' => 'is_admin-config',
  1806. 'is_admin' => true,
  1807. 'bodyclass' => 'denied',
  1808. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Config')
  1809. ));
  1810. }
  1811. } else {
  1812. $login = site_url() . 'login';
  1813. header("location: $login");
  1814. }
  1815. die;
  1816. });
  1817.  
  1818. // Submitted Config page data
  1819. post('/admin/config/performance', function () {
  1820.  
  1821. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  1822. if (login() && $proper) {
  1823. $new_config = array();
  1824. $new_Keys = array();
  1825. $user = $_SESSION[site_url()]['user'];
  1826. $role = user('role', $user);
  1827. if ($role === 'admin') {
  1828. foreach ($_POST as $name => $value) {
  1829. if (substr($name, 0, 8) == "-config-") {
  1830. $name = str_replace("_", ".", substr($name, 8));
  1831. if(!is_null(config($name))) {
  1832. $new_config[$name] = $value;
  1833. } else {
  1834. $new_Keys[$name] = $value;
  1835. }
  1836. }
  1837. }
  1838. save_config($new_config, $new_Keys);
  1839. $redir = site_url() . 'admin/config/performance';
  1840. header("location: $redir");
  1841. } else {
  1842. $redir = site_url();
  1843. header("location: $redir");
  1844. }
  1845. } else {
  1846. $login = site_url() . 'login';
  1847. header("location: $login");
  1848. }
  1849. });
  1850.  
  1851. // Show Backup page
  1852. get('/admin/backup', function () {
  1853. $user = $_SESSION[site_url()]['user'];
  1854. $role = user('role', $user);
  1855. if (login()) {
  1856. config('views.root', 'system/admin/views');
  1857. if ($role === 'admin') {
  1858. render('backup', array(
  1859. 'title' => generate_title('is_default', i18n('Backup')),
  1860. 'description' => safe_html(strip_tags(blog_description())),
  1861. 'canonical' => site_url(),
  1862. 'metatags' => generate_meta(null, null),
  1863. 'type' => 'is_admin-backup',
  1864. 'is_admin' => true,
  1865. 'bodyclass' => 'admin-backup',
  1866. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Backup')
  1867. ));
  1868. } else {
  1869. render('denied', array(
  1870. 'title' => generate_title('is_default', i18n('Denied')),
  1871. 'description' => safe_html(strip_tags(blog_description())),
  1872. 'canonical' => site_url(),
  1873. 'metatags' => generate_meta(null, null),
  1874. 'type' => 'is_admin-config',
  1875. 'is_admin' => true,
  1876. 'bodyclass' => 'denied',
  1877. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Denied')
  1878. ));
  1879. }
  1880. } else {
  1881. $login = site_url() . 'login';
  1882. header("location: $login");
  1883. }
  1884. });
  1885.  
  1886. // Show Create backup page
  1887. get('/admin/backup-start', function () {
  1888. if (login()) {
  1889. config('views.root', 'system/admin/views');
  1890. $user = $_SESSION[site_url()]['user'];
  1891. $role = user('role', $user);
  1892. if ($role === 'admin') {
  1893. render('backup-start', array(
  1894. 'title' => generate_title('is_default', i18n('Create_backup')),
  1895. 'description' => safe_html(strip_tags(blog_description())),
  1896. 'canonical' => site_url(),
  1897. 'metatags' => generate_meta(null, null),
  1898. 'type' => 'is_admin-backup-start',
  1899. 'is_admin' => true,
  1900. 'bodyclass' => 'admin-backup-start',
  1901. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Create_backup')
  1902. ));
  1903. } else {
  1904. $redir = site_url();
  1905. header("location: $redir");
  1906. }
  1907. } else {
  1908. $login = site_url() . 'login';
  1909. header("location: $login");
  1910. }
  1911. });
  1912.  
  1913. // Show clear cache page
  1914. get('/admin/clear-cache', function () {
  1915. $user = $_SESSION[site_url()]['user'];
  1916. $role = user('role', $user);
  1917. if (login()) {
  1918. config('views.root', 'system/admin/views');
  1919. if ($role === 'editor' || $role === 'admin') {
  1920. render('clear-cache', array(
  1921. 'title' => generate_title('is_default', i18n('Clear_cache')),
  1922. 'description' => safe_html(strip_tags(blog_description())),
  1923. 'canonical' => site_url(),
  1924. 'metatags' => generate_meta(null, null),
  1925. 'type' => 'is_admin-clear-cache',
  1926. 'is_admin' => true,
  1927. 'bodyclass' => 'admin-clear-cache',
  1928. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Clear_cache')
  1929. ));
  1930. } else {
  1931. render('denied', array(
  1932. 'title' => generate_title('is_default', i18n('Denied')),
  1933. 'description' => safe_html(strip_tags(blog_description())),
  1934. 'canonical' => site_url(),
  1935. 'metatags' => generate_meta(null, null),
  1936. 'type' => 'is_admin-clear-cache',
  1937. 'is_admin' => true,
  1938. 'bodyclass' => 'denied',
  1939. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Denied')
  1940. ));
  1941. }
  1942. } else {
  1943. $login = site_url() . 'login';
  1944. header("location: $login");
  1945. }
  1946. });
  1947.  
  1948. // Show Update page
  1949. get('/admin/update', function () {
  1950. $user = $_SESSION[site_url()]['user'];
  1951. $role = user('role', $user);
  1952. if (login()) {
  1953. config('views.root', 'system/admin/views');
  1954. if ($role === 'admin') {
  1955. render('update', array(
  1956. 'title' => generate_title('is_default', i18n('Check_update')),
  1957. 'description' => safe_html(strip_tags(blog_description())),
  1958. 'canonical' => site_url(),
  1959. 'metatags' => generate_meta(null, null),
  1960. 'type' => 'is_admin-update',
  1961. 'is_admin' => true,
  1962. 'bodyclass' => 'admin-update',
  1963. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Check_update')
  1964. ));
  1965. } else {
  1966. render('denied', array(
  1967. 'title' => generate_title('is_default', i18n('Denied')),
  1968. 'description' => safe_html(strip_tags(blog_description())),
  1969. 'canonical' => site_url(),
  1970. 'metatags' => generate_meta(null, null),
  1971. 'type' => 'is_admin-config',
  1972. 'is_admin' => true,
  1973. 'bodyclass' => 'denied',
  1974. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Denied')
  1975. ));
  1976. }
  1977. } else {
  1978. $login = site_url() . 'login';
  1979. header("location: $login");
  1980. }
  1981. });
  1982.  
  1983. // Show the update now link
  1984. get('/admin/update/now/:csrf', function ($CSRF) {
  1985. $proper = is_csrf_proper($CSRF);
  1986. $updater = new \Kanti\HubUpdater(array(
  1987. 'name' => 'danpros/htmly',
  1988. 'prerelease' => !!config("prerelease"),
  1989. ));
  1990. if (login() && $proper && $updater->able()) {
  1991. $user = $_SESSION[site_url()]['user'];
  1992. $role = user('role', $user);
  1993. if ($role === 'admin') {
  1994. $updater->update();
  1995. config('views.root', 'system/admin/views');
  1996. render('updated-to', array(
  1997. 'title' => generate_title('is_default', i18n('Update')),
  1998. 'description' => safe_html(strip_tags(blog_description())),
  1999. 'canonical' => site_url(),
  2000. 'metatags' => generate_meta(null, null),
  2001. 'info' => $updater->getCurrentInfo(),
  2002. 'type' => 'is_admin-update',
  2003. 'is_admin' => true,
  2004. 'bodyclass' => 'admin-update',
  2005. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Update')
  2006. ));
  2007. } else {
  2008. $redir = site_url();
  2009. header("location: $redir");
  2010. }
  2011. } else {
  2012. $login = site_url() . 'login';
  2013. header("location: $login");
  2014. }
  2015. });
  2016.  
  2017. // Show Menu builder
  2018. get('/admin/menu', function () {
  2019. $user = $_SESSION[site_url()]['user'];
  2020. $role = user('role', $user);
  2021. if (login()) {
  2022. config('views.root', 'system/admin/views');
  2023. if ($role === 'editor' || $role === 'admin') {
  2024. render('menu', array(
  2025. 'title' => generate_title('is_default', i18n('Menus')),
  2026. 'description' => safe_html(strip_tags(blog_description())),
  2027. 'canonical' => site_url(),
  2028. 'metatags' => generate_meta(null, null),
  2029. 'type' => 'is_admin-menu',
  2030. 'is_admin' => true,
  2031. 'bodyclass' => 'admin-menu',
  2032. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Menus')
  2033. ));
  2034. } else {
  2035. render('denied', array(
  2036. 'title' => generate_title('is_default', i18n('Denied')),
  2037. 'description' => safe_html(strip_tags(blog_description())),
  2038. 'canonical' => site_url(),
  2039. 'metatags' => generate_meta(null, null),
  2040. 'type' => 'is_admin-menu',
  2041. 'is_admin' => true,
  2042. 'bodyclass' => 'denied',
  2043. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Denied')
  2044. ));
  2045. }
  2046. } else {
  2047. $login = site_url() . 'login';
  2048. header("location: $login");
  2049. }
  2050. });
  2051.  
  2052. post('/admin/menu', function () {
  2053.  
  2054. if (login()) {
  2055. $user = $_SESSION[site_url()]['user'];
  2056. $role = user('role', $user);
  2057. if ($role === 'editor' || $role === 'admin') {
  2058. $json = from($_REQUEST, 'json');
  2059. file_put_contents('content/data/menu.json', json_encode($json, JSON_UNESCAPED_UNICODE));
  2060. echo json_encode(array(
  2061. 'message' => 'Menu saved successfully!',
  2062. ));
  2063. } else {
  2064. $redir = site_url();
  2065. header("location: $redir");
  2066. }
  2067. }
  2068. });
  2069.  
  2070. // Manage users page
  2071. get('/admin/users', function () {
  2072. $user = $_SESSION[site_url()]['user'];
  2073. $role = user('role', $user);
  2074. if (login()) {
  2075. config('views.root', 'system/admin/views');
  2076. if ($role === 'admin') {
  2077. render('users', array(
  2078. 'title' => generate_title('is_default', i18n('User')),
  2079. 'description' => safe_html(strip_tags(blog_description())),
  2080. 'canonical' => site_url(),
  2081. 'metatags' => generate_meta(null, null),
  2082. 'type' => 'is_admin-users',
  2083. 'is_admin' => true,
  2084. 'bodyclass' => 'admin-users',
  2085. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('User')
  2086. ));
  2087. } else {
  2088. render('denied', array(
  2089. 'title' => generate_title('is_default', i18n('Denied')),
  2090. 'description' => safe_html(strip_tags(blog_description())),
  2091. 'canonical' => site_url(),
  2092. 'metatags' => generate_meta(null, null),
  2093. 'type' => 'is_admin-menu',
  2094. 'is_admin' => true,
  2095. 'bodyclass' => 'denied',
  2096. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Denied')
  2097. ));
  2098. }
  2099. } else {
  2100. $login = site_url() . 'login';
  2101. header("location: $login");
  2102. }
  2103. });
  2104.  
  2105. get('/admin/add/user', function () {
  2106. $user = $_SESSION[site_url()]['user'];
  2107. $role = user('role', $user);
  2108. if (login()) {
  2109. config('views.root', 'system/admin/views');
  2110. if ($role === 'admin') {
  2111. render('add-user', array(
  2112. 'title' => generate_title('is_default', i18n('Add_user')),
  2113. 'description' => safe_html(strip_tags(blog_description())),
  2114. 'canonical' => site_url(),
  2115. 'metatags' => generate_meta(null, null),
  2116. 'type' => 'is_admin-users',
  2117. 'is_admin' => true,
  2118. 'bodyclass' => 'admin-users',
  2119. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('add_user')
  2120. ));
  2121. } else {
  2122. render('denied', array(
  2123. 'title' => generate_title('is_default', i18n('Denied')),
  2124. 'description' => safe_html(strip_tags(blog_description())),
  2125. 'canonical' => site_url(),
  2126. 'metatags' => generate_meta(null, null),
  2127. 'type' => 'is_admin-menu',
  2128. 'is_admin' => true,
  2129. 'bodyclass' => 'denied',
  2130. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Denied')
  2131. ));
  2132. }
  2133. } else {
  2134. $login = site_url() . 'login';
  2135. header("location: $login");
  2136. }
  2137. });
  2138.  
  2139. post('/admin/add/user', function () {
  2140. $user = $_SESSION[site_url()]['user'];
  2141. $role = user('role', $user);
  2142. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  2143. $username = from($_REQUEST, 'username');
  2144. $user_role = from($_REQUEST, 'user-role');
  2145. $password = from($_REQUEST, 'password');
  2146. if (login() && $proper) {
  2147. config('views.root', 'system/admin/views');
  2148. if ($role === 'admin') {
  2149. if (!empty($username) && !empty($password)) {
  2150. create_user($username, $password, $user_role);
  2151. } else {
  2152. $message['error'] = '';
  2153. if (empty($username)) {
  2154. $message['error'] .= '<li class="alert alert-danger">Username field is required.</li>';
  2155. }
  2156. if (empty($password)) {
  2157. $message['error'] .= '<li class="alert alert-danger">Password field is required.</li>';
  2158. }
  2159. render('add-user', array(
  2160. 'title' => generate_title('is_default', i18n('Add_user')),
  2161. 'description' => safe_html(strip_tags(blog_description())),
  2162. 'canonical' => site_url(),
  2163. 'metatags' => generate_meta(null, null),
  2164. 'error' => '<ul>' . $message['error'] . '</ul>',
  2165. 'type' => 'is_admin-users',
  2166. 'is_admin' => true,
  2167. 'username' => $username,
  2168. 'user_role' => $user_role,
  2169. 'password' => $password,
  2170. 'bodyclass' => 'admin-users',
  2171. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('add_user')
  2172. ));
  2173. }
  2174. $redir = site_url() . 'admin/users';
  2175. header("location: $redir");
  2176. } else {
  2177. $redir = site_url();
  2178. header("location: $redir");
  2179. }
  2180. } else {
  2181. $login = site_url() . 'login';
  2182. header("location: $login");
  2183. }
  2184. });
  2185.  
  2186. get('/admin/users/:username/edit', function ($username) {
  2187. $user = $_SESSION[site_url()]['user'];
  2188. $role = user('role', $user);
  2189. if (login()) {
  2190. config('views.root', 'system/admin/views');
  2191. if ($role === 'admin') {
  2192. render('edit-user', array(
  2193. 'title' => generate_title('is_default', $username),
  2194. 'description' => safe_html(strip_tags(blog_description())),
  2195. 'canonical' => site_url(),
  2196. 'metatags' => generate_meta(null, null),
  2197. 'type' => 'is_admin-users',
  2198. 'username' => $username,
  2199. 'is_admin' => true,
  2200. 'bodyclass' => 'admin-users',
  2201. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . $username
  2202. ));
  2203. } else {
  2204. render('denied', array(
  2205. 'title' => generate_title('is_default', i18n('Denied')),
  2206. 'description' => safe_html(strip_tags(blog_description())),
  2207. 'canonical' => site_url(),
  2208. 'metatags' => generate_meta(null, null),
  2209. 'type' => 'is_admin-menu',
  2210. 'is_admin' => true,
  2211. 'bodyclass' => 'denied',
  2212. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Denied')
  2213. ));
  2214. }
  2215. } else {
  2216. $login = site_url() . 'login';
  2217. header("location: $login");
  2218. }
  2219. });
  2220.  
  2221. // Submitted Config page data
  2222. post('/admin/users/:username/edit', function () {
  2223.  
  2224. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  2225. if (login() && $proper) {
  2226. $username = from($_REQUEST, 'username');
  2227. $user_role = from($_REQUEST, 'role-name');
  2228. $new_password = from($_REQUEST, 'password');
  2229. $user = $_SESSION[site_url()]['user'];
  2230. $role = user('role', $user);
  2231. $old_password = user('password', $username);
  2232. if ($role === 'admin') {
  2233. $file = 'config/users/' . $username . '.ini';
  2234. if (file_exists($file)) {
  2235. if (empty($new_password)) {
  2236. file_put_contents($file, "password = " . $old_password . "\n" .
  2237. "encryption = password_hash\n" .
  2238. "role = " . $user_role . "\n", LOCK_EX);
  2239. } else {
  2240. update_user($username, $new_password, $user_role);
  2241. }
  2242. }
  2243. $redir = site_url() . 'admin/users';
  2244. header("location: $redir");
  2245. } else {
  2246. $redir = site_url();
  2247. header("location: $redir");
  2248. }
  2249. } else {
  2250. $login = site_url() . 'login';
  2251. header("location: $login");
  2252. }
  2253. });
  2254.  
  2255. get('/admin/users/:username/delete', function ($username) {
  2256. $user = $_SESSION[site_url()]['user'];
  2257. $role = user('role', $user);
  2258. if (login()) {
  2259. config('views.root', 'system/admin/views');
  2260. if ($role === 'admin') {
  2261. render('delete-user', array(
  2262. 'title' => generate_title('is_default', $username),
  2263. 'description' => safe_html(strip_tags(blog_description())),
  2264. 'canonical' => site_url(),
  2265. 'metatags' => generate_meta(null, null),
  2266. 'type' => 'is_admin-users',
  2267. 'username' => $username,
  2268. 'is_admin' => true,
  2269. 'bodyclass' => 'admin-users',
  2270. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . $username
  2271. ));
  2272. } else {
  2273. render('denied', array(
  2274. 'title' => generate_title('is_default', i18n('Denied')),
  2275. 'description' => safe_html(strip_tags(blog_description())),
  2276. 'canonical' => site_url(),
  2277. 'metatags' => generate_meta(null, null),
  2278. 'type' => 'is_admin-menu',
  2279. 'is_admin' => true,
  2280. 'bodyclass' => 'denied',
  2281. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Denied')
  2282. ));
  2283. }
  2284. } else {
  2285. $login = site_url() . 'login';
  2286. header("location: $login");
  2287. }
  2288. });
  2289.  
  2290. post('/admin/users/:username/delete', function () {
  2291. $user = $_SESSION[site_url()]['user'];
  2292. $role = user('role', $user);
  2293. $file = from($_REQUEST, 'file');
  2294. $username = from($_REQUEST, 'username');
  2295. $user_role = user('role', $username);
  2296. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  2297. if ($proper && login()) {
  2298. if ($role === 'admin') {
  2299. if ($user_role !== 'admin') {
  2300. unlink($file);
  2301. }
  2302. }
  2303. $redir = site_url() . 'admin/users';
  2304. header("location: $redir");
  2305. } else {
  2306. $login = site_url() . 'login';
  2307. header("location: $login");
  2308. }
  2309. });
  2310.  
  2311. post('/admin/gallery', function () {
  2312.  
  2313. if (login()) {
  2314. $page = from($_REQUEST, 'page');
  2315. $images = image_gallery(null, $page, 40);
  2316. echo json_encode(array('images' => $images));
  2317. }
  2318. });
  2319.  
  2320. // Show category page
  2321. get('/admin/categories', function () {
  2322. $user = $_SESSION[site_url()]['user'];
  2323. $role = user('role', $user);
  2324. if (login()) {
  2325. config('views.root', 'system/admin/views');
  2326. if ($role === 'editor' || $role === 'admin') {
  2327. render('categories', array(
  2328. 'title' => generate_title('is_default', i18n('Categories')),
  2329. 'description' => safe_html(strip_tags(blog_description())),
  2330. 'canonical' => site_url(),
  2331. 'metatags' => generate_meta(null, null),
  2332. 'type' => 'is_admin-categories',
  2333. 'is_admin' => true,
  2334. 'bodyclass' => 'admin-categories',
  2335. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Categories')
  2336. ));
  2337. } else {
  2338. render('denied', array(
  2339. 'title' => generate_title('is_default', i18n('Denied')),
  2340. 'description' => safe_html(strip_tags(blog_description())),
  2341. 'canonical' => site_url(),
  2342. 'metatags' => generate_meta(null, null),
  2343. 'type' => 'is_admin-categories',
  2344. 'is_admin' => true,
  2345. 'bodyclass' => 'denied',
  2346. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Denied')
  2347. ));
  2348. }
  2349. } else {
  2350. $login = site_url() . 'login';
  2351. header("location: $login");
  2352. }
  2353. });
  2354.  
  2355. // Show the category page
  2356. get('/admin/categories/:category', function ($category) {
  2357.  
  2358. $user = $_SESSION[site_url()]['user'];
  2359. $role = user('role', $user);
  2360. if (login()) {
  2361. config('views.root', 'system/admin/views');
  2362. if ($role === 'editor' || $role === 'admin') {
  2363. $page = from($_GET, 'page');
  2364. $page = $page ? (int)$page : 1;
  2365. $perpage = config('category.perpage');
  2366. if (empty($perpage)) {
  2367. $perpage = 10;
  2368. }
  2369.  
  2370. $posts = get_category($category, $page, $perpage);
  2371. $desc = get_category_info($category);
  2372. if(!empty($desc)) {
  2373. $desc = $desc[0];
  2374. }
  2375. if (empty($desc)) {
  2376. // a non-existing page
  2377. not_found();
  2378. }
  2379. $total = $desc->count;
  2380. render('category-list', array(
  2381. 'title' => generate_title('is_default', $desc->title),
  2382. 'description' => $desc->description,
  2383. 'canonical' => $desc->url,
  2384. 'metatags' => generate_meta(null, null),
  2385. 'page' => $page,
  2386. 'posts' => $posts,
  2387. 'category' => $desc,
  2388. 'bodyclass' => 'in-category category-' . strtolower($category),
  2389. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; <a href="' . site_url() . 'admin/categories">' . i18n('Categories') .'</a> &#187; ' . $desc->title,
  2390. 'pagination' => has_pagination($total, $perpage, $page),
  2391. 'is_category' => true,
  2392. ));
  2393. } else {
  2394. render('denied', array(
  2395. 'title' => generate_title('is_default', 'Categories'),
  2396. 'description' => safe_html(strip_tags(blog_description())),
  2397. 'canonical' => site_url(),
  2398. 'metatags' => generate_meta(null, null),
  2399. 'type' => 'is_admin-categories',
  2400. 'is_admin' => true,
  2401. 'bodyclass' => 'denied',
  2402. 'breadcrumb' => '',
  2403. ));
  2404. }
  2405. } else {
  2406. $login = site_url() . 'login';
  2407. }
  2408. });
  2409.  
  2410. // Show the category page
  2411. get('/category/:category', function ($category) {
  2412.  
  2413. if (isset($_GET['search'])) {
  2414. $search = _h($_GET['search']);
  2415. $url = site_url() . 'search/' . remove_accent($search);
  2416. header("Location: $url");
  2417. }
  2418.  
  2419. if (!login()) {
  2420. file_cache($_SERVER['REQUEST_URI']);
  2421. }
  2422.  
  2423. $page = from($_GET, 'page');
  2424. $page = $page ? (int)$page : 1;
  2425. $perpage = config('category.perpage');
  2426. if (empty($perpage)) {
  2427. $perpage = 10;
  2428. }
  2429.  
  2430. $posts = get_category($category, $page, $perpage);
  2431. $desc = get_category_info($category);
  2432. if(!empty($desc)) {
  2433. $desc = $desc[0];
  2434. }
  2435.  
  2436. if (empty($posts) || $page < 1) {
  2437. // a non-existing page
  2438. not_found();
  2439. }
  2440. $total = $desc->count;
  2441. $vroot = rtrim(config('views.root'), '/');
  2442. $lt = $vroot . '/layout--category--'. strtolower($category) .'.html.php';
  2443. $ls = $vroot . '/layout--category.html.php';
  2444. if (file_exists($lt)) {
  2445. $layout = 'layout--category--' . strtolower($category);
  2446. } else if (file_exists($ls)) {
  2447. $layout = 'layout--category';
  2448. } else {
  2449. $layout = '';
  2450. }
  2451. $pv = $vroot . '/main--category--'. strtolower($category) .'.html.php';
  2452. $ps = $vroot . '/main--category.html.php';
  2453. if (file_exists($pv)) {
  2454. $pview = 'main--category--' . strtolower($category);
  2455. } else if (file_exists($ps)) {
  2456. $pview = 'main--category';
  2457. } else {
  2458. $pview = 'main';
  2459. }
  2460. render($pview, array(
  2461. 'title' => generate_title('is_category', $desc),
  2462. 'description' => $desc->description,
  2463. 'canonical' => $desc->url,
  2464. 'metatags' => generate_meta('is_category', $desc),
  2465. 'page' => $page,
  2466. 'posts' => $posts,
  2467. 'category' => $desc,
  2468. 'bodyclass' => 'in-category category-' . strtolower($category),
  2469. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . $desc->title,
  2470. 'pagination' => has_pagination($total, $perpage, $page),
  2471. 'is_category' => true
  2472. ), $layout);
  2473. });
  2474.  
  2475. // Show the RSS feed
  2476. get('/category/:category/feed', function ($category) {
  2477.  
  2478. header('Content-Type: application/rss+xml');
  2479. $posts = get_category($category, 1, config('rss.count'));
  2480. $data = get_category_info($category);
  2481. if(!empty($data)) {
  2482. $data = $data[0];
  2483. }
  2484.  
  2485. // Show an RSS feed
  2486. echo generate_rss($posts, $data);
  2487. });
  2488.  
  2489. // Show edit the category page
  2490. get('/category/:category/edit', function ($category) {
  2491. $user = $_SESSION[site_url()]['user'];
  2492. $role = user('role', $user);
  2493. if (login()) {
  2494. config('views.root', 'system/admin/views');
  2495. if ($role === 'editor' || $role === 'admin') {
  2496. $post = get_category_info($category);
  2497.  
  2498. if(empty($post)) {
  2499. not_found();
  2500. }
  2501.  
  2502. $post = $post[0];
  2503.  
  2504. render('edit-page', array(
  2505. 'title' => generate_title('is_default', i18n('Edit_category')),
  2506. 'description' => safe_html(strip_tags(blog_description())),
  2507. 'canonical' => site_url(),
  2508. 'metatags' => generate_meta(null, null),
  2509. 'type' => 'is_category',
  2510. 'is_admin' => true,
  2511. 'bodyclass' => 'edit-category',
  2512. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Category') . ': ' . $post->title,
  2513. 'p' => $post,
  2514. 'static' => $post,
  2515. ));
  2516. } else {
  2517. render('denied', array(
  2518. 'title' => generate_title('is_default', i18n('Denied')),
  2519. 'description' => safe_html(strip_tags(blog_description())),
  2520. 'canonical' => site_url(),
  2521. 'metatags' => generate_meta(null, null),
  2522. 'type' => 'is_category',
  2523. 'is_admin' => true,
  2524. 'bodyclass' => 'denied',
  2525. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Denied')
  2526. ));
  2527. }
  2528. } else {
  2529. $login = site_url() . 'login';
  2530. header("location: $login");
  2531. }
  2532. });
  2533.  
  2534. // Get edited data from category page
  2535. post('/category/:category/edit', function () {
  2536.  
  2537. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  2538.  
  2539. if(!login()) {
  2540. $login = site_url() . 'login';
  2541. header("location: $login");
  2542. }
  2543.  
  2544. $title = from($_REQUEST, 'title');
  2545. $url = from($_REQUEST, 'url');
  2546. $content = from($_REQUEST, 'content');
  2547. $oldfile = from($_REQUEST, 'oldfile');
  2548. $destination = from($_GET, 'destination');
  2549. $description = from($_REQUEST, 'description');
  2550. $user = $_SESSION[site_url()]['user'];
  2551. $role = user('role', $user);
  2552. if ($role === 'editor' || $role === 'admin') {
  2553. if ($proper && !empty($title) && !empty($content)) {
  2554. if (!empty($url)) {
  2555. edit_category($title, $url, $content, $oldfile, $destination, $description);
  2556. } else {
  2557. $url = $title;
  2558. edit_category($title, $url, $content, $oldfile, $destination, $description);
  2559. }
  2560. } else {
  2561. $message['error'] = '';
  2562. if (empty($title)) {
  2563. $message['error'] .= '<li class="alert alert-danger">Title field is required.</li>';
  2564. }
  2565. if (empty($content)) {
  2566. $message['error'] .= '<li class="alert alert-danger">Content field is required.</li>';
  2567. }
  2568. if (!$proper) {
  2569. $message['error'] .= '<li class="alert alert-danger">CSRF Token not correct.</li>';
  2570. }
  2571. config('views.root', 'system/admin/views');
  2572.  
  2573. render('edit-page', array(
  2574. 'title' => generate_title('is_default', i18n('Edit_category')),
  2575. 'description' => safe_html(strip_tags(blog_description())),
  2576. 'canonical' => site_url(),
  2577. 'metatags' => generate_meta(null, null),
  2578. 'error' => '<ul>' . $message['error'] . '</ul>',
  2579. 'oldfile' => $oldfile,
  2580. 'postTitle' => $title,
  2581. 'postUrl' => $url,
  2582. 'postContent' => $content,
  2583. 'type' => 'is_category',
  2584. 'is_admin' => true,
  2585. 'bodyclass' => 'edit-category',
  2586. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Edit_category')
  2587. ));
  2588. }
  2589. } else {
  2590. $redir = site_url();
  2591. header("location: $redir");
  2592. }
  2593. });
  2594.  
  2595. // Delete category
  2596. get('/category/:category/delete', function ($category) {
  2597. $user = $_SESSION[site_url()]['user'];
  2598. $role = user('role', $user);
  2599. if (login()) {
  2600. config('views.root', 'system/admin/views');
  2601. if ($role === 'editor' || $role === 'admin') {
  2602. $post = get_category_info($category);
  2603.  
  2604. if(empty($post)) {
  2605. not_found();
  2606. }
  2607.  
  2608. $post = $post[0];
  2609.  
  2610. render('delete-category', array(
  2611. 'title' => generate_title('is_default', i18n('Delete') . ' ' . i18n('Category')),
  2612. 'description' => safe_html(strip_tags(blog_description())),
  2613. 'canonical' => site_url(),
  2614. 'metatags' => generate_meta(null, null),
  2615. 'type' => 'is_category',
  2616. 'is_admin' => true,
  2617. 'bodyclass' => 'delete-category',
  2618. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Category') . ': ' . $post->title,
  2619. 'p' => $post,
  2620. 'static' => $post,
  2621. 'type' => 'categoryPage',
  2622. ));
  2623. } else {
  2624. render('denied', array(
  2625. 'title' => generate_title('is_default', i18n('Denied')),
  2626. 'description' => safe_html(strip_tags(blog_description())),
  2627. 'canonical' => site_url(),
  2628. 'metatags' => generate_meta(null, null),
  2629. 'type' => 'is_admin-config',
  2630. 'is_admin' => true,
  2631. 'bodyclass' => 'denied',
  2632. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Denied')
  2633. ));
  2634. }
  2635. } else {
  2636. $login = site_url() . 'login';
  2637. header("location: $login");
  2638. }
  2639. });
  2640.  
  2641. // Get deleted category data
  2642. post('/category/:category/delete', function () {
  2643. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  2644. if ($proper && login()) {
  2645. $user = $_SESSION[site_url()]['user'];
  2646. $role = user('role', $user);
  2647. if ($role === 'editor' || $role === 'admin') {
  2648. $file = from($_REQUEST, 'file');
  2649. $destination = from($_GET, 'destination');
  2650. delete_page($file, $destination);
  2651. } else {
  2652. $redir = site_url();
  2653. header("location: $redir");
  2654. }
  2655. }
  2656. });
  2657.  
  2658. // Show the type page
  2659. get('/type/:type', function ($type) {
  2660.  
  2661. if (isset($_GET['search'])) {
  2662. $search = _h($_GET['search']);
  2663. $url = site_url() . 'search/' . remove_accent($search);
  2664. header("Location: $url");
  2665. }
  2666.  
  2667. if (!login()) {
  2668. file_cache($_SERVER['REQUEST_URI']);
  2669. }
  2670.  
  2671. $page = from($_GET, 'page');
  2672. $page = $page ? (int)$page : 1;
  2673. $perpage = config('type.perpage');
  2674. if (empty($perpage)) {
  2675. $perpage = 10;
  2676. }
  2677.  
  2678. $posts = get_type($type, $page, $perpage);
  2679.  
  2680. $total = get_typecount($type);
  2681. $ttype = new stdClass;
  2682. $ttype->title = ucfirst($type);
  2683. $ttype->url = site_url() . 'type/' . strtolower($type);
  2684. $ttype->count = $total;
  2685. $ttype->description = i18n('Posts_with_type') . ' ' . ucfirst($type) . ' ' . i18n('by') . ' ' . blog_title();
  2686. $ttype->body = $ttype->description;
  2687.  
  2688. if (empty($posts) || $page < 1) {
  2689. // a non-existing page
  2690. not_found();
  2691. }
  2692. $vroot = rtrim(config('views.root'), '/');
  2693. $lt = $vroot . '/layout--type--'. strtolower($type) .'.html.php';
  2694. $ls = $vroot . '/layout--type.html.php';
  2695. if (file_exists($lt)) {
  2696. $layout = 'layout--type--' . strtolower($type);
  2697. } else if (file_exists($ls)) {
  2698. $layout = 'layout--type';
  2699. } else {
  2700. $layout = '';
  2701. }
  2702. $pv = $vroot . '/main--type--'. strtolower($type) .'.html.php';
  2703. $ps = $vroot . '/main--type.html.php';
  2704. if (file_exists($pv)) {
  2705. $pview = 'main--type--' . strtolower($type);
  2706. } else if (file_exists($ps)) {
  2707. $pview = 'main--type';
  2708. } else {
  2709. $pview = 'main';
  2710. }
  2711. render($pview, array(
  2712. 'title' => generate_title('is_type', $ttype),
  2713. 'description' => $ttype->description,
  2714. 'canonical' => $ttype->url,
  2715. 'metatags' => generate_meta('is_type', $ttype),
  2716. 'page' => $page,
  2717. 'posts' => $posts,
  2718. 'type' => $ttype,
  2719. 'bodyclass' => 'in-type type-' . strtolower($type),
  2720. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . ucfirst($type),
  2721. 'pagination' => has_pagination($total, $perpage, $page),
  2722. 'is_type' => true
  2723. ), $layout);
  2724. });
  2725.  
  2726. // Show the RSS feed
  2727. get('/type/:type/feed', function ($type) {
  2728.  
  2729. header('Content-Type: application/rss+xml');
  2730. $posts = get_type($type, 1, config('rss.count'));
  2731. $data = new stdClass;
  2732. $data->title = ucfirst($type);
  2733. $data->url = site_url() . 'type/' . strtolower($type);
  2734. $data->body = i18n('Posts_with_type') . ' ' . ucfirst($type) . ' ' . i18n('by') . ' ' . blog_title();
  2735.  
  2736. // Show an RSS feed
  2737. echo generate_rss($posts, $data);
  2738. });
  2739.  
  2740. // Show the tag page
  2741. get('/tag/:tag', function ($tag) {
  2742.  
  2743. if (isset($_GET['search'])) {
  2744. $search = _h($_GET['search']);
  2745. $url = site_url() . 'search/' . remove_accent($search);
  2746. header("Location: $url");
  2747. }
  2748.  
  2749. if (!login()) {
  2750. file_cache($_SERVER['REQUEST_URI']);
  2751. }
  2752.  
  2753. $page = from($_GET, 'page');
  2754. $page = $page ? (int)$page : 1;
  2755. $perpage = config('tag.perpage');
  2756.  
  2757. $posts = get_tag($tag, $page, $perpage);
  2758.  
  2759. $total = get_tagcount($tag);
  2760. $ttag = new stdClass;
  2761. $ttag->title = tag_i18n($tag);
  2762. $ttag->url = site_url() . 'tag/' . strtolower($tag);
  2763. $ttag->count = $total;
  2764. $ttag->description = i18n('All_posts_tagged') . ' ' . tag_i18n($tag) . ' ' . i18n('by') . ' ' . blog_title();
  2765. $ttag->body = $ttag->description;
  2766.  
  2767. if (empty($posts) || $page < 1) {
  2768. // a non-existing page
  2769. not_found();
  2770. }
  2771. $vroot = rtrim(config('views.root'), '/');
  2772. $lt = $vroot . '/layout--tag--' . strtolower($tag) . '.html.php';
  2773. $ls = $vroot . '/layout--tag.html.php';
  2774. if (file_exists($lt)) {
  2775. $layout = 'layout--tag--' . strtolower($tag);
  2776. } else if (file_exists($ls)) {
  2777. $layout = 'layout--tag';
  2778. } else {
  2779. $layout = '';
  2780. }
  2781. $pv = $vroot . '/main--tag--' . strtolower($tag) . '.html.php';
  2782. $ps = $vroot . '/main--tag.html.php';
  2783. if (file_exists($pv)) {
  2784. $pview = 'main--tag--' . strtolower($tag);
  2785. } elseif (file_exists($ps)) {
  2786. $pview = 'main--tag';
  2787. } else {
  2788. $pview = 'main';
  2789. }
  2790. render($pview, array(
  2791. 'title' => generate_title('is_tag', $ttag),
  2792. 'description' => $ttag->description,
  2793. 'canonical' => $ttag->url,
  2794. 'metatags' => generate_meta('is_tag', $ttag),
  2795. 'page' => $page,
  2796. 'posts' => $posts,
  2797. 'tag' => $ttag,
  2798. 'bodyclass' => 'in-tag tag-' . strtolower($tag),
  2799. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Posts_tagged') . ' ' . tag_i18n($tag),
  2800. 'pagination' => has_pagination($total, $perpage, $page),
  2801. 'is_tag' => true
  2802. ), $layout);
  2803. });
  2804.  
  2805. // Show the RSS feed
  2806. get('/tag/:tag/feed', function ($tag) {
  2807.  
  2808. header('Content-Type: application/rss+xml');
  2809. $posts = get_tag($tag, 1, config('rss.count'));
  2810. $data = new stdClass;
  2811. $data->title = tag_i18n($tag);
  2812. $data->url = site_url() . 'tag/' . strtolower($tag);
  2813. $data->body = i18n('All_posts_tagged') . ' ' . tag_i18n($tag) . ' ' . i18n('by') . ' ' . blog_title();
  2814.  
  2815. // Show an RSS feed
  2816. echo generate_rss($posts, $data);
  2817. });
  2818.  
  2819. // Show the archive page
  2820. get('/archive/:req', function ($req) {
  2821.  
  2822. if (isset($_GET['search'])) {
  2823. $search = _h($_GET['search']);
  2824. $url = site_url() . 'search/' . remove_accent($search);
  2825. header("Location: $url");
  2826. }
  2827.  
  2828. if (!login()) {
  2829. file_cache($_SERVER['REQUEST_URI']);
  2830. }
  2831.  
  2832. $page = from($_GET, 'page');
  2833. $page = $page ? (int)$page : 1;
  2834. $perpage = config('archive.perpage');
  2835.  
  2836. $posts = get_archive($req, $page, $perpage);
  2837.  
  2838. $total = get_count($req, 'basename');
  2839.  
  2840. if (empty($posts) || $page < 1) {
  2841. // a non-existing page
  2842. not_found();
  2843. }
  2844.  
  2845. $time = explode('-', $req);
  2846. $date = strtotime($req);
  2847.  
  2848. if (isset($time[0]) && isset($time[1]) && isset($time[2])) {
  2849. $timestamp = format_date($date, 'd F Y');
  2850. } elseif (isset($time[0]) && isset($time[1])) {
  2851. $timestamp = format_date($date, 'F Y');
  2852. } else {
  2853. $timestamp = $req;
  2854. }
  2855. $tarchive = new stdClass;
  2856. $tarchive->title = $timestamp;
  2857. $tarchive->url = site_url() . 'archive/' . $req;
  2858. $tarchive->count = $total;
  2859. $tarchive->description = i18n('Archive_page_for') . ' ' . $timestamp . ' ' . i18n('by') . ' ' . blog_title();
  2860. $tarchive->body = $tarchive->description;
  2861.  
  2862. if (!$date) {
  2863. // a non-existing page
  2864. not_found();
  2865. }
  2866. $vroot = rtrim(config('views.root'), '/');
  2867. $lt = $vroot . '/layout--archive.html.php';
  2868. if (file_exists($lt)) {
  2869. $layout = 'layout--archive';
  2870. } else {
  2871. $layout = '';
  2872. }
  2873. $pv = $vroot . '/main--archive.html.php';
  2874. if (file_exists($pv)) {
  2875. $pview = 'main--archive';
  2876. } else {
  2877. $pview = 'main';
  2878. }
  2879.  
  2880. render($pview, array(
  2881. 'title' => generate_title('is_archive', $tarchive),
  2882. 'description' => $tarchive->description,
  2883. 'canonical' => $tarchive->url,
  2884. 'metatags' => generate_meta('is_archive', $tarchive),
  2885. 'page' => $page,
  2886. 'posts' => $posts,
  2887. 'archive' => $tarchive,
  2888. 'bodyclass' => 'in-archive archive-' . strtolower($req),
  2889. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Archive_for') . ' ' . $timestamp,
  2890. 'pagination' => has_pagination($total, $perpage, $page),
  2891. 'is_archive' => true
  2892. ), $layout);
  2893. });
  2894.  
  2895. // Show the RSS feed
  2896. get('/archive/:req/feed', function ($req) {
  2897.  
  2898. header('Content-Type: application/rss+xml');
  2899. $posts = get_archive($req, 1, config('rss.count'));
  2900. $time = explode('-', $req);
  2901. $date = strtotime($req);
  2902.  
  2903. if (isset($time[0]) && isset($time[1]) && isset($time[2])) {
  2904. $timestamp = format_date($date, 'd F Y');
  2905. } elseif (isset($time[0]) && isset($time[1])) {
  2906. $timestamp = format_date($date, 'F Y');
  2907. } else {
  2908. $timestamp = $req;
  2909. }
  2910. $data = new stdClass;
  2911. $data->title = $timestamp;
  2912. $data->url = site_url() . 'archive/' . $req;
  2913. $data->body = i18n('Archive_page_for') . ' ' . $timestamp . ' ' . i18n('by') . ' ' . blog_title();
  2914.  
  2915. // Show an RSS feed
  2916. echo generate_rss($posts, $data);
  2917. });
  2918.  
  2919. // Show the search page
  2920. get('/search/:keyword', function ($keyword) {
  2921.  
  2922. if (isset($_GET['search'])) {
  2923. $search = _h($_GET['search']);
  2924. $url = site_url() . 'search/' . remove_accent($search);
  2925. header("Location: $url");
  2926. }
  2927.  
  2928. if (!login()) {
  2929. file_cache($_SERVER['REQUEST_URI']);
  2930. }
  2931.  
  2932. $page = from($_GET, 'page');
  2933. $page = $page ? (int)$page : 1;
  2934. $perpage = config('search.perpage');
  2935.  
  2936. $posts = get_keyword($keyword, $page, $perpage);
  2937. $total = keyword_count($keyword);
  2938.  
  2939. $tsearch = new stdClass;
  2940. $tsearch->title = $keyword;
  2941. $tsearch->url = site_url() . 'search/' . strtolower($keyword);
  2942. $tsearch->count = $total;
  2943. $tsearch->description = i18n('Search_results_for') . ' ' . $keyword . ' ' . i18n('by') . ' ' . blog_title();
  2944. $tsearch->body = $tsearch->description;
  2945.  
  2946. $vroot = rtrim(config('views.root'), '/');
  2947. $lt = $vroot . '/layout--search.html.php';
  2948. if (file_exists($lt)) {
  2949. $layout = 'layout--search';
  2950. } else {
  2951. $layout = '';
  2952. }
  2953.  
  2954. if (!$posts || $page < 1) {
  2955. // a non-existing page or no search result
  2956. render('404-search', array(
  2957. 'title' => i18n('Search_results_not_found') . ' - ' . blog_title(),
  2958. 'description' => i18n('Search_results_not_found'),
  2959. 'canonical' => site_url(),
  2960. 'metatags' => generate_meta(null, null),
  2961. 'search' => $tsearch,
  2962. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('No_search_results'),
  2963. 'canonical' => site_url(),
  2964. 'bodyclass' => 'error-404-search',
  2965. 'is_404search' => true,
  2966. ), $layout);
  2967. die;
  2968. }
  2969. $pv = $vroot . '/main--search.html.php';
  2970. if (file_exists($pv)) {
  2971. $pview = 'main--search';
  2972. } else {
  2973. $pview = 'main';
  2974. }
  2975.  
  2976. render($pview, array(
  2977. 'title' => generate_title('is_search', $tsearch),
  2978. 'description' => $tsearch->description,
  2979. 'canonical' => $tsearch->url,
  2980. 'metatags' => generate_meta('is_search', $tsearch),
  2981. 'page' => $page,
  2982. 'posts' => $posts,
  2983. 'search' => $tsearch,
  2984. 'bodyclass' => 'in-search search-' . strtolower($keyword),
  2985. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Search_results_for') . ' ' . $keyword,
  2986. 'pagination' => has_pagination($total, $perpage, $page),
  2987. 'is_search' => true
  2988. ), $layout);
  2989. });
  2990.  
  2991. // Show the RSS feed
  2992. get('/search/:keyword/feed', function ($keyword) {
  2993.  
  2994. header('Content-Type: application/rss+xml');
  2995. $posts = get_keyword($keyword, 1, config('rss.count'));
  2996.  
  2997. $data = new stdClass;
  2998. $data->title = $keyword;
  2999. $data->url = site_url() . 'search/' . strtolower($keyword);
  3000. $data->body = i18n('Search_results_for') . ' ' . $keyword . ' ' . i18n('by') . ' ' . blog_title();
  3001.  
  3002. // Show an RSS feed
  3003. echo generate_rss($posts, $data);
  3004. });
  3005.  
  3006. // The JSON API
  3007. get('/api/json', function () {
  3008.  
  3009. header('Content-type: application/json');
  3010.  
  3011. $page = from($_GET, 'page');
  3012. $page = $page ? (int)$page : 1;
  3013. $perpage = config('json.count');
  3014.  
  3015. echo generate_json(get_posts(null, $page, $perpage));
  3016. });
  3017.  
  3018. // Show the RSS feed
  3019. get('/feed/rss', function () {
  3020.  
  3021. header('Content-Type: application/rss+xml');
  3022.  
  3023. // Show an RSS feed with the 30 latest posts
  3024. echo generate_rss(get_posts(null, 1, config('rss.count')));
  3025. });
  3026.  
  3027. // Generate OPML file
  3028. get('/feed/opml', function () {
  3029.  
  3030. header('Content-Type: text/xml');
  3031.  
  3032. // Generate OPML file for the RSS
  3033. echo generate_opml();
  3034. });
  3035.  
  3036. // Show blog post without year-month
  3037. get('/post/:name', function ($name) {
  3038.  
  3039. if (isset($_GET['search'])) {
  3040. $search = _h($_GET['search']);
  3041. $url = site_url() . 'search/' . remove_accent($search);
  3042. header("Location: $url");
  3043. }
  3044.  
  3045. if (config('permalink.type') != 'post') {
  3046. $post = find_post(null, null, $name);
  3047. if (is_null($post)) {
  3048. not_found();
  3049. } else {
  3050. $current = $post['current'];
  3051. }
  3052. $redir = site_url() . date('Y/m', $current->date) . '/' . $name;
  3053. header("location: $redir", TRUE, 301);
  3054. }
  3055.  
  3056. if (config("views.counter") != "true") {
  3057. if (!login()) {
  3058. file_cache($_SERVER['REQUEST_URI']);
  3059. }
  3060. } else {
  3061. add_view('post_' . $name);
  3062. if (!login()) {
  3063. file_cache($_SERVER['REQUEST_URI']);
  3064. }
  3065. }
  3066.  
  3067. $post = find_post(null, null, $name);
  3068.  
  3069. if (is_null($post)) {
  3070. not_found('post_' . $name);
  3071. } else {
  3072. $current = $post['current'];
  3073. }
  3074.  
  3075. $author = new stdClass;
  3076. $author->url = $current->authorUrl;
  3077. $author->name = $current->authorName;
  3078. $author->description = $current->authorDescription;
  3079. $author->about = $current->authorAbout;
  3080. $author->avatar = $current->authorAvatar;
  3081.  
  3082. if (array_key_exists('prev', $post)) {
  3083. $prev = $post['prev'];
  3084. } else {
  3085. $prev = array();
  3086. }
  3087.  
  3088. if (array_key_exists('next', $post)) {
  3089. $next = $post['next'];
  3090. } else {
  3091. $next = array();
  3092. }
  3093. if (isset($current->image)) {
  3094. $var = 'imagePost';
  3095. } elseif (isset($current->link)) {
  3096. $var = 'linkPost';
  3097. } elseif (isset($current->quote)) {
  3098. $var = 'quotePost';
  3099. } elseif (isset($current->audio)) {
  3100. $var = 'audioPost';
  3101. } elseif (isset($current->video)) {
  3102. $var = 'videoPost'; }
  3103. else {
  3104. $var = 'blogPost';
  3105. }
  3106. if (config('blog.enable') === 'true') {
  3107. $blog = '<li class="breadcrumb-item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a itemprop="item" href="' . site_url() . 'blog"><span itemprop="name">Blog</span></a><meta itemprop="position" content="2" /></li> &#187; ';
  3108. } else {
  3109. $blog = '';
  3110. }
  3111.  
  3112. $vroot = rtrim(config('views.root'), '/');
  3113. $lt = $vroot . '/layout--post--' . $current->ct . '.html.php';
  3114. $pt = $vroot . '/layout--post--' . $current->type . '.html.php';
  3115. $ls = $vroot . '/layout--post.html.php';
  3116. if (file_exists($lt)) {
  3117. $layout = 'layout--post--' . $current->ct;
  3118. } else if (file_exists($pt)) {
  3119. $layout = 'layout--post--' . $current->type;
  3120. } else if (file_exists($ls)) {
  3121. $layout = 'layout--post';
  3122. } else {
  3123. $layout = '';
  3124. }
  3125. $pv = $vroot . '/post--' . $current->ct . '.html.php';
  3126. $pvt = $vroot . '/post--' . $current->type . '.html.php';
  3127. if (file_exists($pv)) {
  3128. $pview = 'post--' . $current->ct;
  3129. } else if(file_exists($pvt)) {
  3130. $pview = 'post--' . $current->type;
  3131. } else {
  3132. $pview = 'post';
  3133. }
  3134.  
  3135. render($pview, array(
  3136. 'title' => generate_title('is_post', $current),
  3137. 'description' => $current->description,
  3138. 'canonical' => $current->url,
  3139. 'metatags' => generate_meta('is_post', $current),
  3140. 'p' => $current,
  3141. 'post' => $current,
  3142. 'author' => $author,
  3143. 'bodyclass' => 'in-post category-' . $current->ct . ' type-' . $current->type,
  3144. 'breadcrumb' => '<style>.breadcrumb-list {margin:0; padding:0;} .breadcrumb-list li {display: inline-block; list-style: none;}</style><ol class="breadcrumb-list" itemscope itemtype="http://schema.org/BreadcrumbList"><li class="breadcrumb-item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a itemprop="item" href="' . site_url() . '"><span itemprop="name">' . config('breadcrumb.home') . '</span></a><meta itemprop="position" content="1" /></li> &#187; '. $blog . '<li class="breadcrumb-item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">' . $current->categoryb . '<meta itemprop="position" content="3" /></li>' . ' &#187; ' . $current->title . '</ol>',
  3145. 'prev' => has_prev($prev),
  3146. 'next' => has_next($next),
  3147. 'type' => $var,
  3148. 'is_post' => true
  3149. ), $layout);
  3150.  
  3151. });
  3152.  
  3153. // Edit blog post
  3154. get('/post/:name/edit', function ($name) {
  3155.  
  3156. if (login()) {
  3157.  
  3158. $user = $_SESSION[site_url()]['user'];
  3159. $role = user('role', $user);
  3160.  
  3161. config('views.root', 'system/admin/views');
  3162. $post = find_post(null, null, $name);
  3163.  
  3164. if (!$post) {
  3165. $post = find_draft(null, null, $name);
  3166. if (!$post) {
  3167. $post = find_scheduled(null, null, $name);
  3168. if (!$post) {
  3169. not_found();
  3170. }
  3171. }
  3172.  
  3173. }
  3174.  
  3175. $current = $post['current'];
  3176. if (isset($current->image)) {
  3177. $type= 'is_image';
  3178. } elseif (isset($current->link)) {
  3179. $type = 'is_link';
  3180. } elseif (isset($current->quote)) {
  3181. $type = 'is_quote';
  3182. } elseif (isset($current->audio)) {
  3183. $type = 'is_audio';
  3184. } elseif (isset($current->video)) {
  3185. $type = 'is_video';
  3186. } else {
  3187. $type = 'is_post';
  3188. }
  3189. if ($user === $current->author || $role === 'editor' || $role === 'admin') {
  3190. render('edit-content', array(
  3191. 'title' => generate_title('is_default', $current->title),
  3192. 'description' => safe_html(strip_tags(blog_description())),
  3193. 'canonical' => site_url(),
  3194. 'metatags' => generate_meta(null, null),
  3195. 'p' => $current,
  3196. 'post' => $current,
  3197. 'type' => $type,
  3198. 'is_admin' => true,
  3199. 'bodyclass' => 'edit-post',
  3200. 'breadcrumb' => '<span><a href="' . site_url() . '">' . config('breadcrumb.home') . '</a></span> &#187; ' . $current->categoryb . ' &#187; ' . $current->title
  3201. ));
  3202. } else {
  3203. render('denied', array(
  3204. 'title' => generate_title('is_default', $current->title),
  3205. 'description' => safe_html(strip_tags(blog_description())),
  3206. 'canonical' => site_url(),
  3207. 'metatags' => generate_meta(null, null),
  3208. 'p' => $current,
  3209. 'post' => $current,
  3210. 'bodyclass' => 'denied',
  3211. 'is_admin' => true,
  3212. 'breadcrumb' => '<span><a href="' . site_url() . '">' . config('breadcrumb.home') . '</a></span> &#187; ' . $current->categoryb . ' &#187; ' . $current->title
  3213. ));
  3214. }
  3215. } else {
  3216. $login = site_url() . 'login';
  3217. header("location: $login");
  3218. }
  3219. });
  3220.  
  3221. // Get edited data from blog post
  3222. post('/post/:name/edit', function () {
  3223. if(!login()) {
  3224. $login = site_url() . 'login';
  3225. header("location: $login");
  3226. }
  3227. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  3228. $title = from($_REQUEST, 'title');
  3229. $is_post = from($_REQUEST, 'is_post');
  3230. $image = from($_REQUEST, 'image');
  3231. $is_image = from($_REQUEST, 'is_image');
  3232. $video = from($_REQUEST, 'video');
  3233. $is_video = from($_REQUEST, 'is_video');
  3234. $link = from($_REQUEST, 'link');
  3235. $is_link = from($_REQUEST, 'is_link');
  3236. $audio = from($_REQUEST, 'audio');
  3237. $is_audio = from($_REQUEST, 'is_audio');
  3238. $quote = from($_REQUEST, 'quote');
  3239. $is_quote = from($_REQUEST, 'is_quote');
  3240. $tag = from($_REQUEST, 'tag');
  3241. $url = from($_REQUEST, 'url');
  3242. $content = from($_REQUEST, 'content');
  3243. $oldfile = from($_REQUEST, 'oldfile');
  3244. $destination = from($_GET, 'destination');
  3245. $description = from($_REQUEST, 'description');
  3246. $date = from($_REQUEST, 'date');
  3247. $time = from($_REQUEST, 'time');
  3248. $dateTime = null;
  3249. $revertPost = from($_REQUEST, 'revertpost');
  3250. $publishDraft = from($_REQUEST, 'publishdraft');
  3251. $category = from($_REQUEST, 'category');
  3252. if ($date !== null && $time !== null) {
  3253. $dateTime = $date . ' ' . $time;
  3254. }
  3255. if (!empty($is_image)) {
  3256. $type = 'is_image';
  3257. } elseif (!empty($is_video)) {
  3258. $type = 'is_video';
  3259. } elseif (!empty($is_link)) {
  3260. $type = 'is_link';
  3261. } elseif (!empty($is_quote)) {
  3262. $type = 'is_quote';
  3263. } elseif (!empty($is_audio)) {
  3264. $type = 'is_audio';
  3265. } elseif (!empty($is_post)) {
  3266. $type = 'is_post';
  3267. }
  3268. $arr = explode('/', $oldfile);
  3269. $user = $_SESSION[site_url()]['user'];
  3270. $role = user('role', $user);
  3271. if ($user === $arr[1] || $role === 'editor' || $role === 'admin') {
  3272. if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($image)) {
  3273. if (empty($url)) {
  3274. $url = $title;
  3275. }
  3276. edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'image', $destination, $description, $dateTime, $image);
  3277. } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($video)) {
  3278. if (empty($url)) {
  3279. $url = $title;
  3280. }
  3281. edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'video', $destination, $description, $dateTime, $video);
  3282. } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($link)) {
  3283. if (empty($url)) {
  3284. $url = $title;
  3285. }
  3286. edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'link', $destination, $description, $dateTime, $link);
  3287. } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($quote)) {
  3288. if (empty($url)) {
  3289. $url = $title;
  3290. }
  3291. edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'quote', $destination, $description, $dateTime, $quote);
  3292. } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($audio)) {
  3293. if (empty($url)) {
  3294. $url = $title;
  3295. }
  3296. edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'audio', $destination, $description, $dateTime, $audio);
  3297. } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($is_post)) {
  3298. if (empty($url)) {
  3299. $url = $title;
  3300. }
  3301. edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'post', $destination, $description, $dateTime, null);
  3302. } else {
  3303. $message['error'] = '';
  3304. if (empty($title)) {
  3305. $message['error'] .= '<li class="alert alert-danger">Title field is required.</li>';
  3306. }
  3307. if (empty($tag)) {
  3308. $message['error'] .= '<li class="alert alert-danger">Tag field is required.</li>';
  3309. }
  3310. if (empty($content)) {
  3311. $message['error'] .= '<li class="alert alert-danger">Content field is required.</li>';
  3312. }
  3313. if (!$proper) {
  3314. $message['error'] .= '<li class="alert alert-danger">CSRF Token not correct.</li>';
  3315. }
  3316.  
  3317. if (!empty($is_image)) {
  3318. if (empty($image)) {
  3319. $message['error'] .= '<li class="alert alert-danger">Image field is required.</li>';
  3320. }
  3321. } elseif (!empty($is_video)) {
  3322. if (empty($video)) {
  3323. $message['error'] .= '<li class="alert alert-danger">Video field is required.</li>';
  3324. }
  3325. } elseif (!empty($is_link)) {
  3326. if (empty($link)) {
  3327. $message['error'] .= '<li class="alert alert-danger">Link field is required.</li>';
  3328. }
  3329. } elseif (!empty($is_quote)) {
  3330. if (empty($quote)) {
  3331. $message['error'] .= '<li class="alert alert-danger">Quote field is required.</li>';
  3332. }
  3333. } elseif (!empty($is_audio)) {
  3334. if (empty($audio)) {
  3335. $message['error'] .= '<li class="alert alert-danger">Audio field is required.</li>';
  3336. }
  3337. }
  3338. config('views.root', 'system/admin/views');
  3339.  
  3340. render('edit-content', array(
  3341. 'title' => generate_title('is_default', $title),
  3342. 'description' => safe_html(strip_tags(blog_description())),
  3343. 'canonical' => site_url(),
  3344. 'metatags' => generate_meta(null, null),
  3345. 'error' => '<ul>' . $message['error'] . '</ul>',
  3346. 'oldfile' => $oldfile,
  3347. 'postTitle' => $title,
  3348. 'postImage' => $image,
  3349. 'postVideo' => $video,
  3350. 'postLink' => $link,
  3351. 'postQuote' => $quote,
  3352. 'postAudio' => $audio,
  3353. 'postTag' => $tag,
  3354. 'postUrl' => $url,
  3355. 'type' => $type,
  3356. 'is_admin' => true,
  3357. 'postContent' => $content,
  3358. 'bodyclass' => 'edit-post',
  3359. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Edit_content')
  3360. ));
  3361. }
  3362. } else {
  3363. $redir = site_url();
  3364. header("location: $redir");
  3365. }
  3366. });
  3367.  
  3368. // Delete blog post
  3369. get('/post/:name/delete', function ($name) {
  3370.  
  3371. if (login()) {
  3372.  
  3373. $user = $_SESSION[site_url()]['user'];
  3374. $role = user('role', $user);
  3375.  
  3376. config('views.root', 'system/admin/views');
  3377. $post = find_post(null, null, $name);
  3378.  
  3379. if (!$post) {
  3380. $post = find_draft(null, null, $name);
  3381. if (!$post) {
  3382. $post = find_scheduled(null, null, $name);
  3383. if (!$post) {
  3384. not_found();
  3385. }
  3386. }
  3387.  
  3388. }
  3389.  
  3390. $current = $post['current'];
  3391. if (config('blog.enable') === 'true') {
  3392. $blog = '<li class="breadcrumb-item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a itemprop="item" href="' . site_url() . 'blog"><span itemprop="name">Blog</span></a><meta itemprop="position" content="2" /></li> &#187; ';
  3393. } else {
  3394. $blog = '';
  3395. }
  3396.  
  3397. if ($user === $current->author || $role === 'editor' || $role === 'admin') {
  3398. render('delete-post', array(
  3399. 'title' => generate_title('is_default', i18n('Delete')),
  3400. 'description' => safe_html(strip_tags(blog_description())),
  3401. 'canonical' => site_url(),
  3402. 'metatags' => generate_meta(null, null),
  3403. 'p' => $current,
  3404. 'post' => $current,
  3405. 'is_admin' => true,
  3406. 'bodyclass' => 'delete-post',
  3407. 'breadcrumb' => '<span><a href="' . site_url() . '">' . config('breadcrumb.home') . '</a></span> &#187; ' . $current->categoryb . ' &#187; ' . $current->title
  3408. ));
  3409. } else {
  3410. render('denied', array(
  3411. 'title' => generate_title('is_default', 'Delete post'),
  3412. 'description' => safe_html(strip_tags(blog_description())),
  3413. 'canonical' => site_url(),
  3414. 'metatags' => generate_meta(null, null),
  3415. 'p' => $current,
  3416. 'post' => $current,
  3417. 'is_admin' => true,
  3418. 'bodyclass' => 'delete-post',
  3419. 'breadcrumb' => '<span><a href="' . site_url() . '">' . config('breadcrumb.home') . '</a></span> &#187; ' . $current->categoryb . ' &#187; ' . $current->title
  3420. ));
  3421. }
  3422. } else {
  3423. $login = site_url() . 'login';
  3424. header("location: $login");
  3425. }
  3426. });
  3427.  
  3428. // Get deleted data from blog post
  3429. post('/post/:name/delete', function () {
  3430.  
  3431. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  3432. if ($proper && login()) {
  3433. $file = from($_REQUEST, 'file');
  3434. $destination = from($_GET, 'destination');
  3435. $arr = explode('/', $file);
  3436. $user = $_SESSION[site_url()]['user'];
  3437. $role = user('role', $user);
  3438. if ($user === $arr[1] || $role === 'editor' || $role === 'admin') {
  3439. delete_post($file, $destination);
  3440. } else {
  3441. $redir = site_url();
  3442. header("location: $redir");
  3443. }
  3444. }
  3445. });
  3446.  
  3447. // Show various page (top-level), admin, login, sitemap, static page.
  3448. get('/:static', function ($static) {
  3449.  
  3450. if (isset($_GET['search'])) {
  3451. $search = _h($_GET['search']);
  3452. $url = site_url() . 'search/' . remove_accent($search);
  3453. header("Location: $url");
  3454. }
  3455.  
  3456. if (strpos($static, ".xml") !== false) {
  3457. if ($static === 'sitemap.xml') {
  3458. $sitemap = 'index.xml';
  3459. } else {
  3460. $sitemap = str_replace('sitemap.', '', $static);
  3461. }
  3462. header('Content-Type: text/xml');
  3463. generate_sitemap($sitemap);
  3464. die;
  3465. } elseif ($static === 'admin') {
  3466. if (login()) {
  3467. config('views.root', 'system/admin/views');
  3468. render('main', array(
  3469. 'title' => generate_title('is_default', i18n('Admin')),
  3470. 'description' => safe_html(strip_tags(blog_description())),
  3471. 'canonical' => site_url(),
  3472. 'metatags' => generate_meta(null, null),
  3473. 'bodyclass' => 'admin-front',
  3474. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Admin')
  3475. ));
  3476. } else {
  3477. $login = site_url() . 'login';
  3478. header("location: $login");
  3479. }
  3480. die;
  3481. } elseif ($static === 'login') {
  3482. if (session_status() == PHP_SESSION_NONE) session_start();
  3483. config('views.root', 'system/admin/views');
  3484. render('login', array(
  3485. 'title' => generate_title('is_default', i18n('Login')),
  3486. 'description' => 'Login page from ' . blog_title() . '.',
  3487. 'canonical' => site_url() . '/login',
  3488. 'metatags' => generate_meta(null, null),
  3489. 'bodyclass' => 'in-login',
  3490. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Login')
  3491. ));
  3492. die;
  3493. } elseif ($static === 'logout') {
  3494. if (login()) {
  3495. config('views.root', 'system/admin/views');
  3496. render('logout', array(
  3497. 'title' => generate_title('is_default', i18n('Logout')),
  3498. 'description' => safe_html(strip_tags(blog_description())),
  3499. 'canonical' => site_url(),
  3500. 'metatags' => generate_meta(null, null),
  3501. 'bodyclass' => 'in-logout',
  3502. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Logout')
  3503. ));
  3504. } else {
  3505. $login = site_url() . 'login';
  3506. header("location: $login");
  3507. }
  3508. die;
  3509. } elseif ($static === 'blog') {
  3510. if(config('blog.enable') !== 'true') return not_found();
  3511. if (!login()) {
  3512. file_cache($_SERVER['REQUEST_URI']);
  3513. }
  3514.  
  3515. $page = from($_GET, 'page');
  3516. $page = $page ? (int)$page : 1;
  3517. $perpage = config('posts.perpage');
  3518.  
  3519. $posts = get_posts(null, $page, $perpage);
  3520.  
  3521. $total = '';
  3522. $vroot = rtrim(config('views.root'), '/');
  3523. $lt = $vroot . '/layout--blog.html.php';
  3524. if (file_exists($lt)) {
  3525. $layout = 'layout--blog';
  3526. } else {
  3527. $layout = '';
  3528. }
  3529. $pv = $vroot . '/main--blog.html.php';
  3530. if (file_exists($pv)) {
  3531. $pview = 'main--blog';
  3532. } else {
  3533. $pview = 'main';
  3534. }
  3535.  
  3536. if (empty($posts) || $page < 1) {
  3537.  
  3538. // a non-existing page
  3539. render('no-posts', array(
  3540. 'title' => generate_title('is_blog', null),
  3541. 'description' => blog_title() . ' Blog',
  3542. 'canonical' => site_url(),
  3543. 'metatags' => generate_meta('is_blog', null),
  3544. 'bodyclass' => 'no-posts',
  3545. 'is_front' => true,
  3546. ), $layout);
  3547.  
  3548. die;
  3549. }
  3550.  
  3551. render($pview, array(
  3552. 'title' => generate_title('is_blog', null),
  3553. 'description' => blog_title() . ' Blog',
  3554. 'canonical' => site_url() . 'blog',
  3555. 'metatags' => generate_meta('is_blog', null),
  3556. 'page' => $page,
  3557. 'posts' => $posts,
  3558. 'bodyclass' => 'in-blog',
  3559. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; Blog',
  3560. 'pagination' => has_pagination($total, $perpage, $page),
  3561. 'is_blog' => true
  3562. ), $layout);
  3563. } elseif ($static === 'front') {
  3564.  
  3565. $redir = site_url();
  3566. header("location: $redir", TRUE, 301);
  3567.  
  3568. } else {
  3569.  
  3570. if (config("views.counter") != "true") {
  3571. if (!login()) {
  3572. file_cache($_SERVER['REQUEST_URI']);
  3573. }
  3574. } else {
  3575. add_view('page_' . $static);
  3576. if (!login()) {
  3577. file_cache($_SERVER['REQUEST_URI']);
  3578. }
  3579. }
  3580.  
  3581. $post = find_page($static);
  3582.  
  3583. if (!$post) {
  3584. not_found('page_' . $static);
  3585. }
  3586. if (array_key_exists('prev', $post)) {
  3587. $prev = $post['prev'];
  3588. } else {
  3589. $prev = array();
  3590. }
  3591.  
  3592. if (array_key_exists('next', $post)) {
  3593. $next = $post['next'];
  3594. } else {
  3595. $next = array();
  3596. }
  3597.  
  3598. $post = $post['current'];
  3599. $vroot = rtrim(config('views.root'), '/');
  3600. $lt = $vroot . '/layout--' . strtolower($static) . '.html.php';
  3601. $ls = $vroot . '/layout--static.html.php';
  3602. if (file_exists($lt)) {
  3603. $layout = 'layout--' . strtolower($static);
  3604. } else if (file_exists($ls)) {
  3605. $layout = 'layout--static';
  3606. } else {
  3607. $layout = '';
  3608. }
  3609. $pv = $vroot . '/static--' . strtolower($static) . '.html.php';
  3610. if (file_exists($pv)) {
  3611. $pview = 'static--' . strtolower($static);
  3612. } else {
  3613. $pview = 'static';
  3614. }
  3615.  
  3616. render($pview, array(
  3617. 'title' => generate_title('is_page', $post),
  3618. 'description' => $post->description,
  3619. 'canonical' => $post->url,
  3620. 'metatags' => generate_meta('is_page', $post),
  3621. 'bodyclass' => 'in-page ' . strtolower($static),
  3622. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . $post->title,
  3623. 'p' => $post,
  3624. 'static' => $post,
  3625. 'type' => 'staticPage',
  3626. 'prev' => static_prev($prev),
  3627. 'next' => static_next($next),
  3628. 'is_page' => true
  3629. ), $layout);
  3630. }
  3631. });
  3632.  
  3633. // Show the add sub static page
  3634. get('/:static/add', function ($static) {
  3635. $user = $_SESSION[site_url()]['user'];
  3636. $role = user('role', $user);
  3637. if (login()) {
  3638. config('views.root', 'system/admin/views');
  3639. if ($role === 'editor' || $role === 'admin') {
  3640. $post = find_page($static);
  3641.  
  3642. if (!$post) {
  3643. not_found();
  3644. }
  3645.  
  3646. $post = $post['current'];
  3647.  
  3648. render('add-page', array(
  3649. 'title' => generate_title('is_default', i18n('Add_new_page')),
  3650. 'description' => safe_html(strip_tags(blog_description())),
  3651. 'canonical' => site_url(),
  3652. 'metatags' => generate_meta(null, null),
  3653. 'type' => 'is_page',
  3654. 'is_admin' => true,
  3655. 'bodyclass' => 'add-page',
  3656. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; <a href="' . site_url() . 'admin/pages/' . $post->slug . '">' . $post->title . '</a> &#187; ' . i18n('Add_new_page')
  3657. ));
  3658. } else {
  3659. render('denied', array(
  3660. 'title' => generate_title('is_default', i18n('Denied')),
  3661. 'description' => safe_html(strip_tags(blog_description())),
  3662. 'canonical' => site_url(),
  3663. 'metatags' => generate_meta(null, null),
  3664. 'type' => 'is_admin-config',
  3665. 'is_admin' => true,
  3666. 'bodyclass' => 'denied',
  3667. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Denied')
  3668. ));
  3669. }
  3670. } else {
  3671. $login = site_url() . 'login';
  3672. header("location: $login");
  3673. }
  3674. });
  3675.  
  3676. // Submitted data from add sub static page
  3677. post('/:static/add', function ($static) {
  3678. if(!login()) {
  3679. $login = site_url() . 'login';
  3680. header("location: $login");
  3681. }
  3682. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  3683. $title = from($_REQUEST, 'title');
  3684. $url = from($_REQUEST, 'url');
  3685. $content = from($_REQUEST, 'content');
  3686. $description = from($_REQUEST, 'description');
  3687. $draft = from($_REQUEST, 'draft');
  3688. $user = $_SESSION[site_url()]['user'];
  3689. $role = user('role', $user);
  3690. if ($role === 'editor' || $role === 'admin') {
  3691. if ($proper && !empty($title) && !empty($content)) {
  3692. if (!empty($url)) {
  3693. add_sub_page($title, $url, $content, $static, $draft, $description);
  3694. } else {
  3695. $url = $title;
  3696. add_sub_page($title, $url, $content, $static, $draft, $description);
  3697. }
  3698. } else {
  3699. $message['error'] = '';
  3700. if (empty($title)) {
  3701. $message['error'] .= '<li class="alert alert-danger">Title field is required.</li>';
  3702. }
  3703. if (empty($content)) {
  3704. $message['error'] .= '<li class="alert alert-danger">Content field is required.</li>';
  3705. }
  3706. if (!$proper) {
  3707. $message['error'] .= '<li class="alert alert-danger">CSRF Token not correct.</li>';
  3708. }
  3709. config('views.root', 'system/admin/views');
  3710. render('add-page', array(
  3711. 'title' => generate_title('is_default', i18n('Add_new_page')),
  3712. 'description' => safe_html(strip_tags(blog_description())),
  3713. 'canonical' => site_url(),
  3714. 'metatags' => generate_meta(null, null),
  3715. 'error' => '<ul>' . $message['error'] . '</ul>',
  3716. 'postTitle' => $title,
  3717. 'postUrl' => $url,
  3718. 'postContent' => $content,
  3719. 'type' => 'is_page',
  3720. 'is_admin' => true,
  3721. 'bodyclass' => 'add-page',
  3722. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; <a href="' . $title . '">' . $title . '</a> &#187; ' . i18n('Add_new_page')
  3723. ));
  3724. }
  3725. } else {
  3726. $redir = site_url();
  3727. header("location: $redir");
  3728. }
  3729. });
  3730.  
  3731. // Show edit the static page
  3732. get('/:static/edit', function ($static) {
  3733. $user = $_SESSION[site_url()]['user'];
  3734. $role = user('role', $user);
  3735. if (login()) {
  3736. config('views.root', 'system/admin/views');
  3737. if ($role === 'editor' || $role === 'admin') {
  3738. $post = find_page($static);
  3739.  
  3740. if (!$post) {
  3741. $post = find_draft_page($static);
  3742. if (!$post) {
  3743. not_found();
  3744. } else {
  3745. $post = $post[0];
  3746. }
  3747. } else {
  3748. $post = $post['current'];
  3749. }
  3750.  
  3751. render('edit-page', array(
  3752. 'title' => generate_title('is_default', i18n('Edit') . ': ' . $post->title),
  3753. 'description' => safe_html(strip_tags(blog_description())),
  3754. 'canonical' => site_url(),
  3755. 'metatags' => generate_meta(null, null),
  3756. 'bodyclass' => 'edit-page',
  3757. 'is_admin' => true,
  3758. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; <a href="'. site_url() .'admin/pages">' .i18n('pages').'</a> &#187; ' . $post->title,
  3759. 'p' => $post,
  3760. 'static' => $post,
  3761. 'type' => 'staticPage',
  3762. ));
  3763. } else {
  3764. render('denied', array(
  3765. 'title' => generate_title('is_default', i18n('Denied')),
  3766. 'description' => safe_html(strip_tags(blog_description())),
  3767. 'canonical' => site_url(),
  3768. 'metatags' => generate_meta(null, null),
  3769. 'type' => 'staticPage',
  3770. 'is_admin' => true,
  3771. 'bodyclass' => 'denied',
  3772. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Denied')
  3773. ));
  3774. }
  3775. } else {
  3776. $login = site_url() . 'login';
  3777. header("location: $login");
  3778. }
  3779. });
  3780.  
  3781. // Get edited data from static page
  3782. post('/:static/edit', function () {
  3783. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  3784. if(!login()) {
  3785. $login = site_url() . 'login';
  3786. header("location: $login");
  3787. }
  3788. $title = from($_REQUEST, 'title');
  3789. $url = from($_REQUEST, 'url');
  3790. $content = from($_REQUEST, 'content');
  3791. $oldfile = from($_REQUEST, 'oldfile');
  3792. $destination = from($_GET, 'destination');
  3793. $description = from($_REQUEST, 'description');
  3794. $revertPage = from($_REQUEST, 'revertpage');
  3795. $publishDraft = from($_REQUEST, 'publishdraft');
  3796. $user = $_SESSION[site_url()]['user'];
  3797. $role = user('role', $user);
  3798. if ($role === 'editor' || $role === 'admin') {
  3799. if ($proper && !empty($title) && !empty($content)) {
  3800. if (!empty($url)) {
  3801. edit_page($title, $url, $content, $oldfile, $revertPage, $publishDraft, $destination, $description);
  3802. } else {
  3803. $url = $title;
  3804. edit_page($title, $url, $content, $oldfile, $revertPage, $publishDraft, $destination, $description);
  3805. }
  3806. } else {
  3807. $message['error'] = '';
  3808. if (empty($title)) {
  3809. $message['error'] .= '<li class="alert alert-danger">Title field is required.</li>';
  3810. }
  3811. if (empty($content)) {
  3812. $message['error'] .= '<li class="alert alert-danger">Content field is required.</li>';
  3813. }
  3814. if (!$proper) {
  3815. $message['error'] .= '<li class="alert alert-danger">CSRF Token not correct.</li>';
  3816. }
  3817. config('views.root', 'system/admin/views');
  3818.  
  3819. render('edit-page', array(
  3820. 'title' => generate_title('is_default', i18n('Edit') . ': ' . $post->title),
  3821. 'description' => safe_html(strip_tags(blog_description())),
  3822. 'canonical' => site_url(),
  3823. 'metatags' => generate_meta(null, null),
  3824. 'error' => '<ul>' . $message['error'] . '</ul>',
  3825. 'oldfile' => $oldfile,
  3826. 'postTitle' => $title,
  3827. 'postUrl' => $url,
  3828. 'postContent' => $content,
  3829. 'bodyclass' => 'edit-page',
  3830. 'is_admin' => true,
  3831. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Edit')
  3832. ));
  3833. }
  3834. } else {
  3835. $redir = site_url();
  3836. header("location: $redir");
  3837. }
  3838. });
  3839.  
  3840. // Deleted the static page
  3841. get('/:static/delete', function ($static) {
  3842. $user = $_SESSION[site_url()]['user'];
  3843. $role = user('role', $user);
  3844. if (login()) {
  3845. config('views.root', 'system/admin/views');
  3846. if ($role === 'editor' || $role === 'admin') {
  3847. $post = find_page($static);
  3848.  
  3849. if (!$post) {
  3850. $post = find_draft_page($static);
  3851. if (!$post) {
  3852. not_found();
  3853. } else {
  3854. $post = $post[0];
  3855. }
  3856. } else {
  3857. $post = $post['current'];
  3858. }
  3859.  
  3860. render('delete-page', array(
  3861. 'title' => generate_title('is_default', i18n('Delete') . ': ' . $post->title),
  3862. 'description' => safe_html(strip_tags(blog_description())),
  3863. 'canonical' => site_url(),
  3864. 'metatags' => generate_meta(null, null),
  3865. 'bodyclass' => 'delete-page',
  3866. 'is_admin' => true,
  3867. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Delete') . ': ' . $post->title,
  3868. 'p' => $post,
  3869. 'static' => $post,
  3870. 'type' => 'staticPage',
  3871. ));
  3872. } else {
  3873. render('denied', array(
  3874. 'title' => generate_title('is_default', i18n('Denied')),
  3875. 'description' => safe_html(strip_tags(blog_description())),
  3876. 'canonical' => site_url(),
  3877. 'metatags' => generate_meta(null, null),
  3878. 'type' => 'is_admin-config',
  3879. 'is_admin' => true,
  3880. 'bodyclass' => 'denied',
  3881. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Denied')
  3882. ));
  3883. }
  3884. } else {
  3885. $login = site_url() . 'login';
  3886. header("location: $login");
  3887. }
  3888. });
  3889.  
  3890. // Get deleted data for static page
  3891. post('/:static/delete', function () {
  3892.  
  3893. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  3894. if ($proper && login()) {
  3895. $user = $_SESSION[site_url()]['user'];
  3896. $role = user('role', $user);
  3897. if ($role === 'editor' || $role === 'admin') {
  3898. $file = from($_REQUEST, 'file');
  3899. $destination = from($_GET, 'destination');
  3900. delete_page($file, $destination);
  3901. } else {
  3902. $redir = site_url();
  3903. header("location: $redir");
  3904. }
  3905. }
  3906. });
  3907.  
  3908. // Show the sb static page
  3909. get('/:static/:sub', function ($static, $sub) {
  3910.  
  3911. if (isset($_GET['search'])) {
  3912. $search = _h($_GET['search']);
  3913. $url = site_url() . 'search/' . remove_accent($search);
  3914. header("Location: $url");
  3915. }
  3916. if ($static === 'front') {
  3917. $redir = site_url();
  3918. header("location: $redir", TRUE, 301);
  3919. }
  3920. if (config("views.counter") != "true") {
  3921. if (!login()) {
  3922. file_cache($_SERVER['REQUEST_URI']);
  3923. }
  3924. } else {
  3925. add_view('subpage_' . $static.'.'.$sub);
  3926. if (!login()) {
  3927. file_cache($_SERVER['REQUEST_URI']);
  3928. }
  3929. }
  3930.  
  3931. $parent_post = find_page($static);
  3932. if (!$parent_post) {
  3933. not_found('subpage_' . $static.'.'.$sub);
  3934. }
  3935. $post = find_subpage($static, $sub);
  3936. if (!$post) {
  3937. not_found('subpage_' . $static.'.'.$sub);
  3938. }
  3939. if (array_key_exists('prev', $post)) {
  3940. $prev = $post['prev'];
  3941. } else {
  3942. $prev = array();
  3943. }
  3944.  
  3945. if (array_key_exists('next', $post)) {
  3946. $next = $post['next'];
  3947. } else {
  3948. $next = array();
  3949. }
  3950. $post = $post['current'];
  3951. $vroot = rtrim(config('views.root'), '/');
  3952. $lt = $vroot . '/layout--' . strtolower($static) . '--' . strtolower($sub) . '.html.php';
  3953. $ls = $vroot . '/layout--' . strtolower($static) . '.html.php';
  3954. $lf = $vroot . '/layout--static.html.php';
  3955. if (file_exists($lt)) {
  3956. $layout = 'layout--' . strtolower($static) . '--' . strtolower($sub);
  3957. } else if (file_exists($ls)) {
  3958. $layout = 'layout--' . strtolower($static);
  3959. } else if (file_exists($lf)) {
  3960. $layout = 'layout--static';
  3961. } else {
  3962. $layout = '';
  3963. }
  3964. $pv = $vroot . '/static--' . strtolower($static) . '--' . strtolower($sub) . '.html.php';
  3965. $ps = $vroot . '/static--' . strtolower($static) . '.html.php';
  3966. if (file_exists($pv)) {
  3967. $pview = 'static--' . strtolower($static) . '--' . strtolower($sub);
  3968. } else if (file_exists($ps)) {
  3969. $pview = 'static--' . strtolower($static);
  3970. } else {
  3971. $pview = 'static';
  3972. }
  3973.  
  3974. render($pview, array(
  3975. 'title' => generate_title('is_subpage', $post),
  3976. 'description' => $post->description,
  3977. 'canonical' => $post->url,
  3978. 'metatags' => generate_meta('is_subpage', $post),
  3979. 'bodyclass' => 'in-page ' . strtolower($static) . ' ' . strtolower($sub) ,
  3980. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; <a href="' . $parent_post['current']->url . '">' . $parent_post['current']->title . '</a> &#187; ' . $post->title,
  3981. 'p' => $post,
  3982. 'static' => $post,
  3983. 'parent' => $parent_post,
  3984. 'prev' => static_prev($prev),
  3985. 'next' => static_next($next),
  3986. 'type' => 'subPage',
  3987. 'is_subpage' => true
  3988. ), $layout);
  3989. });
  3990.  
  3991. // Edit the sub static page
  3992. get('/:static/:sub/edit', function ($static, $sub) {
  3993. $user = $_SESSION[site_url()]['user'];
  3994. $role = user('role', $user);
  3995. if (login()) {
  3996. config('views.root', 'system/admin/views');
  3997. if ($role === 'editor' || $role === 'admin') {
  3998. $post = find_page($static);
  3999.  
  4000. if (!$post) {
  4001. not_found();
  4002. }
  4003.  
  4004. $post = $post['current'];
  4005.  
  4006. $page = find_subpage($static, $sub);
  4007.  
  4008. if (!$page) {
  4009. $page = find_draft_subpage($static, $sub);
  4010. if (!$page) {
  4011. not_found();
  4012. } else {
  4013. $page = $page[0];
  4014. }
  4015. } else {
  4016. $page = $page['current'];
  4017. }
  4018.  
  4019. render('edit-page', array(
  4020. 'title' => generate_title('is_default', i18n('Edit') . ': ' . $page->title),
  4021. 'description' => safe_html(strip_tags(blog_description())),
  4022. 'canonical' => site_url(),
  4023. 'metatags' => generate_meta(null, null),
  4024. 'bodyclass' => 'edit-page',
  4025. 'is_admin' => true,
  4026. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; <a href="' . site_url() . 'admin/pages/' . $post->slug . '">' . $post->title . '</a> &#187; ' . $page->title,
  4027. 'p' => $page,
  4028. 'static' => $page,
  4029. 'type' => 'subPage',
  4030. ));
  4031. } else {
  4032. render('denied', array(
  4033. 'title' => generate_title('is_default', i18n('Denied')),
  4034. 'description' => safe_html(strip_tags(blog_description())),
  4035. 'canonical' => site_url(),
  4036. 'metatags' => generate_meta(null, null),
  4037. 'type' => 'subPage',
  4038. 'is_admin' => true,
  4039. 'bodyclass' => 'denied',
  4040. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Denied')
  4041. ));
  4042. }
  4043. } else {
  4044. $login = site_url() . 'login';
  4045. header("location: $login");
  4046. }
  4047. });
  4048.  
  4049. // Submitted data from edit sub static page
  4050. post('/:static/:sub/edit', function ($static, $sub) {
  4051. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  4052. if(!login()) {
  4053. $login = site_url() . 'login';
  4054. header("location: $login");
  4055. }
  4056. $title = from($_REQUEST, 'title');
  4057. $url = from($_REQUEST, 'url');
  4058. $content = from($_REQUEST, 'content');
  4059. $oldfile = from($_REQUEST, 'oldfile');
  4060. $destination = from($_GET, 'destination');
  4061. $description = from($_REQUEST, 'description');
  4062. $revertPage = from($_REQUEST, 'revertpage');
  4063. $publishDraft = from($_REQUEST, 'publishdraft');
  4064. if ($destination === null) {
  4065. $destination = $static . "/" . $sub;
  4066. }
  4067. $user = $_SESSION[site_url()]['user'];
  4068. $role = user('role', $user);
  4069. if ($role === 'editor' || $role === 'admin') {
  4070. if ($proper && !empty($title) && !empty($content)) {
  4071. if (!empty($url)) {
  4072. edit_page($title, $url, $content, $oldfile, $revertPage, $publishDraft, $destination, $description, $static);
  4073. } else {
  4074. $url = $title;
  4075. edit_page($title, $url, $content, $oldfile, $revertPage, $publishDraft, $destination, $description, $static);
  4076. }
  4077. } else {
  4078. $message['error'] = '';
  4079. if (empty($title)) {
  4080. $message['error'] .= '<li class="alert alert-danger">Title field is required.</li>';
  4081. }
  4082. if (empty($content)) {
  4083. $message['error'] .= '<li class="alert alert-danger">Content field is required.</li>';
  4084. }
  4085. if (!$proper) {
  4086. $message['error'] .= '<li class="alert alert-danger">CSRF Token not correct.</li>';
  4087. }
  4088. config('views.root', 'system/admin/views');
  4089.  
  4090. render('edit-page', array(
  4091. 'title' => generate_title('is_default', i18n('Edit') . ': ' . $page->title),
  4092. 'description' => safe_html(strip_tags(blog_description())),
  4093. 'canonical' => site_url(),
  4094. 'metatags' => generate_meta(null, null),
  4095. 'error' => '<ul>' . $message['error'] . '</ul>',
  4096. 'oldfile' => $oldfile,
  4097. 'postTitle' => $title,
  4098. 'postUrl' => $url,
  4099. 'postContent' => $content,
  4100. 'static' => $static,
  4101. 'sub' => $sub,
  4102. 'bodyclass' => 'edit-page',
  4103. 'is_admin' => true,
  4104. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Edit')
  4105. ));
  4106. }
  4107. } else {
  4108. $redir = site_url();
  4109. header("location: $redir");
  4110. }
  4111. });
  4112.  
  4113. // Delete sub static page
  4114. get('/:static/:sub/delete', function ($static, $sub) {
  4115. $user = $_SESSION[site_url()]['user'];
  4116. $role = user('role', $user);
  4117. if (login()) {
  4118. config('views.root', 'system/admin/views');
  4119. if ($role === 'editor' || $role === 'admin') {
  4120. $post = find_page($static);
  4121.  
  4122. if (!$post) {
  4123. not_found();
  4124. }
  4125.  
  4126. $post = $post['current'];
  4127.  
  4128. $page = find_subpage($static, $sub);
  4129.  
  4130. if (!$page) {
  4131. $page = find_draft_subpage($static, $sub);
  4132. if (!$page) {
  4133. not_found();
  4134. } else {
  4135. $page = $page[0];
  4136. }
  4137. } else {
  4138. $page = $page['current'];
  4139. }
  4140.  
  4141. render('delete-page', array(
  4142. 'title' => generate_title('is_default', i18n('Delete') . ': ' . $page->title),
  4143. 'description' => safe_html(strip_tags(blog_description())),
  4144. 'canonical' => site_url(),
  4145. 'metatags' => generate_meta(null, null),
  4146. 'bodyclass' => 'delete-page',
  4147. 'is_admin' => true,
  4148. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; <a href="' . site_url() . 'admin/pages/' . $post->slug . '">' . $post->title . '</a> &#187; ' . $page->title,
  4149. 'p' => $page,
  4150. 'static' => $page,
  4151. 'type' => 'subPage',
  4152. ));
  4153. } else {
  4154. render('denied', array(
  4155. 'title' => generate_title('is_default', i18n('Denied')),
  4156. 'description' => safe_html(strip_tags(blog_description())),
  4157. 'canonical' => site_url(),
  4158. 'metatags' => generate_meta(null, null),
  4159. 'type' => 'subPage',
  4160. 'is_admin' => true,
  4161. 'bodyclass' => 'denied',
  4162. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Denied')
  4163. ));
  4164. }
  4165. } else {
  4166. $login = site_url() . 'login';
  4167. header("location: $login");
  4168. }
  4169. });
  4170.  
  4171. // Submitted data from delete sub static page
  4172. post('/:static/:sub/delete', function () {
  4173.  
  4174. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  4175. if ($proper && login()) {
  4176. $user = $_SESSION[site_url()]['user'];
  4177. $role = user('role', $user);
  4178. if ($role === 'editor' || $role === 'admin') {
  4179. $file = from($_REQUEST, 'file');
  4180. $destination = from($_GET, 'destination');
  4181. delete_page($file, $destination);
  4182. } else {
  4183. $redir = site_url();
  4184. header("location: $redir");
  4185. }
  4186. }
  4187. });
  4188.  
  4189. // Show blog post with year-month
  4190. get('/:year/:month/:name', function ($year, $month, $name) {
  4191.  
  4192. if (isset($_GET['search'])) {
  4193. $search = _h($_GET['search']);
  4194. $url = site_url() . 'search/' . remove_accent($search);
  4195. header("Location: $url");
  4196. }
  4197. if (config('permalink.type') == 'post') {
  4198. $redir = site_url() . 'post/' . $name;
  4199. header("location: $redir", TRUE, 301);
  4200. }
  4201.  
  4202. if (config("views.counter") != "true") {
  4203. if (!login()) {
  4204. file_cache($_SERVER['REQUEST_URI']);
  4205. }
  4206. } else {
  4207. add_view('post_' . $name);
  4208. if (!login()) {
  4209. file_cache($_SERVER['REQUEST_URI']);
  4210. }
  4211. }
  4212.  
  4213. $post = find_post($year, $month, $name);
  4214.  
  4215. if (is_null($post)) {
  4216. not_found('post_'. $name);
  4217. } else {
  4218. $current = $post['current'];
  4219. }
  4220.  
  4221. $author = new stdClass;
  4222. $author->url = $current->authorUrl;
  4223. $author->name = $current->authorName;
  4224. $author->description = $current->authorDescription;
  4225. $author->about = $current->authorAbout;
  4226. $author->avatar = $current->authorAvatar;
  4227.  
  4228. if (array_key_exists('prev', $post)) {
  4229. $prev = $post['prev'];
  4230. } else {
  4231. $prev = array();
  4232. }
  4233.  
  4234. if (array_key_exists('next', $post)) {
  4235. $next = $post['next'];
  4236. } else {
  4237. $next = array();
  4238. }
  4239. if (isset($current->image)) {
  4240. $var = 'imagePost';
  4241. } elseif (isset($current->link)) {
  4242. $var = 'linkPost';
  4243. } elseif (isset($current->quote)) {
  4244. $var = 'quotePost';
  4245. } elseif (isset($current->audio)) {
  4246. $var = 'audioPost';
  4247. } elseif (isset($current->video)) {
  4248. $var = 'videoPost'; }
  4249. else {
  4250. $var = 'blogPost';
  4251. }
  4252. if (config('blog.enable') === 'true') {
  4253. $blog = '<li class="breadcrumb-item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a itemprop="item" href="' . site_url() . 'blog"><span itemprop="name">Blog</span></a><meta itemprop="position" content="2" /></li> &#187; ';
  4254. } else {
  4255. $blog = '';
  4256. }
  4257. $vroot = rtrim(config('views.root'), '/');
  4258. $lt = $vroot . '/layout--post--' . $current->ct . '.html.php';
  4259. $pt = $vroot . '/layout--post--' . $current->type . '.html.php';
  4260. $ls = $vroot . '/layout--post.html.php';
  4261. if (file_exists($lt)) {
  4262. $layout = 'layout--post--' . $current->ct;
  4263. } else if (file_exists($pt)) {
  4264. $layout = 'layout--post--' . $current->type;
  4265. } else if (file_exists($ls)) {
  4266. $layout = 'layout--post';
  4267. } else {
  4268. $layout = '';
  4269. }
  4270. $pv = $vroot . '/post--' . $current->ct . '.html.php';
  4271. $pvt = $vroot . '/post--' . $current->type . '.html.php';
  4272. if (file_exists($pv)) {
  4273. $pview = 'post--' . $current->ct;
  4274. } else if(file_exists($pvt)) {
  4275. $pview = 'post--' . $current->type;
  4276. } else {
  4277. $pview = 'post';
  4278. }
  4279. render($pview, array(
  4280. 'title' => generate_title('is_post', $current),
  4281. 'description' => $current->description,
  4282. 'canonical' => $current->url,
  4283. 'metatags' => generate_meta('is_post', $current),
  4284. 'p' => $current,
  4285. 'post' => $current,
  4286. 'author' => $author,
  4287. 'bodyclass' => 'in-post category-' . $current->ct . ' type-' . $current->type,
  4288. 'breadcrumb' => '<style>.breadcrumb-list {margin:0; padding:0;} .breadcrumb-list li {display: inline-block; list-style: none;}</style><ol class="breadcrumb-list" itemscope itemtype="http://schema.org/BreadcrumbList"><li class="breadcrumb-item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a itemprop="item" href="' . site_url() . '"><span itemprop="name">' . config('breadcrumb.home') . '</span></a><meta itemprop="position" content="1" /></li> &#187; '. $blog . '<li class="breadcrumb-item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">' . $current->categoryb . '<meta itemprop="position" content="3" /></li>' . ' &#187; ' . $current->title . '</ol>',
  4289. 'prev' => has_prev($prev),
  4290. 'next' => has_next($next),
  4291. 'type' => $var,
  4292. 'is_post' => true
  4293. ), $layout);
  4294.  
  4295. });
  4296.  
  4297. // Edit blog post
  4298. get('/:year/:month/:name/edit', function ($year, $month, $name) {
  4299.  
  4300. if (login()) {
  4301.  
  4302. $user = $_SESSION[site_url()]['user'];
  4303. $role = user('role', $user);
  4304.  
  4305. config('views.root', 'system/admin/views');
  4306. $post = find_post($year, $month, $name);
  4307.  
  4308. if (!$post) {
  4309. $post = find_draft($year, $month, $name);
  4310. if (!$post) {
  4311. $post = find_scheduled($year, $month, $name);
  4312. if (!$post) {
  4313. not_found();
  4314. }
  4315. }
  4316.  
  4317. }
  4318.  
  4319. $current = $post['current'];
  4320. if (isset($current->image)) {
  4321. $type= 'is_image';
  4322. } elseif (isset($current->link)) {
  4323. $type = 'is_link';
  4324. } elseif (isset($current->quote)) {
  4325. $type = 'is_quote';
  4326. } elseif (isset($current->audio)) {
  4327. $type = 'is_audio';
  4328. } elseif (isset($current->video)) {
  4329. $type = 'is_video';
  4330. } else {
  4331. $type = 'is_post';
  4332. }
  4333. if ($user === $current->author || $role === 'editor' || $role === 'admin') {
  4334. render('edit-content', array(
  4335. 'title' => generate_title('is_default', $current->title),
  4336. 'description' => safe_html(strip_tags(blog_description())),
  4337. 'canonical' => site_url(),
  4338. 'metatags' => generate_meta(null, null),
  4339. 'p' => $current,
  4340. 'post' => $current,
  4341. 'type' => $type,
  4342. 'bodyclass' => 'edit-post',
  4343. 'is_admin' => true,
  4344. 'breadcrumb' => '<span><a href="' . site_url() . '">' . config('breadcrumb.home') . '</a></span> &#187; ' . $current->categoryb . ' &#187; ' . $current->title
  4345. ));
  4346. } else {
  4347. render('denied', array(
  4348. 'title' => generate_title('is_default', $current->title),
  4349. 'description' => safe_html(strip_tags(blog_description())),
  4350. 'canonical' => site_url(),
  4351. 'metatags' => generate_meta(null, null),
  4352. 'p' => $current,
  4353. 'post' => $current,
  4354. 'bodyclass' => 'denied',
  4355. 'is_admin' => true,
  4356. 'breadcrumb' => '<span><a href="' . site_url() . '">' . config('breadcrumb.home') . '</a></span> &#187; ' . $current->categoryb . ' &#187; ' . $current->title
  4357. ));
  4358. }
  4359. } else {
  4360. $login = site_url() . 'login';
  4361. header("location: $login");
  4362. }
  4363. });
  4364.  
  4365. // Get edited data from blog post
  4366. post('/:year/:month/:name/edit', function () {
  4367.  
  4368. if(!login()) {
  4369. $login = site_url() . 'login';
  4370. header("location: $login");
  4371. }
  4372. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  4373. $title = from($_REQUEST, 'title');
  4374. $is_post = from($_REQUEST, 'is_post');
  4375. $image = from($_REQUEST, 'image');
  4376. $is_image = from($_REQUEST, 'is_image');
  4377. $video = from($_REQUEST, 'video');
  4378. $is_video = from($_REQUEST, 'is_video');
  4379. $link = from($_REQUEST, 'link');
  4380. $is_link = from($_REQUEST, 'is_link');
  4381. $audio = from($_REQUEST, 'audio');
  4382. $is_audio = from($_REQUEST, 'is_audio');
  4383. $quote = from($_REQUEST, 'quote');
  4384. $is_quote = from($_REQUEST, 'is_quote');
  4385. $tag = from($_REQUEST, 'tag');
  4386. $url = from($_REQUEST, 'url');
  4387. $content = from($_REQUEST, 'content');
  4388. $oldfile = from($_REQUEST, 'oldfile');
  4389. $destination = from($_GET, 'destination');
  4390. $description = from($_REQUEST, 'description');
  4391. $date = from($_REQUEST, 'date');
  4392. $time = from($_REQUEST, 'time');
  4393. $dateTime = null;
  4394. $revertPost = from($_REQUEST, 'revertpost');
  4395. $publishDraft = from($_REQUEST, 'publishdraft');
  4396. $category = from($_REQUEST, 'category');
  4397. if ($date !== null && $time !== null) {
  4398. $dateTime = $date . ' ' . $time;
  4399. }
  4400. if (!empty($is_image)) {
  4401. $type = 'is_image';
  4402. } elseif (!empty($is_video)) {
  4403. $type = 'is_video';
  4404. } elseif (!empty($is_link)) {
  4405. $type = 'is_link';
  4406. } elseif (!empty($is_quote)) {
  4407. $type = 'is_quote';
  4408. } elseif (!empty($is_audio)) {
  4409. $type = 'is_audio';
  4410. } elseif (!empty($is_post)) {
  4411. $type = 'is_post';
  4412. }
  4413. $arr = explode('/', $oldfile);
  4414. $user = $_SESSION[site_url()]['user'];
  4415. $role = user('role', $user);
  4416. if ($user === $arr[1] || $role === 'editor' || $role === 'admin') {
  4417.  
  4418. if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($image)) {
  4419. if (empty($url)) {
  4420. $url = $title;
  4421. }
  4422. edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'image', $destination, $description, $dateTime, $image);
  4423. } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($video)) {
  4424. if (empty($url)) {
  4425. $url = $title;
  4426. }
  4427. edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'video', $destination, $description, $dateTime, $video);
  4428. } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($link)) {
  4429. if (empty($url)) {
  4430. $url = $title;
  4431. }
  4432. edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'link', $destination, $description, $dateTime, $link);
  4433. } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($quote)) {
  4434. if (empty($url)) {
  4435. $url = $title;
  4436. }
  4437. edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'quote', $destination, $description, $dateTime, $quote);
  4438. } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($audio)) {
  4439. if (empty($url)) {
  4440. $url = $title;
  4441. }
  4442. edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'audio', $destination, $description, $dateTime, $audio);
  4443. } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($is_post)) {
  4444. if (empty($url)) {
  4445. $url = $title;
  4446. }
  4447. edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'post', $destination, $description, $dateTime, null);
  4448. } else {
  4449. $message['error'] = '';
  4450. if (empty($title)) {
  4451. $message['error'] .= '<li class="alert alert-danger">Title field is required.</li>';
  4452. }
  4453. if (empty($tag)) {
  4454. $message['error'] .= '<li class="alert alert-danger">Tag field is required.</li>';
  4455. }
  4456. if (empty($content)) {
  4457. $message['error'] .= '<li class="alert alert-danger">Content field is required.</li>';
  4458. }
  4459. if (!$proper) {
  4460. $message['error'] .= '<li class="alert alert-danger">CSRF Token not correct.</li>';
  4461. }
  4462.  
  4463. if (!empty($is_image)) {
  4464. if (empty($image)) {
  4465. $message['error'] .= '<li class="alert alert-danger">Image field is required.</li>';
  4466. }
  4467. } elseif (!empty($is_video)) {
  4468. if (empty($video)) {
  4469. $message['error'] .= '<li class="alert alert-danger">Video field is required.</li>';
  4470. }
  4471. } elseif (!empty($is_link)) {
  4472. if (empty($link)) {
  4473. $message['error'] .= '<li class="alert alert-danger">Link field is required.</li>';
  4474. }
  4475. } elseif (!empty($is_quote)) {
  4476. if (empty($quote)) {
  4477. $message['error'] .= '<li class="alert alert-danger">Quote field is required.</li>';
  4478. }
  4479. } elseif (!empty($is_audio)) {
  4480. if (empty($audio)) {
  4481. $message['error'] .= '<li class="alert alert-danger">Audio field is required.</li>';
  4482. }
  4483. }
  4484. config('views.root', 'system/admin/views');
  4485.  
  4486. render('edit-content', array(
  4487. 'title' => generate_title('is_default', $title),
  4488. 'description' => safe_html(strip_tags(blog_description())),
  4489. 'canonical' => site_url(),
  4490. 'metatags' => generate_meta(null, null),
  4491. 'error' => '<ul>' . $message['error'] . '</ul>',
  4492. 'oldfile' => $oldfile,
  4493. 'postTitle' => $title,
  4494. 'postImage' => $image,
  4495. 'postVideo' => $video,
  4496. 'postLink' => $link,
  4497. 'postQuote' => $quote,
  4498. 'postAudio' => $audio,
  4499. 'postTag' => $tag,
  4500. 'postUrl' => $url,
  4501. 'type' => $type,
  4502. 'postContent' => $content,
  4503. 'is_admin' => true,
  4504. 'bodyclass' => 'edit-post',
  4505. 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . $title
  4506. ));
  4507. }
  4508. } else {
  4509. $redir = site_url();
  4510. header("location: $redir");
  4511. }
  4512. });
  4513.  
  4514. // Delete blog post
  4515. get('/:year/:month/:name/delete', function ($year, $month, $name) {
  4516.  
  4517. if (login()) {
  4518.  
  4519. $user = $_SESSION[site_url()]['user'];
  4520. $role = user('role', $user);
  4521.  
  4522. config('views.root', 'system/admin/views');
  4523. $post = find_post($year, $month, $name);
  4524.  
  4525. if (!$post) {
  4526. $post = find_draft($year, $month, $name);
  4527. if (!$post) {
  4528. $post = find_scheduled($year, $month, $name);
  4529. if (!$post) {
  4530. not_found();
  4531. }
  4532. }
  4533.  
  4534. }
  4535.  
  4536. $current = $post['current'];
  4537.  
  4538. if ($user === $current->author || $role === 'editor' || $role === 'admin') {
  4539. render('delete-post', array(
  4540. 'title' => generate_title('is_default', i18n('Delete')),
  4541. 'description' => safe_html(strip_tags(blog_description())),
  4542. 'canonical' => site_url(),
  4543. 'metatags' => generate_meta(null, null),
  4544. 'p' => $current,
  4545. 'post' => $current,
  4546. 'bodyclass' => 'delete-post',
  4547. 'is_admin' => true,
  4548. 'breadcrumb' => '<span><a rel="v:url" href="' . site_url() . '">' . config('breadcrumb.home') . '</a></span> &#187; ' . $current->categoryb . ' &#187; ' . $current->title
  4549. ));
  4550. } else {
  4551. render('denied', array(
  4552. 'title' => generate_title('is_default', i18n('Delete')),
  4553. 'description' => safe_html(strip_tags(blog_description())),
  4554. 'canonical' => site_url(),
  4555. 'metatags' => generate_meta(null, null),
  4556. 'p' => $current,
  4557. 'post' => $current,
  4558. 'bodyclass' => 'delete-post',
  4559. 'is_admin' => true,
  4560. 'breadcrumb' => '<span><a href="' . site_url() . '">' . config('breadcrumb.home') . '</a></span> &#187; ' . $current->categoryb . ' &#187; ' . $current->title
  4561. ));
  4562. }
  4563. } else {
  4564. $login = site_url() . 'login';
  4565. header("location: $login");
  4566. }
  4567. });
  4568.  
  4569. // Get deleted data from blog post
  4570. post('/:year/:month/:name/delete', function () {
  4571.  
  4572. $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
  4573. if ($proper && login()) {
  4574. $file = from($_REQUEST, 'file');
  4575. $destination = from($_GET, 'destination');
  4576. $arr = explode('/', $file);
  4577. $user = $_SESSION[site_url()]['user'];
  4578. $role = user('role', $user);
  4579. if ($user === $arr[1] || $role === 'editor' || $role === 'admin') {
  4580. delete_post($file, $destination);
  4581. }
  4582. }
  4583. });
  4584.  
  4585. // If we get here, it means that
  4586. // nothing has been matched above
  4587. get('.*', function () {
  4588. not_found();
  4589. });
  4590.  
  4591. // Serve the blog
  4592. dispatch();