Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.49 KB | None | 0 0
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3.  
  4. class Admin_post extends Admin_Core_Controller
  5. {
  6.  
  7. public function __construct()
  8. {
  9. parent::__construct();
  10.  
  11. //check auth
  12. if (!is_admin() && !is_author()) {
  13. redirect('login');
  14. }
  15.  
  16. //check permission
  17. if (!show_admin_panel()) {
  18. redirect('admin/login');
  19. }
  20. }
  21.  
  22.  
  23. /**
  24. * Add Post
  25. */
  26. public function add_post()
  27. {
  28. $data['title'] = trans("add_post");
  29. $data['top_categories'] = $this->category_model->get_categories();
  30.  
  31. $this->load->view('admin/includes/_header', $data);
  32. $this->load->view('admin/post/add_post', $data);
  33. $this->load->view('admin/includes/_footer');
  34. }
  35.  
  36. /**
  37. * Add Audio
  38. */
  39. public function add_audio()
  40. {
  41. $data['title'] = trans("add_audio");
  42. $data['top_categories'] = $this->category_model->get_categories();
  43.  
  44. $this->load->view('admin/includes/_header', $data);
  45. $this->load->view('admin/post/add_audio', $data);
  46. $this->load->view('admin/includes/_footer');
  47. }
  48.  
  49. /**
  50. * Add Video
  51. */
  52. public function add_video()
  53. {
  54. $data['title'] = trans("add_video");
  55. $data['top_categories'] = $this->category_model->get_categories();
  56.  
  57. $this->load->view('admin/includes/_header', $data);
  58. $this->load->view('admin/post/add_video', $data);
  59. $this->load->view('admin/includes/_footer');
  60. }
  61.  
  62. /**
  63. * Add Post Post
  64. */
  65. public function add_post_post()
  66. {
  67. //validate inputs
  68. $this->form_validation->set_rules('title', trans("title"), 'required|xss_clean|max_length[500]');
  69. $this->form_validation->set_rules('summary', trans("summary"), 'xss_clean|max_length[5000]');
  70. $this->form_validation->set_rules('category_id', trans("category"), 'required');
  71. $this->form_validation->set_rules('optional_url', trans("optional_url"), 'xss_clean|max_length[1000]');
  72.  
  73. if ($this->form_validation->run() === false) {
  74. $this->session->set_flashdata('errors', validation_errors());
  75. $this->session->set_flashdata('form_data', $this->post_admin_model->input_values());
  76. redirect($this->agent->referrer());
  77. } else {
  78.  
  79. $post_type = $this->input->post('post_type', true);
  80.  
  81. //if post added
  82. if ($this->post_admin_model->add_post($post_type)) {
  83. //last id
  84. $last_id = $this->db->insert_id();
  85. //update slug
  86. $this->post_admin_model->update_slug($last_id);
  87. //insert post tags
  88. $this->tag_model->add_post_tags($last_id);
  89. date_flaxh();
  90. if ($post_type == "audio") {
  91. $this->post_file_model->add_post_audios($last_id);
  92. } elseif ($post_type == "post") {
  93. $this->post_file_model->add_post_additional_images($last_id);
  94. }
  95.  
  96. $this->session->set_flashdata('success', trans("post") . " " . trans("msg_suc_added"));
  97. redirect($this->agent->referrer());
  98. } else {
  99. $this->session->set_flashdata('form_data', $this->post_admin_model->input_values());
  100. $this->session->set_flashdata('error', trans("msg_error"));
  101. redirect($this->agent->referrer());
  102. }
  103. }
  104. }
  105.  
  106.  
  107. /**
  108. * Posts
  109. */
  110. public function posts()
  111. {
  112. $data['title'] = trans('posts');
  113. $data['authors'] = $this->auth_model->get_authors();
  114. $data['form_action'] = "admin_post/posts";
  115. $data['list_type'] = "posts";
  116. excptn_haer();
  117. //get paginated posts
  118. $pagination = $this->paginate(base_url() . 'admin_post/posts', $this->post_admin_model->get_paginated_posts_count('posts'));
  119. $data['posts'] = $this->post_admin_model->get_paginated_posts($pagination['per_page'], $pagination['offset'], 'posts');
  120.  
  121. $this->load->view('admin/includes/_header', $data);
  122. $this->load->view('admin/post/posts', $data);
  123. $this->load->view('admin/includes/_footer');
  124. }
  125.  
  126.  
  127. /**
  128. * Slider Posts
  129. */
  130. public function slider_posts()
  131. {
  132. prevent_author();
  133.  
  134. $data['title'] = trans('slider_posts');
  135. $data['authors'] = $this->auth_model->get_authors();
  136. $data['form_action'] = "admin_post/slider_posts";
  137. $data['list_type'] = "slider_posts";
  138.  
  139. //get paginated posts
  140. $pagination = $this->paginate(base_url() . 'admin_post/slider_posts', $this->post_admin_model->get_paginated_posts_count('slider_posts'));
  141. $data['posts'] = $this->post_admin_model->get_paginated_posts($pagination['per_page'], $pagination['offset'], 'slider_posts');
  142.  
  143. $this->load->view('admin/includes/_header', $data);
  144. $this->load->view('admin/post/posts', $data);
  145. $this->load->view('admin/includes/_footer');
  146. }
  147.  
  148.  
  149. /**
  150. * Featured Posts
  151. */
  152. public function featured_posts()
  153. {
  154. prevent_author();
  155.  
  156. $data['title'] = trans('featured_posts');
  157. $data['authors'] = $this->auth_model->get_authors();
  158. $data['form_action'] = "admin_post/featured_posts";
  159. $data['list_type'] = "featured_posts";
  160.  
  161. //get paginated posts
  162. $pagination = $this->paginate(base_url() . 'admin_post/featured_posts', $this->post_admin_model->get_paginated_posts_count('featured_posts'));
  163. $data['posts'] = $this->post_admin_model->get_paginated_posts($pagination['per_page'], $pagination['offset'], 'featured_posts');
  164.  
  165. $this->load->view('admin/includes/_header', $data);
  166. $this->load->view('admin/post/posts', $data);
  167. $this->load->view('admin/includes/_footer');
  168. }
  169.  
  170.  
  171. /**
  172. * Breaking news
  173. */
  174. public function breaking_news()
  175. {
  176. prevent_author();
  177.  
  178. $data['title'] = trans('breaking_news');
  179. $data['authors'] = $this->auth_model->get_authors();
  180. $data['form_action'] = "admin_post/breaking_news";
  181. $data['list_type'] = "breaking_news";
  182.  
  183. //get paginated posts
  184. $pagination = $this->paginate(base_url() . 'admin_post/breaking_news', $this->post_admin_model->get_paginated_posts_count('breaking_news'));
  185. $data['posts'] = $this->post_admin_model->get_paginated_posts($pagination['per_page'], $pagination['offset'], 'breaking_news');
  186.  
  187. $this->load->view('admin/includes/_header', $data);
  188. $this->load->view('admin/post/posts', $data);
  189. $this->load->view('admin/includes/_footer');
  190. }
  191.  
  192.  
  193. /**
  194. * Recommended Posts
  195. */
  196. public function recommended_posts()
  197. {
  198. prevent_author();
  199.  
  200. $data['title'] = trans('recommended_posts');
  201. $data['authors'] = $this->auth_model->get_authors();
  202. $data['form_action'] = "admin_post/recommended_posts";
  203. $data['list_type'] = "recommended_posts";
  204.  
  205. //get paginated posts
  206. $pagination = $this->paginate(base_url() . 'admin_post/recommended_posts', $this->post_admin_model->get_paginated_posts_count('recommended_posts'));
  207. $data['posts'] = $this->post_admin_model->get_paginated_posts($pagination['per_page'], $pagination['offset'], 'recommended_posts');
  208.  
  209. $this->load->view('admin/includes/_header', $data);
  210. $this->load->view('admin/post/posts', $data);
  211. $this->load->view('admin/includes/_footer');
  212. }
  213.  
  214.  
  215. /**
  216. * Pending Posts
  217. */
  218. public function pending_posts()
  219. {
  220.  
  221. $data['title'] = trans('pending_posts');
  222. $data['authors'] = $this->auth_model->get_authors();
  223. $data['form_action'] = "admin_post/pending_posts";
  224. $data['list_type'] = "pending_posts";
  225.  
  226. //get paginated posts
  227. $pagination = $this->paginate(base_url() . 'admin_post/pending_posts', $this->post_admin_model->get_paginated_pending_posts_count());
  228. $data['posts'] = $this->post_admin_model->get_paginated_pending_posts($pagination['per_page'], $pagination['offset']);
  229.  
  230. $this->load->view('admin/includes/_header', $data);
  231. $this->load->view('admin/post/pending_posts', $data);
  232. $this->load->view('admin/includes/_footer');
  233. }
  234.  
  235.  
  236. /**
  237. * Scheduled Posts
  238. */
  239. public function scheduled_posts()
  240. {
  241. $data['title'] = trans('scheduled_posts');
  242. $data['authors'] = $this->auth_model->get_authors();
  243. $data['form_action'] = "admin_post/scheduled_posts";
  244.  
  245. //get paginated posts
  246. $pagination = $this->paginate(base_url() . 'admin_post/scheduled_posts', $this->post_admin_model->get_paginated_scheduled_posts_count());
  247. $data['posts'] = $this->post_admin_model->get_paginated_scheduled_posts($pagination['per_page'], $pagination['offset']);
  248.  
  249. $this->load->view('admin/includes/_header', $data);
  250. $this->load->view('admin/post/scheduled_posts', $data);
  251. $this->load->view('admin/includes/_footer');
  252. }
  253.  
  254.  
  255. /**
  256. * Drafts
  257. */
  258. public function drafts()
  259. {
  260. $data['title'] = trans('drafts');
  261. $data['authors'] = $this->auth_model->get_authors();
  262. $data['form_action'] = "admin_post/drafts";
  263.  
  264. //get paginated posts
  265. $pagination = $this->paginate(base_url() . 'admin_post/drafts', $this->post_admin_model->get_paginated_drafts_count());
  266. $data['posts'] = $this->post_admin_model->get_paginated_drafts($pagination['per_page'], $pagination['offset']);
  267.  
  268. $this->load->view('admin/includes/_header', $data);
  269. $this->load->view('admin/post/drafts', $data);
  270. $this->load->view('admin/includes/_footer');
  271. }
  272.  
  273.  
  274. /**
  275. * Update Post
  276. */
  277. public function update_post($id)
  278. {
  279. $data['title'] = trans("update_post");
  280.  
  281. //get post
  282. $data['post'] = $this->post_admin_model->get_post($id);
  283.  
  284. if (empty($data['post'])) {
  285. redirect($this->agent->referrer());
  286. }
  287.  
  288. //check if author
  289. if (is_author()) {
  290. //check owner
  291. if ($data['post']->user_id != user()->id):
  292. redirect("admin");
  293. endif;
  294. }
  295.  
  296. //combine post tags
  297. $tags = "";
  298. $count = 0;
  299. $tags_array = $this->tag_model->get_post_tags($id);
  300. foreach ($tags_array as $item) {
  301. if ($count > 0) {
  302. $tags .= ",";
  303. }
  304. $tags .= $item->tag;
  305. $count++;
  306. }
  307.  
  308. $data['tags'] = $tags;
  309. $data['post_images'] = $this->post_file_model->get_post_additional_images($id);
  310. $data['categories'] = $this->category_model->get_categories_by_lang($data['post']->lang_id);
  311. $data['subcategories'] = $this->category_model->get_subcategories_by_parent_id($data['post']->category_id);
  312.  
  313. $this->load->view('admin/includes/_header', $data);
  314. if ($data['post']->post_type == "video") {
  315. $this->load->view('admin/post/update_video', $data);
  316. } elseif ($data['post']->post_type == "audio") {
  317. $this->load->view('admin/post/update_audio', $data);
  318. } else {
  319. $this->load->view('admin/post/update_post', $data);
  320. }
  321. $this->load->view('admin/includes/_footer');
  322. }
  323.  
  324.  
  325. /**
  326. * Update Post Post
  327. */
  328. public function update_post_post()
  329. {
  330. //validate inputs
  331. $this->form_validation->set_rules('title', trans("title"), 'required|xss_clean|max_length[500]');
  332. $this->form_validation->set_rules('summary', trans("summary"), 'xss_clean|max_length[5000]');
  333. $this->form_validation->set_rules('category_id', trans("category"), 'required');
  334. $this->form_validation->set_rules('optional_url', trans("optional_url"), 'xss_clean|max_length[1000]');
  335.  
  336. if ($this->form_validation->run() === false) {
  337. $this->session->set_flashdata('errors', validation_errors());
  338. $this->session->set_flashdata('form_data', $this->post_admin_model->input_values());
  339. redirect($this->agent->referrer());
  340. } else {
  341. //post id
  342. $post_id = $this->input->post('id', true);
  343. $post_type = $this->input->post('post_type', true);
  344.  
  345. if ($this->post_admin_model->update_post($post_id, $post_type)) {
  346.  
  347. //update slug
  348. $this->post_admin_model->update_slug($post_id);
  349.  
  350. //update post tags
  351. $this->tag_model->update_post_tags($post_id);
  352.  
  353. if ($post_type == "audio") {
  354. $this->post_file_model->add_post_audios($post_id);
  355. } elseif ($post_type == "post") {
  356. $this->post_file_model->add_post_additional_images($post_id);
  357. }
  358.  
  359. $this->session->set_flashdata('success', trans("post") . " " . trans("msg_suc_updated"));
  360.  
  361. $referrer = $this->input->post("referrer");
  362. if (!empty($referrer)) {
  363. redirect($referrer);
  364. } else {
  365. redirect('admin_post/posts');
  366. }
  367.  
  368. } else {
  369. $this->session->set_flashdata('form_data', $this->post_admin_model->input_values());
  370. $this->session->set_flashdata('error', trans("msg_error"));
  371. redirect($this->agent->referrer());
  372. }
  373. }
  374. }
  375.  
  376. /**
  377. * Post Options Post
  378. */
  379. public function post_options_post()
  380. {
  381. $option = $this->input->post('option', true);
  382. $id = $this->input->post('id', true);
  383.  
  384. $data["post"] = $this->post_admin_model->get_post($id);
  385.  
  386. //check if exists
  387. if (empty($data['post'])) {
  388. redirect($this->agent->referrer());
  389. }
  390.  
  391. //if option add remove from slider
  392. if ($option == 'add-remove-from-slider') {
  393.  
  394. $result = $this->post_admin_model->post_add_remove_slider($id);
  395.  
  396. if ($result == "removed") {
  397. $this->session->set_flashdata('success', trans("msg_remove_slider"));
  398. redirect($this->agent->referrer());
  399. }
  400. if ($result == "added") {
  401. $this->session->set_flashdata('success', trans("msg_add_slider"));
  402. redirect($this->agent->referrer());
  403. }
  404.  
  405. }
  406.  
  407. //if option add remove from featured
  408. if ($option == 'add-remove-from-featured') {
  409.  
  410. $result = $this->post_admin_model->post_add_remove_featured($id);
  411.  
  412. if ($result == "removed") {
  413. $this->session->set_flashdata('success', trans("msg_remove_featured"));
  414. redirect($this->agent->referrer());
  415. }
  416. if ($result == "added") {
  417. $this->session->set_flashdata('success', trans("msg_add_featured"));
  418. redirect($this->agent->referrer());
  419. }
  420. }
  421.  
  422. //if option add remove from breaking
  423. if ($option == 'add-remove-from-breaking') {
  424.  
  425. $result = $this->post_admin_model->post_add_remove_breaking($id);
  426.  
  427. if ($result == "removed") {
  428. $this->session->set_flashdata('success', trans("msg_remove_breaking"));
  429. redirect($this->agent->referrer());
  430. }
  431. if ($result == "added") {
  432. $this->session->set_flashdata('success', trans("msg_add_breaking"));
  433. redirect($this->agent->referrer());
  434. }
  435.  
  436. }
  437.  
  438. //if option add remove from recommended
  439. if ($option == 'add-remove-from-recommended') {
  440.  
  441. $result = $this->post_admin_model->post_add_remove_recommended($id);
  442.  
  443. if ($result == "removed") {
  444. $this->session->set_flashdata('success', trans("msg_remove_recommended"));
  445. redirect($this->agent->referrer());
  446. }
  447. if ($result == "added") {
  448. $this->session->set_flashdata('success', trans("msg_add_recommended"));
  449. redirect($this->agent->referrer());
  450. }
  451. }
  452.  
  453.  
  454. //if option approve
  455. if ($option == 'approve') {
  456. if (is_admin()):
  457. if ($this->post_admin_model->approve_post($id)) {
  458. $this->session->set_flashdata('success', trans("msg_post_approved"));
  459. } else {
  460. $this->session->set_flashdata('error', trans("msg_error"));
  461. }
  462. endif;
  463. redirect($this->agent->referrer());
  464. }
  465.  
  466. //if option publish
  467. if ($option == 'publish') {
  468.  
  469. if ($this->post_admin_model->publish_post($id)) {
  470. $this->session->set_flashdata('success', trans("msg_published"));
  471. } else {
  472. $this->session->set_flashdata('error', trans("msg_error"));
  473. }
  474.  
  475. redirect($this->agent->referrer());
  476. }
  477.  
  478. //if option publish draft
  479. if ($option == 'publish_draft') {
  480.  
  481. if ($this->post_admin_model->publish_draft($id)) {
  482. $this->session->set_flashdata('success', trans("msg_published"));
  483. } else {
  484. $this->session->set_flashdata('error', trans("msg_error"));
  485. }
  486.  
  487. redirect($this->agent->referrer());
  488. }
  489.  
  490. //if option delete
  491. if ($option == 'delete') {
  492.  
  493. if ($this->post_admin_model->delete_post($id)) {
  494. //delete post tags
  495. $this->tag_model->delete_post_tags($id);
  496.  
  497. $this->session->set_flashdata('success', trans("post") . " " . trans("msg_suc_deleted"));
  498. redirect($this->agent->referrer());
  499. } else {
  500. $this->session->set_flashdata('error', trans("msg_error"));
  501. redirect($this->agent->referrer());
  502. }
  503.  
  504. }
  505. }
  506.  
  507. /**
  508. * Delete Selected Posts
  509. */
  510. public function delete_selected_posts()
  511. {
  512. $post_ids = $this->input->post('post_ids', true);
  513. $this->post_admin_model->delete_multi_posts($post_ids);
  514. }
  515.  
  516. /**
  517. * Save Featured Post Order
  518. */
  519. public function featured_posts_order_post()
  520. {
  521. $post_id = $this->input->post('id', true);
  522. $order = $this->input->post('featured_order', true);
  523. $this->post_admin_model->save_featured_post_order($post_id, $order);
  524. redirect($this->agent->referrer());
  525. }
  526.  
  527.  
  528. /**
  529. * Save Home Slider Post Order
  530. */
  531. public function home_slider_posts_order_post()
  532. {
  533. $post_id = $this->input->post('id', true);
  534. $order = $this->input->post('slider_order', true);
  535. $this->post_admin_model->save_home_slider_post_order($post_id, $order);
  536. redirect($this->agent->referrer());
  537. }
  538.  
  539.  
  540. /**
  541. * Get Video from URL
  542. */
  543. public function get_video_from_url()
  544. {
  545. $url = $this->input->post('url', true);
  546.  
  547. $this->load->library('video_url_parser');
  548. echo $this->video_url_parser->get_url_embed($url);
  549.  
  550. }
  551.  
  552.  
  553. /**
  554. * Get Video Thumbnail
  555. */
  556. public function get_video_thumbnail()
  557. {
  558. $url = $this->input->post('url', true);
  559.  
  560. echo $this->file_model->get_video_thumbnail($url);
  561. }
  562.  
  563.  
  564. /**
  565. * Delete Additional Image
  566. */
  567. public function delete_post_additional_image()
  568. {
  569. $file_id = $this->input->post('file_id', true);
  570. $this->post_file_model->delete_post_additional_image($file_id);
  571. }
  572.  
  573.  
  574. /**
  575. * Delete Audio
  576. */
  577. public function delete_post_audio()
  578. {
  579. $post_id = $this->input->post('post_id', true);
  580. $audio_id = $this->input->post('audio_id', true);
  581. $this->post_file_model->delete_post_audio($post_id, $audio_id);
  582. }
  583.  
  584. /**
  585. * Delete Video
  586. */
  587. public function delete_post_video()
  588. {
  589. $post_id = $this->input->post('post_id', true);
  590. $this->post_file_model->delete_post_video($post_id);
  591. }
  592.  
  593. /**
  594. * Delete Post Main Image
  595. */
  596. public function delete_post_main_image()
  597. {
  598. $post_id = $this->input->post('post_id', true);
  599. $this->post_file_model->delete_post_main_image($post_id);
  600. }
  601.  
  602. public function set_pagination_per_page($count)
  603. {
  604. $_SESSION['pagination_per_page'] = $count;
  605. redirect($this->agent->referrer());
  606. }
  607. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement