From a28f677a5d93ec54073eb7e90d858ca8f53845c4 Mon Sep 17 00:00:00 2001 From: Steffen Pegenau Date: Tue, 5 Apr 2016 11:55:04 +0200 Subject: [PATCH 01/30] Adds a simple table of contents to each wiki page --- lang/en/ouwiki.php | 2 + renderer.php | 9 +++ tableofcontents.php | 161 ++++++++++++++++++++++++++++++++++++++++++++ version.php | 2 +- 4 files changed, 173 insertions(+), 1 deletion(-) create mode 100644 tableofcontents.php diff --git a/lang/en/ouwiki.php b/lang/en/ouwiki.php index 6a0f4cb..13bc0c2 100644 --- a/lang/en/ouwiki.php +++ b/lang/en/ouwiki.php @@ -588,3 +588,5 @@ $string['event:ouwikipageupdated'] = 'ouwiki page updated'; $string['event:savefailed'] = 'Session fail on page save'; $string['ouwikicrontask'] = 'OU wiki maintenance jobs'; + +$string['tableofcontents'] = 'Table of contents'; diff --git a/renderer.php b/renderer.php index f1b95a6..f91b53a 100644 --- a/renderer.php +++ b/renderer.php @@ -206,8 +206,17 @@ public function get_topheading_section($title, $gewgaws, $pageversion, $annotati $cm = $this->params->cm; $output = html_writer::start_tag('div', array('class' => 'ouw_topheading')); $output .= html_writer::start_tag('div', array('class' => 'ouw_heading')); + $output .= html_writer::tag('h2', format_string($title), array('class' => 'ouw_topheading')); + + // Add table of contents + global $CFG; + require_once($CFG->dirroot.'/mod/ouwiki/tableofcontents.php'); + $toc = new TableOfContents($pageversion->xhtml); + $output .= $toc->toHtml(); + + if ($gewgaws) { $output .= $this->render_heading_bit(1, $pageversion->title, $subwiki, $cm, null, $annotations, $pageversion->locked, $files, diff --git a/tableofcontents.php b/tableofcontents.php new file mode 100644 index 0000000..3bb306e --- /dev/null +++ b/tableofcontents.php @@ -0,0 +1,161 @@ +. + +/** + * Version. + * + * @package mod_ouwiki + * @copyright 2016 The Open University + * @author Steffen Pegenau + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +class TableOfContents { + // The table of contents is saved in a 6xn-Array + // 6:

-

+ // n: the number of headings + private $ToC = array(array(array(array(array(array()))))); + private $html = ""; + + private $lastH1 = 0; + private $lastH2 = 0; + private $lastH3 = 0; + private $lastH4 = 0; + private $lastH5 = 0; + private $lastH6 = 0; + private $lastLvl = 0; + + public function __construct($html) { + $this->html = $html; + $this->parseHtml($html); + } + + /* + * returns the table of contents as printable html + */ + public function toHtml() { + $toc = $this->ToC; + $output = "

" . get_string('tableofcontents', 'ouwiki') . "

"; + $output .= ""; + + return $output; + } + + /* + * Parses the html-Code and generates the table of contents + * + * @param String $html The html-snippet to parse + */ + private function parseHtml($html) { + $reader = new XMLReader(); + $reader->xml($html); + + $headings = []; + $output = ""; + + $lastlevel = 0; + + // traverse the tree + while($reader->read() !== false) { + $tag = $reader->name; + $content = $reader->readString(); + $matches = null; + + // is it a h1-h6 heading? + preg_match('/[hH][1-6]/', $tag, $matches); + if(!empty($content) && count($matches) > 0) { + // example: h1 -> 1 + $lvl = substr($tag, 1); + //

=> ouw_s0_0 + $id = $reader->getAttribute("id"); + $this->addToTree($lvl, $content, $id); + } + } + } + + /** + * Adds an entry with name and level to the table of contents + * + * param int $lvl The level of the heading + * param string $name The title of the heading + * param string $id html attribute id of heading + */ + private function addToTree($lvl, $name, $id) { + if($lvl < $this->lastLvl) { + $lvlToDelete = $lvl + 1; + switch($lvlToDelete) { + case 1: + $this->lastH1 = 0; + case 2: + $this->lastH2 = 0; + case 3: + $this->lastH3 = 0; + case 4: + $this->lastH4 = 0; + case 5: + $this->lastH5 = 0; + case 6: + $this->lastH6 = 0; + break; + } + } + + switch ($lvl) { + case 1: + ++$this->lastH1; + break; + case 2: + ++$this->lastH2; + break; + case 3: + ++$this->lastH3; + break; + case 4: + ++$this->lastH4; + break; + case 5: + ++$this->lastH5; + break; + case 6: + ++$this->lastH6; + break; + } + $element = new stdClass(); + $element->name = $name; + $element->id = $id; + + // Save element in array + $this->ToC[$this->lastH1][$this->lastH2][$this->lastH3][$this->lastH4][$this->lastH5][$this->lastH6] = $element; + + $this->lastLvl = $lvl; + } +} diff --git a/version.php b/version.php index fe0bd84..6cc9db6 100644 --- a/version.php +++ b/version.php @@ -22,7 +22,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -$plugin->version = 2015101501; +$plugin->version = 2016040500; $plugin->requires = 2014051200; $plugin->component = 'mod_ouwiki'; $plugin->maturity = MATURITY_STABLE; From 633bb3eb784eaf83cea0af6fe4e7b109ebc045a5 Mon Sep 17 00:00:00 2001 From: Steffen Pegenau Date: Wed, 20 Apr 2016 12:22:37 +0200 Subject: [PATCH 02/30] Added chapter number to each heading --- tableofcontents.php | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/tableofcontents.php b/tableofcontents.php index 3bb306e..bf46a41 100644 --- a/tableofcontents.php +++ b/tableofcontents.php @@ -57,7 +57,8 @@ public function toHtml() { foreach($h5tree as $h5 => $h6tree) { foreach($h6tree as $h6 => $obj) { if($obj) { - $output .= '
  • '.$obj->name .'
  • '; + $h = array($h1, $h2, $h3, $h4, $h5, $h6); + $output .= '
  • '.$this->getChapterNumber($h)." ".$obj->name .'
  • '; } } } @@ -70,6 +71,30 @@ public function toHtml() { return $output; } + private function getChapterNumber($h) { + $number = ""; + + // Generate full number with unnecessary zeros and dots + // Example: 1.2.0.0.0.0 + for($i = 0; $i <= 6; $i++) { + $number .= $h[$i] . '.'; + } + + $str = ""; + $bool = true; + + // Deletes unnecessary dots and zeros from the right side + // Example: 1.2.0.0.0.0 becomes 1.2 + while($bool) { + $str = rtrim($number, '.'); + $str = rtrim($str, '0'); + $bool = ($str !== $number) ? true : false; + $number = $str; + } + + return rtrim($number, '.'); + } + /* * Parses the html-Code and generates the table of contents * From 1fb22dd6b0d55a9ca2ab2c8b431c12e0ff312827 Mon Sep 17 00:00:00 2001 From: Steffen Pegenau Date: Wed, 20 Apr 2016 12:27:15 +0200 Subject: [PATCH 03/30] Added comments --- tableofcontents.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tableofcontents.php b/tableofcontents.php index bf46a41..78aef68 100644 --- a/tableofcontents.php +++ b/tableofcontents.php @@ -71,6 +71,11 @@ public function toHtml() { return $output; } + /** + * Generates the chapter number for a heading, for example "1.0.2" + * @param array $h An array of alle heading numbers + * @return string The chapter number + */ private function getChapterNumber($h) { $number = ""; From dde286353289569376ae59ecf80a189bc76e51eb Mon Sep 17 00:00:00 2001 From: Steffen Pegenau Date: Mon, 2 May 2016 13:22:03 +0200 Subject: [PATCH 04/30] Added a table of contents with chapter numbers and nested
      -elements --- tableofcontents.php | 72 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 66 insertions(+), 6 deletions(-) diff --git a/tableofcontents.php b/tableofcontents.php index 78aef68..d49df50 100644 --- a/tableofcontents.php +++ b/tableofcontents.php @@ -28,6 +28,8 @@ class TableOfContents { // 6:

      -

      // n: the number of headings private $ToC = array(array(array(array(array(array()))))); + private $reducedToC = null; + private $html = ""; private $lastH1 = 0; @@ -36,11 +38,15 @@ class TableOfContents { private $lastH4 = 0; private $lastH5 = 0; private $lastH6 = 0; + private $lastLvl = 0; + private $minLvl = 0; public function __construct($html) { $this->html = $html; $this->parseHtml($html); + + $this->setMinLvl(); } /* @@ -48,8 +54,11 @@ public function __construct($html) { */ public function toHtml() { $toc = $this->ToC; - $output = "

      " . get_string('tableofcontents', 'ouwiki') . "

      "; - $output .= "
        "; + $output = "

        " . get_string('tableofcontents', 'ouwiki') . "

        "; + + // Helps building the nested
          -elements + $lastlvl = 0; + foreach($toc as $h1 => $h2tree) { foreach($h2tree as $h2 => $h3tree) { foreach($h3tree as $h3 => $h4tree) { @@ -57,8 +66,33 @@ public function toHtml() { foreach($h5tree as $h5 => $h6tree) { foreach($h6tree as $h6 => $obj) { if($obj) { + // Get the chapter number, for example 1.2.3 $h = array($h1, $h2, $h3, $h4, $h5, $h6); - $output .= '
        • '.$this->getChapterNumber($h)." ".$obj->name .'
        • '; + $chapterNumber = $this->getChapterNumber($h); + + // Get the level, for this example 3 + $currentLvl = $this->getLvlByChapterNumber($chapterNumber); + + // The elements heading + $element = '
        • '.$chapterNumber." ".$obj->name .'
        • '; + + // New nested
            + if($currentLvl > $lastlvl) { + $output .= str_repeat("
              ", $currentLvl - $lastlvl); + $output .= $element; + } + // Close as many
                as necessary + elseif ($currentLvl < $lastlvl) { + $output .= str_repeat("
              ", $lastlvl - $currentLvl); + $output .= $element; + } + // Same level, just add
            • + else { + $output .= $element; + } + + // Set helper + $lastlvl = $currentLvl; } } } @@ -66,11 +100,35 @@ public function toHtml() { } } } - $output .= "
            "; - return $output; } + /** + * Returns the headings level by the chapter number + * + * For example: 1.2.3 => 3 + * 1.3 => 2 + * @param String $n The chapter number + * @return Number The headings lvel + */ + private function getLvlByChapterNumber($n) { + $e = explode('.', $n); + return count($e); + } + + /** + * Sets the minimum level of headings + * + * If there are only

            and

            headings the minlvl is 2 + */ + private function setMinLvl() { + $reducedToC = $this->ToC; + while(!isset($reducedToC[1])) { + $reducedToC = $reducedToC[0]; + $this->minLvl++; + } + } + /** * Generates the chapter number for a heading, for example "1.0.2" * @param array $h An array of alle heading numbers @@ -97,7 +155,9 @@ private function getChapterNumber($h) { $number = $str; } - return rtrim($number, '.'); + $str = rtrim($number, '.'); + + return substr($str, 2*$this->minLvl); } /* From 744bb468b03dbdccb56775487d3903106230bbff Mon Sep 17 00:00:00 2001 From: Steffen Pegenau Date: Tue, 3 May 2016 15:15:12 +0200 Subject: [PATCH 05/30] Rewrote parser to be more robust in case of broken HTML-Code --- tableofcontents.php | 50 ++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/tableofcontents.php b/tableofcontents.php index d49df50..3fd7732 100644 --- a/tableofcontents.php +++ b/tableofcontents.php @@ -42,6 +42,8 @@ class TableOfContents { private $lastLvl = 0; private $minLvl = 0; + public $numberOfHeadings; + public function __construct($html) { $this->html = $html; $this->parseHtml($html); @@ -53,7 +55,13 @@ public function __construct($html) { * returns the table of contents as printable html */ public function toHtml() { + // No headings => no reason for a table of contents + if($this->numberOfHeadings < 1) { + return ""; + } + $toc = $this->ToC; + //echo "
            " . print_r($toc, true) . "
            "; $output = "

            " . get_string('tableofcontents', 'ouwiki') . "

            "; // Helps building the nested
              -elements @@ -108,8 +116,8 @@ public function toHtml() { * * For example: 1.2.3 => 3 * 1.3 => 2 - * @param String $n The chapter number - * @return Number The headings lvel + * @param string $n The chapter number + * @return int The headings lvel */ private function getLvlByChapterNumber($n) { $e = explode('.', $n); @@ -123,7 +131,7 @@ private function getLvlByChapterNumber($n) { */ private function setMinLvl() { $reducedToC = $this->ToC; - while(!isset($reducedToC[1])) { + while(!isset($reducedToC[1]) && isset($reducedToC[0])) { $reducedToC = $reducedToC[0]; $this->minLvl++; } @@ -139,7 +147,7 @@ private function getChapterNumber($h) { // Generate full number with unnecessary zeros and dots // Example: 1.2.0.0.0.0 - for($i = 0; $i <= 6; $i++) { + for($i = 0; $i < 6; $i++) { $number .= $h[$i] . '.'; } @@ -166,28 +174,28 @@ private function getChapterNumber($h) { * @param String $html The html-snippet to parse */ private function parseHtml($html) { - $reader = new XMLReader(); - $reader->xml($html); + $dom = new DOMDocument(); + $dom->loadHTML('' . $html); - $headings = []; - $output = ""; + // Get all Headings + $xpath = new DOMXPath($dom); + $query = '//h1 | //h2 | //h3 | //h4 | //h5 | //h6 | //H1 | //H2 | //H3 | //H4 | //H5 | //H6'; + $headings = $xpath->query($query); - $lastlevel = 0; + $this->numberOfHeadings = $headings->length; - // traverse the tree - while($reader->read() !== false) { - $tag = $reader->name; - $content = $reader->readString(); - $matches = null; + if($headings->length > 0 ) { + foreach ($headings as $heading) { + // Get Heading level:
              => 6 + $lvl = substr($heading->tagName, 1); - // is it a h1-h6 heading? - preg_match('/[hH][1-6]/', $tag, $matches); - if(!empty($content) && count($matches) > 0) { - // example: h1 -> 1 - $lvl = substr($tag, 1); + // Get id: //

              => ouw_s0_0 - $id = $reader->getAttribute("id"); - $this->addToTree($lvl, $content, $id); + $attributes = $heading->attributes; + $id = $attributes->getNamedItem('id')->value; + + // Add heading to data structure + $this->addToTree($lvl, $heading->nodeValue, $id); } } } From 0edd1a15020da8b1a1cf7cce5b8ceaa082f660e3 Mon Sep 17 00:00:00 2001 From: Steffen Pegenau Date: Wed, 6 Jul 2016 10:56:08 +0200 Subject: [PATCH 06/30] Close ul-element before edit button --- tableofcontents.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tableofcontents.php b/tableofcontents.php index 3fd7732..70bc68d 100644 --- a/tableofcontents.php +++ b/tableofcontents.php @@ -47,7 +47,6 @@ class TableOfContents { public function __construct($html) { $this->html = $html; $this->parseHtml($html); - $this->setMinLvl(); } @@ -108,6 +107,8 @@ public function toHtml() { } } } + + $output .= "

            "; return $output; } From fb7c6216807deb9e93fdedecb3af2a5a308cdf34 Mon Sep 17 00:00:00 2001 From: Steffen Pegenau Date: Mon, 11 Jul 2016 12:33:39 +0200 Subject: [PATCH 07/30] Closing ul-elements correctly now. Remove comments in headings from toc --- tableofcontents.php | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/tableofcontents.php b/tableofcontents.php index 70bc68d..1b47817 100644 --- a/tableofcontents.php +++ b/tableofcontents.php @@ -61,7 +61,7 @@ public function toHtml() { $toc = $this->ToC; //echo "
            " . print_r($toc, true) . "
            "; - $output = "

            " . get_string('tableofcontents', 'ouwiki') . "

            "; + $output = PHP_EOL . "

            " . get_string('tableofcontents', 'ouwiki') . "

            " . PHP_EOL; // Helps building the nested
              -elements $lastlvl = 0; @@ -81,16 +81,16 @@ public function toHtml() { $currentLvl = $this->getLvlByChapterNumber($chapterNumber); // The elements heading - $element = '
            • '.$chapterNumber." ".$obj->name .'
            • '; + $element = '
            • '.$chapterNumber." ".$obj->name .'
            • ' . PHP_EOL; // New nested
                if($currentLvl > $lastlvl) { - $output .= str_repeat("
                  ", $currentLvl - $lastlvl); + $output .= str_repeat("
                    " . PHP_EOL, $currentLvl - $lastlvl); $output .= $element; } // Close as many
                      as necessary elseif ($currentLvl < $lastlvl) { - $output .= str_repeat("
                    ", $lastlvl - $currentLvl); + $output .= str_repeat("
                  " . PHP_EOL, $lastlvl - $currentLvl); $output .= $element; } // Same level, just add
                • @@ -108,7 +108,7 @@ public function toHtml() { } } - $output .= "
                "; + $output .= str_repeat("
              " . PHP_EOL, $lastlvl); return $output; } @@ -189,7 +189,17 @@ private function parseHtml($html) { foreach ($headings as $heading) { // Get Heading level:
              => 6 $lvl = substr($heading->tagName, 1); - + + $childNodes = $heading->childNodes; + for($i = 0; $i < $childNodes->length; $i++) { + $node = $childNodes->item($i); + if(isset($node->tagName)) { + $heading->removeChild($node); + echo "Child removed!
              "; + } + } + + // Get id: //

              => ouw_s0_0 $attributes = $heading->attributes; From f253afbe64e722aaded007ab740db190740a1e47 Mon Sep 17 00:00:00 2001 From: Steffen Pegenau Date: Mon, 11 Jul 2016 12:38:28 +0200 Subject: [PATCH 08/30] Removed debug msg --- tableofcontents.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tableofcontents.php b/tableofcontents.php index 1b47817..8ba0c16 100644 --- a/tableofcontents.php +++ b/tableofcontents.php @@ -195,7 +195,6 @@ private function parseHtml($html) { $node = $childNodes->item($i); if(isset($node->tagName)) { $heading->removeChild($node); - echo "Child removed!
              "; } } From 8d9e499faf338e5e44156104a1ebf32e15b28201 Mon Sep 17 00:00:00 2001 From: Steffen Pegenau Date: Mon, 22 Aug 2016 11:51:12 +0200 Subject: [PATCH 09/30] Possible fix for seperate group error Create a wiki with the settings 'seperate groups' and 'seperate wiki for each group'. Open the wiki, you will get the message that the page has not been created yet. Reload the page and you will receive a db write error. table: ouwikis_subwikis I think the problem is related to two uniqueness restrictions: 1. There must be only one entry for a group and wiki 2. There must be only one entry for a wiki and user (a seperate wiki for every user) In case of group wikis the user field is NULL. When opening the wiki first, an table entry is generated. When opening it the second time, Moodle tries to generate a second entry. But there already is the same combination of wiki and user (NULL) - The user-id is written to every entry in the mentioned table to avoid collisions of wikiid<->NULL - When getting the subwiki, moodle shall not look for user=NULL This may lead to problems in case of seperate wikis for every user --- locallib.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/locallib.php b/locallib.php index 1173734..1f2cd51 100644 --- a/locallib.php +++ b/locallib.php @@ -184,8 +184,8 @@ function ouwiki_get_subwiki($course, $ouwiki, $cm, $context, $groupid, $userid, $groupid = reset($groups)->id; } $othergroup = !groups_is_member($groupid); - $subwiki = $DB->get_record_select('ouwiki_subwikis', 'wikiid = ? AND groupid = ? - AND userid IS NULL', array($ouwiki->id, $groupid)); + // Removed AND userid IS NULL + $subwiki = $DB->get_record_select('ouwiki_subwikis', 'wikiid = ? AND groupid = ?', array($ouwiki->id, $groupid)); if ($subwiki) { ouwiki_set_extra_subwiki_fields($subwiki, $ouwiki, $context, $othergroup); return $subwiki; @@ -257,11 +257,11 @@ function ouwiki_get_subwiki($course, $ouwiki, $cm, $context, $groupid, $userid, // Create a new subwiki instance function ouwiki_create_subwiki($ouwiki, $cm, $course, $userid = null, $groupid = null) { - global $DB; + global $DB, $USER; $subwiki = new StdClass; $subwiki->wikiid = $ouwiki->id; - $subwiki->userid = $userid; + $subwiki->userid = $USER->id; $subwiki->groupid = $groupid; $subwiki->magic = ouwiki_generate_magic_number(); try { From 08f2911bad0b8180357c79084278f90132f6d971 Mon Sep 17 00:00:00 2001 From: Steffen Pegenau Date: Tue, 30 Aug 2016 15:02:39 +0200 Subject: [PATCH 10/30] Possible fix for group wiki problem --- locallib.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/locallib.php b/locallib.php index 1f2cd51..a68e1e7 100644 --- a/locallib.php +++ b/locallib.php @@ -257,13 +257,21 @@ function ouwiki_get_subwiki($course, $ouwiki, $cm, $context, $groupid, $userid, // Create a new subwiki instance function ouwiki_create_subwiki($ouwiki, $cm, $course, $userid = null, $groupid = null) { - global $DB, $USER; + global $DB; $subwiki = new StdClass; $subwiki->wikiid = $ouwiki->id; - $subwiki->userid = $USER->id; + $subwiki->userid = $userid; $subwiki->groupid = $groupid; $subwiki->magic = ouwiki_generate_magic_number(); + + // Is there already a wiki? + $conditions = array('wikiid' => $ouwiki->id, 'userid' => $userid, 'groupid' => $groupid); + if($DB->record_exists('ouwiki_subwikis', $conditions)) { + return $DB->get_record('ouwiki_subwikis', $conditions); + } + + // Create Wiki! try { $subwiki->id = $DB->insert_record('ouwiki_subwikis', $subwiki); } catch (Exception $e) { From 394b3cc2d50aa09cbc9ebbf45e4f6d51c77aecfc Mon Sep 17 00:00:00 2001 From: Git on Alpha Date: Tue, 30 Aug 2016 16:09:51 +0200 Subject: [PATCH 11/30] Fixed group/individual MSSQL Bug There are two constraints on the table ouwiki_subwikis 1. combination of wikiid and groupid must be unique 2. combination of wikiid and userid must be unique Example: Two subwikis for different groups resulted in wikiid: 1 groupid: 1 userid: NULL wikiid: 1 groupid: 2 userid: NULL On MSSQL this is prohibited by constraint 2 and the creation of the second subwiki resulted in an exception. To fix this the magic number is used as userid or groupid in case they are NULL. --- locallib.php | 22 ++++++++-------------- view.php | 3 ++- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/locallib.php b/locallib.php index a68e1e7..c7d0e07 100644 --- a/locallib.php +++ b/locallib.php @@ -151,8 +151,8 @@ function ouwiki_get_subwiki($course, $ouwiki, $cm, $context, $groupid, $userid, switch($ouwiki->subwikis) { case OUWIKI_SUBWIKIS_SINGLE: - $subwiki = $DB->get_record_select('ouwiki_subwikis', 'wikiid = ? AND groupid IS NULL - AND userid IS NULL', array($ouwiki->id)); + // Removed AND groupid IS NULL AND userid IS NULL + $subwiki = $DB->get_record_select('ouwiki_subwikis', 'wikiid = ?', array($ouwiki->id)); if ($subwiki) { ouwiki_set_extra_subwiki_fields($subwiki, $ouwiki, $context); return $subwiki; @@ -234,8 +234,8 @@ function ouwiki_get_subwiki($course, $ouwiki, $cm, $context, $groupid, $userid, } } // OK now find wiki - $subwiki = $DB->get_record_select('ouwiki_subwikis', 'wikiid = ? AND groupid IS NULL - AND userid = ?', array($ouwiki->id, $userid)); + // Removed AND groupid IS NULL + $subwiki = $DB->get_record_select('ouwiki_subwikis', 'wikiid = ? AND userid = ?', array($ouwiki->id, $userid)); if ($subwiki) { ouwiki_set_extra_subwiki_fields($subwiki, $ouwiki, $context, $otheruser, !$otheruser); return $subwiki; @@ -261,16 +261,10 @@ function ouwiki_create_subwiki($ouwiki, $cm, $course, $userid = null, $groupid = $subwiki = new StdClass; $subwiki->wikiid = $ouwiki->id; - $subwiki->userid = $userid; - $subwiki->groupid = $groupid; - $subwiki->magic = ouwiki_generate_magic_number(); - - // Is there already a wiki? - $conditions = array('wikiid' => $ouwiki->id, 'userid' => $userid, 'groupid' => $groupid); - if($DB->record_exists('ouwiki_subwikis', $conditions)) { - return $DB->get_record('ouwiki_subwikis', $conditions); - } - + $subwiki->magic = ouwiki_generate_magic_number(); + $subwiki->userid = ($userid) ? $userid : $subwiki->magic; + $subwiki->groupid = ($groupid) ? $groupid : $subwiki->magic; + // Create Wiki! try { $subwiki->id = $DB->insert_record('ouwiki_subwikis', $subwiki); diff --git a/view.php b/view.php index ce96014..b63b560 100644 --- a/view.php +++ b/view.php @@ -51,6 +51,7 @@ // Check consistency in setting subwikis and group mode $courselink = new moodle_url('/course/view.php?id=', array('id' => $cm->course)); +/* if (($cm->groupmode == 0) && isset($subwiki->groupid)) { print_error("Sub-wikis is set to 'One wiki per group'. Please change Group mode to 'Separate groups' or 'Visible groups'.", 'error', $courselink); @@ -59,7 +60,7 @@ print_error("Sub-wikis is NOT set to 'One wiki per group'. Please change Group mode to 'No groups'.", 'error', $courselink); } - +*/ $locked = ($pageversion) ? $pageversion->locked : false; ouwiki_print_tabs('view', $pagename, $subwiki, $cm, $context, $pageversion ? true : false, $locked); From b0c74036e6f94755257a502947dcd2d5b47d20a2 Mon Sep 17 00:00:00 2001 From: Wilker Date: Tue, 1 Nov 2016 16:08:40 +0100 Subject: [PATCH 12/30] css modifications --- styles.css | 182 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 142 insertions(+), 40 deletions(-) diff --git a/styles.css b/styles.css index c445889..e94a397 100644 --- a/styles.css +++ b/styles.css @@ -4,7 +4,7 @@ margin:1em; } #page-mod-ouwiki-view .ouw_recentchanges { - font-size:0.85em; + font-size:0.7em; color:#636363; margin-top:0.5em; } @@ -52,6 +52,11 @@ #page-mod-ouwiki-contributions th { text-align:left; padding: 5px 12px 5px 4px; + background: #f5f5f5; + border-left: 1px solid #f5f5f5; + border-right: 1px solid #f5f5f5; + border-top:1px solid #f5f5f5; + border-bottom:1px solid #f5f5f5; } .dir-rtl#page-mod-ouwiki-history .ouw_history th, .dir-rtl#page-mod-ouwiki-wikihistory th, @@ -63,6 +68,17 @@ #page-mod-ouwiki-wikihistory td, #page-mod-ouwiki-contributions td { padding: 3px 12px 3px 4px; + border-bottom:1px solid #888; +} +#page-mod-ouwiki-wikihistory td.ouw_rightcol, +#page-mod-ouwiki-contributions td.ouw_rightcol, +#page-mod-ouwiki-history .ouw_history td.ouw_rightcol { + border-right:1px solid #888; +} +#page-mod-ouwiki-wikihistory td.ouw_leftcol, +#page-mod-ouwiki-contributions td.ouw_leftcol, +#page-mod-ouwiki-history .ouw_history td.ouw_leftcol { + border-left:1px solid #888; } #page-mod-ouwiki-history .ouw_history td.check, #page-mod-ouwiki-history .ouw_history td.comparebutton { @@ -178,15 +194,39 @@ body.jsenabled #ouwiki_belowtabs_annotate_nojs { #ouwiki_noindexlink { height:1em; } -#ouwiki_indexlinks a { - border:1px solid #aaa; - padding:2px; - font-size:84%; + +#ouwiki_indexlinks a, +#ouwiki_indexlinks a:visited, +#ouwiki_indexlinks a:active, +#ouwiki_indexlinks a:link, +#ouwiki_indexlinks a:focus { + padding:6px 12px; + border:1px solid #ccc; + margin-right:5px; + border-radius: 4px; + text-align:center; + font-size:13px; + vertical-align: middle; + background-color:#fff +} + +#ouwiki_indexlinks a:hover { + background-color:#f1f1f1; + text-decoration: none; + color:#333; + border:1px solid #bbb; } + #ouwiki_indexlinks span { - border:1px solid black; - padding:2px; - font-size:84%; + padding:6px 12px; + margin-right:5px; + border-radius: 4px; + text-align:center; + font-size:13px; + vertical-align: middle; + border:1px solid #ddd; + background-color:#ddd; + font-weight: bold; } #page-mod-ouwiki-wikiindex ul.ouw_index, @@ -207,9 +247,9 @@ body.jsenabled #ouwiki_belowtabs_annotate_nojs { #page-mod-ouwiki-wikiindex .ouw_title { display:block; font-weight:bold; - background:#dcedff; + background:#f5f5f5; padding:4px 8px 8px; - border-top:1px solid #888; + border:1px solid #888; margin-top:-1px; color: black; } @@ -219,14 +259,14 @@ body.jsenabled #ouwiki_belowtabs_annotate_nojs { } #page-mod-ouwiki-import .ouw_indexinfo, #page-mod-ouwiki-wikiindex .ouw_indexinfo { - border:1px dotted #888; + border:1px solid #888; border-top:none; padding:4px 8px 6px; font-size:0.8em; color:#888; } #page-mod-ouwiki-wikiindex .ouw_index .ouw_index_startpage .ouw_indexinfo { - border-bottom:1px dotted #888; + border-bottom:1px solid #888; } .ie#page-mod-ouwiki-wikiindex .ouw_index_startpage .ouw_title { border-top:2px solid #888; @@ -292,9 +332,9 @@ body.jsenabled #ouwiki_belowtabs_annotate_nojs { #page-mod-ouwiki-diff .ouw_diff { background:#f0f0f0; color:#636363; - border-left:1px dotted #888; - border-right:1px dotted #888; - border-bottom:1px dotted #888; + border-left:1px solid #888; + border-right:1px solid #888; + border-bottom:1px solid #888; padding:8px; } #page-mod-ouwiki-diff .ouw_left .ouw_diff, @@ -335,9 +375,35 @@ body.jsenabled #ouwiki_belowtabs_annotate_nojs { font-weight:normal; font-style:normal; font-size:0.85em; - margin-left:1em; + margin-left:0px; } +/* Edited */ +#page-mod-ouwiki-view .ouw_byheading a { + padding:5px 5px; + border:1px solid #ccc; + margin-right:5px; + border-radius: 4px; + text-align:center; + font-size:12px; + vertical-align: middle; + background-color:#fff; + margin-left:0px; + display:inline-block; +} + +.ouw_heading3 a { + margin-left: 0; +} + +#page-mod-ouwiki-view .ouw_byheading a:hover { + background-color:#f1f1f1; + text-decoration: none; + color:#333; + border:1px solid #bbb; +} + + #page-mod-ouwiki-view .ouw_editsection, #page-mod-ouwiki-view .ouw_annotate, #page-mod-ouwiki-view .ouw_editpage, @@ -366,30 +432,36 @@ body.jsenabled #ouwiki_belowtabs_annotate_nojs { .ouwiki_content h1, .ouwiki_content h2 { font-size:1.5em; - display:inline; + display:block; + padding:0px; + line-height:150%; } .ouwiki_content h3, .ouwiki_content h4, .ouwiki_content h5 { - font-size:1em; - display:inline; + font-size:1.2em; + display:block; + padding:0px; + line-height:150%; } .ouwiki_content h6 { - font-size:0.85em; - display:inline; + font-size:1em; + display:block; + padding:0px; + line-height:150%; } .ouwiki_content .ouw_heading1, .ouwiki_content .ouw_heading2 { - margin:0.6667em 0 0.3333em 0; + margin:0 0 0.3333em 0; } .ouwiki_content .ouw_heading3, .ouwiki_content .ouw_heading4, .ouwiki_content .ouw_heading5 { - margin:1em 0 0.5em 0; + margin:0 0 0.5em 0; } .ouwiki_content .ouw_heading6 { - margin:1.25em 0 0.625em 0; + margin:0 0 0.625em 0; } .ouwiki_content h1.ouw_fixedheading, @@ -408,13 +480,13 @@ body.jsenabled #ouwiki_belowtabs_annotate_nojs { } .ouwiki_content h1 { padding-bottom:2px; - border-bottom:1px dotted #888; + border-bottom:1px solid #888; } .ouwiki_content h6.ouw_fixedheading .ouw_headingtext { font-size:0.85em; } .ouwiki_content h3 { - border-bottom:1px dotted #888; + border-bottom:1px solid #888; padding-bottom:2px; } .ouwiki_content h5, @@ -493,15 +565,16 @@ body.jsenabled #ouwiki_belowtabs_annotate_nojs { } #page-mod-ouwiki-view .ouw_linkedfrom h3 { margin:0; - font-size:1em; - font-weight:normal; + font-size:1.2em; + font-weight:bold; } + +/* Edited */ #page-mod-ouwiki-view .ouw_linkedfrom ul, #page-mod-ouwiki-view .ouw_linkedfrom li { - margin:0; - padding:0; - list-style-type:none; - display:inline; + font-size:1.2em; + list-style-type:disc; + text-decoration: underline; } #page-mod-ouwiki-wikiindex .ouw_missingpages ul, @@ -576,23 +649,29 @@ a.ouwiki_noshow:link,a.ouwiki_noshow:visited { top:-1px; } +/* Edited */ .ouw_belowmainhead { - border:1px dotted #888; + border:none; border-top:none; padding:0px 8px 4px; + margin-top:45px; } .ouw_topspacer { padding-top:4px; } .ouw_topheading { - background:#dcedff; + background:#f5f5f5; padding:4px 8px 8px; - border-top:1px solid #888; + border:1px solid #888; margin-top:1.5em; } .ouw_topheading h2 { border:none; + margin-top:0px; + margin-bottom: 0px; + margin-left:0px; + padding:0px; } @@ -601,6 +680,32 @@ a.ouwiki_noshow:link,a.ouwiki_noshow:visited { list-style-type:none; } +/* Edited */ + +#ouwiki_addnew { + margin-top: 45px; +} + +#ouwiki_addnew ul { + list-style-type: none; + border-top: 1px solid rgb(192, 192, 192); + padding-top: 10px; + margin-left: 0px; +} + + +.ouw_linkedfrom .ouw_topheading { + + background: none; + padding:0px; + border: none; + border-top:1px solid #c0c0c0; +} + + +/* End */ + + #page-mod-ouwiki-entirewiki .ouw_entry h1.ouw_entry_heading { background:#dcedff; padding:4px 8px 8px; @@ -610,7 +715,7 @@ a.ouwiki_noshow:link,a.ouwiki_noshow:visited { margin:0.5em 0 0; } #page-mod-ouwiki-entirewiki .ouw_entry .ouwiki_content { - border:1px dotted #888; + border:1px solid #888; border-top:none; padding:4px 8px; margin-top:0; @@ -713,7 +818,7 @@ a.ouwiki_noshow:link,a.ouwiki_noshow:visited { } #page-mod-ouwiki-annotate #mform1 .fitem .fitemtitle { - padding-right: 15px; + margin-left: -30px; width: 160px; } @@ -884,6 +989,3 @@ a.ouwiki_noshow:link,a.ouwiki_noshow:visited { font-size: 0.8em; margin-left: 5px; } -.ouw-comparebutton-wrapper { - text-align: right; -} From a14b63a0850de17704dbc5bb79d8a22d074718c2 Mon Sep 17 00:00:00 2001 From: Wilker Date: Wed, 2 Nov 2016 10:29:12 +0100 Subject: [PATCH 13/30] customized headings similar to wikipedia --- styles.css | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/styles.css b/styles.css index e94a397..3e5348b 100644 --- a/styles.css +++ b/styles.css @@ -436,14 +436,31 @@ body.jsenabled #ouwiki_belowtabs_annotate_nojs { padding:0px; line-height:150%; } + .ouwiki_content h3, .ouwiki_content h4, .ouwiki_content h5 { - font-size:1.2em; display:block; padding:0px; line-height:150%; + font-weight:bold } + +.ouwiki_content h3 { + border-bottom:1px solid #888; + padding-bottom:2px; + font-size:1.5em; +} + +.ouwiki_content h4 { + font-size:1.2em; +} + +.ouwiki_content h5 { + font-size:1em; +} + + .ouwiki_content h6 { font-size:1em; display:block; @@ -485,15 +502,6 @@ body.jsenabled #ouwiki_belowtabs_annotate_nojs { .ouwiki_content h6.ouw_fixedheading .ouw_headingtext { font-size:0.85em; } -.ouwiki_content h3 { - border-bottom:1px solid #888; - padding-bottom:2px; -} -.ouwiki_content h5, -.ouwiki_content h6 { - font-weight:normal; - font-style:italic; -} #ouw_ac_formcontainer { margin-top:1.5em; From db2cd5e207d5e188c90916b35a4fddcd59e4e38c Mon Sep 17 00:00:00 2001 From: Wilker Date: Fri, 9 Dec 2016 11:15:14 +0100 Subject: [PATCH 14/30] plugin icon ersetzt --- pix/icon.gif | Bin 1027 -> 0 bytes pix/icon.png | Bin 0 -> 1437 bytes 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 pix/icon.gif create mode 100644 pix/icon.png diff --git a/pix/icon.gif b/pix/icon.gif deleted file mode 100644 index c891b205c25eb68c349cd3998703a85c2d75c176..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1027 zcmV+e1pNC)Nk%v~VGsZi0O$Sy009610R#d71qJ{B1ONsH000RA00jaE1_KEQ1quuW z0|^EU3kMAj2L%iX4i5u^ zDJ(83DJ&~4FfK7NFf%kTFETSRG%__cGdDOiGdMOnIygK$I5#;uI6yu^Lq0u0KSM)7 zMMXhCMnXYFLq0`ZD?n3Yie$6aB*#Ga&ByJZgO#Nb8~TZc64}jc5``j zb9i=odvDf`);HiHC)WiiL!Uhl`AdhKP!X zi;0bniHMDhkCKdwl8}^@kdBd)kd~B~nUs>4mYSNEo1K`Ko0*-Uo0^}TprW0eq@JCl zproaspQ5CprJ|>(qoSsysHvx`tf!`~sHdx`t*NW1uc@f6tFW=Gs;{lFvahtYu&=eU zwzsmexwNylwYj~ty1BNyzqz=*y1u}@!o|S9!@FVU;>*eI;=;i6= z>+I&`?dRt1=;!O{?dt65@$2gE?eX*N?DX#K^6&HZ@bB~S_44%a_4D`m^YQoe`TF$p z_W1Sr_WS(y_4@bx{rC3!`2GI)_y76${QCa-{Q3X-`ThI<`~CX={QCa<|M~y_|NZ;? z|NH;_|Nj5{EC2ui01yBW000Q+0FS7Nr*Bl74-7UqAOL^>qJQ(|<(sFBfW-g^5LhIj zM&CY<`?fu}NOH@(Ry)Y)`}a>tfB+jULSwffz?FY1`2ctc6F?Vz-Vy|O;O*Z&Z$wf& zDI)}o%4`Y`vQ|dtADuygc1f5CYOIl z2*CVk3V^0m4fWRgx8&j@O+5ernzIo?yMMf@6hIpQ?GZ~mJD6fQZyzN=F(qh&;=z_a xkMrtf`?m4rrg_Aiz;M$lPm2c*URnf@hn))o1~ww7oY5i#V!ZU~)@v~!06WCt{J#JI diff --git a/pix/icon.png b/pix/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..7cd6545412a0c8f25ce4bb76adbb30d49c702f6b GIT binary patch literal 1437 zcmV;O1!DS%P)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!~g&e!~vBn4jTXf00v@9M??Vs0RI60 zpuMM)00007bV*G`2igV@4-y(K;`u@V00j+6L_t(YOSM&NY*S?ze$F{-PcQ4*vqD#3 zY{2Lkmu`WThCLiWQS@}%GSF7Nlf@Atmn^S=CeL;~l3?_sj8?q6}X^9&nz{%{7FOa{O8bR!rFvb6`n<@0%Y+xxRH z$!y2gngfWA-bGVW69$I{VJbJ#4j>kbVd|8raJz3}fzt_t!GKezzDHZz6F70=IM%LR zhwkn!D6!tSev_)X0Is9=1KAh8j$Y4MNEMTDaC?dW?ev-W+kG9a zipUd;zoDHXtky}$=5j<+BW$)RSZsF4r}tr+_y=^l1cKfad~rKwJg+KOQ1XBdD(_ug zU5zw1h7Gm5F&2(upJOGg z&m2T9;%9osLA)s;PhQMzn8!SEIO@UA;lc4O;JGbKu255;;ufbu7pAaf*;+UhMu-ZZ%<+icI0>z7KH{b( zTpluDXxVGH+4~bh6xt+ZaweT&ij{LLL6ylc87MazNnwT=(^D}so6Yc3a#5{gj4_hj zfBP0%HtoUXQzF8aHq^Yh8+MD1&N`Xb8jXe#V0_GRoLVX_Ub;jRz`0-^8Of`H2^$Zd zFY=-YHSRLW1blt$7}l&_4as6*GPXNH$s<`L+M_BcHKEuzj(RdM5ytl_u#o4`=r9{A zU>v~b7iawiepu-RA?T5UAqE)(h_Wba(l_ZNVp&VYv*WIN(<$VGJPJnYXK9lD&V<1 rY8oGf(L9;Wi~k1?3lqQE{|4Y+W+6t9DcmUM00000NkvXXu0mjf_ic_l literal 0 HcmV?d00001 From c96395e9303a4a66f5fa395a5f1df7898012dbc2 Mon Sep 17 00:00:00 2001 From: Wilker Date: Fri, 9 Dec 2016 11:19:11 +0100 Subject: [PATCH 15/30] gesamtes wiki als print-html und pdf version --- entirewiki.php | 129 ++++++++++++++++++++++++++++++++++++++++--------- locallib.php | 3 +- pdf.css | 0 3 files changed, 109 insertions(+), 23 deletions(-) create mode 100644 pdf.css diff --git a/entirewiki.php b/entirewiki.php index 85bbe13..0fc21d3 100644 --- a/entirewiki.php +++ b/entirewiki.php @@ -54,7 +54,8 @@ $ouwikioutput = $PAGE->get_renderer('mod_ouwiki'); $format = required_param('format', PARAM_ALPHA); -if ($format !== OUWIKI_FORMAT_HTML && $format !== OUWIKI_FORMAT_RTF && $format !== OUWIKI_FORMAT_TEMPLATE) { +if ($format !== OUWIKI_FORMAT_HTML && $format !== OUWIKI_FORMAT_PDF + && $format !== OUWIKI_FORMAT_TEMPLATE && $format !== OUWIKI_FORMAT_HTML_PRINT) { print_error('Unexpected format'); } @@ -71,9 +72,28 @@ $files = array(); $fs = get_file_storage(); break; - case OUWIKI_FORMAT_RTF: - require_once($CFG->dirroot.'/local/rtf.php'); - $markup = '

              '.get_string('savedat', 'ouwiki', userdate(time())).'


              '; + case OUWIKI_FORMAT_HTML_PRINT: + + $url_object_array = $PAGE->theme->css_urls($PAGE); + $url_object = $url_object_array[0]; + $css_url = $url_object->out(); + + $markup = ''; + $markup .= ''; + $markup .= ''; + $markup .= ''; + $markup .= ''; + + break; + case OUWIKI_FORMAT_PDF: + + $markup = ''; + $css = file_get_contents(dirname(__FILE__) .'/pdf.css'); + $markup .= ''; + $markup .= ''; + $markup .= ''; + $markup .= ''; + break; case OUWIKI_FORMAT_HTML: // Do header @@ -98,27 +118,61 @@ } } -// If tree view specified. -if (($treemode) && ($format == OUWIKI_FORMAT_HTML) ) { +// // Original +// if (($treemode) && ($format == OUWIKI_FORMAT_HTML) ) { +// ouwiki_build_tree($index); +// // Print out in hierarchical form... +// print '
                '; +// $functionname = 'ouwiki_display_entirewiki_page_in_index'; +// print ouwiki_tree_index($functionname, reset($index)->pageid, $index, $subwiki, $cm, $context); +// print '
              '; + +// if ($orphans) { +// print '

              '.get_string('orphanpages', 'ouwiki').'

              '; +// print '
                '; +// foreach ($index as $indexitem) { +// if (count($indexitem->linksfrom) == 0 && $indexitem->title !== '') { +// $orphanindex = ouwiki_get_sub_tree_from_index($indexitem->pageid, $index); +// ouwiki_build_tree($orphanindex); +// print ouwiki_tree_index($functionname, $indexitem->pageid, $orphanindex, $subwiki, $cm, $context); +// } +// } +// print '
              '; +// } +// } else { + + +//If tree view specified. +if (($treemode) && ($format == OUWIKI_FORMAT_HTML || $format == OUWIKI_FORMAT_PDF || $format == OUWIKI_FORMAT_HTML_PRINT) ) { + ouwiki_build_tree($index); // Print out in hierarchical form... - print '
                '; + + $treeOutput = '
                  '; + $functionname = 'ouwiki_display_entirewiki_page_in_index'; - print ouwiki_tree_index($functionname, reset($index)->pageid, $index, $subwiki, $cm, $context); - print '
                '; + $treeOutput .= ouwiki_tree_index($functionname, reset($index)->pageid, $index, $subwiki, $cm, $context); + $treeOutput .= '
              '; if ($orphans) { - print '

              '.get_string('orphanpages', 'ouwiki').'

              '; - print '
                '; + $treeOutput .= '

                '.get_string('orphanpages', 'ouwiki').'

                '; + $treeOutput .= '
                  '; foreach ($index as $indexitem) { if (count($indexitem->linksfrom) == 0 && $indexitem->title !== '') { $orphanindex = ouwiki_get_sub_tree_from_index($indexitem->pageid, $index); ouwiki_build_tree($orphanindex); - print ouwiki_tree_index($functionname, $indexitem->pageid, $orphanindex, $subwiki, $cm, $context); + $treeOutput .= ouwiki_tree_index($functionname, $indexitem->pageid, $orphanindex, $subwiki, $cm, $context); } } - print '
                '; + $treeOutput .= '
              '; } + + if($format == OUWIKI_FORMAT_HTML) + print $treeOutput; + + if($format == OUWIKI_FORMAT_PDF || $format == OUWIKI_FORMAT_HTML_PRINT) + $markup .= $treeOutput; + } else { foreach ($index as $pageinfo) { if (count($pageinfo->linksfrom)!= 0 || $pageinfo->title === '') { @@ -129,8 +183,15 @@ continue; } - $markup .= get_online_display_content($format, $pageversion, $context, $subwiki, $cm, $index, $fs, $files); - + + $output = get_online_display_content($format, $pageversion, $context, $subwiki, $cm, $index, $fs, $files); + + if($format == OUWIKI_FORMAT_HTML) + print $output; + + if($format == OUWIKI_FORMAT_PDF || $format == OUWIKI_FORMAT_HTML_PRINT) + $markup .= $output; + if ($first) { $first = false; } @@ -184,9 +245,26 @@ exit; break; - case OUWIKI_FORMAT_RTF: - $markup .= '
              '; - rtf_from_html($filename.'.rtf', $markup); + case OUWIKI_FORMAT_HTML_PRINT: + + $markup .= ''; + + echo $markup; + break; + + case OUWIKI_FORMAT_PDF: + $markup .= ''; + + require_once($CFG->libdir . '/pdflib.php'); + + $doc = new pdf; + $doc->setFont('helvetica'); + $doc->setPrintHeader(false); + $doc->setPrintFooter(false); + $doc->AddPage(); + $doc->writeHTML($markup); + $doc->Output(); + break; case OUWIKI_FORMAT_HTML: @@ -245,10 +323,17 @@ function get_online_display_content($format, $pageversion, $context, $subwiki, $ } $markup .= ''; break; - case OUWIKI_FORMAT_RTF: - $markup .= '

              ' . htmlspecialchars($visibletitle) . '

              '; - $markup .= trim($pageversion->xhtml); - $markup .= '


              '; + case OUWIKI_FORMAT_PDF || OUWIKI_FORMAT_HTML_PRINT: + //$markup .= '

              ' . htmlspecialchars($visibletitle) . '

              '; + //$markup .= trim($pageversion->xhtml); + //$markup .= '


              '; + + $markup .= '

              ' . + '' . htmlspecialchars($visibletitle) . '

              '; + $markup .= ouwiki_convert_content($pageversion->xhtml, $subwiki, $cm, $index, $pageversion->xhtmlformat); + $markup .= '
              '; + break; case OUWIKI_FORMAT_HTML: print '

              ' . diff --git a/locallib.php b/locallib.php index c7d0e07..4cf6177 100644 --- a/locallib.php +++ b/locallib.php @@ -51,8 +51,9 @@ define('OUWIKI_PARAMS_ARRAY', 3); define('OUWIKI_FORMAT_HTML', 'html'); -define('OUWIKI_FORMAT_RTF', 'rtf'); +define('OUWIKI_FORMAT_PDF', 'pdf'); define('OUWIKI_FORMAT_TEMPLATE', 'template'); +define('OUWIKI_FORMAT_HTML_PRINT', 'print'); // pages define('OUWIKI_GETPAGE_REQUIREVERSION', 0); diff --git a/pdf.css b/pdf.css new file mode 100644 index 0000000..e69de29 From a2cb0fae5bfdb41f412a4d42422c939b617a4e4e Mon Sep 17 00:00:00 2001 From: Wilker Date: Fri, 9 Dec 2016 16:19:38 +0100 Subject: [PATCH 16/30] Dropdownmenu Wiki-Drucken --- renderer.php | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++ styles.css | 20 ++++++++++--------- 2 files changed, 66 insertions(+), 9 deletions(-) diff --git a/renderer.php b/renderer.php index f91b53a..dc8e77b 100644 --- a/renderer.php +++ b/renderer.php @@ -762,7 +762,9 @@ public function ouwiki_get_links() { */ public function ouwiki_get_links_content() { global $USER; + $output = html_writer::start_tag('ul'); + if ($this->params->page == 'wikiindex.php') { $output .= html_writer::start_tag('li', array('id' => 'ouwiki_nav_index')); $output .= html_writer::start_tag('span'); @@ -839,6 +841,59 @@ public function ouwiki_get_links_content() { $output .= html_writer::end_tag('li'); } } + + + $params = $this->params; + + $wikiParams = function ($format, $isTypeTree = false) use ($params) { + + $subwiki = $params->subwiki; + $cm = $params->cm; + + $url = 'entirewiki.php?'; + $url .= html_entity_decode(ouwiki_display_wiki_parameters('', $subwiki, $cm)); + $url .= sprintf('&format=%s', $format); + + if($isTypeTree) + $url .= '&type=tree'; + + return $url; + }; + + + // Dropdown fuer Druckfunktion + $output .= html_writer::start_tag('li', array('id' => 'ouwiki_nav_print')); + $output .= html_writer::start_tag('div', array('class' => 'btn-group')); + + $output .= html_writer::start_tag('button', array('class' => 'btn dropdown-toggle', 'data-toggle' => 'dropdown')); + $output .= 'Wiki drucken '; + $output .= html_writer::tag('span', '', array('class' => 'caret')); + $output .= html_writer::end_tag('button'); + + $output .= html_writer::start_tag('ul', array('class' => 'dropdown-menu')); + + $output .= html_writer::start_tag('li'); + $output .= html_writer::tag('a', 'PDF (Alphabetisch)', array('target' => '_blank', 'href' => $wikiParams(OUWIKI_FORMAT_PDF))); + $output .= html_writer::end_tag('li'); + + $output .= html_writer::start_tag('li'); + $output .= html_writer::tag('a', 'PDF (Struktur)', array('target' => '_blank', 'href' => $wikiParams(OUWIKI_FORMAT_PDF, true))); + $output .= html_writer::end_tag('li'); + + $output .= html_writer::start_tag('li'); + $output .= html_writer::tag('a', 'HTML (Alphabetisch)', array('target' => '_blank', 'href' => $wikiParams(OUWIKI_FORMAT_HTML_PRINT))); + $output .= html_writer::end_tag('li'); + + $output .= html_writer::start_tag('li'); + $output .= html_writer::tag('a', 'HTML (Struktur)', array('target' => '_blank', 'href' => $wikiParams(OUWIKI_FORMAT_HTML_PRINT, true))); + $output .= html_writer::end_tag('li'); + + $output .= html_writer::end_tag('ul'); + + $output .= html_writer::end_tag('div'); + $output .= html_writer::end_tag('li'); + + $output .= html_writer::end_tag('ul'); return array($output, $participationstr); } diff --git a/styles.css b/styles.css index 3e5348b..9d04efc 100644 --- a/styles.css +++ b/styles.css @@ -169,11 +169,12 @@ body.jsenabled #ouwiki_belowtabs_annotate_nojs { text-align: left; } -#ouwiki_indexlinks ul { +#ouwiki_indexlinks { margin:0; padding:0; display:inline; } + #ouwiki_indexlinks form, #ouwiki_indexlinks form div { display:inline; @@ -185,7 +186,7 @@ body.jsenabled #ouwiki_belowtabs_annotate_nojs { width:10em; } -#ouwiki_indexlinks li { +#ouwiki_nav_print, #ouwiki_nav_index, #ouwiki_nav_history, #ouwiki_nav_participation { margin:0 0.5em 0 0; padding:0; list-style-type:none; @@ -195,11 +196,11 @@ body.jsenabled #ouwiki_belowtabs_annotate_nojs { height:1em; } -#ouwiki_indexlinks a, -#ouwiki_indexlinks a:visited, -#ouwiki_indexlinks a:active, -#ouwiki_indexlinks a:link, -#ouwiki_indexlinks a:focus { +#ouwiki_indexlinks > ul > li > a, +#ouwiki_indexlinks > ul > li > a:visited, +#ouwiki_indexlinks > ul > li > a:active, +#ouwiki_indexlinks > ul > li > a:link, +#ouwiki_indexlinks > ul > li > a:focus { padding:6px 12px; border:1px solid #ccc; margin-right:5px; @@ -217,7 +218,7 @@ body.jsenabled #ouwiki_belowtabs_annotate_nojs { border:1px solid #bbb; } -#ouwiki_indexlinks span { +/* #ouwiki_indexlinks span { padding:6px 12px; margin-right:5px; border-radius: 4px; @@ -228,7 +229,8 @@ body.jsenabled #ouwiki_belowtabs_annotate_nojs { background-color:#ddd; font-weight: bold; } - + */ + #page-mod-ouwiki-wikiindex ul.ouw_index, #page-mod-ouwiki-wikiindex ul.ouw_index li, #page-mod-ouwiki-wikiindex ul.ouw_indextree, From 211c4ab590dc103137b81d7e52bf89d112c32d02 Mon Sep 17 00:00:00 2001 From: Wilker Date: Mon, 20 Mar 2017 12:56:09 +0100 Subject: [PATCH 17/30] add style to display all navigation buttons inline --- styles.css | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/styles.css b/styles.css index 9d04efc..71007d3 100644 --- a/styles.css +++ b/styles.css @@ -999,3 +999,8 @@ a.ouwiki_noshow:link,a.ouwiki_noshow:visited { font-size: 0.8em; margin-left: 5px; } + +div#ouwiki_indexlinks > ul > li { + display:inline +} + From 273773789710cfa18c704e6198ebfbae73dcd086 Mon Sep 17 00:00:00 2001 From: Wilker Date: Tue, 27 Feb 2018 11:09:48 +0100 Subject: [PATCH 18/30] manually set the settings cog to be displayed on the page for boost-based themes --- view.php | 1 + 1 file changed, 1 insertion(+) diff --git a/view.php b/view.php index b63b560..a0fc34b 100644 --- a/view.php +++ b/view.php @@ -31,6 +31,7 @@ $url = new moodle_url('/mod/ouwiki/view.php', array('id' => $id, 'page' => $pagename)); $PAGE->set_url($url); $PAGE->set_cm($cm); +$PAGE->force_settings_menu(); $context = context_module::instance($cm->id); $PAGE->set_pagelayout('incourse'); From 67331a4353bb6a1d6d091c28a9e762f582de782f Mon Sep 17 00:00:00 2001 From: hecatesBrain Date: Mon, 8 Jul 2019 11:03:37 +0200 Subject: [PATCH 19/30] Refactor Table of Contents and fix wiki print function. --- entirewiki.php | 130 ++++++++++++------- lang/en/ouwiki.php | 5 + renderer.php | 17 ++- styles.css | 15 +++ tableofcontents.php | 305 +++++++++++--------------------------------- 5 files changed, 189 insertions(+), 283 deletions(-) diff --git a/entirewiki.php b/entirewiki.php index 0fc21d3..8ec28e8 100644 --- a/entirewiki.php +++ b/entirewiki.php @@ -54,7 +54,7 @@ $ouwikioutput = $PAGE->get_renderer('mod_ouwiki'); $format = required_param('format', PARAM_ALPHA); -if ($format !== OUWIKI_FORMAT_HTML && $format !== OUWIKI_FORMAT_PDF +if ($format !== OUWIKI_FORMAT_HTML && $format !== OUWIKI_FORMAT_PDF && $format !== OUWIKI_FORMAT_TEMPLATE && $format !== OUWIKI_FORMAT_HTML_PRINT) { print_error('Unexpected format'); } @@ -73,27 +73,27 @@ $fs = get_file_storage(); break; case OUWIKI_FORMAT_HTML_PRINT: - + $url_object_array = $PAGE->theme->css_urls($PAGE); $url_object = $url_object_array[0]; $css_url = $url_object->out(); - + $markup = ''; $markup .= ''; $markup .= ''; $markup .= ''; $markup .= ''; - + break; case OUWIKI_FORMAT_PDF: $markup = ''; $css = file_get_contents(dirname(__FILE__) .'/pdf.css'); $markup .= ''; - $markup .= ''; + $markup .= ''; $markup .= ''; $markup .= ''; - + break; case OUWIKI_FORMAT_HTML: // Do header @@ -118,29 +118,6 @@ } } -// // Original -// if (($treemode) && ($format == OUWIKI_FORMAT_HTML) ) { -// ouwiki_build_tree($index); -// // Print out in hierarchical form... -// print '
                '; -// $functionname = 'ouwiki_display_entirewiki_page_in_index'; -// print ouwiki_tree_index($functionname, reset($index)->pageid, $index, $subwiki, $cm, $context); -// print '
              '; - -// if ($orphans) { -// print '

              '.get_string('orphanpages', 'ouwiki').'

              '; -// print '
                '; -// foreach ($index as $indexitem) { -// if (count($indexitem->linksfrom) == 0 && $indexitem->title !== '') { -// $orphanindex = ouwiki_get_sub_tree_from_index($indexitem->pageid, $index); -// ouwiki_build_tree($orphanindex); -// print ouwiki_tree_index($functionname, $indexitem->pageid, $orphanindex, $subwiki, $cm, $context); -// } -// } -// print '
              '; -// } -// } else { - //If tree view specified. if (($treemode) && ($format == OUWIKI_FORMAT_HTML || $format == OUWIKI_FORMAT_PDF || $format == OUWIKI_FORMAT_HTML_PRINT) ) { @@ -170,8 +147,13 @@ if($format == OUWIKI_FORMAT_HTML) print $treeOutput; - if($format == OUWIKI_FORMAT_PDF || $format == OUWIKI_FORMAT_HTML_PRINT) + if($format == OUWIKI_FORMAT_PDF || $format == OUWIKI_FORMAT_HTML_PRINT) { + // begin fix + if($format == OUWIKI_FORMAT_PDF) + $treeOutput = replace_image_urls($context, $treeOutput, 0, true); + // end fix $markup .= $treeOutput; + } } else { foreach ($index as $pageinfo) { @@ -183,15 +165,15 @@ continue; } - + $output = get_online_display_content($format, $pageversion, $context, $subwiki, $cm, $index, $fs, $files); - + if($format == OUWIKI_FORMAT_HTML) print $output; - + if($format == OUWIKI_FORMAT_PDF || $format == OUWIKI_FORMAT_HTML_PRINT) $markup .= $output; - + if ($first) { $first = false; } @@ -246,25 +228,27 @@ break; case OUWIKI_FORMAT_HTML_PRINT: - + $markup .= ''; - + echo $markup; break; - + case OUWIKI_FORMAT_PDF: $markup .= ''; - + require_once($CFG->libdir . '/pdflib.php'); - + $doc = new pdf; $doc->setFont('helvetica'); $doc->setPrintHeader(false); $doc->setPrintFooter(false); $doc->AddPage(); $doc->writeHTML($markup); - $doc->Output(); - + $doc->Output(explode('.',$filename)[1].'.pdf'); //change string for different name + + clean_up($markup); + break; case OUWIKI_FORMAT_HTML: @@ -324,9 +308,7 @@ function get_online_display_content($format, $pageversion, $context, $subwiki, $ $markup .= ''; break; case OUWIKI_FORMAT_PDF || OUWIKI_FORMAT_HTML_PRINT: - //$markup .= '

              ' . htmlspecialchars($visibletitle) . '

              '; - //$markup .= trim($pageversion->xhtml); - //$markup .= '


              '; + $markup .= '

              ' . '

              ' . @@ -347,3 +334,58 @@ function get_online_display_content($format, $pageversion, $context, $subwiki, $ return $markup; } + + +/** + * @param $context + * @param $xhtml + * @param $itemId + * @param bool $treemode + * @return mixed + */ +function replace_image_urls($context, $xhtml, $itemId, $treemode = false) { + $content = $xhtml; + /*preg_match_all('##', $content, $matches);*/ + preg_match_all('##', $content, $matches); + + $fs = get_file_storage(); + $tmpdir = make_temp_directory('moodle_pdf_files'); + + if (! empty($matches)) { + // Extract the file names from the matches. + + foreach ($matches[1] as $key => $match) { + $urlinfo = pathinfo($match); + $image = urldecode($urlinfo['basename']); + + if($treemode){ + $tmp = explode('/', $urlinfo['dirname']); + $itemId = $tmp[sizeof($tmp) -1]; + } + + if (!$file = $fs->get_file($context->id, 'mod_ouwiki', 'content', $itemId, '/', $image)) + continue; + + $filename = $file->get_filename(); + $filepath = "$tmpdir/$filename"; + if (file_exists($filepath) || $file->copy_content_to($filepath)) { + $content = str_replace($match, $filepath, $content); + } + + } + } + return $content; +} + +/** + * Removes the temporary local image files used for creating the pdf + * @param $html + */ +function clean_up($html){ + preg_match_all('##', $html, $matches); + if (!empty($matches)) { + foreach ($matches[1] as $key => $filepath) { + unlink($filepath); + } + } +} diff --git a/lang/en/ouwiki.php b/lang/en/ouwiki.php index 7a99844..7ea2516 100644 --- a/lang/en/ouwiki.php +++ b/lang/en/ouwiki.php @@ -591,3 +591,8 @@ $string['ouwikicrontask'] = 'OU wiki maintenance jobs'; $string['tableofcontents'] = 'Table of contents'; +$string['printwiki'] = 'Print Wiki '; +$string['print_pdf_alphabetic'] = 'PDF (Alphabetic)'; +$string['print_pdf_tree_structure'] = 'PDF (Tree)'; +$string['print_html_alphabetic'] = 'HTML (Alphabetic)'; +$string['print_html_tree_structure'] = 'HTML (Tree)'; \ No newline at end of file diff --git a/renderer.php b/renderer.php index 4834054..4cca3ad 100644 --- a/renderer.php +++ b/renderer.php @@ -214,7 +214,7 @@ public function get_topheading_section($title, $gewgaws, $pageversion, $annotati global $CFG; require_once($CFG->dirroot.'/mod/ouwiki/tableofcontents.php'); $toc = new TableOfContents($pageversion->xhtml); - $output .= $toc->toHtml(); + $output .= $toc->to_html(); if ($gewgaws) { @@ -860,33 +860,32 @@ public function ouwiki_get_links_content() { return $url; }; - - - // Dropdown fuer Druckfunktion + + // Dropdown for print functions $output .= html_writer::start_tag('li', array('id' => 'ouwiki_nav_print')); $output .= html_writer::start_tag('div', array('class' => 'btn-group')); $output .= html_writer::start_tag('button', array('class' => 'btn dropdown-toggle', 'data-toggle' => 'dropdown')); - $output .= 'Wiki drucken '; + $output .= get_string('printwiki', 'ouwiki'); $output .= html_writer::tag('span', '', array('class' => 'caret')); $output .= html_writer::end_tag('button'); $output .= html_writer::start_tag('ul', array('class' => 'dropdown-menu')); $output .= html_writer::start_tag('li'); - $output .= html_writer::tag('a', 'PDF (Alphabetisch)', array('target' => '_blank', 'href' => $wikiParams(OUWIKI_FORMAT_PDF))); + $output .= html_writer::tag('a', get_string('print_pdf_alphabetic', 'ouwiki'), array('target' => '_blank', 'href' => $wikiParams(OUWIKI_FORMAT_PDF))); $output .= html_writer::end_tag('li'); $output .= html_writer::start_tag('li'); - $output .= html_writer::tag('a', 'PDF (Struktur)', array('target' => '_blank', 'href' => $wikiParams(OUWIKI_FORMAT_PDF, true))); + $output .= html_writer::tag('a', get_string('print_pdf_tree_structure', 'ouwiki'), array('target' => '_blank', 'href' => $wikiParams(OUWIKI_FORMAT_PDF, true))); $output .= html_writer::end_tag('li'); $output .= html_writer::start_tag('li'); - $output .= html_writer::tag('a', 'HTML (Alphabetisch)', array('target' => '_blank', 'href' => $wikiParams(OUWIKI_FORMAT_HTML_PRINT))); + $output .= html_writer::tag('a', get_string('print_html_alphabetic', 'ouwiki'), array('target' => '_blank', 'href' => $wikiParams(OUWIKI_FORMAT_HTML_PRINT))); $output .= html_writer::end_tag('li'); $output .= html_writer::start_tag('li'); - $output .= html_writer::tag('a', 'HTML (Struktur)', array('target' => '_blank', 'href' => $wikiParams(OUWIKI_FORMAT_HTML_PRINT, true))); + $output .= html_writer::tag('a', get_string('print_html_tree_structure', 'ouwiki'), array('target' => '_blank', 'href' => $wikiParams(OUWIKI_FORMAT_HTML_PRINT, true))); $output .= html_writer::end_tag('li'); $output .= html_writer::end_tag('ul'); diff --git a/styles.css b/styles.css index 71007d3..ae690d4 100644 --- a/styles.css +++ b/styles.css @@ -1004,3 +1004,18 @@ div#ouwiki_indexlinks > ul > li { display:inline } +/* this version seems better */ +ol.toc { + counter-reset: item; + padding: 5px; +} +li.toc_element > ol { + counter-reset: item; +} +li.toc_element { + display: block; +} +li.toc_element::before { + content: counters(item, ".") " "; + counter-increment: item; +} \ No newline at end of file diff --git a/tableofcontents.php b/tableofcontents.php index 8ba0c16..4e8e66f 100644 --- a/tableofcontents.php +++ b/tableofcontents.php @@ -15,255 +15,100 @@ // along with Moodle. If not, see . /** - * Version. + * Version 1.0 * * @package mod_ouwiki * @copyright 2016 The Open University - * @author Steffen Pegenau + * @author Joel Tschesche * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +class TableOfContents +{ -class TableOfContents { - // The table of contents is saved in a 6xn-Array - // 6:

              -

              - // n: the number of headings - private $ToC = array(array(array(array(array(array()))))); - private $reducedToC = null; + private $html = ""; + private $headings = array(); - private $html = ""; - - private $lastH1 = 0; - private $lastH2 = 0; - private $lastH3 = 0; - private $lastH4 = 0; - private $lastH5 = 0; - private $lastH6 = 0; - - private $lastLvl = 0; - private $minLvl = 0; - - public $numberOfHeadings; - - public function __construct($html) { - $this->html = $html; - $this->parseHtml($html); - $this->setMinLvl(); - } - - /* - * returns the table of contents as printable html - */ - public function toHtml() { - // No headings => no reason for a table of contents - if($this->numberOfHeadings < 1) { - return ""; + public function __construct($html) { + $this->html = $html; + $this->parse_html($html); + $this->set_min_lvl(); } - $toc = $this->ToC; - //echo "
              " . print_r($toc, true) . "
              "; - $output = PHP_EOL . "

              " . get_string('tableofcontents', 'ouwiki') . "

              " . PHP_EOL; - - // Helps building the nested
                -elements - $lastlvl = 0; - - foreach($toc as $h1 => $h2tree) { - foreach($h2tree as $h2 => $h3tree) { - foreach($h3tree as $h3 => $h4tree) { - foreach($h4tree as $h4 => $h5tree) { - foreach($h5tree as $h5 => $h6tree) { - foreach($h6tree as $h6 => $obj) { - if($obj) { - // Get the chapter number, for example 1.2.3 - $h = array($h1, $h2, $h3, $h4, $h5, $h6); - $chapterNumber = $this->getChapterNumber($h); - - // Get the level, for this example 3 - $currentLvl = $this->getLvlByChapterNumber($chapterNumber); - - // The elements heading - $element = '
              • '.$chapterNumber." ".$obj->name .'
              • ' . PHP_EOL; - - // New nested
                  - if($currentLvl > $lastlvl) { - $output .= str_repeat("
                    " . PHP_EOL, $currentLvl - $lastlvl); - $output .= $element; - } - // Close as many
                      as necessary - elseif ($currentLvl < $lastlvl) { - $output .= str_repeat("
                    " . PHP_EOL, $lastlvl - $currentLvl); - $output .= $element; - } - // Same level, just add
                  • - else { - $output .= $element; - } - - // Set helper - $lastlvl = $currentLvl; - } - } - } - } + /** + * returns the table of contents as printable html + */ + public function to_html() { + // No headings => no reason for a table of contents. + if (count($this->headings) < 1) { + return ""; } - } - } - - $output .= str_repeat("
                  " . PHP_EOL, $lastlvl); - return $output; - } - /** - * Returns the headings level by the chapter number - * - * For example: 1.2.3 => 3 - * 1.3 => 2 - * @param string $n The chapter number - * @return int The headings lvel - */ - private function getLvlByChapterNumber($n) { - $e = explode('.', $n); - return count($e); - } + $output = PHP_EOL . "

                  " . get_string('tableofcontents', 'ouwiki') . "

                  " . PHP_EOL; + $lastlvl = 0; - /** - * Sets the minimum level of headings - * - * If there are only

                  and

                  headings the minlvl is 2 - */ - private function setMinLvl() { - $reducedToC = $this->ToC; - while(!isset($reducedToC[1]) && isset($reducedToC[0])) { - $reducedToC = $reducedToC[0]; - $this->minLvl++; - } - } + foreach ($this->headings as $heading) { - /** - * Generates the chapter number for a heading, for example "1.0.2" - * @param array $h An array of alle heading numbers - * @return string The chapter number - */ - private function getChapterNumber($h) { - $number = ""; + if ($lastlvl == 0) { + $output .= '
                    '; + } else if ($heading->lvl > $lastlvl) { + $output .= '
                      '; + } else { + $output .= str_repeat('
                    ', $lastlvl - $heading->lvl); + $output .= ''; + } + $output .= '
                  1. ' . $heading->name . ''; - // Generate full number with unnecessary zeros and dots - // Example: 1.2.0.0.0.0 - for($i = 0; $i < 6; $i++) { - $number .= $h[$i] . '.'; + $lastlvl = $heading->lvl; + } + $output .= str_repeat('
                  ' . PHP_EOL, $lastlvl); + return $output; } - $str = ""; - $bool = true; - - // Deletes unnecessary dots and zeros from the right side - // Example: 1.2.0.0.0.0 becomes 1.2 - while($bool) { - $str = rtrim($number, '.'); - $str = rtrim($str, '0'); - $bool = ($str !== $number) ? true : false; - $number = $str; + /** + * Sets the minimum level of headings + * + * If there are only

                  and

                  headings the minlvl is 2 + */ + private function set_min_lvl() { + $lvls = array(); + foreach ($this->headings as $heading) { + $lvls[] = $heading->lvl; + } + $min = min($lvls); + foreach ($this->headings as $heading) { + $heading->lvl = $heading->lvl - $min + 1; + } } - $str = rtrim($number, '.'); - - return substr($str, 2*$this->minLvl); - } - - /* - * Parses the html-Code and generates the table of contents - * - * @param String $html The html-snippet to parse - */ - private function parseHtml($html) { - $dom = new DOMDocument(); - $dom->loadHTML('' . $html); - - // Get all Headings - $xpath = new DOMXPath($dom); - $query = '//h1 | //h2 | //h3 | //h4 | //h5 | //h6 | //H1 | //H2 | //H3 | //H4 | //H5 | //H6'; - $headings = $xpath->query($query); - - $this->numberOfHeadings = $headings->length; - - if($headings->length > 0 ) { - foreach ($headings as $heading) { - // Get Heading level:

                  => 6 - $lvl = substr($heading->tagName, 1); - - $childNodes = $heading->childNodes; - for($i = 0; $i < $childNodes->length; $i++) { - $node = $childNodes->item($i); - if(isset($node->tagName)) { - $heading->removeChild($node); + /** + * Parses the html-Code and generates the table of contents + * + * @param String $html The html-snippet to parse + */ + private function parse_html($html) { + $dom = new DOMDocument(); + $dom->loadHTML('' . $html); + + // Get all Headings. + $xpath = new DOMXPath($dom); + $query = '//h1 | //h2 | //h3 | //h4 | //h5 | //h6 | //H1 | //H2 | //H3 | //H4 | //H5 | //H6'; + $headings = $xpath->query($query); + + if ($headings->length > 0) { + foreach ($headings as $heading) { + // Get Heading level:
                  => 6. + $lvl = substr($heading->tagName, 1); + + $attributes = $heading->attributes; + $id = $attributes->getNamedItem('id')->value; + + $element = new stdClass(); + $element->name = $heading->nodeValue; + $element->id = $id; + // Set the lvl to 3 if lvl < 3, as all headings <= 3 are treated as section headings. + $element->lvl = $lvl < 3 ? 3: $lvl; + $this->headings[] = $element; } } - - - // Get id: - //

                  => ouw_s0_0 - $attributes = $heading->attributes; - $id = $attributes->getNamedItem('id')->value; - - // Add heading to data structure - $this->addToTree($lvl, $heading->nodeValue, $id); - } - } - } - - /** - * Adds an entry with name and level to the table of contents - * - * param int $lvl The level of the heading - * param string $name The title of the heading - * param string $id html attribute id of heading - */ - private function addToTree($lvl, $name, $id) { - if($lvl < $this->lastLvl) { - $lvlToDelete = $lvl + 1; - switch($lvlToDelete) { - case 1: - $this->lastH1 = 0; - case 2: - $this->lastH2 = 0; - case 3: - $this->lastH3 = 0; - case 4: - $this->lastH4 = 0; - case 5: - $this->lastH5 = 0; - case 6: - $this->lastH6 = 0; - break; - } } - - switch ($lvl) { - case 1: - ++$this->lastH1; - break; - case 2: - ++$this->lastH2; - break; - case 3: - ++$this->lastH3; - break; - case 4: - ++$this->lastH4; - break; - case 5: - ++$this->lastH5; - break; - case 6: - ++$this->lastH6; - break; - } - $element = new stdClass(); - $element->name = $name; - $element->id = $id; - - // Save element in array - $this->ToC[$this->lastH1][$this->lastH2][$this->lastH3][$this->lastH4][$this->lastH5][$this->lastH6] = $element; - - $this->lastLvl = $lvl; - } } From 023ff0d7073a56b75a9301e43577649080f59d5f Mon Sep 17 00:00:00 2001 From: hecatesBrain Date: Mon, 8 Jul 2019 11:09:22 +0200 Subject: [PATCH 20/30] Add .travis.yml --- .travis.yml | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..17e4d57 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,117 @@ +# This is the language of our project. +language: php + +# If using Behat, then this should be true due to an issue with Travis CI. +# If not using Behat, recommended to use `sudo: false` as it is faster. +sudo: false + +# Installs the required version of Firefox for Behat, an updated version +# of PostgreSQL and extra APT packages. Java 8 is only required +# for Mustache command. +addons: + firefox: "47.0.1" + postgresql: "9.4" + apt: + packages: + - openjdk-8-jre-headless + +# Cache NPM's and Composer's caches to speed up build times. +cache: + directories: + - $HOME/.composer/cache + - $HOME/.npm + +# Determines which versions of PHP to test our project against. Each version +# listed here will create a separate build and run the tests against that +# version of PHP. +php: + - 7.0 + - 7.1 + - 7.2 + +# This section sets up the environment variables for the build. +env: + global: + # This line determines which version of Moodle to test against. + - MOODLE_BRANCH=MOODLE_35_STABLE + - MOODLE_BRANCH=MOODLE_36_STABLE + - MOODLE_BRANCH=MOODLE_37_STABLE + # Ignoring sadly does not work for grunt tasks according to https://docs.moodle.org/dev/Travis_integration#Ignoring_files ... + #- IGNORE_PATHS= + # This matrix is used for testing against multiple databases. So for + # each version of PHP being tested, one build will be created for each + # database listed here. + matrix: + - DB=pgsql + - DB=mysqli + +# This lists steps that are run before the installation step. +before_install: + # This disables XDebug which should speed up the build. + - phpenv config-rm xdebug.ini + # This installs NodeJS which is used by Grunt, etc. + - nvm install 8.9 + - nvm use 8.9 + # Currently we are inside of the clone of your repository. We move up two + # directories to build the project. + - cd ../.. + # Install this project into a directory called "ci". + - composer create-project -n --no-dev --prefer-dist blackboard-open-source/moodle-plugin-ci ci ^2 + # Update the $PATH so scripts from this project can be called easily. + - export PATH="$(cd ci/bin; pwd):$(cd ci/vendor/bin; pwd):$PATH" + +# This lists steps that are run for installation and setup. +install: + # Run the default install. The overview of what this does: + # - Clone the Moodle project into a directory called moodle. + # - Create a data directory called moodledata. + # - Create Moodle config.php, database, etc. + # - Copy your plugin(s) into Moodle. + # - Run Composer install within Moodle. + # - Run NPM install in Moodle and in your plugin if it has a "package.json". + # - Run "grunt ignorefiles" within Moodle to update ignore file lists. + # - If your plugin has Behat features, then Behat will be setup. + # - If your plugin has unit tests, then PHPUnit will be setup. + - moodle-plugin-ci install + +# This lists steps that are run for the purposes of testing. Any of +# these steps can be re-ordered or removed to your liking. And of +# course, you can add any of your own custom steps. +script: + # This step lints your PHP files to check for syntax errors. + - moodle-plugin-ci phplint + # This step runs the PHP Copy/Paste Detector on your plugin. + # This helps to find code duplication. + - moodle-plugin-ci phpcpd + # This step runs the PHP Mess Detector on your plugin. This helps to find + # potential problems with your code which can result in + # refactoring opportunities. + - moodle-plugin-ci phpmd + # This step runs the Moodle Code Checker to make sure that your plugin + # conforms to the Moodle coding standards. It is highly recommended + # that you keep this step. + - moodle-plugin-ci codechecker + # This step runs some light validation on the plugin file structure + # and code. Validation can be plugin specific. + - moodle-plugin-ci validate + # This step validates your plugin's upgrade steps. + - moodle-plugin-ci savepoints + # This step validates the HTML and Javascript in your Mustache templates. + - moodle-plugin-ci mustache + # This step runs Grunt tasks on the plugin. By default, it tries to run + # tasks relevant to your plugin and Moodle version, but you can run + # specific tasks by passing them as options, + # EG: moodle-plugin-ci grunt -t task1 -t task2 + #- moodle-plugin-ci grunt -t eslint:amd -t uglify:amd # Do not run stylelint:css because third party css files cannot be ignored + - moodle-plugin-ci grunt + # This step runs the PHPUnit tests of your plugin. If your plugin has + # PHPUnit tests, then it is highly recommended that you keep this step. + - moodle-plugin-ci phpunit + # This step runs the Behat tests of your plugin. If your plugin has + # Behat tests, then it is highly recommended that you keep this step. + # There are two important options that you may want to use: + # - The auto rerun option allows you to rerun failures X number of times, + # default is 2, EG usage: --auto-rerun 3 + # - The dump option allows you to print the failure HTML to the console, + # handy for debugging, EG usage: --dump + - moodle-plugin-ci behat From bb09752063e9e2f8e4e9d802bf7a86e6e170a8d4 Mon Sep 17 00:00:00 2001 From: hecatesBrain Date: Mon, 8 Jul 2019 11:24:54 +0200 Subject: [PATCH 21/30] Add style directory. --- entirewiki.php | 2 +- pdf.css => style/pdf.css | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename pdf.css => style/pdf.css (100%) diff --git a/entirewiki.php b/entirewiki.php index 8ec28e8..d705842 100644 --- a/entirewiki.php +++ b/entirewiki.php @@ -88,7 +88,7 @@ case OUWIKI_FORMAT_PDF: $markup = ''; - $css = file_get_contents(dirname(__FILE__) .'/pdf.css'); + $css = file_get_contents(dirname(__FILE__) .'/style/pdf.css'); $markup .= ''; $markup .= ''; $markup .= ''; diff --git a/pdf.css b/style/pdf.css similarity index 100% rename from pdf.css rename to style/pdf.css From 1f350df321f121b00dabd745c1bc53edf117085c Mon Sep 17 00:00:00 2001 From: hecatesBrain Date: Wed, 10 Jul 2019 13:45:21 +0200 Subject: [PATCH 22/30] Change directory for pdf images --- entirewiki.php | 119 ++++++++++++++++++++++++-------------------- renderer.php | 4 +- tableofcontents.php | 9 ++-- 3 files changed, 71 insertions(+), 61 deletions(-) diff --git a/entirewiki.php b/entirewiki.php index d705842..8e09639 100644 --- a/entirewiki.php +++ b/entirewiki.php @@ -24,7 +24,7 @@ */ require_once(dirname(__FILE__) . '/../../config.php'); -require($CFG->dirroot.'/mod/ouwiki/basicpage.php'); +require($CFG->dirroot . '/mod/ouwiki/basicpage.php'); $id = required_param('id', PARAM_INT); // Course Module ID $pagename = optional_param('page', '', PARAM_TEXT); @@ -55,13 +55,13 @@ $format = required_param('format', PARAM_ALPHA); if ($format !== OUWIKI_FORMAT_HTML && $format !== OUWIKI_FORMAT_PDF - && $format !== OUWIKI_FORMAT_TEMPLATE && $format !== OUWIKI_FORMAT_HTML_PRINT) { + && $format !== OUWIKI_FORMAT_TEMPLATE && $format !== OUWIKI_FORMAT_HTML_PRINT) { print_error('Unexpected format'); } // Get basic wiki details for filename -$filename = $course->shortname.'.'.$ouwiki->name; -$filename = preg_replace('/[^A-Za-z0-9.-]/' , '_', $filename); +$filename = $course->shortname . '.' . $ouwiki->name; +$filename = preg_replace('/[^A-Za-z0-9.-]/', '_', $filename); $markup = ''; $fs = null; @@ -74,21 +74,21 @@ break; case OUWIKI_FORMAT_HTML_PRINT: - $url_object_array = $PAGE->theme->css_urls($PAGE); - $url_object = $url_object_array[0]; - $css_url = $url_object->out(); + $url_object_array = $PAGE->theme->css_urls($PAGE); + $url_object = $url_object_array[0]; + $css_url = $url_object->out(); - $markup = ''; - $markup .= ''; - $markup .= ''; - $markup .= ''; - $markup .= ''; + $markup = ''; + $markup .= ''; + $markup .= ''; + $markup .= ''; + $markup .= ''; - break; + break; case OUWIKI_FORMAT_PDF: - $markup = ''; - $css = file_get_contents(dirname(__FILE__) .'/style/pdf.css'); + $markup = ''; + $css = file_get_contents(dirname(__FILE__) . '/style/pdf.css'); $markup .= ''; $markup .= ''; $markup .= ''; @@ -120,7 +120,7 @@ //If tree view specified. -if (($treemode) && ($format == OUWIKI_FORMAT_HTML || $format == OUWIKI_FORMAT_PDF || $format == OUWIKI_FORMAT_HTML_PRINT) ) { +if (($treemode) && ($format == OUWIKI_FORMAT_HTML || $format == OUWIKI_FORMAT_PDF || $format == OUWIKI_FORMAT_HTML_PRINT)) { ouwiki_build_tree($index); // Print out in hierarchical form... @@ -132,7 +132,7 @@ $treeOutput .= '

                '; if ($orphans) { - $treeOutput .= '

                '.get_string('orphanpages', 'ouwiki').'

                '; + $treeOutput .= '

                ' . get_string('orphanpages', 'ouwiki') . '

                '; $treeOutput .= '
                  '; foreach ($index as $indexitem) { if (count($indexitem->linksfrom) == 0 && $indexitem->title !== '') { @@ -144,20 +144,21 @@ $treeOutput .= '
                '; } - if($format == OUWIKI_FORMAT_HTML) + if ($format == OUWIKI_FORMAT_HTML) print $treeOutput; - if($format == OUWIKI_FORMAT_PDF || $format == OUWIKI_FORMAT_HTML_PRINT) { - // begin fix - if($format == OUWIKI_FORMAT_PDF) + if ($format == OUWIKI_FORMAT_PDF || $format == OUWIKI_FORMAT_HTML_PRINT) { + + if ($format == OUWIKI_FORMAT_PDF) { $treeOutput = replace_image_urls($context, $treeOutput, 0, true); - // end fix + } + $markup .= $treeOutput; } } else { foreach ($index as $pageinfo) { - if (count($pageinfo->linksfrom)!= 0 || $pageinfo->title === '') { + if (count($pageinfo->linksfrom) != 0 || $pageinfo->title === '') { // Get page details. $pageversion = ouwiki_get_current_page($subwiki, $pageinfo->title); // If the page hasn't really been created yet, skip it. @@ -168,11 +169,11 @@ $output = get_online_display_content($format, $pageversion, $context, $subwiki, $cm, $index, $fs, $files); - if($format == OUWIKI_FORMAT_HTML) - print $output; + if ($format == OUWIKI_FORMAT_HTML) + print $output; - if($format == OUWIKI_FORMAT_PDF || $format == OUWIKI_FORMAT_HTML_PRINT) - $markup .= $output; + if ($format == OUWIKI_FORMAT_PDF || $format == OUWIKI_FORMAT_HTML_PRINT) + $markup .= $output; if ($first) { $first = false; @@ -182,9 +183,9 @@ if ($orphans) { if ($format == OUWIKI_FORMAT_HTML) { - print '

                '.get_string('orphanpages', 'ouwiki').'

                '; + print '

                ' . get_string('orphanpages', 'ouwiki') . '

                '; } else if ($format != OUWIKI_FORMAT_TEMPLATE) { - $markup .= '

                '.get_string('orphanpages', 'ouwiki').'

                '; + $markup .= '

                ' . get_string('orphanpages', 'ouwiki') . '

                '; } foreach ($index as $indexitem) { @@ -229,10 +230,10 @@ case OUWIKI_FORMAT_HTML_PRINT: - $markup .= ''; + $markup .= ''; - echo $markup; - break; + echo $markup; + break; case OUWIKI_FORMAT_PDF: $markup .= ''; @@ -245,7 +246,7 @@ $doc->setPrintFooter(false); $doc->AddPage(); $doc->writeHTML($markup); - $doc->Output(explode('.',$filename)[1].'.pdf'); //change string for different name + $doc->Output(explode('.', $filename)[1] . '.pdf'); //change string for different name clean_up($markup); @@ -256,13 +257,14 @@ break; } -function get_online_display_content($format, $pageversion, $context, $subwiki, $cm, $index, $fs, &$files) { +function get_online_display_content($format, $pageversion, $context, $subwiki, $cm, $index, $fs, &$files) +{ $markup = ''; $visibletitle = $pageversion->title === '' ? get_string('startpage', 'ouwiki') : $pageversion->title; if ($format != OUWIKI_FORMAT_TEMPLATE) { $pageversion->xhtml = file_rewrite_pluginfile_urls($pageversion->xhtml, 'pluginfile.php', - $context->id, 'mod_ouwiki', 'content', $pageversion->versionid); + $context->id, 'mod_ouwiki', 'content', $pageversion->versionid); } switch ($format) { @@ -275,25 +277,25 @@ function get_online_display_content($format, $pageversion, $context, $subwiki, $ $markup .= '' . $pageversion->versionid . ''; // Copy images found in content. preg_match_all('##', $pageversion->xhtml, $matches); - if (! empty($matches)) { + if (!empty($matches)) { // Extract the file names from the matches. foreach ($matches[1] as $key => $match) { // Get file name and copy to zip. $match = urldecode($match); // Copy image - on fail swap tag with string. if ($file = $fs->get_file($context->id, 'mod_ouwiki', 'content', - $pageversion->versionid, '/', $match)) { + $pageversion->versionid, '/', $match)) { $files["/$pageversion->versionid/$match/"] = $file; } else { $pageversion->xhtml = str_replace($matches[0][$key], $brokenimagestr, - $pageversion->xhtml); + $pageversion->xhtml); } } } $markup .= '' . htmlspecialchars($pageversion->xhtml) . ''; // Add attachments. if ($attachments = $fs->get_area_files($context->id, 'mod_ouwiki', 'attachment', - $pageversion->versionid, 'itemid', false)) { + $pageversion->versionid, 'itemid', false)) { // We have attachements. $markup .= ''; $attachmentsarray = array(); @@ -311,21 +313,20 @@ function get_online_display_content($format, $pageversion, $context, $subwiki, $ $markup .= '

                ' . - '' . htmlspecialchars($visibletitle) . '

                '; + '' . htmlspecialchars($visibletitle) . '

              '; $markup .= ouwiki_convert_content($pageversion->xhtml, $subwiki, $cm, $index, $pageversion->xhtmlformat); $markup .= '
              '; - // begin fix - if($format === OUWIKI_FORMAT_PDF) + if ($format === OUWIKI_FORMAT_PDF) { $markup = replace_image_urls($context, $markup, $pageversion->versionid); - // end fix + } break; case OUWIKI_FORMAT_HTML: print '

              ' . - '' . htmlspecialchars($visibletitle) . '

              '; + '' . htmlspecialchars($visibletitle) . '

              '; print ouwiki_convert_content($pageversion->xhtml, $subwiki, $cm, $index, $pageversion->xhtmlformat); print '
              '; break; @@ -343,28 +344,29 @@ function get_online_display_content($format, $pageversion, $context, $subwiki, $ * @param bool $treemode * @return mixed */ -function replace_image_urls($context, $xhtml, $itemId, $treemode = false) { +function replace_image_urls($context, $xhtml, $itemId, $treemode = false) +{ $content = $xhtml; - /*preg_match_all('##', $content, $matches);*/ preg_match_all('##', $content, $matches); $fs = get_file_storage(); - $tmpdir = make_temp_directory('moodle_pdf_files'); + $tmpdir = create_dir(dirname(__FILE__) . '/pdf_images'); - if (! empty($matches)) { + if (!empty($matches)) { // Extract the file names from the matches. foreach ($matches[1] as $key => $match) { $urlinfo = pathinfo($match); $image = urldecode($urlinfo['basename']); - if($treemode){ + if ($treemode) { $tmp = explode('/', $urlinfo['dirname']); - $itemId = $tmp[sizeof($tmp) -1]; + $itemId = $tmp[sizeof($tmp) - 1]; } - if (!$file = $fs->get_file($context->id, 'mod_ouwiki', 'content', $itemId, '/', $image)) + if (!$file = $fs->get_file($context->id, 'mod_ouwiki', 'content', $itemId, '/', $image)) { continue; + } $filename = $file->get_filename(); $filepath = "$tmpdir/$filename"; @@ -377,11 +379,20 @@ function replace_image_urls($context, $xhtml, $itemId, $treemode = false) { return $content; } +function create_dir($path) +{ + if (!file_exists(dirname(__FILE__) . '/pdf_images')) { + mkdir(dirname(__FILE__) . '/pdf_images', 0777, true); + } + return $path; +} + /** * Removes the temporary local image files used for creating the pdf * @param $html */ -function clean_up($html){ +function clean_up($html) +{ preg_match_all('##', $html, $matches); if (!empty($matches)) { foreach ($matches[1] as $key => $filepath) { diff --git a/renderer.php b/renderer.php index 4cca3ad..f39f799 100644 --- a/renderer.php +++ b/renderer.php @@ -210,7 +210,7 @@ public function get_topheading_section($title, $gewgaws, $pageversion, $annotati $output .= html_writer::tag('h2', format_string($title), array('class' => 'ouw_topheading')); - // Add table of contents + // Add table of contents. global $CFG; require_once($CFG->dirroot.'/mod/ouwiki/tableofcontents.php'); $toc = new TableOfContents($pageversion->xhtml); @@ -861,7 +861,7 @@ public function ouwiki_get_links_content() { return $url; }; - // Dropdown for print functions + // Dropdown for print functions. $output .= html_writer::start_tag('li', array('id' => 'ouwiki_nav_print')); $output .= html_writer::start_tag('div', array('class' => 'btn-group')); diff --git a/tableofcontents.php b/tableofcontents.php index 4e8e66f..821e1a6 100644 --- a/tableofcontents.php +++ b/tableofcontents.php @@ -35,7 +35,7 @@ public function __construct($html) { } /** - * returns the table of contents as printable html + * returns the table of contents as printable html. */ public function to_html() { // No headings => no reason for a table of contents. @@ -65,9 +65,8 @@ public function to_html() { } /** - * Sets the minimum level of headings + * Sets the minimum level of headings. * - * If there are only

              and

              headings the minlvl is 2 */ private function set_min_lvl() { $lvls = array(); @@ -81,9 +80,9 @@ private function set_min_lvl() { } /** - * Parses the html-Code and generates the table of contents + * Parses the html-Code and generates the table of contents. * - * @param String $html The html-snippet to parse + * @param String $html The html-snippet to parse. */ private function parse_html($html) { $dom = new DOMDocument(); From b58a03aa72d5c41154186c3e84e10c8209341ead Mon Sep 17 00:00:00 2001 From: hecatesBrain Date: Wed, 10 Jul 2019 14:53:36 +0200 Subject: [PATCH 23/30] Update create_dir method --- .travis.yml | 2 +- entirewiki.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 17e4d57..bf8302b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,7 +37,7 @@ env: - MOODLE_BRANCH=MOODLE_36_STABLE - MOODLE_BRANCH=MOODLE_37_STABLE # Ignoring sadly does not work for grunt tasks according to https://docs.moodle.org/dev/Travis_integration#Ignoring_files ... - #- IGNORE_PATHS= + - IGNORE_PATHS= ^(?!entirewiki\.php|tableofcontents\.php|renderer\.php)(.*) # This matrix is used for testing against multiple databases. So for # each version of PHP being tested, one build will be created for each # database listed here. diff --git a/entirewiki.php b/entirewiki.php index 8e09639..0dc596b 100644 --- a/entirewiki.php +++ b/entirewiki.php @@ -381,8 +381,8 @@ function replace_image_urls($context, $xhtml, $itemId, $treemode = false) function create_dir($path) { - if (!file_exists(dirname(__FILE__) . '/pdf_images')) { - mkdir(dirname(__FILE__) . '/pdf_images', 0777, true); + if (!file_exists($path)) { + mkdir($path, 0777, true); } return $path; } From 12967486851ea1ea19693c289b250dd37bd4d94e Mon Sep 17 00:00:00 2001 From: hecatesBrain Date: Wed, 17 Jul 2019 11:48:53 +0200 Subject: [PATCH 24/30] Update .travis.yml IGNORE_PATHS --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index bf8302b..bd1e8dd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,7 +37,7 @@ env: - MOODLE_BRANCH=MOODLE_36_STABLE - MOODLE_BRANCH=MOODLE_37_STABLE # Ignoring sadly does not work for grunt tasks according to https://docs.moodle.org/dev/Travis_integration#Ignoring_files ... - - IGNORE_PATHS= ^(?!entirewiki\.php|tableofcontents\.php|renderer\.php)(.*) + - IGNORE_PATHS=backup,classes,db,internaldoc,lang,pix,style,tests,yui,annotate.php,annotate_form.php,basicpage.phpconfirmlock.php,confirmloggedin.php,csv_writer,delete.php,diff.php,difflib.php,edit.php,edit_form.php,feed-history.php,feed-wikihistory.php,hideannotations.php,history.php,import.php,import_form.php,index.php,locallib.php,lock.php,mod_form.php,module.js,nojslock.php,override.php,participation_table.php,revert.php,savegrades.php,search.php,style.css,userparticipation.php,version.php,view.php,viewold.php,wkihistory.php,wikiindex.php # This matrix is used for testing against multiple databases. So for # each version of PHP being tested, one build will be created for each # database listed here. From 3a40b2814239cc99b6dadc9154fe38096e62ea30 Mon Sep 17 00:00:00 2001 From: hecatesBrain Date: Wed, 17 Jul 2019 12:22:29 +0200 Subject: [PATCH 25/30] Fix style errors --- .travis.yml | 6 ++-- entirewiki.php | 68 ++++++++++++++++++++++----------------------- renderer.php | 54 +++++++++++++++++------------------ tableofcontents.php | 2 +- 4 files changed, 63 insertions(+), 67 deletions(-) diff --git a/.travis.yml b/.travis.yml index bd1e8dd..22fea9a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,7 +37,7 @@ env: - MOODLE_BRANCH=MOODLE_36_STABLE - MOODLE_BRANCH=MOODLE_37_STABLE # Ignoring sadly does not work for grunt tasks according to https://docs.moodle.org/dev/Travis_integration#Ignoring_files ... - - IGNORE_PATHS=backup,classes,db,internaldoc,lang,pix,style,tests,yui,annotate.php,annotate_form.php,basicpage.phpconfirmlock.php,confirmloggedin.php,csv_writer,delete.php,diff.php,difflib.php,edit.php,edit_form.php,feed-history.php,feed-wikihistory.php,hideannotations.php,history.php,import.php,import_form.php,index.php,locallib.php,lock.php,mod_form.php,module.js,nojslock.php,override.php,participation_table.php,revert.php,savegrades.php,search.php,style.css,userparticipation.php,version.php,view.php,viewold.php,wkihistory.php,wikiindex.php + - IGNORE_PATHS=backup,classes,db,internaldoc,lang,pix,style,tests,yui,annotate.php,annotate_form.php,basicpage.php,confirmlock.php,confirmloggedin.php,csv_writer,delete.php,diff.php,difflib.php,edit.php,edit_form.php,feed-history.php,feed-wikihistory.php,hideannotations.php,history.php,import.php,import_form.php,index.php,lib.php,locallib.php,lock.php,mod_form.php,module.js,nojslock.php,override.php,participation.php,participation_table.php,revert.php,savegrades.php,search.php,style.css,userparticipation.php,version.php,view.php,viewold.php,wkihistory.php,wikiindex.php # This matrix is used for testing against multiple databases. So for # each version of PHP being tested, one build will be created for each # database listed here. @@ -106,7 +106,7 @@ script: - moodle-plugin-ci grunt # This step runs the PHPUnit tests of your plugin. If your plugin has # PHPUnit tests, then it is highly recommended that you keep this step. - - moodle-plugin-ci phpunit + #- moodle-plugin-ci phpunit # This step runs the Behat tests of your plugin. If your plugin has # Behat tests, then it is highly recommended that you keep this step. # There are two important options that you may want to use: @@ -114,4 +114,4 @@ script: # default is 2, EG usage: --auto-rerun 3 # - The dump option allows you to print the failure HTML to the console, # handy for debugging, EG usage: --dump - - moodle-plugin-ci behat + #- moodle-plugin-ci behat diff --git a/entirewiki.php b/entirewiki.php index 0dc596b..a35fe26 100644 --- a/entirewiki.php +++ b/entirewiki.php @@ -26,7 +26,7 @@ require_once(dirname(__FILE__) . '/../../config.php'); require($CFG->dirroot . '/mod/ouwiki/basicpage.php'); -$id = required_param('id', PARAM_INT); // Course Module ID +$id = required_param('id', PARAM_INT); // Course Module ID. $pagename = optional_param('page', '', PARAM_TEXT); $filesexist = optional_param('filesexist', 0, PARAM_INT); @@ -38,7 +38,7 @@ print_error('invalidcoursemodule'); } - // Checking course instance + // Checking course instance. $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); if (!$ouwiki = $DB->get_record('ouwiki', array('id' => $cm->instance))) { @@ -59,7 +59,7 @@ print_error('Unexpected format'); } -// Get basic wiki details for filename +// Get basic wiki details for filename. $filename = $course->shortname . '.' . $ouwiki->name; $filename = preg_replace('/[^A-Za-z0-9.-]/', '_', $filename); @@ -74,13 +74,13 @@ break; case OUWIKI_FORMAT_HTML_PRINT: - $url_object_array = $PAGE->theme->css_urls($PAGE); - $url_object = $url_object_array[0]; - $css_url = $url_object->out(); + $urlobjectarray = $PAGE->theme->css_urls($PAGE); + $urlobject = $urlobjectarray[0]; + $cssurl = $urlobject->out(); $markup = ''; $markup .= ''; - $markup .= ''; + $markup .= ''; $markup .= ''; $markup .= ''; @@ -96,7 +96,7 @@ break; case OUWIKI_FORMAT_HTML: - // Do header + // Do header. echo $ouwikioutput->ouwiki_print_start($ouwiki, $cm, $course, $subwiki, get_string('entirewiki', 'ouwiki'), $context, null, false, true); print '
              '; break; @@ -119,41 +119,42 @@ } -//If tree view specified. +// If tree view specified. if (($treemode) && ($format == OUWIKI_FORMAT_HTML || $format == OUWIKI_FORMAT_PDF || $format == OUWIKI_FORMAT_HTML_PRINT)) { ouwiki_build_tree($index); // Print out in hierarchical form... - $treeOutput = '
                '; + $treeoutput = '
                  '; $functionname = 'ouwiki_display_entirewiki_page_in_index'; - $treeOutput .= ouwiki_tree_index($functionname, reset($index)->pageid, $index, $subwiki, $cm, $context); - $treeOutput .= '
                '; + $treeoutput .= ouwiki_tree_index($functionname, reset($index)->pageid, $index, $subwiki, $cm, $context); + $treeoutput .= '
              '; if ($orphans) { - $treeOutput .= '

              ' . get_string('orphanpages', 'ouwiki') . '

              '; - $treeOutput .= '
                '; + $treeoutput .= '

                ' . get_string('orphanpages', 'ouwiki') . '

                '; + $treeoutput .= '
                  '; foreach ($index as $indexitem) { if (count($indexitem->linksfrom) == 0 && $indexitem->title !== '') { $orphanindex = ouwiki_get_sub_tree_from_index($indexitem->pageid, $index); ouwiki_build_tree($orphanindex); - $treeOutput .= ouwiki_tree_index($functionname, $indexitem->pageid, $orphanindex, $subwiki, $cm, $context); + $treeoutput .= ouwiki_tree_index($functionname, $indexitem->pageid, $orphanindex, $subwiki, $cm, $context); } } - $treeOutput .= '
                '; + $treeoutput .= '
              '; } - if ($format == OUWIKI_FORMAT_HTML) - print $treeOutput; + if ($format == OUWIKI_FORMAT_HTML) { + print $treeoutput; + } if ($format == OUWIKI_FORMAT_PDF || $format == OUWIKI_FORMAT_HTML_PRINT) { if ($format == OUWIKI_FORMAT_PDF) { - $treeOutput = replace_image_urls($context, $treeOutput, 0, true); + $treeoutput = replace_image_urls($context, $treeoutput, 0, true); } - $markup .= $treeOutput; + $markup .= $treeoutput; } } else { @@ -169,11 +170,13 @@ $output = get_online_display_content($format, $pageversion, $context, $subwiki, $cm, $index, $fs, $files); - if ($format == OUWIKI_FORMAT_HTML) + if ($format == OUWIKI_FORMAT_HTML) { print $output; + } - if ($format == OUWIKI_FORMAT_PDF || $format == OUWIKI_FORMAT_HTML_PRINT) + if ($format == OUWIKI_FORMAT_PDF || $format == OUWIKI_FORMAT_HTML_PRINT) { $markup .= $output; + } if ($first) { $first = false; @@ -246,7 +249,7 @@ $doc->setPrintFooter(false); $doc->AddPage(); $doc->writeHTML($markup); - $doc->Output(explode('.', $filename)[1] . '.pdf'); //change string for different name + $doc->Output(explode('.', $filename)[1] . '.pdf'); clean_up($markup); @@ -257,8 +260,7 @@ break; } -function get_online_display_content($format, $pageversion, $context, $subwiki, $cm, $index, $fs, &$files) -{ +function get_online_display_content($format, $pageversion, $context, $subwiki, $cm, $index, $fs, &$files) { $markup = ''; $visibletitle = $pageversion->title === '' ? get_string('startpage', 'ouwiki') : $pageversion->title; @@ -311,7 +313,6 @@ function get_online_display_content($format, $pageversion, $context, $subwiki, $ break; case OUWIKI_FORMAT_PDF || OUWIKI_FORMAT_HTML_PRINT: - $markup .= '

              ' . '' . htmlspecialchars($visibletitle) . '

              '; @@ -340,12 +341,11 @@ function get_online_display_content($format, $pageversion, $context, $subwiki, $ /** * @param $context * @param $xhtml - * @param $itemId + * @param $itemid * @param bool $treemode * @return mixed */ -function replace_image_urls($context, $xhtml, $itemId, $treemode = false) -{ +function replace_image_urls($context, $xhtml, $itemid, $treemode = false) { $content = $xhtml; preg_match_all('##', $content, $matches); @@ -361,10 +361,10 @@ function replace_image_urls($context, $xhtml, $itemId, $treemode = false) if ($treemode) { $tmp = explode('/', $urlinfo['dirname']); - $itemId = $tmp[sizeof($tmp) - 1]; + $itemid = $tmp[count($tmp) - 1]; } - if (!$file = $fs->get_file($context->id, 'mod_ouwiki', 'content', $itemId, '/', $image)) { + if (!$file = $fs->get_file($context->id, 'mod_ouwiki', 'content', $itemid, '/', $image)) { continue; } @@ -379,8 +379,7 @@ function replace_image_urls($context, $xhtml, $itemId, $treemode = false) return $content; } -function create_dir($path) -{ +function create_dir($path) { if (!file_exists($path)) { mkdir($path, 0777, true); } @@ -391,8 +390,7 @@ function create_dir($path) * Removes the temporary local image files used for creating the pdf * @param $html */ -function clean_up($html) -{ +function clean_up($html) { preg_match_all('##', $html, $matches); if (!empty($matches)) { foreach ($matches[1] as $key => $filepath) { diff --git a/renderer.php b/renderer.php index f39f799..72f7691 100644 --- a/renderer.php +++ b/renderer.php @@ -216,7 +216,7 @@ public function get_topheading_section($title, $gewgaws, $pageversion, $annotati $toc = new TableOfContents($pageversion->xhtml); $output .= $toc->to_html(); - + if ($gewgaws) { $output .= $this->render_heading_bit(1, $pageversion->title, $subwiki, $cm, null, $annotations, $pageversion->locked, $files, @@ -762,9 +762,9 @@ public function ouwiki_get_links() { */ public function ouwiki_get_links_content() { global $USER; - + $output = html_writer::start_tag('ul'); - + if ($this->params->page == 'wikiindex.php') { $output .= html_writer::start_tag('li', array('id' => 'ouwiki_nav_index')); $output .= html_writer::start_tag('span'); @@ -842,58 +842,56 @@ public function ouwiki_get_links_content() { $output .= html_writer::end_tag('li'); } } - - + $params = $this->params; - - $wikiParams = function ($format, $isTypeTree = false) use ($params) { - + + $wikiparams = function ($format, $istree = false) use ($params) { + $subwiki = $params->subwiki; $cm = $params->cm; - + $url = 'entirewiki.php?'; $url .= html_entity_decode(ouwiki_display_wiki_parameters('', $subwiki, $cm)); $url .= sprintf('&format=%s', $format); - - if($isTypeTree) - $url .= '&type=tree'; - - return $url; + + if ($istree) { + $url .= '&type=tree'; + } + return $url; }; // Dropdown for print functions. $output .= html_writer::start_tag('li', array('id' => 'ouwiki_nav_print')); $output .= html_writer::start_tag('div', array('class' => 'btn-group')); - + $output .= html_writer::start_tag('button', array('class' => 'btn dropdown-toggle', 'data-toggle' => 'dropdown')); $output .= get_string('printwiki', 'ouwiki'); $output .= html_writer::tag('span', '', array('class' => 'caret')); $output .= html_writer::end_tag('button'); - + $output .= html_writer::start_tag('ul', array('class' => 'dropdown-menu')); - + $output .= html_writer::start_tag('li'); - $output .= html_writer::tag('a', get_string('print_pdf_alphabetic', 'ouwiki'), array('target' => '_blank', 'href' => $wikiParams(OUWIKI_FORMAT_PDF))); + $output .= html_writer::tag('a', get_string('print_pdf_alphabetic', 'ouwiki'), array('target' => '_blank', 'href' => $wikiparams(OUWIKI_FORMAT_PDF))); $output .= html_writer::end_tag('li'); - + $output .= html_writer::start_tag('li'); - $output .= html_writer::tag('a', get_string('print_pdf_tree_structure', 'ouwiki'), array('target' => '_blank', 'href' => $wikiParams(OUWIKI_FORMAT_PDF, true))); + $output .= html_writer::tag('a', get_string('print_pdf_tree_structure', 'ouwiki'), array('target' => '_blank', 'href' => $wikiparams(OUWIKI_FORMAT_PDF, true))); $output .= html_writer::end_tag('li'); - + $output .= html_writer::start_tag('li'); - $output .= html_writer::tag('a', get_string('print_html_alphabetic', 'ouwiki'), array('target' => '_blank', 'href' => $wikiParams(OUWIKI_FORMAT_HTML_PRINT))); + $output .= html_writer::tag('a', get_string('print_html_alphabetic', 'ouwiki'), array('target' => '_blank', 'href' => $wikiparams(OUWIKI_FORMAT_HTML_PRINT))); $output .= html_writer::end_tag('li'); - + $output .= html_writer::start_tag('li'); - $output .= html_writer::tag('a', get_string('print_html_tree_structure', 'ouwiki'), array('target' => '_blank', 'href' => $wikiParams(OUWIKI_FORMAT_HTML_PRINT, true))); + $output .= html_writer::tag('a', get_string('print_html_tree_structure', 'ouwiki'), array('target' => '_blank', 'href' => $wikiparams(OUWIKI_FORMAT_HTML_PRINT, true))); $output .= html_writer::end_tag('li'); - + $output .= html_writer::end_tag('ul'); - + $output .= html_writer::end_tag('div'); $output .= html_writer::end_tag('li'); - - + $output .= html_writer::end_tag('ul'); return array($output, $participationstr); } diff --git a/tableofcontents.php b/tableofcontents.php index 821e1a6..6bb8423 100644 --- a/tableofcontents.php +++ b/tableofcontents.php @@ -105,7 +105,7 @@ private function parse_html($html) { $element->name = $heading->nodeValue; $element->id = $id; // Set the lvl to 3 if lvl < 3, as all headings <= 3 are treated as section headings. - $element->lvl = $lvl < 3 ? 3: $lvl; + $element->lvl = $lvl < 3 ? 3 : $lvl; $this->headings[] = $element; } } From 860fba8f443ccd57066f4ad20637f38c1354ffec Mon Sep 17 00:00:00 2001 From: hecatesBrain Date: Thu, 18 Jul 2019 13:08:19 +0200 Subject: [PATCH 26/30] Remove unused local variables. --- entirewiki.php | 4 ++-- locallib.php | 6 +++--- renderer.php | 10 +++++----- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/entirewiki.php b/entirewiki.php index a35fe26..fc6174b 100644 --- a/entirewiki.php +++ b/entirewiki.php @@ -355,7 +355,7 @@ function replace_image_urls($context, $xhtml, $itemid, $treemode = false) { if (!empty($matches)) { // Extract the file names from the matches. - foreach ($matches[1] as $key => $match) { + foreach ($matches[1] as $match) { $urlinfo = pathinfo($match); $image = urldecode($urlinfo['basename']); @@ -393,7 +393,7 @@ function create_dir($path) { function clean_up($html) { preg_match_all('##', $html, $matches); if (!empty($matches)) { - foreach ($matches[1] as $key => $filepath) { + foreach ($matches[1] as $filepath) { unlink($filepath); } } diff --git a/locallib.php b/locallib.php index 4cf6177..a775db5 100644 --- a/locallib.php +++ b/locallib.php @@ -185,7 +185,7 @@ function ouwiki_get_subwiki($course, $ouwiki, $cm, $context, $groupid, $userid, $groupid = reset($groups)->id; } $othergroup = !groups_is_member($groupid); - // Removed AND userid IS NULL + // Removed AND userid IS NULL. $subwiki = $DB->get_record_select('ouwiki_subwikis', 'wikiid = ? AND groupid = ?', array($ouwiki->id, $groupid)); if ($subwiki) { ouwiki_set_extra_subwiki_fields($subwiki, $ouwiki, $context, $othergroup); @@ -234,8 +234,8 @@ function ouwiki_get_subwiki($course, $ouwiki, $cm, $context, $groupid, $userid, } } } - // OK now find wiki - // Removed AND groupid IS NULL + // OK now find wiki. + // Removed AND groupid IS NULL. $subwiki = $DB->get_record_select('ouwiki_subwikis', 'wikiid = ? AND userid = ?', array($ouwiki->id, $userid)); if ($subwiki) { ouwiki_set_extra_subwiki_fields($subwiki, $ouwiki, $context, $otheruser, !$otheruser); diff --git a/renderer.php b/renderer.php index 72f7691..8b79bbd 100644 --- a/renderer.php +++ b/renderer.php @@ -847,12 +847,12 @@ public function ouwiki_get_links_content() { $wikiparams = function ($format, $istree = false) use ($params) { - $subwiki = $params->subwiki; - $cm = $params->cm; + $subwiki = $params->subwiki; + $cm = $params->cm; - $url = 'entirewiki.php?'; - $url .= html_entity_decode(ouwiki_display_wiki_parameters('', $subwiki, $cm)); - $url .= sprintf('&format=%s', $format); + $url = 'entirewiki.php?'; + $url .= html_entity_decode(ouwiki_display_wiki_parameters('', $subwiki, $cm)); + $url .= sprintf('&format=%s', $format); if ($istree) { $url .= '&type=tree'; From 9508cc89f01ccb1c35cf75c5071d14302adb5f90 Mon Sep 17 00:00:00 2001 From: Joel Tschesche Date: Thu, 18 Jul 2019 13:14:05 +0200 Subject: [PATCH 27/30] Delete .travis.yml --- .travis.yml | 117 ---------------------------------------------------- 1 file changed, 117 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 22fea9a..0000000 --- a/.travis.yml +++ /dev/null @@ -1,117 +0,0 @@ -# This is the language of our project. -language: php - -# If using Behat, then this should be true due to an issue with Travis CI. -# If not using Behat, recommended to use `sudo: false` as it is faster. -sudo: false - -# Installs the required version of Firefox for Behat, an updated version -# of PostgreSQL and extra APT packages. Java 8 is only required -# for Mustache command. -addons: - firefox: "47.0.1" - postgresql: "9.4" - apt: - packages: - - openjdk-8-jre-headless - -# Cache NPM's and Composer's caches to speed up build times. -cache: - directories: - - $HOME/.composer/cache - - $HOME/.npm - -# Determines which versions of PHP to test our project against. Each version -# listed here will create a separate build and run the tests against that -# version of PHP. -php: - - 7.0 - - 7.1 - - 7.2 - -# This section sets up the environment variables for the build. -env: - global: - # This line determines which version of Moodle to test against. - - MOODLE_BRANCH=MOODLE_35_STABLE - - MOODLE_BRANCH=MOODLE_36_STABLE - - MOODLE_BRANCH=MOODLE_37_STABLE - # Ignoring sadly does not work for grunt tasks according to https://docs.moodle.org/dev/Travis_integration#Ignoring_files ... - - IGNORE_PATHS=backup,classes,db,internaldoc,lang,pix,style,tests,yui,annotate.php,annotate_form.php,basicpage.php,confirmlock.php,confirmloggedin.php,csv_writer,delete.php,diff.php,difflib.php,edit.php,edit_form.php,feed-history.php,feed-wikihistory.php,hideannotations.php,history.php,import.php,import_form.php,index.php,lib.php,locallib.php,lock.php,mod_form.php,module.js,nojslock.php,override.php,participation.php,participation_table.php,revert.php,savegrades.php,search.php,style.css,userparticipation.php,version.php,view.php,viewold.php,wkihistory.php,wikiindex.php - # This matrix is used for testing against multiple databases. So for - # each version of PHP being tested, one build will be created for each - # database listed here. - matrix: - - DB=pgsql - - DB=mysqli - -# This lists steps that are run before the installation step. -before_install: - # This disables XDebug which should speed up the build. - - phpenv config-rm xdebug.ini - # This installs NodeJS which is used by Grunt, etc. - - nvm install 8.9 - - nvm use 8.9 - # Currently we are inside of the clone of your repository. We move up two - # directories to build the project. - - cd ../.. - # Install this project into a directory called "ci". - - composer create-project -n --no-dev --prefer-dist blackboard-open-source/moodle-plugin-ci ci ^2 - # Update the $PATH so scripts from this project can be called easily. - - export PATH="$(cd ci/bin; pwd):$(cd ci/vendor/bin; pwd):$PATH" - -# This lists steps that are run for installation and setup. -install: - # Run the default install. The overview of what this does: - # - Clone the Moodle project into a directory called moodle. - # - Create a data directory called moodledata. - # - Create Moodle config.php, database, etc. - # - Copy your plugin(s) into Moodle. - # - Run Composer install within Moodle. - # - Run NPM install in Moodle and in your plugin if it has a "package.json". - # - Run "grunt ignorefiles" within Moodle to update ignore file lists. - # - If your plugin has Behat features, then Behat will be setup. - # - If your plugin has unit tests, then PHPUnit will be setup. - - moodle-plugin-ci install - -# This lists steps that are run for the purposes of testing. Any of -# these steps can be re-ordered or removed to your liking. And of -# course, you can add any of your own custom steps. -script: - # This step lints your PHP files to check for syntax errors. - - moodle-plugin-ci phplint - # This step runs the PHP Copy/Paste Detector on your plugin. - # This helps to find code duplication. - - moodle-plugin-ci phpcpd - # This step runs the PHP Mess Detector on your plugin. This helps to find - # potential problems with your code which can result in - # refactoring opportunities. - - moodle-plugin-ci phpmd - # This step runs the Moodle Code Checker to make sure that your plugin - # conforms to the Moodle coding standards. It is highly recommended - # that you keep this step. - - moodle-plugin-ci codechecker - # This step runs some light validation on the plugin file structure - # and code. Validation can be plugin specific. - - moodle-plugin-ci validate - # This step validates your plugin's upgrade steps. - - moodle-plugin-ci savepoints - # This step validates the HTML and Javascript in your Mustache templates. - - moodle-plugin-ci mustache - # This step runs Grunt tasks on the plugin. By default, it tries to run - # tasks relevant to your plugin and Moodle version, but you can run - # specific tasks by passing them as options, - # EG: moodle-plugin-ci grunt -t task1 -t task2 - #- moodle-plugin-ci grunt -t eslint:amd -t uglify:amd # Do not run stylelint:css because third party css files cannot be ignored - - moodle-plugin-ci grunt - # This step runs the PHPUnit tests of your plugin. If your plugin has - # PHPUnit tests, then it is highly recommended that you keep this step. - #- moodle-plugin-ci phpunit - # This step runs the Behat tests of your plugin. If your plugin has - # Behat tests, then it is highly recommended that you keep this step. - # There are two important options that you may want to use: - # - The auto rerun option allows you to rerun failures X number of times, - # default is 2, EG usage: --auto-rerun 3 - # - The dump option allows you to print the failure HTML to the console, - # handy for debugging, EG usage: --dump - #- moodle-plugin-ci behat From ace273d0bda1eeba3d466abdfc198cc3eb8ede2a Mon Sep 17 00:00:00 2001 From: curiosity Date: Tue, 8 Aug 2023 10:35:16 +0200 Subject: [PATCH 28/30] fix value error for pages with 0 headings --- tableofcontents.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tableofcontents.php b/tableofcontents.php index 6bb8423..4fa85c2 100644 --- a/tableofcontents.php +++ b/tableofcontents.php @@ -73,7 +73,7 @@ private function set_min_lvl() { foreach ($this->headings as $heading) { $lvls[] = $heading->lvl; } - $min = min($lvls); + $min = empty($lvls) ? 0 : min($lvls); foreach ($this->headings as $heading) { $heading->lvl = $heading->lvl - $min + 1; } From 71262acbd96389620d31f81794bb766117c6b79d Mon Sep 17 00:00:00 2001 From: curiosity Date: Tue, 12 Sep 2023 13:46:17 +0200 Subject: [PATCH 29/30] fix db error in per group subwikis --- locallib.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/locallib.php b/locallib.php index 16a6226..451fcff 100644 --- a/locallib.php +++ b/locallib.php @@ -187,8 +187,7 @@ function ouwiki_get_subwiki($course, $ouwiki, $cm, $context, $groupid, $userid, $othergroup = !groups_is_member($groupid); // Place get subwiki here to facilitate checking agaimst magic number below. - $subwiki = $DB->get_record_select('ouwiki_subwikis', 'wikiid = ? AND groupid = ? - AND userid IS NULL', array($ouwiki->id, $groupid)); + $subwiki = $DB->get_record_select('ouwiki_subwikis', 'wikiid = ? AND groupid = ?', array($ouwiki->id, $groupid)); if ($othergroup && $cm->groupmode == SEPARATEGROUPS) { // Ignore if in feed, From 846d5ad84abd04e8d5ede319c3743d95450db121 Mon Sep 17 00:00:00 2001 From: curiosity Date: Tue, 12 Sep 2023 14:48:34 +0200 Subject: [PATCH 30/30] remove deprecated get_legacy_logdata from events --- classes/event/ouwiki_viewed.php | 10 ---------- classes/event/page_created.php | 11 ----------- classes/event/page_lock.php | 10 ---------- classes/event/page_unlock.php | 10 ---------- classes/event/page_updated.php | 11 ----------- classes/event/page_version_deleted.php | 10 ---------- classes/event/page_version_undeleted.php | 10 ---------- classes/event/save_failed.php | 12 ------------ 8 files changed, 84 deletions(-) diff --git a/classes/event/ouwiki_viewed.php b/classes/event/ouwiki_viewed.php index 6210fe6..deb8027 100644 --- a/classes/event/ouwiki_viewed.php +++ b/classes/event/ouwiki_viewed.php @@ -77,16 +77,6 @@ public function get_url() { return new \moodle_url('\\mod\\ouwiki\\' . $this->other['logurl']); } - /** - * Return the legacy event log data. - * - * @return array|null - */ - protected function get_legacy_logdata() { - return array($this->courseid, 'ouwiki', $this->other['action'], $this->other['logurl'], - $this->other['info'], $this->contextinstanceid); - } - /** * Custom validation. * diff --git a/classes/event/page_created.php b/classes/event/page_created.php index 231e4f8..335afcd 100644 --- a/classes/event/page_created.php +++ b/classes/event/page_created.php @@ -75,17 +75,6 @@ public function get_url() { return new \moodle_url($this->other['logurl']); } - /** - * Return the legacy event log data. - * - * @return array|null - */ - protected function get_legacy_logdata() { - $logurl = substr($this->other['logurl'], strlen('/mod/ouwiki/')); - return array($this->courseid, 'ouwiki', 'page created', $logurl, - $this->other['info'], $this->contextinstanceid); - } - /** * Custom validation. * diff --git a/classes/event/page_lock.php b/classes/event/page_lock.php index 739acc6..58d82f7 100644 --- a/classes/event/page_lock.php +++ b/classes/event/page_lock.php @@ -75,16 +75,6 @@ public function get_url() { return new \moodle_url('\\mod\\ouwiki\\' . $this->other['logurl']); } - /** - * Return the legacy event log data. - * - * @return array|null - */ - protected function get_legacy_logdata() { - return array($this->courseid, 'ouwiki', 'lock', $this->other['logurl'], - $this->other['info'], $this->contextinstanceid); - } - /** * Custom validation. * diff --git a/classes/event/page_unlock.php b/classes/event/page_unlock.php index 74f9d77..e0aa82c 100644 --- a/classes/event/page_unlock.php +++ b/classes/event/page_unlock.php @@ -75,16 +75,6 @@ public function get_url() { return new \moodle_url('\\mod\\ouwiki\\' . $this->other['logurl']); } - /** - * Return the legacy event log data. - * - * @return array|null - */ - protected function get_legacy_logdata() { - return array($this->courseid, 'ouwiki', 'unlock', $this->other['logurl'], - $this->other['info'], $this->contextinstanceid); - } - /** * Custom validation. * diff --git a/classes/event/page_updated.php b/classes/event/page_updated.php index 189ba17..7d240f4 100644 --- a/classes/event/page_updated.php +++ b/classes/event/page_updated.php @@ -74,17 +74,6 @@ public function get_url() { return new \moodle_url( $this->other['logurl']); } - /** - * Return the legacy event log data. - * - * @return array|null - */ - protected function get_legacy_logdata() { - $logurl = substr($this->other['logurl'], strlen('/mod/ouwiki/')); - return array($this->courseid, 'ouwiki', 'page updated', $logurl, - $this->other['info'], $this->contextinstanceid); - } - /** * Custom validation. * diff --git a/classes/event/page_version_deleted.php b/classes/event/page_version_deleted.php index 6213f24..d1e9b42 100644 --- a/classes/event/page_version_deleted.php +++ b/classes/event/page_version_deleted.php @@ -75,16 +75,6 @@ public function get_url() { return new \moodle_url('\\mod\\ouwiki\\' . $this->other['logurl']); } - /** - * Return the legacy event log data. - * - * @return array|null - */ - protected function get_legacy_logdata() { - return array($this->courseid, 'ouwiki', 'version delete', $this->other['logurl'], - '', $this->contextinstanceid); - } - /** * Custom validation. * diff --git a/classes/event/page_version_undeleted.php b/classes/event/page_version_undeleted.php index 84b2ad4..4bd2487 100644 --- a/classes/event/page_version_undeleted.php +++ b/classes/event/page_version_undeleted.php @@ -75,16 +75,6 @@ public function get_url() { return new \moodle_url('\\mod\\ouwiki\\' . $this->other['logurl']); } - /** - * Return the legacy event log data. - * - * @return array|null - */ - protected function get_legacy_logdata() { - return array($this->courseid, 'ouwiki', 'version delete', $this->other['logurl'], - '', $this->contextinstanceid); - } - /** * Custom validation. * diff --git a/classes/event/save_failed.php b/classes/event/save_failed.php index 7b094d6..adc8ef0 100644 --- a/classes/event/save_failed.php +++ b/classes/event/save_failed.php @@ -76,18 +76,6 @@ public function get_url() { return new \moodle_url($this->other['page']); } - /** - * Return the legacy event log data. - * - * @return array|null - */ - protected function get_legacy_logdata() { - global $SITE; - $url = str_replace('/mod/ouwiki/', '', $this->other['page']); - return array($SITE->id, 'ouwiki', 'error editpage', $this->other['page'], 'session error', - $this->contextinstanceid); - } - /** * Custom validation. *