function lightboxgallery_rss_feed($gallery) { global $CFG; $result = ""; $images = lightboxgallery_directory_images($CFG->dataroot . '/' . $gallery->course . '/' . $gallery->folder); $captions = array(); if ($cobjs = get_records_select('lightboxgallery_image_meta', "metatype = 'caption' AND gallery = {$gallery->id}")) { foreach ($cobjs as $cobj) { $captions[$cobj->image] = $cobj->description; } } if (!empty($images)) { $webroot = lightboxgallery_get_image_url($gallery->id); $dataroot = $CFG->dataroot . '/' . $gallery->course . '/' . $gallery->folder; $result .= "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"; $result .= "<rss version=\"2.0\" xmlns:media=\"http://search.yahoo.com/mrss\" xmlns:atom=\"http://www.w3.org/2005/Atom\">"; $result .= rss_start_tag('channel', 1, true); $result .= rss_full_tag('title', 2, false, strip_tags(format_string($gallery->name, true))); $result .= rss_full_tag('link', 2, false, $CFG->wwwroot . '/mod/lightboxgallery/view.php?l=' . $gallery->id); $result .= rss_full_tag('description', 2, false, format_string($gallery->description, true)); $result .= rss_start_tag('image', 2, true); $result .= rss_full_tag('url', 3, false, $CFG->pixpath . '/i/rsssitelogo.gif'); $result .= rss_full_tag('title', 3, false, 'moodle'); $result .= rss_full_tag('link', 3, false, $CFG->wwwroot); $result .= rss_full_tag('width', 3, false, '140'); $result .= rss_full_tag('height', 3, false, '35'); $result .= rss_end_tag('image', 2, true); $counter = 1; foreach ($images as $image) { $description = isset($captions[$image]) ? $captions[$image] : $image; $result .= rss_start_tag('item', 2, true); $result .= rss_full_tag('title', 3, false, strip_tags($image)); $result .= rss_full_tag('link', 3, false, $webroot . '/' . $image); $result .= rss_full_tag('guid', 3, false, 'img' . $counter); $result .= rss_full_tag('media:description', 3, false, $description); $result .= rss_full_tag('media:thumbnail', 3, false, '', array('url' => lightboxgallery_get_image_url($gallery->id, $image, true))); $result .= rss_full_tag('media:content', 3, false, '', array('url' => $webroot . '/' . $image, 'type' => mime_content_type($dataroot . '/' . $image))); $result .= rss_end_tag('item', 2, true); $counter++; } $result .= rss_standard_footer(); } return $result; }
/** * Return the while xml element, including content * * @param string $tag the xml tag name * @param int $level the indentation level * @param bool $endline whether or not to start new tags on a new line * @param string $content the text to go inside the tag * @param array $attributes the attributes of the xml tag * @return string the whole xml element */ function rss_full_tag($tag, $level = 0, $endline = true, $content, $attributes = null) { $st = rss_start_tag($tag, $level, $endline, $attributes); $co = ""; $co = preg_replace("/\r\n|\r/", "\n", htmlspecialchars($content)); $et = rss_end_tag($tag, 0, true); return $st . $co . $et; }
function lightboxgallery_rss_header($title = null, $link = null, $description = null) { global $CFG, $USER, $OUTPUT; $status = true; $result = ""; $site = get_site(); if ($status) { // Calculate title, link and description. if (empty($title)) { $title = format_string($site->fullname); } if (empty($link)) { $link = $CFG->wwwroot; } if (empty($description)) { $description = $site->summary; } // XML headers. $result .= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; $result .= "<rss version=\"2.0\" xmlns:media=\"http://search.yahoo.com/mrss\"" . "xmlns:atom=\"http://www.w3.org/2005/Atom\">\n"; // Open the channel. $result .= rss_start_tag('channel', 1, true); // Write channel info. $result .= rss_full_tag('title', 2, false, strip_tags($title)); $result .= rss_full_tag('link', 2, false, $link); $result .= rss_full_tag('description', 2, false, $description); $result .= rss_full_tag('generator', 2, false, 'Moodle'); if (!empty($USER->lang)) { $result .= rss_full_tag('language', 2, false, substr($USER->lang, 0, 2)); } $today = getdate(); $result .= rss_full_tag('copyright', 2, false, '© ' . $today['year'] . ' ' . format_string($site->fullname)); /* if (!empty($USER->email)) { $result .= rss_full_tag('managingEditor', 2, false, fullname($USER)); $result .= rss_full_tag('webMaster', 2, false, fullname($USER)); } */ // Write image info. $rsspix = $OUTPUT->pix_url('i/rsssitelogo'); // Write the info. $result .= rss_start_tag('image', 2, true); $result .= rss_full_tag('url', 3, false, $rsspix); $result .= rss_full_tag('title', 3, false, 'moodle'); $result .= rss_full_tag('link', 3, false, $CFG->wwwroot); $result .= rss_full_tag('width', 3, false, '140'); $result .= rss_full_tag('height', 3, false, '35'); $result .= rss_end_tag('image', 2, true); } if (!$status) { return false; } else { return $result; } }
/** * Builds the .pcast file with the users RSS token * @param object $pcast * @param string $url * @return string */ function pcast_build_pcast_file($pcast, $url) { //xml headers $result = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; $result .= "<!DOCTYPE pcast PUBLIC \"-//Apple Computer//DTD PCAST 1.0//EN\" \"http://www.itunes.com/DTDs/pcast-1.0.dtd\">\n"; $result .= rss_start_tag('pcast version="1.0"', 1, true); $result .= rss_start_tag('channel', 1, true); $result .= rss_start_tag('link rel="feed" type="application/rss+xml" href="' . $url . '" /', 2, true); $result .= rss_full_tag('title', 2, false, $pcast->name); $category = pcast_rss_category_lookup($pcast); if (isset($category->top->name) && !empty($category->top->name)) { $result .= rss_full_tag('category', 2, false, $category->top->name); } if (isset($category->nested->name) && !empty($category->nested->name)) { $result .= rss_full_tag('category', 2, false, $category->nested->name); } if (isset($pcast->subtitle) && !empty($category->subtitle)) { $result .= rss_full_tag('subtitle', 2, false, $pcast->subtitle); } $result .= rss_end_tag('channel', 1, true); $result .= rss_end_tag('pcast', 1, true); return $result; }