HTML Logo by World Wide Web Consortium (www.w3.org). Click to learn more about our commitment to accessibility and standards.

Moving forward with Composr

ocPortal has been relaunched as Composr CMS, which is now in beta. ocPortal 9 will be superseded by Composr 10.

Head over to compo.sr for our new site, and to our migration roadmap. Existing ocPortal member accounts have been mirrored.


using PHP in the editor

Login / Search

 [ Join | More ]
 Add topic 
Posted
Rating:
#79527 (In Topic #16190)
Avatar

Fan in action

I have a small script i want to add in the page

on my statr page i want to add this:

Code

<!-- EDIT NOTHING ABOVE HERE! -->
<marquee bgcolor="#000000"direction="left"behavior="scroll"scroll="continuous"scrollamount="3"vspace="10"hspace="10"align="center"width="100%"height="28"style="font-size:24px;color:#00ff00;font-family:verdana;border:1px #fffff0 solid;">
<?php
include("/news/edit/news.txt");
?>
</marquee>
<!-- EDIT NOTHING BELOW HERE! -->

I can get the Marquee to work just fine, but i cannot figure out how to include the other pages text except with PHP…Can you help?
Back to the top
 
Posted
Rating:
#79529
Avatar

Community saint

I am no PHP-guru, but your 'include' call appears to be incomplete.

Where is the file lodged? If it is a folder off the root of your site, perhaps preceding the URL with {$BASE_URL} would give it a fighting chance to find the called file, e.g.

Code

include("{$BASE_URL}/news/edit/news.txt");

But I am sure there are other skilled coders who will pick up on this, so it might pay to wait a bit for somebody like temp or one of the staff to step in …

 :thumbs:

Take my advice. I'm not using it!

View my working ocPortal site (version 9.x.x) at Anglo-Indian Portal
Back to the top
 
Posted
Rating:
#79536
Avatar

Community saint

02/28/1962 said

but i cannot figure out how to include the other pages text except with PHP
Try replacing the php code with this:

Code

{$BLOCK,block=fileinclude,path={$BASE_URL_NOHTTP}/news/edit/news.txt}

Fletch said

I am no PHP-guru, but your 'include' call appears to be incomplete.
@02/28/1962 doesn't actually want a php solution  ;) .
Where is the file lodged? If it is a folder off the root of your site, perhaps preceding the URL with {$BASE_URL} would give it a fighting chance to find the called file, e.g.
@02/28/1962 has actually got it working so it is not a path issue.

In any case, {$BASE_URL_NOHTTP} should be used instead of {$BASE_URL} as php code is executed on the server, so http is redundant.

Do you have a Samsung Galaxy S / Galaxy S II ? If so, why not check out my ScreenFree FM Radio .
Back to the top
 
Posted
Rating:
#79537
Avatar

Is fileinclude.php your code temp1024?


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#79538
Avatar

Community saint

Good pickup Chris  :thumbs:

Yes, it is in my path, but I forgot that I wrote this block a looooong time ago (i.e. its not a standard block), so @02/28/1962 won't have it in his path  :$ .

@02/28/1962, in order for my {$BLOCK…} suggestion to work your will need to create a new file called \sources_custom\miniblocks\fileinclude.php with the following code:

Code (php)

<?php
        require_code('tempcode_compiler');
        $tempcode=template_to_tempcode(file_get_contents($map['path'],FILE_TEXT));
        echo $tempcode->evaluate();
 

Do you have a Samsung Galaxy S / Galaxy S II ? If so, why not check out my ScreenFree FM Radio .
Back to the top
 
Posted
Rating:
#79540
Avatar

Fan in action

the php code works with every other site i run it on, lol…
ok yes the file is located in a directory in the the base directory with the Base code, i need to modify the file location i know…was not worried about all that i can handle that part…i am having a problem making the actual <?php whatever ?> run on the page…it will run on the start page is pulls news from another part of the site that also runs the ticker.
the actual path is:

Code

<?php
include("baseUrl/chatrooms/news/edit/news.txt");
?>
Back to the top
 
Posted
Rating:
#79541
Avatar

Fan in action

wait…geez i got the wrong path up there i just noticed, that was when i was trying different ways to pull the news…the actual path that works on the Originating site is:

Code

<?php include ("Baseurl/chatrooms/newsservices.php");
?>
this page i could adddirectly into the base directory if that would be easier
Back to the top
 
Posted
Rating:
#79549
Avatar

Community saint

02/28/1962 said

… the php code works with every other site i run it on, lol…
Yeah, well …

One thing I know about ocPortal is that you are dealing not only with XHTML, but COMCODE and TEMPCODE, and that dictates how you input stuff.

