kure

the simple blogging engine

You are not logged in.

#1 2009-05-06 00:40:44

Fluffball
Member

Atom 2.0 Plugin

I finally found some time to finish the Atom 2.0 plugin that has been lurking on my harddisk for quite some time.

Features

* Autodetect (no link in sidebar)
* Works with IE7/8, FF 3.0, Opera 9.64 and Safari browsers
* Configuration trough admin panel
* Valid feed

Have fun!

:)     

Code:

<?php
  /**************************************************
   * Atom 2.0 Feed for Kure 0.7
   * Version: 0.1
   * Last change: 2009-06-05
   * Script by: Fluffball
   **************************************************/

  // Load configuraton file
  include('config/atom.php');

  // Display link in the browser's adress bar
  $rack['kure']['head'] = "<link rel='alternate' href='" . $atom['id'] . "/plugins/atom.php?feed=atom' type='application/atom+xml'/>";

  // Show link on plugin page
  $rack['admplugins']['listing'] = "
        Atom-feed plugin by Fluffball<br>Click <a href=?plugin=atom_config>here for configuration</a><br>";

  // Plugin admin
  if ($_GET[plugin] == "atom_config") {
      $rack['admplugins']['page'] = "
      <span class='pagesub'>atom feed configuration</span><br /><br />
      <form action='?plugin=atom_config' method='post'>
      <p><input type='text' size='30' name='id' value='" . $atom['id'] . "' />
      <label for='id'> full URL of your website (http://www.yoururl.com)</label></p>
      <p><input type='text' size='30' name='title' value='" . $atom['title'] . "' />
      <label for='title'> site title</label></p>
      <p><input type='text' size='30' name='subtitle' value='" . $atom['subtitle'] . "' />
      <label for='subtitle'> sub title or slogan</label></p>
      <p><input type='text' size='30' name='name' value='" . $atom['name'] . "' />
      <label for='name'> author name</label></p>
      <p><input type='text' size='30' name='email' value='" . $atom['email'] . "' />
      <label for='email'> author e-mail address</label></p>
      <p><input type='text' size='30' name='exerptLen' value='" . $atom['exerptLen'] . "' />
      <label for='exerptLen'>exerpt length (200 - 300)</label></p>
      <p><input type='submit' name='saveSettings' value='submit'/></p>
      </form>";
  }
  // Save settings
  if (isset($_POST['saveSettings'])) {
      $cfg = array('id' => $_POST['id'], 'title' => $_POST['title'], 'subtitle' => $_POST['subtitle'], 'name' => $_POST['name'], 'email' => $_POST['email'], 'exerptLen' => $_POST['exerptLen']);

      if (set_config("atom", $cfg))
          $rack['admplugins']['page'] = "Config changed.";
      else
          $rack['admplugins']['page'] = "ERROR: Config could not be written.";
  }

  // If feed is requested
  if ($_GET[feed] == "atom") {
      // get the current date & time
      $now = date("D, d M Y H:i:s T");

      $output .= "<?xml version='1.0' encoding='utf-8'?>
<atom:feed xmlns:atom='http://www.w3.org/2005/Atom'>
    <atom:id>" . $atom['id'] . "</atom:id>
    <atom:title>" . $atom['title'] . "</atom:title>
    <atom:subtitle>" . $atom['subtitle'] . "</atom:subtitle>
    <atom:link href='" . $atom['id'] . "' rel='self'/>
    <atom:updated>" . $now . "</atom:updated>
    <atom:author>
        <atom:name>" . $atom['name'] . "</atom:name>
        <atom:email>" . $atom['email'] . "</atom:email>
    </atom:author>";

      $allposts = glob("../posts/*.txt");
      foreach ($allposts as $file) {
          $title = str_replace("../posts/", "", $file);
          $title = str_replace(".txt", "", $title);
          $uftitle = $title;
          $title = str_replace("_", " ", $title);
          $content = str_replace("\n", "<br />\n", file_get_contents($file));
          //$summary = strlen($content) > $atom['exerptLen'] ? substr($content, 0, $atom['exerptLen']) . "..." : $content;
          //$summary = htmlentities($summary);

          $output .= "
    <atom:entry>
        <atom:id>" . $atom['id'] . "?post=" . $uftitle . "</atom:id>
        <atom:title>" . $title . "</atom:title>
        <atom:updated>" . date("D, d M Y H:i:s T", filemtime($file)) . "</atom:updated>
        <atom:summary type='xhtml'>
            <div xmlns='http://www.w3.org/1999/xhtml'>
                " . $summary . "
            </div>
        </atom:summary>
        <atom:link href='" . $atom['id'] . "?post=" . $uftitle . "'/>
        <atom:content type='xhtml'>
            <div xmlns='http://www.w3.org/1999/xhtml'>
                " . $content . "
            </div>
        </atom:content>
    </atom:entry>";
      }
      $output .= "\n</atom:feed>";

      // Send output to browser
      header("Content-Type: application/rss+xml");
      echo $output;
  }
?>

Last edited by Fluffball (2009-05-06 01:43:37)

Offline

 

#2 2009-11-19 16:57:50

titaniumtux
Member

Re: Atom 2.0 Plugin

Hey Fluffball...I'm having difficulties with your plugin...where do I put it? In the plugins folder? The /plugins/config folder? I'm so confused...Your plugin keeps giving me errors in the plugin panel, but I want to be able to use it.


Primary machines: Everex StepNote SA2053T 2GB RAM Ubuntu/Firefox&Midori
Asus Eee PC t91 2GB RAM Ubuntu/Chromium
Server: Dell Inspiron 1300 1.25GB RAM Ubuntu/Epiphany/XAMPP (http://dubroy.servehttp.com); blog at http://dubroy.servehttp.com/blog

Offline

 

#3 2009-11-19 19:08:06

titaniumtux
Member

Re: Atom 2.0 Plugin

Ok, after going through the settings, the errors went away, however I am still having troubles. I can see the feed icon in the browser address bar, however clicking on it loads a blank. I am using your Kure v.0.7.1a, and I disabled the RSS plugin.

When I do save the settings, it gives me

Invalid datatype: write_value()

Last edited by titaniumtux (2009-11-19 19:17:08)


Primary machines: Everex StepNote SA2053T 2GB RAM Ubuntu/Firefox&Midori
Asus Eee PC t91 2GB RAM Ubuntu/Chromium
Server: Dell Inspiron 1300 1.25GB RAM Ubuntu/Epiphany/XAMPP (http://dubroy.servehttp.com); blog at http://dubroy.servehttp.com/blog

Offline

 

#4 2009-11-19 20:45:35

Fluffball
Member

Re: Atom 2.0 Plugin

Hi Joel,

PHP throws an error because it can't find the configuration file.

My fault, I should have checked if the file exists. :(

Code:

// Load configuration file
  if (file_exists('config/atom.php')){
  include('config/atom.php');
  }

About the invalid datatype: did you write enable the plugins folder after you installed Kure?

If not, chmod 775 /plugins and (if exists) /plugins/config and try again.

Fluff

Offline

 

#5 2009-11-20 05:18:59

titaniumtux
Member

Re: Atom 2.0 Plugin

Fluffball,

I tried your updated code, so it would spare me those nasty errors (you should test this fix to see if it really helps). It's not an appealing fix to me, because once I have an existing atom.php in the /plugins/config folder, I don't see the errors anyway.

I chmod 777'd all those files so that's not an issue (in fact I've done chmod 777 on all the files and folders in my kure folder and sub folders). Now when I try to save anything, I still get the same error. /plugins/config/atom.php will retain the info, but when I return to the Atom options in the plugin panel in the browser, everything is blank (this was not the case before).

Now when I click on the RSS icon in the address bar, it says

Not Found

The requested URL /plugins/atom.php was not found on this server.

Now, reverting to the original code

// Load configuraton file
include('config/atom.php');

I now see the text again on the Atom plugin configuration page in the browser. Not like this really matters, as long as the plugin works.

The problem is that the plugin doesn't really work in either case. I've even tried disabling the RSS plugin. When I click on the feed icon in the address bar, it will load a blank feed. I can add it to my feed reader, but it won't load any posts. I've even tried creating a new post since the addition of the atom plugin, but the feed still shoots blanks.

Can you please solve this? I don't need the plugin to be more polished for the admin, I just need it to use my posts as feed items. Thanks :)


Primary machines: Everex StepNote SA2053T 2GB RAM Ubuntu/Firefox&Midori
Asus Eee PC t91 2GB RAM Ubuntu/Chromium
Server: Dell Inspiron 1300 1.25GB RAM Ubuntu/Epiphany/XAMPP (http://dubroy.servehttp.com); blog at http://dubroy.servehttp.com/blog

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson