Example #1
0
 /**
  * @covers \Pressbooks\Sanitize\sanitize_xml_attribute
  */
 public function test_sanitize_xml_attribute()
 {
     $var = 'Hello-World!';
     $this->assertEquals($var, \Pressbooks\Sanitize\sanitize_xml_attribute($var));
     $var = "\t <Hello&World!> ";
     $this->assertEquals('&lt;Hello&amp;World!&gt;', \Pressbooks\Sanitize\sanitize_xml_attribute($var));
     $var = " te\fst";
     $this->assertEquals('test', \Pressbooks\Sanitize\sanitize_xml_attribute($var));
 }
Example #2
0
 /**
  * @param $book_contents
  *
  * @return mixed
  */
 protected function preProcessBookContents($book_contents)
 {
     // We need to change global $id for shortcodes, the_content, ...
     global $id;
     $old_id = $id;
     // Do root level structures first.
     foreach ($book_contents as $type => $struct) {
         if (preg_match('/^__/', $type)) {
             continue;
             // Skip __magic keys
         }
         foreach ($struct as $i => $val) {
             if (isset($val['post_content'])) {
                 // @codingStandardsIgnoreLine
                 $id = $val['ID'];
                 $book_contents[$type][$i]['post_content'] = $this->preProcessPostContent($val['post_content']);
             }
             if (isset($val['post_title'])) {
                 $book_contents[$type][$i]['post_title'] = \Pressbooks\Sanitize\sanitize_xml_attribute($val['post_title']);
             }
             if (isset($val['post_name'])) {
                 $book_contents[$type][$i]['post_name'] = $this->preProcessPostName($val['post_name']);
             }
             if ('part' == $type) {
                 // Do chapters, which are embedded in part structure
                 foreach ($book_contents[$type][$i]['chapters'] as $j => $val2) {
                     if (isset($val2['post_content'])) {
                         // @codingStandardsIgnoreLine
                         $id = $val2['ID'];
                         $book_contents[$type][$i]['chapters'][$j]['post_content'] = $this->preProcessPostContent($val2['post_content']);
                     }
                     if (isset($val2['post_title'])) {
                         $book_contents[$type][$i]['chapters'][$j]['post_title'] = \Pressbooks\Sanitize\sanitize_xml_attribute($val2['post_title']);
                     }
                     if (isset($val2['post_name'])) {
                         $book_contents[$type][$i]['chapters'][$j]['post_name'] = $this->preProcessPostName($val2['post_name']);
                     }
                 }
             }
         }
     }
     // @codingStandardsIgnoreLine
     $id = $old_id;
     return $book_contents;
 }