PageRenderTime 47ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/library/XenForo/ControllerAdmin/LinkForum.php

https://github.com/hanguyenhuu/DTUI_201105
PHP | 127 lines | 93 code | 21 blank | 13 comment | 4 complexity | b16649656eb1c37ffd5b6215095c7191 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, BSD-3-Clause
  1. <?php
  2. class XenForo_ControllerAdmin_LinkForum extends XenForo_ControllerAdmin_NodeAbstract
  3. {
  4. /**
  5. * Name of the DataWriter that will handle this node type
  6. *
  7. * @var string
  8. */
  9. protected $_nodeDataWriterName = 'XenForo_DataWriter_LinkForum';
  10. public function actionIndex()
  11. {
  12. return $this->responseReroute('XenForo_ControllerAdmin_Node', 'index');
  13. }
  14. public function actionAdd()
  15. {
  16. return $this->responseReroute(__CLASS__, 'edit');
  17. }
  18. public function actionEdit()
  19. {
  20. $nodeModel = $this->_getNodeModel();
  21. $linkForumModel = $this->_getLinkForumModel();
  22. if ($nodeId = $this->_input->filterSingle('node_id', XenForo_Input::UINT))
  23. {
  24. // if a node ID was specified, we should be editing, so make sure node exists
  25. $link = $linkForumModel->getLinkForumById($nodeId);
  26. if (!$link)
  27. {
  28. return $this->responseError(new XenForo_Phrase('requested_link_forum_not_found'), 404);
  29. }
  30. }
  31. else
  32. {
  33. // add a new link
  34. $link = array(
  35. 'parent_node_id' => $this->_input->filterSingle('parent_node_id', XenForo_Input::UINT),
  36. 'display_order' => 1,
  37. 'display_in_list' => 1
  38. );
  39. }
  40. $viewParams = array(
  41. 'link' => $link,
  42. 'nodeParentOptions' => $nodeModel->getNodeOptionsArray(
  43. $nodeModel->getPossibleParentNodes($link), $link['parent_node_id'], true
  44. )
  45. );
  46. return $this->responseView('XenForo_ViewAdmin_LinkForum_Edit', 'link_forum_edit', $viewParams);
  47. }
  48. public function actionSave()
  49. {
  50. $this->_assertPostOnly();
  51. $nodeId = $this->_input->filterSingle('node_id', XenForo_Input::UINT);
  52. $writerData = $this->_input->filter(array(
  53. 'title' => XenForo_Input::STRING,
  54. 'node_type_id' => XenForo_Input::BINARY,
  55. 'parent_node_id' => XenForo_Input::UINT,
  56. 'display_order' => XenForo_Input::UINT,
  57. 'display_in_list' => XenForo_Input::UINT,
  58. 'description' => XenForo_Input::STRING,
  59. 'link_url' => XenForo_Input::STRING
  60. ));
  61. $writer = $this->_getNodeDataWriter();
  62. if ($nodeId)
  63. {
  64. $writer->setExistingData($nodeId);
  65. }
  66. $writer->bulkSet($writerData);
  67. $writer->save();
  68. return $this->responseRedirect(
  69. XenForo_ControllerResponse_Redirect::SUCCESS,
  70. XenForo_Link::buildAdminLink('nodes') . $this->getLastHash($writer->get('node_id'))
  71. );
  72. }
  73. public function actionDeleteConfirm()
  74. {
  75. $nodeModel = $this->_getNodeModel();
  76. $linkForumModel = $this->_getLinkForumModel();
  77. $link = $linkForumModel->getLinkForumById($this->_input->filterSingle('node_id', XenForo_Input::UINT));
  78. if (!$link)
  79. {
  80. return $this->responseError(new XenForo_Phrase('requested_link_forum_not_found'), 404);
  81. }
  82. $childNodes = $nodeModel->getChildNodes($link);
  83. $viewParams = array(
  84. 'link' => $link,
  85. 'childNodes' => $childNodes,
  86. 'nodeParentOptions' => $nodeModel->getNodeOptionsArray(
  87. $nodeModel->getPossibleParentNodes($link), $link['parent_node_id'], true
  88. )
  89. );
  90. return $this->responseView('XenForo_ViewAdmin_LinkForum_Delete', 'link_forum_delete', $viewParams);
  91. }
  92. /**
  93. * @return XenForo_Model_LinkForum
  94. */
  95. protected function _getLinkForumModel()
  96. {
  97. return $this->getModelFromCache('XenForo_Model_LinkForum');
  98. }
  99. /**
  100. * @return XenForo_DataWriter_Link
  101. */
  102. protected function _getNodeDataWriter()
  103. {
  104. return XenForo_DataWriter::create($this->_nodeDataWriterName);
  105. }
  106. }