PHP in a plugin

Creating and modifying plugins.
kehbop
Posts: 2
Joined: Mon Oct 15, 2007 10:10 pm

PHP in a plugin

Post by kehbop »

I want to put some PHP and HTML code in a plugin that will fetch the newest images from my coppermine album.

So basically, I want to make a custom plugin.

Will the html nugget work? How bout gutting a pre-existing plugin and replacing it with my own code?

Can someone tell me how to approach this?
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: PHP in a plugin

Post by garvinhicking »

Hi!

The HTML nugget is not for PHP code. You'll need to create your own plugin!

However, there is already a "Media sidebar" plugin that can output plugins from a gallery installation. Checkout serendipity_plugin_imagesidebar (on spartacus), this already has a coppermine_sidebar.php file that you might want to modify.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Nicola
Regular
Posts: 48
Joined: Wed May 25, 2005 5:08 pm
Contact:

simple PHP-include (for text-file) - Plugin a must?

Post by Nicola »

Hi!

May I add a related question?!

In this Page: http://www.shopanbieter.de/news/index.php

I would like to 'extract' the code parts of the main menue (top) as well as of the newsletter-box (right) into separate text-files as both are elements of the whole site and should be maintained in a central file (e.g. mainmenue.inc)

So I need to make something like this:
<? include('include/common_navi.php');?>

Only of course, this doesn't work. So do I really need to create plugins for this simple task? Isn't there some smarty-something that does a simple include or so?

Thanks for your hints (I did not really understand the plugin-concept as described here: http://www.s9y.org/78.html#A4, I'm more in HTML and only very very basic PHP, like 'include' ;-((

Nicola
carl_galloway
Regular
Posts: 1331
Joined: Sun Dec 04, 2005 5:43 pm
Location: Andalucia, Spain
Contact:

Post by carl_galloway »

You could use the smarty include function which is identical to the php version, for example {include file="file name"} where 'file name' is the .inc, or .tpl file
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: simple PHP-include (for text-file) - Plugin a must?

Post by garvinhicking »

Hi!

Check the "include_php" command from smarty. First you need to disable smarty security in your template's config.inc.php file:

Code: Select all

<?php
$serendipity['smarty']->security = false;
?>
to be able to use that inside your .tpl files.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Nicola
Regular
Posts: 48
Joined: Wed May 25, 2005 5:08 pm
Contact:

Re: simple PHP-include (for text-file) - Plugin a must?

Post by Nicola »

Hi to both of you!
garvinhicking wrote:Hi!
Check the "include_php" command from smarty. First you need to disable smarty security in your template's config.inc.php file:
I read about that at the mentioned page. And dismissed this option
because I fear, that this means that ma project then be somehow
'insecure'... Is it?

Greetings
Nicola
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: simple PHP-include (for text-file) - Plugin a must?

Post by garvinhicking »

Hi!

Well, it's the only way. If you want to include a foreign piece of code (which your header/footer is), you can only do it that way, or not include it at all. :)

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Nicola
Regular
Posts: 48
Joined: Wed May 25, 2005 5:08 pm
Contact:

Re: simple PHP-include (for text-file) - Plugin a must?

Post by Nicola »

Hi!
garvinhicking wrote: in your template's config.inc.php file:
Seems, I'm to dumb or to blind ;-( Where do I find this file? It's
NOT in _my_ Template-Folder (nor in one of the others like "default",
as I can see). Nor can I find it somewhere else. Not a
"config.inc.php", nor a
"config.inc.php.file" (as written on http://www.s9y.org/78.html#A4,
but that's a mistake, is it? Just wanted to be sure about the name...)

Should I create such a file? Inside my Template-Folder and/or
any template folders, I've have (I use an nother template-style
for one special cathegory)?

TIA
Nicola
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: simple PHP-include (for text-file) - Plugin a must?

Post by garvinhicking »

Hi!

This file might not exist for your template. You can create the file, if it's not there.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Nicola
Regular
Posts: 48
Joined: Wed May 25, 2005 5:08 pm
Contact:

Re: simple PHP-include (for text-file) - Plugin a must?

Post by Nicola »

[quote="garvinhicking"]This file might not exist for your template. You can create the file, if it's not there./quote]

Thanks - works very well!

Regards
Nicola
Nicola
Regular
Posts: 48
Joined: Wed May 25, 2005 5:08 pm
Contact:

Re: simple PHP-include (for text-file) - Plugin a must?

Post by Nicola »

Nicola wrote: Thanks - works very well!
Just, that it breaks the RSS-Feed:

XML-Verarbeitungsfehler: XML-Deklaration nicht am Beginn von externer Entität
Adresse: http://www.shopanbieter.de/news/feeds/index.rss2
Zeile Nr. 1, Spalte 2: <?xml version="1.0" encoding="utf-8" ?>
-^
http://www.shopanbieter.de/news/feeds/index.rss2

How does the 'insecure-Mode' affect the RSS-Feeds? Can I have
my includes AND a proper RSS-Feed?

As we _need_ the RSS-Feeds, I will have to return to old
Version very soon, so if You want to have a look, please
hurry ;-(

Greetings
Nicola
Nicola
Regular
Posts: 48
Joined: Wed May 25, 2005 5:08 pm
Contact:

Re: simple PHP-include (for text-file) - Plugin a must?

Post by Nicola »

Hi!

Ok, what it does is this:

RSS-File 'normal' (=secure mode):
-----------------------------------------------
<?xml version="1.0" encoding="utf-8" ?>

<rss version="2.0"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:admin="http://webns.net/mvcb/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
-----------------------------------------------

RSS File with "insecure-mode":
-----------------------------------------------
<?xml version="1.0" encoding="utf-8" ?>

<rss version="2.0"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:admin="http://webns.net/mvcb/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
-----------------------------------------------

You see: It's a space that causes the problems...
Any idea, where this space comes from?
And - more important, how we get rid of it?

Thanks
Nicola
Nicola
Regular
Posts: 48
Joined: Wed May 25, 2005 5:08 pm
Contact:

Re: simple PHP-include (for text-file) - Plugin a must?

Post by Nicola »

Mist. You don't see the space ;-(

Believe me, it's here:

RSS File with "insecure-mode":
-----------------------------------------------
_<?xml version="1.0" encoding="utf-8" ?>

<rss version="2.0"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:admin="http://webns.net/mvcb/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
-----------------------------------------------
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: simple PHP-include (for text-file) - Plugin a must?

Post by garvinhicking »

Hi!

Make sure you don't have any spaces in your config.inc.php file - it comes from there.

regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Nicola
Regular
Posts: 48
Joined: Wed May 25, 2005 5:08 pm
Contact:

Re: simple PHP-include (for text-file) - Plugin a must?

Post by Nicola »

garvinhicking wrote:Make sure you don't have any spaces in your config.inc.php file - it comes from there.
true, there it was. *SIGH*

THANKS!
Nicola
Post Reply