PageRenderTime 49ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/lib.php

https://github.com/jacano1969/moodle-theme_cubic
PHP | 1247 lines | 818 code | 174 blank | 255 comment | 168 complexity | cfb118d47da776182d9c51a857c66a06 MD5 | raw file
  1. <?php
  2. /**
  3. * Lib functions for the cubic theme.
  4. * @copyright 2013 Bruno Sampaio
  5. */
  6. /**
  7. * LAYOUT FUNCTIONS
  8. *-------------------------------------------------------------------------------------------------*/
  9. /**
  10. * Get logo base on theme settings.
  11. * @return string (HTML)
  12. */
  13. function cubic_get_layout_conditions() {
  14. global $PAGE, $OUTPUT;
  15. $conditions = array();
  16. //Main Sections
  17. $conditions['bar'] = empty($PAGE->layout_options['nobar']);
  18. $conditions['lang'] = !empty($PAGE->layout_options['langmenu']);
  19. $conditions['navbar'] = empty($PAGE->layout_options['nonavbar']) && $PAGE->has_navbar();
  20. $conditions['blocks'] = empty($PAGE->layout_options['noblocks']);
  21. $conditions['footer'] = empty($PAGE->layout_options['nofooter']);
  22. $hassidepre = false;
  23. $hassidepost = false;
  24. try {
  25. //Blocks Sections
  26. $hassidepre = $PAGE->blocks->region_has_content('side-pre', $OUTPUT);
  27. $hassidepost = $PAGE->blocks->region_has_content('side-post', $OUTPUT);
  28. }
  29. catch (Exception $e) {}
  30. $conditions['side-pre'] = $conditions['blocks'] && $hassidepre;
  31. $conditions['side-post'] = $conditions['blocks'] && $hassidepost;
  32. //Custom Menu
  33. $conditions['custom-menu-content'] = $OUTPUT->custom_menu();
  34. $conditions['custom-menu'] = empty($PAGE->layout_options['nocustommenu']) && !empty($conditions['custom-menu-content']);
  35. //Body Classes
  36. $bodyclasses = array();
  37. if ($conditions['side-pre'] && !$conditions['side-post']) {
  38. $bodyclasses[] = 'side-pre-only';
  39. }
  40. else if (!$conditions['side-pre'] && $conditions['side-post']) {
  41. $bodyclasses[] = 'side-post-only';
  42. }
  43. else if (!$conditions['side-pre'] && !$conditions['side-post']) {
  44. $bodyclasses[] = 'content-only';
  45. }
  46. if ($conditions['custom-menu']) {
  47. $bodyclasses[] = 'has-custom-menu';
  48. }
  49. $conditions['body-classes'] = $PAGE->bodyclasses.' '.join(' ', $bodyclasses);
  50. //Course Page
  51. $conditions['course-view'] = ($PAGE->course->id > 1) && ($PAGE->bodyid == 'page-course-view-topics');
  52. return $conditions;
  53. }
  54. /**
  55. * Get table or file error message.
  56. * @return string (HTML)
  57. */
  58. function cubic_get_file_error($url) {
  59. return
  60. html_writer::start_tag('div', array('class' => 'notifytiny notifyproblem')).
  61. get_string('plugin-missing', 'theme_cubic')." <a href=\"$url\" >$url</a>".
  62. html_writer::end_tag('div').
  63. html_writer::start_tag('div', array('class' => 'notifytiny notifywarning')).
  64. get_string('plugin-note', 'theme_cubic').
  65. html_writer::end_tag('div');
  66. }
  67. /**
  68. * USER BAR FUNCTIONS
  69. *-------------------------------------------------------------------------------------------------*/
  70. /**
  71. * Get logo base on theme settings.
  72. * @return string (HTML)
  73. */
  74. function cubic_get_logo() {
  75. global $PAGE, $OUTPUT;
  76. if (!empty($PAGE->theme->settings->bar_logo)) {
  77. $image = $OUTPUT->pix_url($PAGE->theme->settings->bar_logo, 'theme');
  78. } else {
  79. $image = $OUTPUT->pix_url('logo', 'theme');
  80. }
  81. $html = '<img src="'.$image.'" alt="'.cubic_get_title().'" />';
  82. return $html;
  83. }
  84. /**
  85. * Get user picture.
  86. * @param int $size - picture size.
  87. * @return string (HTML)
  88. */
  89. function cubic_get_user_picture($size) {
  90. global $PAGE, $OUTPUT, $USER;
  91. $html = '';
  92. if(isloggedin() && !isguestuser()) {
  93. $html.= $OUTPUT->user_picture($USER, array('size' => $size));
  94. }
  95. else {
  96. if($size > 35) {
  97. $html.= '<img src="'.$OUTPUT->pix_url('g/f1').'" />';
  98. }
  99. else {
  100. $html.= '<img src="'.$OUTPUT->pix_url('g/f2').'" />';
  101. }
  102. }
  103. return $html;
  104. }
  105. /**
  106. * Check if is to show institutions section on user bar.
  107. * @return bool
  108. */
  109. function cubic_show_institutions() {
  110. global $PAGE;
  111. if (!empty($PAGE->theme->settings->show_institutions)) {
  112. return true;
  113. } else {
  114. return false;
  115. }
  116. }
  117. /**
  118. * Check if is to show applications section on user bar.
  119. * @return bool
  120. */
  121. function cubic_show_applications() {
  122. global $PAGE;
  123. if (!empty($PAGE->theme->settings->show_applications)) {
  124. return true;
  125. } else {
  126. return false;
  127. }
  128. }
  129. /**
  130. * Get current logged user courses.
  131. * @return array
  132. */
  133. function cubic_get_courses_list($fields=null) {
  134. global $CFG;
  135. include_once($CFG->dirroot . '/course/lib.php');
  136. return enrol_get_my_courses($fields, 'visible DESC, fullname ASC');
  137. }
  138. /**
  139. * Get current logged user events for his courses.
  140. * @param int $records - num of records to search for.
  141. * @return array
  142. */
  143. function cubic_get_events_list($records, $count=false) {
  144. global $CFG;
  145. if(isloggedin() && !isguestuser()) {
  146. //Filter Events by Course
  147. include_once($CFG->dirroot .'/calendar/lib.php');
  148. $filtercourse = calendar_get_default_courses();
  149. list($coursesIds, $group, $user) = calendar_set_filters($filtercourse);
  150. $key = array_search(1, $coursesIds);
  151. unset($coursesIds[$key]);
  152. //Get User Preferences for Calendar
  153. if($count) {
  154. $lookahead = 7;
  155. //Count Events
  156. return count(calendar_get_upcoming($coursesIds, $group, $user, $lookahead, $records));
  157. }
  158. else {
  159. $defaultlookahead = CALENDAR_DEFAULT_UPCOMING_LOOKAHEAD;
  160. if (isset($CFG->calendar_lookahead)) {
  161. $defaultlookahead = intval($CFG->calendar_lookahead);
  162. }
  163. $lookahead = get_user_preferences('calendar_lookahead', $defaultlookahead);
  164. //Get Events
  165. return calendar_get_upcoming($coursesIds, $group, $user, $lookahead, $records);
  166. }
  167. }
  168. else {
  169. return array();
  170. }
  171. }
  172. /**
  173. * Get current logged user notifications for his courses.
  174. * @param array $coursesList - current user courses.
  175. * @param int $records - num of records to search for.
  176. * @param bool $count - determines if its returned the number or the list of notifications.
  177. * @param bool $recent - if true the query will search for notifications only for the current day.
  178. * @return string or array
  179. */
  180. function cubic_get_notifications_list($coursesList, $records=0, $count=false, $recent=false) {
  181. global $CFG, $DB, $USER;
  182. if(isloggedin() && !isguestuser()) {
  183. //Get User Courses
  184. $i = 0;
  185. $courses = '';
  186. $extra = '';
  187. $len = count($coursesList);
  188. if($len > 0) {
  189. foreach($coursesList as $course) {
  190. $courses.= $course->id;
  191. if($i != $len - 1) {
  192. $courses.=', ';
  193. }
  194. $i++;
  195. }
  196. //Set Notifications Date
  197. if($recent) {
  198. $extra.= 'AND DATE(FROM_UNIXTIME({forum_posts}.modified)) = DATE(NOW()) ';
  199. }
  200. // Set User (if counting do not count the current user posts)
  201. if($count) {
  202. //$extra = 'AND {forum_posts}.userid != '.$USER->id;
  203. }
  204. //Set Limit
  205. if($records > 0) {
  206. $records = ' LIMIT '.$records;
  207. }
  208. else {
  209. $records = ';';
  210. }
  211. //Query
  212. $query =
  213. 'SELECT {forum_posts}.id as idP, {forum_posts}.discussion, {forum_posts}.subject, '.
  214. '{forum_posts}.message, {forum_posts}.modified, {forum_posts}.userid, '.
  215. '{forum_discussions}.id as idD, {forum_discussions}.forum, '.
  216. '{forum}.id as idF, {forum}.course, {forum}.type '.
  217. 'FROM {forum} JOIN {forum_discussions} ON {forum}.id = {forum_discussions}.forum '.
  218. 'JOIN {forum_posts} ON {forum_discussions}.id = {forum_posts}.discussion '.
  219. 'WHERE {forum}.type = "news" '.$extra.' AND {forum}.course IN ('.$courses.') '.
  220. 'ORDER BY {forum_posts}.modified DESC'.$records;
  221. $list = $DB->get_records_sql($query);
  222. return $count? count($list) : $list;
  223. }
  224. else {
  225. return $count? 0 : array();
  226. }
  227. }
  228. else {
  229. return array();
  230. }
  231. }
  232. /**
  233. * Count notifications for current day.
  234. * @return string (HTML)
  235. */
  236. function cubic_get_notifications_count() {
  237. global $USER;
  238. $html = '';
  239. if(isloggedin() && !isguestuser()) {
  240. $notifications = cubic_get_notifications_list(cubic_get_courses_list(), 0, true, true);
  241. if($notifications > 0 && $notifications < 100) {
  242. $html = '<span class="counter">'.$notifications.'</span>';
  243. }
  244. else if($notifications >= 100) {
  245. $html = '<span class="counter">99</span>';
  246. }
  247. }
  248. return $html;
  249. }
  250. /**
  251. * Count events for next week.
  252. * @return string (HTML)
  253. */
  254. function cubic_get_events_count() {
  255. global $USER;
  256. $html = '';
  257. if(isloggedin() && !isguestuser()) {
  258. $events = cubic_get_events_list(99, true);
  259. if($events > 0 && $events < 100) {
  260. $html = '<span class="counter">'.$events.'</span>';
  261. }
  262. else if($events >= 100) {
  263. $html = '<span class="counter">99</span>';
  264. }
  265. }
  266. return $html;
  267. }
  268. /**
  269. * Count unread messages.
  270. * @return string (HTML)
  271. */
  272. function cubic_get_messages_count() {
  273. global $DB, $USER;
  274. $html = '';
  275. if(isloggedin() && !isguestuser()) {
  276. //Get Number of Unread Messages
  277. $messages = $DB->count_records('message', array('useridto' => $USER->id));
  278. if($messages > 0 && $messages < 100) {
  279. $html = '<span class="counter">'.$messages.'</span>';
  280. }
  281. else if($messages >= 100) {
  282. $html = '<span class="counter">99</span>';
  283. }
  284. }
  285. return $html;
  286. }
  287. /**
  288. * Get current user institutions menu.
  289. * @return string (HTML)
  290. */
  291. function cubic_get_user_institutions() {
  292. global $CFG, $OUTPUT;
  293. $file = $CFG->dirroot . '/local/institutions/lib.php';
  294. $html = '<div class="container">';
  295. if(!@file_exists($file) ) {
  296. $html.= cubic_get_file_error('https://moodle.org/plugins/view.php?plugin=local_institutions').'</div>';
  297. }
  298. else {
  299. include_once($file);
  300. $title = get_string('menu-intitutions','theme_cubic');
  301. if(!local_institutions_table_exists()) {
  302. $html.= local_institutions_print_table_error();
  303. }
  304. else {
  305. $institutionsList = local_institutions_get_all();
  306. if(count($institutionsList) > 0) {
  307. foreach($institutionsList as $institution) {
  308. $html.=
  309. '<div class="institution">'.
  310. '<a href="'.$CFG->wwwroot.'/local/institutions/view.php?id='.$institution->id.'">'.
  311. $institution->shortname.
  312. '<img src="'.$institution->logo.'" />'.
  313. '</a>'.
  314. '</div>';
  315. }
  316. }
  317. else {
  318. $html.=
  319. '<div class="empty">'.
  320. get_string('empty-institutions','theme_cubic').
  321. '</div>';
  322. }
  323. }
  324. $html.=
  325. '</div>'.
  326. '<a href="'.$CFG->wwwroot.'/local/institutions/" class="all">'.
  327. get_string('see-all','theme_cubic').' '.$title.
  328. '</a>';
  329. }
  330. return $html;
  331. }
  332. /**
  333. * Get current user courses menu.
  334. * @param string $title - menu title.
  335. * @return string (HTML)
  336. */
  337. function cubic_get_user_courses() {
  338. global $DB, $CFG, $OUTPUT;
  339. $title = get_string('menu-courses','theme_cubic');
  340. $html = '';
  341. if(isloggedin() && !isguestuser()) {
  342. $html.= '<div class="container">';
  343. //Get User Courses
  344. $coursesList = cubic_get_courses_list('id, fullname');
  345. if(count($coursesList) > 0) {
  346. foreach($coursesList as $course) {
  347. $html.=
  348. '<div class="course">'.
  349. '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'.
  350. $course->fullname.
  351. '<img src="'.$OUTPUT->pix_url('i/course').'" class="icon" />'.
  352. '</a>'.
  353. '</div>';
  354. }
  355. }
  356. else {
  357. $html.=
  358. '<div class="empty">'.
  359. get_string('empty-courses','theme_cubic').
  360. '</div>';
  361. }
  362. $html.=
  363. '</div>'.
  364. '<a href="'.$CFG->wwwroot.'/course/" class="all">'.
  365. get_string('see-all','theme_cubic').' '.$title.
  366. '</a>';
  367. }
  368. return $html;
  369. }
  370. /**
  371. * Get current user applications menu.
  372. * @param string $title - menu title.
  373. * @return string (HTML)
  374. */
  375. function cubic_get_user_applications() {
  376. global $CFG, $OUTPUT;
  377. $file = $CFG->dirroot . '/local/applications/lib.php';
  378. $html = '<div class="container">';
  379. if(!@file_exists($file) ) {
  380. $html.= cubic_get_file_error('https://moodle.org/plugins/view.php?plugin=local_applications').'</div>';
  381. }
  382. else {
  383. include_once($file);
  384. $title = get_string('menu-applications','theme_cubic');
  385. if(!local_applications_table_exists()) {
  386. $html.= local_applications_print_table_error();
  387. }
  388. else {
  389. $applicationsList = local_applications_get_user_apps();
  390. if(count($applicationsList) > 0) {
  391. foreach($applicationsList as $application) {
  392. $html.=
  393. '<div class="application">'.
  394. '<a href="'.$CFG->wwwroot.'/local/applications/view.php?id='.$application->id.'">'.
  395. $application->name.
  396. '<img src="'.$application->icon.'" />'.
  397. '</a>'.
  398. '</div>';
  399. }
  400. }
  401. else {
  402. $html.=
  403. '<div class="empty">'.
  404. get_string('empty-applications','theme_cubic').
  405. '</div>';
  406. }
  407. }
  408. $html.=
  409. '</div>'.
  410. '<a href="'.$CFG->wwwroot.'/local/applications/" class="all">'.
  411. get_string('see-all','theme_cubic').' '.$title.
  412. '</a>';
  413. }
  414. return $html;
  415. }
  416. /**
  417. * Get current user activities menu.
  418. * @param string $title - menu title.
  419. * @return string (HTML)
  420. */
  421. function cubic_get_user_activities() {
  422. global $DB, $CFG, $OUTPUT, $USER;
  423. $title = get_string('menu-activities','theme_cubic');
  424. $html = '';
  425. if(isloggedin() && !isguestuser()) {
  426. $html.= '<div class="container">';
  427. //Get User Courses
  428. $coursesList = cubic_get_courses_list('id, fullname');
  429. $hasActivities = false;
  430. foreach($coursesList as $course) {
  431. //Get Activities of Current Course
  432. $activitiesList = get_array_of_activities($course->id);
  433. if(count($activitiesList) > 0) {
  434. $html.= '<div class="division">'.$course->fullname.'</div>';
  435. foreach($activitiesList as $activity) {
  436. if($activity->mod != 'label' && $activity->mod != 'folder' && $activity->mod != 'resource'
  437. && ($activity->visible or $activity->has_view())) {
  438. $hasActivities = true;
  439. $imgsrc = isset($activity->iconurl)? $activity->iconurl->out() : $OUTPUT->pix_url('icon', $activity->mod);
  440. $html.=
  441. '<div class="activity">'.
  442. '<a href="'.$CFG->wwwroot.'/mod/'.$activity->mod.'/view.php?id='.$activity->cm.'">'.
  443. $activity->name.
  444. '<img src="'.$imgsrc.'" class="icon" />'.
  445. '</a>'.
  446. '</div>';
  447. }
  448. }
  449. }
  450. }
  451. if(!$hasActivities) {
  452. $html.=
  453. '<div class="empty">'.
  454. get_string('empty-activities','theme_cubic').
  455. '</div>';
  456. }
  457. $html.= '</div>';
  458. }
  459. return $html;
  460. }
  461. /**
  462. * Get current user notifications menu.
  463. * @param string $title - menu title.
  464. * @param int $records - num of records to search for.
  465. * @return string (HTML)
  466. */
  467. function cubic_get_user_notifications($records=0) {
  468. global $DB, $CFG, $OUTPUT;
  469. $title = get_string('menu-notifications','theme_cubic');
  470. $html = '';
  471. if(isloggedin() && !isguestuser()) {
  472. if(!$records) {
  473. $html.= '<div class="title">'.$title.'</div><div class="ajax"></div><div class="container">';
  474. }
  475. else {
  476. $hasNotifications = false;
  477. //Get Notifications of Current Course
  478. $coursesList = cubic_get_courses_list('id, shortname');
  479. $notificationsList = cubic_get_notifications_list($coursesList, $records);
  480. foreach($notificationsList as $notification) {
  481. $hasNotifications = true;
  482. $user = $DB->get_record('user', array('id' => $notification->userid), 'id, firstname, lastname, email, picture, imagealt');
  483. $html.=
  484. '<div class="notification">'.
  485. '<a href="'.$CFG->wwwroot.'/mod/forum/discuss.php?d='.$notification->idd.'#p'.$notification->idp.'" />'.
  486. '<div class="picture">'.
  487. $OUTPUT->user_picture($user, array('size' => 50)).
  488. '</div>'.
  489. '<div class="content">'.
  490. '<p class="subject">' . $notification->subject . '</p>'.
  491. '<p class="body">' . $notification->message . '</p>'.
  492. '<p class="course">' . $coursesList[$notification->course]->shortname . '</p>'.
  493. '<p class="time">' . userdate($notification->modified, get_string('strftimerecent')) . '</p>'.
  494. '</div>'.
  495. '</div>';
  496. }
  497. if(!$hasNotifications) {
  498. $html.=
  499. '<div class="empty">'.
  500. get_string('empty-notifications','theme_cubic').
  501. '</div>';
  502. }
  503. }
  504. if(!$records) {
  505. $html.= '</div>';
  506. }
  507. }
  508. return $html;
  509. }
  510. /**
  511. * Get current user events menu.
  512. * @param string $title - menu title.
  513. * @param int $records - num of records to search for.
  514. * @return string (HTML)
  515. */
  516. function cubic_get_user_events($records=0) {
  517. global $DB, $CFG, $OUTPUT;
  518. $title = get_string('menu-events','theme_cubic');
  519. $html = '';
  520. if(isloggedin() && !isguestuser()) {
  521. if(!$records) {
  522. $html.= '<div class="title">'.$title.'</div><div class="ajax"></div><div class="container">';
  523. }
  524. else {
  525. $coursesList = cubic_get_courses_list();
  526. $eventsList = cubic_get_events_list($records);
  527. if(count($eventsList) > 0) {
  528. foreach($eventsList as $event) {
  529. $date = getdate($event->timestart);
  530. $html.=
  531. '<div class="event">'.
  532. '<a href="'.$CFG->wwwroot.'/calendar/view.php?view=day&course='.$event->courseid.'&cal_d='.$date['mday'].'&cal_m='.$date['mon'].'&cal_y='.$date['year'].'#event_'.$event->id.'"></a>'.
  533. '<div class="picture">'.
  534. '<img src="'.$OUTPUT->pix_url('c/'.$event->eventtype).'" class="icon" />'.
  535. '<div class="color calendar_event_'.$event->eventtype.'"></div>'.
  536. '</div>'.
  537. '<div class="content">'.
  538. '<p class="name">' . $event->name . '</p>'.
  539. $event->description;
  540. if($event->eventtype == 'course') {
  541. $html.= '<p class="course">' . $coursesList[$event->courseid]->shortname . '</p>';
  542. }
  543. $html.=
  544. '<p class="time">'.
  545. userdate($event->timestart, get_string('strftimerecent')).
  546. '</p>'.
  547. '</div>'.
  548. '</div>';
  549. }
  550. }
  551. else {
  552. $html.=
  553. '<div class="empty">'.
  554. get_string('empty-events','theme_cubic').
  555. '</div>';
  556. }
  557. }
  558. if(!$records) {
  559. $html.=
  560. '</div>'.
  561. '<a href="'.$CFG->wwwroot.'/calendar/view.php" class="all">'.
  562. get_string('see-all','theme_cubic').' '.$title.
  563. '</a>';
  564. }
  565. }
  566. return $html;
  567. }
  568. /**
  569. * Get current user messages menu.
  570. * @param string $title - menu title.
  571. * @param int $records - num of records to search for.
  572. * @return string (HTML)
  573. */
  574. function cubic_get_user_messages($records=0) {
  575. global $DB, $CFG, $USER, $OUTPUT;
  576. $title = get_string('menu-messages','theme_cubic');
  577. $html = '';
  578. if(isloggedin() && !isguestuser()) {
  579. if(!$records) {
  580. $html.= '<div class="title">'.$title.'</div><div class="ajax"></div><div class="container">';
  581. }
  582. else {
  583. //Get Unread Messages
  584. $messagesList = $DB->get_records('message', array('useridto' => $USER->id), 'timecreated desc', 'id, useridfrom, useridto, smallmessage, timecreated', 0, $records);
  585. if(count($messagesList) < $records) {
  586. //Get Read Messages
  587. $readMessages = $DB->get_records('message_read', array('useridto' => $USER->id), 'timecreated desc', 'id, useridfrom, useridto, smallmessage, timecreated', 0, $records-count($messagesList));
  588. $messagesList = array_merge($messagesList, $readMessages);
  589. }
  590. if(count($messagesList) > 0) {
  591. foreach($messagesList as $message) {
  592. $from = $DB->get_record('user', array('id' => $message->useridfrom), 'id, firstname, lastname, email, picture, imagealt');
  593. $html.=
  594. '<div class="message">'.
  595. '<a href="'.$CFG->wwwroot.'/message/index.php?viewing=unread&user2='.$message->useridfrom.'" />'.
  596. '<div class="picture">'.
  597. $OUTPUT->user_picture($from, array('size' => 50)).
  598. '</div>'.
  599. '<div class="content">'.
  600. '<p class="sender">' . $from->firstname.' '.$from->lastname. '</p>'.
  601. '<p class="body">' . $message->smallmessage . '</p>'.
  602. '<p class="time">' . userdate($message->timecreated, get_string('strftimerecent')) . '</p>'.
  603. '</div>'.
  604. '</div>';
  605. }
  606. }
  607. else {
  608. $html.=
  609. '<div class="empty">'.
  610. get_string('empty-messages','theme_cubic').
  611. '</div>';
  612. }
  613. }
  614. if(!$records) {
  615. $html.=
  616. '</div>'.
  617. '<a href="'.$CFG->wwwroot.'/message/" class="all">'.
  618. get_string('see-all','theme_cubic').' '.$title.
  619. '</a>';
  620. }
  621. }
  622. return $html;
  623. }
  624. /**
  625. * Get system languages menu.
  626. * @param string $title - menu title.
  627. * @return string (HTML)
  628. */
  629. function cubic_get_languages() {
  630. global $OUTPUT;
  631. $title = get_string('menu-languages','theme_cubic');
  632. $html =
  633. '<div class="title">'.$title.'</div>'.
  634. $OUTPUT->lang_menu().
  635. '<div class="container"></div>';
  636. return $html;
  637. }
  638. /**
  639. * Get current user information menu.
  640. * @return string (HTML)
  641. */
  642. function cubic_get_user_info() {
  643. global $CFG, $USER, $OUTPUT;
  644. $html = '<table><tr><td>';
  645. if(isloggedin() && !isguestuser()) {
  646. $html.=
  647. '<a href="' . $CFG->wwwroot.'/user/view.php?id='.$USER->id . '">'.
  648. '<h2>' . $USER->firstname.' '.$USER->lastname . '</h2>'.
  649. '</a>';
  650. if(!empty($USER->email)) {
  651. $html.= '<p class="email">' . $USER->email . '</p>';
  652. }
  653. if(!empty($USER->phone2)) {
  654. $html.= '<p class="phone">' . $USER->phone2 . '</p>';
  655. }
  656. $social = '';
  657. if(!empty($USER->url)) {
  658. $social.= '<a class="website" title="Website" href="'.$USER->url.'" target="_blank"></a>';
  659. }
  660. if(!empty($USER->icq)) {
  661. $social.= '<span class="icq" title="'.$USER->icq.'"></span>';
  662. }
  663. if(!empty($USER->skype)) {
  664. $social.= '<span class="skype" title="'.$USER->skype.'"></span>';
  665. }
  666. if(!empty($USER->yahoo)) {
  667. $social.= '<span class="yahoo" title="'.$USER->yahoo.'"></span>';
  668. }
  669. if(!empty($USER->aim)) {
  670. $social.= '<span class="aim" title="'.$USER->aim.'"></span>';
  671. }
  672. if(!empty($USER->msn)) {
  673. $social.= '<span class="msn" title="'.$USER->msn.'"></span>';
  674. }
  675. $html.= '<div class="social">'.$social.'</div></td>';
  676. }
  677. else {
  678. $html.=
  679. '<h2>'.get_string('guest','theme_cubic').'</h2>'.
  680. '<p class="desc">'.get_string('nouser-info','theme_cubic').'</p>';
  681. }
  682. $html.= '</td><td>'.cubic_get_user_picture(85).'</td></tr></table>';
  683. return $html;
  684. }
  685. /**
  686. * Get current user settings menu.
  687. * @param string $title - menu title.
  688. * @return string (HTML)
  689. */
  690. function cubic_get_user_settings() {
  691. global $CFG, $USER, $OUTPUT;
  692. $title = get_string('menu-settings','theme_cubic');
  693. $html = '<div class="title">'.$title.'</div>';
  694. if(isloggedin() && !isguestuser()) {
  695. $html.=
  696. '<div class="container">'.
  697. '<div class="setting">'.
  698. '<a href="'.$CFG->wwwroot.'/user/edit.php?id='.$USER->id.'">'.
  699. get_string('settings-edit','theme_cubic').
  700. '<img src="'.$OUTPUT->pix_url('t/edit').'" class="icon" />'.
  701. '</a>'.
  702. '</div>'.
  703. '<div class="setting">'.
  704. '<a href="'.$CFG->wwwroot.'/login/change_password.php?id=1">'.
  705. get_string('settings-password','theme_cubic').
  706. '<img src="'.$OUTPUT->pix_url('i/key').'" class="icon" />'.
  707. '</a>'.
  708. '</div>'.
  709. '<div class="setting">'.
  710. '<a href="'.$CFG->wwwroot.'/message/edit.php?id='.$USER->id.'">'.
  711. get_string('settings-msg','theme_cubic').
  712. '<img src="'.$OUTPUT->pix_url('t/email').'" class="icon" />'.
  713. '</a>'.
  714. '</div>'.
  715. '<div class="setting">'.
  716. '<a href="'.$CFG->wwwroot.'/login/logout.php?sesskey='.sesskey().'">'.
  717. get_string('settings-logout','theme_cubic').
  718. '<img src="'.$OUTPUT->pix_url('a/logout').'" class="icon" />'.
  719. '</a>'.
  720. '</div>'.
  721. '</div>';
  722. }
  723. else {
  724. $html.=
  725. '<div class="container">'.
  726. '<div class="setting">'.
  727. '<a href="'.$CFG->wwwroot.'/login/index.php">'.
  728. get_string('settings-login','theme_cubic').
  729. '<img src="'.$OUTPUT->pix_url('a/login').'" class="icon" />'.
  730. '</a>'.
  731. '</div>'.
  732. '<div class="setting">'.
  733. '<a href="'.$CFG->wwwroot.'/login/forgot_password.php">'.
  734. get_string('settings-reset','theme_cubic').
  735. '<img src="'.$OUTPUT->pix_url('i/key').'" class="icon" />'.
  736. '</a>'.
  737. '</div>'.
  738. '</div>';
  739. }
  740. return $html;
  741. }
  742. /**
  743. * SETTINGS FUNCTIONS
  744. *-------------------------------------------------------------------------------------------------*/
  745. /**
  746. * Get system name.
  747. * @return string
  748. */
  749. function cubic_get_title() {
  750. global $PAGE;
  751. if (!empty($PAGE->theme->settings->title)) {
  752. return $PAGE->theme->settings->title;
  753. } else {
  754. return get_string('pluginname', 'theme_cubic');
  755. }
  756. }
  757. /**
  758. * Get activities view mode.
  759. * @return string
  760. */
  761. function cubic_get_activities_view() {
  762. global $PAGE;
  763. if (!empty($PAGE->theme->settings->activity_view)) {
  764. return $PAGE->theme->settings->activity_view;
  765. } else {
  766. return 'icons';
  767. }
  768. }
  769. /**
  770. * Process CSS files based on theme settings.
  771. */
  772. function cubic_process_css($css, $theme) {
  773. //Set Bar Color
  774. if (!empty($theme->settings->bar_color)) {
  775. $bar_color = $theme->settings->bar_color;
  776. } else {
  777. $bar_color = null;
  778. }
  779. $css = cubic_set_bar_color($css, $bar_color);
  780. //Set Bar Border Color
  781. if (!empty($theme->settings->bar_border_color)) {
  782. $bar_border_color = $theme->settings->bar_border_color;
  783. } else {
  784. $bar_border_color = null;
  785. }
  786. $css = cubic_set_bar_border_color($css, $bar_border_color);
  787. //Set Bar Text Color
  788. if (!empty($theme->settings->bar_text_color)) {
  789. $bar_text_color = $theme->settings->bar_text_color;
  790. } else {
  791. $bar_text_color = null;
  792. }
  793. $css = cubic_set_bar_text_color($css, $bar_text_color);
  794. //Set Bar Hover Color
  795. if (!empty($theme->settings->bar_hover_color)) {
  796. $bar_hover_color = $theme->settings->bar_hover_color;
  797. } else {
  798. $bar_hover_color = null;
  799. }
  800. $css = cubic_set_bar_hover_color($css, $bar_hover_color);
  801. //Set Menu Bottom Section Color
  802. if (!empty($theme->settings->menu_all_color)) {
  803. $menu_all_color = $theme->settings->menu_all_color;
  804. } else {
  805. $menu_all_color = null;
  806. }
  807. $css = cubic_set_menu_all_color($css, $menu_all_color);
  808. //Set Text Color
  809. if (!empty($theme->settings->text_color)) {
  810. $text_color = $theme->settings->text_color;
  811. } else {
  812. $text_color = null;
  813. }
  814. $css = cubic_set_text_color($css, $text_color);
  815. //Set Hover Color
  816. if (!empty($theme->settings->hover_color)) {
  817. $hover_color = $theme->settings->hover_color;
  818. } else {
  819. $hover_color = null;
  820. }
  821. $css = cubic_set_hover_color($css, $hover_color);
  822. //Set Links Color
  823. if (!empty($theme->settings->links_color)) {
  824. $links_color = $theme->settings->links_color;
  825. } else {
  826. $links_color = null;
  827. }
  828. $css = cubic_set_links_color($css, $links_color);
  829. //Set Borders Color
  830. if (!empty($theme->settings->borders_color)) {
  831. $borders_color = $theme->settings->borders_color;
  832. } else {
  833. $borders_color = null;
  834. }
  835. $css = cubic_set_borders_color($css, $borders_color);
  836. //Set Buttons Top Color
  837. if (!empty($theme->settings->button_top_color)) {
  838. $button_top_color = $theme->settings->button_top_color;
  839. } else {
  840. $button_top_color = null;
  841. }
  842. $css = cubic_set_button_top_color($css, $button_top_color);
  843. //Set Buttons Bottom Color
  844. if (!empty($theme->settings->button_bottom_color)) {
  845. $button_bottom_color = $theme->settings->button_bottom_color;
  846. } else {
  847. $button_bottom_color = null;
  848. }
  849. $css = cubic_set_button_bottom_color($css, $button_bottom_color);
  850. //Set Buttons Border Color
  851. if (!empty($theme->settings->button_border_color)) {
  852. $button_border_color = $theme->settings->button_border_color;
  853. } else {
  854. $button_border_color = null;
  855. }
  856. $css = cubic_set_button_border_color($css, $button_border_color);
  857. //Set Custom CSS
  858. if (!empty($theme->settings->custom_css)) {
  859. $custom_css = $theme->settings->custom_css;
  860. } else {
  861. $custom_css = null;
  862. }
  863. $css = cubic_set_custom_css($css, $custom_css);
  864. return $css;
  865. }
  866. /**
  867. * Sets the bar background color variable in CSS
  868. *
  869. * @param string $css
  870. * @param mixed $bar_color
  871. * @return string
  872. */
  873. function cubic_set_bar_color($css, $bar_color) {
  874. $tag = '[[setting:bar_color]]';
  875. $replacement = $bar_color;
  876. if (is_null($replacement)) {
  877. $replacement = '#295A34';
  878. }
  879. $css = str_replace($tag, $replacement, $css);
  880. return $css;
  881. }
  882. /**
  883. * Sets the bar border color variable in CSS
  884. *
  885. * @param string $css
  886. * @param mixed $bar_border_color
  887. * @return string
  888. */
  889. function cubic_set_bar_border_color($css, $bar_border_color) {
  890. $tag = '[[setting:bar_border_color]]';
  891. $replacement = $bar_border_color;
  892. if (is_null($replacement)) {
  893. $replacement = '#173920';
  894. }
  895. $css = str_replace($tag, $replacement, $css);
  896. return $css;
  897. }
  898. /**
  899. * Sets the bar text color variable in CSS
  900. *
  901. * @param string $css
  902. * @param mixed $bar_text_color
  903. * @return string
  904. */
  905. function cubic_set_bar_text_color($css, $bar_text_color) {
  906. $tag = '[[setting:bar_text_color]]';
  907. $replacement = $bar_text_color;
  908. if (is_null($replacement)) {
  909. $replacement = '#B0DDBA';
  910. }
  911. $css = str_replace($tag, $replacement, $css);
  912. return $css;
  913. }
  914. /**
  915. * Sets the bar hover color variable in CSS
  916. *
  917. * @param string $css
  918. * @param mixed $bar_hover_color
  919. * @return string
  920. */
  921. function cubic_set_bar_hover_color($css, $bar_hover_color) {
  922. $tag = '[[setting:bar_hover_color]]';
  923. $replacement = $bar_hover_color;
  924. if (is_null($replacement)) {
  925. $replacement = '#397548';
  926. }
  927. $css = str_replace($tag, $replacement, $css);
  928. return $css;
  929. }
  930. /**
  931. * Sets the menu bottom section color variable in CSS
  932. *
  933. * @param string $css
  934. * @param mixed $menu_all_color
  935. * @return string
  936. */
  937. function cubic_set_menu_all_color($css, $menu_all_color) {
  938. $tag = '[[setting:menu_all_color]]';
  939. $replacement = $menu_all_color;
  940. if (is_null($replacement)) {
  941. $replacement = '#E2F3E6';
  942. }
  943. $css = str_replace($tag, $replacement, $css);
  944. return $css;
  945. }
  946. /**
  947. * Sets the text color variable in CSS
  948. *
  949. * @param string $css
  950. * @param mixed $text_color
  951. * @return string
  952. */
  953. function cubic_set_text_color($css, $text_color) {
  954. $tag = '[[setting:text_color]]';
  955. $replacement = $text_color;
  956. if (is_null($replacement)) {
  957. $replacement = '#000000';
  958. }
  959. $css = str_replace($tag, $replacement, $css);
  960. return $css;
  961. }
  962. /**
  963. * Sets the hover color variable in CSS
  964. *
  965. * @param string $css
  966. * @param mixed $hover_color
  967. * @return string
  968. */
  969. function cubic_set_hover_color($css, $hover_color) {
  970. $tag = '[[setting:hover_color]]';
  971. $replacement = $hover_color;
  972. if (is_null($replacement)) {
  973. $replacement = '#F1F1F1';
  974. }
  975. $css = str_replace($tag, $replacement, $css);
  976. return $css;
  977. }
  978. /**
  979. * Sets the links color variable in CSS
  980. *
  981. * @param string $css
  982. * @param mixed $links_color
  983. * @return string
  984. */
  985. function cubic_set_links_color($css, $links_color) {
  986. $tag = '[[setting:links_color]]';
  987. $replacement = $links_color;
  988. if (is_null($replacement)) {
  989. $replacement = '#295A34';
  990. }
  991. $css = str_replace($tag, $replacement, $css);
  992. return $css;
  993. }
  994. /**
  995. * Sets the borders color variable in CSS
  996. *
  997. * @param string $css
  998. * @param mixed $borders_color
  999. * @return string
  1000. */
  1001. function cubic_set_borders_color($css, $borders_color) {
  1002. $tag = '[[setting:borders_color]]';
  1003. $replacement = $borders_color;
  1004. if (is_null($replacement)) {
  1005. $replacement = '#DDD';
  1006. }
  1007. $css = str_replace($tag, $replacement, $css);
  1008. return $css;
  1009. }
  1010. /**
  1011. * Sets the buttons top color variable in CSS
  1012. *
  1013. * @param string $css
  1014. * @param mixed $button_top_color
  1015. * @return string
  1016. */
  1017. function cubic_set_button_top_color($css, $button_top_color) {
  1018. $tag = '[[setting:button_top_color]]';
  1019. $replacement = $button_top_color;
  1020. if (is_null($replacement)) {
  1021. $replacement = '#5ECC76';
  1022. }
  1023. $css = str_replace($tag, $replacement, $css);
  1024. return $css;
  1025. }
  1026. /**
  1027. * Sets the buttons bottom color variable in CSS
  1028. *
  1029. * @param string $css
  1030. * @param mixed $button_bottom_color
  1031. * @return string
  1032. */
  1033. function cubic_set_button_bottom_color($css, $button_bottom_color) {
  1034. $tag = '[[setting:button_bottom_color]]';
  1035. $replacement = $button_bottom_color;
  1036. if (is_null($replacement)) {
  1037. $replacement = '#3B804A';
  1038. }
  1039. $css = str_replace($tag, $replacement, $css);
  1040. return $css;
  1041. }
  1042. /**
  1043. * Sets the buttons border color variable in CSS
  1044. *
  1045. * @param string $css
  1046. * @param mixed $button_border_color
  1047. * @return string
  1048. */
  1049. function cubic_set_button_border_color($css, $button_border_color) {
  1050. $tag = '[[setting:button_border_color]]';
  1051. $replacement = $button_border_color;
  1052. if (is_null($replacement)) {
  1053. $replacement = '#2A6639';
  1054. }
  1055. $css = str_replace($tag, $replacement, $css);
  1056. return $css;
  1057. }
  1058. /**
  1059. * Sets the custom css variable in CSS
  1060. *
  1061. * @param string $css
  1062. * @param mixed $custom_css
  1063. * @return string
  1064. */
  1065. function cubic_set_custom_css($css, $custom_css) {
  1066. $tag = '[[setting:custom_css]]';
  1067. $replacement = $custom_css;
  1068. if (is_null($replacement)) {
  1069. $replacement = '';
  1070. }
  1071. $css = str_replace($tag, $replacement, $css);
  1072. return $css;
  1073. }