Problems, need help? Have a tip or advice? Post it here.
4 posts Page 1 of 1
Hello,
I hired an agency to develop a custom web page that has a part with Couch CMS only for posting updates.
Today i wanted to post a video, on other webpages i was doing this by simply going to "source" and pasting the youtube embed code. I try to do this on Couch but i get only the code as output. I also tried to add it as flash by uploading the video to the server but it said the file is too large.
I was reading a lot on the forum but as a beginner and a non programer i could not understand anything.
Can someone please simply explain if there is an opportunity to add video on Couch? And if yes, how can i do this in simple words and step-by-step explanations?
Hi,

I think using 'shortcode' would be the best method for you.
The details can be found at http://docs.couchcms.com/miscellaneous/shortcodes.html but it assumes some familiarity with PHP coding.

To make things easier for you, I'll list out the exact steps you need to take.

1. Please take a look in your installation's 'couch/addons' folder and see if there is a file named 'kfunctions.php' in there. If not, you'll definitely find another file named 'kfunctions.example.php' - rename this file to 'kfunctions.php'.

2. Next, in the file mentioned above, copy and paste the following code -
Code: Select all
// YouTube Shortcode
   // Usage:   [youtube video="http://www.youtube.com/watch?v=5PsnxDQvQpw"]
   //          [youtube https://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
         https://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="//www.youtube.com/embed/$video" frameborder="0"></iframe>
EOS;
      return $html;
   }

3. Final step - you need to do a little editing on the front-end template of your site that is being managed by Couch (i.e. that you are using to display the updates you mentioned). If you are unsure about which template this is, take a look at the URL of your relevant webpage - suppose, e.g., you see 'http://www.yoursite.com/news.php' the template is 'news.php'.

Open that template up in your text editor and try to locate the point where the content you enter in the admin-panel appears. You should see something like this -
<cms:show desc />

where 'desc' is the name of the editable-region that you enter content into from the admin-panel (this name would likely be different in your template; the 'desc' I used is just an example).

Once you find that statement, modify it as follows to surround it with the opening/closing <cms:do_shortcodes> tags
Code: Select all
<cms:do_shortcodes>
    <cms:show desc />
</cms:do_shortcodes>


And that is it. Now you can add a video into your contents by typing any of the following -
Code: Select all
[youtube video="http://www.youtube.com/watch?v=5PsnxDQvQpw"]
Code: Select all
[youtube https://www.youtube.com/watch?v=1aBSPn2P9bg]
Code: Select all
[youtube 1aBSPn2P9bg]

I think you can make out from the shortcodes above that we are using the ID of the video as seen in YouTube's URL for it.

Please try it and let us know how it goes.
Worked like a charm. Thank you very much for the detailed explanation. Hope this helps for others also.
Regards.
You are welcome. I am glad I could help :)
4 posts Page 1 of 1