Following the documentation on shortcodes, I added a kfunctions.php to the root folder of my domain (http://example.com/kfunctions.php) in order to embed YouTube videos via shortcode in a rich textarea. The documentation states:
So I assume this refers to the website's root location and not the couchcms-folder.
Here is my kfunctions.php, which I adapted from the sample file. I simply deleted the functions I don't need:
Visiting http://example.com/kfunctions.php returns a 500 error and the shortcodes are literally printed in the content sections, i.e. the video is not embedded.
Any idea what is wrong?
With version 1.2, Couch has begun opening up its architecture to allow extending it. As a part of this initiative, Couch runtime now searches for a PHP file named kfunctions.php within the website managed by it (i.e. the main website folder - not the couch installation folder). If the file is found, Couch includes it within its execution flow.
So I assume this refers to the website's root location and not the couchcms-folder.
Here is my kfunctions.php, which I adapted from the sample file. I simply deleted the functions I don't need:
- Code: Select all
<?php
// 1.
// IFrame shortcode
// Usage: [iframe src="http://www.somesite.com/" width="100" height="100" scrolling="yes" frameborder="1" marginheight="2"]
$FUNCS->register_shortcode( 'iframe', 'iframe_handler' );
function iframe_handler( $params, $content=null ){
global $FUNCS;
extract( $FUNCS->get_named_vars(array(
'src' => '',
'width' => '100%',
'height' => '500',
'scrolling' => 'no',
'frameborder' => '0',
'marginheight' => '0'
), $params) );
$html =<<<EOS
<iframe src="$src" title="" width="$width" height="$height" scrolling="$scrolling" frameborder="$frameborder" marginheight="$marginheight">
<a href="$src" target="_blank">$src</a>
</iframe>
EOS;
return $html;
}
// 2.
// Google map shortcode
// Usage: [googlemap src="http://maps.google.com/?ll=23.250652,77.402072&spn=0.019912,0.038581&z=15"]
$FUNCS->register_shortcode( 'googlemap', 'googlemap_handler' );
function googlemap_handler( $params, $content=null ){
global $FUNCS;
extract( $FUNCS->get_named_vars(array(
'src' => '',
'width' => '425',
'height' => '350'
), $params) );
return '<iframe width="'.$width.'" height="'.$height.'" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="'.$src.'&output=embed"></iframe>';
}
// 3.
// YouTube Shortcode
// Usage: [youtube video="http://www.youtube.com/watch?v=5PsnxDQvQpw"]
// [youtube http://www.youtube.com/watch?v=1aBSPn2P9bg]
// [youtube 1aBSPn2P9bg]
$FUNCS->register_shortcode( 'youtube', 'youtube_handler' );
function youtube_handler( $params, $content=null ){
global $FUNCS;
extract( $FUNCS->get_named_vars(array(
'video' => 'http://',
'width' => '475',
'height' => '350',
), $params) );
// Video parameter is link or ID?
if ( (substr($video, 0, 7) == 'http://') || (substr($video, 0, 8) == 'https://') ){
/*
Example links that can be handled:
http://www.youtube.com/watch?v=5PsnxDQvQpw
http://youtube.com/watch?v=5PsnxDQvQpw
http://youtube.com/watch?gl=US&hl=en-US&v=5PsnxDQvQpw
http://youtube.com/v/5PsnxDQvQpw&rel=1
*/
if( !preg_match('#https?://(?:[^\.]+\.)?youtube.com.*(?:\?v=|&v=|/v/)([\w_-]+)#i', $video, $matches) ) return;
$video = $matches[1];
}
// Sanitize parameters
$video = htmlspecialchars( $video, ENT_QUOTES );
$width = (int)$width;
$height = (int)$height;
// Output HTML
$html =<<<EOS
<iframe class="youtube-player" type="text/html" width="$width" height="$height" src="http://www.youtube.com/embed/$video" frameborder="0"></iframe>
EOS;
return $html;
}
Visiting http://example.com/kfunctions.php returns a 500 error and the shortcodes are literally printed in the content sections, i.e. the video is not embedded.
Any idea what is wrong?