3 * Elgg Presentation tool
6 * @package mod_presentation
11 export presentation to zip?
12 The ability to search for blog posts and files via tag
13 The ability to choose files uploaded to a community
14 Auto table of contents
22 * Standard page setup function
24 * @param string $varname
28 function presentation_pagesetup() {
30 global $PAGE, $CFG, $USER, $page_owner, $function, $metatags, $template;
32 require_once($CFG->dirroot
.'lib/filelib.php'); // to ensure file_get_contents()
33 $css = file_get_contents($CFG->dirroot
. "mod/presentation/presentation.css");
34 $css = str_replace("{{url}}", $CFG->wwwroot
, $css);
35 $metatags .= '<style type="text/css">' . $css . '</style>';
36 $metatags .= '<script type="text/javascript" src="' . $CFG->wwwroot
. 'mod/presentation/presentation.js"></script>' . "\n";
38 $page_username = user_info("username",$page_owner);
40 if (isloggedin() && user_info("user_type", $USER->ident
) != "external") {
41 if (defined("context") && context
== "presentation" && $page_owner == $USER->ident
) {
42 $PAGE->menu
[] = array(
43 'name' => 'presentation',
44 'html' => '<li><a href="' . $CFG->wwwroot
. $USER->username
. '/presentations/" class="selected">' . __gettext("Your Presentations") . '</a></li>'
47 $PAGE->menu
[] = array(
48 'name' => 'presentation',
49 'html' => '<li><a href="' . $CFG->wwwroot
. $USER->username
. '/presentations/">' . __gettext("Your Presentations") . '</a></li>'
54 if (defined("context") && context
== "presentation") {
56 $PAGE->menu_sub
[] = array(
57 'name' => 'presentation:index',
59 $CFG->wwwroot
. $page_username . '/presentations/',
64 if (isloggedin() && run("permissions:check", "profile") && $page_owner == $USER->ident
) {
65 $PAGE->menu_sub
[] = array(
66 'name' => 'presentation:create',
68 $CFG->wwwroot
. 'mod/presentation/new.php?owner=' . $USER->ident
,
77 $function['display:sidebar'][] = $CFG->dirroot
. "mod/presentation/user_info_menu.php";
80 $keywords = __gettext("Keywords: ");
81 $template['presentation_weblogpost'] = <<< END
82 <div
class="weblog-post"><!-- Holds all aspects of a blog post
-->
83 <div
class="user"><!-- Open
class user
-->
84 <img alt
="" src
="{{url}}_icon/user/{{usericon}}"/><br
/>{{fullname
}}
85 </div
><!-- Close
class user
-->
86 <div
class="weblog-title"><h3
>{{title
}}</h3
></div
>
87 <div
class="post"><!-- Open
class post
-->
89 </div
><!-- Close
class post
-->
90 <div
class="info"><!-- Open
class info
-->
92 $postedby {{fullname
}}
96 </div
><!-- Close
class info
-->
101 </div
><!-- Close weblog_post
-->
102 <div
class="clearing"></div
>
105 $comments = __gettext("Comments (+/-)");
106 $template['presentation_weblogcomments'] = <<< END
107 <div
class="presentation-importedcomments"><!-- start comments div
-->
108 <h4
><a href
="javascript:toggleVisibility('{{blockid}}')">{{numcomments
}} $comments</a
></h4
>
109 <ol id
="{{blockid}}">
112 <script type
="text/javascript">
114 toggleVisibility('{{blockid}}');
117 </div
><!-- end comments div
-->
120 $template['presentation_weblogcomment'] = <<< END
123 <div
class="comment-owner">
125 {{usericon
}}{{postedname
}} on
{{posted
}}
131 $template['presentation_comment'] = <<< END
134 <div
class="comment-owner">
136 {{usericon
}}{{postedname
}} on
{{posted
}} |
{{links
}}
142 $comments = __gettext("Comments");
143 //template for overall presentation comments
144 $template['presentation_comments'] = <<< END
145 <div
class="presentation-comments"><!-- start comments div
-->
146 <ol id
="{{blockid}}">
149 </div
><!-- end comments div
-->
151 //template for per-section comments, with integrated comment adding form
152 $template['presentation_sectioncomments'] = <<< END
153 <div
class="presentation-sectioncomments" id
="{{blockid}}">
159 <script type
="text/javascript">
161 toggleVisibility('{{blockid}}');
177 * Initialisation function
180 function presentation_init() {
182 global $CFG, $function, $db, $METATABLES;
184 $CFG->presentation
->types
= array('text', 'blogpost', 'file');
186 if (!array_intersect(array(
187 $CFG->prefix
. "presentations",
188 $CFG->prefix
. "presentation_sections",
189 $CFG->prefix
. "presentation_sections_data",
190 $CFG->prefix
. "presentation_comments"
192 if (file_exists($CFG->dirroot
. "mod/presentation/$CFG->dbtype.sql")) {
193 modify_database($CFG->dirroot
. "mod/presentation/$CFG->dbtype.sql");
195 error("Error: Your database ($CFG->dbtype) is not yet fully supported by the Elgg Presentation tool. See the mod/presentation directory.");
197 print_continue("index.php");
201 $function['search:all:tagtypes'][] = $CFG->dirroot
. "mod/presentation/function_search_all_tagtypes.php";
202 $function['search:display_results'][] = $CFG->dirroot
. "mod/presentation/function_search.php";
203 $function['groups:delete'][] = $CFG->dirroot
. "mod/presentation/groups_delete.php";
205 $action = trim(optional_param('action'));
207 presentation_actions($action);
210 listen_for_event("user", "delete", "presentation_user_delete");
218 * Get presentations of a particular user visible to the logged on user
220 * @param int $user_id userid to get presentations for
223 function presentation_get_presentations_visible($owner_id) {
227 // Get access list for this user
228 $where = run("users:access_level_sql_where",$USER->ident
);
230 // Get a list of presentations
231 $sql = "SELECT * FROM ".$CFG->prefix
."presentations WHERE ($where) AND owner = $owner_id ORDER BY name";
232 $presentations = get_records_sql($sql);
235 return $presentations;
243 * Get presentations sidebar content
245 * @return string html to add on to sidebar
247 function presentation_sidebar() {
249 global $page_owner, $CFG;
252 if ($page_owner > 0) { // TODO: a better way to do this - Sven
253 $title = __gettext("Presentations");
255 $ownername = user_info("username",$page_owner);
256 $body .= '<a href="' . $CFG->wwwroot
. $ownername . '/presentations/">' . __gettext("Presentations List") . '</a></li></ul>';
258 $run_result .= "<li id=\"sidebar_presentations\">";
259 $run_result .= templates_draw(array(
260 'context' => 'sidebarholder',
265 $run_result .= "</li>";
274 * Do updatey things for presentations
276 * @param string $action the action to trigger
279 function presentation_actions($action) {
281 global $CFG, $USER, $page_owner, $messages;
283 // logged on-only actions
287 case "presentation:create":
288 // this always creates as the logged in user, not the page owner
289 $new_presentation = new StdClass
;
290 $new_presentation->name
= trim(optional_param('new_presentation_title'));
291 $new_presentation->access
= trim(optional_param('new_presentation_access'));
292 $new_presentation->owner
= $USER->ident
;
293 $new_presentation_keywords = trim(optional_param('new_presentation_keywords'));
295 // If we've been asked to add an item, do that
296 if (!empty($new_presentation->name
)) {
298 $new_presentation = plugin_hook("presentation","create",$new_presentation);
299 if (!empty($new_presentation)) {
300 $insert_id = insert_record('presentations',$new_presentation);
301 $new_presentation->ident
= $insert_id;
303 insert_tags_from_string ($new_presentation_keywords, 'presentation', $insert_id, $new_presentation->access
, $new_presentation->owner
);
305 $new_presentation = plugin_hook("presentation","publish",$new_presentation);
306 $messages[] = __gettext("Your presentation has been created.");
307 define('redirect_url',$CFG->wwwroot
. user_info("username",$USER->ident
) . "/presentations/");
310 $messages[] = __gettext("Your presentation has to have a name.");
316 case "presentation:editsave":
318 $edit_presentation = new StdClass
;
319 $edit_presentation->ident
= optional_param('edit_presentation_ident',0,PARAM_INT
);
320 $edit_presentation->name
= trim(optional_param('edit_presentation_title'));
321 $edit_presentation->access
= trim(optional_param('edit_presentation_access'));
322 $edit_presentation_keywords = trim(optional_param('edit_presentation_keywords'));
324 $presrec = get_record("presentations", "ident", $edit_presentation->ident
);
326 // presentation exists? right owner?
327 if ($presrec && presentation_permissions_check($presrec->ident
, $USER->ident
)) {
329 if ($edit_presentation->name
) {
331 $edit_presentation = plugin_hook("presentation","update",$edit_presentation);
332 if (!empty($edit_presentation)) {
333 $insert_id = update_record('presentations',$edit_presentation);
335 delete_records('tags','tagtype','presentation','ref',$edit_presentation->ident
);
336 insert_tags_from_string ($edit_presentation_keywords, 'presentation', $edit_presentation->ident
, $edit_presentation->access
, $USER->ident
);
338 $edit_presentation = plugin_hook("presentation","republish",$edit_presentation);
339 $messages[] = __gettext("Your changes have been saved.");
340 $page_username = user_info("username",$USER->ident
);
341 define('redirect_url',$CFG->wwwroot
. $page_username . "/presentations/" . $edit_presentation->ident
. '/edit');
342 //define('redirect_url',$CFG->wwwroot . "mod/presentation/edit.php?id=" . $edit_presentation->ident);
345 $messages[] = __gettext("Your changes could not be saved.");
352 case "presentation:delete":
354 $deleteident = optional_param('delete_presentation_ident',0,PARAM_INT
);
356 $presrec = get_record("presentations", "ident", $deleteident);
358 // presentation exists? right owner?
359 if ($presrec && presentation_permissions_check($presrec->ident
, $USER->ident
)) {
361 //$edit_presentation = plugin_hook("presentation","delete",$edit_presentation);
363 presentation_delete($deleteident);
365 //$edit_presentation = plugin_hook("presentation","republish",$edit_presentation);
366 $messages[] = __gettext("Your presentation was deleted.");
368 $page_username = user_info("username",$USER->ident
);
369 define('redirect_url',$CFG->wwwroot
. $page_username . "/presentations/");
371 $messages[] = __gettext("Your presentation could not be deleted.");
377 case "presentation:movesec":
378 $presentation = optional_param('id',0,PARAM_INT
);
379 $section = optional_param('sec',0,PARAM_INT
);
380 $direction = optional_param('dir');
382 $presrec = get_record("presentations", "ident", $presentation);
384 // presentation exists? right owner?
385 if ($presrec && presentation_permissions_check($presrec->ident
, $USER->ident
)) {
386 if ($secrec = get_record("presentation_sections", "ident", $section, "presentation", $presentation)) {
387 if ($direction == "up") {
388 presentation_section_moveup($secrec);
389 } elseif ($direction == "down") {
390 presentation_section_movedown($secrec);
393 $page_username = user_info("username",$USER->ident
);
394 define('redirect_url',$CFG->wwwroot
. $page_username . "/presentations/" . $presentation . '/edit');
395 //define('redirect_url',$CFG->wwwroot . "mod/presentation/edit.php?id=" . $presentation);
402 case "presentation:delsec":
403 $presentation = optional_param('id',0,PARAM_INT
);
404 $section = optional_param('sec',0,PARAM_INT
);
406 $presrec = get_record("presentations", "ident", $presentation);
408 // presentation exists? right owner?
409 if ($presrec && presentation_permissions_check($presrec->ident
, $USER->ident
)) {
410 if ($secrec = get_record("presentation_sections", "ident", $section, "presentation", $presentation)) {
411 presentation_section_delete($presentation, $section);
412 $messages[] = __gettext("Section deleted.");
414 $page_username = user_info("username",$USER->ident
);
415 define('redirect_url',$CFG->wwwroot
. $page_username . "/presentations/" . $presentation . '/edit');
416 //define('redirect_url',$CFG->wwwroot . "mod/presentation/edit.php?id=" . $presentation);
423 case "presentation:savesec":
424 $presentation = optional_param('id',0,PARAM_INT
);
425 $section = optional_param('sec',0,PARAM_INT
);
426 $sectiontype = optional_param('sectype');
427 $dataarray = optional_param('pres_sec_data');
429 $presrec = get_record("presentations", "ident", $presentation);
433 // presentation exists? right owner?
434 if ($presrec && presentation_permissions_check($presrec->ident
, $USER->ident
)) {
436 if ($section == -1) {
438 $newsec = new stdClass
;
439 $newsec->presentation
= $presrec->ident
;
440 $newsec->section_type
= $sectiontype;
441 $newsec->updated
= $newsec->created
= $time;
442 $newsec->display_order
= 10001; //yeah, i know. i can't be arsed. - sven
444 if ($insert = insert_record('presentation_sections', $newsec)) {
445 $func = "presentation_section_save_" . $sectiontype;
446 if (is_callable($func)) {
447 $func($presrec->ident
, $insert, $dataarray);
449 presentation_sections_reorder($presrec->ident
);
450 $messages[] = __gettext("Added section.");
453 $messages[] = __gettext("Error: Could not create section.");
459 if ($secrec = get_record("presentation_sections", "ident", $section, "presentation", $presrec->ident
)) {
460 $func = "presentation_section_save_" . $sectiontype;
461 if (is_callable($func)) {
462 $func($presrec->ident
, $section, $dataarray);
464 set_field('presentation_sections', 'updated', $time, 'ident', $section);
466 $messages[] = __gettext("Error: Could not find section to update.");
472 $page_username = user_info("username",$USER->ident
);
473 define('redirect_url',$CFG->wwwroot
. $page_username . "/presentations/" . $presentation . '/edit');
474 //define('redirect_url',$CFG->wwwroot . "mod/presentation/edit.php?id=" . $presentation);
479 case "presentation:delcomment":
481 $presentation = optional_param('id',0,PARAM_INT
);
482 $section = optional_param('sec',0,PARAM_INT
);
483 $deleteident = optional_param('commentid',0,PARAM_INT
);
485 $presrec = get_record("presentations", "ident", $presentation);
486 $commentrec = get_record("presentation_comments", "ident", $deleteident);
488 // presentation + comment exist? presentation or comment owner?
493 presentation_permissions_check($presrec->ident
, $USER->ident
)
494 ||
$commentrec->owner
== $USER->ident
498 delete_records('presentation_comments', 'ident', $deleteident, 'presentation', $presentation, 'section', $section);
500 $messages[] = __gettext("Comment deleted.");
502 $page_username = user_info("username",$USER->ident
);
503 define('redirect_url',$CFG->wwwroot
. $page_username . "/presentations/" . $presentation);
505 $messages[] = __gettext("Comment could not be deleted.");
513 } // end if logged_on
515 // logged-out actions
518 case "presentation:addcomment":
520 $presentation = optional_param('id',0,PARAM_INT
);
521 $section = optional_param('sec',0,PARAM_INT
);
522 $presrec = get_record("presentations", "ident", $presentation);
524 // presentation exists? comment poster is logged on or public comments allowed?
525 if ($presrec && (logged_on ||
(!$CFG->disable_publiccomments
&& user_flag_get("publiccomments",$presrec->owner
)) )) {
527 if ($section && !record_exists("presentation_sections", "ident", $section, "presentation", $presentation)) {
531 $newcomment = new stdClass
;
532 $newcomment->presentation
= $presrec->ident
;
533 $newcomment->section
= $section;
534 $newcomment->created
= time();
536 $newcomment->owner
= $USER->ident
;
538 $newcomment->owner
= -1;
540 $newcomment->postedname
= trim(optional_param('postedname'));
541 $newcomment->body
= trim(optional_param('commentbody'));
543 if ($newcomment->body
) {
544 if ($insert = insert_record('presentation_comments', $newcomment)) {
545 $messages[] = __gettext("Comment added.");
547 $messages[] = __gettext("Error: Failed to add comment.");
550 $messages[] = __gettext("Error: Not adding blank comment.");
553 //stay on the same page
554 define('redirect_url', $_SERVER['REQUEST_URI']);
565 if (defined('redirect_url')) {
566 $_SESSION['messages'] = $messages;
567 header("Location: " . redirect_url
);
577 * Reorders sections for a particular presentation
579 * @param int $presentationid ID of the presentation to reorder
582 function presentation_sections_reorder($presentationid) {
584 $sections = presentation_get_sections($presentationid);
585 if (!empty($sections) && is_array($sections)) {
588 foreach($sections as $section) {
589 $order[$section->ident
] = $i * 10;
592 foreach($order as $ident => $display_order) {
593 // no point in updating non-changing values
594 if ($sections[$ident]->display_order
!= $display_order) {
595 $section = new StdClass
;
596 $section->display_order
= $display_order;
597 $section->ident
= $ident;
598 update_record('presentation_sections',$section);
608 * @param object $section section row to move
611 function presentation_section_moveup($section) {
612 $section->display_order
= $section->display_order
- 11;
613 update_record('presentation_sections',$section);
614 presentation_sections_reorder($section->presentation
);
618 * Move a section down
620 * @param object $section section row to move
623 function presentation_section_movedown($section) {
624 $section->display_order
= $section->display_order +
11;
625 update_record('presentation_sections',$section);
626 presentation_sections_reorder($section->presentation
);
632 * Get section rows for a presentation
634 * @param int $presentation presentation id
635 * @return mixed false, or an array of sections
637 function presentation_get_sections($presentation) {
639 return get_records('presentation_sections', 'presentation', $presentation, 'display_order');
645 * Purge a section from a presentation
647 * @param int $presentation presentation id
648 * @param int $section section id
650 function presentation_section_delete($presentation, $sectionid) {
652 $secrec = get_record("presentation_sections", "ident", $sectionid, "presentation", $presentation);
653 $func = "presentation_section_delete_" . $secrec->section_type
;
654 if (is_callable($func)) {
655 $func($presentation, $sectionid);
658 delete_records('presentation_comments', 'section', $sectionid, 'presentation', $presentation);
659 delete_records('presentation_sections_data', 'section', $sectionid, 'presentation', $presentation);
660 delete_records('presentation_sections', 'ident', $sectionid, 'presentation', $presentation);
667 * Purge a presentation
669 * @param int $presentation ID of presentation to delete
671 function presentation_delete($presentation) {
673 if ($secrecs = get_records("presentation_sections", "presentation", $presentation)) {
674 foreach ($secrecs as $secrec) {
675 presentation_section_delete($presentation, $secrec->ident
);
679 delete_records('tags','tagtype','presentation','ref',$presentation);
680 delete_records('presentations', 'ident', $presentation);
687 * Check whether a user id has write permission for a presentation
688 * Currently just checks owner, but could be so much more!
690 * @param int $presentation presentation id
691 * @param int $userid user id
692 * @return boolean true for has write permission
694 function presentation_permissions_check($presentation, $userid) {
696 $presrec = get_record("presentations", "ident", $presentation);
698 // presentation exists? right owner?
699 if ($presrec && $presrec->owner
== $userid) {
710 * Returns HTML for a particular section
712 * @param object $section section row
713 * @return string HTML output
715 function presentation_section_display($section, $menuedit = false, $menucomments = true, $forcenoaddcomments = false) {
717 global $CFG, $PAGE, $USER;
720 if (is_object($section)) {
722 // If the handler for displaying this particular section type exists,
723 // run it - otherwise display nothing
724 $func = "presentation_section_display_" . $section->section_type
;
725 if (is_callable($func)) {
726 $body = $func($section);
728 $body = "<div class=\"presentation-widget-content\">$body</div>\n";
731 if ($menuedit && isloggedin() && presentation_permissions_check($section->presentation
, $USER->ident
)) {
732 $menu[] = '<a href="' . $CFG->wwwroot
. 'mod/presentation/editsection.php?id=' . $section->presentation
. '&sec=' . $section->ident
. '">' . __gettext("Edit section") . "</a>";
733 $menu[] = '<a href="' . $CFG->wwwroot
. 'mod/presentation/edit.php?action=presentation:delsec&id=' . $section->presentation
. '&sec=' . $section->ident
. '" onclick="return confirm(\'' . __gettext("Are you sure you want to delete this section?") . '\')">' . __gettext("Delete section") . "</a>";
734 $menu[] = '<a href="' . $CFG->wwwroot
. 'mod/presentation/edit.php?action=presentation:movesec&id=' . $section->presentation
. '&sec=' . $section->ident
. '&dir=up">' . __gettext("Move up") . "</a>";
735 $menu[] = '<a href="' . $CFG->wwwroot
. 'mod/presentation/edit.php?action=presentation:movesec&id=' . $section->presentation
. '&sec=' . $section->ident
. '&dir=down">' . __gettext("Move down") . "</a>";
740 //TODO comment link/code here?
746 if ($comments = presentation_get_comments($section->presentation
, $section->ident
)) {
747 $numcomments = count($comments);
750 $blockid = "cmtp" . $section->presentation
. "s" . $section->ident
;
752 $presrec = get_record("presentations", "ident", $section->presentation
);
754 if (!$forcenoaddcomments) {
755 if (logged_on ||
(!$CFG->disable_publiccomments
&& user_flag_get("publiccomments",$presrec->owner
)) ) {
761 if ($numcomments ||
$addform) {
762 $menutext .= '<a class="presentation-seclinkcom" href="javascript:toggleVisibility(\'' . $blockid . '\')">';
763 $menutext .= $numcomments . __gettext(' Section Comments');
770 $commentstext = presentation_comments_display($section->presentation
, $section->ident
, $comments, $addform);
773 if ($menuedit ||
$menucomments) {
774 $menu[] = '<a class="presentation-seclinktop" href="#container" title="' . __gettext('Jump to the top of the page') . '">' . __gettext('Top') . '</a>';
775 $body .= '<p class="presentation-widget-menu">' . implode(' | ', $menu) . '</p>';
776 $body .= $commentstext;
779 $body = "<div class=\"presentation-widget\">$body</div>\n";
790 * Return title for section
792 * @param object $section section row
793 * @return string HTML output
795 function presentation_section_gettitle($section) {
798 if (is_object($section)) {
800 // If the handler for displaying this particular section type exists,
801 // run it - otherwise display nothing
802 $func = "presentation_section_gettitle_" . $section->section_type
;
803 if (is_callable($func)) {
804 $body = $func($section);
815 * Returns HTML for editing a particular section
817 * @param object $section section row object
818 * @return string HTML output
820 function presentation_section_edit($section) {
824 $body = "something went wrong";
827 if (is_object($section)) {
828 // If the handler for displaying this particular section type exists,
829 // run it - otherwise display nothing
830 $func = "presentation_section_edit_" . $section->section_type
;
831 if (is_callable($func)) {
832 $obj = $func($section);
834 $showform = $obj->showform
;
837 if ($section->ident
> 0) {
838 $submitstring = __gettext("Update section");
840 $submitstring = __gettext("Add section");
844 // Stick it in an appropriate form for saving
845 $body = "<form action=\"" . $CFG->wwwroot
. "mod/presentation/edit.php\" method=\"post\">\n" . $body;
849 <input type="hidden" name="action" value="presentation:savesec" />
850 <input type="hidden" name="id" value="' . $section->presentation
. '" />
851 <input type="hidden" name="sec" value="' . $section->ident
. '" />
852 <input type="hidden" name="sectype" value="' . $section->section_type
. '" />
853 <input type="submit" value="' . $submitstring . '" />
872 * Display plain text section
874 * @param object $section section row
875 * @return string HTML output
877 function presentation_section_display_text($section) {
881 $title = presentation_section_get_data($section->ident
,"title");
882 $body = presentation_section_get_data($section->ident
,"body");
886 $return .= "<h2>" . $title->value
. "</h2>\n";
889 $return .= "<div>" . nl2br($body->value
) . "</div>\n";
898 * Return title for plain text section
900 * @param object $section section row
901 * @return string HTML output
903 function presentation_section_gettitle_text($section) {
907 $title = presentation_section_get_data($section->ident
,"title");
908 if (empty($title->value
)) {
911 $ret = htmlspecialchars($title->value
);
920 * Display edit form for plain text section
922 * @param object $section section row
923 * @return object body=HTML output, showform=whether to surround output with a form
925 function presentation_section_edit_text($section) {
927 global $CFG, $page_owner;
930 $ret->showform
= true;
932 if (is_object($section)) {
933 if ($section->ident
> 0) {
934 $sectitle = presentation_section_get_data($section->ident
,"title");
935 $sectitle = $sectitle->value
;
936 $secbody = presentation_section_get_data($section->ident
,"body");
937 $secbody = $secbody->value
;
943 $ret->body
.= "<h2>" . __gettext("Text box") . "</h2>\n";
944 $ret->body
.= "<p>" . __gettext("This displays the text content of your choice. All you need to do is enter the title and body below:") . "</p>\n";
946 if ($section->ident
> 0) {
947 // presentation edit page runs its own
948 run('tinymce:include', array(array("pres_sec_data__body__")) );
951 $ret->body
.= "<p>" . display_input_field(array("pres_sec_data[title]",$sectitle,"text")) . "</p>\n";
952 $ret->body
.= "<p>" . display_input_field(array("pres_sec_data[body]",$secbody,"longtext")) . "</p>\n";
962 * Handle saving data for a plain text section
964 * @param int $presentation presentation id
965 * @param int $section section id
966 * @param array $dataarray extra data
969 function presentation_section_save_text($presentation, $section, $dataarray) {
971 global $CFG, $page_owner;
974 if (is_array($dataarray)) {
975 foreach ($dataarray as $name => $value) {
976 presentation_section_set_data($presentation, $section, $name, $value);
990 * Display blog post section
992 * @param object $section section row
993 * @return string HTML output
995 function presentation_section_display_blogpost($section) {
997 global $CFG, $template;
1000 if (is_object($section)) {
1002 $data = presentation_section_get_all_data($section->ident
);
1004 $sectitle = isset($data['title']) ?
$data['title']->value
: 'Untitled';
1005 $secbody = isset($data['body']) ?
$data['body']->value
: '';
1006 $secposted = isset($data['posted']) ?
strftime("%d %B %Y", $data['posted']->value
) : '';
1007 $secicon = isset($data['icon']) ?
$data['icon']->value
: -1;
1008 $secblogid = isset($data['weblog']) ?
$data['weblog']->value
: '';
1009 $secowner = isset($data['owner']) ?
$data['owner']->value
: '';
1010 $commentsbody = isset($data['comments']) ?
$data['comments']->value
: '';
1011 $numcomments = isset($data['numcomments']) ?
$data['numcomments']->value
: 0;
1012 $tags = isset($data['tags']) ?
$data['tags']->value
: '';
1013 $narrative = isset($data['narrative']) ?
$data['narrative']->value
: '';
1015 $sourceid = presentation_section_get_data($section->ident
, "sourceid");
1017 $body .= '<h2>Blog post: ' . $secposted . '</h2>';
1018 //$body .= '<div>' . $secbody . '</div>';
1020 $body .= '<div class="presentation-narrative">' . $narrative . '</div>';
1023 if ($numcomments && $commentsbody) {
1024 $blockid = "cmtp" . $section->presentation
. "s" . $section->ident
. "content";
1025 $commentsbody = templates_draw(
1027 'context' => 'presentation_weblogcomments',
1028 'comments' => $commentsbody,
1029 'numcomments' => $numcomments,
1030 'blockid' => $blockid,
1035 if ($secicon == -1) {
1036 if ($newicon = user_info("icon", $secowner)) {
1037 $secicon = $newicon;
1045 $body .= templates_draw(
1047 'context' => 'presentation_weblogpost',
1048 'date' => $secposted,
1049 'username' => $username,
1050 'usericon' => $secicon,
1052 'fullname' => $fullname,
1053 'title' => $sectitle,
1054 'comments' => $commentsbody,
1060 if (!empty($sourceid)) {
1061 $body .= '<div class="presentation-imported-guff">';
1062 if ($sourceid->created
) {
1063 $body .= __gettext('Imported at: ') . strftime("%d/%m/%Y %H:%M %Z", $sourceid->created
) . '<br />';
1066 if ($sourcepost = get_record("weblog_posts", "ident", $sourceid->value
)) {
1067 $ownerusername = user_info("username", $sourcepost->weblog
);
1068 $url = $CFG->wwwroot
. $ownerusername . '/weblog/' . $sourceid->value
. '.html';
1069 $body .= sprintf(__gettext('The original blog post this was imported from is <a href="%s">here</a>.'), $url) . '<br />';
1081 * Return title for blog post section
1083 * @param object $section section row
1084 * @return string HTML output
1086 function presentation_section_gettitle_blogpost($section) {
1090 $title = presentation_section_get_data($section->ident
,"title");
1091 $posted = presentation_section_get_data($section->ident
,"posted");
1093 $ret = 'Blog post: ' . strftime("%d %B %Y", $posted->value
) . ' -- ';
1095 if (empty($title->value
)) {
1098 $ret .= htmlspecialchars($title->value
);
1107 * Display edit form for blog post section
1109 * @param object $section section row
1110 * @return object body=HTML output, showform=whether to surround output with a form
1112 function presentation_section_edit_blogpost($section) {
1114 global $CFG, $USER, $page_owner;
1115 $ret = new stdClass
;
1117 $ret->showform
= true;
1119 if (is_object($section)) {
1121 $presrec = get_record("presentations", "ident", $section->presentation
);
1123 $ret->body
.= "<h2>" . __gettext("Blog post") . "</h2>\n";
1124 $url = $CFG->wwwroot
. $USER->username
. '/weblog/';;
1126 $secnarrative = presentation_section_get_data($section->ident
,"narrative");
1127 $secnarrative = $secnarrative->value
;
1128 if ($section->ident
> 0) {
1129 // presentation edit page runs its own
1130 run('tinymce:include', array(array("pres_sec_data__blognarrative__")) );
1132 $ret->body
.= "<p>" . __gettext('Description:') . "</p>\n";
1133 $ret->body
.= "<p>" . display_input_field(array("pres_sec_data[blognarrative]",$secnarrative,"longtext")) . "</p>\n";
1135 if ($section->ident
> 0) {
1138 $ownerusername = user_info("username", $presrec->owner
);
1139 $url = $CFG->wwwroot
. $ownerusername . '/weblog/';
1141 $sourceid = presentation_section_get_data($section->ident
, "sourceid");
1142 if ($sourcepost = get_record("weblog_posts", "ident", $sourceid->value
)) {
1144 $url .= $sourceid->value
. '.html';
1145 $ret->body
.= "<p>" . sprintf(__gettext('You can reimport <a href="%s">this post</a> from your blog, optionally with the comments it currently has:'), $url) . "</p>\n";
1148 . '<label for="pres_sec_data__postid__"><input type="checkbox" id="pres_sec_data__postid__" name="pres_sec_data[postid]" value="' . $sourcepost->ident
. '" /> ' . __gettext('Reimport blog post.') . '</label>'
1152 . '<label for="pres_sec_data__withcomments__"><input type="checkbox" id="pres_sec_data__withcomments__" name="pres_sec_data[withcomments]" value="yes" /> ' . __gettext('Import comments too.') . '</label>'
1158 $ret->body
.= "<p>" . sprintf(__gettext('You can not reimport this post, as it no longer exists on <a href="%s">your blog</a>.'), $url) . "</p>\n";
1159 $ret->showform
= false;
1165 $ret->body
.= "<p>" . sprintf(__gettext('You can import a post from <a href="%s">your blog</a> into a new section, optionally with the comments it currently has:'), $url) . "</p>\n";
1167 if ($posts = get_records_select('weblog_posts', 'owner = '.$presrec->owner
, null, 'posted ASC')) {
1168 $ret->body
.= '<p><select name="pres_sec_data[postid]">' . "\n";
1170 foreach ($posts as $apost) {
1171 $time = strftime("%d %B %Y", $apost->posted
);
1172 if ($time != $lasttime) {
1174 $ret->body
.= '</optgroup>' . "\n";
1176 $ret->body
.= '<optgroup label="' . $time . '">' . "\n";
1178 $title = strip_tags(get_access_description($apost->access
)) . (($apost->title
) ?
htmlspecialchars($apost->title
) : "Untitled");
1179 if ($apost->weblog
!= $apost->owner
) {
1180 $title = '@' . run("profile:display:name", $apost->weblog
) . ': ' . $title;
1182 $text = htmlspecialchars(substr($apost->body
, 0, 50));
1183 $ret->body
.= "\t" . '<option value="' . $apost->ident
. '" title="' . $text . '">' . $title . '</option>' . "\n";
1187 $ret->body
.= '</optgroup>' . "\n";
1189 $ret->body
.= '</select></p>' . "\n";
1190 $ret->body
.= '<p><label for="pres_sec_data__withcomments__"><input type="checkbox" id="pres_sec_data__withcomments__" name="pres_sec_data[withcomments]" value="yes" /> ' . __gettext('Import blog post comments too.') . '</label></p>' . "\n";
1194 $ret->showform
= false;
1195 $ret->body
.= "<p>" . __gettext("You don't have any blog posts yet.") . "</p>\n";
1207 * Handle saving data for a blog post section
1209 * @param int $presentation presentation id
1210 * @param int $section section id
1211 * @param array $dataarray extra data
1214 function presentation_section_save_blogpost($presentation, $section, $dataarray) {
1216 global $CFG, $USER, $page_owner;
1219 if (!empty($dataarray['blognarrative'])) {
1220 presentation_section_set_data($presentation, $section, "narrative", $dataarray['blognarrative']);
1223 if (!empty($dataarray['postid'])) {
1224 if ($post = get_record("weblog_posts", "ident", $dataarray['postid'], "owner", $USER->ident
)) {
1226 presentation_section_set_data($presentation, $section, "sourceid", $post->ident
);
1227 $postbody = run("weblogs:text:process", $post->body
);
1228 presentation_section_set_data($presentation, $section, "body", $postbody);
1229 presentation_section_set_data($presentation, $section, "title", $post->title
);
1230 presentation_section_set_data($presentation, $section, "icon", $post->icon
);
1231 presentation_section_set_data($presentation, $section, "owner", $post->owner
);
1232 presentation_section_set_data($presentation, $section, "weblog", $post->weblog
);
1233 presentation_section_set_data($presentation, $section, "posted", $post->posted
);
1235 $keywords = display_output_field(array("", "keywords", "weblog", "weblog", $post->ident
, $post->owner
));
1236 presentation_section_set_data($presentation, $section, "tags", $keywords);
1238 if (!empty($dataarray['withcomments'])) {
1239 //adding comments too
1243 if ($commentarray = get_records('weblog_comments','post_id',$post->ident
,'posted ASC')) {
1245 $numcomments = count($commentarray);
1247 templates_page_setup();
1249 foreach ($commentarray as $comment) {
1250 // turn commentor name into a link if they're a registered user
1251 // add rel="nofollow" to comment links if they're not
1252 if ($comment->owner
> 0) {
1253 $commentownerusername = user_info('username', $comment->owner
);
1254 $comment->postedname
= '<a href="' . $CFG->wwwroot
. $commentownerusername . '/">' . $comment->postedname
. '</a>';
1255 $comment->icon
= '<a href="' . $CFG->wwwroot
. $commentownerusername . '/"><img src="' . $CFG->wwwroot
. '_icon/user/' . run("icons:get",$comment->owner
) . '/w/50/h/50" border="0" align="left" alt="" /></a>';
1256 $comment->body
= run("weblogs:text:process", array($comment->body
, false));
1258 $comment->icon
= '<img src="' . $CFG->wwwroot
. '_icons/data/default.png" width="50" height="50" align="left" alt="" />';
1259 $comment->body
= run("weblogs:text:process", array($comment->body
, true));
1261 $commentsbody .= templates_draw(
1263 'context' => 'presentation_weblogcomment',
1264 'postedname' => $comment->postedname
,
1265 'body' => '' . $comment->body
,
1266 'posted' => strftime("%A, %d %B %Y, %H:%M %Z",$comment->posted
),
1267 'usericon' => $comment->icon
,
1274 presentation_section_set_data($presentation, $section, "comments", $commentsbody);
1275 presentation_section_set_data($presentation, $section, "numcomments", $numcomments);
1277 presentation_section_set_data($presentation, $section, "comments", '');
1278 presentation_section_set_data($presentation, $section, "numcomments", 0);
1297 * Display file section
1299 * @param object $section section row
1300 * @return string HTML output
1302 function presentation_section_display_file($section) {
1306 if (is_object($section)) {
1308 $data = presentation_section_get_all_data($section->ident
);
1310 $title = isset($data['title']) ?
$data['title']->value
: 'Untitled';
1311 $description = isset($data['description']) ?
$data['description']->value
: '';
1312 $size = isset($data['size']) ?
$data['size']->value
: 0;
1313 $originalname = isset($data['originalname']) ?
$data['originalname']->value
: '';
1314 $location = isset($data['location']) ?
$data['location']->value
: '';
1315 $tags = isset($data['tags']) ?
$data['tags']->value
: '';
1316 $narrative = isset($data['narrative']) ?
$data['narrative']->value
: '';
1318 $sourceid = presentation_section_get_data($section->ident
,"sourceid");
1320 $body .= "<h2>File: " . htmlspecialchars($title) . "</h2>\n";
1322 $body .= '<div class="presentation-narrative">' . $narrative . '</div>';
1324 $url = $CFG->wwwroot
. 'mod/presentation/file.php?pres=' . $section->presentation
. '&sec=' . $section->ident
;
1326 $body .= '<div class="presentation-file">';
1327 $body .= '<a href="' . $url . '&get=file"><img align="left" border="0" src="' . $url . '&get=icon" alt="' . __gettext('Thumbnail') . '" /></a>';
1328 $body .= '<div style="margin-left: 100px;">';
1329 $body .= __gettext('Title: ') . htmlspecialchars($title) . '<br />';
1330 $body .= __gettext('Description: ') . $description . '<br />';
1331 $body .= __gettext('Keywords: ') . $tags . '<br />';
1332 $body .= __gettext('Size: ') . $size . ' ' . __gettext('bytes') . '<br />';
1333 $body .= __gettext('Original filename: ') . $originalname . '<br />';
1334 //$body .= 'location: ' . $location->value . '<br />';
1335 //$body .= 'Source: ' . $sourceid->value . '<br />';
1338 $body .= '<div class="presentation-imported-guff">';
1339 $body .= __gettext('Imported at: ') . strftime("%d/%m/%Y %H:%M %Z", $sourceid->created
) . '<br />';
1341 if ($sourcefile = get_record("files", "ident", $sourceid->value
)) {
1342 $ownerusername = user_info("username", $sourcefile->files_owner
);
1343 $url = $CFG->wwwroot
. $ownerusername . '/files/';
1344 if ($sourcefile->folder
> 0) {
1345 $url .= $sourcefile->folder
. '/';
1347 $body .= sprintf(__gettext('The original file this was imported from is <a href="%s">here</a>.'), $url) . '<br />';
1359 * Return title for file section
1361 * @param object $section section row
1362 * @return string HTML output
1364 function presentation_section_gettitle_file($section) {
1366 $title = presentation_section_get_data($section->ident
,"title");
1370 if (empty($title->value
)) {
1373 $ret .= htmlspecialchars($title->value
);
1382 * Display edit form for file section
1384 * @param object $section section row
1385 * @return object body=HTML output, showform=whether to surround output with a form
1387 function presentation_section_edit_file($section) {
1389 global $CFG, $USER, $page_owner;
1390 $ret = new stdClass
;
1392 $ret->showform
= true;
1394 //TODO - better file selector
1396 if (is_object($section)) {
1398 $presrec = get_record("presentations", "ident", $section->presentation
);
1400 $ret->body
.= "<h2>" . __gettext("File") . "</h2>\n";
1401 $fileurl = $CFG->wwwroot
. $USER->username
. '/files/';
1403 $secnarrative = presentation_section_get_data($section->ident
,"narrative");
1404 $secnarrative = $secnarrative->value
;
1405 if ($section->ident
> 0) {
1406 // presentation edit page runs its own
1407 run('tinymce:include', array(array("pres_sec_data__filenarrative__")) );
1409 $ret->body
.= "<p>" . __gettext('Description:') . "</p>\n";
1410 $ret->body
.= "<p>" . display_input_field(array("pres_sec_data[filenarrative]",$secnarrative,"longtext")) . "</p>\n";
1412 if ($section->ident
> 0) {
1415 $ownerusername = user_info("username", $presrec->owner
);
1417 $sourceid = presentation_section_get_data($section->ident
, "sourceid");
1418 if ($sourcefile = get_record("files", "ident", $sourceid->value
)) {
1420 $url = $CFG->wwwroot
. '_files/edit_file.php?edit_file_id=' . $sourcefile->ident
. '&owner=' . $presrec->owner
;
1421 $ret->body
.= "<p>" . sprintf(__gettext('You can reimport this file, to update its title/description/keywords from the <a href="%s">source file</a>.'), $url) . '</p>';
1422 $ret->body
.= '<p><label for="pres_sec_data__fileid__"><input type="checkbox" id="pres_sec_data__fileid__" name="pres_sec_data[fileid]" value="' . $sourcefile->ident
. '" /> ' . __gettext('Reimport file.') . '</label></p>' . "\n";
1426 $url = $CFG->wwwroot
. $ownerusername . '/files/';
1427 $ret->body
.= "<p>" . sprintf(__gettext('You can not reimport this file, as it no longer exists in <a href="%s">your files</a>.'), $url) . "</p>\n";
1428 $ret->showform
= false;
1435 $ret->body
.= "<p>" . sprintf(__gettext('You can copy one of <a href="%s">your files</a> into a new section.'), $fileurl) . "</p>\n";
1436 if ($files = get_records_select('files',"files_owner = ?",array($USER->ident
))) {
1438 $ret->body
.= '<p><select name="pres_sec_data[fileid]">' . "\n";
1439 $ret->body
.= presentation_viewfolder(-1, $USER->ident
, 0);
1440 $ret->body
.= "</select></p>\n";
1445 $ret->showform
= false;
1446 $ret->body
.= "<p>" . __gettext("You don't have any files yet.") . "</p>\n";
1457 * Handle saving data for a file section
1459 * @param int $presentation presentation id
1460 * @param int $section section id
1461 * @param array $dataarray extra data
1464 function presentation_section_save_file($presentation, $section, $dataarray) {
1466 global $CFG, $USER, $page_owner;
1469 require_once($CFG->dirroot
. 'lib/filelib.php');
1471 $initial = substr($presentation, -1, 1);
1472 require_once($CFG->dirroot
. 'lib/uploadlib.php');
1473 make_upload_directory('presentation');
1474 make_upload_directory('presentation/' . $initial);
1475 make_upload_directory('presentation/' . $initial . '/' . $presentation);
1477 if (!empty($dataarray['filenarrative'])) {
1478 presentation_section_set_data($presentation, $section, "narrative", $dataarray['filenarrative']);
1481 if (!empty($dataarray['fileid'])) {
1482 if ($file = get_record("files", "ident", $dataarray['fileid'], "owner", $USER->ident
)) {
1483 if ($filelocation = file_cache($file)) {
1484 $filename = basename($filelocation);
1485 $location = 'presentation/' . $initial . '/' . $presentation . '/' . time() . $filename;
1486 $destdir = $CFG->dataroot
. $location;
1487 // var_dump($filelocation);
1488 // var_dump($destdir);
1489 if (copy($filelocation, $destdir)) {
1491 presentation_section_set_data($presentation, $section, "sourceid", $file->ident
);
1492 presentation_section_set_data($presentation, $section, "originalname", $file->originalname
);
1493 presentation_section_set_data($presentation, $section, "location", $location);
1494 presentation_section_set_data($presentation, $section, "title", $file->title
);
1495 presentation_section_set_data($presentation, $section, "description", $file->description
);
1496 presentation_section_set_data($presentation, $section, "size", $file->size
);
1498 $keywords = display_output_field(array("", "keywords", "file", "file", $file->ident
, $file->owner
));
1499 presentation_section_set_data($presentation, $section, "tags", $keywords);
1513 * Handle deleting data for a file section
1515 * @param int $presentation presentation id
1516 * @param int $section section id
1519 function presentation_section_delete_file($presentation, $section) {
1521 global $CFG, $USER, $page_owner;
1524 $location = presentation_section_get_data($section, "location");
1525 $fullocation = $CFG->dataroot
. $location->value
;
1526 if (is_file($fullocation)) {
1527 unlink($fullocation);
1542 * Get a data row for a section
1544 * @param int $sectionid section id
1545 * @param string $field "name"-field value to search for
1546 * @return object presentation_sections_data table row
1548 function presentation_section_get_data($sectionid, $field) {
1552 $value = get_record_sql("SELECT * FROM ".$CFG->prefix
."presentation_sections_data where section=? AND name=?", array($sectionid, $field));
1554 if (empty($value)) {
1555 $value = new stdClass
;
1556 $value->name
= $field;
1567 * Get a data array for a section
1569 * @param int $sectionid section id
1570 * @param string $field "name"-field value to search for
1571 * @return mixed false or an array of allpresentation_sections_data
1573 function presentation_section_get_all_data($sectionid) {
1575 return get_records('presentation_sections_data', 'section', $sectionid, $sort='', $fields='name,value');
1582 * Sets data with a particular name for a particular section ID
1584 * @param int $presentation presentation id
1585 * @param int $section section id
1586 * @param string $name field name
1587 * @param string $value value to set
1588 * @return mixed something
1590 function presentation_section_set_data($presentation, $section, $name, $value) {
1591 $data = new stdClass
;
1592 $data->presentation
= $presentation;
1593 $data->section
= $section;
1594 $data->name
= $name;
1595 $data->value
= $value;
1596 $data->created
= time();
1597 $existing = presentation_section_get_data($section, $name);
1598 if (!empty($existing->ident
)) {
1599 $data->ident
= $existing->ident
;
1600 return update_record('presentation_sections_data',$data);
1602 return insert_record('presentation_sections_data',$data);
1619 * copied from units/files/weblogs_posts_add_fields.php and modified
1621 * @param int $folderid folder id
1622 * @param int $userid user id whose files we're browsing
1623 * @param int $level how many levels down the recursion we are
1624 * @return string HTML of a list of <option> tags
1627 function presentation_viewfolder($folderid, $userid, $level) {
1630 for ($i = 0; $i < $level; $i++
) {
1633 $fileprefix = $prefix . ">";
1635 if ($folderid == -1) {
1637 <option value
="" title
="Folder" disabled
="disabled">ROOT
</option
>
1640 $current_folder = get_record('file_folders','files_owner',$userid,'ident',$folderid);
1641 $textlib = textlib_get_instance();
1642 $name = htmlspecialchars($textlib->strtoupper($current_folder->name
));
1644 <option value
="" title
="Folder" disabled
="disabled">{$prefix} {$name}</option
>
1647 if ($files = get_records_select('files',"files_owner = ? AND folder = ?",array($userid,$folderid))) {
1648 foreach($files as $file) {
1649 $filetitle = strip_tags(get_access_description($file->access
)) . htmlspecialchars($file->title
);
1650 $filename = htmlspecialchars($file->originalname
);
1653 <option value
="{$file->ident}" title
="{$filename}">{$fileprefix} {$filetitle}</option
>
1658 if ($folders = get_records_select('file_folders',"files_owner = ? AND parent = ? ",array($userid,$folderid))) {
1659 foreach($folders as $folder) {
1660 $body .= presentation_viewfolder($folder->ident
, $userid, $level +
1);
1669 * get the comments for a given presentation, overall or a section
1671 * @param int $presentation presentation id
1672 * @param int $section section id, 0 for presentation comments
1673 * @return mixed array list of comments, or false
1676 function presentation_get_comments($presentation, $section) {
1678 return get_records_select('presentation_comments', 'presentation = ? AND section = ?', array($presentation,$section), 'created ASC');
1688 * get the comment adding form
1690 * @param int $presentation presentation id
1691 * @param int $section section id, 0 for presentation comments
1692 * @param string $posturl URL the form should submit to
1693 * @return string HTML
1695 function presentation_comments_add_form($presentation, $section, $posturl) {
1700 $posturl = htmlspecialchars($posturl);
1702 $addComment = __gettext("Add a section comment"); // gettext variable
1704 $addComment = __gettext("Add a comment"); // gettext variable
1706 $run_result .= <<< END
1707 <form action
="$posturl" method
="post" class="presentation-commentaddform">
1708 <h2
>$addComment</h2
>
1711 $id = 'commentbodyp' . $presentation . 's' . $section;
1712 $field = '<textarea name="commentbody" id="' . $id . '" style="width: 95%; height: 200px"></textarea>';
1715 <input type
="hidden" name
="action" value
="presentation:addcomment" />
1716 <input type
="hidden" name
="id" value
="{$presentation}" />
1717 <input type
="hidden" name
="sec" value
="{$section}" />
1720 $run_result .= templates_draw(array(
1721 'context' => 'databox1',
1722 'name' => __gettext("Your comment text"),
1728 $comment_name = $USER->name
;
1730 $comment_name = __gettext("Guest");
1733 $run_result .= templates_draw(array(
1734 'context' => 'databox1',
1735 'name' => __gettext("Your name"),
1736 'column1' => "<input type=\"text\" name=\"postedname\" value=\"".htmlspecialchars($comment_name, ENT_COMPAT
, 'utf-8')."\" />"
1740 $run_result .= templates_draw(array(
1741 'context' => 'databox1',
1743 'column1' => "<input type=\"submit\" value=\"".__gettext("Add comment")."\" />"
1747 $run_result .= "</form>\n";
1755 * get HTML for a presentation or section's comments
1757 * @param int $presentation presentation id
1758 * @param int $section section id, 0 for presentation comments
1759 * @param array $commentarray array of comment db rows
1760 * @param boolean $showaddform whether to show the add comment form
1761 * @return string HTML
1763 function presentation_comments_display($presentation, $section, $commentarray, $showaddform = false) {
1765 global $CFG, $USER, $PAGE;
1770 $commentcontext = 'presentation_comment';
1771 $commentscontext = 'presentation_sectioncomments';
1772 $blockid = "cmtp" . $presentation . "s" . $section;
1774 $commentcontext = 'presentation_comment';
1775 $commentscontext = 'presentation_comments';
1776 $blockid = "cmtp" . $presentation . "s0";
1780 if (is_array($commentarray)) {
1781 $numcomments = count($commentarray);
1782 foreach ($commentarray as $comment) {
1784 // turn commentor name into a link if they're a registered user
1785 // add rel="nofollow" to comment links if they're not
1786 if ($comment->owner
> 0) {
1787 $commentownerusername = user_info('username', $comment->owner
);
1788 $comment->postedname
= '<a href="' . $CFG->wwwroot
. $commentownerusername . '/">' . $comment->postedname
. '</a>';
1789 $comment->icon
= '<a href="' . $CFG->wwwroot
. $commentownerusername . '/"><img src="' . $CFG->wwwroot
. '_icon/user/' . run("icons:get",$comment->owner
) . '/w/50/h/50" border="0" align="left" alt="" /></a>';
1790 $comment->body
= run("weblogs:text:process", array($comment->body
, false));
1792 $comment->icon
= '<img src="' . $CFG->wwwroot
. '_icons/data/default.png" width="50" height="50" align="left" alt="" />';
1793 $comment->body
= run("weblogs:text:process", array($comment->body
, true));
1797 if (logged_on
&& ($comment->owner
== $USER->ident ||
presentation_permissions_check($presentation, $USER->ident
) )) {
1798 $returnConfirm = __gettext("Are you sure you want to permanently delete this comment?");
1799 $url = $CFG->wwwroot
. 'mod/presentation/index.php?action=presentation:delcomment&id=' . $presentation . '&sec=' . $section . '&commentid=' . $comment->ident
;
1800 $commentmenu = '<a href="' . $url . '" onclick="return confirm(\'' . $returnConfirm . '\')">' . __gettext("Delete") . '</a>';
1804 $commentsbody .= templates_draw(
1806 'context' => $commentcontext,
1807 'postedname' => $comment->postedname
,
1808 'body' => '' . $comment->body
,
1809 'posted' => strftime("%A, %d %B %Y, %H:%M %Z",$comment->created
),
1810 'usericon' => $comment->icon
,
1811 'links' => $commentmenu,
1820 $addform = presentation_comments_add_form($presentation, $section, $_SERVER['REQUEST_URI']);
1823 if ($commentsbody ||
$addform) {
1824 $body .= templates_draw(
1826 'context' => $commentscontext,
1827 'comments' => $commentsbody,
1828 'addform' => $addform,
1829 'numcomments' => $numcomments,
1830 'blockid' => $blockid,
1840 * hook into user deletion
1842 * @param string $object_type
1843 * @param string $event
1844 * @param object $object user to delete
1845 * @return object user to delete
1847 function presentation_user_delete($object_type, $event, $object) {
1849 if ($presentations = get_records('presentations', 'owner', $object->ident
, $sort='', $fields='ident')) {
1850 foreach ($presentations as $apresentation) {
1851 presentation_delete($apresentation->ident
);
1855 // You must pass $object back unless something goes wrong!