<commit_before><?php

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.

/**
 * This file contains all the common stuff to be used in RSS System
 *
 * @package   moodlecore
 * @copyright 1999 onwards <NAME>  {@link http://moodle.com}
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */

/**
 * This function returns the icon (from theme) with the link to rss/file.php
 *
 * @global object
 * @global object
 */
function rss_get_link($courseid, $userid, $modulename, $id, $tooltiptext='') {

    global $OUTPUT;

    static $rsspath = '';

    //In site course, if no logged (userid), use admin->id. Bug 2048.
    if ($courseid == SITEID and empty($userid)) {
        $admin = get_admin();
        $userid = $admin->id;
    }

    $rsspath = rss_get_url($courseid, $userid, $modulename, $id);
    $rsspix = $OUTPUT->old_icon_url('i/rss');

    return '<a href="'. $rsspath .'"><img src="'. $rsspix .'" title="'. strip_tags($tooltiptext) .'" alt="'.get_string('rss').'" /></a>';

}

/**
 * This function returns the URL for the RSS XML file.
 *
 * @global object
 */
function rss_get_url($courseid, $userid, $modulename, $id) {
    global $CFG;
    require_once($CFG->libdir.'/filelib.php');
    return get_file_url($courseid.'/'.$userid.'/'.$modulename.'/'.$id.'/rss.xml', null, 'rssfile');
}

/**
 * This function prints the icon (from theme) with the link to rss/file.php
 */
function rss_print_link($courseid, $userid, $modulename, $id, $tooltiptext='') {
    print rss_get_link($courseid, $userid, $modulename, $id, $tooltiptext);

}

/**
 * This function iterates over each module in the server to see if
 * it supports generating rss feeds, searching for a MODULENAME_rss_feeds()
 * function and invoking it foreach activity as necessary
 *
 * @global object
 * @global object
 */
function cron_rss_feeds () {
    global $CFG, $DB;

    $status = true;

    mtrace('    Generating rssfeeds...');

    //Check for required functions...
    if(!function_exists('utf8_encode')) {
        mtrace('        ERROR: You need to add XML support to your PHP installation!');
        return true;
    }

    if ($allmods = $DB->get_records('modules') ) {
        foreach ($allmods as $mod) {
            mtrace('        '.$mod->name.': ', '');
            $modname = $mod->name;
            $modfile = "$CFG->dirroot/mod/$modname/rsslib.php";
            //If file exists and we have selected to restore that type of module
            if (file_exists($modfile)) {
                include_once($modfile);
                $generaterssfeeds = $modname.'_rss_feeds';
                if (function_exists($generaterssfeeds)) {
                    if ($status) {
                        mtrace('generating ', '');;
                        $status = $generaterssfeeds();
                        if (!empty($status)) {
                            mtrace('...OK');
                        } else {
                            mtrace('...FAILED');
                        }
                    } else {
                        mtrace('...SKIPPED (failed above)');
                    }
                } else {
                    mtrace('...NOT SUPPORTED (function)');
                }
            } else {
                mtrace('...NOT SUPPORTED (file)');
            }
        }
    }
    mtrace('    Ending  rssfeeds...', '');
    if (!empty($status)) {
        mtrace('...OK');
    } else {
        mtrace('...FAILED');
    }

    return $status;
}

/**
 * This function saves to file the rss feed specified in the parameters
 *
 * @global object
 */
function rss_save_file($modname, $mod, $result) {
    global $CFG;

    $status = true;

    if (! $basedir = make_upload_directory ('rss/'. $modname)) {
        //Cannot be created, so error
        $status = false;
    }

    if ($status) {
        $file = rss_file_name($modname, $mod);
        $rss_file = fopen($file, "w");
        if ($rss_file) {
            $status = fwrite ($rss_file, $result);
            fclose($rss_file);
        } else {
            $status = false;
        }
    }
    return $status;
}


function rss_file_name($modname, $mod) {
    global $CFG;

    return "$CFG->dataroot/rss/$modname/$mod->id.xml";
}

/**
 * This function return all the common headers for every rss feed in the site
 *
 * @global object
 * @global object
 */
