<?php
/*
+------------------------------------------------------
| Write2Left
| (c) timdorr
| http://www.write2left.com
| hide@address.com
| See License.txt for license info
|------------------------------------------------------
| Script: post_break.php
| Description:
| A plugin to auto convert \n to <br> or <br />
| Created Aug-10-2003
+------------------------------------------------------
*/
if( !class_exists( 'PostBreaks' ) )
{
/* Class: PostBreaks
* Description:
* Converts linebreaks
*/
class PostBreaks
{
var $convert = -1;
function initialize( $post_id, $extra )
{
if( array_key_exists( 'convert_breaks', $extra ) )
{
if( $extra['convert_breaks'] == 1 )
$this->convert = 1;
else
$this->convert = 0;
}
}
function filter_post( &$title, &$body, &$extended )
{
if( $this->convert == 1 )
{
$body = str_replace( '<br />', "\n", $body );
$extended = str_replace( '<br />', "\n", $extended );
}
}
function filter_input( &$input )
{
if( $input['do_breaks'] == 1 )
{
$input['post_body'] = str_replace( "\n", '<br />', $input['post_body'] );
$input['post_extended'] = str_replace( "\n", '<br />', $input['post_extended'] );
}
}
function get_inputs()
{
}
function get_options()
{
global $W2L;
$retval = '<input type="hidden" name="do_breaks" value="0" />';
$retval .= '<input type="checkbox" name="do_breaks" value="1"';
if( !array_key_exists( 'do_breaks', $W2L->input ) )
{
if( $this->convert == 1 )
$retval .= ' checked';
}
else if( $W2L->input['do_breaks'] != 0 )
$retval .= ' checked';
$retval .= ' />Convert linebreaks<br />';
return $retval;
}
function store_saved( &$input, $extra, $new_id )
{
global $db;
$db->query( "INSERT INTO w2l_post_extra VALUES
( $new_id,
'convert_breaks',
'$input[do_breaks]' )" );
}
function update_saved( &$input, $extra )
{
global $db;
if( array_key_exists( 'convert_breaks', $extra ) )
$db->query( "UPDATE w2l_post_extra SET value='$input[do_breaks]'
WHERE post_id=$input[post_id]
AND name='convert_breaks'" );
else
$db->query( "INSERT INTO w2l_post_extra VALUES
( $input[post_id],
'convert_breaks',
'$input[do_breaks]' )" );
}
}
}
$this->post_plugins[] = new PostBreaks();
?>