Try this (adjusting any path irregularities that I've assumed from your previous posts):

Code

{+START,BOX,Chatroom News,100%,curved,}
[html]
<iframe id="crnews" name="crnews" title="crnews" src="{$BASE_URL}/chatrooms/newsservices.php" scrolling="auto" marginwidth="0" marginheight="0" frameborder="0" width="100%"></iframe>
[/html]
{+END}

I'm not familiar with temp's _NOHTTP assertion, mainly because I haven't edited any of my paths to reflect it, but the original {$BASE_URL} works for me at the moment.

 :thumbs:

Take my advice. I'm not using it!

View my working ocPortal site (version 9.x.x) at Anglo-Indian Portal
Back to the top
 
Posted
Rating:
#79550
Avatar

Community saint

02/28/1962 said

i am having a problem making the actual <?php whatever ?> run on the page
ocPortal doesn't allows for the direct use of  <?php within templates, so that's probably why it doesn't work.

The {$BLOCK…} example I gave would include text/html files ok (which is what I thought you wanted with your news.txt example), but will not execute arbitrary php code like newsservices.php that you want. So what you need instead is something like this:

Code

{$BLOCK,block=fileinclude,path={$BASE_URL_NOHTTP}/chatrooms/newsservices.php}
and a \sources_custom\miniblocks\fileinclude.php that contains:

Code (php)

<?php
    include($map['path']);
 
@Fletch

Fletch said

I'm not familiar with temp's _NOHTTP assertion, mainly because I haven't edited any of my paths to reflect it, but the original {$BASE_URL} works for me at the moment.
The reason you need the _NOHTTP version is that include() takes a file path and not a URL.

Do you have a Samsung Galaxy S / Galaxy S II ? If so, why not check out my ScreenFree FM Radio .
Back to the top
 
Posted
Rating:
#79551
Avatar

Community saint

temp1024 said

@Fletch
Thanks temp. Filed away in Swiss-cheese-type brain for future reference.

 :thumbs:

Take my advice. I'm not using it!

View my working ocPortal site (version 9.x.x) at Anglo-Indian Portal
Back to the top
 
Posted
Rating:
#79559
Avatar

Community saint

temp to the rescue again  ;)

It's remarkable to me that he knows and understands the ocPortal code so well. Heck, he's only been using the software for a year or so. I am looking forward to the day that we have four or five members with similar knowledge and ability. Things will really get interesting then.

Bob
Back to the top
 
Posted
Rating:
#79569
Avatar

Fan in action

Thanks Guys, i tried the one Fletch gave...it works but man is it ugly in the box, lol...but it did work...going to try the other now from Temp now...
Back to the top
 
Posted
Rating:
#79570
Avatar

Community saint

... dump the box!

Take my advice. I'm not using it!

View my working ocPortal site (version 9.x.x) at Anglo-Indian Portal
Back to the top
 
Posted
Rating:
#79571
Avatar

Fan in action

hey Temp…
why am i not closing the php tags
IE ?>
Back to the top
 
Posted
Rating:
#79572
Avatar

Community saint

02/28/1962 said

hey Temp…
why am i not closing the php tags
IE ?>
I'll steal temp's thunder … closing PHP tags is entirely optional if you’re coding a PHP-only file and there’s no intermingled HTM …  :devil:

Take my advice. I'm not using it!

View my working ocPortal site (version 9.x.x) at Anglo-Indian Portal
Back to the top
 
Posted
Rating:
#79573
Avatar

Community saint

02/28/1962 said

hey Temp…
why am i not closing the php tags
IE ?>
For php files it is common practice to just open it at the start of the file and not bother closing it.

In your first post you where embedding php into a html file, so it was necessary to close the tag.

In my example, all php is in a standalone file, so no closing of php tag is necessary.

EDIT: Fletch!!!!!!!!!!!!!!!! (  :thumbs:  )

Do you have a Samsung Galaxy S / Galaxy S II ? If so, why not check out my ScreenFree FM Radio .
Back to the top
 
Posted
Rating:
#79574
Avatar

Fan in action

ok…Temp if i run that in the Marquee ir screws up the page, it does scroll the marquee but it also scrolls the rest of the page inside the marquee, lol…if i run that with out the marquee it gives me a Errors…
i should mention.
newsservices.php creates the Marquee,
and calls the /chatrooms/news/edit/news.txt to fill it…if that makes sence.
thats why i gave you the wrong one the first time…i was by passing newsservice .php and trying to call the text directly, dont work either way…
the way fletch did it does work, but it is ugly, lol…
Back to the top
 
Posted
Rating:
#79575
Avatar

Community saint

What errors are you getting? Do you have a stack trace?

Do you have a Samsung Galaxy S / Galaxy S II ? If so, why not check out my ScreenFree FM Radio .
Back to the top
 
Posted
Rating:
#79576
Avatar

Fan in action

PHP WARNING [2] include(/chatrooms/newsservices.php) [<a href='PHP: include - Manual'>function.include.php</a>]: failed to open stream: No such file or directory in sources_custom/miniblocks/fileinclude.php on line 2 (version: 7.1.5, PHP version: 5.2.17, URL: /cms/index.php?page=cms_comcode_pages&type=__ed&wide=1)
 
Here is the stack trace: ECT.
Back to the top
 
Posted
Rating:
#79577
Avatar

Fan in action

now thats running the code you gave me strait paste in, no marquee , i took that out because newsservices.php builds it ...if i run that code in the Marquee it dont give an error, but is mangles the display, lol
Back to the top
 
There are too many online users to list.
Control functions:

Quick reply   Expand