MDL-32709 book: finish coding style review (errors only)
This commit is contained in:
@@ -73,7 +73,7 @@ function booktool_exportimscp_build_package($book, $context) {
|
||||
WHERE contextid = :contextid AND component = 'booktool_exportimscp' AND itemid < :revision";
|
||||
$params = array('contextid'=>$context->id, 'revision'=>$book->revision);
|
||||
$revisions = $DB->get_records_sql($sql, $params);
|
||||
foreach ($revisions as $rev=>$unused) {
|
||||
foreach ($revisions as $rev => $unused) {
|
||||
$fs->delete_area_files($context->id, 'booktool_exportimscp', 'temp', $rev);
|
||||
$fs->delete_area_files($context->id, 'booktool_exportimscp', 'package', $rev);
|
||||
}
|
||||
@@ -108,11 +108,13 @@ function booktool_exportimscp_prepare_files($book, $context) {
|
||||
$file->delete();
|
||||
}
|
||||
$content = booktool_exportimscp_chapter_content($chapter, $context);
|
||||
$index_file_record = array('contextid'=>$context->id, 'component'=>'booktool_exportimscp', 'filearea'=>'temp', 'itemid'=>$book->revision, 'filepath'=>"/$chapter->pagenum/", 'filename'=>'index.html');
|
||||
$index_file_record = array('contextid'=>$context->id, 'component'=>'booktool_exportimscp', 'filearea'=>'temp',
|
||||
'itemid'=>$book->revision, 'filepath'=>"/$chapter->pagenum/", 'filename'=>'index.html');
|
||||
$fs->create_file_from_string($index_file_record, $content);
|
||||
}
|
||||
|
||||
$css_file_record = array('contextid'=>$context->id, 'component'=>'booktool_exportimscp', 'filearea'=>'temp', 'itemid'=>$book->revision, 'filepath'=>"/css/", 'filename'=>'styles.css');
|
||||
$css_file_record = array('contextid'=>$context->id, 'component'=>'booktool_exportimscp', 'filearea'=>'temp',
|
||||
'itemid'=>$book->revision, 'filepath'=>"/css/", 'filename'=>'styles.css');
|
||||
$fs->create_file_from_pathname($css_file_record, dirname(__FILE__).'/imscp.css');
|
||||
|
||||
// Init imsmanifest and others
|
||||
@@ -137,6 +139,7 @@ function booktool_exportimscp_prepare_files($book, $context) {
|
||||
|
||||
// To store the prev level (book only have 0 and 1)
|
||||
$prevlevel = null;
|
||||
$currlevel = 0;
|
||||
foreach ($chapters as $chapter) {
|
||||
// Calculate current level ((book only have 0 and 1)
|
||||
$currlevel = empty($chapter->subchapter) ? 0 : 1;
|
||||
@@ -164,9 +167,10 @@ function booktool_exportimscp_prepare_files($book, $context) {
|
||||
|
||||
$chaptertitle = format_string($chapter->title, true, array('context'=>$context));
|
||||
|
||||
// Add the imsitems
|
||||
$imsitems .= $currspaces .' <item identifier="ITEM-' . $book->course . '-' . $book->id . '-' . $chapter->pagenum .'" isvisible="true" identifierref="RES-' . $book->course . '-' . $book->id . '-' . $chapter->pagenum . '">
|
||||
' . $currspaces . ' <title>' . htmlspecialchars($chaptertitle) . '</title>' . "\n";
|
||||
// Add the imsitems
|
||||
$imsitems .= $currspaces .' <item identifier="ITEM-' . $book->course . '-' . $book->id . '-' . $chapter->pagenum .'" isvisible="true" identifierref="RES-' .
|
||||
$book->course . '-' . $book->id . '-' . $chapter->pagenum . "\">\n" .
|
||||
$currspaces . ' <title>' . htmlspecialchars($chaptertitle) . '</title>' . "\n";
|
||||
|
||||
// Add the imsresources
|
||||
// First, check if we have localfiles
|
||||
@@ -177,9 +181,10 @@ function booktool_exportimscp_prepare_files($book, $context) {
|
||||
// Now add the dependency to css
|
||||
$cssdependency = "\n" . ' <dependency identifierref="RES-' . $book->course . '-' . $book->id . '-css" />';
|
||||
// Now build the resources section
|
||||
$imsresources .= ' <resource identifier="RES-' . $book->course . '-' . $book->id . '-' . $chapter->pagenum . '" type="webcontent" xml:base="' . $chapter->pagenum . '/" href="index.html">
|
||||
<file href="' . $chapter->pagenum . '/index.html" />' . implode($localfiles) . $cssdependency . '
|
||||
</resource>' . "\n";
|
||||
$imsresources .= ' <resource identifier="RES-' . $book->course . '-' . $book->id . '-' . $chapter->pagenum . '" type="webcontent" xml:base="' .
|
||||
$chapter->pagenum . '/" href="index.html">' . "\n" .
|
||||
' <file href="' . $chapter->pagenum . '/index.html" />' . implode($localfiles) . $cssdependency . "\n".
|
||||
' </resource>' . "\n";
|
||||
}
|
||||
|
||||
// Close items (the latest chapter)
|
||||
@@ -208,7 +213,8 @@ function booktool_exportimscp_prepare_files($book, $context) {
|
||||
// Close manifest
|
||||
$imsmanifest .= "\n</manifest>\n";
|
||||
|
||||
$manifest_file_record = array('contextid'=>$context->id, 'component'=>'booktool_exportimscp', 'filearea'=>'temp', 'itemid'=>$book->revision, 'filepath'=>"/", 'filename'=>'imsmanifest.xml');
|
||||
$manifest_file_record = array('contextid'=>$context->id, 'component'=>'booktool_exportimscp', 'filearea'=>'temp',
|
||||
'itemid'=>$book->revision, 'filepath'=>"/", 'filename'=>'imsmanifest.xml');
|
||||
$fs->create_file_from_string($manifest_file_record, $imsmanifest);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,14 +31,14 @@ defined('MOODLE_INTERNAL') || die;
|
||||
* @param navigation_node $node The node to add module settings to
|
||||
*/
|
||||
function booktool_importhtml_extend_settings_navigation(settings_navigation $settings, navigation_node $node) {
|
||||
global $USER, $PAGE, $CFG, $DB, $OUTPUT;
|
||||
global $USER, $PAGE, $CFG, $DB, $OUTPUT;
|
||||
|
||||
if ($PAGE->cm->modname !== 'book') {
|
||||
return;
|
||||
}
|
||||
if ($PAGE->cm->modname !== 'book') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (has_capability('booktool/importhtml:import', $PAGE->cm->context)) {
|
||||
$url = new moodle_url('/mod/book/tool/importhtml/index.php', array('id'=>$PAGE->cm->id));
|
||||
$node->add(get_string('import', 'booktool_importhtml'), $url, navigation_node::TYPE_SETTING, null, null, null);
|
||||
}
|
||||
if (has_capability('booktool/importhtml:import', $PAGE->cm->context)) {
|
||||
$url = new moodle_url('/mod/book/tool/importhtml/index.php', array('id'=>$PAGE->cm->id));
|
||||
$node->add(get_string('import', 'booktool_importhtml'), $url, navigation_node::TYPE_SETTING, null, null, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ function toolbook_importhtml_import_chapters($package, $type, $book, $context, $
|
||||
$matches = null;
|
||||
if (preg_match_all('/(src|codebase|name|href)\s*=\s*"([^"]+)"/i', $chapter->content, $matches)) {
|
||||
$file_record = array('contextid'=>$context->id, 'component'=>'mod_book', 'filearea'=>'chapter', 'itemid'=>$chapter->id);
|
||||
foreach ($matches[0] as $i=>$match) {
|
||||
foreach ($matches[0] as $i => $match) {
|
||||
$filepath = dirname($chapter->importsrc).'/'.$matches[2][$i];
|
||||
$filepath = toolbook_importhtml_fix_path($filepath);
|
||||
|
||||
@@ -128,7 +128,7 @@ function toolbook_importhtml_import_chapters($package, $type, $book, $context, $
|
||||
$newcontent = $chapter->content;
|
||||
$matches = null;
|
||||
if (preg_match_all('/(href)\s*=\s*"([^"]+)"/i', $chapter->content, $matches)) {
|
||||
foreach ($matches[0] as $i=>$match) {
|
||||
foreach ($matches[0] as $i => $match) {
|
||||
if (strpos($matches[2][$i], ':') !== false or strpos($matches[2][$i], '@') !== false) {
|
||||
// it is either absolute or pluginfile link
|
||||
continue;
|
||||
@@ -177,7 +177,7 @@ function toolbook_importhtml_parse_styles($html) {
|
||||
if (preg_match('/<head[^>]*>(.+)<\/head>/is', $html, $matches)) {
|
||||
$head = $matches[1];
|
||||
if (preg_match_all('/<link[^>]+rel="stylesheet"[^>]*>/i', $head, $matches)) { // Extract links to css.
|
||||
for($i=0; $i<count($matches[0]); $i++) {
|
||||
for ($i=0; $i<count($matches[0]); $i++) {
|
||||
$styles .= $matches[0][$i]."\n";
|
||||
}
|
||||
}
|
||||
@@ -196,7 +196,7 @@ function toolbook_importhtml_fix_path($path) {
|
||||
$path = '/'.ltrim($path, './'); // dirname() produces . for top level files + our paths start with /
|
||||
|
||||
$cnt = substr_count($path, '..');
|
||||
for($i=0; $i<$cnt; $i++) {
|
||||
for ($i=0; $i<$cnt; $i++) {
|
||||
$path = preg_replace('|[^/]+/\.\./|', '', $path, 1);
|
||||
}
|
||||
|
||||
@@ -309,7 +309,7 @@ function toolbook_importhtml_get_chapter_files($package, $type) {
|
||||
$chapterfiles = $tophtmlfiles;
|
||||
|
||||
} else if ($type == 1) {
|
||||
foreach ($topdirs as $dir=>$htmlfiles) {
|
||||
foreach ($topdirs as $dir => $htmlfiles) {
|
||||
if (empty($htmlfiles)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ if ($chapter) {
|
||||
<td><?php echo get_string('printedby', 'booktool_print') ?>:</td>
|
||||
<td><?php echo fullname($USER, true) ?></td>
|
||||
</tr><tr>
|
||||
<td><?php echo get_string('printdate','booktool_print') ?>:</td>
|
||||
<td><?php echo get_string('printdate', 'booktool_print') ?>:</td>
|
||||
<td><?php echo userdate(time()) ?></td>
|
||||
</tr>
|
||||
</table></div>
|
||||
|
||||
@@ -44,18 +44,18 @@ function booktool_print_get_toc($chapters, $book, $cm) {
|
||||
$toc = ''; // Representation of toc (HTML).
|
||||
|
||||
switch ($book->numbering) {
|
||||
case BOOK_NUM_NONE:
|
||||
$toc .= '<div class="book_toc_none">';
|
||||
break;
|
||||
case BOOK_NUM_NUMBERS:
|
||||
$toc .= '<div class="book_toc_numbered">';
|
||||
break;
|
||||
case BOOK_NUM_BULLETS:
|
||||
$toc .= '<div class="book_toc_bullets">';
|
||||
break;
|
||||
case BOOK_NUM_INDENTED:
|
||||
$toc .= '<div class="book_toc_indented">';
|
||||
break;
|
||||
case BOOK_NUM_NONE:
|
||||
$toc .= '<div class="book_toc_none">';
|
||||
break;
|
||||
case BOOK_NUM_NUMBERS:
|
||||
$toc .= '<div class="book_toc_numbered">';
|
||||
break;
|
||||
case BOOK_NUM_BULLETS:
|
||||
$toc .= '<div class="book_toc_bullets">';
|
||||
break;
|
||||
case BOOK_NUM_INDENTED:
|
||||
$toc .= '<div class="book_toc_indented">';
|
||||
break;
|
||||
}
|
||||
|
||||
$toc .= '<a name="toc"></a>'; // Representation of toc (HTML).
|
||||
@@ -66,7 +66,7 @@ function booktool_print_get_toc($chapters, $book, $cm) {
|
||||
$toc .= '<p class="book_chapter_title">'.get_string('toc', 'mod_book').'</p>';
|
||||
}
|
||||
$toc .= '<ul>';
|
||||
foreach($chapters as $ch) {
|
||||
foreach ($chapters as $ch) {
|
||||
if (!$ch->hidden) {
|
||||
$title = book_get_chapter_title($ch->id, $chapters, $book, $context);
|
||||
if (!$ch->subchapter) {
|
||||
|
||||
Reference in New Issue
Block a user