PageRenderTime 141ms CodeModel.GetById 1ms RepoModel.GetById 1ms app.codeStats 1ms

/export/DomitSiteExporter.class.php

https://github.com/adamfranco/segue-1.x
PHP | 1013 lines | 642 code | 175 blank | 196 comment | 95 complexity | 0a83fbbe1fb30c96b2517a1316bac89e MD5 | raw file
  1. <?
  2. require_once(dirname(__FILE__).'/SiteExporter.class.php');
  3. require_once(dirname(__FILE__).'/../objects/discussion.inc.php');
  4. require_once(dirname(__FILE__).'/../dbwrapper.inc.php');
  5. require_once(dirname(__FILE__).'/../functions.inc.php');
  6. require_once(dirname(__FILE__).'/../objects/slot.inc.php');
  7. require_once(dirname(__FILE__).'/../objects/segue.inc.php');
  8. require_once(dirname(__FILE__).'/../objects/site.inc.php');
  9. require_once(dirname(__FILE__).'/../objects/section.inc.php');
  10. require_once(dirname(__FILE__).'/../objects/page.inc.php');
  11. require_once(dirname(__FILE__).'/../objects/story.inc.php');
  12. require_once(dirname(__FILE__).'/../permissions.inc.php');
  13. /**
  14. * This class exports a Segue Site to a string in a specified format.
  15. *
  16. * @author Adam Franco
  17. */
  18. class DomitSiteExporter {
  19. /**
  20. * The current DOMIT document
  21. */
  22. var $_document;
  23. function DomitSiteExporter() {
  24. }
  25. /**
  26. * Exports a site to XML
  27. *
  28. * @param object Site The site to export.
  29. *
  30. * @return string The resulting text.
  31. */
  32. function export(& $site) {
  33. $this->_document =& new DOMIT_Document();
  34. $this->_document->xmlDeclaration = '<?xml version="1.0" encoding="UTF-8" '.'?'.'>';
  35. $doctype = "<!DOCTYPE site [";
  36. $doctype .= "\n\t<!ELEMENT site (title,history,(activation?),(permissions?),header,footer,(theme?),(media?),(section|navlink)*)>";
  37. $doctype .= "\n\t<!ATTLIST site id CDATA #REQUIRED owner CDATA #REQUIRED type (system|class|personal|other) #REQUIRED>";
  38. $doctype .= "\n\t<!ELEMENT section (title,history,(activation?),(permissions?),(page|navlink|heading|divider)*)>";
  39. $doctype .= "\n\t<!ELEMENT page (title,history,(activation?),(permissions?),(story|link|image|file)*)>";
  40. $doctype .= "\n\t<!ATTLIST page story_order (custom|addeddesc|addedasc|editeddesc|editedasc|author|editor|category|titleasc|titledesc) #REQUIRED horizontal_rule (TRUE|FALSE) #REQUIRED show_creator (TRUE|FALSE) #REQUIRED show_date (TRUE|FALSE) #REQUIRED archiving CDATA #REQUIRED>";
  41. $doctype .= "\n\t<!ELEMENT story (title,history,(activation?),(permissions?),shorttext,(longtext?),(category?),(discussion?))>";
  42. $doctype .= "\n\t<!ELEMENT navlink (title,history,(activation?),(permissions?),url)>";
  43. $doctype .= "\n\t<!ELEMENT heading (title,history,(activation?),(permissions?))>";
  44. $doctype .= "\n\t<!ELEMENT divider (history,(activation?),(permissions?))>";
  45. $doctype .= "\n\t<!ELEMENT link (title,history,(activation?),(permissions?),description,url,(category?),(discussion?))>";
  46. $doctype .= "\n\t<!ELEMENT image (title,history,(activation?),(permissions?),description,(filename|url),(category?),(discussion?))>";
  47. $doctype .= "\n\t<!ELEMENT file (title,history,(activation?),(permissions?),description,(filename|url),(category?),(discussion?))>";
  48. $doctype .= "\n\t<!ELEMENT discussion (discussion_node*)>";
  49. $doctype .= "\n\t<!ATTLIST discussion email_owner (TRUE|FALSE) #REQUIRED show_authors (TRUE|FALSE) #REQUIRED show_others_posts (TRUE|FALSE) #REQUIRED>";
  50. $doctype .= "\n\t<!ELEMENT discussion_node (creator,created_time,title,text,rating?,filename?,(discussion_node*))>";
  51. $doctype .= "\n\t<!ELEMENT media (media_file*)>";
  52. $doctype .= "\n\t<!ELEMENT media_file (creator,last_editor,last_edited_time,filename,type)>";
  53. $doctype .= "\n\t<!ELEMENT type (#PCDATA)>";
  54. $doctype .= "\n\t<!ELEMENT theme (name,color_scheme?,background_color?,border_style?,border_color?,text_color?,link_color?,navigation_arrangement?,navigation_width?,section_nav_size?,page_nav_size?)>";
  55. $doctype .= "\n\t<!ELEMENT name (#PCDATA)>";
  56. $doctype .= "\n\t<!ELEMENT color_scheme (#PCDATA)>";
  57. $doctype .= "\n\t<!ELEMENT background_color (#PCDATA)>";
  58. $doctype .= "\n\t<!ELEMENT border_style (#PCDATA)>";
  59. $doctype .= "\n\t<!ELEMENT border_color (#PCDATA)>";
  60. $doctype .= "\n\t<!ELEMENT text_color (#PCDATA)>";
  61. $doctype .= "\n\t<!ELEMENT link_color (#PCDATA)>";
  62. $doctype .= "\n\t<!ELEMENT navigation_arrangement (#PCDATA)>";
  63. $doctype .= "\n\t<!ELEMENT navigation_width (#PCDATA)>";
  64. $doctype .= "\n\t<!ELEMENT section_nav_size (#PCDATA)>";
  65. $doctype .= "\n\t<!ELEMENT page_nav_size (#PCDATA)>";
  66. $doctype .= "\n\t<!ELEMENT history (creator,created_time,last_editor,last_edited_time)>";
  67. $doctype .= "\n\t<!ELEMENT created_time (#PCDATA)>";
  68. $doctype .= "\n\t<!ELEMENT last_edited_time (#PCDATA)>";
  69. $doctype .= "\n\t<!ELEMENT creator (#PCDATA)>";
  70. $doctype .= "\n\t<!ELEMENT last_editor (#PCDATA)>";
  71. $doctype .= "\n\t<!ELEMENT activation ((manual_activiation)?,(activate_date)?,(deactivate_date)?)>";
  72. $doctype .= "\n\t<!ELEMENT manual_activiation (#PCDATA)>";
  73. $doctype .= "\n\t<!ELEMENT activate_date (#PCDATA)>";
  74. $doctype .= "\n\t<!ELEMENT deactivate_date (#PCDATA)>";
  75. $doctype .= "\n\t<!ELEMENT permissions ((locked?),(view_permission?),(add_permission?),(edit_permission?),(delete_permission?),(discuss_permission?))>";
  76. $doctype .= "\n\t<!ELEMENT locked EMPTY>";
  77. $doctype .= "\n\t<!ELEMENT view_permission (agent*)>";
  78. $doctype .= "\n\t<!ELEMENT add_permission (agent*)>";
  79. $doctype .= "\n\t<!ELEMENT edit_permission (agent*)>";
  80. $doctype .= "\n\t<!ELEMENT delete_permission (agent*)>";
  81. $doctype .= "\n\t<!ELEMENT discuss_permission (agent*)>";
  82. $doctype .= "\n\t<!ELEMENT agent (#PCDATA)>";
  83. $doctype .= "\n\t<!ELEMENT category (#PCDATA)>";
  84. $doctype .= "\n\t<!ELEMENT title (#PCDATA)>";
  85. $doctype .= "\n\t<!ELEMENT text (#PCDATA)>";
  86. $doctype .= "\n\t<!ELEMENT shorttext (#PCDATA)>";
  87. $doctype .= "\n\t<!ATTLIST shorttext text_type (text|html) #REQUIRED>";
  88. $doctype .= "\n\t<!ELEMENT longtext (#PCDATA)>";
  89. $doctype .= "\n\t<!ELEMENT filename (#PCDATA)>";
  90. $doctype .= "\n\t<!ELEMENT rating (#PCDATA)>";
  91. $doctype .= "\n\t<!ELEMENT url (#PCDATA)>";
  92. $doctype .= "\n\t<!ELEMENT description (#PCDATA)>";
  93. $doctype .= "\n\t<!ELEMENT header (#PCDATA)>";
  94. $doctype .= "\n\t<!ELEMENT footer (#PCDATA)>";
  95. $doctype .= "\n]>";
  96. $this->_document->doctype = $doctype;
  97. $this->addSite($site);
  98. return $this->_document->toNormalizedString();
  99. // return $this->_document->toString();
  100. }
  101. function saveXML($fileName) {
  102. return $this->_document->saveXML($fileName);
  103. } //saveXML
  104. /**
  105. * Adds a site to the buffer.
  106. *
  107. * @param object site $site The site to add.
  108. * @param integer $indent The indent level of the object
  109. */
  110. function addSite(& $site) {
  111. // Add flags for when to add permissions rows
  112. $site->spiderDownLockedFlag();
  113. $siteElement =& $this->_document->createElement('site');
  114. $this->_document->appendChild($siteElement);
  115. // site id and type
  116. $siteElement->setAttribute('owner', slot::getOwner($site->getField('name')));
  117. $siteElement->setAttribute('type', $site->getField('type'));
  118. // Media quota
  119. $slot = new Slot($site->getField('name'));
  120. $quota = $slot->getField('quota');
  121. if ($quota)
  122. $siteElement->setAttribute('mediaQuota', $quota);
  123. $this->addCommonProporties($site, $siteElement);
  124. // use the slot-name for backwards-compatability
  125. $siteElement->setAttribute('id', $site->getField('name'));
  126. // header
  127. $header =& $this->_document->createElement('header');
  128. $siteElement->appendChild($header);
  129. $header->appendChild($this->_document->createTextNode(htmlspecialchars($site->getField('header'))));
  130. // footer
  131. $footer =& $this->_document->createElement('footer');
  132. $siteElement->appendChild($footer);
  133. $footer->appendChild($this->_document->createTextNode(htmlspecialchars($site->getField('footer'))));
  134. // Theme
  135. $this->addTheme($site, $siteElement);
  136. // Media
  137. $this->addMedia($site, $siteElement);
  138. // sections
  139. foreach ($site->sections as $key => $val) {
  140. if ($site->sections[$key]->getField('type') == 'link')
  141. $this->addSectionNavLink($site->sections[$key], $siteElement);
  142. else if ($site->sections[$key]->getField('type') == 'heading')
  143. $this->addHeading($site->sections[$key], $siteElement);
  144. else if ($site->sections[$key]->getField('type') == 'divider')
  145. $this->addDivider($site->sections[$key], $siteElement);
  146. else
  147. $this->addSection($site->sections[$key], $siteElement);
  148. }
  149. }
  150. /**
  151. * Adds a section to the buffer.
  152. *
  153. * @param object section $section The section to add.
  154. * @param integer $indent The indent level of the object
  155. */
  156. function addSection(& $section, & $siteElement) {
  157. $sectionElement =& $this->_document->createElement('section');
  158. $siteElement->appendChild($sectionElement);
  159. $this->addCommonProporties($section, $sectionElement);
  160. foreach ($section->pages as $key => $val) {
  161. if ($section->pages[$key]->getField('type') == 'link')
  162. $this->addPageNavLink($section->pages[$key], $sectionElement);
  163. else if ($section->pages[$key]->getField('type') == 'heading')
  164. $this->addHeading($section->pages[$key], $sectionElement);
  165. else if ($section->pages[$key]->getField('type') == 'divider')
  166. $this->addDivider($section->pages[$key], $sectionElement);
  167. else if ($section->pages[$key]->getField('type') == 'content')
  168. $this->addPageContent($section->pages[$key], $sectionElement);
  169. else if ($section->pages[$key]->getField('type') == 'rss')
  170. $this->addPageRSS($section->pages[$key], $sectionElement);
  171. else if ($section->pages[$key]->getField('type') == 'participants')
  172. $this->addParticipantList($section->pages[$key], $sectionElement);
  173. else if ($section->pages[$key]->getField('type') == 'tags')
  174. $this->addCategoryList($section->pages[$key], $sectionElement);
  175. else
  176. $this->addPage($section->pages[$key], $sectionElement);
  177. }
  178. }
  179. /**
  180. * Adds a page to the buffer.
  181. *
  182. * @param object page $page The page to add.
  183. * @param integer $indent The indent level of the object
  184. */
  185. function addPage(& $page, & $sectionElement) {
  186. $pageElement =& $this->_document->createElement('page');
  187. $sectionElement->appendChild($pageElement);
  188. $this->addCommonProporties($page, $pageElement);
  189. // Display options
  190. if (!$order = $page->getField('storyorder'))
  191. $order = "custom";
  192. $pageElement->setAttribute('story_order', $order);
  193. $pageElement->setAttribute('horizontal_rule', (($page->getField('showhr'))?"TRUE":"FALSE"));
  194. $pageElement->setAttribute('show_creator', (($page->getField('showcreator'))?"TRUE":"FALSE"));
  195. $pageElement->setAttribute('show_editor', (($page->getField('showeditor'))?"TRUE":"FALSE"));
  196. $pageElement->setAttribute('show_versions', (($page->getField('showversions'))?"TRUE":"FALSE"));
  197. $pageElement->setAttribute('show_date', (($page->getField('showdate'))?"TRUE":"FALSE"));
  198. if (!$archiving = $page->getField('archiveby'))
  199. $archiving = "none";
  200. $pageElement->setAttribute('archiving', $archiving);
  201. if ($page->getField('location') == 'right')
  202. $pageElement->setAttribute('location', 'right');
  203. else
  204. $pageElement->setAttribute('location', 'left');
  205. $pageElement->setAttribute('type', $page->getField('type'));
  206. // if (strlen($page->getField('url')))
  207. // $pageElement->appendChild($this->_document->createElement('url'))->appendChild(
  208. // $this->_document->createCDATASection($page->getField('url')));
  209. foreach ($page->stories as $key => $val) {
  210. if ($page->stories[$key]->getField('type') == 'link')
  211. $this->addLink($page->stories[$key], $pageElement);
  212. else if ($page->stories[$key]->getField('type') == 'rss')
  213. $this->addRss($page->stories[$key], $pageElement);
  214. else if ($page->stories[$key]->getField('type') == 'file')
  215. $this->addFile($page->stories[$key], $pageElement);
  216. else if ($page->stories[$key]->getField('type') == 'image')
  217. $this->addImage($page->stories[$key], $pageElement);
  218. else
  219. $this->addStory($page->stories[$key], $pageElement);
  220. }
  221. }
  222. /**
  223. * Adds a story to the buffer.
  224. *
  225. * @param object story $story The story to add.
  226. * @param integer $indent The indent level of the object
  227. */
  228. function addStory(& $story, & $pageElement) {
  229. $storyElement =& $this->_document->createElement('story');
  230. $pageElement->appendChild($storyElement);
  231. $this->addCommonProporties($story, $storyElement);
  232. if ($story->getField('texttype') == "text")
  233. $texttype = "text";
  234. else
  235. $texttype = "html";
  236. if ($story->getField('shorttext')) {
  237. $shorttext =& $this->_document->createElement('shorttext');
  238. $storyElement->appendChild($shorttext);
  239. $shorttext->appendChild($this->_document->createTextNode(htmlspecialchars(convertInteralLinksToTags($story->owning_site, $story->getField('shorttext')))));
  240. $shorttext->setAttribute('text_type', $texttype);
  241. }
  242. if ($story->getField('longertext')) {
  243. $longertext =& $this->_document->createElement('longertext');
  244. $storyElement->appendChild($longertext);
  245. $longertext->appendChild($this->_document->createTextNode(htmlspecialchars(convertInteralLinksToTags($story->owning_site, $story->getField('longertext')))));
  246. $longertext->setAttribute('text_type', $texttype);
  247. }
  248. $this->addStoryProporties($story, $storyElement);
  249. }
  250. /**
  251. * Adds a link to the buffer.
  252. *
  253. * @param object link $link The link to add.
  254. * @param integer $indent The indent level of the object
  255. */
  256. function addSectionNavLink(& $link, & $parentElement) {
  257. $linkElement =& $this->_document->createElement('navlink');
  258. $parentElement->appendChild($linkElement);
  259. $this->addCommonProporties($link, $linkElement);
  260. // url
  261. $url =& $this->_document->createElement('url');
  262. $linkElement->appendChild($url);
  263. $url->appendChild($this->_document->createTextNode(htmlspecialchars($link->getField('url'))));
  264. }
  265. /**
  266. * Adds a link to the buffer.
  267. *
  268. * @param object link $link The link to add.
  269. * @param integer $indent The indent level of the object
  270. */
  271. function addPageNavLink(& $link, & $parentElement) {
  272. $linkElement =& $this->_document->createElement('navlink');
  273. $parentElement->appendChild($linkElement);
  274. $this->addCommonProporties($link, $linkElement);
  275. // url
  276. $url =& $this->_document->createElement('url');
  277. $linkElement->appendChild($url);
  278. $url->appendChild($this->_document->createTextNode(htmlspecialchars($link->getField('url'))));
  279. if ($link->getField('location') == 'right')
  280. $linkElement->setAttribute('location', 'right');
  281. else
  282. $linkElement->setAttribute('location', 'left');
  283. }
  284. /**
  285. * Adds an RSS page block to the buffer.
  286. *
  287. * @param object link $link The link to add.
  288. * @param integer $indent The indent level of the object
  289. */
  290. function addPageRSS(& $link, & $parentElement) {
  291. $linkElement =& $this->_document->createElement('pageRSS');
  292. $parentElement->appendChild($linkElement);
  293. $this->addCommonProporties($link, $linkElement);
  294. // url
  295. $url =& $this->_document->createElement('url');
  296. $linkElement->appendChild($url);
  297. $url->appendChild($this->_document->createTextNode(htmlspecialchars($link->getField('url'))));
  298. $url->setAttribute('maxItems', $link->getField("archiveby"));
  299. if ($link->getField('location') == 'right')
  300. $linkElement->setAttribute('location', 'right');
  301. else
  302. $linkElement->setAttribute('location', 'left');
  303. }
  304. /**
  305. * Adds a heading to the buffer.
  306. *
  307. * @param object heading $heading The heading to add.
  308. * @param integer $indent The indent level of the object
  309. */
  310. function addHeading(& $heading, & $parentElement) {
  311. $headingElement =& $this->_document->createElement('heading');
  312. $parentElement->appendChild($headingElement);
  313. $this->addCommonProporties($heading, $headingElement);
  314. if ($heading->getField('location') == 'right')
  315. $headingElement->setAttribute('location', 'right');
  316. else
  317. $headingElement->setAttribute('location', 'left');
  318. }
  319. /**
  320. * Adds a page content to the buffer.
  321. *
  322. * @param object page $page The pageContent to add.
  323. * @param integer $indent The indent level of the object
  324. */
  325. function addPageContent(& $page, & $parentElement) {
  326. $element = $parentElement->appendChild(
  327. $this->_document->createElement('pageContent'));
  328. $this->addCommonProporties($page, $element);
  329. $textElement = $element->appendChild($this->_document->createElement('text'));
  330. $textElement->appendChild(
  331. $this->_document->createCDATASection(urldecode($page->getField('text'))));
  332. if ($page->getField('location') == 'right')
  333. $element->setAttribute('location', 'right');
  334. else
  335. $element->setAttribute('location', 'left');
  336. }
  337. /**
  338. * Adds a divider to the buffer.
  339. *
  340. * @param object divider $divider The divider to add.
  341. * @param integer $indent The indent level of the object
  342. */
  343. function addDivider(& $divider, & $parentElement) {
  344. $dividerElement =& $this->_document->createElement('divider');
  345. $parentElement->appendChild($dividerElement);
  346. // history
  347. $history =& $this->_document->createElement('history');
  348. $dividerElement->appendChild($history);
  349. $this->gethistory($divider, $history);
  350. // permissions
  351. $permissions =& $this->_document->createElement('permissions');
  352. $hasPerms = $this->getPermissions($divider, $permissions);
  353. if ($hasPerms)
  354. $dividerElement->appendChild($permissions);
  355. if ($divider->getField('location') == 'right')
  356. $dividerElement->setAttribute('location', 'right');
  357. else
  358. $dividerElement->setAttribute('location', 'left');
  359. }
  360. /**
  361. * Adds a participant list to the buffer.
  362. *
  363. * @param object $participantList
  364. * @param integer $indent The indent level of the object
  365. */
  366. function addParticipantList(& $participantList, & $parentElement) {
  367. $element =& $this->_document->createElement('participantList');
  368. $parentElement->appendChild($element);
  369. $this->addCommonProporties($participantList, $element);
  370. if ($participantList->getField('location') == 'right')
  371. $element->setAttribute('location', 'right');
  372. else
  373. $element->setAttribute('location', 'left');
  374. }
  375. /**
  376. * Adds a category list to the buffer.
  377. *
  378. * @param object $categoryList
  379. * @param integer $indent The indent level of the object
  380. */
  381. function addCategoryList(& $categoryList, & $parentElement) {
  382. $element =& $this->_document->createElement('categoryList');
  383. $parentElement->appendChild($element);
  384. $this->addCommonProporties($categoryList, $element);
  385. if ($categoryList->getField('location') == 'right')
  386. $element->setAttribute('location', 'right');
  387. else
  388. $element->setAttribute('location', 'left');
  389. }
  390. /**
  391. * Adds a file to the buffer.
  392. *
  393. * @param object story $story The file to add.
  394. * @param integer $indent The indent level of the object
  395. */
  396. function addFile(& $story, & $pageElement) {
  397. $storyElement =& $this->_document->createElement('file');
  398. $pageElement->appendChild($storyElement);
  399. $this->addCommonProporties($story, $storyElement);
  400. // description
  401. $shorttext =& $this->_document->createElement('description');
  402. $storyElement->appendChild($shorttext);
  403. $shorttext->appendChild($this->_document->createTextNode(htmlspecialchars($story->getField('shorttext'))));
  404. // file
  405. $longertext =& $this->_document->createElement('filename');
  406. $storyElement->appendChild($longertext);
  407. $filename = addslashes(urldecode(db_get_value("media","media_tag","media_id=".$story->getField("longertext"))));
  408. $longertext->appendChild($this->_document->createTextNode(htmlspecialchars($filename)));
  409. $this->addStoryProporties($story, $storyElement);
  410. }
  411. /**
  412. * Adds a image to the buffer.
  413. *
  414. * @param object story $story The image to add.
  415. * @param integer $indent The indent level of the object
  416. */
  417. function addImage(& $story, & $pageElement) {
  418. $storyElement =& $this->_document->createElement('image');
  419. $pageElement->appendChild($storyElement);
  420. $this->addCommonProporties($story, $storyElement);
  421. // description
  422. $shorttext =& $this->_document->createElement('description');
  423. $storyElement->appendChild($shorttext);
  424. $shorttext->appendChild($this->_document->createTextNode(htmlspecialchars($story->getField('shorttext'))));
  425. // file
  426. $longertext =& $this->_document->createElement('filename');
  427. $storyElement->appendChild($longertext);
  428. $filename = addslashes(urldecode(db_get_value("media","media_tag","media_id=".$story->getField("longertext"))));
  429. $longertext->appendChild($this->_document->createTextNode(htmlspecialchars($filename)));
  430. $this->addStoryProporties($story, $storyElement);
  431. }
  432. /**
  433. * Adds a link to the buffer.
  434. *
  435. * @param object story $story The link to add.
  436. * @param integer $indent The indent level of the object
  437. */
  438. function addLink(& $story, & $pageElement) {
  439. $storyElement =& $this->_document->createElement('link');
  440. $pageElement->appendChild($storyElement);
  441. $this->addCommonProporties($story, $storyElement);
  442. // description
  443. $shorttext =& $this->_document->createElement('description');
  444. $storyElement->appendChild($shorttext);
  445. $shorttext->appendChild($this->_document->createTextNode(htmlspecialchars($story->getField('shorttext'))));
  446. // file
  447. $longertext =& $this->_document->createElement('url');
  448. $storyElement->appendChild($longertext);
  449. $longertext->appendChild($this->_document->createTextNode(htmlspecialchars($story->getField("url"))));
  450. $this->addStoryProporties($story, $storyElement);
  451. }
  452. /**
  453. * Add an Rss feed to the buffer
  454. *
  455. * @param object story $story The link to add.
  456. * @param object DOMITElement $pageElement
  457. * @return void
  458. * @access public
  459. * @since 7/9/08
  460. */
  461. function addRss(& $story, & $pageElement) {
  462. $storyElement =& $this->_document->createElement('rss');
  463. $pageElement->appendChild($storyElement);
  464. $this->addCommonProporties($story, $storyElement);
  465. // Get the values
  466. $url = $story->getField('url');
  467. $maxItems = $story->getField('shorttext');
  468. $extendedMaxItems = $story->getField('longertext');
  469. $urlElement =& $storyElement->appendChild($this->_document->createElement('url'));
  470. $urlElement->appendChild($this->_document->createTextNode(str_replace('&', '&amp;', $url)));
  471. $urlElement->setAttribute('maxItems', $maxItems);
  472. $urlElement->setAttribute('extendedMaxItems', $extendedMaxItems);
  473. $this->addStoryProporties($story, $storyElement);
  474. }
  475. function getHistory(& $obj, &$historyElement) {
  476. // Creator
  477. $creator =& $this->_document->createElement('creator');
  478. $historyElement->appendChild($creator);
  479. $creator->appendChild($this->_document->createTextNode($obj->getField('addedby')));
  480. // Created timestamp
  481. $created_time =& $this->_document->createElement('created_time');
  482. $historyElement->appendChild($created_time);
  483. $created_time->appendChild($this->_document->createTextNode($obj->getField('addedtimestamp')));
  484. // Last Editor
  485. $last_editor =& $this->_document->createElement('last_editor');
  486. $historyElement->appendChild($last_editor);
  487. $last_editor->appendChild($this->_document->createTextNode($obj->getField('editedby')));
  488. // Last Edited timestamp
  489. $edited_time =& $this->_document->createElement('last_edited_time');
  490. $historyElement->appendChild($edited_time);
  491. $edited_time->appendChild($this->_document->createTextNode($obj->getField('editedtimestamp')));
  492. $versions = $this->getVersions($obj);
  493. if ($versions)
  494. $historyElement->appendChild($versions);
  495. }
  496. /**
  497. * Answer a list of version or null if not supported
  498. *
  499. * @param object $obj
  500. * @return mixed DOMITElement or null
  501. * @access protected
  502. * @since 2/13/08
  503. */
  504. function getVersions ($obj) {
  505. if (strtolower(get_class($obj)) != 'story')
  506. return null;
  507. $element = $this->_document->createElement('versions');
  508. $versions = get_versions($obj->id);
  509. foreach ($versions as $version) {
  510. $element->appendChild($this->getVersion($version, $obj->getField('type'), $obj->getField('texttype'), $obj));
  511. }
  512. return $element;
  513. }
  514. /**
  515. * Answer an element that represents a version of a story.
  516. *
  517. * @param array $version
  518. * @param string $storyType One of link, rss, file, image, text
  519. * @param optional string $textType text or html
  520. * @return DOMITElement
  521. * @access protected
  522. * @since 2/13/08
  523. */
  524. function getVersion ($version, $storyType, $textType = 'html') {
  525. $element = $this->_document->createElement('version');
  526. $element->setAttribute('id', $version['version_id']);
  527. $element->setAttribute('number', $version['version_order']);
  528. $element->setAttribute('time_stamp', $version['create_time_stamp']);
  529. $element->setAttribute('agent_id', $version['author_uname']);
  530. $commentElement = $element->appendChild($this->_document->createElement('comment'));
  531. $commentElement->appendChild(
  532. $this->_document->createCDATASection($version['version_comments']));
  533. switch ($storyType) {
  534. case 'link':
  535. $field1 = 'description';
  536. $field2 = 'url';
  537. $value1 = urldecode($version['version_text_short']);
  538. $value2 = urldecode($version['version_text_long']);
  539. break;
  540. case 'rss':
  541. // RSS url info is not in the version, so just return it empty
  542. return $element;
  543. case 'file':
  544. case 'image':
  545. $field1 = 'description';
  546. $field2 = 'filename';
  547. $value1 = urldecode($version['version_text_short']);
  548. $filename = addslashes(urldecode(db_get_value("media","media_tag","media_id='".addslashes(urldecode($version['version_text_long']))."'")));
  549. $value2 = htmlspecialchars($filename);
  550. break;
  551. default:
  552. $field1 = 'shorttext';
  553. $field2 = 'longertext';
  554. $value1 = urldecode($version['version_text_short']);
  555. $value2 = urldecode($version['version_text_long']);
  556. }
  557. $shortText = $element->appendChild($this->_document->createElement($field1));
  558. $shortText->appendChild($this->_document->createCDATASection($value1));
  559. $shortText->setAttribute('text_type', $textType);
  560. $shortText = $element->appendChild($this->_document->createElement($field2));
  561. $shortText->appendChild($this->_document->createCDATASection($value2));
  562. $shortText->setAttribute('text_type', $textType);
  563. return $element;
  564. }
  565. function getPermissions(& $obj, &$permissionsElement) {
  566. // get all the editors
  567. $obj->buildPermissionsArray();
  568. $permissions = $obj->getPermissions();
  569. // print "\npermissions:";
  570. // print_r($permissions);
  571. if (get_class($obj) != 'site' && $isLocked = $obj->getField('locked')) {
  572. $locked =& $this->_document->createElement('locked');
  573. $permissionsElement->appendChild($locked);
  574. }
  575. $hasView = $this->addPermissions($obj, $permissionsElement, 'view', $permissions);
  576. $hasAdd = $this->addPermissions($obj, $permissionsElement, 'add', $permissions);
  577. $hasEdit = $this->addPermissions($obj, $permissionsElement, 'edit', $permissions);
  578. $hasDelete = $this->addPermissions($obj, $permissionsElement, 'delete', $permissions);
  579. $hasDiscuss = $this->addPermissions($obj, $permissionsElement, 'discuss', $permissions);
  580. if ($isLocked | $hasView | $hasAdd | $hasEdit | $hasDelete | $hasDiscuss)
  581. $hasAny = TRUE;
  582. else
  583. $hasAny = FALSE;
  584. return $hasAny;
  585. }
  586. function hasPermission($permissionArray, $agent, $type) {
  587. $permTypes = array('add'=>0, 'edit'=>1, 'delete'=>2, 'view'=>3, 'discuss'=>4);
  588. return $permissionArray[$agent][$permTypes[$type]];
  589. }
  590. function addPermissions(& $obj, & $permissionsElement, $type, $permissionsArray) {
  591. //add agents/groups of type
  592. $hasPerms = FALSE;
  593. $element =& $this->_document->createElement($type.'_permission');
  594. foreach ($permissionsArray as $editorName => $array) {
  595. // if they have permission here, create an entry for them.
  596. if ($this->hasPermission($permissionsArray, $editorName, $type) && !$obj->getField("l%$editorName%".$type)) {
  597. $agent =& $this->_document->createElement('agent');
  598. $agent->appendChild($this->_document->createTextNode($editorName));
  599. $element->appendChild($agent);
  600. $hasPerms = TRUE;
  601. }
  602. }
  603. if ($hasPerms)
  604. $permissionsElement->appendChild($element);
  605. return $hasPerms;
  606. }
  607. function getActivation(& $obj, & $activationElement) {
  608. $hasActivation = FALSE;
  609. if (get_class($obj) != 'story' && !$obj->getField('active')) {
  610. $active =& $this->_document->createElement('manual_activiation');
  611. $active->appendChild($this->_document->createTextNode('INACTIVE'));
  612. $activationElement->appendChild($active);
  613. $hasActivation = TRUE;
  614. }
  615. if ($obj->getField('activatedate') != '0000-00-00') {
  616. $activate_date =& $this->_document->createElement('activate_date');
  617. $activate_date->appendChild($this->_document->createTextNode($obj->getField('activatedate')));
  618. $activationElement->appendChild($activate_date);
  619. $hasActivation = TRUE;
  620. }
  621. if ($obj->getField('deactivatedate') != '0000-00-00') {
  622. $deactivate_date =& $this->_document->createElement('deactivate_date');
  623. $deactivate_date->appendChild($this->_document->createTextNode($obj->getField('deactivatedate')));
  624. $activationElement->appendChild($deactivate_date);
  625. $hasActivation = TRUE;
  626. }
  627. return $hasActivation;
  628. }
  629. function addStoryProporties (& $story, & $storyElement) {
  630. // category
  631. // if ($story->getField('category')) {
  632. // $category =& $this->_document->createElement('category');
  633. // $storyElement->appendChild($category);
  634. // $category->appendChild($this->_document->createTextNode(htmlspecialchars($story->getField('category'))));
  635. // }
  636. // categories
  637. $tags = get_record_tags_info($story->getField('id'));
  638. $tagsElement =& $this->_document->createElement('tags');
  639. $storyElement->appendChild($tagsElement);
  640. if (count($tags) > 0) {
  641. foreach($tags as $tag => $infoArray) {
  642. $tagElement =& $this->_document->createElement('tag');
  643. $tag_value = $tag;
  644. $tagsElement->appendChild($tagElement);
  645. $tagElement->appendChild($this->_document->createTextNode(htmlspecialchars($tag_value)));
  646. $tagElement->setAttribute('agent_id', $infoArray['agent_id']);
  647. $tagElement->setAttribute('create_date', $infoArray['time_stamp']);
  648. }
  649. }
  650. // discussions
  651. if ($story->getField('discuss')) {
  652. $discussion =& $this->_document->createElement('discussion');
  653. $storyElement->appendChild($discussion);
  654. $emailOwner = (($story->getField('discussemail'))?"TRUE":"FALSE");
  655. $discussion->setAttribute('email_owner', $emailOwner);
  656. $show_authors = (($story->getField('discussauthor') == 1)?"TRUE":"FALSE");
  657. $discussion->setAttribute('show_authors', $show_authors);
  658. $show_others_posts = (($story->getField('discussdisplay') == 1)?"TRUE":"FALSE");
  659. $discussion->setAttribute('show_others_posts', $show_others_posts);
  660. $discussionObj = & new discussion( $story);
  661. $discussionObj->_fetchchildren();
  662. while ($node =& $discussionObj->getNext()) {
  663. $this->addDiscussionNode($node, $discussion);
  664. }
  665. }
  666. }
  667. function addCommonProporties (& $partObj, & $element) {
  668. if (isset($partObj->id))
  669. $element->setAttribute('id', $partObj->id);
  670. // title
  671. $title =& $this->_document->createElement('title');
  672. $element->appendChild($title);
  673. $title->appendChild($this->_document->createTextNode(htmlspecialchars($partObj->getField('title'))));
  674. // history
  675. $history =& $this->_document->createElement('history');
  676. $element->appendChild($history);
  677. $this->gethistory($partObj, $history);
  678. // activation
  679. $activation =& $this->_document->createElement('activation');
  680. $hasActivation = $this->getActivation($partObj, $activation);
  681. if ($hasActivation)
  682. $element->appendChild($activation);
  683. // permissions
  684. $permissions =& $this->_document->createElement('permissions');
  685. $hasPerms =& $this->getPermissions($partObj, $permissions);
  686. if ($hasPerms)
  687. $element->appendChild($permissions);
  688. }
  689. function addDiscussionNode(& $node, & $parentElement) {
  690. $discussionNode =& $this->_document->createElement('discussion_node');
  691. $parentElement->appendChild($discussionNode);
  692. if (isset($node->id))
  693. $discussionNode->setAttribute('id', $node->id);
  694. // Add the creator, title, timestamp, and text.
  695. // creator
  696. $creator =& $this->_document->createElement('creator');
  697. $discussionNode->appendChild($creator);
  698. $creator->appendChild($this->_document->createTextNode(htmlspecialchars($node->authoruname)));
  699. // created_time
  700. $created_time =& $this->_document->createElement('created_time');
  701. $discussionNode->appendChild($created_time);
  702. $created_time->appendChild($this->_document->createTextNode(htmlspecialchars($node->tstamp)));
  703. // title
  704. $title =& $this->_document->createElement('title');
  705. $discussionNode->appendChild($title);
  706. $title->appendChild($this->_document->createTextNode(htmlspecialchars($node->subject)));
  707. // text
  708. $text =& $this->_document->createElement('text');
  709. $discussionNode->appendChild($text);
  710. $text->appendChild($this->_document->createTextNode(htmlspecialchars($node->content)));
  711. // rating
  712. $rating =& $this->_document->createElement('rating');
  713. $discussionNode->appendChild($rating);
  714. $rating->appendChild($this->_document->createTextNode(htmlspecialchars($node->rating)));
  715. // filename
  716. $filename =& $this->_document->createElement('filename');
  717. $discussionNode->appendChild($filename);
  718. $filename->appendChild($this->_document->createTextNode($node->media_tag));
  719. // If this node has children, add them.
  720. $node->_fetchchildren();
  721. foreach ($node->children as $key => $val) {
  722. $this->addDiscussionNode($node->children[$key], $discussionNode);
  723. }
  724. }
  725. function addMedia(& $site, & $siteElement) {
  726. $query = "
  727. SELECT
  728. media_id AS id,
  729. media_tag AS filename,
  730. media_updated_tstamp AS last_edited_time,
  731. media_type AS type,
  732. creator.user_uname AS creator,
  733. editor.user_uname AS last_editor
  734. FROM
  735. media
  736. INNER JOIN
  737. slot
  738. ON media.FK_site = slot.FK_site
  739. INNER JOIN
  740. user AS creator
  741. ON media.FK_createdby = creator.user_id
  742. INNER JOIN
  743. user AS editor
  744. ON media.FK_updatedby = editor.user_id
  745. WHERE
  746. slot_name = '".$site->name."'
  747. AND media_location = 'local'
  748. ";
  749. $r = db_query($query);
  750. if (db_num_rows($r)) {
  751. $mediaElement =& $this->_document->createElement('media');
  752. $siteElement->appendChild($mediaElement);
  753. while ($a = db_fetch_assoc($r)) {
  754. $fileElement =& $this->_document->createElement('media_file');
  755. $mediaElement->appendChild($fileElement);
  756. // Creator
  757. $creatorElement =& $this->_document->createElement('creator');
  758. $fileElement->appendChild($creatorElement);
  759. $creatorElement->appendChild($this->_document->createTextNode(htmlspecialchars($a['creator'])));
  760. // last_editor
  761. $last_editorElement =& $this->_document->createElement('last_editor');
  762. $fileElement->appendChild($last_editorElement);
  763. $last_editorElement->appendChild($this->_document->createTextNode(htmlspecialchars($a['last_editor'])));
  764. // last_edited_time
  765. $last_edited_timeElement =& $this->_document->createElement('last_edited_time');
  766. $fileElement->appendChild($last_edited_timeElement);
  767. $last_edited_timeElement->appendChild($this->_document->createTextNode(htmlspecialchars($a['last_edited_time'])));
  768. // filename
  769. $filenameElement =& $this->_document->createElement('filename');
  770. $fileElement->appendChild($filenameElement);
  771. $filenameElement->appendChild($this->_document->createTextNode(htmlspecialchars($a['filename'])));
  772. // type
  773. $typeElement =& $this->_document->createElement('type');
  774. $fileElement->appendChild($typeElement);
  775. $typeElement->appendChild($this->_document->createTextNode(htmlspecialchars($a['type'])));
  776. // file metadata
  777. $title_whole = & $this->_document->createElement('title_whole');
  778. $fileElement->appendChild($title_whole);
  779. $title_whole_value = addslashes(urldecode(db_get_value("media","title_whole","media_id=".$a['id'])));
  780. $title_whole->appendChild($this->_document->createTextNode(htmlspecialchars($title_whole_value)));
  781. $title_part = & $this->_document->createElement('title_part');
  782. $fileElement->appendChild($title_part);
  783. $title_part_value = addslashes(urldecode(db_get_value("media","title_part","media_id=".$a['id'])));
  784. $title_part->appendChild($this->_document->createTextNode(htmlspecialchars($title_part_value)));
  785. $author = & $this->_document->createElement('author');
  786. $fileElement->appendChild($author);
  787. $author_value = addslashes(urldecode(db_get_value("media","author","media_id=".$a['id'])));
  788. $author->appendChild($this->_document->createTextNode(htmlspecialchars($author_value)));
  789. $pagerange = & $this->_document->createElement('pagerange');
  790. $fileElement->appendChild($pagerange);
  791. $pagerange_value = addslashes(urldecode(db_get_value("media","pagerange","media_id=".$a['id'])));
  792. $pagerange->appendChild($this->_document->createTextNode(htmlspecialchars($pagerange_value)));
  793. $publisher = & $this->_document->createElement('publisher');
  794. $fileElement->appendChild($publisher);
  795. $publisher_value = addslashes(urldecode(db_get_value("media","publisher","media_id=".$a['id'])));
  796. $publisher->appendChild($this->_document->createTextNode(htmlspecialchars($publisher_value)));
  797. $pubyear = & $this->_document->createElement('pubyear');
  798. $fileElement->appendChild($pubyear);
  799. $pubyear_value = addslashes(urldecode(db_get_value("media","pubyear","media_id=".$a['id'])));
  800. $pubyear->appendChild($this->_document->createTextNode(htmlspecialchars($pubyear_value)));
  801. }
  802. }
  803. }
  804. function addTheme(& $site, & $siteElement) {
  805. // If we have a theme add it
  806. if ($site->getField('theme')) {
  807. $themeElement =& $this->_document->createElement('theme');
  808. $siteElement->appendChild($themeElement);
  809. $element =& $this->_document->createElement('name');
  810. $themeElement->appendChild($element);
  811. $element->appendChild($this->_document->createTextNode($site->getField('theme')));
  812. // if we have themesettings, add them
  813. if ($themesettings = $site->getField('themesettings')) {
  814. $settingsArray = unserialize(urldecode($themesettings));
  815. $settingsParts = array(
  816. 'color_scheme' => 'colorscheme',
  817. 'background_color' => 'bgcolor',
  818. 'border_style' => 'borderstyle',
  819. 'border_color' => 'bordercolor',
  820. 'text_color' => 'textcolor',
  821. 'link_color' => 'linkcolor',
  822. 'navigation_arrangement' => 'nav_arrange',
  823. 'site_width' => 'site_width',
  824. 'navigation_width' => 'nav_width',
  825. 'section_nav_size' => 'sectionnav_size',
  826. 'page_nav_size' => 'nav_size'
  827. );
  828. foreach ($settingsParts as $tag => $key) {
  829. if ($settingsArray[$key]) {
  830. $element =& $this->_document->createElement($tag);
  831. $themeElement->appendChild($element);
  832. $element->appendChild($this->_document->createTextNode($settingsArray[$key]));
  833. }
  834. }
  835. }
  836. }
  837. }
  838. }