/** * handler for the plugins shortcode (e.g. [link2moodle cohort='abc123']my link text[/link2moodle]) * note: applies do_shortcode() to content to allow other plugins to be handled on links * when unauthenticated just returns the inner content (e.g. my link text) without a link */ function wp2moodle_handler($atts, $content = null) { // clone attribs over any default values, builds variables out of them so we can use them below // $class => css class to put on link we build // $cohort => text id of the moodle cohort in which to enrol this user // $group => text id of the moodle group in which to enrol this user // $authtext => string containing text content to display when not logged on (defaults to content between tags when empty / missing) extract(shortcode_atts(array("cohort" => '', "group" => '', "class" => 'wp2moodle', "target" => '_self', "authtext" => ''), $atts)); if ($content == null || !is_user_logged_in()) { if (trim($authtext) == "") { $url = do_shortcode($content); // return unlinked content (value between start and end tag) } else { $url = do_shortcode($authtext); // return authtext (value of attribute, if set) } } else { // url = moodle_url + "?data=" + <encrypted-value> $url = '<a target="' . esc_attr($target) . '" class="' . esc_attr($class) . '" href="' . wp2moodle_generate_hyperlink($cohort, $group) . '">' . do_shortcode($content) . '</a>'; // hyperlinked content } return $url; }
function wp2m_download_url($url, $order, $download) { if (strpos($url, 'wp2moodle.txt') !== false) { // mp url is full url = including http:// and so on... we want the file url $path = $_SERVER['DOCUMENT_ROOT'] . parse_url($url)["path"]; $cohort = ""; $group = ""; $data = file($path); // now it's an array! foreach ($data as $row) { $pair = explode("=", $row); switch (strtolower(trim($pair[0]))) { case "group": $group = trim(str_replace(array('\'', '"'), '', $pair[1])); break; case "cohort": $cohort = trim(str_replace(array('\'', '"'), '', $pair[1])); break; case "course": $cohort = trim(str_replace(array('\'', '"'), '', $pair[1])); break; } } $url = wp2moodle_generate_hyperlink($cohort, $group, $course); if (ob_get_contents()) { ob_clean(); } header('Location: ' . $url, true, 301); // redirect to this url exit; } return $url; }