Props and questions...

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
Martin
Regular
Posts: 90
Joined: Mon Sep 27, 2004 1:30 am
Location: Oslo
Contact:

Props and questions...

Post by Martin »

Firstly I'd like to thank you for an absolutelt beautiful piece of software (or scripting or whatchamacallit). I was practically tearing my hair out after trying to use Wordpress, BMachine and countless other alternatives that all turned out to be super-buggy or impossible to design for.

Now that's taken care of I do of course have some questions.

1: What should I edit to make s9y include a .html or .php page in the maincontent area without the blog-formatting? I'd like to have pages with photo-album, links or other content available from the sidebar, and I'd like to retain the sidebar there while it's showing.

2. Would there be any way for me to modify the admin area to contain for example the snippet of code necessary to launch a pop-up url? I found the code by reverse-engineering the "comment-popup code" from my browsers source window, but it's kind of a drag having to do that everytime.

3. Where do I find the code to modify the comments popup? My background image is making it fairly illegible.

Once again; I thank you for making s9y available, and for any answers you might provide.

-Martin
jasonr
Regular
Posts: 14
Joined: Thu Sep 23, 2004 4:57 am

I can answer one of them...

Post by jasonr »

1) HTML Nugget, you can have as many as you like, and are good for holding links. See www.i40.com for examples. The links on the left side of the page are in a html Nugget. and the google links are another nugget.

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

Re: Props and questions...

Post by garvinhicking »

Hi Martin!

First off, thanks for your praise. We highly appreciate that! :-)
1: What should I edit to make s9y include a .html or .php page in the maincontent area without the blog-formatting? I'd like to have pages with photo-album, links or other content available from the sidebar, and I'd like to retain the sidebar there while it's showing.
For this, you'd need to create your own plugin. We have a real powerful plugin-API, where you can assign any content you like pretty anywhere.

In your case, you would need to use the 'entry_display' hook in a plugin. This would look like:

Code: Select all

<?php

class serendipity_event_spamblock extends serendipity_event {
    function introspect(&$propbag) {
        global $serendipity;

        $propbag->add('name',          'My Photoalbum');
        $propbag->add('description',   'Show my Photoalbum');
        $propbag->add('event_hooks',    array('entry_display' => true));
    }

    function generate_content(&$title) {
        $title = 'Photoalbum';
        
        // Put your content here. It will be shown instead of an entry list in the
        // center of your page!
        include 'photoalbum.php';
    }

    function event_hook($event, &$bag, &$eventData, $addData = null) {
        global $serendipity;

        $hooks = &$bag->get('event_hooks');

        if (isset($hooks[$event])) {
            switch($event) {
                case 'entry_display':
                    if (!isset($serendipity['GET']['subpage']) || $serendipity['GET']['subpage'] != 'photoalbum') {
                        $title = '';
                        $this->generate_content($title);
                        $eventData['clean_page'] = true; // This is important to not display an entry list!
                    }
                    return true;
                    break;

                default:
                    return false;
                    break;
            }
        } else {
            return false;
        }
    }
}
/* vim: set sts=4 ts=4 expandtab : */
?>
Pay special attention to the $serendipity['GET']['subpage'] and the 'clean_page' variables. Those mean that if you open your blog with:

http://yourdomain/yourblog/index.php?se ... photoalbum

you will see the output of your plugin (which includes photoalbum.php). I hope this is what you're looking for.
2. Would there be any way for me to modify the admin area to contain for example the snippet of code necessary to launch a pop-up url? I found the code by reverse-engineering the "comment-popup code" from my browsers source window, but it's kind of a drag having to do that everytime.
You could use our bundled WYSIWYG-editor for this (htmlarea). It enables the easy addition of buttons with custom code to it. You could also either modify the serendipity_functions.inc.php file, function 'serendipity_printEntryForm', where s9y defines its own buttons. At that point you [or we ;)] could also place an plugin event hook, so that you can create a plugin which generates additional clickable buttons for any kind of custom code. However we can only insert that hook in a future release of serendipity, since the current 0.7 release is in feature freeze. But you could easily modify the code in that function like this:

Code: Select all

<?php
        /* Since the user has WYSIWYG editor disabled, we want to check if we should use the "better" non-WYSIWYG editor */
        if (!$serendipity['wysiwyg'] && eregi($serendipity['EditorBrowsers'], $_SERVER['HTTP_USER_AGENT']) ) {
?>
                        <input type="button" name="insI" value="I" accesskey="i" style="font-style: italic" onclick="wrapSelection(document.forms['serendipityEntry']['serendipity[body]'],'<i>','</i>')" />
                        <input type="button" name="insB" value="B" accesskey="i" style="font-weight: bold" onclick="wrapSelection(document.forms['serendipityEntry']['serendipity[body]'],'<b>','</b>')" />
                        <input type="button" name="insU" value="U" accesskey="u" style="text-decoration: underline;" onclick="wrapSelection(document.forms['serendipityEntry']['serendipity[body]'],'<u>','</u>')" />
<?php
serendipity_event_hook('backend_buttonlist', $serendipity);
?>
And then you could create a plugin which listens for the backend_buttonlist event and emoits simple <input> buttons like the other ones.

I hope you get what I mean, I don't know how much you are able to code. :-)
3. Where do I find the code to modify the comments popup? My background image is making it fairly illegible.
You can easily use CSS to style the popup window seperately, by using:

Code: Select all

#serendipity_comment_page {
background-image: url('non-illegibale-image.png');
}
Good luck and have fun exploring s9y,
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/
Martin
Regular
Posts: 90
Joined: Mon Sep 27, 2004 1:30 am
Location: Oslo
Contact:

