PageRenderTime 26ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/add-ons/frag_news/manager/news/news.class.php

https://github.com/iconifyit/SkyBlue-1.1
PHP | 152 lines | 106 code | 29 blank | 17 comment | 5 complexity | 0e4a0a6c4e41a924fae698df434fec54 MD5 | raw file
  1. <?php
  2. /**
  3. * @version RC 1.1 2008-12-08 21:00:00 $
  4. * @package SkyBlueCanvas
  5. * @copyright Copyright (C) 2005 - 2008 Scott Edwin Lewis. All rights reserved.
  6. * @license GNU/GPL, see COPYING.txt
  7. * SkyBlueCanvas is free software. This version may have been modified pursuant
  8. * to the GNU General Public License, and as distributed it includes or
  9. * is derivative of works licensed under the GNU General Public License or
  10. * other free or open source software licenses.
  11. * See COPYING.txt for copyright notices and details.
  12. */
  13. defined('SKYBLUE') or die(basename(__FILE__));
  14. class news extends manager
  15. {
  16. var $storyfile = null;
  17. var $updatesitemap = true;
  18. function __construct()
  19. {
  20. $this->Init();
  21. }
  22. function news()
  23. {
  24. $this->__construct();
  25. }
  26. function AddEventHandlers()
  27. {
  28. $this->AddEventHandler('OnBeforeSave','PrepareForSave');
  29. }
  30. function PrepareForSave()
  31. {
  32. global $Core;
  33. $this->AddFieldValidation('title','notnull');
  34. $this->AddFieldValidation('intro','notnull');
  35. $this->SaveStoryText();
  36. $_POST['intro'] = base64_encode(stripslashes(urldecode($_POST['intro'])));
  37. $_POST['text'] = base64_encode(stripslashes(urldecode($_POST['text'])));
  38. }
  39. function InitProps()
  40. {
  41. $this->setProp('headings', array('News', 'Date', 'Tasks'));
  42. $this->setProp('tasks', array('edit', 'delete'));
  43. $this->setProp('cols', array('title', 'date'));
  44. }
  45. function Trigger()
  46. {
  47. global $Core;
  48. switch($this->button)
  49. {
  50. case 'add':
  51. case 'edit':
  52. case 'editnews':
  53. $this->AddButton('Save');
  54. $this->InitSkin();
  55. $this->InitEditor();
  56. $this->Edit();
  57. break;
  58. case 'save':
  59. if (DEMO_MODE)
  60. {
  61. $Core->ExitDemoEvent($this->redirect);
  62. }
  63. $this->SaveItems();
  64. break;
  65. case 'delete':
  66. case 'deletenews':
  67. if (DEMO_MODE)
  68. {
  69. $Core->ExitDemoEvent($this->redirect);
  70. }
  71. $this->DeleteItem();
  72. break;
  73. case 'cancel':
  74. $this->Cancel();
  75. break;
  76. default:
  77. $this->AddButton('Add');
  78. $this->InitProps();
  79. $this->ViewItems();
  80. break;
  81. }
  82. }
  83. function SaveStoryText()
  84. {
  85. global $Core;
  86. $this->SaveStory(
  87. $Core->GetVar($_POST,'story', $this->GetStoryFileName()),
  88. stripslashes(urldecode($_POST['text'])));
  89. $_POST['text'] =
  90. base64_encode(stripslashes(urldecode($_POST['text'])));
  91. }
  92. function InitEditor()
  93. {
  94. global $Core;
  95. // Set the form message
  96. $this->SetFormMessage('title','News');
  97. // Initialize the object properties to empty strings or
  98. // the properties of the object being edited
  99. $_OBJ = $this->InitObjProps($this->skin, $this->obj);
  100. // This step creates a $form array to pass to buildForm().
  101. // buildForm() merges the $obj properites with the form HTML.
  102. $form['ID'] = $this->GetItemID($_OBJ);
  103. $form['TITLE'] = $this->GetObjProp($_OBJ,'title');
  104. $form['DATE'] = $this->GetObjProp($_OBJ,'date');
  105. $form['TEXT'] = $this->GetStoryContent($_OBJ); // "";
  106. $form['INTRO'] = $this->Decode($_OBJ,'intro');
  107. $form['PUBLISHED'] =
  108. $Core->YesNoList('published', $this->GetObjProp($_OBJ,'published'));
  109. $form['ORDER'] =
  110. $Core->OrderSelector2($this->objs, 'title', $_OBJ['title']);
  111. $form['STORY'] = $this->GetStoryFileName();
  112. $this->BuildForm($form);
  113. // id, title, date, text, published, introlength, link, order
  114. }
  115. function GetStoryContent($obj)
  116. {
  117. global $Core;
  118. if (!isset($obj['story'])) return null;
  119. if (!file_exists(SB_STORY_DIR . $obj['story']) || empty($obj['story'])) return null;
  120. return $Core->SBReadFile(SB_STORY_DIR . $obj['story']);
  121. }
  122. }
  123. ?>