Books: Using the Library Catalog Pluslet and file_get_contents

19 views
Skip to first unread message

Gavin

unread,
Oct 16, 2009, 5:30:44 PM10/16/09
to SubjectsPlus
I have been having fun trying out the sweet new jQuery-ified interface
for making guides, now that I have all my v0.8 data imported and
modified for v0.9. Almost makes me wish I was a librarian. ;)

The pluslet in the subject line wasn't working for me; even after I
set allow_url_open to "On" in my php.ini file, I was still getting:

Warning: file_get_contents(http://testserver.lib.cwu.edu/sp/assets/
fixed_pluslets/catalogsearch.html) [function.file-get-contents]:
failed to open stream: Connection refused in /usr/local/www/sp/control/
guides/guide_functions.php on line 367

While researching the problem w/ Google, I discovered that some
servers/networks are set up such that you can't use the php function
file_get_contents with the file parameter being a url that points to
the server that the call is being made from. I found that to be the
case in my setup, both on my test server and our primary webserver. To
test this (on my test server), I changed line 367 in sp/control/guides/
guide_functions.php from:

$pluslet .= file_get_contents ($AssetPath . "fixed_pluslets/" .
$local_file);

... to:

$pluslet .= file_get_contents ('http://www.lib.cwu.edu/sp/
assets/' . "fixed_pluslets/" . $local_file);

... so that it grabbed the catalogsearch.html from our primary web
server and that allowed the pluslet to work. But a better solutions,
since file_get_contents allows it, might be to use a file path instead
of a url for the file parameter:

$pluslet .= file_get_contents ("../../assets/fixed_pluslets/" .
$local_file);

I noticed that catalogsearch.html is the only one in the
fixed_pluslets directory that is .html and uses the file_get_contents
function to grab the content. Another way might be to use the php
include() function that is being used to get the contents of all the
other files in this directory, I dunno. What say you Andrew?

- Gavin

Andrew Darby

unread,
Oct 19, 2009, 10:18:08 AM10/19/09
to subjec...@googlegroups.com
Hi Gavin,

Thanks for the information about file_get_contents--I didn't know
that. Because both public and admin pages call this guide, and are at
different depths in the file system, you'll need to stick another else
in there to get the correct relative path (like it's done right above
in the code):

if ($action == "public") {
$pluslet .= file_get_contents ("../assets/fixed_pluslets/" . $local_file);
} else {
$pluslet .= file_get_contents ("../../assets/fixed_pluslets/" .
$local_file);
}

I haven't actually tested this, but I'm guessing this will be the
case. As for using file_get_contents vs. the include, using the
latter on HTML files would just plunk the HTML snippet at the top of
the page, rather than storing it in the variable $pluslet to be used
later.

I was thinking that libraries might add their own HTML or PHP "fixed"
pluslets later, and ideally, that once created, these could be shared.
An obvious one is a meebo or chat pluslet. Mind you, I need to post
a "howto add new fixed pluslets" on the wiki . . . .

Anyway, if that code block above works in your environment, let me
know, and I'll update the distributed zip.

Andrew

Gavin

unread,
Oct 19, 2009, 5:47:41 PM10/19/09
to SubjectsPlus
Yes sir, yer code is better as I noticed guide.php calls the same
function. It works great.

And you're 100% correct about include vs. file_get_contents... I don't
know what I was thinking. It was a long week I suppose. ;)

Yeah, adding custom pluslets would be way cool! I like the available
ones so far too. It gives our users here more than enough to play
with. Thanks Andrew.

- Gavin

On Oct 19, 7:18 am, Andrew Darby <agda...@gmail.com> wrote:
> Hi Gavin,
>
> Thanks for the information about file_get_contents--I didn't know
> that.  Because both public and admin pages call this guide, and are at
> different depths in the file system, you'll need to stick another else
> in there to get the correct relative path (like it's done right above
> in the code):
>
>                 if ($action == "public") {
>                         $pluslet .=  file_get_contents ("../assets/fixed_pluslets/" . $local_file);
>                 } else {
>                         $pluslet .=  file_get_contents ("../../assets/fixed_pluslets/" .
> $local_file);
>                 }
>
> I haven't actually tested this, but I'm guessing this will be the
> case.  As for using file_get_contents vs. the include, using the
> latter on HTML files would just plunk the HTML snippet at the top of
> the page, rather than storing it in the variable $pluslet to be used
> later.
>
> I was thinking that libraries might add their own HTML or PHP "fixed"
> pluslets later, and ideally, that once created, these could be shared.
>  An obvious one is a meebo or chat pluslet.  Mind you, I need to post
> a "howto add new fixed pluslets" on the wiki . . . .
>
> Anyway, if that code block above works in your environment, let me
> know, and I'll update the distributed zip.
>
> Andrew
>
Reply all
Reply to author
Forward
0 new messages