1

(15 replies, posted in PunBB 1.2 discussion)

http://gophp5.org/projects

That's might interest punbb developers too.

Thanks for the good job

this is a modified version of the news generator created by Rickard.
this version will produce a navigation (only back and next) at the end of the page.

<?php
/***********************************************************************

  Copyright (C) 2002-2005  Rickard Andersson (rickard@punbb.org)

  This file is part of PunBB.

  PunBB is free software; you can redistribute it and/or modify it
  under the terms of the GNU General Public License as published
  by the Free Software Foundation; either version 2 of the License,
  or (at your option) any later version.

  PunBB is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  MA  02111-1307  USA

************************************************************************/
//This a modified version of hte News Generator created by Rickard Andersson
//Piero Orlando

// The forum from which we'll pull the news bits
$forum_id = 1;

// Number of news posts to include in the index
$num_posts_index = 5;

// Path to news item template
$template_path = PUN_ROOT.'plugins/AP_News_Generator/news.tpl';

// Directories in which plugin will save generated markup (must end with slash)
$output_dir_latest = PUN_ROOT.'plugins/AP_News_Generator/';
//no archive needed
//$output_dir_archive = PUN_ROOT.'plugins/AP_Share_Generator/archive/';

/***********************************************************************
                     DO NOT EDIT BELOW THIS LINE
/***********************************************************************/

// Make sure no one attempts to run this script "directly"
if (!defined('PUN'))exit;

// Tell admin_loader.php that this is indeed a plugin and that it is loaded
define('PUN_PLUGIN_LOADED', 1);
$count = $db->query('SELECT COUNT(id) FROM '.$db->prefix.'topics WHERE forum_id='.$forum_id.'AND moved_to IS NULL') or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error());
$Tot_records =  $db->fetch_row($count);
//echo $Tot_records[0];
$tot_pages = ceil($Tot_records[0] / $num_posts_index);
if (isset($_POST['gen_news'])){
    // Generate front page news
    require PUN_ROOT.'include/parser.php';
    // create the so many page as $tot_pages
    for ($i = 1; $i<= $tot_pages; $i++) {
    $first = ($i==1) ? 0 : (($num_posts_index*$i)-$num_posts_index); 
    
    //the query to pull out data from DB
    $result = $db->query('SELECT id, subject FROM '.$db->prefix.'topics WHERE forum_id='.$forum_id.' ORDER BY sticky DESC, posted DESC LIMIT '.$first.','.$num_posts_index) or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error());
    
    if (!$db->num_rows($result))
        message('There are no topics to generate news based on in forum with ID = '.$forum_id.'.');

    

    $news_tpl = file_get_contents($template_path) or error('Unable to open new item template '.$template_path.'. Make sure $template_path is correct', __FILE__, __LINE__);

    $fh = @fopen($output_dir_latest.'news'.$i.'.html', 'wb');
    if (!$fh)
        error('Unable to write news to '.$output_dir_latest.'main.html. Please make sure PHP has write access to the directory '.$output_dir_latest, __FILE__, __LINE__);
        
    while ($cur_topic = $db->fetch_assoc($result))
    {
        $result2 = $db->query('SELECT posted, poster, message, hide_smilies FROM '.$db->prefix.'posts WHERE topic_id='.$cur_topic['id'].' ORDER BY posted ASC LIMIT 1') or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error());
        $cur_post = $db->fetch_assoc($result2);

        $search = array('<news_subject>', '<news_posted>', '<news_poster>', '<news_message>', '<news_comments>');
        $replace = array(pun_htmlspecialchars($cur_topic['subject']), date('Y-m-d H:i', $cur_post['posted']), pun_htmlspecialchars($cur_post['poster']), parse_message($cur_post['message'], $cur_post['hide_smilies']), '<a href="'.$pun_config['o_base_url'].'/viewtopic.php?id='.$cur_topic['id'].'">Comments</a>');


        fwrite($fh, str_replace($search, $replace, $news_tpl));
    }
$previous = ($i>1) ? ("<a href=\"?page=news".($i-1)."\" title=\"Go back to previous page\"><< back</a>") : ($previous = ""); 
$next = ($i < $tot_pages) ? ("|  <a href=\"?page=news".($i+1)."\" title=\"Go to the next page\">next >></a>") : ($next ="");

fwrite($fh, "<div align='center'>$previous   $next</div>");
    fclose($fh);
}

    generate_admin_menu($plugin);

?>
    <div class="block">
        <h2><span>News Generator results</span></h2>
        <div class="box">
            <div class="inbox">
                <p>News generated.</p>
            </div>
        </div>
    </div>
<?php

}
else
{
    generate_admin_menu($plugin);

?>
    <div class="blockform">
        <h2><span>News Generator</span></h2>
        <div class="box">
            <form id="example" method="post" action="<?php echo $_SERVER['REQUEST_URI'] ?>&foo=bar">
                <div class="inform">
                    <fieldset>
                        <legend>Generate static news output</legend>
                        <div class="infldset">
                            <p>This plugin fetches posts from the specified forum and generates static markup for those posts based on the news item template.It outputs (<?=$tot_pages?>) pages like news1.html news2.html etc containing (<?=$num_posts_index ?>) post per page. the plugin create a navigation tool at the end of every page to move to forward and previous pages <strong>Look at the top of the PHP source code for this plugin to change the settings you see below.</strong></p>
                            <table class="aligntop" cellspacing="0">
                                <tr>
                                    <th scope="row">Fetch news from forum</th>
                                    <td><span><?php echo $forum_id ?></span></td>
                                </tr>
                                <tr>
                                    <th scope="row">No of posts for latest</th>
                                    <td><span><?php echo $num_posts_index ?></span></td>
                                </tr>
                                <tr>
                                    <th scope="row">Using template</th>
                                    <td><span><?php echo $template_path ?></span></td>
                                </tr>
                                <tr>
                                    <th scope="row">Saving latest news to</th>
                                    <td><span><?php echo $output_dir_latest ?></span></td>
                                </tr>
                                                            </table>
                            <div class="fsetsubmit"><input type="submit" name="gen_news" value="Generate news" tabindex="1" /></div>
                        </div>
                    </fieldset>
                </div>
            </form>
        </div>
    </div>
<?php

}
?>

