示例#1
0
require_once '../tag/lib.php';
$action = optional_param('action', '', PARAM_ALPHA);
require_login();
if (empty($CFG->usetags)) {
    error('Tags are disabled!');
}
if (isguestuser()) {
    print_error('noguest');
}
if (!confirm_sesskey()) {
    print_error('sesskey');
}
switch ($action) {
    case 'addinterest':
        $id = optional_param('id', 0, PARAM_INT);
        $name = optional_param('name', '', PARAM_TEXT);
        if (empty($name) && $id) {
            $name = tag_name($id);
        }
        tag_an_item('user', $USER->id, $name);
        if (!empty($name) && !$id) {
            $id = tag_id(tag_normalize($name));
        }
        redirect($CFG->wwwroot . '/tag/index.php?id=' . $id);
        break;
    case 'flaginappropriate':
        $id = required_param('id', PARAM_INT);
        tag_flag_inappropriate($id);
        redirect($CFG->wwwroot . '/tag/index.php?id=' . $id, get_string('responsiblewillbenotified', 'tag'));
        break;
}
示例#2
0
/**
 * In a comma separated string of ids or names of tags, replaces all tag ids with their correspoding names
 *
 * Ex:
 *  Suppose the DB contains only the following entries in the tags table:
 *      id    name
 *      10    moodle
 *      12    science
 *      22    education
 *
 *  tag_name_from_string('mOOdle, 10, HiStOrY, 17, 22')
 *     will return the string 'mOOdle,moodle,HiStOrY,,education'
 *
 * This is a helper function used by functions of this API to process function arguments ($tag_name_or_id)
 *
 * @param string $tag_names_or_ids_csv comma separated names or ids of tags
 * @return int comma separated names of the tags
 */
function tag_name_from_string($tag_names_or_ids_csv)
{
    $tag_names_or_ids = explode(',', $tag_names_or_ids_csv);
    $tag_names = array();
    foreach ($tag_names_or_ids as $name_or_id) {
        if (is_numeric($name_or_id)) {
            $tag_names[] = tag_name($name_or_id);
        } elseif (is_string($name_or_id)) {
            $tag_names[] = trim($name_or_id);
        }
    }
    $tag_names_csv = implode(',', $tag_names);
    return $tag_names_csv;
}