Announcement

Do not use the forums to submit bug reports, feature requests or patches, submit a New Ticket instead.

#1 2006-07-10 16:35:45

mjarrell
New member
Registered: 2006-07-10
Posts: 4

insertsnippet plugin PHP not working

I've tried altering the insertsnippet plugin, but the popup window stops working whenever I make any changes to snippets.html at all.

My ultimate goal is to get snippets.php to pull from a simple db table instead of an html file.  Here's my code:

<? 
  include("../../../includes/db.php");
?>
var snippets = new Array();
var i = 0;
<?php

/* function get_all_parts($string)
{
    preg_match_all('#<!--(.*?)-->(.*?)<!--/.*?-->#s',$string,$matches);
    
    $array=array();
    for ($i=0;$i<count($matches[1]);$i++)
    {
        $array[$matches[1][$i]] = $matches[2][$i];
    }
    return $array;
}
$snippets = file_get_contents('snippets.html');

$matches = get_all_parts($snippets); */

$query = "SELECT *
        FROM snippets
        ORDER BY snippetId";
$result = mysql_query($query) or die ("Query failed." . mysql_error());
while ($row = mysql_fetch_array($result)) {
    $snippetName = stripslashes($row['snippetName']);
    $snippet = stripslashes($row['snippet']);
    $matches["$snippetName"] = $snippet;
}

foreach ($matches as $name =>$html)
{
    print "snippets[i] = new Object();\n";
    print "snippets[i]['id'] = '$name';\n";
    print "snippets[i]['HTML'] = '".str_replace("\n",'\n',addcslashes($html,"'"))."';\n";
    print "i++;\n";
}

?>

Offline

#2 2006-07-12 12:46:07

ray
Xinha Administrator
From: Germany
Registered: 2005-03-23
Posts: 521
Website

Re: insertsnippet plugin PHP not working

Hi,
I can't tell what the problem is from what I see, I'd have to have a look at the page.
is there any error report in the js console?

Offline

#3 2006-07-12 13:04:25

mjarrell
New member
Registered: 2006-07-10
Posts: 4

Re: insertsnippet plugin PHP not working

I got the following from the js console:

Warning: function __dlg_init does not always return a value
Source File: http://localhost/dataManager/xinha/popups/popup.js
Line: 96
Source Code:
}

Warning: assignment to undeclared variable HTMLArea
Source File: http://localhost/dataManager/xinha/popups/popup.js
Line: 13

Error: [Exception... "Component is not available"  nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)"  location: "JS frame :: chrome://password/content/passwordOverlay.xul :: password :: line 19"  data: no]
Source File: chrome://password/content/passwordOverlay.xul
Line: 19

Error: unterminated string literal
Source File: http://localhost/dataManager/xinha/plugins/InsertSnippet/popups/insertsnippet.html
Line: 22, Column: 22
Source Code:
snippets[i]['HTML'] = '<table border="1" cellspacing="0" cellpadding="5">

Offline

#4 2006-07-12 14:50:40

ray
Xinha Administrator
From: Germany
Registered: 2005-03-23
Posts: 521
Website

Re: insertsnippet plugin PHP not working

Ok, the problem is that your html  contains linebreaks which is not possible in js variables. This should normally be taken care of by the str_replace("\n",'\n'... thing.
Maybe you have a different coding for the linebreaks (probably \r\n which is windows standard).
try it this way

print "snippets[i]['HTML'] = '".str_replace(array("\n","\r"),'\n',addcslashes($html,"'"))."';\n";

or

print "snippets[i]['HTML'] = '".preg_replace("/\r|\n/s",'\n',addcslashes($html,"'"))."';\n";

Last edited by ray (2006-07-12 14:54:53)

Offline

#5 2006-07-12 15:00:30

mjarrell
New member
Registered: 2006-07-10
Posts: 4

Re: insertsnippet plugin PHP not working

That worked perfectly!  Thanks!  smile

Offline

Board footer

Powered by FluxBB