PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/mod/oublog/view.php

https://github.com/galitush2005/RTL-BIDI-Hebrew-Moodle-Plugins
PHP | 401 lines | 288 code | 66 blank | 47 comment | 90 complexity | cbbfd4ed5063e66f849d75bf92329118 MD5 | raw file
  1. <?php
  2. /**
  3. * This page prints a particular instance of oublog
  4. *
  5. * @author Matt Clarkson <mattc@catalyst.net.nz>
  6. * @author Sam Marshall <s.marshall@open.ac.uk>
  7. * @package oublog
  8. */
  9. // This code tells OU authentication system to let the public access this page
  10. // (subject to Moodle restrictions below and with the accompanying .sams file).
  11. global $DISABLESAMS;
  12. $DISABLESAMS = 'opt';
  13. require_once('../../config.php');
  14. require_once('locallib.php');
  15. if(class_exists('ouflags')) {
  16. require_once('../../local/mobile/ou_lib.php');
  17. global $OUMOBILESUPPORT;
  18. $OUMOBILESUPPORT = true;
  19. ou_set_is_mobile(ou_get_is_mobile_from_cookies());
  20. $blogdets = optional_param('blogdets', null, PARAM_TEXT);
  21. $DASHBOARD_COUNTER=DASHBOARD_BLOG_VIEW;
  22. }
  23. $id = optional_param('id', 0, PARAM_INT); // Course Module ID
  24. $user = optional_param('user', 0, PARAM_INT); // User ID
  25. $offset = optional_param('offset', 0, PARAM_INT); // Offset fo paging
  26. $tag = optional_param('tag', null, PARAM_TAG); // Tag to display
  27. if ($id) {
  28. if (!$cm = get_coursemodule_from_id('oublog', $id)) {
  29. error("Course module ID was incorrect");
  30. }
  31. if (!$course = get_record("course", "id", $cm->course)) {
  32. error("Course is misconfigured");
  33. }
  34. if (!$oublog = get_record("oublog", "id", $cm->instance)) {
  35. error("Course module is incorrect");
  36. }
  37. $oubloguser->id = null;
  38. $oubloginstance = null;
  39. $oubloginstanceid = null;
  40. } elseif ($user) {
  41. if (!$oubloguser = get_record('user', 'id', $user)) {
  42. error("User not found");
  43. }
  44. if (!list($oublog, $oubloginstance) = oublog_get_personal_blog($oubloguser->id)) {
  45. error("Course module is incorrect");
  46. }
  47. if (!$cm = get_coursemodule_from_instance('oublog', $oublog->id)) {
  48. error("Course module ID was incorrect");
  49. }
  50. if (!$course = get_record("course", "id", $oublog->course)) {
  51. error("Course is misconfigured");
  52. }
  53. $oubloginstanceid = $oubloginstance->id;
  54. } elseif (isloggedin()) {
  55. redirect('view.php?user='.$USER->id);
  56. } else {
  57. redirect('bloglogin.php');
  58. }
  59. // The mod_edit page gets it wrong when redirecting to a personal blog.
  60. // Since there's no way to know what personal blog was being updated
  61. // this redirects to the users own blog
  62. if ($oublog->global && empty($user)) {
  63. redirect('view.php?user='.$USER->id);
  64. exit;
  65. }
  66. $context = get_context_instance(CONTEXT_MODULE, $cm->id);
  67. oublog_check_view_permissions($oublog, $context, $cm);
  68. /// Check security
  69. $canpost = oublog_can_post($oublog,$user,$cm);
  70. $canmanageposts = has_capability('mod/oublog:manageposts', $context);
  71. $canaudit = has_capability('mod/oublog:audit', $context);
  72. /// Get strings
  73. $stroublogs = get_string('modulenameplural', 'oublog');
  74. $stroublog = get_string('modulename', 'oublog');
  75. $straddpost = get_string('newpost', 'oublog');
  76. $strtags = get_string('tags', 'oublog');
  77. $stredit = get_string('edit', 'oublog');
  78. $strdelete = get_string('delete', 'oublog');
  79. $strnewposts = get_string('newerposts', 'oublog');
  80. $strolderposts = get_string('olderposts', 'oublog');
  81. $strcomment = get_string('comment', 'oublog');
  82. $strviews = get_string('views', 'oublog');
  83. $strlinks = get_string('links', 'oublog');
  84. $strfeeds = get_string('feeds', 'oublog');
  85. $strblogsearch = get_string('searchthisblog', 'oublog');
  86. /// Set-up groups
  87. $groupmode = oublog_get_activity_groupmode($cm, $course);
  88. $currentgroup = oublog_get_activity_group($cm, true);
  89. if (!oublog_is_writable_group($cm)) {
  90. $canpost=false;
  91. $canmanageposts=false;
  92. $cancomment=false;
  93. $canaudit=false;
  94. }
  95. /// Print the header
  96. $PAGEWILLCALLSKIPMAINDESTINATION = true;
  97. $hideunusedblog=false;
  98. if (class_exists('ouflags') && ou_get_is_mobile()){
  99. ou_mobile_configure_theme();
  100. }
  101. if ($oublog->global) {
  102. $blogtype = 'personal';
  103. $returnurl = $CFG->wwwroot . '/mod/oublog/view.php?user='.$user;
  104. $name = $oubloginstance->name;
  105. if(oublog_search_installed()) {
  106. $buttontext=<<<EOF
  107. <form action="search.php" method="get"><div>
  108. <input type="hidden" name="user" value="{$oubloguser->id}"/>
  109. <input type="text" name="query" value=""/>
  110. <input type="submit" value="{$strblogsearch}"/>
  111. </div></form>
  112. EOF;
  113. } else {
  114. $buttontext='';
  115. }
  116. $buttontext.=update_module_button($cm->id, $course->id, $stroublog);
  117. } else {
  118. $blogtype = 'course';
  119. $returnurl = $CFG->wwwroot . '/mod/oublog/view.php?id='.$id;
  120. $name = $oublog->name;
  121. if(oublog_search_installed()) {
  122. $buttontext=<<<EOF
  123. <form action="search.php" method="get"><div>
  124. <input type="hidden" name="id" value="{$cm->id}"/>
  125. <input type="text" name="query" value=""/>
  126. <input type="submit" value="{$strblogsearch}"/>
  127. </div></form>
  128. EOF;
  129. } else {
  130. $buttontext='';
  131. }
  132. $buttontext.=update_module_button($cm->id, $course->id, $stroublog);
  133. }
  134. if ($tag) {
  135. $returnurl .= '&amp;tag='.urlencode($tag);
  136. }
  137. /// Set-up individual
  138. $currentindividual = -1;
  139. $individualdetails = 0;
  140. //set up whether the group selector should display
  141. $showgroupselector = true;
  142. if($oublog->individual) {
  143. //if separate individual and visible group, do not show groupselector
  144. //unless the current user has permission
  145. if ($oublog->individual == OUBLOG_SEPARATE_INDIVIDUAL_BLOGS
  146. && !has_capability('mod/oublog:viewindividual', $context)) {
  147. $showgroupselector = false;
  148. }
  149. $canpost=true;
  150. $individualdetails = oublog_individual_get_activity_details($cm, $returnurl, $oublog, $currentgroup, $context);
  151. if ($individualdetails) {
  152. $currentindividual = $individualdetails->activeindividual;
  153. if (!$individualdetails->newblogpost) {
  154. $canpost=false;
  155. }
  156. }
  157. }
  158. /// Get Posts
  159. list($posts, $recordcount) = oublog_get_posts($oublog, $context, $offset, $cm, $currentgroup, $currentindividual, $oubloguser->id, $tag, $canaudit);
  160. /// Generate extra navigation
  161. $extranav = array();
  162. if ($offset) {
  163. $a = new stdClass();
  164. $a->from = ($offset+1);
  165. $a->to = (($recordcount - $offset) > OUBLOG_POSTS_PER_PAGE) ? $offset + OUBLOG_POSTS_PER_PAGE : $recordcount;
  166. $extranav = array('name' => get_string('extranavolderposts', 'oublog', $a), 'link' => '', 'type' => 'misc');
  167. }
  168. if ($tag) {
  169. $extranav = array('name' => get_string('extranavtag', 'oublog', $tag), 'link' => '', 'type' => 'misc');
  170. }
  171. if ($oublog->global) {
  172. // bit about hidden with if global then $posts
  173. // In order to prevent people from looping through numbers to get the
  174. // name of every user in the site (in case these names are considered
  175. // private), don't display the header when not displaying posts, except
  176. // to users who can post
  177. $hideunusedblog=!$posts && !$canpost && !$canaudit;
  178. if($hideunusedblog) {
  179. print_header();
  180. } else {
  181. $navigation = oublog_build_navigation($cm, $oublog, $oubloginstance,
  182. $oubloguser, $extranav);
  183. print_header_simple(format_string($oublog->name), "", $navigation, "", oublog_get_meta_tags($oublog, $oubloginstance, $currentgroup, $cm), true,
  184. $buttontext, navmenu($course, $cm));
  185. }
  186. } else {
  187. $navigation = oublog_build_navigation($cm, $oublog, $oubloginstance,
  188. null, $extranav);
  189. print_header_simple(format_string($oublog->name), "", $navigation, "", oublog_get_meta_tags($oublog, $oubloginstance, $currentgroup, $cm), true,
  190. $buttontext, navmenu($course, $cm));
  191. }
  192. print '<div class="oublog-topofpage"></div>';
  193. require_once(dirname(__FILE__).'/pagelib.php');
  194. // Initialize $PAGE, compute blocks
  195. $PAGE = page_create_instance($oublog->id);
  196. $pageblocks = blocks_setup($PAGE);
  197. $editing = isediting($cm->course);
  198. if (class_exists('ouflags') && ou_get_is_mobile() && $blogdets == 'show'){
  199. print '<div id="middle-column">';
  200. ou_print_mobile_navigation($id,$blogdets,null,$user);
  201. }
  202. else {
  203. // The left column ...
  204. if($hasleft=!empty($CFG->showblocksonmodpages) && (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $editing)) {
  205. print '<div id="left-column">';
  206. blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
  207. print '</div>';
  208. }
  209. print '</div>';// fix mixed columns in rtl mode and editing mode (nadavkav patch)
  210. // The right column, BEFORE the middle-column.
  211. print '<div id="right-column">';
  212. }
  213. if(!$hideunusedblog) {
  214. // Name, summary, related links
  215. oublog_print_summary_block($oublog, $oubloginstance, $canmanageposts);
  216. /// Tag Cloud
  217. if ($tags = oublog_get_tag_cloud($returnurl, $oublog, $currentgroup, $cm, $oubloginstanceid, $currentindividual)) {
  218. print_side_block($strtags, $tags, NULL, NULL, NULL, array('id' => 'oublog-tags'),$strtags);
  219. }
  220. /// Links
  221. $links = oublog_get_links($oublog, $oubloginstance, $context);
  222. if ($links) {
  223. print_side_block($strlinks, $links, NULL, NULL, NULL, array('id' => 'oublog-links'),$strlinks);
  224. }
  225. // Feeds
  226. if ($feeds = oublog_get_feedblock($oublog, $oubloginstance, $currentgroup, false, $cm, $currentindividual)) {
  227. $feedicon = ' <img src="'.$CFG->pixpath.'/i/rss.gif" alt="'.get_string('blogfeed', 'oublog').'" class="feedicon" />';
  228. print_side_block($strfeeds . $feedicon, $feeds, NULL, NULL, NULL, array('id' => 'oublog-feeds'), $strfeeds);
  229. }
  230. }
  231. if (class_exists('ouflags') && ou_get_is_mobile() && $blogdets == 'show'){
  232. ou_print_mobile_navigation($id,$blogdets,null,$user);
  233. }
  234. print '</div>';
  235. if (class_exists('ouflags') && ou_get_is_mobile() && $blogdets == 'show'){
  236. print_footer($course);
  237. exit;
  238. }
  239. // Start main column
  240. $classes='';
  241. if (!class_exists('ouflags') || !ou_get_is_mobile()){
  242. $classes.=$hasleft ? 'has-left-column ' : '';
  243. $classes.='has-right-column ';
  244. }
  245. $classes=trim($classes);
  246. if($classes) {
  247. print '<div id="middle-column" class="'.$classes.'">';
  248. } else {
  249. print '<div id="middle-column">';
  250. }
  251. if (class_exists('ouflags') && ou_get_is_mobile()){
  252. ou_print_mobile_navigation($id,$blogdets,null,$user);
  253. }
  254. print skip_main_destination();
  255. //adding a link to the computing guide
  256. if (class_exists('ouflags')) {
  257. require_once($CFG->dirroot.'/local/utils_shared.php');
  258. $computingguidelink = get_link_to_computing_guide('oublog');
  259. print '<span class="computing-guide"> '.$computingguidelink.'</span>';
  260. }
  261. /// Print Groups and individual drop-down menu
  262. echo '<div class="oublog-groups-individual-selectors">';
  263. /// Print Groups
  264. if ($showgroupselector) {
  265. groups_print_activity_menu($cm, $returnurl);
  266. }
  267. /// Print Individual
  268. if($oublog->individual) {
  269. if ($individualdetails) {
  270. echo $individualdetails->display;
  271. $individualmode = $individualdetails->mode;
  272. $currentindividual = $individualdetails->activeindividual;
  273. }
  274. }
  275. echo '</div>';
  276. /// Print the main part of the page
  277. // New post button - in group blog, you can only post if a group is selected
  278. if ($oublog->individual && $individualdetails) {
  279. $showpostbutton = $canpost;
  280. } else {
  281. $showpostbutton = $canpost && ($currentgroup || !$groupmode );
  282. }
  283. if ($showpostbutton) {
  284. print_single_button('editpost.php', array('blog' => $cm->instance), $straddpost);
  285. }
  286. // Print blog posts
  287. if ($posts) {
  288. echo '<div id="oublog-posts">';
  289. if ($offset > 0) {
  290. if ($offset-OUBLOG_POSTS_PER_PAGE == 0) {
  291. print "<div class='oublog-newerposts'><a href=\"$returnurl\">$strnewposts</a></div>";
  292. } else {
  293. print "<div class='oublog-newerposts'><a href=\"$returnurl&amp;offset=".($offset-OUBLOG_POSTS_PER_PAGE)."\">$strnewposts</a></div>";
  294. }
  295. }
  296. foreach ($posts as $post) {
  297. oublog_print_post($cm, $oublog, $post, $returnurl, $blogtype, $canmanageposts, $canaudit);
  298. }
  299. if ($recordcount - $offset > OUBLOG_POSTS_PER_PAGE) {
  300. print "<div class='oublog-olderposts'><a href=\"$returnurl&amp;offset=".($offset+OUBLOG_POSTS_PER_PAGE)."\">$strolderposts</a></div>";
  301. }
  302. echo '</div>';
  303. }
  304. // Print information allowing the user to log in if necessary, or letting
  305. // them know if there are no posts in the blog
  306. if (isguestuser() && $USER->id==$user) {
  307. print '<p class="oublog_loginnote">'.
  308. get_string('guestblog','oublog',
  309. 'bloglogin.php?returnurl='.urlencode($returnurl)).'</p>';
  310. } else if(!isloggedin() || isguestuser()) {
  311. print '<p class="oublog_loginnote">'.
  312. get_string('maybehiddenposts','oublog',
  313. 'bloglogin.php?returnurl='.urlencode($returnurl)).'</p>';
  314. } else if(!$posts) {
  315. print '<p class="oublog_noposts">'.
  316. get_string('noposts','oublog').'</p>';
  317. }
  318. /// Log visit and bump view count
  319. add_to_log($course->id, "oublog", "view", $returnurl, $oublog->id, $cm->id);
  320. $views = oublog_update_views($oublog, $oubloginstance);
  321. // Show dashboard feature if enabled, if course blog
  322. if (class_exists('ouflags') && !$oublog->global) {
  323. require_once($CFG->dirroot . '/local/externaldashboard/external_dashboard.php');
  324. external_dashboard::print_favourites_button($cm);
  325. }
  326. /// Finish the page
  327. echo "<div class=\"clearer\"></div><div class=\"oublog-views\">$strviews $views</div></div>";
  328. if(class_exists('ouflags')) {
  329. completion_set_module_viewed($course,$cm);
  330. }
  331. if (class_exists('ouflags') && ou_get_is_mobile()){
  332. ou_print_mobile_navigation($id,$blogdets,null,$user);
  333. }
  334. print_footer($course);
  335. ?>