MWDelaney / bootstrap-3-shortcodes

WordPress shortcodes for easier use of Bootstrap elements in your content.
https://wordpress.org/plugins/bootstrap-3-shortcodes/
MIT License
377 stars 118 forks source link

[table-wrap] produces errors #87

Closed bostondv closed 9 years ago

bostondv commented 10 years ago

Using [table-wrap] I am getting the following errors when loading page in front end.

Warning: DOMDocument::loadXML(): Opening and ending tag mismatch: td line 73 and p in Entity, line: 73 in /home/pomelo/webapps/dynamicgreens_dev/web/app/plugins/bootstrap-3-shortcodes/bootstrap-shortcodes.php on line 1032

Warning: DOMDocument::loadXML(): Opening and ending tag mismatch: tr line 71 and td in Entity, line: 74 in /home/pomelo/webapps/dynamicgreens_dev/web/app/plugins/bootstrap-3-shortcodes/bootstrap-shortcodes.php on line 1032

Warning: DOMDocument::loadXML(): Opening and ending tag mismatch: td line 75 and p in Entity, line: 75 in /home/pomelo/webapps/dynamicgreens_dev/web/app/plugins/bootstrap-3-shortcodes/bootstrap-shortcodes.php on line 1032

Warning: DOMDocument::loadXML(): Opening and ending tag mismatch: tbody line 3 and td in Entity, line: 76 in /home/pomelo/webapps/dynamicgreens_dev/web/app/plugins/bootstrap-3-shortcodes/bootstrap-shortcodes.php on line 1032

Warning: DOMDocument::loadXML(): Opening and ending tag mismatch: table line 2 and tr in Entity, line: 77 in /home/pomelo/webapps/dynamicgreens_dev/web/app/plugins/bootstrap-3-shortcodes/bootstrap-shortcodes.php on line 1032

Warning: DOMDocument::loadXML(): Extra content at the end of the document in Entity, line: 78 in /home/pomelo/webapps/dynamicgreens_dev/web/app/plugins/bootstrap-3-shortcodes/bootstrap-shortcodes.php on line 1032

Fatal error: Call to a member function setAttribute() on a non-object in /home/pomelo/webapps/dynamicgreens_dev/web/app/plugins/bootstrap-3-shortcodes/bootstrap-shortcodes.php on line 1033

This is the code in TinyMCE editor:

