Quote:
Originally Posted by JohnBee
I would like to publish the contents of a .txt file in a thread.
this way when there are updates to that .txt file say from a blog etc.
the thread would update as well.
Would this be hard to do?
The text would contain no formating but I don't want the left justifying
to happen, I have tested pasting a text file with basic formating using the
custom BB code option but when I click SUBMIT everything gets left
aligned
Is it feasible to produce a hack to do this?
|
If you give me an example of exactly what you want to do I could show you how to do it!
What I would do is have a simple tag that allows you to diplay the file where you want, like bbcode tag but something you only know. Then when a post is displayed and the that special tag is found it calls the function and the template that would be used to display the file output!
example...
:EDIT:
NOTE use the full path to the file and the file name
Code:
[include_file]my_file.txt[/include_file]
How to do it
open './includes/functions_bbcodeparse.php';
FIND THIS...
Code:
global $html_allowed;
REPLACE WITH
Code:
global $html_allowed, $post;
FIND THIS...
Code:
$bbcode = preg_replace($global_find, $global_replace, $bbcode);
BELOW IT ADD....
Code:
if ( ! $iswysiwyg )
{
/* place all the userids that can use this tag
*
* example userid 1, 4, 7 can use the tag
*
* $valid_users = array ( 1, 4, 7 );
*
*/
$valid_users = array ( 1 );
if ( stripos ( $bbcode, '[include_file]' ) !== false )
{
$post_ok = 0;
if ( ! empty ( $post['userid'] ) && in_array ( $post['userid'], $valid_users ) || ! empty ( $bbuserinfo['userid'] ) && in_array ( $bbuserinfo['userid'], $valid_users ) )
{
$post_ok = 1;
}
include_once ( './includes/functions_files.php' );
$bbcode = process_files ( $bbcode, $post_ok );
}
}
Now create a new file called 'functions_files.php'
place it in your './includes/' directory....
Put the following code in that file....
Code:
<?
function process_files ( $out, $ok )
{
if ( ( $s = stripos ( $out, '[include_file]' ) ) !== false )
{
$t = substr ( $out, 0, $s );
$u = substr ( $out, ( $s + 14 ) );
$v = stripos ( $u, '[/include_file]' );
$w = substr ( $u, 0, $v );
$x = substr ( $u, ( strlen ( $w ) + 15 ) );
if ( $ok )
{
$out = $t . do_file ( $w ) . $x;
}
else
{
$out = $t . $x;
}
$out = process_files ( $out, $ok );
}
return ( $out );
}
function do_file ( $path )
{
global $stylevar, $vbphrase;
$display = '';
if ( is_readable ( $path ) )
{
$data = fread ( fopen ( $path, 'r' ), filesize ( $path ) );
eval('$display .= "' . fetch_template ( 'my_files' ) . '";');
}
else
{
$display .= $vbphrase['invalid_file'];
}
return ( $display );
}
?>
Now create (2) new 'phrases'
Code:
phrase type: global
phrase name: invalid_file
phrase text: (file not found)
phrase type: global
phrase name: blog_title
phrase text: My Blog Information:
Then create a new template... template name 'my_files'
Code:
<div style="margin:20px; margin-top:5px">
<div class="smallfont" style="margin-bottom:2px">$vbphrase[blog_title]</div>
<pre class="alt2" style="margin:0px; padding:$stylevar[cellpadding]px; border:1px inset; width:$stylevar[codeblockwidth]; height:200px; overflow:auto"><div dir="ltr" style="text-align:left;">$data</div></pre>
</div>
All done...
Sonia