Esempio n. 1
0
function get_category_info($category)
{
    $posts = get_category_files();
    $tmp = array();
    if (!empty($posts)) {
        foreach ($posts as $index => $v) {
            if (stripos($v, $category . '.md') !== false) {
                $desc = new stdClass();
                // Replaced string
                $replaced = substr($v, 0, strrpos($v, '/')) . '/';
                // The static page URL
                $url = str_replace($replaced, '', $v);
                $desc->url = site_url() . 'category/' . str_replace('.md', '', $url);
                $desc->md = str_replace('.md', '', $url);
                $desc->file = $v;
                // Get the contents and convert it to HTML
                $content = file_get_contents($v);
                // Extract the title and body
                $desc->title = get_content_tag('t', $content, $category);
                $desc->body = MarkdownExtra::defaultTransform(remove_html_comments($content));
                $desc->description = get_content_tag("d", $content, get_description($desc->body));
                $tmp[] = $desc;
            }
        }
    }
    if (strtolower($category) == 'uncategorized') {
        return default_category();
    }
    return $tmp;
}
 // Everything to Unix Line Endings
 $text = my_file_get_contents($filename);
 $text = preg_replace('!\\r\\n?!', "\n", $text);
 if ($fp = fopen($filename, "w")) {
     fwrite($fp, $text);
     unset($text);
     // Memory!
     fclose($fp);
 } else {
     csverror('File I/O Error! (1)', 'uploadcourse.php?sesskey=' . $USER->sesskey);
 }
 if (!($fp = fopen($filename, "r"))) {
     csverror('File I/O Error! (2)', 'uploadcourse.php?sesskey=' . $USER->sesskey);
 }
 // make arrays of fields for error checking
 $defaultcategory = default_category();
 $defaultmtime = time();
 $required = array('fullname' => false, 'shortname' => false);
 $optional = array('category' => $defaultcategory, 'sortorder' => 0, 'summary' => 'Write a concise and interesting paragraph here that explains what this course is about', 'format' => 'weeks', 'showgrades' => 1, 'newsitems' => 5, 'teacher' => 'Teacher', 'teachers' => 'Teachers', 'student' => 'Student', 'students' => 'Students', 'startdate' => $defaultmtime, 'numsections' => 10, 'maxbytes' => 2097152, 'visible' => 1, 'groupmode' => 0, 'timecreated' => $defaultmtime, 'timemodified' => $defaultmtime, 'idnumber' => '', 'password' => '', 'enrolperiod' => 0, 'groupmodeforce' => 0, 'metacourse' => 0, 'lang' => '', 'theme' => '', 'cost' => '', 'showreports' => 0, 'guest' => 0, 'enrollable' => 1, 'enrolstartdate' => $defaultmtime, 'enrolenddate' => $defaultmtime, 'notifystudents' => 0, 'template' => '', 'expirynotify' => 0, 'expirythreshold' => 10);
 $validate = array('fullname' => array(1, 254, 1), 'shortname' => array(1, 15, 1), 'category' => array(5), 'sortorder' => array(2, 4294967295.0, 0), 'summary' => array(1, 0, 0), 'format' => array(4, 'social,topics,weeks'), 'showgrades' => array(4, '0,1'), 'newsitems' => array(2, 10, 0), 'teacher' => array(1, 100, 1), 'teachers' => array(1, 100, 1), 'student' => array(1, 100, 1), 'students' => array(1, 100, 1), 'startdate' => array(3), 'numsections' => array(2, 52, 0), 'maxbytes' => array(2, $CFG->maxbytes, 0), 'visible' => array(4, '0,1'), 'groupmode' => array(4, NOGROUPS . ',' . SEPARATEGROUPS . ',' . VISIBLEGROUPS), 'timecreated' => array(3), 'timemodified' => array(3), 'idnumber' => array(1, 100, 0), 'password' => array(1, 50, 0), 'enrolperiod' => array(2, 4294967295.0, 0), 'groupmodeforce' => array(4, '0,1'), 'metacourse' => array(4, '0,1'), 'lang' => array(1, 50, 0), 'theme' => array(1, 50, 0), 'cost' => array(1, 10, 0), 'showreports' => array(4, '0,1'), 'guest' => array(4, '0,1,2'), 'enrollable' => array(4, '0,1'), 'enrolstartdate' => array(3), 'enrolenddate' => array(3), 'notifystudents' => array(4, '0,1'), 'template' => array(1, 0, 0), 'expirynotify' => array(4, '0,1'), 'expirythreshold' => array(2, 30, 1), 'topic' => array(1, 0, 0), 'teacher_account' => array(6, 0), 'teacher_role' => array(1, 40, 0));
 $header = fgetcsv($fp, 1024);
 // check for valid field names
 if ($header[0] == null && count($line) < 1) {
     // Blank Line?
     csverror('First line must be the CSV header', 'uploadcourse.php?sesskey=' . $USER->sesskey);
 }
 foreach ($header as $i => $h) {
     if ($h == null) {
         csverror('Null CSV columns are not permitted in header', 'uploadcourse.php?sesskey=' . $USER->sesskey);
     }
     if (preg_match(TOPIC_FIELD, $h)) {