You are not logged in.
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
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: 13Error: [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: 19Error: 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
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
That worked perfectly! Thanks!
Offline