PageRenderTime 56ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/objects/discussion.inc.php

https://github.com/adamfranco/segue-1.x
PHP | 1103 lines | 687 code | 184 blank | 232 comment | 234 complexity | a3668c25ac0075a3c179cb2a198556d5 MD5 | raw file
  1. <? /* $Id$ */
  2. //echo "bla";
  3. class discussion {
  4. var $storyid,$parentid,$id;
  5. var $detail;
  6. // var $author = array("id"=>0,"uname"=>"","fname"=>"");
  7. var $authorid=0,$authoruname,$authorfname,$authoremail;
  8. var $libraryfilename,$libraryfileid,$media_tag,$media_size;
  9. var $tstamp,$content,$subject,$order;
  10. var $rating = NULL;
  11. var $children=array();
  12. var $numchildren=0,$pointer=-1,$direction=1;
  13. var $flat=false;
  14. var $recent=false;
  15. var $dis_order="recentlast";
  16. var $opt = array(
  17. "showcontent"=>false,
  18. "showsubject"=>true,
  19. "showauthor"=>true,
  20. "showtstamp"=>true,
  21. "useoptforchildren"=>false
  22. );
  23. var $getinfo;
  24. var $storyObj;
  25. /******************************************************************************
  26. * sets discussion options variables from $opt array
  27. ******************************************************************************/
  28. function opt($key,$val=NULL) {
  29. if ($val!=NULL) { // they're setting the option
  30. $this->opt[$key] = $val;
  31. return $val;
  32. }
  33. if (is_array($key)) {
  34. $this->opt = $key;
  35. return true;
  36. }
  37. return $this->opt[$key];
  38. }
  39. /******************************************************************************
  40. * called from fetchchilden, passed $a = array
  41. * (FK_parent,discussion_subject,discussion_id,FK_author,discussion_tstamp,
  42. * discussion_content,discussion_rate,FK_story,media_tag,discussion_order,
  43. * user_uname,user_fname,user_last_name,user_email)
  44. * if discussion posts exist, parse post info from database
  45. * calls _parseDBline which creates discussion post variables for each discussion post
  46. * (discussion posts are displayed by outputAll called from fullstory.inc.php)
  47. ******************************************************************************/
  48. function discussion(& $story,$a=NULL,$parent=0) {
  49. if (is_array($a)) $this->_parseDBline($a);
  50. if (is_numeric($a)) $this->id = $a;
  51. if (is_object($story)) {
  52. $this->storyObj =& $story;
  53. $this->storyid = $story->id;
  54. }
  55. if (is_numeric($story)) $this->storyid = $story;
  56. if ($parent) $this->parentid = $parent;
  57. }
  58. /******************************************************************************
  59. * gets next post
  60. ******************************************************************************/
  61. function getNext() {
  62. $this->pointer+=$this->direction;
  63. // if we're out of range, return false
  64. if (($this->direction > 0 && $this->pointer >= $this->numchildren) || ($this->direction < 0 && $this->pointer <= -1)) return false;
  65. return $this->children[$this->pointer];
  66. }
  67. /******************************************************************************
  68. * delete post
  69. ******************************************************************************/
  70. function _del() {
  71. global $site_owner;
  72. // print "$site_owner";
  73. if ($_SESSION['auser'] != $site_owner && $this->authorid != $_SESSION['aid']) return false;
  74. if (!$this->id) return false;
  75. if ($this->count() || $this->dbcount()) {
  76. $this->_fetchchildren();
  77. for ($i = 0; $i < $this->numchildren; $i++) {
  78. $this->children[$i]->_del();
  79. }
  80. $this->numchildren=0;
  81. }
  82. discussion::delID($this->id);
  83. }
  84. function delID($id) {
  85. // print "deleting $id.<br />";
  86. $query = "
  87. DELETE FROM
  88. discussion
  89. WHERE
  90. discussion_id='".addslashes($id)."'
  91. ";
  92. db_query($query);
  93. //log_entry("discussion","$_SESSION[auser] deleted story ".$_REQUEST['story']." discussion post id ".$_REQUEST['id']." in site ".$_REQUEST['site'],$_REQUEST['site'],$_REQUEST['story'],"story");
  94. // done;
  95. }
  96. /******************************************************************************
  97. * stats on # of posts, last post, timestamp, etc.
  98. ******************************************************************************/
  99. function generateStatistics($story) {
  100. if (is_object($story)) $storyid = $story->id;
  101. if (is_numeric($story)) $storyid = $story;
  102. // get the count:
  103. $count = discussion::getCount($storyid);
  104. if ($count) $lastPostData = discussion::getLastPostData($storyid);
  105. else {return "No posts yet.";}
  106. $posts = ($count==1)?"post":"posts";
  107. $str = '';
  108. $str .= "$count $posts, last post on ";
  109. $str .= timestamp2usdate($lastPostData['timestamp']);
  110. //$str .= ' by ';
  111. //$str .= $lastPostData['fullname'];
  112. return $str;
  113. }
  114. function getCount($storyid) {
  115. $query = "
  116. SELECT
  117. COUNT(*) as count
  118. FROM
  119. discussion
  120. WHERE
  121. FK_story='".addslashes($storyid)."'
  122. ";
  123. $r = db_query($query);
  124. $a = db_fetch_assoc($r);
  125. return $a['count'];
  126. }
  127. function getLastPostData($storyid) {
  128. $query = "
  129. SELECT
  130. user_fname AS fullname,discussion_tstamp AS timestamp
  131. FROM
  132. discussion
  133. INNER JOIN
  134. user
  135. ON
  136. FK_author=user_id
  137. WHERE
  138. FK_story = '".addslashes($storyid)."'
  139. ORDER BY
  140. discussion_tstamp DESC
  141. LIMIT 1
  142. ";
  143. $r = db_query($query);
  144. if (db_num_rows($r)) {
  145. return db_fetch_assoc($r);
  146. }
  147. return null;
  148. }
  149. function rewind() { $this->pointer = -1; }
  150. function reverse() { $this->direction*=-1; }
  151. function setstep($s) { $this->direction=$s; }
  152. function end() { $this->pointer = $this->numchildren; }
  153. function startfrombeginning() { $this->rewind(); $this->setstep(1); }
  154. function startfromend() { $this->end(); $this->setstep(-1); }
  155. /******************************************************************************
  156. * flat or threaded
  157. ******************************************************************************/
  158. function flat() { $this->flat = true; }
  159. function threaded() { $this->flat = false; }
  160. /******************************************************************************
  161. * discussion sort order
  162. ******************************************************************************/
  163. function recentfirst() { $this->dis_order = "recentfirst"; }
  164. function recentlast() { $this->dis_order = "recentlast"; }
  165. function rating() { $this->dis_order = "rating"; }
  166. function author() { $this->dis_order = "author"; }
  167. /******************************************************************************
  168. * number of posts (children)
  169. ******************************************************************************/
  170. function count() { return $this->numchildren; }
  171. function dbcount() {
  172. if ($this->numchildren) return $this->numchildren;
  173. $query = "
  174. SELECT
  175. COUNT(*) as count
  176. FROM
  177. discussion
  178. WHERE
  179. FK_story='".addslashes($this->storyid)."'"
  180. .(($this->id)?" and FK_parent='".addslashes($this->id)."'":"");
  181. $r = db_query($query);
  182. $a = db_fetch_assoc($r);
  183. return $a['count'];
  184. }
  185. function fetchID($id) {
  186. $this->id = $id;
  187. $this->_fetch();
  188. }
  189. function fetch() { $this->_fetch(); }
  190. function fetchchildren() { $this->_fetchchildren(); }
  191. /******************************************************************************
  192. * called from discussion
  193. * parses DB line from query for discussion post info
  194. * creates $_f array of discussion post variables:
  195. * (FK_parent,discussion_subject,discussion_id,FK_author,discussion_tstamp,
  196. * discussion_content,discussion_rate,FK_story,media_tag,discussion_order,
  197. * user_uname,user_fname,user_last_name,user_email)
  198. * creates variables for each item in $_f array
  199. ******************************************************************************/
  200. function _parseDBline($a) {
  201. $_f = array("discussion_subject"=>"subject","FK_parent"=>"parentid","FK_author"=>"authorid","FK_story"=>"storyid","media_tag"=>"media_tag","media_size"=>"media_size","discussion_id"=>"id","discussion_tstamp"=>"tstamp","discussion_content"=>"content","discussion_rate"=>"rating","discussion_order"=>"order","user_uname"=>"authoruname","user_fname"=>"authorfname","user_email"=>"authoremail");
  202. foreach ($_f as $f=>$v) {
  203. if (isset($a[$f])) $this->$v = $a[$f];
  204. }
  205. if ($this->content) $this->content = urldecode($this->content);
  206. if ($this->subject) $this->subject = urldecode($this->subject);
  207. // :: hack for anonymous posts
  208. if (!$this->authorfname) {
  209. $this->authorfname = $this->authoruname = "Anonymous";
  210. $this->authorid = 0;
  211. }
  212. }
  213. /******************************************************************************
  214. * not sure when this is called...?
  215. ******************************************************************************/
  216. function _fetch() {
  217. if (!$this->id) return false;
  218. $query = "
  219. SELECT
  220. discussion_tstamp,discussion_content,discussion_subject,discussion_rate,user_uname,user_fname,FK_story,FK_author,FK_parent,media_tag,media_size
  221. FROM
  222. discussion
  223. INNER JOIN
  224. user
  225. ON
  226. FK_author = user_id
  227. LEFT JOIN
  228. media
  229. ON
  230. FK_media = media_id
  231. WHERE
  232. discussion_id='".addslashes($this->id)."'
  233. ";
  234. $r = db_query($query);
  235. $a = db_fetch_assoc($r);
  236. $this->_parseDBline($a);
  237. return true;
  238. }
  239. /******************************************************************************
  240. * get all discussion posts
  241. ******************************************************************************/
  242. function _fetchchildren() {
  243. if (!$this->storyid) return false;
  244. if ($this->numchildren) return false; // they've already called _fetchchildren();
  245. $this->_commithttpdata();
  246. if ($this->dis_order == "recentfirst") {
  247. $order = " discussion_tstamp DESC";
  248. } else if ($this->dis_order == "recentlast") {
  249. $order = " discussion_tstamp ASC";
  250. } else if ($this->dis_order == "rating") {
  251. $order = " discussion_rate DESC";
  252. } else if ($this->dis_order == "author") {
  253. $order = " user_fname ASC";
  254. }
  255. //$order = " discussion_rate DESC";
  256. // printpre($order);
  257. $query = "
  258. SELECT
  259. FK_parent,discussion_subject,discussion_id,FK_author,discussion_tstamp,discussion_content,discussion_rate,FK_story,media_tag,media_size,discussion_order,user_uname,user_fname,user_last_name,user_email
  260. FROM
  261. discussion
  262. LEFT JOIN
  263. user
  264. ON
  265. FK_author = user_id
  266. LEFT JOIN
  267. media
  268. ON
  269. FK_media = media_id
  270. WHERE
  271. FK_story = '".addslashes($this->storyid)."' ".
  272. // check if we're not top-level - if !flat disc, fetch all children, otherwise fetch all discussions
  273. (($this->flat)?"":" and FK_parent<=>".(($this->id)?"'".addslashes($this->id)."'":"NULL"))."
  274. ORDER BY
  275. ".$order;
  276. //print $query;
  277. $r = db_query($query);
  278. /******************************************************************************
  279. * instantiate a discussion object for each post (child) to this story's discussion
  280. * pass discussion object $a = array of discussion posts
  281. * (FK_parent,discussion_subject,discussion_id,FK_author,discussion_tstamp,
  282. * discussion_content,discussion_rate,FK_story,media_tag,discussion_order,
  283. * user_uname,user_fname,user_last_name,user_email)
  284. ******************************************************************************/
  285. while($a = db_fetch_assoc($r)) {
  286. if ($this->storyObj)
  287. $this->children[] = &new discussion($this->storyObj,$a);
  288. else
  289. $this->children[] = &new discussion($this->storyid,$a);
  290. $this->numchildren++;
  291. }
  292. return true;
  293. }
  294. /******************************************************************************
  295. * insert new posts into discussion table
  296. ******************************************************************************/
  297. function _insert() {
  298. $query = "
  299. SELECT
  300. COUNT(*) as count
  301. FROM
  302. discussion
  303. WHERE
  304. FK_story='".addslashes($this->storyid)."'
  305. ";
  306. $a = db_fetch_assoc(db_query($query));
  307. $this->order = $a['count'];
  308. $query = "
  309. INSERT INTO
  310. discussion
  311. SET
  312. ".$this->_generateSQLdata();
  313. // If we've set a timestamp before saving, we probably want to keep it.
  314. //if ($this->tstamp) $query .= ",discussion_tstamp='".$this->tstamp."'";
  315. db_query($query);
  316. //printc($query);
  317. $this->id = lastid();
  318. return $this->id;
  319. }
  320. /******************************************************************************
  321. * update posts in discussion table
  322. ******************************************************************************/
  323. function _update() {
  324. if (!$this->id) return false;
  325. $query = "
  326. UPDATE
  327. discussion
  328. SET
  329. ".$this->_generateSQLdata()."
  330. WHERE
  331. discussion_id='".addslashes($this->id)."'
  332. ";
  333. // printc ($query);
  334. db_query($query);
  335. //$newid = lastid();
  336. return true;
  337. }
  338. function insert() {
  339. $newid = $this->_insert();
  340. return $newid;
  341. }
  342. function update() { $this->_update(); }
  343. function _generateSQLdata() {
  344. $query = "FK_author=".$this->authorid;
  345. if ($this->parentid) $query .= ",FK_parent=".$this->parentid;
  346. if ($this->libraryfileid) {
  347. $media_id = $this->libraryfileid;
  348. $query .= ",FK_media=".$media_id;
  349. }
  350. $query .= ",discussion_content='".urlencode(stripslashes($this->content))."'";
  351. $query .= ",discussion_subject='".urlencode(stripslashes($this->subject))."'";
  352. if (is_numeric($this->rating)) {
  353. $query .= ",discussion_rate=".$this->rating;
  354. } else {
  355. $query .= ",discussion_rate=NULL";
  356. }
  357. $query .= ",FK_story=".$this->storyid;
  358. // If we've set a timestamp before saving, we probably want to keep it.
  359. if ($this->tstamp) $query .= ",discussion_tstamp='".$this->tstamp."'";
  360. //if ($this->order) $query .= $this->order;
  361. return $query;
  362. }
  363. /******************************************************************************
  364. * Threaded dicussion: outputs new post link and calls _output function
  365. * for all children of current post
  366. * $cr=can reply (ie has permission), $o=owner, $top=parent
  367. ******************************************************************************/
  368. function outputAll($cr=false,$o=false,$top=false,$showposts=1,$showallauthors=1,$mailposts=0) {
  369. global $sid,$content, $cfg;
  370. // debug
  371. // print "outputAll($canreply,$owner,$copt)<br />";
  372. // spider down and output every one
  373. if ($top) {
  374. // print_r($this->storyObj->permissions);
  375. // $cand = $this->storyObj->hasPermission("discuss");
  376. $newpostbar='';
  377. $newpostbar.="<tr><td>\n";
  378. /******************************************************************************
  379. * if user can reply (cr) (ie has permission
  380. ******************************************************************************/
  381. if ($cr) {
  382. // just in case...
  383. $this->_commithttpdata();
  384. printc ("<tr><td>\n");
  385. printerr2();
  386. printc ("</td></tr>\n");
  387. if ($_REQUEST['discuss'] == 'newpost' && ($cfg['disable_discussion'] != TRUE || $_SESSION['ltype'] == 'admin')) {
  388. $this->_outputform('newpost');
  389. } else {
  390. //$newpostbar='';
  391. //$newpostbar.="<tr><td align='right'>";
  392. if (!$_SESSION[auser] && $showposts != 1) {
  393. $newpostbar.="You must be logged in to do this assessment.\n";
  394. } else {
  395. if ($cfg['disable_discussion'] == TRUE && $_SESSION['ltype'] != 'admin') {
  396. $newpostbar.="<div align='right'>Discussion posting has been disabled</div>";
  397. } else {
  398. $newpostbar.="<div align='right'><a href='".$_SERVER['SCRIPT_NAME']."?$sid&amp;".$this->getinfo."&amp;action=site&amp;discuss=newpost#new'>new post</a></div>\n";
  399. }
  400. }
  401. // $newpostbar.="</td></tr>";
  402. }
  403. /******************************************************************************
  404. * if user doesn't have permission....
  405. ******************************************************************************/
  406. } else {
  407. if (!$_SESSION[auser]) {
  408. $newpostbar.="You must be logged in to contribute to this discussion.\n";
  409. } else {
  410. $newpostbar.="Only specified groups or individuals can participant.\n";
  411. }
  412. }
  413. $newpostbar.="</td></tr>\n";
  414. printc ($newpostbar);
  415. }
  416. /******************************************************************************
  417. * output a discussion post
  418. ******************************************************************************/
  419. if ($this->id) $this->_output($cr,$o);
  420. /******************************************************************************
  421. * output all discussion of current post's thread (children)
  422. ******************************************************************************/
  423. $this->_outputChildren($cr,$o,(($top)?$this->opt:NULL));
  424. if ($this->numchildren && $showposts == 1) printc ($newpostbar);
  425. }
  426. /******************************************************************************
  427. * Threaded discussion: calls _fetchchildren to get all threads of current post
  428. * for each post (child) calls outputAll (threaded) or _output (flat) to display
  429. ******************************************************************************/
  430. function _outputChildren($cr,$o,$opt=NULL) {
  431. $this->_fetchchildren();
  432. if ($this->numchildren) {
  433. if (is_array($opt)) $p = 0;
  434. else $p = 1;
  435. if ($p) {
  436. printc ("<tr><td style='padding: 0px'><table align='right' width='95%' style='padding-left:".$p."px' cellspacing='0px'>\n");
  437. } else {
  438. printc ("<tr><td style='padding: 0px'><table width='100%' style='padding-left:".$p."px' cellspacing='0px'>\n");
  439. }
  440. for ($i=0;$i<$this->numchildren;$i++) {
  441. if (is_array($opt)) $this->children[$i]->opt($opt);
  442. if ($this->opt("useoptforchildren")) $this->children[$i]->opt($this->opt);
  443. $this->children[$i]->getinfo = $this->getinfo;
  444. if ($this->flat)
  445. $this->children[$i]->_output($cr,$o);
  446. else
  447. $this->children[$i]->outputAll($cr,$o);
  448. }
  449. printc ("</table></td></tr>\n");
  450. }
  451. }
  452. /******************************************************************************
  453. * outputs discussion table
  454. ******************************************************************************/
  455. function output($canreply=false,$owner=false) {
  456. // print a small table that will house the discussion
  457. printc ("<table width='100%' style='padding:0' cellspacing='0px'>\n");
  458. $this->_output($canreply,$owner);
  459. printc ("</table>\n");
  460. }
  461. /******************************************************************************
  462. * commits data from posting form
  463. ******************************************************************************/
  464. function _commithttpdata() {
  465. global $sid,$error,$_full_uri;
  466. global $mailposts, $cfg;
  467. //require_once("htmleditor/editor.inc.php");
  468. if ($_REQUEST['commit'] && ($cfg['disable_discussion'] != TRUE || $_SESSION['ltype'] == 'admin')) { // indeed, we are supposed to commit
  469. $site = $_REQUEST['site'];
  470. $action = $_REQUEST['action'];
  471. $a = $_REQUEST['discuss'];
  472. if (!$_REQUEST['subject']) error("You must enter a subject.\n");
  473. if (!$_REQUEST['content']) error("You must enter some text to post.\n");
  474. if (isset($_REQUEST['rating']) && !is_numeric($_REQUEST['rating']) && $_REQUEST['rating'] != "") $error = "Post rating must be numeric.\n";
  475. if ($error) { unset($_REQUEST['commit']); return false; }
  476. /******************************************************************************
  477. * if public discussion and no log in then add user to user table
  478. * uname = email address, type = visitor
  479. ******************************************************************************/
  480. if (!$_SESSION[auser]) {
  481. if (user::userEmailExists($_REQUEST['visitor_email'])) {
  482. error("A user with that email address already exists. Please log in before posting.");
  483. }
  484. /******************************************************************************
  485. * Visitor account validation:
  486. * check that a name has been entered
  487. * check that the email enter doesn't already exist in Segue and
  488. * is not part of the $cfg[visitor_email_excludes] specified in the config
  489. ******************************************************************************/
  490. if (!$_REQUEST['visitor_name']) error("You must enter a username.");
  491. if (!$_REQUEST['visitor_email'] || !ereg("@", $_REQUEST['visitor_email'])) {
  492. error("You must enter a valid email address.");
  493. } else if ($_REQUEST['visitor_email'] ) {
  494. foreach ($cfg[visitor_email_excludes] as $visitor_email_exclude) {
  495. if ($exclude = ereg($visitor_email_exclude, $_REQUEST['visitor_email'])) {
  496. error("Please log in above with your $cfg[inst_name] account.");
  497. }
  498. }
  499. }
  500. // all good
  501. if (!$error) {
  502. $obj = &new user();
  503. $obj->uname = $_REQUEST['visitor_email'];
  504. $obj->fname = $_REQUEST['visitor_name'];
  505. $obj->email = $_REQUEST['visitor_email'];
  506. $obj->type = "visitor";
  507. $obj->authtype = 'db';
  508. $obj->randpass(5,3);
  509. $obj->insertDB();
  510. $obj->sendemail();
  511. $visitor_id = lastid();
  512. }
  513. }
  514. if ($error) { unset($_REQUEST['commit']); return false; }
  515. if ($a=='edit') {
  516. $d = & new discussion($_REQUEST['story']);
  517. $d->fetchID($_REQUEST['id']);
  518. if ($_SESSION['auser'] != $d->authoruname) return false;
  519. $d->subject = $_REQUEST['subject'];
  520. $d->content = cleanEditorText($_REQUEST['content']);
  521. $d->content = convertInteralLinksToTags($site, $d->content);
  522. $d->update();
  523. //log_entry("discussion","$_SESSION[auser] edited story ".$_REQUEST['story']." discussion post id ".$_REQUEST['id']." in site ".$_REQUEST['site'],$_REQUEST['site'],$_REQUEST['story'],"story");
  524. unset($_REQUEST['discuss'],$_REQUEST['commit']);
  525. //unset($d);
  526. }
  527. if ($a=='rate') {
  528. $d = & new discussion($_REQUEST['story']);
  529. $d->fetchID($_REQUEST['id']);
  530. $d->rating = $_REQUEST['rating'];
  531. $d->update();
  532. //log_entry("discussion","$_SESSION[auser] edited story ".$_REQUEST['story']." discussion post id ".$_REQUEST['id']." in site ".$_REQUEST['site'],$_REQUEST['site'],$_REQUEST['story'],"story");
  533. unset($_REQUEST['discuss'],$_REQUEST['commit']);
  534. // unset($d);
  535. }
  536. if ($a=='reply'|| $a=='newpost') {
  537. $d = & new discussion($_REQUEST['story']);
  538. $d->subject = $_REQUEST['subject'];
  539. // Lets pass the cleaning of editor text off to the editor.
  540. $d->content = cleanEditorText($_REQUEST['content']);
  541. $d->content = convertInteralLinksToTags($site, $d->content);
  542. if ($a=='reply') {
  543. $d->parentid = $_REQUEST['replyto'];
  544. //log_entry("discussion","$_SESSION[auser] replied to story ".$_REQUEST['story']." discussion post id ".$_REQUEST['replyto']." in site ".$_REQUEST['site'],$_REQUEST['site'],$_REQUEST['story'],"story");
  545. } else {
  546. //log_entry("discussion","$_SESSION[auser] posted to story ".$_REQUEST['story']." discussion in site ".$_REQUEST['site'],$_REQUEST['site'],$_REQUEST['story'],"story");
  547. }
  548. $d->authorid = ($_SESSION['aid'])?$_SESSION['aid']:$visitor_id;
  549. $d->authorfname = ($_SESSION['afname'])?$_SESSION['afname']:$_REQUEST['visitor_name'];
  550. $d->libraryfileid = $_REQUEST['libraryfileid'];
  551. $newid = $d->insert();
  552. }
  553. /******************************************************************************
  554. * gather data for sendmail function
  555. ******************************************************************************/
  556. if ($mailposts == 1) {
  557. //printpre("email sending...");
  558. $this->sendemail($newid);
  559. }
  560. unset($_REQUEST['discuss'],$_REQUEST['commit']);
  561. }
  562. }
  563. /******************************************************************************
  564. * outputs posting form (new post, edit, reply)
  565. * add editor options here...
  566. ******************************************************************************/
  567. function _outputform($t) { // outputs a post form of type $t (newpost,edit,reply)
  568. global $sid,$error,$site_owner,$_full_uri, $cfg;
  569. //$script = $_SERVER['SCRIPT_NAME'];
  570. //printpre ("fulluri: ".$_full_uri);
  571. //printpre ("thisinfo: ".$this->getinfo);
  572. if ($t == 'edit') {
  573. $b = 'update';
  574. $d = "You are editing your post &quot;<a name='".$this->id."'>".$this->subject."</a>&quot;\n";
  575. $c = ($_REQUEST['content'])?$_REQUEST['content']:$this->content;
  576. $s = ($_REQUEST['subject'])?$_REQUEST['subject']:$this->subject;
  577. }
  578. if ($t == 'reply' || $t == 'newpost') {
  579. $b = 'post';
  580. $d = "<a name='new'>You are posting a new entry.</a>\n";
  581. $c = $_REQUEST['content'];
  582. if ($t == 'reply') {
  583. $d = "You are replying to &quot;<a name='reply' href='#'".$this->id.">".$this->subject."</a>&quot;";
  584. if (!$_REQUEST['subject'] && !ereg("^Re:",$this->subject))
  585. $s = "Re: ". $this->subject;
  586. else $s = $this->subject;
  587. }
  588. else $s = $_REQUEST['subject'];
  589. }
  590. if ($t == 'rate') {
  591. $b = 'rate';
  592. //$d = "<a name='".$this->id."'>You are editing your post &quot;".$this->subject."&quot;</a>";
  593. $s = ($_REQUEST['subject'])?$_REQUEST['subject']:$this->subject;
  594. $a = "by <span class='subject'>".$this->authorfname."</span>\n";
  595. $a .= " posted on ";
  596. $a .= timestamp2usdate($this->tstamp);
  597. $c = ($_REQUEST['content'])?$_REQUEST['content']:$this->content;
  598. }
  599. $p = ($t=='reply')?" style='padding-left: 15px'":'';
  600. printc ("\n<form action='".$_full_uri."/index.php?$sid&amp;action=site&amp;".$this->getinfo."#".$this->id."' method='post' name='addform'>\n");
  601. printc ("<tr><td$p><b>$d</b></td></tr>\n");
  602. printc ("<tr><td$p>\n");
  603. printc ("<table width='100%' cellspacing='0px'>\n");
  604. if ($t == 'rate') {
  605. //printc ("Subject: <input type='text' size='50' name='subject' value='".spchars($s)."' readonly />");
  606. if ($this->rating && isnumeric($this->rating)) {
  607. $rating_value = $this->rating;
  608. } else {
  609. $rating_value = "";
  610. }
  611. printc ("<td class='dheader3'>\n");
  612. printc ("<table width='100%' cellspacing='0px'>\n");
  613. printc ("<tr><td align='left'>\n");
  614. printc ("<span class='subject'><a name='".$this->id."'>\n");
  615. printc ($s);
  616. printc ("</a><input type='hidden' name='subject' value='".spchars($s)."' />\n");
  617. printc (" (<input type='text' size='3' class='textfield small' name='rating' value='".$rating_value."' />\n");
  618. printc("<input type='submit' class='button small' value='rate' />");
  619. printc(" <a href='".$_full_uri."/index.php?$sid&amp;action=site&amp;".$this->getinfo."#".$this->id."'><input type='button' class='button small' value='cancel' /></a>\n");
  620. printc(" numeric only");
  621. printc(")\n");
  622. printc ("</span></td>\n");
  623. printc ("<td align='right'></td>\n");
  624. printc ("</tr><tr>\n");
  625. printc ("<td align='left'>\n");
  626. printc ($a);
  627. if ($this->media_tag) {
  628. $media_link = "<a href='".$uploadurl."/".$_REQUEST[site]."/".$this->media_tag."' target='media'>".$this->media_tag."</a>\n";
  629. printc ("<br />attached: $media_link\n");
  630. }
  631. printc ("</td>\n");
  632. printc ("<td align='right' valign='bottom'></td></tr>\n");
  633. printc("</table>\n");
  634. printc ("</td>\n");
  635. } else {
  636. printc ("<tr><td align='left'>\n");
  637. printc ("<table>");
  638. /******************************************************************************
  639. * If public discussion and not logged in
  640. * add fields for visitor name and email
  641. ******************************************************************************/
  642. if (!$_SESSION[auser]) {
  643. printc ("<tr><td colspan = 2><div style='font-size: 9px'>If you part of the ".$cfg[inst_name]);
  644. printc (" community or have posted to a public forum here and received a visitor user account, please log in <b>before</b> posting.");
  645. printc (" If you do not yet have a user account, please register below.</div></td></tr>\n");
  646. //printc ("<tr><td>Full Name:</td><td><input type='text' size='50' name='visitor_name' value='".$_REQUEST['visitor_name']."' /></td></tr>\n");
  647. //printc ("<tr><td>Email:</td><td><div style='font-size: 9px'><input type='text' size='25' name='visitor_email' value='".$_REQUEST['visitor_email']."' />\n");
  648. printc ("<tr><td colspan = 2 align = center><div style='font-size: 10px'>");
  649. printc ("<a href='passwd.php?action=login' target='password' onclick='doWindow(\"password\",400,300)'>Login</a> | ");
  650. printc ("<a href='passwd.php?action=register' target='password' onclick='doWindow(\"password\",400,300)'>Register</a> | ");
  651. printc ("<a href='passwd.php?action=reset' target='password' onclick='doWindow(\"password\",400,300)'>Forget your password?</a></div>");
  652. printc ("</td></tr>");
  653. }
  654. if ($_SESSION[auser]) {
  655. printc ("<tr><td>Subject:</td><td><input type='text' class='textfield small' size='50' name='subject' value='".spchars($s)."' /></td></tr>\n");
  656. // printc ("<tr><td></td><td></td></tr>\n");
  657. }
  658. printc ("</table>\n");
  659. }
  660. printc ("</td><td align='right'>\n");
  661. // if not rate, print edit, update or post
  662. if ($t != 'rate' && $_SESSION[auser]) {
  663. printc("<input type='submit' class='button small' value='$b' />\n");
  664. printc("<a href='".$_full_uri."/index.php?$sid&amp;action=site&amp;".$this->getinfo."#".$this->id."'><input type='button' class='button small' value='cancel' /></a>\n");
  665. }
  666. printc ("</td></tr></table>\n");
  667. printc ("</td></tr>\n");
  668. // print out post content
  669. //printc ("<tr><td class='content$p'>");
  670. /******************************************************************************
  671. * print out editor here... (if editing post or adding new or not rating)
  672. ******************************************************************************/
  673. if ($t != 'rate' && $_SESSION[auser]) {
  674. printc ("<td class='content$p'>\n");
  675. $c = convertTagsToInteralLinks ($_REQUEST[site], $c);
  676. addeditor ("content",60,20,$c,"discuss");
  677. } else {
  678. printc ("<td>".$c."<br /><br />\n");
  679. printc ("<input type='hidden' name='content' value='".$c."' />\n");
  680. }
  681. /******************************************************************************
  682. * print hidden fields
  683. ******************************************************************************/
  684. printc ("<input type='hidden' name='discuss' value='".$_REQUEST['discuss']."' />\n");
  685. //added fullstory action for posting form
  686. printc ("<input type='hidden' name='action' value='".$_REQUEST['action']."' />\n");
  687. //added site variable for discussion logging
  688. printc ("<input type='hidden' name='site' value='".$_REQUEST['site']."' />\n");
  689. printc ("<input type='hidden' name='libraryfileid' value='".$_REQUEST['libraryfileid']."' />\n");
  690. printc ("<input type='hidden' name='dis_order' value='".$this->dis_order."' />\n");
  691. printc ("<input type='hidden' name='commit' value='1' />\n");
  692. if ($t=='edit' || $t=='rate') printc ("<input type='hidden' name='id' value=".$_REQUEST['id']." />\n");
  693. if ($t=='reply') printc ("<input type='hidden' name='replyto' value=".$_REQUEST['replyto']." />\n");
  694. $site = $_REQUEST[site];
  695. /******************************************************************************
  696. * print file upload UI
  697. ******************************************************************************/
  698. if ($t != 'rate' && $_SESSION[auser]) {
  699. printc ("<br />Upload a File:<input type='text' class='textfield small' name='libraryfilename' value='".$_REQUEST['libraryfilename']."' size='25' readonly />\n<input type='button' class='button small' name='browsefiles' value='Browse...' onclick='sendWindow(\"filebrowser\",700,600,\"filebrowser.php?site=$site&amp;source=discuss&amp;owner=$site_owner&amp;editor=none\")' target='filebrowser' style='text-decoration: none' />\n\n");
  700. if ($_SESSION['aid']) printc ("<br />You will be able to edit your post as long as no-one replies to it.\n");
  701. else printc ("<br />Once submitted, you will not be able to modify your post.\n");
  702. }
  703. printc ("</form>\n");
  704. printc ("</td></tr>\n");
  705. }
  706. /******************************************************************************
  707. * determines what kind of output to do (edit, del) and what to display
  708. ******************************************************************************/
  709. function _output($cr,$o) {
  710. global $sid,$error,$showallauthors,$showposts,$uploadurl,$site_owner,$_full_uri;
  711. $siteOwnerId = db_get_value("user","user_id","user_uname='".addslashes($site_owner)."'");
  712. $parentAuthorId = db_get_value("discussion","FK_author","discussion_id='".addslashes($this->parentid)."'");
  713. //print $siteOwnerId;
  714. //printc("author=".$parentAuthorId);
  715. $siteObj =& $this->storyObj->owningSiteObj;
  716. $siteLevelEditors = $siteObj->getSiteLevelEditors();
  717. $isSiteEditor = in_array($_SESSION[auser], $siteLevelEditors);
  718. if (
  719. // Discussion mode, not assement
  720. $showposts == 1
  721. // In assemment mode and one of the users that can view this post
  722. || (
  723. // You are the author of the post
  724. ($_SESSION[auser] == $this->authoruname
  725. // you are the site_owner
  726. || $o == 1
  727. // you are a site-level editor
  728. || $isSiteEditor
  729. // This is a reply to your post by the site owner
  730. || ($site_owner == $this->authoruname && $_SESSION[aid] == $parentAuthorId && $_SESSION[auser])
  731. // This is a reply to your post by a site-level editor
  732. || (in_array($this->authoruname, $siteLevelEditors) && $_SESSION[aid] == $parentAuthorId && $_SESSION[auser])
  733. )
  734. )) {
  735. // check to see if we have any info to commit
  736. $this->_commithttpdata();
  737. if ($_REQUEST['discuss'] == 'edit' && $_REQUEST['id'] == $this->id) {
  738. $this->_outputform('edit');
  739. return true;
  740. }
  741. if ($_REQUEST['discuss'] == 'del' && $_REQUEST['id'] == $this->id) {
  742. $this->_del();
  743. return true;
  744. }
  745. if ($_REQUEST['discuss'] == 'rate' && $_REQUEST['id'] == $this->id) {
  746. $this->_outputform('rate');
  747. return true;
  748. }
  749. //$script = $_SERVER['SCRIPT_NAME'];
  750. /******************************************************************************
  751. * Outputs html for displaying posts
  752. * outputs discussion post info
  753. ******************************************************************************/
  754. if (!$this->id) return false;
  755. printc ("\n<tr>");
  756. $s = "<a href='".$_full_uri."/index.php?$sid&amp;action=site&amp;".$this->getinfo."&amp;expand=".$this->id."' name='".$this->id."'>".$this->subject."</a>\n";
  757. // printc ("</form>");
  758. // $s = $this->subject;
  759. //printpre($_SESSION);
  760. $a = "";
  761. if ($showallauthors == 1 || ($_SESSION[auser] && ($o || $_SESSION[auser] == $this->authoruname || $site_owner == $this->authoruname && $_SESSION[aid] == $parentAuthorId))) {
  762. if ($this->opt("showauthor")) $a .= "by <span class='subject'>".$this->authorfname."</span>\n";
  763. if ($this->opt("showauthor") && $this->opt("showtstamp")) $a .= " on ";
  764. } else {
  765. $a .= "posted on ";
  766. }
  767. if ($this->opt("showtstamp")) $a .= timestamp2usdate($this->tstamp);
  768. // Wiki-markup example
  769. global $storyObj;
  770. $a .= WikiResolver::getMarkupExample($storyObj->getField("title"), $this->id);
  771. /******************************************************************************
  772. * collect possible actions to current post (rely | del | edit | rate)
  773. ******************************************************************************/
  774. $b = array();
  775. if ($cfg['disable_discussion'] != TRUE && ($cfg['disable_discussion'] != TRUE && $_SESSION['ltype'] == 'admin')) {
  776. if ($cr)
  777. $b[] = "<a href='".$_full_uri."/index.php?$sid".$this->getinfo."&amp;replyto=".$this->id."&amp;action=site&amp;discuss=reply#reply'>reply</a>\n";
  778. if ($o || ($_SESSION[auser] == $this->authoruname && !$this->dbcount()))
  779. $b[] = "| <a href='".$_full_uri."/index.php?$sid".$this->getinfo."&amp;action=site&amp;discuss=del&amp;id=".$this->id."'>delete</a>\n";
  780. if ($_SESSION[auser] == $this->authoruname && !$this->dbcount())
  781. $b[] = " | <a href='".$_full_uri."/index.php?$sid".$this->getinfo."&amp;id=".$this->id."&amp;action=site&amp;discuss=edit#".$this->id."'>edit</a>\n";
  782. if ($o)
  783. $ratelink = "<a href='".$_full_uri."/index.php?$sid".$this->getinfo."&amp;id=".$this->id."&amp;action=site&amp;discuss=rate#".$this->id."'>rate</a>\n";
  784. }
  785. /******************************************************************************
  786. * if there are dicussion actions (reply | del | edit | rate) then print
  787. ******************************************************************************/
  788. if ($a != "" || count($b)) {
  789. $c = '';
  790. if (count($b)) $c .= implode(" ",$b);
  791. /******************************************************************************
  792. * discussion post header info (subject=$s, author and timestamp=$a, options=$c)
  793. ******************************************************************************/
  794. //printc ("<table width='100%' cellspacing='0px'>\n");
  795. printc ("\n<td class='dheader3'>\n");
  796. printc ("<table width='100%' cellspacing='0px'>\n");
  797. printc ("<tr><td align='left'>\n");
  798. printc ("<span class='subject'>\n");
  799. // subject
  800. printc ($s);
  801. // rating
  802. if ($this->rating !== NULL)
  803. printc (" (Rating: ".$this->rating.")");
  804. printc ("</span></td>\n");
  805. // link for rating
  806. printc ("<td align='right'>$ratelink</td>\n");
  807. printc ("</tr><tr>\n");
  808. printc ("<td>$a\n");
  809. printc ("</td>\n");
  810. printc ("<td align='right' valign='bottom'>$c</td>");
  811. printc("</tr>\n</table>\n");
  812. /******************************************************************************
  813. * if there are no dicussion actions (rely | del | edit | rate) then
  814. * print subject only
  815. ******************************************************************************/
  816. } else printc ($s);
  817. printc ("</td></tr>");
  818. /******************************************************************************
  819. * print discussion post content
  820. ******************************************************************************/
  821. if ($this->opt("showcontent")) {
  822. printc ("<tr><td class='dtext'>");
  823. if ($this->media_tag) {
  824. $media_link = "<a href='".$uploadurl."/".$_REQUEST[site]."/".$this->media_tag."' target='media'>".$this->media_tag."</a>\n";
  825. $mediaRow[media_tag] = $this->media_tag;
  826. $mediaRow[slot_name] = $_REQUEST[site];
  827. $mediaRow[media_size] = $this->media_size;
  828. $audioplayer = printMediaPlayer($mediaRow);
  829. $downloadlink = printDownloadLink($mediaRow);
  830. // $citation = printCitation($mediaRow);
  831. // if attached file is an .mp3 print out audio player
  832. if ($audioplayer) {
  833. printc ("<table width='100%' cellpadding='2' border='0'>");
  834. printc ("<tr><td>");
  835. printc ($downloadlink."\n");
  836. printc ($audioplayer."\n");
  837. // printc ("<div style='clear: left; font-size: smaller; margin-bottom: 10px; '>");
  838. // printc ($citation."\n");
  839. // printc ("</div>");
  840. printc ("</td></tr>");
  841. printc ("</table>");
  842. // if attached file not .mp3 print out download link only
  843. } else {
  844. printc ("<table width='100%' cellpadding='2' border='0'>");
  845. printc ("<tr><td>");
  846. printc ("<div style='clear: left; float: left; '>$media_link</div>\n");
  847. printc ($downloadlink."\n");
  848. printc ("</td></tr>");
  849. printc ("</table>");
  850. }
  851. }
  852. $content = convertTagsToInteralLinks ($_REQUEST[site], stripslashes($this->content));
  853. $wikiResolver =& WikiResolver::instance();
  854. $content = $wikiResolver->parseText($content, $_REQUEST[site], $_REQUEST[section],$_REQUEST[page]);
  855. printc ("<div style='clear: both;'>\n");
  856. printc($content);
  857. printc ("</div>\n");
  858. //printc ("- [ $c]</td></tr>\n");
  859. //printc ("<tr><td align='right'>$c</td></tr>\n");
  860. }
  861. // done
  862. // now check if we're replying to this post
  863. if ($_REQUEST['discuss'] == 'reply' && $_REQUEST['replyto'] == $this->id) $this->_outputform('reply');
  864. //if ($_REQUEST['discuss'] == 'rate' && $_REQUEST['replyto'] == $this->id) $this->_outputform('rate');
  865. printc ("</td></tr>");
  866. }
  867. }
  868. /******************************************************************************
  869. * Emails site owner discussion posts
  870. ******************************************************************************/
  871. function sendemail($newid=0,$emaillist=0) {
  872. global $sid,$error;
  873. global $_full_uri;
  874. //printpre("email sending...");
  875. //$script = $_SERVER['SCRIPT_NAME'];
  876. $site =& new site($_REQUEST[site]);
  877. $siteowneremail = $site->owneremail;
  878. $siteownerfname = $site->ownerfname;
  879. $sitetitle = $site->title;
  880. $pageObj =& new page($_REQUEST[site],$_REQUEST[section],$_REQUEST[page], $sectionObj);
  881. $pagetitle = $pageObj->getField('title');
  882. $storyObj =& new story($_REQUEST[site],$_REQUEST[section],$_REQUEST[page],$_REQUEST[story], $pageObj);
  883. $storytext = $storyObj->getField('shorttext');
  884. // send an email to the siteowner
  885. $html = 1;
  886. $emaillist = array();
  887. $subject = "Segue: ".$_REQUEST['subject'];
  888. $to = $siteownerfname."<".$siteowneremail.">\n";
  889. //$to = $siteowneremail;
  890. if ($html == 1) {
  891. $from = $_SESSION['afname']."<".$_SESSION['aemail'].">\nContent-Type: text/html\n";
  892. } else {
  893. $from = $_SESSION['afname']."<".$_SESSION['aemail'].">\n";
  894. }
  895. $discussurl = "/index.php?$sid&amp;action=site&amp;site=".$_REQUEST['site']."&amp;section=".$_REQUEST['section']."&amp;page=".$_REQUEST['page']."&amp;story=".$_REQUEST['story']."&amp;detail=".$_REQUEST['detail']."#".$newid;
  896. if ($html == 1) {
  897. $body = $siteownerfname.", There has been a discussion posting from the following Segue site:<br />\n";
  898. $body .= "<a href='".$_full_uri.$discussurl."'>".$sitetitle." > ".$pagetitle."</a><br /><br />\n";
  899. $body .= "<table cellpadding='0' cellspacing='0' border='0'>";
  900. $body .= "<tr><td>subject: </td><td>".$_REQUEST['subject']."</td></tr>\n";
  901. $body .= "<tr><td>author: </td><td>".$_SESSION['afname']."</td></tr></table><br />\n";
  902. $body .= $_REQUEST['content']."<br /><br />\n";
  903. $body .= "For complete discussion, see:<br />";
  904. $body .= "<a href='".$_full_uri.$discussurl."'>".$sitetitle." > ".$pagetitle."</a><br /><br />\n";
  905. } else {
  906. $body = "site: ".$sitetitle."\n";
  907. //$body .= "topic: ".$this->story."\n";
  908. $body .= "subject: ".$_REQUEST['subject']."\n";
  909. $body .= "author: ".$_SESSION['afname']."\n";
  910. $body .= $_REQUEST['content']."\n\n";
  911. $body .= "For complete discussion, see:\n";
  912. $discussurl2 = "/index.php?$sid&amp;action=site&amp;site=".$_REQUEST['site']."&amp;section=".$_REQUEST['section']."&amp;page=".$_REQUEST['page']."&amp;story=".$_REQUEST['story']."&amp;detail=".$_REQUEST['detail']."#".$newid;
  913. $body .= $_full_uri.$discussurl2."\n";
  914. }
  915. // send it!
  916. if (!mail($to,$subject,$body,"From: $from"))
  917. print "ERROR: Sending message, '$subject', to '$to' failed.";
  918. }
  919. }