Post by Martin »

Beautiful. This'll keep me busy for a while. :) It's actually my first attampt at PHP (except from fairly easy forum-moding) so I'm no hotshot as of yet. I sat up all night to modify the "Bunny Of The Day"-plugin so that the random image would link to pop-up version of itself.

Naturally though I do have some further questions.

1. Do I understand you correctly if I think you mean I need to make one Plug-in pr extra content page I want? The code at a glance seems to specify this one to be the photo-album for instance.
Also, just to make sure: After implementing this my link would be http://yourdomain/yourblog/index.php?se ... photoalbum as you suggest? (Naturally with my own settings...)

2. Whoa... I'll get on this one as well. Safari doesn't seem to be too fond of the wysiwyg-editor (although the only signal I get it's not working is the message apologizing in advance that it might not get it right.)

3. I guess I should have been able to figure that one out myself.
:oops:

Ok. I'll get on these little babies and naturally if anything fruitful comes out of it I'll let you partake of the code.

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

Post by garvinhicking »

Hi Martin!
1. Do I understand you correctly if I think you mean I need to make one Plug-in pr extra content page I want?
Not necessarily, no. You could use one plugin per sub-page, but you could also create a plugin which outputs different sections. You can just easily evaulate the $serendipity['GET']['subpage'] variable and display content defined therein.
2. Whoa... I'll get on this one as well. Safari doesn't seem to be too fond of the wysiwyg-editor (although the only signal I get it's not working is the message apologizing in advance that it might not get it right.)
Yeah. Safari sucks. ;) Use Mozilla! :-)

But as I pointed out, you could also easily use the "non-wysiwyg"-mode with the plugin/eventhook-method I talked about.
Ok. I'll get on these little babies and naturally if anything fruitful comes out of it I'll let you partake of the code.
Yeah, that would be cool. Thanks!

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/
Martin
Regular
Posts: 90
Joined: Mon Sep 27, 2004 1:30 am
Location: Oslo
Contact:

Post by Martin »

So...
Didn't take me long to get stuck on the first plug-in.
Here's a better explanation of the situation in the hope that someone will spot my (probably obvious) problem.

I took garvin's code and saved it in

Code: Select all

hastalasiesta.org/blog/plugins/serendipity_plugin_photoalbum/serendipity_plugin_photoalbum.php
I then tried to run the plugin manager just to see if s9y would recognize it at all, although I hadn't configured anything in the file itself. I get an error message saying "error serendipity_plugin_photoalbum".

My pictures and their respective php-files are located in

Code: Select all

hastalasiesta.org/bilder/foto/index.php
Which I tried specifying in the

Code: Select all

function generate_content(&$title) { 
        $title = 'Photoalbum'; 
        
        // Put your content here. It will be shown instead of an entry list in the 
        // center of your page! 
        include 'photoalbum.php'; 
but to no avail.

What I'm wondering is: When it says in the comment to "put my content here" does it refer to "in the file photoalbum.php" or "right here in this document"? Where does this script expect to find photoalbum.php, and can I customize this to be a folder outside my blogs home folder?

Is there any other obvious reason that this isn't working?
As stated I am fairly new to this so if there is a "Oh my god, haven't you remembered to i 'insert generic action everyone knows about here'"-solution to this I'm not all that surprised.

-m
[/code]
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi Martin!

I hope you adjusted the classname of the plugin? It should be class serendipity_plugin_photoalbum - not 'spamblock' like I pasted in my example :(

The "put content here" refers to either include a PHP file which holds your content, or you can also put any HTML/PHP code in the plugin itself. It's only a matter of what you prefer. :)

Good luck,
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/
Martin
Regular
Posts: 90
Joined: Mon Sep 27, 2004 1:30 am
Location: Oslo
Contact:

Post by Martin »

Actually I did do that. I guessed as much ;)

Problem is now solved. It seems copying from this browser window embellished the code with quite a lot of gremlins. The funny thing is that BBedit didn't catch them. It didn't even notice them. The solution was opening the file in Dreamweaver and running a find/replace command.

:)

-m
Martin
Regular
Posts: 90
Joined: Mon Sep 27, 2004 1:30 am
Location: Oslo
Contact:

Post by Martin »

Ok... We're getting there. Just a couple of more probs. :roll:

1. When I install the plugin it basically overrides the rest of the site. No matter what I attempt to load into the main content area the Photo-plugin will be what shows up. What should I do in the plugin code to make the plugin wait until a link such as the one you described is clicked before showing up?

2. The plugin seems awfully insistent on all links being relative to the serendipity home folder instead of my domains root. Is this the $serendipity tag making this decision? Can it be overridden?

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

