Camen Design Forum

embedd youtube videos?

append delete Stephen

is there anyway to embedd a youtube video into a post for my forum?. as it would be cool to alow pepole post to add videos. its cool how you can post a link and it hyperlinks it thats awsome. but i am just wondering is there anyway to embedd the video?. :) thanks!

Reply RSS

Replies

append delete #26. Nikolai

Just remove the md5 function call:

%
<img src="/avatar/' . trim($node->nodeValue) . '.png" alt="" />
%
append delete #27. MS

thnx dude! and then the code for the default icon part.. :P

haha learning these things is hard. I almost got it right, but i missed the 'trim' part.

append delete #28. MS

I think it would be easier to make it so that if username.jpg doesnt exist, there would be no avatar printed at all. But as u can see, im having a hard time putting these things into a form of code.

if(file_exist).......

append delete #29. Martijn

Sorry, I was too busy celebrating my birthday last night.

First off all it might not be a wise idea to not use `md5`. NNF allows any symbols for names. This means I could make my name something like `../malware.php?ignore=` and the visitor’s browser will not load `/avatar/name.png` but `/malware.php?ignore=.png`. I would have broken out of the avatar directory and can make the browser load any file on your server.

Not cool. And that is ignoring the fact some symbols simply aren’t allowed in filenames or URLs, those will all give errors too.

Now for not showing any image if none exists on the server, here is some code. This is 100% untested, so if I have forgotten a semi-colon or something don’t put too much blame on me. You should get a pretty good idea of what I am doing here so you can fix any small issues yourself.

%
/* Put this in theme.php, inside the `theme_custom` function. */

	foreach ($template->query('.nnf_reply-author, #nnf_post-author') as $node) {
		// The file we want, md5 of the user name and the PNG extension:
		$filename = md5(trim($node->nodeValue)) . '.png';
		// The avatar directory on the server, I am assuming in the forum root:
		$avatardir = FORUM_ROOT . DIRECTORY_SEPARATOR . 'avatar' . DIRECTORY_SEPARATOR;
		// Test if the file exists in the directory:
		if (file_exists ($avatardir . $filename)) {
			$value = '<img src="/avatar/' . $filename . '" alt="" /> '
			       . $node->nodeValue;
			$node->nodeValue = '';
			$frag = $node->ownerDocument->createDocumentFragment();
			if (!@$frag->appendXML($value) || !@$node->appendChild($frag)) {
				throw new Exception("Invalid HTML");
			}
		}
	}
%
append delete #30. MS

The thing with the md5 is, that i have no clue what it is and how to convert usernames into md5 :) But huge thanks for the code!

append delete #31. Martijn

These things aren’t really easy to make by hand. You should let software handle it, e.g. if you build a script that lets people upload their own icons. Otherwise you can always use an online service such as md5.cz.

You could also use `hash('sha512', strtolower(trim($node->nodeValue)))` and you will get the same strings as are used in the ‘users’ directory. That will not help you in the creating of them, but at least you get a bit more order as you can compare to the user files.

append delete #32. MS

Hey im starting to learn something. Im trying to change the code to make it display a default avatar in case username.png doesnt exist. If such a .png doesnt exist, how do you point to a default .png -file to appear? im pretty comfortable with html but this is waaaay more complicated :P

append delete #33. Nikolai

Then you could alter the code above to:

%
/* Put this in theme.php, inside the `theme_custom` function. */

	foreach ($template->query('.nnf_reply-author, #nnf_post-author') as $node) {
		// The file we want, md5 of the user name and the PNG extension:
		$filename = md5(trim($node->nodeValue)) . '.png';
		// The avatar directory on the server, I am assuming in the forum root:
		$avatardir = FORUM_ROOT . DIRECTORY_SEPARATOR . 'avatar' . DIRECTORY_SEPARATOR;
		// Test if the file exists in the directory:
		if (!file_exists ($avatardir . $filename)) {
			$filename = 'default.png';
		}
		// Write the HTML for the avatar:
		$value = '<img src="/avatar/' . $filename . '" alt="" /> '
		       . $node->nodeValue;
		$node->nodeValue = '';
		$frag = $node->ownerDocument->createDocumentFragment();
		if (!@$frag->appendXML($value) || !@$node->appendChild($frag)) {
			throw new Exception("Invalid HTML");
		}
	}
%

I didn't change much except the layout of the code. As with previous version, it still checks for the avatar of the user, but now falls back to the default one. The default avatar is named `default.png`, and should be in the avatar directory.

append delete #34. MS

I got this working, but for the basic understanding of the code structure, ill need to start studying hard.

Thank you guys so much!

append delete #35. dummy

Hi @Martijn

I already add this code to my theme.php but my forum still cannot embed youtube video.
Anything I need to alter / add ?

%
/* Put this in theme.php, inside the `theme_custom` function. */

	foreach ($template->query('.nnf_reply-author, #nnf_post-author') as $node) {
		// The file we want, md5 of the user name and the PNG extension:
		$filename = md5(trim($node->nodeValue)) . '.png';
		// The avatar directory on the server, I am assuming in the forum root:
		$avatardir = FORUM_ROOT . DIRECTORY_SEPARATOR . 'avatar' . DIRECTORY_SEPARATOR;
		// Test if the file exists in the directory:
		if (file_exists ($avatardir . $filename)) {
			$value = '<img src="/avatar/' . $filename . '" alt="" /> '
			       . $node->nodeValue;
			$node->nodeValue = '';
			$frag = $node->ownerDocument->createDocumentFragment();
			if (!@$frag->appendXML($value) || !@$node->appendChild($frag)) {
				throw new Exception("Invalid HTML");
			}
		}
	}
%
append delete #36. Martijn

@dummy the code you show there is just for adding avaatars for posters, and has nothing to do with YouTube. You probably want to try the code from reply #22: https://forum.camendesign.com/embedd_youtube_videos_+1#24b46l14pukd

Reply

(Leave this as-is, it’s a trap!)

There is no need to “register”, just enter the same name + password of your choice every time.

Pro tip: Use markup to add links, quotes and more.

Your friendly neighbourhood moderators: Kroc, Impressed, Martijn