Help:

--- problem

My page generated via a template can't find some javascript.

---- setup

I am hosted on Apache 1.*

I have a folder containing many *.html containing content which I want to be
displayed in another style of page.

Suppose there is
foo/
foo/content1.html
...
foo/contentN.html
foo/content1.js
foo/template.html
foo/js1.js
foo/js2.js
foo/slick.css
foo/slick.php

The content might have it's own style and javascript parts

template.html
---
<HTML>
  <HEAD>
  <TITLE>:title:</TITLE>
  <LINK REL="stylesheet" HREF="slick.css" TYPE="text/css">
  <SCRIPT SRC="js1.js" LANGUAGE="JavaScript"></SCRIPT>
  <SCRIPT SRC="js2.js" LANGUAGE="JavaScript"></SCRIPT>
  :script: :style: :link:
  </HEAD>
  <BODY>
  <DIV ID="logo">Logo ...</DIV>
  <DIV ID="main">
        <DIV ID="links"><SCRIPT>/* navbar('js') */</SCRIPT></DIV>
        <DIV ID="content">:content:</DIV>
  </DIV>
  <DIV ID="copyright">Copyright ...</DIV>
  </BODY>
</HTML>
---

slick.css
---
div#logo { background: #AAA }
div#content { background: #DDD }
div#links { background: #CCC }
div#copyright { background: #EEE }
---

content1.html
---
<HTML>
<HEAD>
  <TITLE>Content 1</TITLE>
  <SCRIPT SRC="content1.js" LANGUAGE="JavaScript"></SCRIPT>
</HEAD>
<BODY>
  <H1>Content is king</H1>
  <SCRIPT LANGUAGE="JAVASCRIPT">
    helloFromContent1()
  </SCRIPT>
</BODY>
</HTML>
---

content1.js
---
function helloFromContent1 () {
  document.write ('<P>Hello from content1.js</P>')
}
---

js1.js
---
alert ('js1 here')
---

js2.js
---
alert ('js2 here')
---

slick.php
---
<?
  list ($slash, $page) = explode ('/',  $HTTP_SERVER_VARS['PATH_INFO']);

  if (!file_exists ($page)) {
    header("HTTP/1.0 404 Not Found");
    echo ("<HTML><HEAD><TITLE></TITLE></HEAD><BODY><P>$page not
found.</P></BODY></HTML>");
    return;
  }

  $template = 'template.html';
  $template = implode ("", file ($template));

  $source = implode ("", file ($page));

  preg_match     ("|<HEAD.*?>(.*)?</HEAD>|is",    $source,  $head);  // i
insensitive, s newlines are a character
  preg_match     ("|<TITLE.*>(.*)?</TITLE>|is",   $head[1], $title);
  preg_match_all ("|(<SCRIPT.*?>.*?/SCRIPT>)|isU",$head[1], $script); // U
ungreedy
  preg_match_all ("|(<STYLE .*>.*/STYLE>)|isU",   $head[1], $style);
  preg_match_all ("|(<LINK .*>)|isU",             $head[1], $link);
  preg_match     ("|<BODY.*?>(.*)</BODY>|is",     $source,  $content);

  $title  = isset($title  [1]) ? $title[1] : '';
  $script = isset($script [1]) ? implode ($script[1]) : '';
  $style  = isset($style  [1]) ? implode ($style [1]) : '';
  $link   = isset($link   [1]) ? implode ($link  [1]) : '';
  $content= isset($content[1]) ? $content[1] : '';

  $html = preg_replace (
    array ("/:title:/", "/:style:/", "/:script:/", "/:link:/",
"/:content:/" )
  , array (  $title   ,   $style   ,   $script   ,   $link   ,   $content )
  , $template
  );

  echo $html;
?>
---

I can do
- site.com/info/template.html and get two alerts
- site.com/info/content1.html and see a new text under H1
- site.com/info/slick.php/content1.html and get neither alert nor new text.
  - instead I get 4 browser (IE) 'problem alerts', I presume
  - 1. for not finding js1.js
  - 2. for not finding js2.js
  - 3. for not finding content1.js
  - 4. for not finding helloFromContent1() function

I don't want to change my SRC references to be site absolute, I want them
relative.

Any ideas how I should 'wrap' my content using php and get functioning pages
?

Thanks

-- 
Richard A. DeVenezia

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to