PageRenderTime 66ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

/objects/page.inc.php

https://github.com/adamfranco/segue-1.x
PHP | 820 lines | 620 code | 95 blank | 105 comment | 148 complexity | 110c0b754a00d6ba93193ceaaac7da32 MD5 | raw file
  1. <? /* $Id$ */
  2. /******************************************************************************
  3. * page object - handles site pages
  4. ******************************************************************************/
  5. class page extends segue {
  6. var $stories;
  7. var $_allfields = array("section_id","site_id","title","location","addedtimestamp","addedby",
  8. "editedby","editedtimestamp","text","activatedate","deactivatedate",
  9. "active","locked","showcreator","showeditor","showdate","showversions","showhr","stories",
  10. "storyorder","type","url","ediscussion","archiveby");
  11. // fields listed in $_datafields are stored in the database.
  12. // the first element is the table join syntax required to pull the data.
  13. // the second element is an array of the database fields we will be selecting
  14. // the third element is the database field by which we will sort
  15. var $_datafields = array(
  16. "id" => array(
  17. "page",
  18. array("page_id"),
  19. "page_id"
  20. ),
  21. "section_id" => array(
  22. "page",
  23. array("FK_section"),
  24. "page_id"
  25. ),
  26. "site_id" => array(
  27. "page
  28. INNER JOIN
  29. section
  30. ON FK_section = section_id
  31. INNER JOIN
  32. site
  33. ON section.FK_site = site.site_id
  34. INNER JOIN
  35. slot
  36. ON site.site_id = slot.FK_site
  37. ",
  38. array("slot_name"),
  39. "page_id"
  40. ),
  41. "type" => array(
  42. "page",
  43. array("page_display_type"),
  44. "page_id"
  45. ),
  46. "title" => array(
  47. "page",
  48. array("page_title"),
  49. "page_id"
  50. ),
  51. "location" => array(
  52. "page",
  53. array("page_location"),
  54. "page_id"
  55. ),
  56. "activatedate" => array(
  57. "page",
  58. array("DATE_FORMAT(page_activate_tstamp, '%Y-%m-%d')"),
  59. "page_id"
  60. ),
  61. "deactivatedate" => array(
  62. "page",
  63. array("DATE_FORMAT(page_deactivate_tstamp, '%Y-%m-%d')"),
  64. "page_id"
  65. ),
  66. "active" => array(
  67. "page",
  68. array("page_active"),
  69. "page_id"
  70. ),
  71. "storyorder" => array(
  72. "page",
  73. array("page_story_order"),
  74. "page_id"
  75. ),
  76. "showcreator" => array(
  77. "page",
  78. array("page_show_creator"),
  79. "page_id"
  80. ),
  81. "showeditor" => array(
  82. "page",
  83. array("page_show_editor"),
  84. "page_id"
  85. ),
  86. "showdate" => array(
  87. "page",
  88. array("page_show_date"),
  89. "page_id"
  90. ),
  91. "showversions" => array(
  92. "page",
  93. array("page_show_versions"),
  94. "page_id"
  95. ),
  96. "showhr" => array(
  97. "page",
  98. array("page_show_hr"),
  99. "page_id"
  100. ),
  101. "url" => array(
  102. "page
  103. LEFT JOIN
  104. media
  105. ON FK_media = media_id",
  106. array("media_tag"),
  107. "page_id"
  108. ),
  109. "archiveby" => array(
  110. "page",
  111. array("page_archiveby"),
  112. "page_id"
  113. ),
  114. "locked" => array(
  115. "page",
  116. array("page_locked"),
  117. "page_id"
  118. ),
  119. "editedby" => array(
  120. "page
  121. INNER JOIN
  122. user
  123. ON FK_updatedby = user_id",
  124. array("user_uname"),
  125. "page_id"
  126. ),
  127. "editedtimestamp" => array(
  128. "page",
  129. array("page_updated_tstamp"),
  130. "page_id"
  131. ),
  132. "addedby" => array(
  133. "page
  134. INNER JOIN
  135. user
  136. ON FK_createdby = user_id",
  137. array("user_uname"),
  138. "page_id"
  139. ),
  140. "addedtimestamp" => array(
  141. "page",
  142. array("page_created_tstamp"),
  143. "page_id"
  144. ),
  145. "ediscussion" => array(
  146. "page",
  147. array("page_ediscussion"),
  148. "page_id"
  149. ),
  150. "text" => array(
  151. "page",
  152. array("page_text"),
  153. "page_id"
  154. ),
  155. "stories" => array(
  156. "page
  157. INNER JOIN
  158. story
  159. ON page_id = FK_page",
  160. array("story_id"),
  161. "story_order"
  162. )
  163. );
  164. var $_table = "page";
  165. function page($insite,$insection,$id=0,&$sectionObj) {
  166. $this->owning_site = $insite;
  167. $this->owning_section = $insection;
  168. $this->owningSectionObj = &$sectionObj;
  169. $this->owningSiteObj = &$this->owningSectionObj->owningSiteObj;
  170. $this->fetchedup = 1;
  171. $this->id = $id;
  172. // initialize the data array
  173. $this->data[site_id] = $insite;
  174. $this->data[section_id] = $insection;
  175. $this->init();
  176. $this->data[type] = "page";
  177. }
  178. function init($formdates=0) {
  179. $this->stories = array();
  180. if (!is_array($this->data)) $this->data = array();
  181. $this->data[title] = "";
  182. $this->data[activatedate] = $this->data[deactivatedate] = "0000-00-00";
  183. $this->data[active] = 1;
  184. $this->data[url] = "http://";
  185. $this->data[locked] = 0;
  186. $this->data[showcreator] = 0;
  187. $this->data[showeditor] = 0;
  188. $this->data[showdate] = 0;
  189. $this->data[showversions] = 0;
  190. $this->data[archiveby] = "none";
  191. $this->data[ediscussion] = 0;
  192. $this->data[showcreator] = 0;
  193. $this->data[showdate] = 0;
  194. $this->data[showhr] = 0;
  195. $this->data[archiveby] = "none";
  196. $this->data[stories] = array();
  197. $this->data[storyorder] = "custom";
  198. if ($this->id) $this->fetchFromDB();
  199. if ($formdates) $this->initFormDates();
  200. }
  201. function delete($deleteFromParent=0) { // delete from db
  202. // print "<br /><br /> Deleting Page<br /><br />";
  203. if (!$this->id) return false;
  204. if ($deleteFromParent) {
  205. $parentObj =& new section($this->owning_site,$this->owning_section,$this->owningSectionObj->owningSiteObj);
  206. $parentObj->fetchDown();
  207. $parentObj->delPage($this->id);
  208. $parentObj->updateDB();
  209. } else {
  210. // remove stories
  211. $this->fetchDown();
  212. if ($this->stories) {
  213. foreach ($this->stories as $s=>$o) {
  214. $o->delete();
  215. }
  216. }
  217. $query = "DELETE FROM page WHERE page_id='".addslashes($this->id)."'";
  218. db_query($query);
  219. $query = "DELETE FROM permission WHERE FK_scope_id='".addslashes($this->id)."' AND permission_scope_type='page';";
  220. db_query($query);
  221. $query = "DELETE FROM links WHERE source_id='".addslashes($this->id)."' AND source_type='page';";
  222. db_query($query);
  223. $query = "DELETE FROM links WHERE target_id='".addslashes($this->id)."' AND target_type='page';";
  224. db_query($query);
  225. // // should page media (i.e. link or rss url be deleted when page is...?
  226. // $query = "DELETE FROM media WHERE media_id=".$media_id;
  227. // db_query($query);
  228. $this->clearPermissions();
  229. $this->updatePermissionsDB();
  230. }
  231. }
  232. function addStory($id) {
  233. if (!is_array($this->getField("stories"))) $this->data[stories] = array();
  234. array_push($this->data["stories"],$id);
  235. $this->changed[stories]=1;
  236. }
  237. function delStory($id,$delete=1) {
  238. /* print "<br /> deleting - $id - $delete<br />"; */
  239. /* print "<pre>"; print_r($this); print "</pre>"; */
  240. $d = array();
  241. foreach ($this->getField("stories") as $s) {
  242. if ($s != $id) $d[]=$s;
  243. }
  244. $this->data[stories] = $d;
  245. $this->changed[stories]=1;
  246. /* print "------------------------ <br /><pre>"; print_r($this); print "</pre>"; */
  247. if ($delete) {
  248. $story =& new story($this->owning_site,$this->owning_section,$this->owning_page,$id,$this);
  249. $story->delete();
  250. }
  251. }
  252. function fetchUp($full = 0) {
  253. if (!$this->fetchedup || $full) {
  254. $this->owningSiteObj =& new site($this->owning_site);
  255. $this->owningSiteObj->fetchFromDB();
  256. // $this->owningSiteObj->buildPermissionsArray(1);
  257. $this->owningSectionObj =& new section($this->owning_site,$this->owning_section,$this->owningSiteObj);
  258. $this->owningSectionObj->fetchFromDB();
  259. // $this->owningSectionObj->buildPermissionsArray(1);
  260. $this->fetchedup = 1;
  261. }
  262. }
  263. function fetchDown($full=0) {
  264. if (!$this->fetcheddown || $full) {
  265. /* print "---->page fetchdown".$this->id." full = $full<br />"; */
  266. if (!$this->tobefetched || $full)
  267. $this->fetchFromDB(0,$full);
  268. foreach ($this->getField("stories") as $s) {
  269. $this->stories[$s] =& new story($this->owning_site,$this->owning_section,$this->id,$s,$this);
  270. $this->stories[$s]->fetchDown($full);
  271. }
  272. $this->fetcheddown = 1;
  273. }
  274. }
  275. function fetchFromDB($id=0,$force=0) {
  276. if ($id) $this->id = $id;
  277. global $dbuser, $dbpass, $dbdb, $dbhost;
  278. global $cfg;
  279. // take this out when appropriate & replace occurences;
  280. global $uploaddir;
  281. $this->tobefetched=1;
  282. //$this->id = $this->getField("id"); // why need to do this?
  283. if ($force) {
  284. // the code below is inefficient! why fetch each field separately when we can fetch all fields at same time
  285. // thus we can cut the number of queries significantly
  286. /* foreach ($this->_allfields as $f) {
  287. $this->getField($f);
  288. }
  289. */
  290. // connect to db and initialize data array
  291. db_connect($dbhost,$dbuser,$dbpass, $dbdb);
  292. $this->data = array();
  293. // first fetch all fields that are not part of a 1-to-many relationship
  294. $query = "
  295. SELECT
  296. page_display_type AS type, page_title AS title, page_location AS location, page_text AS text, DATE_FORMAT(page_activate_tstamp, '%Y-%m-%d') AS activatedate, DATE_FORMAT(page_deactivate_tstamp, '%Y-%m-%d') AS deactivatedate,
  297. page_active AS active, page_story_order AS storyorder, page_show_creator AS showcreator, page_show_editor AS showeditor,
  298. page_show_date AS showdate, page_show_versions AS showversions, page_show_hr AS showhr, page_archiveby AS archiveby, page_locked AS locked,
  299. page_updated_tstamp AS editedtimestamp, page_created_tstamp AS addedtimestamp,
  300. page_ediscussion AS ediscussion,
  301. user_createdby.user_uname AS addedby, user_updatedby.user_uname AS editedby, slot_name as site_id,
  302. FK_section AS section_id, media_tag AS url
  303. FROM
  304. page
  305. INNER JOIN
  306. section
  307. ON FK_section = section_id
  308. INNER JOIN
  309. user AS user_createdby
  310. ON page.FK_createdby = user_createdby.user_id
  311. INNER JOIN
  312. user AS user_updatedby
  313. ON page.FK_updatedby = user_updatedby.user_id
  314. INNER JOIN
  315. site
  316. ON section.FK_site = site.site_id
  317. INNER JOIN
  318. slot
  319. ON site.site_id = slot.FK_site
  320. LEFT JOIN
  321. media
  322. ON page.FK_media = media_id
  323. WHERE
  324. page_id = '".addslashes($this->id)."'";
  325. $r = db_query($query);
  326. $a = db_fetch_assoc($r);
  327. array_change_key_case($a); // make all keys lower case
  328. // for each field returned by the query
  329. foreach ($a as $field => $value)
  330. // make sure we have defined this field in the _allfields array
  331. if (in_array($field,$this->_allfields)) {
  332. // decode if necessary
  333. if (in_array($field,$this->_encode))
  334. $value = stripslashes(urldecode($value));
  335. $this->data[$field] = $value;
  336. $this->fetched[$field] = 1;
  337. }
  338. else
  339. echo "ERROR: field $field not in _allfields!!!<br />";
  340. // now fetch the sections (they are part of a 1-to-many relationship and therefore
  341. // we cannot fetch them along with the other fields)
  342. $query = "
  343. SELECT
  344. story_id
  345. FROM
  346. page
  347. INNER JOIN
  348. story
  349. ON page_id = FK_page
  350. WHERE page_id = '".addslashes($this->id)."'
  351. ORDER BY
  352. page_order
  353. ";
  354. $r = db_query($query);
  355. $this->data[stories] = array();
  356. while ($a = db_fetch_assoc($r))
  357. $this->data[stories][] = $a[story_id];
  358. $this->fetched[stories] = 1;
  359. }
  360. return $this->id;
  361. }
  362. function updateDB($down=0, $force=0, $keepEditHistory = FALSE) {
  363. if (count($this->changed)) {
  364. $a = $this->createSQLArray();
  365. if ($keepEditHistory) {
  366. $a[] = $this->_datafields[editedtimestamp][1][0]."='".addslashes($this->getField("editedtimestamp"))."'";
  367. } else
  368. $a[] = "FK_updatedby='".addslashes($_SESSION[aid])."'";
  369. $query = "UPDATE page SET \n\t".implode(",\n\t",$a)."\nWHERE page_id='".addslashes($this->id)."'";
  370. // print "<pre>Page->UpdateDB:";
  371. // printpre($query);
  372. db_query($query);
  373. /* print mysql_error()."<br />"; */
  374. /* print_r($this->data['stories']); */
  375. /* print "</pre>"; */
  376. // the hard step: update the fields in the JOIN tables
  377. // Urls are now stored in the media table
  378. if ($this->changed[url]) {
  379. // Urls are now stored in the media table
  380. // get id of media item
  381. $query = "
  382. SELECT
  383. FK_media
  384. FROM
  385. page
  386. WHERE
  387. page_id = '".addslashes($this->id)."'";
  388. $a = db_fetch_assoc(db_query($query));
  389. $media_id = $a[FK_media];
  390. if ($media_id) {
  391. $query = "
  392. UPDATE
  393. media
  394. SET
  395. media_tag = '".addslashes($this->data[url])."',
  396. FK_updatedby = '".addslashes($_SESSION[aid])."'
  397. WHERE
  398. media_id = $media_id
  399. ";
  400. } else {
  401. $query = "
  402. INSERT INTO
  403. media
  404. SET
  405. media_tag = '".addslashes($this->data[url])."',
  406. FK_updatedby = '".addslashes($_SESSION[aid])."'
  407. ";
  408. }
  409. db_query($query);
  410. }
  411. }
  412. // update permissions
  413. $this->updatePermissionsDB($force);
  414. // add log entry
  415. /* log_entry("edit_section",$this->owning_site,$this->id,"","$_SESSION[auser] edited section id ".$this->id." in site ".$this->owning_site); */
  416. // update down
  417. if ($down) {
  418. if ($this->fetcheddown && $this->stories) {
  419. foreach (array_keys($this->stories) as $i) $this->stories[$i]->updateDB($down, $force, $keepEditHistory);
  420. }
  421. }
  422. return true;
  423. }
  424. function insertDB($down=0, $newsite=null, $newsection=0, $removeOrigional=0, $keepaddedby=0, $keepDiscussions=0) {
  425. $origsite = $this->owning_site;
  426. $origid = $this->id;
  427. if ($newsite) {
  428. $this->owning_site = $newsite;
  429. unset($this->owningSiteObj);
  430. }
  431. if ($newsection) {
  432. $this->owning_section = $newsection;
  433. unset($this->owningSectionObj);
  434. }
  435. /* print "<pre>\n\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n"; */
  436. /* print "owning_site=".$this->owning_site."\nowning section=".$this->owning_section."\nOwningSiteObj: "; */
  437. /* // print_r ($this->owningSiteObj); */
  438. /* print "\nOwningSectionObj: "; */
  439. /* print_r ($this->owningSectionObj); */
  440. /* print "\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n\n</pre>"; */
  441. $this->fetchUp(1);
  442. /*********************************************************
  443. * Re-Key the ordering of the rest of the pages in the
  444. * section to make sure that there are no holes
  445. *********************************************************/
  446. foreach($this->owningSectionObj->getField("pages") as $order => $pageId) {
  447. $query =
  448. "UPDATE
  449. page
  450. SET
  451. page_order = '".addslashes($order)."'
  452. WHERE
  453. page_id = '".$pageId."'";
  454. // printpre($query);
  455. db_query($query);
  456. }
  457. $a = $this->createSQLArray(1);
  458. if (!$keepaddedby) {
  459. $a[] = "FK_createdby='".addslashes($_SESSION[aid])."'";
  460. $a[] = $this->_datafields[addedtimestamp][1][0]."=NOW()";
  461. $a[] = "FK_updatedby='".addslashes($_SESSION[aid])."'";
  462. } else {
  463. $a[] = "FK_createdby=".db_get_value("user","user_id","user_uname='".addslashes($this->getField("addedby"))."'");
  464. $a[] = $this->_datafields[addedtimestamp][1][0]."='".addslashes($this->getField("addedtimestamp"))."'";
  465. $a[] = "FK_updatedby=".db_get_value("user","user_id","user_uname='".addslashes($this->getField("editedby"))."'");
  466. $a[] = $this->_datafields[editedtimestamp][1][0]."='".addslashes($this->getField("editedtimestamp"))."'";
  467. }
  468. // insert media (url)
  469. if ($this->data[url]) {
  470. // first see, if media item already exists in media table
  471. $query = "
  472. SELECT
  473. media_id
  474. FROM
  475. media
  476. WHERE
  477. FK_site = '".addslashes($this->owningSiteObj->id)."' AND
  478. FK_createdby = '".addslashes($_SESSION[aid])."' AND
  479. media_tag = '".addslashes($this->data[url])."' AND
  480. media_location = 'remote'";
  481. $r = db_query($query);
  482. // if not in media table insert it
  483. if (!db_num_rows($r)) {
  484. $query = "
  485. INSERT
  486. INTO media
  487. SET
  488. FK_site = '".addslashes($this->owningSiteObj->id)."',
  489. FK_createdby = '".addslashes($_SESSION[aid])."',
  490. media_tag = '".addslashes($this->data[url])."',
  491. media_location = 'remote',
  492. FK_updatedby = '".addslashes($_SESSION[aid])."'
  493. ";
  494. db_query($query);
  495. $a[] = "FK_media=".lastid();
  496. }
  497. // if in media table, assign the media id
  498. else {
  499. $arr = db_fetch_assoc($r);
  500. $a[] = "FK_media= '".addslashes($arr[media_id])."'";
  501. }
  502. }
  503. $query = "INSERT INTO page SET \n\t".implode(",\n\t",$a);
  504. //printpre($query);
  505. db_query($query);
  506. $this->id = lastid();
  507. // See if there is a site hash (meaning that we are being copied).
  508. // If so, try to match our id with the hash entry for 'NEXT'.
  509. if ($GLOBALS['__site_hash']['pages']
  510. && $oldId = array_search('NEXT', $GLOBALS['__site_hash']['pages']))
  511. {
  512. $GLOBALS['__site_hash']['pages'][$oldId] = $this->id;
  513. }
  514. $this->fetchUp();
  515. /* $this->owningSectionObj->addPage($this->id); */
  516. if ($removeOrigional) $this->owningSectionObj->delPage($origid,0);
  517. $this->owningSectionObj->updateDB();
  518. // add new permissions entry.. force update
  519. // $this->updatePermissionsDB(1); // We shouldn't need this because new sections will just
  520. //inherit the permissions of their parent sites
  521. // add log entry
  522. /* log_entry("add_page",$this->owning_site,$this->owning_section,$this->id,"$_SESSION[auser] added page id ".$this->id." to site ".$this->owning_site); */
  523. // insert down
  524. if ($down && $this->fetcheddown && $this->stories) {
  525. foreach (array_keys($this->stories) as $i) {
  526. // Mark our Id as the next one to set
  527. if (is_array($GLOBALS['__site_hash']['stories']))
  528. $GLOBALS['__site_hash']['stories'][$i] = 'NEXT';
  529. $storyTags = get_record_tags($this->stories[$i]->id); // Get any tags for the story
  530. $this->stories[$i]->id = 0; // createSQLArray uses this to tell if we are inserting or updating
  531. $this->stories[$i]->insertDB(1, $this->owning_site, $this->owning_section, $this->id, 1, $keepaddedby, $keepDiscussions, $storyTags);
  532. }
  533. }
  534. return true;
  535. }
  536. function createSQLArray($all=0) {
  537. $d = $this->data;
  538. // print "This->data: ";
  539. // printpre($d);
  540. $a = array();
  541. $this->fetchUp();
  542. /* print "<pre>OwningSite: ".$this->owning_site."\nOwning_section: ".$this->owning_section."\nOwningSiteObj for page".$this->id.":\n"; */
  543. /* print_r($this->owningSiteObj); */
  544. /* print "</pre>"; */
  545. if (!isset($this->owningSectionObj)) {
  546. $this->owningSectionObj = &$this->owningSiteObj->sections[$this->owning_section];
  547. }
  548. if ($all) $a[] = $this->_datafields[section_id][1][0]."='".addslashes($this->owningSectionObj->id)."'";
  549. // if ($this->id && ($all || $this->changed[pages])) { //I belive we may always need to fix the order.
  550. if ($this->id) {
  551. $orderkeys = array_keys($this->owningSectionObj->getField("pages"),$this->id);
  552. $a[] = "page_order='".addslashes($orderkeys[0])."'";
  553. } else {
  554. $a[] = "page_order='".addslashes(count($this->owningSectionObj->getField("pages")))."'";
  555. }
  556. /* print "\nXXXXXXX\n</pre>"; */
  557. if ($all || $this->changed[title]) $a[] = $this->_datafields[title][1][0]."='".addslashes($d[title])."'";
  558. if ($all || $this->changed[text]) $a[] = $this->_datafields[text][1][0]."='".addslashes(urlencode($d[text]))."'";
  559. if ($all || $this->changed[location]) $a[] = $this->_datafields[location][1][0]."='".addslashes($d['location'])."'";
  560. if ($all || $this->changed[activatedate]) $a[] = "page_activate_tstamp ='".addslashes(ereg_replace("-","",$d[activatedate]))."'"; // remove dashes to make a tstamp
  561. if ($all || $this->changed[deactivatedate]) $a[] = "page_deactivate_tstamp ='".addslashes(ereg_replace("-","",$d[deactivatedate]))."'"; // remove dashes to make a tstamp
  562. if ($all || $this->changed[active]) $a[] = $this->_datafields[active][1][0]."='".addslashes((($d[active])?1:0))."'";
  563. if ($all || $this->changed[type]) $a[] = $this->_datafields[type][1][0]."='".addslashes($d[type])."'";
  564. if ($all || $this->changed[locked]) $a[] = $this->_datafields[locked][1][0]."='".addslashes((($d[locked])?1:0))."'";
  565. // if ($all || $this->changed[stories]) $a[] = "stories='".encode_array($d[stories])."'";
  566. // if ($all || $this->changed[url]) $a[] = $this->_datafields[url][1][0]."='".addslashes($d[url])."'";
  567. if ($all || $this->changed[ediscussion]) $a[] = $this->_datafields[ediscussion][1][0]."='".addslashes((($d[ediscussion])?1:0))."'";
  568. if ($all || $this->changed[archiveby]) $a[] = $this->_datafields[archiveby][1][0]."='$d[archiveby]'";
  569. if ($all || $this->changed[showcreator]) $a[] = $this->_datafields[showcreator][1][0]."='".addslashes((($d[showcreator])?1:0))."'";
  570. if ($all || $this->changed[showeditor]) $a[] = $this->_datafields[showeditor][1][0]."='".addslashes((($d[showeditor])?1:0))."'";
  571. if ($all || $this->changed[showdate]) $a[] = $this->_datafields[showdate][1][0]."='".addslashes((($d[showdate])?1:0))."'";
  572. if ($all || $this->changed[showversions]) $a[] = $this->_datafields[showversions][1][0]."='".addslashes((($d[showversions])?1:0))."'";
  573. if ($all || $this->changed[showhr]) $a[] = $this->_datafields[showhr][1][0]."='".addslashes((($d[showhr])?1:0))."'";
  574. if ($all || $this->changed[storyorder]) $a[] = $this->_datafields[storyorder][1][0]."='".addslashes($d[storyorder])."'";
  575. return $a;
  576. }
  577. function handleStoryArchive() {
  578. global $months;
  579. /* global $usesearch; */
  580. /* global $site,$section,$page; */
  581. $site = $this->owning_site;
  582. $section = $this->owning_section;
  583. $page=$this->id;
  584. /* $stories = $this->getField("stories"); */
  585. $newstories = array();
  586. $pa = $this->getField("archiveby");
  587. if ($pa == 'none' || $pa == '') return;
  588. // if we're looking at a discussion, don't do the archiving
  589. if ($_REQUEST['detail']) return;
  590. $_a = array("startday","startmonth","startyear","endday","endmonth","endyear","usestart","useend","usesearch");
  591. foreach ($_a as $a) $$a = $_REQUEST[$a];
  592. if (!$usesearch) {
  593. $endyear = date("Y");
  594. $endmonth = date("n");
  595. $endday = date("j");
  596. }
  597. printc("<div>");
  598. // printc("<b>Search:</b> ");
  599. printc("Display content in date rage: ");
  600. printc("<form action='$PHP_SELF?$sid&amp;action=site&amp;site=$site&amp;section=$section&amp;page=$page' method='post'>");
  601. printc("<input type='hidden' name='usesearch' value='1' />");
  602. printc("<select name='startday'>");
  603. for ($i=1;$i<=31;$i++) {
  604. printc("<option" . (($startday == $i)?" selected":"") . ">$i\n");
  605. }
  606. printc("</select>\n");
  607. printc("<select name='startmonth'>");
  608. for ($i=0; $i<12; $i++)
  609. printc("<option value=".($i+1). (($startmonth == $i+1)?" selected":"") . ">$months[$i]\n");
  610. printc("</select>\n<select name='startyear'>");
  611. $curryear = date("Y");
  612. for ($i=$curryear-10; $i <= ($curryear); $i++) {
  613. printc("<option" . (($startyear == $i)?" selected":"") . ">$i\n");
  614. }
  615. printc("</select>");
  616. // printc("<br />");
  617. printc(" to <select name='endday'>");
  618. for ($i=1;$i<=31;$i++) {
  619. printc("<option" . (($endday == $i)?" selected":"") . ">$i\n");
  620. }
  621. printc("</select>\n");
  622. printc("<select name='endmonth'>");
  623. for ($i=0; $i<12; $i++) {
  624. printc("<option value=".($i+1) . (($endmonth == $i+1)?" selected":"") . ">$months[$i]\n");
  625. }
  626. printc("</select>\n<select name='endyear'>");
  627. for ($i=$curryear; $i <= ($curryear+5); $i++) {
  628. printc("<option" . (($endyear == $i)?" selected":"") . ">$i\n");
  629. }
  630. printc("</select>");
  631. printc(" <input type='submit' class='button' value='go' />");
  632. printc("</form></div>");
  633. $start = mktime(1,1,1,$startmonth,$startday,$startyear);
  634. $end = mktime(1,1,1,$endmonth,$endday,$endyear);
  635. if ($pa == 'week') {
  636. if (!$usesearch) {
  637. $start = mktime(0,0,0,date("n"),date('j')-7,date('Y'));
  638. $end = time();
  639. }
  640. }
  641. if ($pa == 'month') {
  642. if (!$usesearch) {
  643. $start = mktime(0,0,0,date("n")-1,date('j'),date("Y"));
  644. $end = time();
  645. }
  646. }
  647. if ($pa == 'year') {
  648. if (!$usesearch) {
  649. $start = mktime(0,0,0,date("n"),date('j'),date("Y")-1);
  650. $end = time();
  651. }
  652. }
  653. $txtstart = date("n/j/y",$start);
  654. $txtend = date("n/j/y",$end);
  655. // print "start $start, end: $end<br />";
  656. $this->fetchDown();
  657. foreach ($this->stories as $s=>$o) {
  658. $added = $o->getField("addedtimestamp");
  659. // print $added."<br />";
  660. ereg ("([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})",$added,$regs);
  661. // print_r($regs);
  662. $year = (integer)$regs[1];
  663. $month = (integer)$regs[2];
  664. $day = (integer)$regs[3];
  665. $t = mktime(0,0,0,$month,$day,$year);
  666. // print $t."<br />";
  667. // $week = date("W",$t-(date("w",$t)*86400));
  668. //
  669. // if ($startyear == $year && $startweek == $week)
  670. // $newstories[] = $s;
  671. // if ((!$usestart || $start < $t) && (!$useend || $t < $end)) {
  672. if (($start < $t) && ($t < $end) || false) {
  673. $newstories[$s] = $t;
  674. }
  675. }
  676. // print_r($newstories);
  677. // arsort($newstories,SORT_NUMERIC);
  678. // print_r($newstories);
  679. $this->setField("stories",array_keys($newstories));
  680. $a = array();
  681. foreach (array_keys($newstories) as $s)
  682. $a[$s] = &$this->stories[$s];
  683. $this->stories = &$a;
  684. /* $this->fetcheddown=0;$this->fetchDown(); */
  685. printc("<b>Content ranging from $txtstart to $txtend.</b><br /><br />");
  686. }
  687. function handleStoryOrder() {
  688. // reorders the stories array passed to it depending on the order specified.
  689. // Orders: addedesc, addedasc, editeddesc, editedasc, author, editor, category, titledesc, titleasc
  690. $newstories = array();
  691. $order = $this->getField("storyorder");
  692. if ($order == '' || $order=='custom') return;
  693. $this->fetchDown();
  694. foreach ($this->stories as $s=>$o) {
  695. $added = ereg_replace("[: -]","",$o->getField("addedtimestamp"));
  696. /* $added = str_replace("-","",$added); */
  697. /* $added = str_replace(" ","",$added); */
  698. if ($order == "addeddesc" || $order == "addedasc")
  699. $newstories[$s] = $added;
  700. else if ($order == "editeddesc" || $order == "editedasc")
  701. $newstories[$s] = $o->getField("editedtimestamp");
  702. else if ($order == "author")
  703. $newstories[$s] = $o->getField("addedby");
  704. else if ($order == "editor")
  705. $newstories[$s] = $o->getField("editedby");
  706. else if ($order == "category")
  707. $newstories[$s] = $o->getField("category");
  708. else if ($order == "titledesc" || $order == "titleasc")
  709. $newstories[$s] = strtolower($o->getField("title"));
  710. }
  711. if ($order == "addeddesc" || $order == "editeddesc")
  712. arsort($newstories,SORT_NUMERIC);
  713. else if ($order == "addedasc" || $order == "editedasc")
  714. asort($newstories,SORT_NUMERIC);
  715. else if ($order == "titledesc")
  716. arsort($newstories);
  717. else
  718. asort($newstories);
  719. foreach ($newstories as $id=>$n) {
  720. $newstories[$id] = $this->stories[$id];
  721. }
  722. $this->stories = $newstories;
  723. $this->setField("stories",array_keys($newstories));
  724. }
  725. }