View Single Post
  #2  
Old 05-03-2005, 12:19 PM
why-not why-not is offline
 
Join Date: Feb 2004
Posts: 218
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01319 seconds
  • Memory Usage 1,791KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (8)bbcode_code
  • (1)bbcode_quote
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • showpost_complete