plugins/Newsboy.php
changeset 17 f6edf51a9479
parent 16 3d96dbb770b5
child 18 8205e4ca237e
equal deleted inserted replaced
16:3d96dbb770b5 17:f6edf51a9479
    81   }
    81   }
    82   
    82   
    83   if ( $paths->namespace != 'NewsBoy' )
    83   if ( $paths->namespace != 'NewsBoy' )
    84     return;
    84     return;
    85   
    85   
    86   if ( $paths->cpage['urlname_nons'] == 'Portal' || preg_match('/^Archive(\/|$)/', $page->page_id) || preg_match('/^Article\//', $page->page_id) )
    86   if ( $paths->cpage['urlname_nons'] == 'Portal' || preg_match('/^Archive(\/|$)/', $page->page_id) )
    87   {
    87   {
    88     
    88     
    89     // Add admin opener Javascript function
    89     // Add admin opener Javascript function
    90     $template->add_header('<!-- NewsBoy: admin panel nav function -->
    90     $template->add_header('<!-- NewsBoy: admin panel nav function -->
    91     <enano:no-opt>
    91     <enano:no-opt>
   109         window.location = loc;
   109         window.location = loc;
   110       }
   110       }
   111     </script>
   111     </script>
   112     </enano:no-opt>');
   112     </enano:no-opt>');
   113     
   113     
   114     $x = getConfig('nb_portal_title');
   114     if ( !$page->perms->get_permissions('read') )
   115     
   115     {
   116     if ( $page->page_id == 'Portal' || $page->page_id == 'Archive' )
   116       $page->err_access_denied();
   117     {
   117       return false;
   118       $page_name = ( $page->page_id == 'Portal' ) ?
   118     }
   119             ( ( empty($x) ) ?
   119     
   120                 'Welcome to ' . getConfig('site_name') :
   120     $paths->cpage['comments_on'] = 0;
   121                 $x ) :
   121     
   122             'News Archive';
   122     if ( $page->page_id == 'Portal' )
   123       if ( method_exists($template, 'assign_vars') )
   123     {
       
   124       $template->header();
       
   125       NewsBoy_portal();
       
   126       $template->footer();
       
   127     }
       
   128     else if ( preg_match('/^Archive(\/|$)/', $page->page_id) )
       
   129     {
       
   130       $template->header();
       
   131       NewsBoy_archive();
       
   132       $template->footer();
       
   133     }
       
   134   }
       
   135 }
       
   136 
       
   137 // This is a 1.1.6-and-later thing.
       
   138 
       
   139 if ( class_exists('Namespace_Default') )
       
   140 {
       
   141   class Namespace_NewsBoy extends Namespace_Default
       
   142   {
       
   143     public $perms, $password, $send_headers;
       
   144     
       
   145     function __construct($page_id, $namespace, $revision = 0)
       
   146     {
       
   147       global $db, $session, $paths, $template, $plugins; // Common objects
       
   148       
       
   149       if ( preg_match('#^Article/#', $page_id) )
   124       {
   150       {
   125         $template->assign_vars(array(
   151         $timestamp = NewsBoy_resolve_article_url($page_id);
   126             'PAGE_NAME' => $page_name
   152         if ( $timestamp )
   127           ));
   153         {
       
   154           $page_id = strval($timestamp);
       
   155           $template->set_page($page_id, $namespace);
       
   156         }
       
   157       }
       
   158       
       
   159       parent::__construct($page_id, $namespace, $revision);
       
   160       $this->perms = $session->fetch_page_acl($this->page_id, $this->namespace);
       
   161       $this->build_cdata();
       
   162     }  
       
   163     
       
   164     function build_cdata()
       
   165     {
       
   166       if ( $this->page_id == 'Portal' || $this->page_id == 'Article' )
       
   167       {
       
   168         $config_title = getConfig('nb_portal_title');
       
   169         $this->cdata = array(
       
   170             'urlname' => $this->page_id,
       
   171             'namespace' => $this->namespace,
       
   172             'name' => $this->page_id == 'Portal' ? ( !empty($config_title) ? $config_title : "Welcome to " . getConfig('site_name') ) : 'News archive',
       
   173             'special' => 1,
       
   174             'comments_on' => 0,
       
   175             'protected' => 0,
       
   176             'wiki_mode' => 0,
       
   177             'visible' => 1,
       
   178             'delvotes' => 0,
       
   179             'delvote_ips' => ''
       
   180           );
       
   181         $this->cdata = Namespace_Default::bake_cdata($this->cdata);
       
   182         $this->title =& $this->cdata['name'];
   128       }
   183       }
   129       else
   184       else
   130       {
   185       {
   131         $template->tpl_strings['PAGE_NAME'] = $page_name;
   186         parent::build_cdata();
   132       }
   187       }
   133     }
   188     }
   134     
   189     
   135     if ( !$page->perms->get_permissions('read') )
   190     function set_conds()
   136     {
   191     {
   137       $page->err_access_denied();
   192       parent::set_conds();
   138       return false;
   193       if ( $this->page_id == 'Portal' || $this->page_id == 'Archive' )
   139     }
       
   140     
       
   141     $paths->cpage['comments_on'] = 0;
       
   142     
       
   143     if ( $page->page_id == 'Portal' )
       
   144     {
       
   145       $template->header();
       
   146       NewsBoy_portal();
       
   147       $template->footer();
       
   148     }
       
   149     else if ( preg_match('/^Archive(\/|$)/', $page->page_id) )
       
   150     {
       
   151       $template->header();
       
   152       NewsBoy_archive();
       
   153       $template->footer();
       
   154     }
       
   155     else if ( preg_match('/^Article\//', $page->page_id) )
       
   156     {
       
   157       if ( !preg_match('#^Article/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/(.+?)$#', $page->page_id, $id_match) )
       
   158       {
   194       {
   159         return;
   195         $this->conds['edit'] = false;
       
   196         $this->conds['password'] = false;
       
   197         $this->conds['clearlogs'] = false;
   160       }
   198       }
   161       // look around for this page
       
   162       // int mktime  ([ int $hour  [, int $minute  [, int $second  [, int $month  [, int $day  [, int $year  [, int $is_dst  ]]]]]]] )
       
   163       $timestamp_min = gmmktime(0, 0, 0, intval($id_match[2]), intval($id_match[3]), intval($id_match[1]));
       
   164       $timestamp_max = $timestamp_min + 86400;
       
   165       // mysql and postgresql friendly
       
   166       $integer_prepend = ( ENANO_DBLAYER == 'MYSQL' ) ? "unsigned" : '';
       
   167       $q = $db->sql_query('SELECT urlname, name FROM ' . table_prefix . "pages WHERE CAST(urlname AS $integer_prepend integer) >= $timestamp_min AND CAST(urlname AS $integer_prepend integer) <= $timestamp_max AND namespace = 'NewsBoy';");
       
   168       if ( !$q )
       
   169         $db->_die();
       
   170       if ( $db->numrows() < 1 )
       
   171         return;
       
   172       // found a page
       
   173       $found_match = false;
       
   174       while ( $row = $db->fetchrow($q) )
       
   175       {
       
   176         if ( sanitize_page_id($row['name']) === $id_match[4] )
       
   177         {
       
   178           $found_match = true;
       
   179           // we have a definitive match, send the page through
       
   180           $article = new PageProcessor($row['urlname'], 'NewsBoy');
       
   181           $article->send_headers = $page->send_headers;
       
   182           $article->password = $page->password;
       
   183           $article->send(true);
       
   184         }
       
   185       }
       
   186       if ( !$found_match )
       
   187       {
       
   188         // can't find it.
       
   189         return;
       
   190       }
       
   191       return;
       
   192     }
       
   193   }
       
   194 }
       
   195 
       
   196 // This is a 1.1.6-and-later thing.
       
   197 
       
   198 if ( class_exists('Namespace_Default') )
       
   199 {
       
   200   class Namespace_NewsBoy extends Namespace_Default
       
   201   {
       
   202     public $perms, $password, $send_headers;
       
   203     
       
   204     function __construct($a, $b, $c = 0)
       
   205     {
       
   206       global $db, $session, $paths, $template, $plugins; // Common objects
       
   207       
       
   208       parent::__construct($a, $b, $c);
       
   209       $this->perms = $session->fetch_page_acl($this->page_id, $this->namespace);
       
   210     }
   199     }
   211     
   200     
   212     function send()
   201     function send()
   213     {
   202     {
   214       ob_start();
   203       ob_start();
   221       $c = ob_get_contents();
   210       $c = ob_get_contents();
   222       ob_end_clean();
   211       ob_end_clean();
   223       echo $c;
   212       echo $c;
   224     }
   213     }
   225   }
   214   }
       
   215 }
       
   216 
       
   217 function NewsBoy_resolve_article_url($url)
       
   218 {
       
   219   global $db, $session, $paths, $template, $plugins; // Common objects
       
   220   
       
   221   if ( !preg_match('#^Article/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/(.+?)$#', $url, $id_match) )
       
   222   {
       
   223     return false;
       
   224   }
       
   225   // look around for this page
       
   226   // int mktime  ([ int $hour  [, int $minute  [, int $second  [, int $month  [, int $day  [, int $year  [, int $is_dst  ]]]]]]] )
       
   227   $timestamp_min = gmmktime(0, 0, 0, intval($id_match[2]), intval($id_match[3]), intval($id_match[1]));
       
   228   $timestamp_max = $timestamp_min + 86400;
       
   229   // mysql and postgresql friendly
       
   230   $integer_prepend = ( ENANO_DBLAYER == 'MYSQL' ) ? "unsigned" : '';
       
   231   $q = $db->sql_query('SELECT urlname, name FROM ' . table_prefix . "pages WHERE CAST(urlname AS $integer_prepend integer) >= $timestamp_min AND CAST(urlname AS $integer_prepend integer) <= $timestamp_max AND namespace = 'NewsBoy';");
       
   232   if ( !$q )
       
   233     $db->_die();
       
   234   if ( $db->numrows() < 1 )
       
   235     return false;
       
   236   // found a page
       
   237   $found_match = false;
       
   238   while ( $row = $db->fetchrow($q) )
       
   239   {
       
   240     if ( sanitize_page_id($row['name']) === $id_match[4] )
       
   241     {
       
   242       $found_match = true;
       
   243       // we have a definitive match, send the page through
       
   244       return $row['urlname'];
       
   245     }
       
   246   }
       
   247   if ( !$found_match )
       
   248   {
       
   249     // can't find it.
       
   250     return false;
       
   251   }
       
   252   return false;
   226 }
   253 }
   227 
   254 
   228 function NewsBoy_set_page_string()
   255 function NewsBoy_set_page_string()
   229 {
   256 {
   230   global $db, $session, $paths, $template, $plugins; // Common objects
   257   global $db, $session, $paths, $template, $plugins; // Common objects