the includer will look like this

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Includer</title>
</head>

<body>


    <?php 
    //example how to include inside your home page the news created by the modified News Generator.
    //Piero Orlando
    
    $News_Path = 'folder/';
    
    $page="news1";              //default page 
if(isset($_GET['page'])){      //page we get from our address bar
    $page=$_GET['page'];
    // this is to check the genuineness of the file included
    if($page!=basename($page) || !preg_match("/^[A-Za-z0-9\-_]+$/",$page) || $page=="index" || !file_exists($News_Path.$page.".html")){
  include('error.htm');//error page in case is not a genuine path
    exit(); //exit
        }
    }
    //if genuine include the page here 
    include($News_Path.$shares.'.html');
    ?>
</body>
</html>
Koos wrote:

But I think you meant how to insert a paragraph next to an image. I don't think this is possible without editing the parser.

I tried your suggestion of editing the include/parser.php file - but it did not work for me.

That's what I mean body.
Well if you change the parser.php like I said in previous post you'll get it but it's not enough becaue u need to set if you want to align the photo right center or left!

If I got time I'll work it out how to modify the parser too

Koos wrote:
beipink wrote:

A nice, very nice feature would be to put text next to the image, like in the magazines. To get that is quite easy, an example here below

Thanks for the idea - but it is already possible to to this. Just type your text right after inserting the code of the image - the text will then display next to the image.

How??

A nice, very nice feature would be to put text next to the image, like in the magazines. To get that is quite easy, an example here below

<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt.....
<img src="our_img.jpg" alt="info" align="left" >Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor 
invidunt.....</p>

To get the same in our forum, we need to edit  the file include/parser.php

    change this line:
$img_tag = '<img class="sigimage"  src="'.$url.'" alt="'.htmlspecialchars($url).'" />';

with this one below:
    $img_tag = '<img class="sigimage"  src="'.$url.'" alt="'.htmlspecialchars($url).'" align="left"  hspace="10" vspace="10" />';

note that (hspace="10" vspace="10") add some space betwen the image and the text!

That's to give the Idea, but you won't like the image allways on the left, sometime you need to set align to  center or right. One way to  do that is educating the parser to read the align inside the img tag. another way maybe easyer to implement is to set a select when you post a new comment and you pass with the  form in a variable the instruction to set the align!

see ya
kirk

6

(10 replies, posted in PunBB 1.2 discussion)

Connorhd wrote:
beipink wrote:

PDO for PHP4 is also available, have look this classes here....
http://phpclasses.org/browse/package/2572.html

kirk

Its not supported by hosting companies though, so rather irrelevant

I just quote:
This package implements the PDO database abstraction interface that is compatible with PHP 4.

PDO is an extension introduced in PHP 5 that provides a common interface to several types of relational databases.

Since PDO only became standard extension with PHP 5.1 and very few hosting companies provide PHP 5.1 servers, the idea of this package is to provide an implementation of the PDO API that works under PHP 4 without special extension in a compatible way to the PHP 5 extension.

I can read in the way that hosting that support PHP4 have not istalled SQLite library ;-)
kirk

7

(10 replies, posted in PunBB 1.2 discussion)

PDO for PHP4 is also available, have look this classes here....
http://phpclasses.org/browse/package/2572.html

kirk

8

(13 replies, posted in Feature requests)

jimchen wrote:

In Fact, I had a testing forum which used SQLite3 DB that convert from SQLite2.
I just know a little php, so wrote an example php to test SQLite3 DB:

<?
$db = sqlite3_open("punbb.db3");
$query = sqlite3_query($db, "SELECT poster,message FROM posts");
if (!$query) die (sqlite3_error($db));
while ( ($row = sqlite3_fetch_array($query)) )
{
    echo $row['poster'], $row['message'];
    echo "\n";
}
sqlite3_query_close($query);
sqlite3_close ($db); 
?>

and it just work fine.

But PunBB just show a empty page when i try to change some code in include\dblayer\sqlite.php like this:
from
sqlite_xxx()
to
sqlite3_xxx()

I thought it should be easy for people that familiar with php convert to SQLite3. smile

the only way to acces sqlite3 is through PDO.

I did replace UNIX_TIMESTAMP() with PHP's time() and even with Timestamp taken from the db! I don't think the problem is the timestamp!!
thanks
Kirk

the follow query does not work with SQLite or at least I could not get it to work!

$result = $db->query('SELECT id, subject FROM '.$db->prefix.'topics WHERE forum_id='.$forum_id.' AND 
posted>=UNIX_TIMESTAMP(\''.$year_start.'-'.$month_start.'-01\') AND posted<UNIX_TIMESTAMP
(\''.$year_end.'-'.$month_end.'-01\') ORDER BY posted DESC') or error('Unable to fetch topic list', __FILE__, 
__LINE__, $db->error());

Is there anybody who got a solution to the issue?
thanks a lot
Kirk