PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/fullstory.inc.php

https://github.com/adamfranco/segue-1.x
PHP | 436 lines | 280 code | 71 blank | 85 comment | 106 complexity | cb464797856857af1cb97c77f6d507a8 MD5 | raw file
  1. <? /* $Id$ */
  2. //require("objects/objects.inc.php");
  3. $content = '';
  4. //ob_start();
  5. /******************************************************************************
  6. * This script is an adaptation of fullstory.php
  7. * this script is included in site.inc.php when detail variable is set
  8. ******************************************************************************/
  9. if ($_REQUEST['action'] == 'viewsite')
  10. $action = 'viewsite';
  11. else
  12. $action = 'site';
  13. // Set the default to threaded
  14. if (!isset($_SESSION['flat_discussion'])) {
  15. $_SESSION['flat_discussion'] = false;
  16. }
  17. if (isset($_REQUEST['discussion_threading'])) {
  18. if ($_REQUEST['discussion_threading'] == 'flat')
  19. $_SESSION['flat_discussion'] = true;
  20. else
  21. $_SESSION['flat_discussion'] = false;
  22. }
  23. if ($tmp = $_REQUEST['order']) {
  24. $_SESSION['order'] = $_REQUEST['order'];
  25. }
  26. /* if ($tmp2 = $_REQUEST['recent']) { */
  27. /* $_SESSION['recent'] = ($tmp2=='true')?true:false; */
  28. /* } */
  29. //printpre($_SESSION);
  30. //printpre($_REQUEST);
  31. $partialstatus = 1;
  32. $siteObj =& new site($_REQUEST[site]);
  33. $sectionObj =& new section($_REQUEST[site],$_REQUEST[section], $siteObj);
  34. $pageObj =& new page($_REQUEST[site],$_REQUEST[section],$_REQUEST[page], $sectionObj);
  35. $storyObj =& new story($_REQUEST[site],$_REQUEST[section],$_REQUEST[page],$_REQUEST[story], $pageObj);
  36. $getinfo = "site=".$siteObj->name."&amp;section=".$sectionObj->id."&amp;page=".$pageObj->id."&amp;story=".$storyObj->id."&amp;detail=".$storyObj->id;
  37. $getinfo2 = "site=".$siteObj->name."&amp;section=".$sectionObj->id."&amp;page=".$pageObj->id;
  38. $editsettingsurl = "&amp;site=".$siteObj->name."&amp;section=".$sectionObj->id."&amp;page=".$pageObj->id."&amp;action=edit_story&amp;edit_story=".$storyObj->id."&amp;detail=".$storyObj->id."&amp;step=4&amp;goback=discuss&amp;link=1";
  39. $storyObj->fetchFromDB();
  40. $storyObj->owningSiteObj->fetchFromDB();
  41. //$site_owner=slot::getOwner($story->owningSiteObj->name);
  42. $site_owner=$storyObj->owningSiteObj->owner;
  43. //print_r($story->owningSiteObj);
  44. //print $site_owner;
  45. // get the correct shorttext
  46. if ($storyObj->getField("type") == 'story') {
  47. //printpre($storyObj->getField("shorttext"));
  48. $smalltext = convertTagsToInteralLinks($siteObj->name, $storyObj->getField("shorttext"));
  49. $fulltext = convertTagsToInteralLinks($siteObj->name, $storyObj->getField("longertext"));
  50. $smalltext = stripslashes($smalltext);
  51. $fulltext = stripslashes($fulltext);
  52. // $smalltext = convertWikiMarkupToLinks($site,$section,$page,$o->id, $page_title, $smalltext);
  53. // $fulltext = convertWikiMarkupToLinks($site,$section,$page,$o->id, $page_title, $fulltext);
  54. $wikiResolver =& WikiResolver::instance();
  55. $smalltext = $wikiResolver->parseText($smalltext, $site, $section, $page);
  56. $fulltext = $wikiResolver->parseText($fulltext, $site, $section, $page);
  57. if ($storyObj->getField("texttype") == 'text') $fulltext = htmlbr($fulltext);
  58. if ($storyObj->getField("texttype") == 'text') $smalltext = htmlbr($smalltext);
  59. } else if ($storyObj->getField("type") == 'image') {
  60. $filename = urldecode(db_get_value("media","media_tag","media_id='".addslashes($storyObj->getField("longertext"))."'"));
  61. $dir = db_get_value("media INNER JOIN slot ON media.FK_site = slot.FK_site","slot_name","media_id='".addslashes($storyObj->getField("longertext"))."'");
  62. $imagepath = "$uploadurl/$dir/$filename";
  63. $fulltext = "\n<div style='text-align: center'><br /><img src='$imagepath' border='0' /></div>";
  64. /* if ($story->getField("title")) $fulltext .= "<tr><td align='center'><b>".spchars($story->getField("title"))."</b></td></tr>"; */
  65. if ($storyObj->getField("shorttext")) {
  66. $captiontext = $st = convertTagsToInteralLinks($site, $storyObj->getField("shorttext"));
  67. $captiontext = "<br />".stripslashes($captiontext);
  68. }
  69. $fulltext .= "";
  70. } else if ($storyObj->getField("type") == 'file') {
  71. $fulltext = "<br />";
  72. $fulltext .= makedownloadbar($storyObj);
  73. } else {
  74. $fulltext = "<br />";
  75. $siteType = preg_replace('/[^a-z0-9_-]/i', '', $siteObj->getField("type"));
  76. $storyType = preg_replace('/[^a-z0-9_-]/i', '', $storyObj->getField("type"));
  77. $incfile = "output_modules/".$siteType."/".$storyType.".inc.php";
  78. // print $incfile; // debug
  79. include($incfile);
  80. $fulltext .= $content;
  81. $content = '';
  82. }
  83. /******************************************************************************
  84. * print out shory and discussion (if any)
  85. ******************************************************************************/
  86. // require_once("htmleditor/editor.inc.php");
  87. if ($storyObj->getField("discuss")) $titleExtra = " Discussion";
  88. printc("\n<table width='100%' id='maintable' cellspacing='1'>");
  89. printc($pagePagination);
  90. printc("\n\t<tr>\n\t\t<td align='left' class='title'>\n\t\t\t<a href='index.php?action=".$action."&amp;".$getinfo2."'>".spchars($pageObj->getField('title'))."</a>");
  91. if ($storyObj->getField('title')) {
  92. printc("\n\t\t\t&gt; ".spchars($storyObj->getField('title'))." &gt; in depth");
  93. } else {
  94. printc("\n\t\t\t&gt; in depth");
  95. }
  96. printc("\n\t\t</td>\n\t</tr>");
  97. if ($storyObj->getField('type') != "image" && $storyObj->getField('type') != "link" && $storyObj->getField('type') != "rss") printc("\n\t<tr>\n\t\t<td align='left'>\n\t\t\t<strong>".(($storyObj->getField('title'))?spchars($storyObj->getField('title')):'&nbsp;')."</strong>\n\t\t</td>\n\t</tr>");
  98. $record_id = $story;
  99. $user_id = $_SESSION[aid];
  100. $record_type = "story";
  101. $story_tags = get_record_tags($record_id);
  102. //printpre($story_tags);
  103. if ($story_tags) {
  104. printc("\n\t\t\t\t<div class='contentinfo' style='margin-top: 0px;'>");
  105. printc("\n\t\t\t\tCategories:");
  106. foreach ($story_tags as $tag) {
  107. $urltag = urlencode($tag);
  108. $tagname = urldecode($tag);
  109. printc("\n\t\t\t\t<a href='index.php?$sid&amp;action=".$action."&amp;site=$site&amp;section=$section&amp;page=$page&amp;tag=$urltag'>".$tagname."</a>");
  110. };
  111. printc("\n\t\t\t</div>\n\t\t</td>\n\t</tr>");
  112. }
  113. printc("\n\t<tr>\n\t\t<td style='padding-bottom: 15px; font-size: 12px'>\n\t\t\t$smalltext\n\t\t</td>\n\t</tr>");
  114. if ($storyObj->getField('type') != "rss") {
  115. printc("\n\t<tr>\n\t\t<td style='padding-bottom: 15px; font-size: 12px'>\n\t\t\t$fulltext\n\t\t</td>\n\t</tr>");
  116. }
  117. if ($storyObj->getField('type') == "image") {
  118. printc("\n\t<tr>\n\t\t<td align='center' font-size: 12px'>\n\t\t\t<strong>".spchars($storyObj->getField('title'))."</strong>\n\t\t</td>\n\t</tr>");
  119. printc("\n\t<tr>\n\t\t<td font-size: 12px'>$captiontext</td>\n\t</tr>");
  120. }
  121. if ($storyObj->getField('type') == "rss") {
  122. //include_once (dirname(__FILE__)."/carprss/carp.php");
  123. ob_clean();
  124. ob_start();
  125. print "\n\n";
  126. $url = $storyObj->getField("url");
  127. MyCarpConfReset();
  128. MyCarpConfReset('rss_contentblock');
  129. if (is_numeric($storyObj->getField("longertext"))) {
  130. $num_per_set = $storyObj->getField("longertext");
  131. CarpConf('maxitems',$num_per_set);
  132. } else {
  133. CarpConf('maxitems',5);
  134. }
  135. // If we have an auser, create a cache just for them.
  136. if ($_SESSION['auser']) {
  137. CarpCacheShow($url, '', 1, $_SESSION['auser']);
  138. } else {
  139. // If the user has a valid campus ip-address, then they are a
  140. // member of 'institute'.
  141. $ipIsInInstitute = FALSE;
  142. $ip = $_SERVER[REMOTE_ADDR];
  143. // check if our IP is in inst_ips
  144. if (is_array($cfg[inst_ips])) {
  145. foreach ($cfg[inst_ips] as $i) {
  146. if (ereg("^$i",$ip))
  147. $ipIsInInstitute = TRUE;
  148. }
  149. }
  150. // if we are in the institute IPs, use the institute
  151. // cache.
  152. if ($ipIsInInstitute) {
  153. CarpCacheShow($url, '', 1, 'institute');
  154. }
  155. // If we aren't logged in or in the institute IPs, just use the
  156. // everyone cache.
  157. else {
  158. CarpCacheShow($url);
  159. }
  160. }
  161. $rssitems = ob_get_contents();
  162. printc("\n\t<tr>\n\t\t<td style='padding-bottom: 15px; font-size: 12px'>\n\t\t\t$rssitems\n\t\t</td>\n\t</tr>");
  163. ob_clean();
  164. }
  165. printc("\n</table>\n");
  166. /*********************************************************
  167. * Print out edit links if we are in viewsite mode
  168. *********************************************************/
  169. if ($action == 'viewsite' && isset($storyEditLinks))
  170. printc($storyEditLinks);
  171. /*********************************************************
  172. * output discussions?
  173. *********************************************************/
  174. if ($storyObj->getField("discuss")) {
  175. $mailposts = $storyObj->getField("discussemail");
  176. $showposts = $storyObj->getField("discussdisplay");
  177. $showallauthors = $storyObj->getField("discussauthor");
  178. $siteowner = $siteObj->ownerfname;
  179. $discusslabel = $storyObj->getField("discusslabel");
  180. printc("\n<table width='100%' cellspacing='1'>");
  181. printc("\n\t<tr>\n\t\t<td align='left' class='dheader'>\n\t\t\t<a name='discuss'></a>");
  182. printc(($discusslabel)? $discusslabel:"Discuss");
  183. /* if ($showposts == 1) { */
  184. /* printc("<td align='left'><table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td align='left' class='dheader'>Discussion\n"); */
  185. /* } else { */
  186. /* printc("<td align='left'><table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td align='left' class='dheader'>Assessment\n"); */
  187. /* } */
  188. //get number of discuss/assess participants
  189. $numparticipants = participants();
  190. $storyid = $storyObj->getField('id');
  191. $siteid = $siteObj->getField('id');
  192. $site=$siteObj->name;
  193. //printpre($_SESSION);
  194. printc("\n\t\t\t<div style='font-size: 10px'>\n\t\t\t\t");
  195. if ($_SESSION[auser]==$site_owner) {
  196. printc($numparticipants." participants");
  197. printc(" - <a href='email.php?$sid&amp;storyid=$storyid&amp;siteid=$siteid&amp;site=$site&amp;action=list' onclick='doWindow(\"email\",700,500)' target='email'>Summary &amp; Email</a> \n");
  198. //printc("<a href='email.php?$sid&amp;storyid=$storyid&amp;siteid=$siteid&amp;site=$site&amp;action=email' onclick='doWindow(\"email\",700,500)' target='email'>Email</a> - \n");
  199. } else {
  200. printc($numparticipants." participants");
  201. }
  202. printc("\n\t\t\t</div>");
  203. printc("\n\t\t</td>");
  204. printc("\n\t\t<td align='right' class='dheader2'>");
  205. printc("\n\t\t\t<table>");
  206. printc("\n\t\t\t\t<tr>\n\t\t\t\t\t<td>");
  207. printc("\n\t\t\t\t\t\t<form action='index.php?$sid&amp;action=".$action."&amp;".$getinfo."' method='post' name='viewform'>");
  208. printc("\n\t\t\t\t\t\t\t<select name='discussion_threading'>");
  209. printc("\n\t\t\t\t\t\t\t\t<option value='flat'".(($_SESSION['flat_discussion'])?" selected='selected'":"").">Flat</option>");
  210. printc("\n\t\t\t\t\t\t\t\t<option value='threaded'".(($_SESSION['flat_discussion'])?"":" selected='selected'").">Threaded</option>");
  211. printc("\n\t\t\t\t\t\t\t</select>");
  212. //printc("</td><td>\n");
  213. $r = $_SESSION['order'];
  214. printc("\n\t\t\t\t\t\t\t<select name='order'>");
  215. printc("\n\t\t\t\t\t\t\t\t<option value='2'".(($r == 2)?" selected='selected'":"").">Recent Last</option>");
  216. printc("\n\t\t\t\t\t\t\t\t<option value='1'".(($r == 1)?" selected='selected'":"").">Recent First</option>");
  217. //if ($_SESSION[auser]==$site_owner) {
  218. printc("\n\t\t\t\t\t\t\t\t<option value='3'".(($r == 3)?" selected='selected'":"").">Rating</option>");
  219. printc("\n\t\t\t\t\t\t\t\t<option value='4'".(($r == 4)?" selected='selected'":"").">Author</option>");
  220. //}
  221. printc("\n\t\t\t\t\t\t\t</select>");
  222. printc("\n\t\t\t\t\t\t\t<input type='submit' class='button' value='Change' />");
  223. printc("\n\t\t\t\t\t\t</form>");
  224. printc("\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\t\t\t</table>");
  225. printc("\n\t\t</td>\n\t</tr>");
  226. printc("\n</table>\n");
  227. /******************************************************************************
  228. * Explain discuss/assess settings to participants
  229. ******************************************************************************/
  230. $siteLevelEditors = $siteObj->getSiteLevelEditors();
  231. //printpre($siteLevelEditors);
  232. // hide posts (assessment)
  233. if ($showposts == 2 && $showallauthors == 1) {
  234. printc("Posts to this assessment are currently viewable only be the site owner, <i>$siteowner</i>");
  235. if (count($siteLevelEditors)) {
  236. printc(" and full editors of this site");
  237. }
  238. printc(".");
  239. printc(" Shown here are only your posts and any replies to your post by <i>$siteowner</i>");
  240. if (count($siteLevelEditors)) {
  241. printc(" and full editors of this site");
  242. }
  243. printc(".");
  244. // show posts, hide author names (Anonymous Discussion)
  245. } else if ($showposts == 1 && $showallauthors == 2) {
  246. printc("Author of posts to this discussion are known only to the site owner, <i>$siteowner</i>. Other participants will not see your name associated with your posts (unless you include it in the subject or body of your post).");
  247. // hide posts, hide authornames (assessment)
  248. } else if ($showposts == 2 && $showallauthors == 2) {
  249. printc("Posts to this assessment are currently viewable only be the site owner, <i>$siteowner</i>. Shown here are only your posts and any replies to your post by <i>$siteowner</i>.");
  250. }
  251. /******************************************************************************
  252. * Summarize discuss/assess settings for site owner
  253. ******************************************************************************/
  254. if ($_SESSION[auser]==$site_owner) {
  255. printc("\n<br />\n<table class='dinfo1' width='90%' align='center'>");
  256. printc("\n\t<tr>\n\t\t<td align='left'>\n\t\t\t<div style='font-size: 12px'>");
  257. printc("\n\t\t\t\t<strong>Current Discussion Settings:</strong>");
  258. printc("\n\t\t\t</div>\n\t\t</td>\n\t</tr>");
  259. printc("\n\t<tr>\n\t\t<td align='left'>\n\t\t\t<div style='font-size: 9px'>");
  260. printc("\n\t\t\t\t<b>Mail Posts:</b>");
  261. if ($mailposts == 1) {
  262. printc(" All posts to this discussion/assessment will be mailed to you.");
  263. } else {
  264. printc(" Email notification of posts to this discussion/assessment has been disabled.");
  265. }
  266. printc("\n\t\t\t</div>\n\t\t</td>\n\t</tr>");
  267. printc("\n\t<tr>\n\t\t<td align='left'>\n\t\t\t<div style='font-size: 9px'>");
  268. if ($showposts == 1) {
  269. $type = "discussion";
  270. printc("<b>Discussion:</b> Participants can read and respond to each other's posts.");
  271. } else {
  272. $type = "assessment";
  273. printc("<b>Assessment:</b> Participants will not be able to read each other's posts.");
  274. }
  275. printc("\n\t\t\t</div>\n\t\t</td>\n\t</tr>");
  276. printc("\n\t<tr>\n\t\t<td align='left'>\n\t\t\t<div style='font-size: 9px'>");
  277. // if showposts == 2 (assessment), info about authors display is not necessary
  278. if ($showallauthors == 2 && $showposts != 2) {
  279. printc("<b>Hide Authors:</b> Authors of posts have been hidden from participants to allow for anonymous discussion (only you can see participant names).");
  280. } else if ($showallauthors == 1 && $showposts != 2) {
  281. printc("<b>Show Authors:</b> Author of each and every post is identified to all participants.");
  282. }
  283. printc("\n\t\t\t</div>\n\t\t</td>\n\t</tr>");
  284. printc("\n\t<tr>\n\t\t<td align='left'>\n\t\t\t<div style='font-size: 9px'><i>To change these settings and determine who can participant in this ".$type.", click on edit link below.</i>\n\t\t\t</div>\n\t\t</td>\n\t</tr>");
  285. printc("\n\t<tr>\n\t\t<td align='right'>\n\t\t\t<div style='font-size: 10px'><a href='index.php?".$editsettingsurl."'>edit</a></div>\n\t\t</td>\n\t</tr>");
  286. printc("\n</table>");
  287. }
  288. /******************************************************************************
  289. * Instantiate a discussion object $ds from objects/discussion.inc.php
  290. * and pass it discussion settings: $order, $showposts, $showallauthors, $mailposts
  291. ******************************************************************************/
  292. $ds = & new discussion($storyObj);
  293. if ($_SESSION['flat_discussion']) {
  294. $ds->flat(); // must be called before _fetchchildren();
  295. } else {
  296. $ds->threaded(); // must be called before _fetchchildren();
  297. }
  298. if ($_REQUEST['order'] == 1) {
  299. $ds->recentfirst();
  300. } else if ($_REQUEST['order'] == 2) {
  301. $ds->recentlast();
  302. } else if ($_REQUEST['order'] == 3) {
  303. $ds->rating();
  304. } else if ($_REQUEST['order'] == 4) {
  305. $ds->author();
  306. } else {
  307. //$ds->recentlast();
  308. }
  309. // printpre($_REQUEST['order']);
  310. /******************************************************************************
  311. * get all discussion posts and order them by $order
  312. * (recent first, recent last, rating, author)
  313. * returns an array of discussion objects
  314. ******************************************************************************/
  315. $ds->_fetchchildren();
  316. /******************************************************************************
  317. * set discussion options
  318. ******************************************************************************/
  319. $ds->opt("showcontent",true);
  320. $ds->opt("showauthor",false);
  321. $ds->opt("showtstamp",false);
  322. $ds->opt("useoptforchildren",true);
  323. $ds->getinfo = $getinfo;
  324. /******************************************************************************
  325. * output all posts that user has permission to view
  326. * using array of posts generated by _fetchchildren
  327. ******************************************************************************/
  328. // Start with default perms
  329. $canReply = $storyObj->hasPermission("discuss");
  330. // Unless everyone is specifically given permission; i.e "anonymous posting" is allowed,
  331. // make sure that the user is logged in.
  332. if ((!$_SESSION[auser] || $_SESSION[atype] == "visitor") && !$storyObj->hasPermission("discuss", "everyone", 1))
  333. $canReply = FALSE;
  334. printc("\n<table width='100%' cellspacing='1'>");
  335. $ds->outputAll($canReply,($_SESSION[auser]==$site_owner),true,$showposts,$showallauthors,$mailposts);
  336. if (!$ds->count()) printc("\n\t<tr>\n\t\t<td>There have been no posts to this discussion.</td>\n\t</tr>");
  337. printc("\n</table>");
  338. }
  339. printc("<table>");
  340. printc("\n\t<tr>\n\t\t<td align='left'>\n\t\t\t<br /><a href='index.php?action=".$action."&amp;".$getinfo2."'>".spchars($pageObj->getField('title'))."</a> &gt; in depth</td>\n\t</tr>");
  341. printc("</table>\n");
  342. function participants() {
  343. global $storyObj;
  344. $storyid = $storyObj->getField("id");
  345. $where = "story_id ='".addslashes( $storyid)."'";
  346. $query = "
  347. SELECT
  348. distinct user_fname, user_email
  349. FROM
  350. discussion
  351. INNER JOIN story ON FK_story = story_id
  352. INNER JOIN page ON FK_page = page_id
  353. INNER JOIN section ON FK_section = section_id
  354. INNER JOIN site ON FK_site = site_id
  355. INNER JOIN user ON FK_author = user_id
  356. WHERE
  357. $where
  358. ";
  359. $r = db_query($query);
  360. $a = db_fetch_assoc($r);
  361. $num = db_num_rows($r);
  362. //$num.= " participants";
  363. return $num;
  364. }
  365. ?>