PageRenderTime 51ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/export/DomitSiteImporter.class.php

https://github.com/adamfranco/segue-1.x
PHP | 952 lines | 897 code | 17 blank | 38 comment | 9 complexity | e5c11d8b81749c64d419a0e5ab0c4c26 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__).'/../objects/ugroup.inc.php');
  13. require_once(dirname(__FILE__).'/../permissions.inc.php');
  14. /**
  15. * This class exports a Segue Site to a string in a specified format.
  16. *
  17. * @author Adam Franco
  18. */
  19. class DomitSiteImporter {
  20. /**
  21. * The current DOMIT document
  22. */
  23. var $_document;
  24. /**
  25. * The source directory for the media.
  26. */
  27. function DomitSiteImporter() {
  28. }
  29. /**
  30. * Imports a site from XML
  31. *
  32. * @param string $xml The xml to import.
  33. *
  34. * @return boolean True on success.
  35. */
  36. function importString($xml, $mediaSource = "", $apacheUser = "", $apacheGroup = "") {
  37. $this->_document =& new DOMIT_Document;
  38. $loaded = $this->_document->parseXML($xml);
  39. if ($loaded) {
  40. $this->_mediaSource = $mediaSource;
  41. $this->_apacheUser = $apacheUser;
  42. $this->_apacheGroup = $apacheGroup;
  43. return $this->createSite();
  44. } else
  45. return FALSE;
  46. }
  47. /**
  48. * Imports a site from an XML file
  49. *
  50. * @param string $xmlFile The xml file path to import.
  51. *
  52. * @return boolean True on success.
  53. */
  54. function importFile($xmlFile, $mediaSource = "", $apacheUser = "", $apacheGroup = "") {
  55. $this->_document =& new DOMIT_Document;
  56. $loaded = $this->_document->loadXML($xmlFile);
  57. if ($loaded) {
  58. $this->_mediaSource = $mediaSource;
  59. $this->_apacheUser = $apacheUser;
  60. $this->_apacheGroup = $apacheGroup;
  61. return $this->createSite();
  62. } else
  63. return FALSE;
  64. }
  65. /**
  66. * Creates a site object in Segue and saves it.
  67. *
  68. * @return boolean True on success.
  69. */
  70. function createSite() {
  71. $siteElement =& $this->_document->documentElement;
  72. global $dbhost, $dbuser, $dbpass, $dbdb, $debug;
  73. $debug=0;
  74. db_connect($dbhost, $dbuser, $dbpass, $dbdb);
  75. // Make sure that we have a valid XML file
  76. if ($siteElement->nodeName == "site" && $siteElement->hasAttribute('id')
  77. && $siteElement->hasAttribute('owner') && $siteElement->hasAttribute('type')) {
  78. // Make sure the site doesn't exist
  79. $query = "
  80. SELECT
  81. site_id
  82. FROM
  83. slot
  84. INNER JOIN
  85. site
  86. ON
  87. fk_site = site_id
  88. WHERE
  89. slot_name = '".$siteElement->getAttribute('id')."'";
  90. $r = db_query($query);
  91. if (db_num_rows($r)) {
  92. print "\nSite '".$siteElement->getAttribute('id')."' exists.";
  93. return FALSE;
  94. }
  95. // Create the site object
  96. $site =& new site ( $siteElement->getAttribute('id') );
  97. /*********************************************************
  98. * Set the owner for the Site
  99. *********************************************************/
  100. // The site is going to be setting its owner field to $_SESSION[aid], so
  101. // lets just set that manually.
  102. $query = "
  103. SELECT
  104. user_id
  105. FROM
  106. user
  107. WHERE
  108. user_uname = '".$siteElement->getAttribute('owner')."'";
  109. $r = db_query($query);
  110. if (!db_num_rows($r)) {
  111. print "\nUser '".$siteElement->getAttribute('owner')."' doesn't exist.";
  112. return FALSE;
  113. }
  114. while ($a = db_fetch_assoc($r)) {
  115. $_SESSION[aid] = $a['user_id'];
  116. }
  117. /*********************************************************
  118. * Add all the editors
  119. *********************************************************/
  120. $editors = array('everyone','institute');
  121. // Editors
  122. $agentList =& $this->_document->getElementsByTagName('agent');
  123. $numAgents = $agentList->getLength();
  124. for ($i=0; $i<$numAgents; $i++) {
  125. $agentElement =& $agentList->item($i);
  126. $editors[] = trim($agentElement->getText());
  127. }
  128. //
  129. // // Creators
  130. // $agentList =& $this->_document->getElementsByTagName('creator');
  131. // $numAgents = $agentList->getLength();
  132. // for ($i=0; $i<$numAgents; $i++) {
  133. // $agentElement =& $agentList->item($i);
  134. // $editors[] = trim($agentElement->getText());
  135. // }
  136. //
  137. // // Last Editors
  138. // $agentList =& $this->_document->getElementsByTagName('last_editor');
  139. // $numAgents = $agentList->getLength();
  140. // for ($i=0; $i<$numAgents; $i++) {
  141. // $agentElement =& $agentList->item($i);
  142. // $editors[] = trim($agentElement->getText());
  143. // }
  144. $editors = array_unique($editors);
  145. foreach ($editors as $key => $editor) {
  146. // add the editors
  147. if ($editor != $siteElement->getAttribute('owner'))
  148. $site->addEditor($editor);
  149. }
  150. /*********************************************************
  151. * Set the rest of the fields.
  152. *********************************************************/
  153. $site->setField( 'type', $siteElement->getAttribute('type') );
  154. if (!$siteElement->hasChildNodes()) {
  155. print "\nNo child elements of the site!";
  156. return FALSE;
  157. }
  158. // Common Fields - title, history, activation, permissions
  159. if (!$this->setCommonFields($site, $siteElement))
  160. return FALSE;
  161. // Header and footer
  162. if (!$this->setHeaderFooter($site, $siteElement))
  163. return FALSE;
  164. // Theme
  165. if (!$this->setTheme($site, $siteElement))
  166. return FALSE;
  167. /*********************************************************
  168. * Save; media and discussions must be added to existing sites
  169. *********************************************************/
  170. $site->insertDB(0,0,1);
  171. /*********************************************************
  172. * Add the media
  173. *********************************************************/
  174. if (!$this->addMedia($site, $siteElement))
  175. return FALSE;
  176. /*********************************************************
  177. * Add the children
  178. *********************************************************/
  179. $types = array("section","navlink");
  180. if ($siteElement->hasChildNodes()) {
  181. $childElement =& $siteElement->firstChild;
  182. while ($childElement != NULL) {
  183. if (in_array($childElement->nodeName, $types)) {
  184. $childGood = $this->addSection($site, $childElement);
  185. if (!$childGood)
  186. return FALSE;
  187. }
  188. $childElement =& $childElement->nextSibling;
  189. }
  190. }
  191. /*********************************************************
  192. * Save (again, update) and finish.
  193. *********************************************************/
  194. //print_r ($site);
  195. // If we've made it this far, we're good.
  196. return TRUE;
  197. } else {
  198. print "\nXML Not a site!";
  199. return FALSE;
  200. }
  201. }
  202. function addSection(& $site, & $sectionElement) {
  203. // Create the section
  204. $section =& new section($site->name, 0, $site);
  205. $site->sections[] =& $section;
  206. /*********************************************************
  207. * Set the fields.
  208. *********************************************************/
  209. if (!$sectionElement->hasChildNodes()) {
  210. print "\nNo child elements of the section!";
  211. return FALSE;
  212. }
  213. if ($sectionElement->nodeName == "section")
  214. $section->setField( 'type', "section" );
  215. else if ($sectionElement->nodeName == "navlink") {
  216. $section->setField( 'type', "link" );
  217. // url
  218. $urlList =& $sectionElement->getElementsByPath("url");
  219. if ($urlList->getLength() != 1) {
  220. print "\nRequired 'url' element is missing!";
  221. return FALSE;
  222. }
  223. $urlElement =& $urlList->item(0);
  224. $section->setField('url', html_entity_decode(trim($urlElement->getText())));
  225. }
  226. // Common Fields - title, history, activation, permissions
  227. if (!$this->setCommonFields($section, $sectionElement))
  228. return FALSE;
  229. /*********************************************************
  230. * Save
  231. *********************************************************/
  232. $section->insertDB(1,null,0,1);
  233. // update permissions
  234. $section->updatePermissionsDB(1);
  235. /*********************************************************
  236. * Add the children
  237. *********************************************************/
  238. $types = array("page","navlink", "heading", "divider");
  239. if ($sectionElement->hasChildNodes()) {
  240. $childElement =& $sectionElement->firstChild;
  241. while ($childElement != NULL) {
  242. if (in_array($childElement->nodeName, $types)) {
  243. $childGood = $this->addPage($section, $childElement);
  244. if (!$childGood)
  245. return FALSE;
  246. }
  247. $childElement =& $childElement->nextSibling;
  248. }
  249. }
  250. return TRUE;
  251. }
  252. function addPage(& $section, & $pageElement) {
  253. // Create the page
  254. $page =& new page($section->owning_site, $section->id, 0, $section);
  255. $section->pages[] =& $page;
  256. /*********************************************************
  257. * Set the fields.
  258. *********************************************************/
  259. if (!$pageElement->hasChildNodes()) {
  260. print "\nNo child elements of the page!";
  261. return FALSE;
  262. }
  263. if ($pageElement->nodeName == "page")
  264. $page->setField( 'type', "page" );
  265. else if ($pageElement->nodeName == "navlink") {
  266. $page->setField( 'type', "link" );
  267. // url
  268. $urlList =& $pageElement->getElementsByPath("url");
  269. if ($urlList->getLength() != 1) {
  270. print "\nRequired 'url' element is missing!";
  271. return FALSE;
  272. }
  273. $urlElement =& $urlList->item(0);
  274. $page->setField('url', html_entity_decode(trim($urlElement->getText())));
  275. } else if ($pageElement->nodeName == "heading")
  276. $page->setField( 'type', "heading" );
  277. else if ($pageElement->nodeName == "divider")
  278. $page->setField( 'type', "divider" );
  279. // Common Fields - title, history, activation, permissions
  280. if (!$this->setCommonFields($page, $pageElement))
  281. return FALSE;
  282. // Page display options
  283. // Story order
  284. $page->setField("storyorder", $pageElement->getAttribute("story_order"));
  285. // Show hr
  286. $page->setField("showhr",(($pageElement->getAttribute("horizontal_rule") == "TRUE")?1:0));
  287. // Show creator
  288. $page->setField("showcreator",(($pageElement->getAttribute("show_creator") == "TRUE")?1:0));
  289. // Show date
  290. $page->setField("showdate",(($pageElement->getAttribute("show_date") == "TRUE")?1:0));
  291. // Story archiving
  292. $page->setField("archiveby", $pageElement->getAttribute("archiving"));
  293. /*********************************************************
  294. * Save
  295. *********************************************************/
  296. $page->insertDB(1,NULL,0,0,1);
  297. // update permissions
  298. $page->updatePermissionsDB(1);
  299. /*********************************************************
  300. * Add the children
  301. *********************************************************/
  302. $types = array("story","link", "file", "image");
  303. if ($pageElement->hasChildNodes()) {
  304. $childElement =& $pageElement->firstChild;
  305. while ($childElement != NULL) {
  306. if (in_array($childElement->nodeName, $types)) {
  307. $childGood = $this->addStory($page, $childElement);
  308. if (!$childGood)
  309. return FALSE;
  310. }
  311. $childElement =& $childElement->nextSibling;
  312. }
  313. }
  314. return TRUE;
  315. }
  316. function addStory(& $page, & $storyElement) {
  317. // Create the story
  318. $story =& new story($page->owning_site, $page->owning_section, $page->id, 0, $section);
  319. $page->stories[] =& $story;
  320. /*********************************************************
  321. * Set the fields.
  322. *********************************************************/
  323. if (!$storyElement->hasChildNodes()) {
  324. print "\nNo child elements of the story!";
  325. return FALSE;
  326. }
  327. $story->setField( 'type', $storyElement->nodeName );
  328. // Story
  329. if ($storyElement->nodeName == "story") {
  330. // shorttext
  331. $shorttextList =& $storyElement->getElementsByPath("shorttext");
  332. if ($shorttextList->getLength() != 1) {
  333. print "\nRequired 'shorttext' element is missing!";
  334. return FALSE;
  335. }
  336. $shorttextElement =& $shorttextList->item(0);
  337. $story->setField('shorttext', html_entity_decode(trim($shorttextElement->getText())));
  338. // longtext
  339. $longtextList =& $storyElement->getElementsByPath("longtext");
  340. if ($longtextList->getLength() > 1) {
  341. print "\nInvalid number of 'longtext' elements!";
  342. return FALSE;
  343. }
  344. if ($longtextList->getLength() == 1) {
  345. $longtextElement =& $longtextList->item(0);
  346. $story->setField('longertext', html_entity_decode(trim($longtextElement->getText())));
  347. }
  348. // Link
  349. } else if ($storyElement->nodeName == "link") {
  350. // description
  351. $descriptionList =& $storyElement->getElementsByPath("description");
  352. if ($descriptionList->getLength() != 1) {
  353. print "\nRequired 'description' element is missing!";
  354. return FALSE;
  355. }
  356. $descriptionElement =& $descriptionList->item(0);
  357. $story->setField('description', html_entity_decode(trim($descriptionElement->getText())));
  358. // url
  359. $urlList =& $storyElement->getElementsByPath("url");
  360. if ($urlList->getLength() != 1) {
  361. print "\nRequired 'url' element is missing!";
  362. return FALSE;
  363. }
  364. $urlElement =& $urlList->item(0);
  365. $story->setField('url', html_entity_decode(trim($urlElement->getText())));
  366. // File
  367. } else if ($storyElement->nodeName == "file" || $storyElement->nodeName == "image") {
  368. // description
  369. $descriptionList =& $storyElement->getElementsByPath("description");
  370. if ($descriptionList->getLength() != 1) {
  371. print "\nRequired 'description' element is missing!";
  372. return FALSE;
  373. }
  374. $descriptionElement =& $descriptionList->item(0);
  375. $story->setField('description', html_entity_decode(trim($descriptionElement->getText())));
  376. // Assume that the files have been added to the media table.
  377. $filenameList =& $storyElement->getElementsByPath("filename");
  378. $filenameElement =& $filenameList->item(0);
  379. $filename = trim($filenameElement->getText());
  380. $mediaID = db_get_value("media","media_id", "media_tag='".$filename."'");
  381. $story->setField('longertext', $mediaID);
  382. }
  383. // Common Fields - title, history, activation, permissions
  384. if (!$this->setCommonFields($story, $storyElement))
  385. return FALSE;
  386. // category
  387. $categoryList =& $storyElement->getElementsByPath("category");
  388. if ($categoryList->getLength() > 1) {
  389. print "\nInvalid number of 'category' elements!";
  390. return FALSE;
  391. }
  392. if ($categoryList->getLength() == 1) {
  393. $categoryElement =& $categoryList->item(0);
  394. $story->setField('category', html_entity_decode(trim($categoryElement->getText())));
  395. }
  396. /*********************************************************
  397. * Add the discussion properties (we need to do this before inserting).
  398. *********************************************************/
  399. // discussion
  400. $discussionList =& $storyElement->getElementsByPath("discussion");
  401. if ($discussionList->getLength() > 1) {
  402. print "\nInvalid number of 'discussion' elements!";
  403. return FALSE;
  404. }
  405. if ($discussionList->getLength() == 1) {
  406. $discussionElement =& $discussionList->item(0);
  407. $story->setField("discuss", 1);
  408. $email = (($discussionElement->getAttribute("email_owner") == "TRUE")?1:0);
  409. $story->setField("discussemail", $email);
  410. $authors = (($discussionElement->getAttribute("show_authors") == "TRUE")?1:2);
  411. $story->setField("discussauthor", $authors);
  412. $display = (($discussionElement->getAttribute("show_others_posts") == "TRUE")?1:2);
  413. $story->setField("discussdisplay", $display);
  414. }
  415. /*********************************************************
  416. * Save
  417. *********************************************************/
  418. $story->insertDB(1,NULL,0,0,0,1);
  419. // update permissions
  420. $story->updatePermissionsDB(1);
  421. /*********************************************************
  422. * Add the discussion posts
  423. *********************************************************/
  424. if ($discussionList->getLength() == 1) {
  425. if (!$this->addDiscussion($story, $discussionElement))
  426. return FALSE;
  427. }
  428. return TRUE;
  429. }
  430. function addDiscussion(& $story, & $discussionElement) {
  431. /*********************************************************
  432. * Add the children
  433. *********************************************************/
  434. $types = array("discussion_node");
  435. if ($discussionElement->hasChildNodes()) {
  436. $childElement =& $discussionElement->firstChild;
  437. while ($childElement != NULL) {
  438. if (in_array($childElement->nodeName, $types)) {
  439. $childGood = $this->addPost($story, 0, $childElement);
  440. if (!$childGood)
  441. return FALSE;
  442. }
  443. $childElement =& $childElement->nextSibling;
  444. }
  445. }
  446. return TRUE;
  447. }
  448. function addPost(& $story, $parentId, & $discussion_nodeElement) {
  449. /*********************************************************
  450. * Add the discussion_node
  451. *********************************************************/
  452. $discussion =& new discussion($story, NULL, $parentId);
  453. /*********************************************************
  454. * Add the fields
  455. *********************************************************/
  456. // creator
  457. $creatorList =& $discussion_nodeElement->getElementsByPath("creator");
  458. if ($creatorList->getLength() != 1) {
  459. print "\nRequired 'creator' element is missing from the discussion!";
  460. return FALSE;
  461. }
  462. $creatorElement =& $creatorList->item(0);
  463. $discussion->authorid = db_get_value("user", "user_id", "user_uname='".trim($creatorElement->getText())."'");
  464. // created_time
  465. $created_timeList =& $discussion_nodeElement->getElementsByPath("created_time");
  466. if ($created_timeList->getLength() != 1) {
  467. print "\nRequired 'created_time' element is missing from the discussion!";
  468. return FALSE;
  469. }
  470. $created_timeElement =& $created_timeList->item(0);
  471. $discussion->tstamp = trim($created_timeElement->getText());
  472. // title
  473. $titleList =& $discussion_nodeElement->getElementsByPath("title");
  474. if ($titleList->getLength() != 1) {
  475. print "\nRequired 'title' element is missing from the discussion!";
  476. return FALSE;
  477. }
  478. $titleElement =& $titleList->item(0);
  479. $discussion->subject = html_entity_decode(trim($titleElement->getText()));
  480. // text
  481. $textList =& $discussion_nodeElement->getElementsByPath("text");
  482. if ($textList->getLength() != 1) {
  483. print "\nRequired 'text' element is missing from the discussion!";
  484. return FALSE;
  485. }
  486. $textElement =& $textList->item(0);
  487. $discussion->content = html_entity_decode(trim($textElement->getText()));
  488. // Assume that the files have been added to the media table.
  489. $filenameList =& $discussion_nodeElement->getElementsByPath("filename");
  490. $filenameElement =& $filenameList->item(0);
  491. $filename = trim($filenameElement->getText());
  492. if ($filename) {
  493. $mediaID = db_get_value("media","media_id", "media_tag='".$filename."'");
  494. $discussion->libraryfileid = $mediaID;
  495. $discussion->libraryfilename = $filename;
  496. $discussion->media_tag = $filename;
  497. }
  498. // rating
  499. $ratingList =& $discussion_nodeElement->getElementsByPath("rating");
  500. if ($ratingList->getLength() != 1) {
  501. print "\nRequired 'rating' element is missing from the discussion!";
  502. return FALSE;
  503. }
  504. $ratingElement =& $ratingList->item(0);
  505. $discussion->rating = html_entity_decode(trim($ratingElement->getText()));
  506. /*********************************************************
  507. * Save
  508. *********************************************************/
  509. $discussion->insert();
  510. /*********************************************************
  511. * Add the children
  512. *********************************************************/
  513. $types = array("discussion_node");
  514. if ($discussion_nodeElement->hasChildNodes()) {
  515. $childElement =& $discussion_nodeElement->firstChild;
  516. while ($childElement != NULL) {
  517. if (in_array($childElement->nodeName, $types)) {
  518. $childGood = $this->addPost($story, $discussion->id, $childElement);
  519. if (!$childGood)
  520. return FALSE;
  521. }
  522. $childElement =& $childElement->nextSibling;
  523. }
  524. }
  525. return TRUE;
  526. }
  527. function setCommonFields(& $partObj, & $partElement) {
  528. // Title
  529. $titleList =& $partElement->getElementsByPath("title");
  530. $titleElement =& $titleList->item(0);
  531. if ($titleList->getLength() != 1 && $partElement->nodeName != 'divider') {
  532. print "\nRequired 'title' element is missing from a ".$partElement->nodeName."!";
  533. return FALSE;
  534. } else if ($partElement->nodeName != 'divider')
  535. $partObj->setField('title', html_entity_decode(trim($titleElement->getText())));
  536. // History
  537. $historyList =& $partElement->getElementsByPath("history");
  538. if ($historyList->getLength() != 1) {
  539. print "\nRequired 'history' element is missing!";
  540. return FALSE;
  541. }
  542. $historyElement =& $historyList->item(0);
  543. $historyGood = $this->setHistory($partObj, $historyElement);
  544. // Activation
  545. $activationList =& $partElement->getElementsByPath("activation");
  546. if ($activationList->getLength() > 1) {
  547. print "\nInvaid number of 'activation' elements!";
  548. return FALSE;
  549. }
  550. if ($activationList->getLength()) {
  551. $activationElement =& $activationList->item(0);
  552. $activationGood = $this->setActivation($partObj, $activationElement);
  553. } else {
  554. $activationGood = TRUE;
  555. }
  556. // Permissions
  557. $permissionsList =& $partElement->getElementsByPath("permissions");
  558. if ($permissionsList->getLength() > 1) {
  559. print "\nInvaid number of 'permissions' elements!";
  560. return FALSE;
  561. }
  562. if ($permissionsList->getLength()) {
  563. $permissionsElement =& $permissionsList->item(0);
  564. $permissionsGood = $this->setPermissions($partObj, $permissionsElement);
  565. } else {
  566. $permissionsGood = TRUE;
  567. }
  568. if ($historyGood && $activationGood && $permissionsGood)
  569. return TRUE;
  570. else
  571. return FALSE;
  572. }
  573. function setHistory(& $partObj, & $historyElement) {
  574. // Creator
  575. $creatorList =& $historyElement->getElementsByPath("creator");
  576. $creatorElement =& $creatorList->item(0);
  577. if ($creatorList->getLength() != 1) {
  578. print "\nRequired 'creator' element is missing!";
  579. return FALSE;
  580. }
  581. $partObj->setField('addedby', trim($creatorElement->getText()));
  582. // Last Editor
  583. $last_editorList =& $historyElement->getElementsByPath("last_editor");
  584. $last_editorElement =& $last_editorList->item(0);
  585. if ($last_editorList->getLength() != 1) {
  586. print "\nRequired 'last_editor' element is missing!";
  587. return FALSE;
  588. }
  589. $partObj->setField('editedby', trim($last_editorElement->getText()));
  590. // Created Time
  591. $created_timeList =& $historyElement->getElementsByPath("created_time");
  592. $created_timeElement =& $created_timeList->item(0);
  593. if ($created_timeList->getLength() != 1) {
  594. print "\nRequired 'created_time' element is missing!";
  595. return FALSE;
  596. }
  597. $partObj->setField('addedtimestamp', trim($created_timeElement->getText()));
  598. // Last Edited Time
  599. $last_edited_timeList =& $historyElement->getElementsByPath("last_edited_time");
  600. $last_edited_timeElement =& $last_edited_timeList->item(0);
  601. if ($last_edited_timeList->getLength() != 1) {
  602. print "\nRequired 'last_edited_time' element is missing!";
  603. return FALSE;
  604. }
  605. $partObj->setField('editedtimestamp', trim($last_edited_timeElement->getText()));
  606. return TRUE;
  607. }
  608. function setActivation(& $partObj, & $activationElement) {
  609. // Activate Date
  610. $activate_dateList =& $activationElement->getElementsByPath("activate_date");
  611. $activate_dateElement =& $activate_dateList->item(0);
  612. if ($activate_dateList->getLength() > 1) {
  613. print "\nInvalid number of 'activate_date' elements!";
  614. return FALSE;
  615. }
  616. if ($activate_dateElement)
  617. $partObj->setField('activatedate', trim($activate_dateElement->getText()));
  618. // Deactivate Date
  619. $deactivate_dateList =& $activationElement->getElementsByPath("deactivate_date");
  620. $deactivate_dateElement =& $deactivate_dateList->item(0);
  621. if ($deactivate_dateList->getLength() > 1) {
  622. print "\nInvalid number of 'deactivate_date' elements!";
  623. return FALSE;
  624. }
  625. if ($deactivate_dateElement)
  626. $partObj->setField('deactivatedate', trim($deactivate_dateElement->getText()));
  627. // Deactivate Date
  628. $manual_activationList =& $activationElement->getElementsByPath("manual_activation");
  629. $manual_activationElement =& $manual_activationList->item(0);
  630. if ($manual_activationList->getLength() > 1) {
  631. print "\nInvalid number of 'manual_activation' elements!";
  632. return FALSE;
  633. }
  634. if ($manual_activationElement && $manual_activationElement->getText() == 'INACTIVE')
  635. $partObj->setField('active', 0);
  636. return TRUE;
  637. }
  638. function setPermissions(& $partObj, & $permissionsElement) {
  639. // Assume that we have added any agents as an editor already.
  640. // editor permissions
  641. $viewGood = $this->setPermission('view', $partObj, $permissionsElement);
  642. $addGood = $this->setPermission('add', $partObj, $permissionsElement);
  643. $editGood = $this->setPermission('edit', $partObj, $permissionsElement);
  644. $deleteGood = $this->setPermission('delete', $partObj, $permissionsElement);
  645. $discussGood = $this->setPermission('discuss', $partObj, $permissionsElement);
  646. // Locked flags
  647. $lockedList =& $permissionsElement->getElementsByPath("locked");
  648. if($lockedList->getLength() == 1) {
  649. $partObj->setField("locked", 1);
  650. }
  651. // We will update the permissions db after inserting our partObj
  652. if ($viewGood && $addGood && $editGood && $deleteGood && $discussGood)
  653. return TRUE;
  654. else
  655. return FALSE;
  656. }
  657. function setPermission($type, & $partObj, & $permissionsElement) {
  658. $permissionList =& $permissionsElement->getElementsByPath($type."_permission");
  659. if ($permissionList->getLength() > 1) {
  660. print "\nInvaid number of '".$type."_permission' elements!";
  661. return FALSE;
  662. }
  663. if ($permissionElement =& $permissionList->item(0)) {
  664. // Get all the agents
  665. $agentList =& $permissionElement->getElementsByPath("agent");
  666. $count = $agentList->getLength();
  667. for ($i=0; $i<$count; $i++) {
  668. $agentElement =& $agentList->item($i);
  669. // Set the permissions for for the aget/part
  670. $partObj->setUserPermissionDown($type, trim($agentElement->getText()));
  671. }
  672. }
  673. return TRUE;
  674. }
  675. function setHeaderFooter(& $site, & $siteElement) {
  676. // header
  677. $headerList =& $siteElement->getElementsByPath("header");
  678. $headerElement =& $headerList->item(0);
  679. if ($headerElement) {
  680. $site->setField('header', html_entity_decode(trim($headerElement->getText())));
  681. }
  682. // footer
  683. $footerList =& $siteElement->getElementsByPath("footer");
  684. $footerElement =& $footerList->item(0);
  685. if ($footerElement) {
  686. $site->setField('footer', html_entity_decode(trim($footerElement->getText())));
  687. }
  688. return TRUE;
  689. }
  690. function setTheme(& $site, & $siteElement) {
  691. // theme
  692. $themeList =& $siteElement->getElementsByPath("theme");
  693. $themeElement =& $themeList->item(0);
  694. if ($themeElement) {
  695. $settingsParts = array(
  696. 'name' => 'theme',
  697. 'color_scheme' => 'colorscheme',
  698. 'background_color' => 'bgcolor',
  699. 'border_style' => 'borderstyle',
  700. 'border_color' => 'bordercolor',
  701. 'text_color' => 'textcolor',
  702. 'link_color' => 'linkcolor',
  703. 'navigation_arrangement' => 'nav_arrange',
  704. 'navigation_width' => 'nav_width',
  705. 'section_nav_size' => 'sectionnav_size',
  706. 'page_nav_size' => 'nav_size'
  707. );
  708. $themeSettings = array();
  709. foreach ($settingsParts as $tag => $key) {
  710. $list =& $themeElement->getElementsByPath($tag);
  711. $element =& $list->item(0);
  712. if ($element) {
  713. if ($tag == 'name')
  714. $site->setField($key, trim($element->getText()));
  715. $themeSettings[$key] = trim($element->getText());
  716. }
  717. }
  718. $site->setField('themesettings', urlencode(serialize($themeSettings)));
  719. }
  720. return TRUE;
  721. }
  722. function addMedia(& $site, & $siteElement) {
  723. global $uploaddir;
  724. $sitedir = $uploaddir.((ereg(".*/$", $uploaddir))?"":"/").$site->name."/";
  725. // media
  726. $mediaList =& $siteElement->getElementsByPath("media");
  727. $mediaElement =& $mediaList->item(0);
  728. if ($mediaElement) {
  729. // Make sure that we have the directory created.
  730. if (!is_dir($sitedir))
  731. mkdir($sitedir,0775);
  732. // Make sure the ownership is right
  733. if ($this->_apacheUser) {
  734. if (!chown($sitedir, $this->_apacheUser))
  735. print "\nError changing owner of ".$sitedir." to ".$this->_apacheUser.".";
  736. }
  737. if ($this->_apacheGroup) {
  738. if (!chgrp($sitedir, $this->_apacheGroup))
  739. print "\nError changing group of ".$sitedir." to ".$this->_apacheGroup.".";
  740. }
  741. // Get the file list
  742. $fileList =& $mediaElement->getElementsByPath("media_file");
  743. $numFiles =& $fileList->getLength();
  744. // Add each file
  745. for ($i=0; $i<$numFiles; $i++) {
  746. $fileElement =& $fileList->item($i);
  747. // get the filename
  748. $filenameList =& $fileElement->getElementsByPath("filename");
  749. $filenameElement =& $filenameList->item(0);
  750. $filename = trim($filenameElement->getText());
  751. // Copy the file to segue
  752. $result = copy($this->_mediaSource.$filename,$sitedir.$filename);
  753. if (!$result) {
  754. print "\nError copying file '".$this->_mediaSource.$filename."' to '".$sitedir.$filename."'. ";
  755. return FALSE;
  756. }
  757. // Make sure the ownership is right
  758. if ($this->_apacheUser) {
  759. if (!chown($sitedir.$filename, $this->_apacheUser))
  760. print "\nError changing owner of ".$sitedir.$filename." to ".$this->_apacheUser.".";
  761. }
  762. if ($this->_apacheGroup) {
  763. if (!chgrp($sitedir.$filename, $this->_apacheGroup))
  764. print "\nError changing group of ".$sitedir.$filename." to ".$this->_apacheGroup.".";
  765. }
  766. // Collect our info about the file
  767. $size = filesize($sitedir.$filename);
  768. $creatorList =& $fileElement->getElementsByPath("creator");
  769. $creatorElement =& $creatorList->item(0);
  770. $creatorId = db_get_value("user", "user_id", "user_uname='".trim($creatorElement->getText())."'");
  771. $last_editorList =& $fileElement->getElementsByPath("last_editor");
  772. $last_editorElement =& $last_editorList->item(0);
  773. $last_editorId = db_get_value("user", "user_id", "user_uname='".trim($last_editorElement->getText())."'");
  774. $last_edited_timeList =& $fileElement->getElementsByPath("last_edited_time");
  775. $last_edited_timeElement =& $last_edited_timeList->item(0);
  776. $last_edited_time = trim($last_edited_timeElement->getText());
  777. $typeList =& $fileElement->getElementsByPath("type");
  778. $typeElement =& $typeList->item(0);
  779. $type = trim($typeElement->getText());
  780. // Insert into the media directory
  781. $query = "
  782. INSERT INTO
  783. media
  784. SET
  785. media_tag='".$filename."',
  786. FK_site='".$site->id."',
  787. FK_createdby='".$creatorId."',
  788. FK_updatedby='".$last_editorId."',
  789. media_updated_tstamp='".$last_edited_time."',
  790. media_type='".$type."',
  791. media_size='".$size."'";
  792. db_query($query);
  793. print mysql_error();
  794. }
  795. }
  796. return TRUE;
  797. }
  798. }