plugins/Newsboy.php
changeset 12 62c594682bf6
parent 11 b0995e600bde
parent 10 0d52ee49c11c
child 13 4d8ce84092c9
equal deleted inserted replaced
11:b0995e600bde 12:62c594682bf6
     1 <?php
     1 <?php
     2 /*
     2 /*
     3 Plugin Name: Newsboy
     3 Plugin Name: Newsboy
     4 Plugin URI: javascript: // No URL yet, stay tuned!
     4 Plugin URI: http://enanocms.org/plugin/newsboy
     5 Description: Newsboy adds a news management system to Enano. It can integrate with the Feed Me plugin to provide an additional RSS feed. 
     5 Description: Newsboy adds a news management system to Enano. It can integrate with the Feed Me plugin to provide an additional RSS feed. 
     6 Author: Dan Fuhry
     6 Author: Dan Fuhry
     7 Version: 0.1
     7 Version: 0.1
     8 Author URI: http://www.enanocms.org/
     8 Author URI: http://enanocms.org/
     9 */
     9 */
    10 
    10 
    11 /*
    11 /*
    12  * Newsboy
    12  * Newsboy
    13  * Version 0.1
    13  * Version 1.1.2
    14  * Copyright (C) 2007 Dan Fuhry
    14  * Copyright (C) 2007 Dan Fuhry
    15  *
    15  *
    16  * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
    16  * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
    17  * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
    17  * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
    18  *
    18  *
   190       return;
   190       return;
   191     }
   191     }
   192   }
   192   }
   193 }
   193 }
   194 
   194 
   195 class Namespace_NewsBoy extends Namespace_Default
   195 // This is a 1.1.6-and-later thing.
   196 {
   196 
   197   public $perms;
   197 if ( class_exists('Namespace_Default') )
   198   
   198 {
   199   function __construct($a, $b, $c = 0)
   199   class Namespace_NewsBoy extends Namespace_Default
   200   {
   200   {
   201     global $db, $session, $paths, $template, $plugins; // Common objects
   201     public $perms;
   202     
   202     
   203     parent::__construct($a, $b, $c);
   203     function __construct($a, $b, $c = 0)
   204     $this->perms = $session->fetch_page_acl($this->page_id, $this->namespace);
   204     {
   205   }
   205       global $db, $session, $paths, $template, $plugins; // Common objects
   206   
   206       
   207   function send()
   207       parent::__construct($a, $b, $c);
   208   {
   208       $this->perms = $session->fetch_page_acl($this->page_id, $this->namespace);
   209     NewsBoy_namespace_handler($this);
   209     }
       
   210     
       
   211     function send()
       
   212     {
       
   213       ob_start();
       
   214       NewsBoy_namespace_handler($this);
       
   215       if ( ob_get_contents() == '' )
       
   216       {
       
   217         parent::send();
       
   218       } 
       
   219     }
   210   }
   220   }
   211 }
   221 }
   212 
   222 
   213 function NewsBoy_set_page_string()
   223 function NewsBoy_set_page_string()
   214 {
   224 {
   911           
   921           
   912           if ( count($errors) < 1 )
   922           if ( count($errors) < 1 )
   913           {
   923           {
   914             $publ = ( isset($_POST['published']) ) ? 1 : 0;
   924             $publ = ( isset($_POST['published']) ) ? 1 : 0;
   915             
   925             
   916             $result = PageUtils::createpage( (string)$time, 'NewsBoy', $name, $publ );
   926             $page = new PageProcessor((string)$time, 'NewsBoy');
       
   927             $page->create_page($name, $publ);
   917             
   928             
   918             if ( $result == 'good' )
   929             if ( $page->update_page($_POST['content'], 'Initial revision', false) )
   919             {
   930             {
   920               // Set content
   931               echo '<div class="info-box">Your changes have been saved.</div>';
   921               $content = RenderMan::preprocess_text($_POST['content'], true); // this also SQL-escapes it
       
   922               
       
   923               $q = $db->sql_query('UPDATE '.table_prefix.'page_text SET page_text=\'' . $content . '\' WHERE page_id=\'' . $time . '\' AND namespace=\'NewsBoy\';');
       
   924               if ( !$q )
       
   925                 $db->_die();
       
   926               
       
   927               if ( $result )
       
   928                 echo '<div class="info-box">Your changes have been saved.</div>';
       
   929               else
       
   930                 $errors[] = 'PageUtils::createpage returned an error.';
       
   931             }
   932             }
   932             else
   933             else
   933             {
   934             {
   934               $errors[] = 'PageUtils::createpage returned an error: ' . htmlspecialchars($result);
   935               while ( $err = $page->pop_error() )
       
   936               {
       
   937                 $errors[] = $err;
       
   938               }
   935             }
   939             }
   936             
   940             
   937             break;
   941             break;
   938           }
   942           }
   939         }
   943         }