Page 1 of 1

Feeding blog topics into static html page

Posted: Fri Jun 02, 2006 3:13 pm
by neov
Could someone point me in the right direction to figure out how to do this? I thought it had something to do with the rss feed, but I can't seem to get things to come out right.

Thanks.

Re: Feeding blog topics into static html page

Posted: Fri Jun 02, 2006 4:08 pm
by garvinhicking
Hi!

You need to describe this more detailed. Do you mean with "static html page" something unrelated to your blog? Or you you mean a "static page" using the s9y static page plugin?

You have various options, like using the serendipity_event_backend plugin for using JS to show feed topics.

Or using an RSS Feed parser (PHP-tools are available) for your RSS Feeds.

Or using custom PHP code by using the serendipity_fetchEntries function (search the forum for that keyword).

Or using the serendipity_event_smartymarkup plugin and using {serendipity_fetchPrintEntries}. Read the www.s9y.org technical docs or search the forums for details on that.

Best regards,
Garvin

Posted: Fri Jun 02, 2006 4:27 pm
by neov
Garvin, I mean a static page unrelated to the blog itself. I have a feeling that requires the java plugin?

Posted: Fri Jun 02, 2006 6:02 pm
by neov
Okay, I'm trying the java plugin, but I can't seem to figure out how to set it up. I followed the directions in the readme file, but I'm missing something. Any ideas?

Posted: Sat Jun 03, 2006 3:44 pm
by neov
Has anyone else been successful in using the serendipity_event_backend plugin? I'm pretty sure it's what I want, but I can't seem to make it work. For example, the readme file says the script should looks something like this:

Code: Select all

<script src="http://blog.linux-stats.org/plugin/backend?details=1&category=s9y&num=30&order=DESC&date=1&dateformat=d.m.Y&time=1&timeformat=H:i"></script>
So, I tried to do something similar, using a category from the blog:

Code: Select all

<script src="http://www.neoutdoorvoice.com/blogs/plugins/backend?details=1&category=all&num=30&order=DESC&date=1&dateformat=d.m.Y&time=1&timeformat=H:i"></script>
I put both of the above into a page, and only get the first one:

http://www.neoutdoorvoice.com/blogfeedtest.html

Any ideas on what I'm doing wrong? Have I messed up something in the setup of the plugin?

Posted: Sun Jun 04, 2006 12:13 am
by garvinhicking
Hi!

You are just using the wrong URL; your Blog does not have URL Rewriting enabled, so you need to prefix the URL like this:

Code: Select all

http://www.neoutdoorvoice.com/blogs/index.php?/plugin/backend?details=1&num=30&order=DESC&date=1&dateformat=d.m.Y&time=1&timeformat=H:i
This should work.

Regards,
Garvin

Posted: Sun Jun 04, 2006 5:59 am
by neov
Hmmm...that's one I didn't try in the many, many tries I made. And, now that I see it, it's almost obvious.Image

Thanks again Garvin, you're a life saver! :D

Posted: Wed Jul 05, 2006 4:53 pm
by neov
I've run into another question on this subject. Is it possible to make the title show up in bold while the rest isn't?

Posted: Wed Jul 05, 2006 5:36 pm
by garvinhicking
Hi!

You would need to edit the plugin file for that.

Best regards,
Garvin

Posted: Wed Jul 05, 2006 7:58 pm
by neov
I'm assuming that means editing the serendipity_event_backend.php file, but I have no idea what to change when I look at it. If it was a .tpl file, or even a .css I might be able to figure it out, but the .php file has me stumped.

Here's what's in the serendipity_event_backend.php file if that's helpful:

Code: Select all

<?php

# (c) 2005 by Alexander 'dma147' Mieland, http://blog.linux-stats.org, <dma147@linux-stats.org>
# Contact me on IRC in #linux-stats, #archlinux, #archlinux.de, #s9y on irc.freenode.net