[table-wrap bordered="true" striped="true"]
<table>
    <tbody>
        <tr>
            <th>General Information</th>
            <th>1 Fluid Oz.</th>
            <th>10 Fluid Ozs.</th>
        </tr>
        <tr>
            <td>Ash (Total)</td>
            <td>136.08 mg</td>
            <td>1360.8 mg</td>
        </tr>
        <tr>
            <td>Calories</td>
            <td>5.9535 cal</td>
            <td>59.535 cal</td>
        </tr>
        <tr>
            <td>Carbohydrates</td>
            <td>0.567 g</td>
            <td>5.67 g</td>
        </tr>
        <tr>
            <td>Chlorophyll</td>
            <td>11.9637 mg</td>
            <td>119.637 mg</td>
        </tr>
        <tr>
            <td>Dietary Fiber</td>
            <td>&lt; 28.35 mg</td>
            <td>&lt; 283.50 mg</td>
        </tr>
        <tr>
            <td>Fat</td>
            <td>0.017 g</td>
            <td>0.1701 g</td>
        </tr>
        <tr>
            <td>Moisture</td>
            <td>26.9325 g</td>
            <td>269.325 g</td>
        </tr>
        <tr>
            <td>Protein-N x 6.25</td>
            <td>0.5528 g</td>
            <td>5.5283 g</td>
        </tr>
        <tr>
            <th colspan="3">Vitamins</th>
        </tr>
        <tr>
            <td>Biotin</td>
            <td>2.835 mcg</td>
            <td>28.35 mcg</td>
        </tr>
        <tr>
            <td>Choline</td>
            <td>26.1954 mg</td>
            <td>261.954 mg</td>
        </tr>
        <tr>
            <td>Folic Acid / Folacin</td>
            <td>8.2215 mcg</td>
            <td>82.215 mcg</td>
        </tr>
        <tr>
            <td>Inositol</td>
            <td>&lt; 0.1 g / 100 g[Not Detected]</td>
            <td>&lt; 0.1 g / 100 g[Not Detected]</td>
        </tr>
        <tr>
            <td>Vitamin A</td>
            <td>121.0545 IU</td>
            <td>1210.545 IU</td>
        </tr>
        <tr>
            <td>Vitamin B1 (Thiamine)</td>
            <td>22.68 mcg</td>
            <td>226.8 mcg</td>
        </tr>
        <tr>
            <td>Vitamin B2 (Riboflavin)</td>
            <td>36.855 mcg</td>
            <td>368.55 mcg</td>
        </tr>
        <tr>
            <td>Vitamin B3 (Niacinamide)</td>
            <td>31.185 mcg</td>
            <td>311.85 mcg</td>
        </tr>
        <tr>
            <td>Vitamin B5 (Pantothenic Acid)</td>
            <td>1.701 mg</td>
            <td>17.01 mg</td>
        </tr>
        <tr>
            <td>Vitamin B6 (Pyridoxine HCI)</td>
            <td>56.7 mcg</td>
            <td>567 mcg</td>
        </tr>
        <tr>
            <td>Vitamin B12 (Cyanocobalamin)</td>
            <td>&lt; 28.35 mcg</td>
            <td>&lt; 283.50 mcg</td>
        </tr>
        <tr>
            <td>Vitamin C (Ascorbic Acid)</td>
            <td>1.03 mg</td>
            <td>10.2478 mg</td>
        </tr>
        <tr>
            <td>Vitamin D</td>
            <td>Not Tested</td>
            <td>Not Tested</td>
        </tr>
        <tr>
            <td>Vitamin E</td>
            <td>4.3092 IU</td>
            <td>43.092 IU</td>
        </tr>
        <tr>
            <td>Vitamin K</td>
            <td>Not Tested</td>
            <td>Not Tested</td>
        </tr>
        <tr>
            <th colspan="3">Minerals</th>
        </tr>
        <tr>
            <td>Calcium</td>
            <td>6.8607 mg</td>
            <td>68.607 mg</td>
        </tr>
        <tr>
            <td>Iron</td>
            <td>0.1729 mg</td>
            <td>1.7294 mg</td>
        </tr>
        <tr>
            <td>Magnesium</td>
            <td>6.804 mg</td>
            <td>68.04 mg</td>
        </tr>
        <tr>
            <td>Phosphorus</td>
            <td>21.3192 mg</td>
            <td>213.192 mg</td>
        </tr>
        <tr>
            <td>Potassium</td>
            <td>41.6745 mg</td>
            <td>416.745 mg</td>
        </tr>
        <tr>
            <td>Selenium</td>
            <td>&lt; 0.2835 ppm</td>
            <td>&lt; 2.835 ppm</td>
        </tr>
        <tr>
            <td>Sodium</td>
            <td>2.9201 mg</td>
            <td>29.2005 mg</td>
        </tr>
        <tr>
            <td>Zinc</td>
            <td>0.0936 mg</td>
            <td>0.9356 mg</td>
        </tr>
        <tr>
            <th colspan="3">Amino Acids</th>
        </tr>
        <tr>
            <td>Alanine</td>
            <td>86.751 mg</td>
            <td>867.51 mg</td>
        </tr>
        <tr>
            <td>Aspartic Acid</td>
            <td>73.71 mg</td>
            <td>737.1 mg</td>
        </tr>
        <tr>
            <td>Cysteine</td>
            <td>8.8452 mg</td>
            <td>88.452 mg</td>
        </tr>
        <tr>
            <td>Glutamic Acid</td>
            <td>Not Detected</td>
            <td>Not Detected</td>
        </tr>
        <tr>
            <td>Glycine</td>
            <td>Not Detected</td>
            <td>Not Detected</td>
        </tr>
        <tr>
            <td>Histidine</td>
            <td>Not Detected</td>
            <td>Not Detected</td>
        </tr>
        <tr>
            <td>Isoleucine</td>
            <td>16.0461 mg</td>
            <td>160.461 mg</td>
        </tr>
        <tr>
            <td>L-Arginine</td>
            <td>38.2725 mg</td>
            <td>382.725 mg</td>
        </tr>
        <tr>
            <td>L-Lysine</td>
            <td>10.4895 mg</td>
            <td>104.895 mg</td>
        </tr>
        <tr>
            <td>Leucine</td>
            <td>29.8526 mg</td>
            <td>298.5255 mg</td>
        </tr>
        <tr>
            <td>Methionine</td>
            <td>26.5356 mg</td>
            <td>265.356 mg</td>
        </tr>
        <tr>
            <td>Phenylalanine</td>
            <td>29.3139 mg</td>
            <td>293.139 mg</td>
        </tr>
        <tr>
            <td>Proline</td>
            <td>67.1895 mg</td>
            <td>671.895 mg</td>
        </tr>
        <tr>
            <td>Serine</td>
            <td>Not Detected</td>
            <td>Not Detected</td>
        </tr>
        <tr>
            <td>Threonine</td>
            <td>79.38 mg</td>
            <td>793.8 mg</td>
        </tr>
        <tr>
            <td>Tryptophan</td>
            <td>Not Tested</td>
            <td>Not Tested</td>
        </tr>
        <tr>
            <td>Tyrosine</td>
            <td>17.6904 mg</td>
            <td>176.904 mg</td>
        </tr>
        <tr>
            <td>Valine</td>
            <td>12.7292 mg</td>
            <td>127.2915 mg</td>
        </tr>
        <tr>
            <th colspan="3">Enzymes</th>
        </tr>
        <tr>
            <td>Amylase</td>
            <td>Not Detected</td>
            <td>Not Detected</td>
        </tr>
        <tr>
            <td>Lipase</td>
            <td>Not Detected</td>
            <td>Not Detected</td>
        </tr>
        <tr>
            <td>Protease</td>
            <td>Not Detected</td>
            <td>Not Detected</td>
        </tr>
        <tr>
            <th colspan="3">Essential Fatty Acids</th>
        </tr>
        <tr>
            <td>Lecithin</td>
            <td>&lt; 85.05 mg</td>
            <td>&lt; 850.5 mg</td>
        </tr>
        <tr>
            <td>Mono Unsaturated Fatty Acid</td>
            <td>&lt; 0.1 g / 100 g[Not Detected]</td>
            <td>&lt; 0.1 g / 100 g[Not Detected]</td>
        </tr>
        <tr>
            <td>Poly Unsaturated Fatty Acid</td>
            <td>&lt; 0.1 g / 100 g[Not Detected]</td>
            <td>&lt; 0.1 g / 100 g[Not Detected]</td>
        </tr>
        <tr>
            <td>Saturated Fatty Acid</td>
            <td>&lt; 0.1 g / 100 g[Not Detected]</td>
            <td>&lt; 0.1 g / 100 g[Not Detected]</td>
        </tr>
        <tr>
            <th colspan="3">Carbohydrates</th>
        </tr>
        <tr>
            <td>Fructose</td>
            <td>&lt; 0.1 g / 100 g[Not Detected]</td>
            <td>&lt; 0.1 g / 100 g[Not Detected]</td>
        </tr>
        <tr>
            <td>Glucose</td>
            <td>0.2268 g</td>
            <td>2.268 g</td>
        </tr>
        <tr>
            <td>Lactose</td>
            <td>&lt; 0.1 g / 100 g[Not Detected]</td>
            <td>&lt; 0.1 g / 100 g[Not Detected]</td>
        </tr>
        <tr>
            <td>Maltose</td>
            <td>&lt; 0.1 g / 100 g[Not Detected]</td>
            <td>&lt; 0.1 g / 100 g[Not Detected]</td>
        </tr>
        <tr>
            <td>Sucrose</td>
            <td>&lt; 0.1 g / 100 g[Not Detected]</td>
            <td>&lt; 0.1 g / 100 g[Not Detected]</td>
        </tr>
    </tbody>
