function block_exabis_eportfolio_print_attachments($id, $entry, $return = NULL, $align = "left") { // if return=html, then return a html string. // if return=text, then return a text-only string. // otherwise, print HTML for non-images, and return image HTML // if attachment is an image, $align set its aligment. global $CFG; $newentry = $entry; $filearea = block_exabis_eportfolio_file_area_name($newentry); $imagereturn = ""; $output = ""; if ($basedir = block_exabis_eportfolio_file_area($newentry)) { if ($files = get_directory_list($basedir)) { $strattachment = get_string("attachment", "block_exabis_eportfolio"); $strpopupwindow = get_string("popupwindow"); foreach ($files as $file) { $icon = mimeinfo("icon", $file); if ($CFG->slasharguments) { $ffurl = "file.php/{$filearea}/{$file}"; } else { $ffurl = "file.php?file=/{$filearea}/{$file}"; } $image = "<img border=0 src=\"{$CFG->wwwroot}/files/pix/{$icon}\" height=16 width=16 alt=\"{$strpopupwindow}\">"; if ($return == "html") { $output .= "<a target=_image href=\"{$CFG->wwwroot}/{$ffurl}\">{$image}</a> "; $output .= "<a target=_image href=\"{$CFG->wwwroot}/{$ffurl}\">{$file}</a><br />"; } else { if ($return == "text") { $output .= "{$strattachment} {$file}:\n{$CFG->wwwroot}/{$ffurl}\n"; } else { if ($icon == "image.gif") { // Image attachments don't get printed as links $imagereturn .= "<br /><img src=\"{$CFG->wwwroot}/{$ffurl}\" align={$align}>"; } else { link_to_popup_window("/{$ffurl}", "attachment", $image, 500, 500, $strattachment); echo "<a target=_image href=\"{$CFG->wwwroot}/{$ffurl}\">{$file}</a>"; echo "<br />"; } } } } } } if ($return) { return $output; } return $imagereturn; }
function get_category_content(&$xmlElement, &$resources, $id, $name, $exportpath, $export_dir, $identifier, &$ridentifier, $viewid) { global $USER, $CFG, $COURSE; $bookmarks = get_category_items($id, $viewid, 'link'); $hasItems = false; if ($bookmarks) { $hasItems = true; foreach ($bookmarks as $bookmark) { unset($filecontent); unset($filename); $filecontent = ''; $filecontent .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . "\n"; $filecontent .= '<html xmlns="http://www.w3.org/1999/xhtml">' . "\n"; $filecontent .= '<head>' . "\n"; $filecontent .= ' <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />' . "\n"; $filecontent .= ' <title>' . spch(format_string($bookmark->name)) . '</title>' . "\n"; $filecontent .= '<!-- ' . get_string("exportcomment", "block_exabis_eportfolio") . ' -->'; $filecontent .= '</head>' . "\n"; $filecontent .= '<body>' . "\n"; $filecontent .= ' <h1 id="header">' . spch(format_string($bookmark->name)) . '</h1>' . "\n"; $filecontent .= ' <div id="url"><a href="' . spch($bookmark->url) . '"><!--###BOOKMARK_EXT_URL###-->' . spch($bookmark->url) . '<!--###BOOKMARK_EXT_URL###--></a></div>' . "\n"; $filecontent .= ' <div id="description"><!--###BOOKMARK_EXT_DESC###-->' . spch_text($bookmark->intro) . '<!--###BOOKMARK_EXT_DESC###--></div>' . "\n"; $filecontent .= add_comments('block_exabeporitemcomm', $bookmark->id); $filecontent .= '</body>' . "\n"; $filecontent .= '</html>' . "\n"; $filename = clean_param($bookmark->name, PARAM_ALPHANUM); $ext = ".html"; $i = 0; if ($filename == "") { $filepath = $export_dir . $filename . $i . $ext; } else { $filepath = $export_dir . $filename . $ext; } if (is_file($exportpath . $filepath) || is_dir($exportpath . $filepath) || is_link($exportpath . $filepath)) { do { $i++; $filepath = $export_dir . $filename . $i . $ext; } while (is_file($exportpath . $filepath) || is_dir($exportpath . $filepath) || is_link($exportpath . $filepath)); } file_put_contents($exportpath . $filepath, $filecontent); create_ressource($resources, 'RES-' . $ridentifier, $filepath); create_item($xmlElement, 'ITEM-' . $identifier, $bookmark->name, 'RES-' . $ridentifier); $identifier++; $ridentifier++; } } $files = get_category_items($id, $viewid, 'file'); if ($files) { $hasItems = true; foreach ($files as $file) { unset($filecontent); unset($filename); $i = 0; $content_filename = $file->attachment; if (is_file($exportpath . $export_dir . $content_filename) || is_dir($exportpath . $export_dir . $content_filename) || is_link($exportpath . $export_dir . $content_filename)) { do { $i++; $content_filename = $i . $file->attachment; } while (is_file($exportpath . $export_dir . $content_filename) || is_dir($exportpath . $export_dir . $content_filename) || is_link($exportpath . $export_dir . $content_filename)); } if ($file->attachment != '') { copy($CFG->dataroot . "/" . block_exabis_eportfolio_file_area_name($file) . "/" . $file->attachment, $exportpath . $export_dir . $content_filename); } $filecontent = ''; $filecontent .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . "\n"; $filecontent .= '<html xmlns="http://www.w3.org/1999/xhtml">' . "\n"; $filecontent .= '<head>' . "\n"; $filecontent .= ' <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />' . "\n"; $filecontent .= ' <title>' . spch($file->name) . '</title>' . "\n"; $filecontent .= '<!-- ' . get_string("exportcomment", "block_exabis_eportfolio") . ' -->'; $filecontent .= '</head>' . "\n"; $filecontent .= '<body>' . "\n"; $filecontent .= ' <h1 id="header">' . spch($file->name) . '</h1>' . "\n"; $filecontent .= ' <div id="url"><a href="' . spch($content_filename) . '"><!--###BOOKMARK_FILE_URL###-->' . spch($content_filename) . '<!--###BOOKMARK_FILE_URL###--></a></div>' . "\n"; $filecontent .= ' <div id="description"><!--###BOOKMARK_FILE_DESC###-->' . spch_text($file->intro) . '<!--###BOOKMARK_FILE_DESC###--></div>' . "\n"; $filecontent .= add_comments('block_exabeporitemcomm', $file->id); $filecontent .= '</body>' . "\n"; $filecontent .= '</html>' . "\n"; $filename = clean_param($file->name, PARAM_ALPHANUM); $ext = ".html"; $i = 0; if ($filename == "") { $filepath = $export_dir . $filename . $i . $ext; } else { $filepath = $export_dir . $filename . $ext; } if (is_file($exportpath . $filepath) || is_dir($exportpath . $filepath) || is_link($exportpath . $filepath)) { do { $i++; $filepath = $export_dir . $filename . $i . $ext; } while (is_file($exportpath . $filepath) || is_dir($exportpath . $filepath) || is_link($exportpath . $filepath)); } file_put_contents($exportpath . $filepath, $filecontent); create_ressource($resources, 'RES-' . $ridentifier, $filepath); create_item($xmlElement, 'ITEM-' . $identifier, $file->name, 'RES-' . $ridentifier); $identifier++; $ridentifier++; } } $notes = get_category_items($id, $viewid, 'note'); if ($notes) { $hasItems = true; foreach ($notes as $note) { unset($filecontent); unset($filename); $filecontent = ''; $filecontent .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . "\n"; $filecontent .= '<html xmlns="http://www.w3.org/1999/xhtml">' . "\n"; $filecontent .= '<head>' . "\n"; $filecontent .= ' <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />' . "\n"; $filecontent .= ' <title>' . spch($note->name) . '</title>' . "\n"; $filecontent .= '<!-- ' . get_string("exportcomment", "block_exabis_eportfolio") . ' -->'; $filecontent .= '</head>' . "\n"; $filecontent .= '<body>' . "\n"; $filecontent .= ' <h1 id="header">' . spch($note->name) . '</h1>' . "\n"; $filecontent .= ' <div id="description"><!--###BOOKMARK_NOTE_DESC###-->' . spch_text($note->intro) . '<!--###BOOKMARK_NOTE_DESC###--></div>' . "\n"; $filecontent .= add_comments('block_exabeporitemcomm', $note->id); $filecontent .= '</body>' . "\n"; $filecontent .= '</html>' . "\n"; $filename = clean_param($note->name, PARAM_ALPHANUM); $ext = ".html"; $i = 0; if ($filename == "") { $filepath = $export_dir . $filename . $i . $ext; } else { $filepath = $export_dir . $filename . $ext; } if (is_file($exportpath . $filepath) || is_dir($exportpath . $filepath) || is_link($exportpath . $filepath)) { do { $i++; $filepath = $export_dir . $filename . $i . $ext; } while (is_file($exportpath . $filepath) || is_dir($exportpath . $filepath) || is_link($exportpath . $filepath)); } file_put_contents($exportpath . $filepath, $filecontent); create_ressource($resources, 'RES-' . $ridentifier, $filepath); create_item($xmlElement, 'ITEM-' . $identifier, $note->name, 'RES-' . $ridentifier); $identifier++; $ridentifier++; } } return $hasItems; }
function insert_entry($unzip_dir, $url, $title, $category, $course) { global $USER, $CFG, $COURSE; $filePath = $unzip_dir . '/' . $url; $content = file_get_contents($filePath); if (($startUrl = strpos($content, '<!--###BOOKMARK_EXT_URL###-->')) !== false && ($startDesc = strpos($content, '<!--###BOOKMARK_EXT_DESC###-->')) !== false) { $startUrl += strlen('<!--###BOOKMARK_EXT_URL###-->'); $startDesc += strlen('<!--###BOOKMARK_EXT_DESC###-->'); if (($endUrl = strpos($content, '<!--###BOOKMARK_EXT_URL###-->', $startUrl)) !== false && ($endDesc = strpos($content, '<!--###BOOKMARK_EXT_DESC###-->', $startDesc)) !== false) { $new = new stdClass(); $new->userid = $USER->id; $new->categoryid = $category; $new->name = block_exabis_eportfolio_clean_title($title); $new->url = block_exabis_eportfolio_clean_url(substr($content, $startUrl, $endUrl - $startUrl)); $new->intro = block_exabis_eportfolio_clean_text(substr($content, $startDesc, $endDesc - $startDesc)); $new->timemodified = time(); $new->type = 'link'; $new->course = $COURSE->id; if ($new->id = insert_record('block_exabeporitem', $new)) { get_comments($content, $new->id, 'block_exabeporitemcomm'); } else { notify(get_string("couldntinsert", "block_exabis_eportfolio", $title)); } } else { notify(get_string("filetypenotdetected", "block_exabis_eportfolio", array("filename" => $url, "title" => $title))); } } else { if (($startUrl = strpos($content, '<!--###BOOKMARK_FILE_URL###-->')) !== false && ($startDesc = strpos($content, '<!--###BOOKMARK_FILE_DESC###-->')) !== false) { $startUrl += strlen('<!--###BOOKMARK_FILE_URL###-->'); $startDesc += strlen('<!--###BOOKMARK_FILE_DESC###-->'); if (($endUrl = strpos($content, '<!--###BOOKMARK_FILE_URL###-->', $startUrl)) !== false && ($endDesc = strpos($content, '<!--###BOOKMARK_FILE_DESC###-->', $startDesc)) !== false) { $linkedFileName = block_exabis_eportfolio_clean_path(substr($content, $startUrl, $endUrl - $startUrl)); $linkedFilePath = dirname($filePath) . '/' . $linkedFileName; if (is_file($linkedFilePath)) { $new = new stdClass(); $new->userid = $USER->id; $new->categoryid = $category; $new->name = block_exabis_eportfolio_clean_title($title); $new->intro = block_exabis_eportfolio_clean_text(substr($content, $startDesc, $endDesc - $startDesc)); $new->timemodified = time(); $new->type = 'file'; $new->course = $COURSE->id; // not necessary //$new->url = str_replace($CFG->wwwroot, "", $_SERVER["HTTP_REFERER"]); if ($new->id = insert_record('block_exabeporitem', $new)) { $destination = block_exabis_eportfolio_file_area_name($new); if (make_upload_directory($destination, false)) { $destination = $CFG->dataroot . '/' . $destination; $destination_name = handle_filename_collision($destination, $linkedFileName); if (copy($linkedFilePath, $destination . '/' . $destination_name)) { set_field("block_exabeporitem", "attachment", $destination_name, "id", $new->id); } else { notify(get_string("couldntcopyfile", "block_exabis_eportfolio", $title)); } } else { notify(get_string("couldntcreatedirectory", "block_exabis_eportfolio", $title)); } get_comments($content, $new->id, 'block_exabeporitemcomm'); } else { notify(get_string("couldntinsert", "block_exabis_eportfolio", $title)); } } else { notify(get_string("linkedfilenotfound", "block_exabis_eportfolio", array("filename" => $linkedFileName, "url" => $url, "title" => $title))); } } else { notify(get_string("filetypenotdetected", "block_exabis_eportfolio", array("filename" => $url, "title" => $title))); } } else { if (($startDesc = strpos($content, '<!--###BOOKMARK_NOTE_DESC###-->')) !== false) { $startDesc += strlen('<!--###BOOKMARK_NOTE_DESC###-->'); if (($endDesc = strpos($content, '<!--###BOOKMARK_NOTE_DESC###-->', $startDesc)) !== false) { $new = new stdClass(); $new->userid = $USER->id; $new->categoryid = $category; $new->name = block_exabis_eportfolio_clean_title($title); $new->intro = block_exabis_eportfolio_clean_text(substr($content, $startDesc, $endDesc - $startDesc)); $new->timemodified = time(); $new->type = 'note'; $new->course = $COURSE->id; if ($new->id = insert_record('block_exabeporitem', $new)) { get_comments($content, $new->id, 'block_exabeporitemcomm'); } else { notify(get_string("couldntinsert", "block_exabis_eportfolio", $title)); } } else { notify(get_string("filetypenotdetected", "block_exabis_eportfolio", array("filename" => $url, "title" => $title))); } } else { notify(get_string("filetypenotdetected", "block_exabis_eportfolio", array("filename" => $url, "title" => $title))); } } } }
} else { $lifetime = $CFG->filelifetime; } // disable moodle specific debug messages disable_debugging(); $relativepath = get_file_argument('portfoliofile.php'); // the check of the parameter to PARAM_PATH is executed inside get_file_argument $access = optional_param('access', 0, PARAM_TEXT); $itemid = optional_param('itemid', 0, PARAM_INT); require_login(); if ($access && $itemid) { $item = block_exabis_eportfolio_get_item($itemid, $access); if (!$item || $item->type != 'file' || !$item->attachment) { error('No valid arguments supplied'); } $filepath = $CFG->dataroot . '/' . block_exabis_eportfolio_file_area_name($item) . '/' . $item->attachment; } else { if (!$relativepath) { error('No valid arguments supplied or incorrect server configuration'); } else { if ($relativepath[0] != '/') { error('No valid arguments supplied, path does not start with slash!'); } } // relative path must start with '/', because of backup/restore!!! // extract relative path components $args = explode('/', trim($relativepath, '/')); if ($args[0] != 'exabis_eportfolio') { error('No valid arguments supplied'); } if ($args[1] == 'temp') {
/** * Write a new item into database */ function block_exabis_eportfolio_do_add($post, $blogeditform, $returnurl, $courseid) { global $CFG, $USER; $post->userid = $USER->id; $post->timemodified = time(); $post->courseid = $courseid; // Insert the new blog entry. if ($post->id = insert_record('block_exabeporitem', $post)) { if ($post->type == 'file') { $dir = block_exabis_eportfolio_file_area_name($post); if ($blogeditform->save_files($dir) && ($newfilename = $blogeditform->get_new_filename())) { set_field("block_exabeporitem", "attachment", $newfilename, "id", $post->id); } } add_to_log(SITEID, 'bookmark', 'add', 'item.php?courseid=' . $courseid . '&id=' . $post->id . '&action=add', $post->name); } else { print_error('addposterror', 'block_exabis_eportfolio', $returnurl); } }
/** * Write a new blog entry into database */ function do_add($post, $blogeditform, $returnurl, $courseid, $checked_file) { global $CFG, $USER; $post->userid = $USER->id; $post->timemodified = time(); $post->course = $courseid; $post->type = 'file'; // Insert the new blog entry. if ($post->id = insert_record('block_exabeporitem', $post)) { add_to_log(SITEID, 'bookmark', 'add', 'add_file.php?courseid=' . $courseid . '&id=' . $post->id . '&action=add', $post->name); $dir = block_exabis_eportfolio_file_area_name($post); if (is_file($CFG->dataroot . '/' . $checked_file->fullpath)) { if (make_upload_directory($dir) != false) { if (!copy($CFG->dataroot . '/' . $checked_file->fullpath, $CFG->dataroot . '/' . $dir . '/' . $checked_file->filename)) { error("Copy failed!"); } set_field("block_exabeporitem", "attachment", $checked_file->filename, "id", $post->id); } else { print_error("couldntcreatedirectory", "block_exabis_eportfolio"); } } else { print_error("filenotfound", "block_exabis_eportfolio"); } } else { print_error('addposterror', 'block_exabis_eportfolio', $returnurl); } }
function block_exabis_eportfolio_get_epx_category_content(&$xmlElement, &$resources, $id, $exportpath, $export_dir, &$ridentifier, $viewid) { global $USER, $CFG, $COURSE; $bookmarks = get_category_items($id, $viewid, 'link'); if ($bookmarks) { foreach ($bookmarks as $bookmark) { unset($thisitem); unset($thisitemtitle); unset($thisitemdescription); unset($thisitemurl); unset($itemref); $itemidentifier = $ridentifier; $ridentifier++; $thisitem =& $resources->createChild('epx:item'); $thisitem->attribute('id', 'link' . $itemidentifier); $thisitem->attribute('created', date("c", $bookmark->timemodified)); $thisitem->attribute('lastedited', date("c", $bookmark->timemodified)); $thisitem->attribute('editable', 'true'); $thisitem->attribute('visible', 'true'); $thisitem->attribute('xsi:type', 'epx:linkType'); $thisitem->attribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); block_exabis_eportfolio_get_comments_for_item($thisitem, 'block_exabeporitemcomm', $bookmark->id, $ridentifier); $thisitemtitle =& $thisitem->createChild('epx:title'); $thisitemtitle->cdata(spch($bookmark->name)); $thisitemdescription =& $thisitem->createChild('epx:description'); $thisitemdescription->cdata(spch($bookmark->intro)); $thisitemurl =& $thisitem->createChild('epx:url'); $thisitemurl->cdata(spch($bookmark->url)); $itemref =& $xmlElement->createChild('epx:itemref'); $itemref->attribute('id', 'link' . $itemidentifier); } } $files = get_category_items($id, $viewid, 'file'); if ($files) { foreach ($files as $file) { unset($thisitem); unset($thisitemtitle); unset($thisitemdescription); unset($thisitemuri); unset($itemref); $itemidentifier = $ridentifier; $ridentifier++; $i = 0; $content_filename = $file->attachment; if (is_file($exportpath . $export_dir . $content_filename) || is_dir($exportpath . $export_dir . $content_filename) || is_link($exportpath . $export_dir . $content_filename)) { do { $i++; $content_filename = $i . $file->attachment; } while (is_file($exportpath . $export_dir . $content_filename) || is_dir($exportpath . $export_dir . $content_filename) || is_link($exportpath . $export_dir . $content_filename)); } if ($file->attachment != '') { copy($CFG->dataroot . "/" . block_exabis_eportfolio_file_area_name($file) . "/" . $file->attachment, $exportpath . $export_dir . $content_filename); } $thisitem =& $resources->createChild('epx:item'); $thisitem->attribute('id', 'file' . $itemidentifier); $thisitem->attribute('created', date("c", $file->timemodified)); $thisitem->attribute('lastedited', date("c", $file->timemodified)); $thisitem->attribute('editable', 'true'); $thisitem->attribute('visible', 'true'); $thisitem->attribute('xsi:type', 'epx:fileType'); $thisitem->attribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); block_exabis_eportfolio_get_comments_for_item($thisitem, 'block_exabeporitemcomm', $file->id, $ridentifier); $thisitemtitle =& $thisitem->createChild('epx:title'); $thisitemtitle->cdata(spch($file->name)); $thisitemdescription =& $thisitem->createChild('epx:text'); $thisitemdescription->cdata(spch($file->intro)); $thisitemuri =& $thisitem->createChild('epx:uri'); $thisitemuri->cdata(spch('epx:' . $export_dir . $content_filename)); $itemref =& $xmlElement->createChild('epx:itemref'); $itemref->attribute('id', 'file' . $itemidentifier); } } $notes = get_category_items($id, $viewid, 'note'); if ($notes) { foreach ($notes as $note) { unset($thisitem); unset($thisitemtitle); unset($thisitemdescription); unset($itemref); $itemidentifier = $ridentifier; $ridentifier++; $thisitem =& $resources->createChild('epx:item'); $thisitem->attribute('id', 'note' . $itemidentifier); $thisitem->attribute('created', date("c", $note->timemodified)); $thisitem->attribute('lastedited', date("c", $note->timemodified)); $thisitem->attribute('editable', 'true'); $thisitem->attribute('visible', 'true'); $thisitem->attribute('xsi:type', 'epx:noteType'); $thisitem->attribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); block_exabis_eportfolio_get_comments_for_item($thisitem, 'block_exabeporitemcomm', $note->id, $ridentifier); $thisitemtitle =& $thisitem->createChild('epx:title'); $thisitemtitle->cdata(spch($note->name)); $thisitemdescription =& $thisitem->createChild('epx:text'); $thisitemdescription->cdata(spch($note->intro)); $itemref =& $xmlElement->createChild('epx:itemref'); $itemref->attribute('id', 'note' . $itemidentifier); } } return true; }