// Probe for a language include with constants. Still include defines later on, if some constants were missing
$probelang = dirname(__FILE__) . '/' . $serendipity['charset'] . 'lang_' . $serendipity['lang'] . '.inc.php';
if (file_exists($probelang)) {
    include $probelang;
}

include dirname(__FILE__) . '/lang_en.inc.php';

#########################################################################################


class serendipity_event_backend extends serendipity_event {

    var $debug;
	
    function introspect(&$propbag) {
        global $serendipity;

        $propbag->add('name',          PLUGIN_BACKEND_TITLE);
        $propbag->add('description',   PLUGIN_BACKEND_DESC);
        $propbag->add('requirements',  array(
            'serendipity' => '0.8',
            'smarty'      => '2.6.7',
            'php'         => '4.1.0'
        ));

        $propbag->add('version',       '0.1');
        $propbag->add('author',       'Alexander \'dma147\' Mieland, http://blog.linux-stats.org, dma147@linux-stats.org');
        $propbag->add('stackable',     false);
        $propbag->add('event_hooks',   array(
        									'external_plugin'         => true
        	)
		);
        $propbag->add('configuration', array(
        									'backendurl'
										)
		);
        $propbag->add('groups', array('FRONTEND_FULL_MODS'));
        $this->dependencies = array('serendipity_event_entryproperties' => 'keep');
    }

    function introspect_config_item($name, &$propbag)
    {
    	global $serendipity;
    	
        switch($name) {

            case 'backendurl' :
                $propbag->add('type', 'string');
                $propbag->add('name', PLUGIN_BACKEND_BACKENDURL);
                $propbag->add('description', PLUGIN_BACKEND_BACKENDURL_BLAHBLAH);
                $propbag->add('default', 'backend');
                
                break;
                
            default:
                    return false;
        }
        return true;
    }


    
    function generate_content(&$title) {
        $title = PLUGIN_BACKEND_TITLE;
    }