</table>
[/table-wrap]

Running plugin version 3.2.3

bostondv commented 10 years ago

I also get the issue using [media]

Fatal error: Call to a member function setAttribute() on a non-object in /home/pomelo/webapps/dynamicgreens_dev/web/app/plugins/bootstrap-3-shortcodes/bootstrap-shortcodes.php on line 1575

WordPress 3.9.1 PHP 5.5.7 Apache

TinyMCE content:

[media]
[media-object pull="right"]
...
[/media-object]
[media-body title="Testing"]
Test
[/media-body]
[/media]
MWDelaney commented 10 years ago

I think these are separate issues. Let's take them one at a time.

[table-wrap] Can you double-check the "Text" tab in your WordPress page or post? I got the same errors you saw when I copy-and-pasted your table, and it turns out to have pasted like this:

screen shot 2014-07-29 at 7 49 10 pm

When I corrected the to be proper HTML rather than entities, it worked on my test site.

[media] The [media-object] shortcode actually expects an image as its contents. I can add some error-checking for this in a future version, but I'll bet if you stick an image that shortcode it'll work.

Let me now how these turn out and we'll keep troubleshooting if necessary!

bostondv commented 10 years ago

I can open a separate issue for media object, if it's better?

[table-wrap]

That's odd about the entities, I think it may be due to the copy-paste from github because in the editor I have proper html markup.

screen shot 2014-07-29 at 9 22 02 pm

