[Howto] Solve the simple quotes problem in META

Find How to do something.

[Howto] Solve the simple quotes problem in META

Postby Jiff » Mon Jul 09, 2012 1:47 am

This won't affect you much if you're English or German, but french use simple quotes a lot.
e.g. (META description):
Code: Select all
N'oubliez pas d'imprimer l'indispensable documentation.

This meta cause a huge problem: after a page modification you just find it to be:
Code: Select all
N\

Which is certainly something you want to avoid.
Of course, you could escape yourself the single quotes like that:
Code: Select all
N\'oubliez pas d\'imprimer l\'indispensable documentation.

alas, each time you'll modify the page, you'll an extra simple quote to escape the former simple quote to quote...... Raaaahhhhh
Code: Select all
N\\\'oubliez pas d\\\'imprimer l\\\'indispensable documentation.


After some research in PHP's functions and string handling, I find a solution - CAUTION: it ISN'T tested with double-quotes! and almost certainly generates the same problem with them, but they aren't use very much in METAs.
Here's the patch to apply to /blade_packs/system_metaForPages.php:
Code: Select all
--- system_metaForPages.php_ORG   2012-07-09 00:51:34.000000000 +0200
+++ system_metaForPages.php   2012-07-09 02:31:51.000000000 +0200
@@ -26,24 +26,25 @@
 // blade - save META DATA content //
 function metaDataInput($slabName) {
    global $razorArray;
-    $razorArray['meta'][$slabName]['metades'] = $_POST['metades'];
-   $razorArray['meta'][$slabName]['metakey'] = $_POST['metakey'];
+    $razorArray['meta'][$slabName]['metades'] = stripslashes($_POST["metades"]);
+   $razorArray['meta'][$slabName]['metakey'] = stripslashes($_POST["metakey"]);
 }
 // end /////////////////////////////
 
 // blade - output form to input META DATA //
 function metaDataOutput(&$formOutput) {
 $formOutput=<<<TET
-        <table width='98%' border='0'>
+        <table width="98%" border="0">
           <tr>
-            <td width='20%'>META Description</td>
-            <td><input type='text' value='' name='metades'></td>
+            <td width="20%">META Description</td>
+            <td><input type="text" value="" name="metades"></td>
           </tr>
           <tr>
-            <td width='20%'>META Keywords</td>
-            <td><input type='text' value='' name='metakey'></td>
+            <td width="20%">META Keywords</td>
+            <td><input type="text" value="" name="metakey"></td>
           </tr>
         </table>
+
 TET;
 }
 // end /////////////////////////////////////
@@ -54,14 +55,14 @@
 $metaDes = $razorArray['meta'][$slab]['metades'];
 $metaKey = $razorArray['meta'][$slab]['metakey'];
 $formOutput=<<<TET
-        <table width='98%' border='0'>
+        <table width="98%" border="0">
           <tr>
-            <td width='20%'>META Description</td>
-            <td><input type='text' value='$metaDes' name='metades'></td>
+            <td width="20%">META Description</td>
+            <td><input type="text" value="$metaDes" name="metades"></td>
           </tr>
           <tr>
-            <td width='20%'>META Keywords</td>
-            <td><input type='text' value='$metaKey' name='metakey'></td>
+            <td width="20%">META Keywords</td>
+            <td><input type="text" value="$metaKey" name="metakey"></td>
           </tr>
         </table>
 TET;
@@ -71,8 +72,8 @@
 // blade - output xhtml META DATA //
 function xhtmlMetaData() {
    global $razorArray,$slabFlag;
-   echo "<meta name='description' content='".$razorArray['meta'][$slabFlag]['metades']."' />";
-    echo "<meta name='keywords' content='".$razorArray['meta'][$slabFlag]['metakey']."' />";
+   echo '<meta name="description" content="'.$razorArray["meta"][$slabFlag]["metades"].'" />';
+    echo '<meta name="keywords" content="'.$razorArray["meta"][$slabFlag]["metakey"].'" />';
 }
 // end /////////////////////////////
 
@@ -84,3 +85,4 @@
 // end ///////////////////////
 
 ?>
+

I don't care about PHP and my knowledge directly come from reading docs, so if you find any error please add a comment and I'll change my modifications accordingly.
Jiff
 
Posts: 15
Joined: Mon Jun 25, 2012 10:48 pm

Return to How-To's

Who is online

Users browsing this forum: No registered users and 1 guest

cron