    function event_hook($event, &$bag, &$eventData) {
        global $serendipity;
		
        $hooks = &$bag->get('event_hooks');
        if (isset($hooks[$event])) {
            switch($event) {
                

                case 'external_plugin':
                	
                	
                	
                	$uri_parts = explode('?', str_replace('&', '&', $eventData));
                	
                    // Try to get request parameters from eventData name
                    if (!empty($uri_parts[1])) {
                        $reqs = explode('&', $uri_parts[1]);
                        foreach($reqs AS $id => $req) {
                            $val = explode('=', $req);
                            if (empty($_REQUEST[$val[0]])) {
                                $_REQUEST[$val[0]] = $val[1];
                            }
                        }
                    }


                    $req = trim($uri_parts[0]);

                    switch($req) {
                        case $this->get_config('backendurl'):
                        	
							if (!headers_sent()) {
								header('HTTP/1.0 200');
							}
                       		
                       		
                       		if (isset($_REQUEST['category']) && !empty($_REQUEST['category'])) {
                       			$category = trim(urldecode($_REQUEST['category']));
							} else {
								$category = '';
							}
                       		
                       		if (isset($_REQUEST['num']) && !empty($_REQUEST['num'])) {
                       			$num = intval(trim(urldecode($_REQUEST['num'])));
							} else {
								$num = 10;
                       		}
                       		
							$order = (strtolower(trim(urldecode($_REQUEST['order'])))=='asc' || 
									  strtolower(trim(urldecode($_REQUEST['order'])))=='desc' ?
									  trim(urldecode($_REQUEST['order'])) :
									  "DESC");
                       		
                       		
                       		$showdate = (intval(trim(urldecode($_REQUEST['date']))) >= 1 ?
									  1 : 0);
                       		
                       		$dateformat = (trim(urldecode($_REQUEST['dateformat']))!='' ?
									  trim(urldecode($_REQUEST['dateformat'])) :
									  "Y-m-d");
                       		
                       		$showtime = (intval(trim(urldecode($_REQUEST['time']))) >= 1 ?
									  1 : 0);
                       		
                       		$timeformat = (trim(urldecode($_REQUEST['timeformat']))!='' ?
									  trim(urldecode($_REQUEST['timeformat'])) :
									  "g:ia");
                       		
                       		$point = (trim(urldecode($_REQUEST['point']))!='' ?
									  trim(urldecode($_REQUEST['point'])) :
									  "");
                       		
                       		
                       		$details = (intval(trim(urldecode($_REQUEST['details']))) >= 1 ?
									  1 : 0);
                       		
                       		if ($category == "") {
								$entries = serendipity_fetchEntries(null, true, $num, false, false, 'timestamp '.$order, '', false, true);
							} else {
								$entries = serendipity_fetchEntries(null, true, $num, false, false, 'timestamp '.$order, 'c.category_name = \''.serendipity_db_escape_string($category).'\'', false, true);
							}
                       		
                       		for ($a=0, $maxa=count($entries); $a<$maxa; $a++) {
                       			
                       			if ($showtime == 1 && $showdate == 1)
                       				$date = date($dateformat." ".$timeformat, $entries[$a]['timestamp']);
								elseif ($showtime == 1)
                       				$date = date($timeformat, $entries[$a]['timestamp']);
								elseif ($showdate == 1)
                       				$date = date($dateformat, $entries[$a]['timestamp']);
								else
                       				$date = "";
								
								$entryurl = serendipity_archiveURL($entries[$a]['id'], $entries[$a]['title']);
								
                       			if ($details <= 0) {
                       				if ($date != "")
                       					$date = "[".$date."] ";
                       				echo "	document.write('".(trim($point)!=""?trim($point)." ":"").$date."<a href=\"".$entryurl."\">".addslashes($entries[$a]['title'])."</a><br />');\n";
								} else {
                       				
                       				
                       				echo "	document.write('<span class=\"blog_title\">".addslashes($entries[$a]['title'])."</span>');\n";
                       				
                       				echo "	document.write('<hr class=\"blog_hr\" />');\n";
                       				
                     				serendipity_plugin_api::hook_event('frontend_display', $entries[$a]);
                       		
                       				$entries[$a]['body'] = preg_replace('@(href|src)=("|\')(' . preg_quote($serendipity['serendipityHTTPPath']) . ')(.*)("|\')(.*)>@imsU', '\1=\2' . $serendipity['baseURL'] . '\4\2\6>', $entries[$a]['body']);
                       				
                       				$body = str_replace("\n", "", str_replace("\r\n", "", trim($entries[$a]['body'])));
                       				
                       				if (substr($body, strlen($body)-5, strlen($body)) == "<br />")
                       					$body = substr($body, 0, strlen($body)-5);
                       				
                       				if ($date != "")
                       					$date = " @ ".$date."";
                       				
                       				$body = str_replace("'", "\'", $body);
                       				
                       				echo "	document.write('<span class=\"blog_body\">".$body."</span>');\n";
                       				
                       				echo "	document.write('<hr class=\"blog_hr\" />');\n";
                       				
                       				echo "	document.write('<span class=\"blog_body\">".addslashes($entries[$a]['author'])."".$date." [<a href=\"".$entryurl."\">read original...</a>]</span><br /><br />');\n";
                       				
                       				
                       			}
                       		}
                       		
                            break;
                    }
                    return true;
                    break;
                    

            }
        }
        
        return true;
    }
    
    
}

/* vim: set sts=4 ts=4 expandtab : */

I'm guessing it has something to do with this part:

Code: Select all

echo "	document.write('".(trim($point)!=""?trim($point)." ":"").$date."<a href=\"".$entryurl."\">".addslashes($entries[$a]['title'])."</a><br />');\n";
Then again, I'm only guessing...

Can I get another hint Garvin? Please?

Posted: Wed Jul 05, 2006 9:41 pm
by garvinhicking
Hi!

That's right. Have a look on how the docoument.write from javascript outputs the different HTML tags.

Just play with it, edit stuff that is written there and you'll see what changes. That's the best way to learn :)

Best regards,
Garvin