Post by garvinhicking »

Hi Martin!

1. Maybe the $serendipity['GET']['subpage'] check is wrong? Can you post the source code of your current plugin somewhere?

2. You mean your programmed plugin? Which links to you mean?

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/
Martin
Regular
Posts: 90
Joined: Mon Sep 27, 2004 1:30 am
Location: Oslo
Contact:

Post by Martin »

1. Here goes

Code: Select all

 <?php 

 class serendipity_event_photoalbum extends serendipity_event { 
function introspect(&$propbag) { 
global $serendipity; 

$propbag->add('name','My Photoalbum'); 
$propbag->add('description', 'Show my Photoalbum'); 
     $propbag->add('event_hooks',  array('entry_display' => true)); 
   } 

   function generate_content(&$title) { 
     $title = 'Photoalbum'; 


          // Put your content here. It will be shown instead of an entry list in the 
     // center of your page! 
	include 'http://www.hastalasiesta.org/bilder/foto/index.php'; 
   } 

   function event_hook($event, &$bag, &$eventData, $addData = null) { 
     global $serendipity; 

     $hooks = &$bag->get('event_hooks'); 

     if (isset($hooks[$event])) { 
       switch($event) { 
         case 'entry_display': 
           if (!isset($serendipity['GET']['subpage']) || $serendipity['GET']['subpage'] != 'photoalbum') {
             $title = ''; 
             $this->generate_content($title); 
             $eventData['clean_page'] = true; // This is important to not display an entry list! 
           } 
           return true; 
           break; 

         default: 
           return false; 
           break; 
       } 
     } else { 
       return false; 
     } 
   } 
 } 
 /* vim: set sts=4 ts=4 expandtab : */ 
 ?> 
It's basically the code you posted above. What I suspect it needs (but have no idea how to accomplish) is a command that tells it only to go through with this if a certain link is clicked.

2.
My domain www.hastalasiesta.org
My blog is located in www.hastalasiesta.org/blog
I'm trying to get the plugin to address www.hastalasiesta.org/bilder/foto/index.html. While it manages to fetch this file all links in the file remains relative to www.hastalasiesta.org/blog instead of www.hastalasiesta.org.

Hmmm... I guess the key is to avoid relative linkage in external files...

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

Post by garvinhicking »

Hi Martin!

You are right, I think the plugin should be modified a bit. Try this:

Code: Select all

<?php

 class serendipity_event_photoalbum extends serendipity_event {
function introspect(&$propbag) {
global $serendipity;

$propbag->add('name','My Photoalbum');
$propbag->add('description', 'Show my Photoalbum');
     $propbag->add('event_hooks',  array('entry_display' => true));
   }

   function generate_content(&$title, $output = false) {
     $title = 'Photoalbum';
if ($output) {
          // Put your content here. It will be shown instead of an entry list in the
     // center of your page!
   include 'http://www.hastalasiesta.org/bilder/foto/index.php';
}
   }

   function event_hook($event, &$bag, &$eventData, $addData = null) {
     global $serendipity;

     $hooks = &$bag->get('event_hooks');

     if (isset($hooks[$event])) {
       switch($event) {
         case 'entry_display':
           if (!isset($serendipity['GET']['subpage']) || $serendipity['GET']['subpage'] != 'photoalbum') {
             $title = '';
             $this->generate_content($title, true);
             $eventData['clean_page'] = true; // This is important to not display an entry list!
           }
           return true;
           break;

         default:
           return false;
           break;
       }
     } else {
       return false;
     }
   }
 }
 /* vim: set sts=4 ts=4 expandtab : */
 ?>
(Note the new parameter to generate_content!)

2. You will need to adjust all links in your index.html to be absolute - there's no way around that. So index.html may not contain '<a href="album.htm">' bust must contain '<a href="/bilder/foto/album.htm">'. Because the links are not modified by serendipity, but interpreted by your browser which still thinks he resides in the /blog/ subdirectory.

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/
Martin
Regular
Posts: 90
Joined: Mon Sep 27, 2004 1:30 am
Location: Oslo
Contact:

Post by Martin »

Hmmm...
Still hijacking the page. :(

Tell me; which part of the code is it that tells the content area to load something different than usual into it? I wonder if this perhaps (from what I understand of the _plugin_ vs _event_ structure) should be a sidebar plugin instead of a event-plugin. IE a plugin called "External content" where you define the links in the admin area which are then loaded into the sidebar with the commands necessary to load content into the main area.

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

Post by garvinhicking »

The actual code part which does the inclusion is:

Code: Select all

switch($event) {
         case 'entry_display':
           if (!isset($serendipity['GET']['subpage']) || $serendipity['GET']['subpage'] != 'photoalbum') {
             $title = '';
             $this->generate_content($title, true);
             $eventData['clean_page'] = true; // This is important to not display an entry list!
           }
           return true;
           break; 
[code]

The generate_content() function is called and creates the output - you could also do your include there instead of calling generate_content. A very important setting is the 'clean_page' which tells s9y to not output its article listing!

And, an event plugin is the right thing to do, because the sidebar items do not influence the main content area...

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/
Post Reply