Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- public
- function list_categories()
- {
- global $CFG, $OUTPUT, $DB;
- $header = '<div>
- <h2>category</h2><div class="courses frontpage-course-list-all"><div class="row-fluid">';
- $footer = '</div>
- </div>
- </div>';
- $co_cnt = 1;
- $content = '';
- $noimg_url = $OUTPUT - >
- pix_url('no-image', 'theme');
- $categories = $DB - >
- get_records('course_categories', array(
- 'visible' = & gt;
- '1',
- 'depth' = & gt;
- '1'
- ));
- function URLIsValid($URL)
- {
- $exists = true;
- $file_headers = @get_headers($URL);
- $InvalidHeaders = array(
- '404',
- '403',
- '500'
- );
- foreach($InvalidHeaders as $HeaderVal)
- {
- if (strstr($file_headers[0], $HeaderVal))
- {
- $exists = false;
- break;
- }
- }
- return $exists;
- }
- foreach($categories as $categorie)
- {
- $categorie_url = new moodle_url('/course/category.php', array(
- 'id' = & gt;
- $categorie - >
- id
- ));
- $img_url = $OUTPUT - >
- pix_url('categories/' . $categorie - >
- id, 'theme');
- if (!URLIsValid($img_url))
- {
- $img_url = $noimg_url;
- }
- $content.= '<div class="span3"><div class="fp-coursebox"><div class="fp-coursethumb"><a href="' . $categorie_url . '"><img src="' . $img_url . '" width="243" height="165" alt="' . $categorie - >name . '" /></a></div>
- <div class="fp-courseinfo"><h5><a href="' . $categorie_url . '">' . $categorie - >name . '</a></h5><div class="readmore"><a href="' . $categorie_url . '">En savoir plus<i class="fa fa-angle-double-right"></i></a></div></div></div></div>';
- if (($co_cnt % 4) == "0")
- {
- $content.= '<div class="clearfix hidexs"></div>';
- }
- $co_cnt++;
- }
- $course_html = $header . $content . $footer;
- $frontpage = isset($CFG - >
- frontpage) ? $CFG - >
- frontpage : '';
- $frontpageloggedin = isset($CFG - >
- frontpageloggedin) ? $CFG - >
- frontpageloggedin : '';
- $f1_pos = strpos($frontpage, '6');
- $f2_pos = strpos($frontpageloggedin, '6');
- $btn_html = '';
- if ($co_cnt & lt; = 1 & amp; & amp;
- !$this - >
- page - >
- user_is_editing() & amp; & amp;
- has_capability('moodle/course:create', context_system::instance()))
- {
- $btn_html = $this - >
- add_new_course_button();
- }
- if (!isloggedin() or isguestuser())
- {
- if ($f1_pos === false)
- {
- if ($co_cnt & gt;
- 1)
- {
- echo $course_html;
- }
- }
- }
- else
- {
- if ($f2_pos === false)
- {
- echo $course_html . "<br />" . $btn_html;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement