Show source code?

Is it possible to create a button on a page that will show the source code of that page?


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Here’s a snippet that will do this.

To use, save this code into a file called whatever you like (dot) php.
Then on the page where you want to see source, create a link to
whatever you called this file, maybe source.php (use the external link
part of the Freeway Hyperlink palette to do this).

As long as your server supports opening files from other servers using
what are called stream wrappers (most PHP servers do) this will just
work. Note that any interpreted code will be stripped by the server
before the file is served up. So you couldn’t use this trick to lift
the uninterpreted PHP code from a server – even your own. If you want
to do that, you’ll need to extend this script quite a bit, and you’ll
need to think long and hard about how you do that as you would be
opening a major security hole if you don’t think about it clearly
enough.

Walter

On Sep 25, 2010, at 9:46 AM, twb716 wrote:

Is it possible to create a button on a page that will show the
source code of that page?


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Thanks, Walter! Didn’t see any snippets in your note?


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Sorry, I had a typo in the gist parser on Freewaytalk. It’s fixed now.


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Just revved the Gist to show a way to get the source of a file in your
own filesystem, in which case PHP could safely highlight the source
code and show it to you. If you make a link to the file you want to
show like this:

source.php?src=some_file.php

then the source of some_file.php would be shown, assuming that file
was in the same folder as source.php. If you wanted to traverse
directories, then you would need to be sure that the file you’re
reading is lower in the filesystem hierarchy than the source.php file.
So you could look for source.php?src=foo/bar/baz/blah.php but you
couldn’t look at source.php?src=/etc/passwd or the like.

Walter

On Sep 25, 2010, at 12:52 PM, waltd wrote:

Sorry, I had a typo in the gist parser on Freewaytalk. It’s fixed now.


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Thanks, Walter! Any way to use this code snippet to generate an embed code from the current page? Thanks again.

TB


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

I’m not sure what you’re after here. Can you say a little more about
what you are trying to accomplish?

The script I posted is little more than a gussied-up version of the
View Source command found in any Web browser. All it does is take the
requested file, pass it through a PHP function which sanitizes it for
Web view (converting any special characters which might make the
server do something specific into their HTML entity equivalents) and
format it for view on screen.

When you want to take that code and convert it into an “embed”, what
form do you want that to take, exactly?

Are you looking to strip off the HTML, HEAD, and BODY tags, and retain
the contents of the BODY as the only source on screen? That’s what the
PHP Make Insert Page Action does directly in Freeway, and that’s the
base level of what you would do to a normal Web page in order to make
it safe to insert into the DOM of another page.

Beyond that, you’d also want to ensure that any IDs in the insert page
are namespaced to avoid collisions with the IDs already in the parent
page. (Freeway is highly deterministic in its automatic ID assignment,
so it’s more than likely that two different pages would clash, and any
JavaScript which relied on having access to elements on the page would
fail in a difficult-to-diagnose manner.) I can’t recall if PMIP does
this, I am pretty sure it does for the PageDiv, but I don’t know if it
also does so for any children of that DIV.

If you could write a little story that illustrates your desired usage,
I could probably help you further with this.

Walter

On Sep 26, 2010, at 6:06 AM, twb716 wrote:

Thanks, Walter! Any way to use this code snippet to generate an
embed code from the current page? Thanks again.

TB


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Thanks so much, Walter. I am trying to design a promo system. Here’s what I am trying to accomplish:

  1. Using a WebYep menu, a user is able to create a new mini-page (300x300) that has preset content AND WebYep content in it.

  2. I would like that person to be able to embed the page that they have just created into Facebook, MySpace, etc. by just copying the code that is created from your script, thus eliminating the need to manually create a different page for the same purpose.

Basically, I’d like to have an “Embed” box similar to the ones located on YouTube video pages that people can copy the code from into a site of their choice. Obviously, all of the images and text would have to not only be dynamic resulting from WebYep, but also must have absolute URLs, since the promo system will obviously be sitting on a different server than Facebook, MySpace, etc.

Thoughts? Please let me know if you need any more information. I truly appreciate you looking at this for me.

TB


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Sure, this could be done pretty simply. Make an example page, using WebYep, and post it somewhere online. It would be best if there was only one promo on the page. Also add a big textarea on the same page, but don’t hook up the form to anything. Then post a link. If I’m right, I think you can do this with fewer than ten lines of JavaScript – no php needed.

Walter


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Walter,

You really go above and beyond and I really appreciate it. Here is a link to a demo page that I have set up:

http://www.mmsies.com/test/promotest/

This will be the template that is created when a user creates a new page using the WebYep Menu in their “control panel”.

I hope that I’ve set it up correctly in order for you to have a look. Please let me know if it needs adjustment. Thanks again.

TB


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Very close. Can you please group the entire element that you wish to
export, and give the group a definitive name, like ExportMe, in the
Inspector? It’s not completely clear from the source which parts of
the page belong together.

Walter

On Sep 27, 2010, at 10:30 AM, twb716 wrote:

Walter,

You really go above and beyond and I really appreciate it. Here is
a link to a demo page that I have set up:

http://www.mmsies.com/test/promotest/

This will be the template that is created when a user creates a new
page using the WebYep Menu in their “control panel”.

I hope that I’ve set it up correctly in order for you to have a
look. Please let me know if it needs adjustment. Thanks again.

TB


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Sorry about that. I have updated the demo:

http://www.mmsies.com/test/promotest/

Thanks.

TB


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

This is pretty simple. You do have a couple of things you will need to
fix before it will work, though. First, in your form elements at the
bottom of the page, you need to clean up the names and add IDs to the
button and textarea.

Click once on the textarea, and move in the Inspector to the Output
tab. There will be a field labeled Name, make sure the textarea is
named TextBox there. Then choose Item / Extended from the main menu,
make sure the textarea tab is selected, and add a new attribute:

  • Name: id
  • Value: TextBox

Then switch to the left-most tab of the Inspector, and change the
Title to something other than TextBox – make it TBHolder or something
useless like that.

On the Generate button, go through the same steps, adding the Name and
ID ‘generate’ and make sure the div that holds the button in your
layout has a different Title than the form field’s ID (otherwise
you’ll get a clash and this won’t work at all).

Finally, apply the Protaculous Action to the page, click on the top
Function Body button and paste in the following script:

$('generate').observe('click',function(evt){
	evt.stop();
	var text = $('ExportMe').innerHTML;
	text = text.gsub(/"Resources/,'"' + window.location.href +  

‘Resources’);
$(‘TextBox’).setValue(’

’ + text + ‘
’);
$(‘TextBox’).select();
});

That’s it. Note that the URL that this creates for the images will
only work if you are viewing this page online. It uses the current
document URL to work out the correct absolute path to the resources
folder.

Walter
On Sep 27, 2010, at 10:46 AM, twb716 wrote:

Sorry about that. I have updated the demo:

http://www.mmsies.com/test/promotest/

Thanks.

TB


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Forgot the second thing – where you have the “editable text here”
placeholder, you have nested an H1 tag inside a P tag, which isn’t
valid. Prototype may balk at this conjunction and refuse to create the
source code view, so you definitely need to fix this. Look at how you
have created this element in your Freeway layout, and try to remove
the outer paragraph, or failing that, remove the H1 creation from the
WebYep section and make the container P an H1.

Walter

On Sep 27, 2010, at 11:18 AM, Walter Lee Davis wrote:

This is pretty simple. You do have a couple of things you will need
to fix before it will work, though. First, in your form elements at
the bottom of the page, you need to clean up the names and add IDs
to the button and textarea.


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Walter,

You are the man. I don’t have a clue what the last post means, however. I added a WebYep Rich Text element from the “Insert” menu inside of an HTML div because I wanted to constrain the amount of text that can be entered in the box. I don’t have any idea about H1 or P or outer paragraphs. Was all of this added automatically?

Sorry to not have a clue…still learning.

TB


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Freeway always wraps an inline element with a P unless you tell it
otherwise. That goes for images or Action-items, anyway. It won’t wrap
an inline HTML box. It looks as though the Rich Text element took the
“bold large text” setting to mean H1 tag, and WebYep has no inkling of
the page that surrounds its output – it just outputs what you have
asked it to do.

You might want to ask Max if there’s a way around this problem.

One shortcut you could consider would be to use a plain text element
rather than a riche text element, then type a space before and after
that inline Action element and select all of the text and style it as
an H1 using the Styles palette. Then you maintain control over what
tag is output, while the user gets to change the words. I presume
there is a single-line plain text element in the WY canon you can use…

Walter

On Sep 27, 2010, at 11:53 AM, twb716 wrote:

Walter,

You are the man. I don’t have a clue what the last post means,
however. I added a WebYep Rich Text element from the “Insert” menu
inside of an HTML div because I wanted to constrain the amount of
text that can be entered in the box. I don’t have any idea about H1
or P or outer paragraphs. Was all of this added automatically?

Sorry to not have a clue…still learning.

TB


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Thanks again, Walter. I have sent him an email. I will let you know what he says.


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Also, when I embed the code (even without any WebYep elements), it only shows the alternate text- none of the visible elements. Thoughts?

http://www.mmsies.com/test/promotest/embed


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Yup. I can see where this is going. Here’s one of your image links:


And it needs to be this:

This is going to take a little work in the script to figure out the
correct base URL to add to the Resources.

Walter

On Sep 27, 2010, at 2:08 PM, twb716 wrote:

Also, when I embed the code (even without any WebYep elements), it
only shows the alternate text- none of the visible elements. Thoughts?

http://www.mmsies.com/test/promotest/embed


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Maybe this (untested):

$('generate').observe('click',function(evt){
    evt.stop();
    var text = $('ExportMe').innerHTML;
    var base = window.location.href.substring(0,window.location.href.lastIndexOf('/'));
    text = text.gsub(/"Resources/,'"' + base + '/Resources');
    $('TextBox').setValue('<div id="EmbedMe">' + text + '</div>');
    $('TextBox').select();
});

Walter


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options