We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 16545
    • 358 Posts
    I’ve got an error then trying to run with 2 or more Youtube snippets:
    Fatal error: Cannot redeclare getidfromurl() (previously declared in C:\xampp\htdocs\domain\manager\includes\document.parser.class.inc.php(769) : eval()'d code:130) in C:\xampp\htdocs\domain\manager\includes\document.parser.class.inc.php(769) : eval()'d code on line 138
      • 36592
      • 970 Posts
      Why don’t you modify the snippet like this ...
      <?php
      if(!function_exists('getIdFromUrl')) {
        function getIdFromUrl($url) {
          $url_parts = parse_url($url);
          parse_str($url_parts['query']);
          if(isset($v)) {
            return $v;	  
          } else {
            return false;	
          }
        }
      }
      ?>
      
        • 16545
        • 358 Posts
        Thx to tkfm, exacly what I looking for.

        This trick could be used in a new version.
          • 30585
          • 833 Posts
          Hi guys,

          I`m getting a blank page when I add 2 or more Youtube calls on the same page. I`ve tried tweaking the snippet as suggested by tkfm and I`m still getiing that problem. Can anyone help?

          Thanks
            A MODx Fanatic
            • 16545
            • 358 Posts
            Try to use one youtube link first....
              • 30585
              • 833 Posts
              Quote from: labasus at Feb 10, 2009, 03:18 AM

              Try to use one youtube link first....

              Thanks fo your time.

              You mean one call with &url as opposed to &id?

              I`ve tried both and they work like a charm. When you try to add a second call, the page goes blank.

              Any help?
                A MODx Fanatic
                • 16545
                • 358 Posts
                Try to replace you snippet code with this one

                <?php
                //SETTINGS
                $width = isset($width)?$width:425;
                $height = isset($height)?$height:350;

                // YouTube API settings
                $related = isset($related)?$related:true;
                $autoplay = isset($autoplay)?$autoplay:false;
                $loop = isset($loop)?$loop:false;
                $disablekb = isset($disablekb)?$disablekb:false;
                $egm = isset($egm)?$egm:false;
                $border = isset($border)?$border:false;
                $color1 = isset($color1)?$color1:’’;
                $color2 = isset($color2)?$color2:’’;

                // Javascript
                $js = isset($js)?$js:true;
                $swfobject_url = isset($swfobject_url)?$swfobject_url:’/assets/js/swfobject/swfobject.js’;
                $swfobject_express_url = isset($swfobject_url)?$swfobject_url:’/assets/js/swfobject/expressInstall.swf’;
                $missing = isset($missing)?$missing:’<p>This video requires the free Flash plugin.</p>’;

                // If a URL is supplied, work out the ID part of it
                if (isset($url) && $ytid = (getIdFromUrl(urldecode($url))) ) {
                // $ytid is already set
                } else if (isset($id)) {
                $ytid = $id;
                } else { // No URL or ID supplied
                return;
                }

                // Ensure the "related" value is appropriate for the YouTube URL
                $related_val = ($related)?’&rel=1’:’&rel=0’;
                $autoplay_val = ($autoplay)?’&autoplay=1’:’&autoplay=0’;
                $loop_val = ($loop)?’&loop=1’:’&loop=0’;
                $disablekb_val = ($disablekb)?’&disablekb=1’:’&disablekb=0’;
                $egm_val = ($egm)?’&egm=1’:’&egm=0’;
                $border_val = ($border)?’&border=1’:’&border=0’;
                $color1_val = (!empty($color1))?’&color1=’.$color1:’’;
                $color2_val = (!empty($color2))?’&color2=’.$color2:’’;

                // Construct the YouTube URL
                $yturl =’ http://www.youtube.com/v/’.$ytid.$related_val.$autoplay_val.$loop_val.$disablekb_val.$egm_val.$border_val.$color1_val.$color2_val.’&hl=en’;

                // HTML template, based on cross-browser recommendation from SWFobject project
                $html = ’
                <object id="’.$ytid.’" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="’.$width.’" height="’.$height.’">
                <param name="movie" value="’.$yturl.’" />
                <!--[if !IE]>-->
                <object type="application/x-shockwave-flash" data="’.$yturl.’" width="’.$width.’" height="’.$height.’">
                <!--<![endif]-->
                ’.$missing.’
                <!--[if !IE]>-->
                </object>
                <!--<![endif]-->
                </object>
                ’;


                // If we want to use javascript to check Flash version, etc.
                if ($js) {
                // Register the SWFObject script
                $modx->regClientStartupScript($swfobject_url);

                // Activate the content with JS
                $script = ’
                <script type="text/javascript">
                swfobject.registerObject("’.$ytid.’", "8.0.0", "’.$swfobject_express_url.’");
                </script>
                ’;
                $modx->regClientStartupScript($script);
                }

                return $html;



                // A function to extract the youtube ID from a page URL.
                // It is in a funciton because parse_str sets variables based on input, so we want to do this within the local
                // scope of the funtion, rather than globally
                //function getIdFromUrl($url) {
                // $url_parts = parse_url($url);
                // parse_str($url_parts[’query’]);
                // if (isset($v)) {
                // return $v;
                // } else {
                // return false;
                // }
                // }
                if(!function_exists(’getIdFromUrl’)) {
                function getIdFromUrl($url) {
                $url_parts = parse_url($url);
                parse_str($url_parts[’query’]);
                if(isset($v)) {
                return $v;
                } else {
                return false;
                }
                }
                }
                ?>
                  • 30585
                  • 833 Posts
                  Quote from: labasus at Feb 10, 2009, 09:36 AM

                  Try to replace you snippet code with this one

                  <?php
                  //SETTINGS
                  $width = isset($width)?$width:425;
                  $height = isset($height)?$height:350;

                  // YouTube API settings
                  $related = isset($related)?$related:true;
                  $autoplay = isset($autoplay)?$autoplay:false;
                  $loop = isset($loop)?$loop:false;
                  $disablekb = isset($disablekb)?$disablekb:false;
                  $egm = isset($egm)?$egm:false;
                  $border = isset($border)?$border:false;
                  $color1 = isset($color1)?$color1:’’;
                  $color2 = isset($color2)?$color2:’’;

                  // Javascript
                  $js = isset($js)?$js:true;
                  $swfobject_url = isset($swfobject_url)?$swfobject_url:’/assets/js/swfobject/swfobject.js’;
                  $swfobject_express_url = isset($swfobject_url)?$swfobject_url:’/assets/js/swfobject/expressInstall.swf’;
                  $missing = isset($missing)?$missing:’<p>This video requires the free Flash plugin.</p>’;

                  // If a URL is supplied, work out the ID part of it
                  if (isset($url) && $ytid = (getIdFromUrl(urldecode($url))) ) {
                  // $ytid is already set
                  } else if (isset($id)) {
                  $ytid = $id;
                  } else { // No URL or ID supplied
                  return;
                  }

                  // Ensure the "related" value is appropriate for the YouTube URL
                  $related_val = ($related)?’&rel=1’:’&rel=0’;
                  $autoplay_val = ($autoplay)?’&autoplay=1’:’&autoplay=0’;
                  $loop_val = ($loop)?’&loop=1’:’&loop=0’;
                  $disablekb_val = ($disablekb)?’&disablekb=1’:’&disablekb=0’;
                  $egm_val = ($egm)?’&egm=1’:’&egm=0’;
                  $border_val = ($border)?’&border=1’:’&border=0’;
                  $color1_val = (!empty($color1))?’&color1=’.$color1:’’;
                  $color2_val = (!empty($color2))?’&color2=’.$color2:’’;

                  // Construct the YouTube URL
                  $yturl =’ http://www.youtube.com/v/’.$ytid.$related_val.$autoplay_val.$loop_val.$disablekb_val.$egm_val.$border_val.$color1_val.$color2_val.’&hl=en’;

                  // HTML template, based on cross-browser recommendation from SWFobject project
                  $html = ’
                  <object id="’.$ytid.’" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="’.$width.’" height="’.$height.’">
                  <param name="movie" value="’.$yturl.’" />
                  <!--[if !IE]>-->
                  <object type="application/x-shockwave-flash" data="’.$yturl.’" width="’.$width.’" height="’.$height.’">
                  <!--<![endif]-->
                  ’.$missing.’
                  <!--[if !IE]>-->
                  </object>
                  <!--<![endif]-->
                  </object>
                  ’;


                  // If we want to use javascript to check Flash version, etc.
                  if ($js) {
                  // Register the SWFObject script
                  $modx->regClientStartupScript($swfobject_url);

                  // Activate the content with JS
                  $script = ’
                  <script type="text/javascript">
                  swfobject.registerObject("’.$ytid.’", "8.0.0", "’.$swfobject_express_url.’");
                  </script>
                  ’;
                  $modx->regClientStartupScript($script);
                  }

                  return $html;



                  // A function to extract the youtube ID from a page URL.
                  // It is in a funciton because parse_str sets variables based on input, so we want to do this within the local
                  // scope of the funtion, rather than globally
                  //function getIdFromUrl($url) {
                  // $url_parts = parse_url($url);
                  // parse_str($url_parts[’query’]);
                  // if (isset($v)) {
                  // return $v;
                  // } else {
                  // return false;
                  // }
                  // }
                  if(!function_exists(’getIdFromUrl’)) {
                  function getIdFromUrl($url) {
                  $url_parts = parse_url($url);
                  parse_str($url_parts[’query’]);
                  if(isset($v)) {
                  return $v;
                  } else {
                  return false;
                  }
                  }
                  }
                  ?>

                  You did it man, you’re the best.

                  You should suggest that snippet instead of the current one in the repository.

                  Thanks again buddy
                    A MODx Fanatic
                    • 16545
                    • 358 Posts
                    It’s not mine own solution, this one was before, but only modified piece of snippet.
                    I’ve just put it in a right place.

                    You did it man, you’re the best.

                    You should suggest that snippet instead of the current one in the repository.

                    Thanks again buddy

                      • 16545
                      • 358 Posts
                      If we need HD video quality, we must add fmt=18 to the link.
                      Youtube snippet didn’t parse it correctly.