plugins/Newsboy.php
changeset 10 0d52ee49c11c
parent 9 162b0f10e3d0
child 12 62c594682bf6
equal deleted inserted replaced
9:162b0f10e3d0 10:0d52ee49c11c
     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  *
    68   $session->acl_extend_scope('php_in_pages',           'NewsBoy', $paths);
    68   $session->acl_extend_scope('php_in_pages',           'NewsBoy', $paths);
    69   $session->acl_extend_scope('edit_acl',               'NewsBoy', $paths);
    69   $session->acl_extend_scope('edit_acl',               'NewsBoy', $paths);
    70   
    70   
    71 }
    71 }
    72 
    72 
    73 function NewsBoy_namespace_handler($page)
    73 function NewsBoy_namespace_handler(&$page)
    74 {
    74 {
    75   global $db, $session, $paths, $template, $plugins; // Common objects
    75   global $db, $session, $paths, $template, $plugins; // Common objects
    76   
    76   
    77   if ( defined('ENANO_FEEDBURNER_INCLUDED') )
    77   if ( defined('ENANO_FEEDBURNER_INCLUDED') )
    78   {
    78   {
   186       {
   186       {
   187         // can't find it.
   187         // can't find it.
   188         return;
   188         return;
   189       }
   189       }
   190       return;
   190       return;
       
   191     }
       
   192   }
       
   193 }
       
   194 
       
   195 // This is a 1.1.6-and-later thing.
       
   196 
       
   197 if ( class_exists('Namespace_Default') )
       
   198 {
       
   199   class Namespace_NewsBoy extends Namespace_Default
       
   200   {
       
   201     public $perms;
       
   202     
       
   203     function __construct($a, $b, $c = 0)
       
   204     {
       
   205       global $db, $session, $paths, $template, $plugins; // Common objects
       
   206       
       
   207       parent::__construct($a, $b, $c);
       
   208       $this->perms = $session->fetch_page_acl($this->page_id, $this->namespace);
       
   209     }
       
   210     
       
   211     function send()
       
   212     {
       
   213       ob_start();
       
   214       NewsBoy_namespace_handler($this);
       
   215       if ( ob_get_contents() == '' )
       
   216       {
       
   217         parent::send();
       
   218       } 
   191     }
   219     }
   192   }
   220   }
   193 }
   221 }
   194 
   222 
   195 function NewsBoy_set_page_string()
   223 function NewsBoy_set_page_string()
   893           
   921           
   894           if ( count($errors) < 1 )
   922           if ( count($errors) < 1 )
   895           {
   923           {
   896             $publ = ( isset($_POST['published']) ) ? 1 : 0;
   924             $publ = ( isset($_POST['published']) ) ? 1 : 0;
   897             
   925             
   898             $result = PageUtils::createpage( (string)$time, 'NewsBoy', $name, $publ );
   926             $page = new PageProcessor((string)$time, 'NewsBoy');
       
   927             $page->create_page($name, $publ);
   899             
   928             
   900             if ( $result == 'good' )
   929             if ( $page->update_page($_POST['content'], 'Initial revision', false) )
   901             {
   930             {
   902               // Set content
   931               echo '<div class="info-box">Your changes have been saved.</div>';
   903               $content = RenderMan::preprocess_text($_POST['content'], true); // this also SQL-escapes it
       
   904               
       
   905               $q = $db->sql_query('UPDATE '.table_prefix.'page_text SET page_text=\'' . $content . '\' WHERE page_id=\'' . $time . '\' AND namespace=\'NewsBoy\';');
       
   906               if ( !$q )
       
   907                 $db->_die();
       
   908               
       
   909               if ( $result )
       
   910                 echo '<div class="info-box">Your changes have been saved.</div>';
       
   911               else
       
   912                 $errors[] = 'PageUtils::createpage returned an error.';
       
   913             }
   932             }
   914             else
   933             else
   915             {
   934             {
   916               $errors[] = 'PageUtils::createpage returned an error: ' . htmlspecialchars($result);
   935               while ( $err = $page->pop_error() )
       
   936               {
       
   937                 $errors[] = $err;
       
   938               }
   917             }
   939             }
   918             
   940             
   919             break;
   941             break;
   920           }
   942           }
   921         }
   943         }