PageRenderTime 46ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/app/modules/Comment/controllers/ApplicationController.php

https://gitlab.com/gregtyka/SiberianCMS
PHP | 149 lines | 136 code | 13 blank | 0 comment | 12 complexity | 9fe741fe118f254c5c35afd46d191308 MD5 | raw file
  1. <?php
  2. class Comment_ApplicationController extends Application_Controller_Default
  3. {
  4. public function editpostAction() {
  5. $html = '';
  6. if($datas = $this->getRequest()->getPost()) {
  7. try {
  8. if(!empty($datas['text'])) {
  9. $comment = new Comment_Model_Comment();
  10. $img_src = Core_Model_Directory::getTmpDirectory(true).'/';
  11. $image = '';
  12. if(empty($datas['image'])) {
  13. $datas['image'] = null;
  14. } else if(file_exists($img_src.$datas['image'])) {
  15. $img_src = $img_src.$datas['image'];
  16. $relativePath = '/feature/'.$this->getCurrentOptionValue()->getId();
  17. $img_dst = Application_Model_Application::getBaseImagePath().$relativePath;
  18. if(!is_dir($img_dst)) mkdir($img_dst, 0777, true);
  19. $img_dst .= '/'.$datas['image'];
  20. @rename($img_src, $img_dst);
  21. if(!file_exists($img_dst)) throw new Exception($this->_('An error occurred while saving your picture. Please try againg later.'));
  22. $datas['image'] = $relativePath.'/'.$datas['image'];
  23. $image = Application_Model_Application::getImagePath().'/';
  24. $image .= $datas['image'];
  25. }
  26. $comment->setData($datas)
  27. ->save()
  28. ;
  29. $url = array('comment/admin/edit');
  30. if($pos_id) $url[] = 'pos_id/'.$pos_id;
  31. $html = array(
  32. 'success' => '1',
  33. 'success_message' => $this->_('Information successfully saved'),
  34. 'image' => $image,
  35. 'message_timeout' => 2,
  36. 'message_button' => 0,
  37. 'message_loader' => 0
  38. );
  39. }
  40. } catch (Exception $e) {
  41. $html = array(
  42. 'error' => 1,
  43. 'message' => $e->getMessage()
  44. );
  45. }
  46. $this->getLayout()->setHtml(Zend_Json::encode($html));
  47. }
  48. }
  49. public function deleteAction() {
  50. $html = '';
  51. if($id = $this->getRequest()->getParam('id')) {
  52. try {
  53. $comment = new Comment_Model_Comment();
  54. $comment->find($id)->delete();
  55. $html = array(
  56. 'success' => '1',
  57. 'success_message' => $this->_('Information successfully deleted'),
  58. 'message_timeout' => 2,
  59. 'message_button' => 0,
  60. 'message_loader' => 0
  61. );
  62. } catch (Exception $e) {
  63. $html = array(
  64. 'error' => 1,
  65. 'message' => $e->getMessage()
  66. );
  67. }
  68. $this->getLayout()->setHtml(Zend_Json::encode($html));
  69. }
  70. }
  71. public function hideAction() {
  72. $html = '';
  73. if($id = $this->getRequest()->getParam('id')) {
  74. try {
  75. $comment = new Comment_Model_Comment();
  76. $comment->find($id)->setisVisible(0)->save();
  77. $html = array(
  78. 'success' => '1',
  79. 'success_message' => $this->_('Information successfully hidden'),
  80. 'message_timeout' => 2,
  81. 'message_button' => 0,
  82. 'message_loader' => 0
  83. );
  84. } catch (Exception $e) {
  85. $html = array(
  86. 'error' => 1,
  87. 'message' => $e->getMessage()
  88. );
  89. }
  90. $this->getLayout()->setHtml(Zend_Json::encode($html));
  91. }
  92. }
  93. public function showAction() {
  94. $html = '';
  95. if($id = $this->getRequest()->getParam('id')) {
  96. try {
  97. $comment = new Comment_Model_Comment();
  98. $comment->find($id)->setisVisible(1)->save();
  99. $html = array(
  100. 'success' => '1',
  101. 'success_message' => $this->_('Information successfully shown'),
  102. 'message_timeout' => 2,
  103. 'message_button' => 0,
  104. 'message_loader' => 0
  105. );
  106. } catch (Exception $e) {
  107. $html = array(
  108. 'error' => 1,
  109. 'message' => $e->getMessage()
  110. );
  111. }
  112. $this->getLayout()->setHtml(Zend_Json::encode($html));
  113. }
  114. }
  115. public function validatecropAction() {
  116. if($datas = $this->getRequest()->getPost()) {
  117. try {
  118. $uploader = new Core_Model_Lib_Uploader();
  119. $file = $uploader->savecrop($datas);
  120. $datas = array(
  121. 'success' => 1,
  122. 'file' => $file,
  123. 'message_success' => 'Enregistrement réussi',
  124. 'message_button' => 0,
  125. 'message_timeout' => 2,
  126. );
  127. } catch (Exception $e) {
  128. $datas = array(
  129. 'error' => 1,
  130. 'message' => $e->getMessage()
  131. );
  132. }
  133. $this->getLayout()->setHtml(Zend_Json::encode($datas));
  134. }
  135. }
  136. }