function rss_standard_header($title = NULL, $link = NULL, $description = NULL) {
    global $CFG, $USER;

    $status = true;
    $result = "";

    if (!$site = get_site()) {
        $status = false;
    }
<commit_msg>lib/rsslib - Missing global decloration of $OUTPUT<commit_after><?php

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.

/**
 * This file contains all the common stuff to be used in RSS System
 *
 * @package   moodlecore
 * @copyright 1999 onwards <NAME>  {@link http://moodle.com}
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */

/**
 * This function returns the icon (from theme) with the link to rss/file.php
 *
 * @global object
 * @global object
 */
function rss_get_link($courseid, $userid, $modulename, $id, $tooltiptext='') {

    global $OUTPUT;

    static $rsspath = '';

    //In site course, if no logged (userid), use admin->id. Bug 2048.
    if ($courseid == SITEID and empty($userid)) {
        $admin = get_admin();
        $userid = $admin->id;
    }

    $rsspath = rss_get_url($courseid, $userid, $modulename, $id);
    $rsspix = $OUTPUT->old_icon_url('i/rss');

    return '<a href="'. $rsspath .'"><img src="'. $rsspix .'" title="'. strip_tags($tooltiptext) .'" alt="'.get_string('rss').'" /></a>';

}

/**
 * This function returns the URL for the RSS XML file.
 *
 * @global object
 */
function rss_get_url($courseid, $userid, $modulename, $id) {
    global $CFG;
    require_once($CFG->libdir.'/filelib.php');
    return get_file_url($courseid.'/'.$userid.'/'.$modulename.'/'.$id.'/rss.xml', null, 'rssfile');
}

/**
 * This function prints the icon (from theme) with the link to rss/file.php
 */
function rss_print_link($courseid, $userid, $modulename, $id, $tooltiptext='') {
    print rss_get_link($courseid, $userid, $modulename, $id, $tooltiptext);

}

/**
 * This function iterates over each module in the server to see if
 * it supports generating rss feeds, searching for a MODULENAME_rss_feeds()
 * function and invoking it foreach activity as necessary
 *
 * @global object
 * @global object
 */
function cron_rss_feeds () {
    global $CFG, $DB;

    $status = true;

    mtrace('    Generating rssfeeds...');

    //Check for required functions...
    if(!function_exists('utf8_encode')) {
        mtrace('        ERROR: You need to add XML support to your PHP installation!');
        return true;
    }

    if ($allmods = $DB->get_records('modules') ) {
        foreach ($allmods as $mod) {
            mtrace('        '.$mod->name.': ', '');
            $modname = $mod->name;
            $modfile = "$CFG->dirroot/mod/$modname/rsslib.php";
            //If file exists and we have selected to restore that type of module
            if (file_exists($modfile)) {
                include_once($modfile);
                $generaterssfeeds = $modname.'_rss_feeds';
                if (function_exists($generaterssfeeds)) {
                    if ($status) {
                        mtrace('generating ', '');;
                        $status = $generaterssfeeds();
                        if (!empty($status)) {
                            mtrace('...OK');
                        } else {
                            mtrace('...FAILED');
                        }
                    } else {
                        mtrace('...SKIPPED (failed above)');
                    }
                } else {
                    mtrace('...NOT SUPPORTED (function)');
                }
            } else {
                mtrace('...NOT SUPPORTED (file)');
            }
        }
    }
    mtrace('    Ending  rssfeeds...', '');
    if (!empty($status)) {
        mtrace('...OK');
    } else {
        mtrace('...FAILED');
    }

    return $status;
}

/**
 * This function saves to file the rss feed specified in the parameters
 *
 * @global object
 */
function rss_save_file($modname, $mod, $result) {
    global $CFG;

    $status = true;

    if (! $basedir = make_upload_directory ('rss/'. $modname)) {
        //Cannot be created, so error
        $status = false;
    }

    if ($status) {
        $file = rss_file_name($modname, $mod);
        $rss_file = fopen($file, "w");
        if ($rss_file) {
            $status = fwrite ($rss_file, $result);
            fclose($rss_file);
        } else {
            $status = false;
        }
    }
    return $status;
}


function rss_file_name($modname, $mod) {
    global $CFG;

    return "$CFG->dataroot/rss/$modname/$mod->id.xml";
}

/**
 * This function return all the common headers for every rss feed in the site
 *
 * @global object
 * @global object
 */
function rss_standard_header($title = NULL, $link = NULL, $description = NULL) {
    global $CFG, $USER, $OUTPUT;

    $status = true;
    $result = "";

    if (!$site = get_site()) {
        $status = false;
    }

{'fraction_non_alphanumeric': 0.1449846272098386, 'fraction_numerical': 0.002113758647194466, 'mean_word_length': 2.156155245603396, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '711729', 'n_tokens_mistral': 3224, 'n_tokens_neox': 3136, 'n_words': 944}