[media]

I actually had an image there, just omitted it from my comments. With the following markup I still get an error.

[media]
[media-object pull="right"]
<img class="alignnone wp-image-804 size-full" src="http://dynamicgreens.pmlo.org/app/uploads/2014/06/alpha-linolenic-acid.png" alt="alpha-linolenic-acid" width="256" height="213" />
[/media-object]
[media-body title="Testing"]
Donec ullamcorper nulla non metus auctor fringilla.
[/media-body]
[/media]

Both I've now tested on a dev site with plugins disabled and using Twenty Eleven theme. Was able to reproduce the error for both shortcodes.

Thanks!

MWDelaney commented 10 years ago

Hm. Both of those functions use PHP's DOMDocument class. I wonder if your host doesn't like that class somehow.

Does this shortcode also produce the error?

[img type="circle" responsive="true"]<img class="alignnone" src="http://upload.wikimedia.org/wikipedia/en/1/11/Serenityship.jpg" alt="" width="250" height="154" />[/img]

Also, just to be sure, does WordPress think the table markup is good? Your table (once the entities are fixed) is working correctly in my test environment and the WordPress visual editor looks like this: screen shot 2014-07-29 at 10 52 20 pm

bostondv commented 10 years ago

The [img] shortcode worked and yes, the table is correct in the visual tab.

I think I've identified cause of the issues for both though. If there are new lines between the and the opening or closing [media-object] shortcodes, it fails. Same goes for

and [table-wrap] codes. Note the different white spaces in the examples below (I've omitted the surrounding [media] shortcodes)

These Work:

[media-object pull="right"]<img class="size-full wp-image-906 aligncenter" title="Image Alignment 580x300" src="http://localhost/wp/assets/image-alignment-580x300.jpg" alt="Image Alignment 580x300" width="580" height="300" />[/media-object]

[media-object pull="right"]
<img class="size-full wp-image-906 aligncenter" title="Image Alignment 580x300" src="http://localhost/wp/assets/image-alignment-580x300.jpg" alt="Image Alignment 580x300" width="580" height="300" />[/media-object]

[media-object pull="right"]     <img class="size-full wp-image-906 aligncenter" title="Image Alignment 580x300" src="http://localhost/wp/assets/image-alignment-580x300.jpg" alt="Image Alignment 580x300" width="580" height="300" />    [/media-object]

These fail:

[media-object pull="right"]<img class="size-full wp-image-906 aligncenter" title="Image Alignment 580x300" src="http://localhost/wp/assets/image-alignment-580x300.jpg" alt="Image Alignment 580x300" width="580" height="300" />
[/media-object]

[media-object pull="right"]
<img class="size-full wp-image-906 aligncenter" title="Image Alignment 580x300" src="http://localhost/wp/assets/image-alignment-580x300.jpg" alt="Image Alignment 580x300" width="580" height="300" />
[/media-object]

[media-object pull="right"]

<img class="size-full wp-image-906 aligncenter" title="Image Alignment 580x300" src="http://localhost/wp/assets/image-alignment-580x300.jpg" alt="Image Alignment 580x300" width="580" height="300" />[/media-object]

[media-object pull="right"][caption id="attachment_906" align="aligncenter" width="580"]<img class="wp-image-906 size-full" title="Image Alignment 580x300" src="http://localhost/wp/assets/image-alignment-580x300.jpg" alt="Image Alignment 580x300" width="580" height="300" /> Test[/caption][/media-object]

[media-object pull="right"]<img class="wp-image-906 size-full" title="Image Alignment 580x300" src="http://localhost/wp/assets/image-alignment-580x300.jpg" alt="Image Alignment 580x300" width="580" height="300" /><p>Hello</p>[/media-object]

Can you do something to ignore whitespace?

It also fails if there is any other HTML content inside the shortcode other than what it expects, such as a caption on the image. Is it be possible to render any extraneous html markup normally or at least fail more gracefully when other html content is present?

MWDelaney commented 10 years ago

Thanks for narrowing this down! I'm able to reproduce the error with whitespace.

I'll definitely look at better ignoring or dealing with unexpected input on these shortcodes for the next release!

MWDelaney commented 10 years ago

ee1b01f6e977a43a1805baed97e00b47a5e6ffd3 should fix this issue for [media-object] and 4afed2a32fd3ec7d407e45c06ca2cc183cf6bfe3 should fix it for [table-wrap]

I'll be going through the other shortcodes which use the same method and correcting those as time allows, too. I'll roll these fixes into the next major release.

Thanks again for your help finding this bug!