Hi, and happy holidays!
Now, this is over my head...
I've got a site on one physical server that serves a php/mysql-portal, some of the content is drawn from another physical server that runs lotus notes.
I've got a script that works, but is resource intensive to say the least, and it's pretty much hardcoded.
Looks like this:
code:
function getNotes($notesurl){
openTable();
//defines variables to use as part of url later on
$fileurl = "http://rohan/BullAB";
$fileurl2 = "http://rohan";
$baseurl = "http://rohan/";
$imgurl = "<img src=\"http://rohan/BullAB";
$imgurl2 = "<img src=\"http://rohan";
$imgurl3 = "<img src=\"http://rohan/";
//replaces wierd lotus-combinations in the url that will disrupt the getting of the file from notes
$notesurl = eregi_replace("<X>Open",'?Open',$notesurl);
$notesurl = eregi_replace("<Y>Search",'?Search',$notesurl);
$notesurl = eregi_replace("<Z>",'&',$notesurl);
$notesurl = eregi_replace("<A>",'/Intranet+document.nsf/',$notesurl);
$notesurl = eregi_replace("<B>",'/Telefoner+FAQ.nsf',$notesurl);
$notesurl = eregi_replace("<C>",'/IEDB+Docs.nsf',$notesurl);
$notesurl = eregi_replace("<D>",'/By+Category',$notesurl);
$notesurl = eregi_replace("/Intranet dokument.nsf/",'/Intranet+dokument.nsf/',$notesurl);
$notesurl = eregi_replace("/Telefoner FAQ.nsf",'/Telefoner+FAQ.nsf',$notesurl);
$notesurl = eregi_replace("/IEDB Docs.nsf",'/IEDB+Docs.nsf',$notesurl);
$notesurl = eregi_replace("/By Category",'/By+Category',$notesurl);
//just a check...
print($notesurl);
//get the file from notes
$nsfile = file("$baseurl$notesurl");
//loop through the file from notes and rebuild the urls since they will be shown from another machine
for($i=0; $i < count($nsfile);$i++){
//imagepaths...
$nsfile[$i] = eregi_replace('<IMG SRC="/BullAB',"$imgurl",$nsfile[$i]);
$nsfile[$i] = eregi_replace('<IMG SRC="/local',"$imgurl2/local",$nsfile[$i]);
$nsfile[$i] = eregi_replace('<IMG SRC="/idp',"$imgurl2/idp",$nsfile[$i]);
$nsfile[$i] = eregi_replace('<IMG SRC="idp',"$imgurl3idp",$nsfile[$i]);
$nsfile[$i] = eregi_replace('<IMG SRC="/Samm',"$imgurl2/Samm",$nsfile[$i]);
if(strstr($nsfile[$i],"\$FILE")==false){
//make links on page point to script
$nsfile[$i] = eregi_replace('<A HREF="/BullAB',"<A href=\"getnotes.php?noteslink=BullAB",$nsfile[$i]);
$nsfile[$i] = eregi_replace('<A HREF="http://rohan/BullAB',"<A href=\"getnotes.php?noteslink=BullAB",$nsfile[$i]);
$nsfile[$i] = eregi_replace('<A HREF="http://rohan/',"<A href=\"getnotes.php?noteslink=",$nsfile[$i]);
$nsfile[$i] = eregi_replace('<A HREF="http://infranet/local',"<A href=\"getnotes.php?noteslink=local",$nsfile[$i]);
$nsfile[$i] = eregi_replace('<A HREF="http://infranet',"<A href=\"getnotes.php?noteslink=",$nsfile[$i]);
$nsfile[$i] = eregi_replace('<A HREF="/local',"<A href=\"getnotes.php?noteslink=local",$nsfile[$i]);
$nsfile[$i] = eregi_replace('<A HREF="/idp',"<A href=\"getnotes.php?noteslink=idp",$nsfile[$i]);
$nsfile[$i] = eregi_replace('<A HREF="/Samm',"<A href=\"getnotes.php?noteslink=Samm",$nsfile[$i]);
$nsfile[$i] = eregi_replace('<A HREF="/Forsaljning',"<A href=\"getnotes.php?noteslink=forsaljning",$nsfile[$i]);
}else{
//correct other links
$nsfile[$i] = eregi_replace('<A HREF="/BullAB',"<A href=\"$fileurl",$nsfile[$i]);
$nsfile[$i] = eregi_replace('<A HREF="http://rohan/BullAB',"<A href=\"$fileurl",$nsfile[$i]);
$nsfile[$i] = eregi_replace('<A HREF="http://infranet/local',"<A href=\"$fileurl2/local",$nsfile[$i]);
$nsfile[$i] = eregi_replace('<A HREF="http://infranet',"<A href=\"$fileurl2/",$nsfile[$i]);
$nsfile[$i] = eregi_replace('<A HREF="/local',"<A href=\"$fileurl2/local",$nsfile[$i]);
$nsfile[$i] = eregi_replace('<A HREF="/idp',"<A href=\"$fileurl2/idp",$nsfile[$i]);
$nsfile[$i] = eregi_replace('<A HREF="/Samm',"<A href=\"$fileurl2/Samm",$nsfile[$i]);
$nsfile[$i] = eregi_replace('<A HREF="/forsaljning',"<A href=\"$fileurl2/forsaljning",$nsfile[$i]);
}
//if there is a searchform, make it open the result in new window
if(strstr($nsfile[$i],"ACTION")!=false){
$nsfile[$i] = eregi_replace('ACTION="/BullAB',"ACTION=\"$fileurl",$nsfile[$i]);
$nsfile[$i] = eregi_replace("SearchView",'SearchView" target="_blank"',$nsfile[$i]);
}
$nsfile[$i] = eregi_replace("/icons","$baseurl/icons",$nsfile[$i]);
$nsfile[$i] = eregi_replace("\?Open",'<X>Open',$nsfile[$i]);
//if no form, correct the urls so notes will recognize them
if(strstr($nsfile[$i],"ACTION")==false){
$nsfile[$i] = eregi_replace("\?Search",'<Y>Search',$nsfile[$i]);
}
$nsfile[$i] = eregi_replace("&",'<Z>',$nsfile[$i]);
$nsfile[$i] = eregi_replace("/Intranet+dokument.nsf/",'<A>',$nsfile[$i]);
$nsfile[$i] = eregi_replace("/Telefoner+FAQ.nsf",'<B>',$nsfile[$i]);
$nsfile[$i] = eregi_replace("/IEDB+Docs.nsf",'<C>',$nsfile[$i]);
$nsfile[$i] = eregi_replace("/By+Category",'<D>',$nsfile[$i]);
//print the code to the page
print($nsfile[$i]);
}
closeTable();
}
print("<b>Följande information hämtas direkt från Lotus Notes.</b>");
//call the function recusivly for the links I've created in the script
getNotes("$noteslink");
(it's a hack and it eats the processor, I know, but this site is low traffic and sits alone on a server...)
So far so good, it works, but...
The thing is that as admins of the portal add new noteslinks, there will be new, strange combinations of databasenames in notes and so on that this hardcoded script doesn't handle, so I'll have to go in and add more lines...
In essence, there might be "+", " ", "&","?", "-", in the urls I encounter that I need to handle as I step into the script, and then reverse it so notes will recognise it as I call the path again...
I've tried using the same principle as above to replace just the offending_chars but that breaks everything totally except for the "&", that works. I've got a feeling that the ? and + and - means something special in the pattern matching since I have to escape them if they are alone or in the beginning, but if they are escaped, they won't be recognized in the string...
I don't know squat about regular expressions, perl or otherwise so I have no clue whatsoever on how to fix this.
Anyone have an idea?
I can't put up the page since it's on the intranet, but any tips are more than welcome.
Happy holidays!
/Dan
-{ a vibration is a movement that doesn't know which way to go }-