We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 30585
    • 833 Posts
    Hi guys,

    I was wondering if this Modx Evolution old Snippet will be compatible with MODx Revolution. Revo doesn’t come with anything close to the power of JWPlayer and I was hoping to keep using it since it did some excellent things such skin customization etc.

    Can anyone help with the upgrade to the new version of MODx.
    <?php
    // SNIPPET NAME: JWPlayer
    // SNIPPET DESCRIPTION: A Snippet to place the JW FLV Player into a MODx Page
    // VERSION 1.1
    
    /*---------------------------------
    ================
    :: CREDIT
    ================
    
      This Snippet writes the code necessary to properly display the JW FLV player in MODx
      THE JW FLV player is developed by Jeroen Wijering and is available at http://www.jeroenwijering.com/
      Respect the developer's license: http://creativecommons.org/licenses/by-nc-sa/3.0/
    
    
      MODx Snippet thingie by George D. Carstensen
      www.anablepo.com
    
    =======
    1.0.1 Changelog
    Multiple player per page better supported - thanks keshon
    
    ================
    :: INSTALL
    ================
    
      - Download the .zip at http://www.jeroenwijering.com/?item=JW_FLV_Player
      - Unzip the file  and rename it 'embed'
      - Place /embed/ inside another directory entitled 'JWPlayer'
      - Upload the JWPlayer directory to your assets/snippets/ directory
      - Paste the text of this document in a snippet - entitled 'JWPlayer'
      
      - Reccommended: Create a Templave Variable (TV) Called 'videosrc' and
        Set the input type as 'file'
      
      * I'm not packaging these files in the snippet download - because the player is 
        sometimes updated - and you probably want the newest one.
    
      * Tested and written for JW FLV MEDIA PLAYER v. 4.0
    
    ================
    :: USAGE
    ================
    
      - Simple! Place the snippet call [[JWPlayer? &src=[*videosrc*]]] in your document.
      - If you chose to create the TV above, use the call [[JWPlayer? &src=[*videosrc*]]]
        and set the filename using the TV dialog in your document.
      - If you choose to use paramaters, simply append them like so: 
        [[JWPlayer? &src=[*videosrc*]&parameter1=value1&parameter2=value2&]]
        (kind-of like a URL line, but make sure there's a space between the ? and the &.)
      - If you use the player more than once in a page with different sources, scrap the TV and do this:
        [[JWPlayer? &src=path/to/file]]
    
    ================
    :: AVAILABLE PARAMETERS
    ================
    
      *- All of these parameters defaults are editable below
    
      &width - width in px
      &height - height in px
      &logo - location of logo from MODx install root. (ex: assets/images/monkeys/logo.png )
      &fullscreen - enables fullscreen function ( true | false )
      &stretching - specifies stretch type (uniform | fill | exactfit | none )
          -'uniform' plays the video and fills up the frame - using black bars to perserve aspect
          -'fill' fills up the frame while maintaining aspect ratio - may result in clipping.
          -'exactfit' stretches the movie to fit the frame - aspect ratio is out the window
          -'none' doesn't stretch at all - just plays the video in it's original dimensions. 
            Clipping possible.
      &controlbar - displays controlbar either as a floaty transparent thing, or the traditional
       bottom ( float | over | none )
    
    ================
    :: FORMATS
    ================
    
    Baseline h.264. The player isn't too picky about the file extension - I use .mp4, but I tested it with .flv and .m4v.
    To be kind, stick to about 600/700 mb/sec or less.
    
    
    ---------------------------------*/
    
    //EDITABLE PARAMETER DEFAULTS - only edit the stuff in Quotes - " ~ "
    
    $width = (isset($width)) ? strtolower($width) : "550" ;   //default video width in px
    $height = (isset($height)) ? strtolower($height) : "434" ;   //default video height in px
    $logo = (isset($logo)) ? strtolower($logo) : "assets/images/system/vidlogo.png" ;   //location of logo for overlay
    $fullscreen = (isset($fullscreen)) ? strtolower($fullscreen) : "true" ;   //Enable fullscreen function
    $stretching = (isset($stretching)) ? strtolower($stretching) : "fill" ;   //Stretching options available: uniform | fill | exactfit | none
    $controlbar = (isset($controlbar)) ? strtolower($controlbar) : "over" ;   //Controlbar location options available: bottom | over | none
    $image = (isset($image)) ? strtolower($image) : "assets/images/preview/drapeau.jpg" ;   //default preview image
    $title = (isset($title)) ? strtolower($title) : "" ;   //default Video Title
    $author = (isset($author)) ? strtolower($author) : "UNIR-MN" ;   //default Video Author
    $description = (isset($description)) ? strtolower($description) : "" ;   //default Video Description
    $dateadded= (isset($dateadded)) ? strtolower($dateadded) : "" ;   //Date video was added
    
    //FINISH EDITABLE CONTENT - if you don't know what you're doing - Keep Out!
    $jw_base = $modx->config['site_url'] . "assets/snippets/JWPlayer/";
    $Site_base = $modx->config['site_url'];
    $file = $modx->config['site_url'] . $src;
    $logosrc = $modx->config['site_url'].$logo;
    
    echo "<script type=\"text/javascript\" src=\"" . $jw_base."embed/swfobject.js\"></script> \n";
    echo "<div id=\"$file\"></div>\n<script type=\"text/javascript\"> \n";
    echo "var so = new SWFObject('" . $jw_base . "embed/player-licensed-viral.swf','mpl','$width','$height','9'); \n";
    echo "so.addParam('allowscriptaccess','always'); \n";
    echo "so.addParam('allowfullscreen','true'); \n";
    echo "so.addParam('wmode','transparent'); \n";
    echo "so.addParam('flashvars','&dock=false&file=$file&logo=$logosrc&skin=$jw_base/embed/skins/modieus/modieus.swf&controlbar=$controlbar&fullscreen=$fullscreen&stretching=$stretching&image=$image&title=$title&author=$author&description=$description'); \n";
    echo "so.write(\"$file\"); \n";
    echo "</script>";
    ?>

      A MODx Fanatic
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      No Revo expert here, but I would suspect that all you’d need to change would be these lines
      //FINISH EDITABLE CONTENT - if you don't know what you're doing - Keep Out!
      $jw_base = $modx->config['site_url'] . "assets/snippets/JWPlayer/";
      $Site_base = $modx->config['site_url'];
      $file = $modx->config['site_url'] . $src;
      $logosrc = $modx->config['site_url'].$logo;

      to use the equivalent values as generated by Revo.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 28215
        • 4,149 Posts
        Change the $modx->config calls to $modx->getOption() (ie, $modx->getOption(’site_url’)), and change the ’echo’ statements at the end to instead return the output.

        Other than that, it’ll work fine.
          shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
          • 30585
          • 833 Posts
          Quote from: splittingred at Aug 07, 2010, 10:06 AM

          Change the $modx->config calls to $modx->getOption() (ie, $modx->getOption(’site_url’)), and change the ’echo’ statements at the end to instead return the output.

          Other than that, it’ll work fine.

          Thanks for making it look and sound so easy. I’ve modified the code as suggested, can you tell me if it’s fine now?

          <?php
          // SNIPPET NAME: JWPlayer
          // SNIPPET DESCRIPTION: A Snippet to place the JW FLV Player into a MODx Page
          // VERSION 1.1
          
          /*---------------------------------
          ================
          :: CREDIT
          ================
          
            This Snippet writes the code necessary to properly display the JW FLV player in MODx
            THE JW FLV player is developed by Jeroen Wijering and is available at http://www.jeroenwijering.com/
            Respect the developer's license: http://creativecommons.org/licenses/by-nc-sa/3.0/
          
          
            MODx Snippet thingie by George D. Carstensen
            www.anablepo.com
          
          =======
          1.0.1 Changelog
          Multiple player per page better supported - thanks keshon
          
          ================
          :: INSTALL
          ================
          
            - Download the .zip at http://www.jeroenwijering.com/?item=JW_FLV_Player
            - Unzip the file  and rename it 'embed'
            - Place /embed/ inside another directory entitled 'JWPlayer'
            - Upload the JWPlayer directory to your assets/snippets/ directory
            - Paste the text of this document in a snippet - entitled 'JWPlayer'
            
            - Reccommended: Create a Templave Variable (TV) Called 'videosrc' and
              Set the input type as 'file'
            
            * I'm not packaging these files in the snippet download - because the player is 
              sometimes updated - and you probably want the newest one.
          
            * Tested and written for JW FLV MEDIA PLAYER v. 4.0
          
          ================
          :: USAGE
          ================
          
            - Simple! Place the snippet call [[JWPlayer? &src=[*videosrc*]]] in your document.
            - If you chose to create the TV above, use the call [[JWPlayer? &src=[*videosrc*]]]
              and set the filename using the TV dialog in your document.
            - If you choose to use paramaters, simply append them like so: 
              [[JWPlayer? &src=[*videosrc*]&parameter1=value1&parameter2=value2&]]
              (kind-of like a URL line, but make sure there's a space between the ? and the &.)
            - If you use the player more than once in a page with different sources, scrap the TV and do this:
              [[JWPlayer? &src=path/to/file]]
          
          ================
          :: AVAILABLE PARAMETERS
          ================
          
            *- All of these parameters defaults are editable below
          
            &width - width in px
            &height - height in px
            &logo - location of logo from MODx install root. (ex: assets/images/monkeys/logo.png )
            &fullscreen - enables fullscreen function ( true | false )
            &stretching - specifies stretch type (uniform | fill | exactfit | none )
                -'uniform' plays the video and fills up the frame - using black bars to perserve aspect
                -'fill' fills up the frame while maintaining aspect ratio - may result in clipping.
                -'exactfit' stretches the movie to fit the frame - aspect ratio is out the window
                -'none' doesn't stretch at all - just plays the video in it's original dimensions. 
                  Clipping possible.
            &controlbar - displays controlbar either as a floaty transparent thing, or the traditional
             bottom ( float | over | none )
          
          ================
          :: FORMATS
          ================
          
          Baseline h.264. The player isn't too picky about the file extension - I use .mp4, but I tested it with .flv and .m4v.
          To be kind, stick to about 600/700 mb/sec or less.
          
          
          ---------------------------------*/
          
          //EDITABLE PARAMETER DEFAULTS - only edit the stuff in Quotes - " ~ "
          
          $width = (isset($width)) ? strtolower($width) : "550" ;   //default video width in px
          $height = (isset($height)) ? strtolower($height) : "434" ;   //default video height in px
          $logo = (isset($logo)) ? strtolower($logo) : "assets/images/system/vidlogo.png" ;   //location of logo for overlay
          $fullscreen = (isset($fullscreen)) ? strtolower($fullscreen) : "true" ;   //Enable fullscreen function
          $stretching = (isset($stretching)) ? strtolower($stretching) : "fill" ;   //Stretching options available: uniform | fill | exactfit | none
          $controlbar = (isset($controlbar)) ? strtolower($controlbar) : "over" ;   //Controlbar location options available: bottom | over | none
          $image = (isset($image)) ? strtolower($image) : "assets/images/preview/drapeau.jpg" ;   //default preview image
          $title = (isset($title)) ? strtolower($title) : "" ;   //default Video Title
          $author = (isset($author)) ? strtolower($author) : "UNIR-MN" ;   //default Video Author
          $description = (isset($description)) ? strtolower($description) : "" ;   //default Video Description
          $dateadded= (isset($dateadded)) ? strtolower($dateadded) : "" ;   //Date video was added
          
          //FINISH EDITABLE CONTENT - if you don't know what you're doing - Keep Out!
          $jw_base = $modx->getOption('site_url') . "assets/snippets/JWPlayer/";
          $Site_base = $modx->getOption('site_url');
          $file = $modx->getOption('site_url') . $src;
          $logosrc = $modx->getOption('site_url').$logo;
          
          "<script type=\"text/javascript\" src=\"" . $jw_base."embed/swfobject.js\"></script> \n";
          "<div id=\"$file\"></div>\n<script type=\"text/javascript\"> \n";
          "var so = new SWFObject('" . $jw_base . "embed/player-licensed-viral.swf','mpl','$width','$height','9'); \n";
          "so.addParam('allowscriptaccess','always'); \n";
          "so.addParam('allowfullscreen','true'); \n";
          "so.addParam('wmode','transparent'); \n";
          "so.addParam('flashvars','&dock=false&file=$file&logo=$logosrc&skin=$jw_base/embed/skins/modieus/modieus.swf&controlbar=$controlbar&fullscreen=$fullscreen&stretching=$stretching&image=$image&title=$title&author=$author&description=$description'); \n";
          "so.write(\"$file\"); \n";
          "</script>";
          ?>


          Thanks again!
            A MODx Fanatic
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            You’ll need to gather all that last part into a variable then return it:
            $output = "<script type=\"text/javascript\" src=\"" . $jw_base."embed/swfobject.js\"></script> \n";
            $output .= "<div id=\"$file\"></div>\n<script type=\"text/javascript\"> \n";
            $output .= "var so = new SWFObject('" . $jw_base . "embed/player-licensed-viral.swf','mpl','$width','$height','9'); \n";
            $output .= "so.addParam('allowscriptaccess','always'); \n";
            $output .= "so.addParam('allowfullscreen','true'); \n";
            $output .= "so.addParam('wmode','transparent'); \n";
            $output .= "so.addParam('flashvars','&dock=false&file=$file&logo=$logosrc&skin=$jw_base/embed/skins/modieus/modieus.swf&controlbar=$controlbar&fullscreen=$fullscreen&stretching=$stretching&image=$image&title=$title&author=$author&description=$description'); \n";
            $output .= "so.write(\"$file\"); \n";
            $output .= "</script>";
            return $output;
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 30585
              • 833 Posts
              Quote from: sottwell at Aug 07, 2010, 10:29 AM

              You’ll need to gather all that last part into a variable then return it:
              $output = "<script type=\"text/javascript\" src=\"" . $jw_base."embed/swfobject.js\"></script> \n";
              $output .= "<div id=\"$file\"></div>\n<script type=\"text/javascript\"> \n";
              $output .= "var so = new SWFObject('" . $jw_base . "embed/player-licensed-viral.swf','mpl','$width','$height','9'); \n";
              $output .= "so.addParam('allowscriptaccess','always'); \n";
              $output .= "so.addParam('allowfullscreen','true'); \n";
              $output .= "so.addParam('wmode','transparent'); \n";
              $output .= "so.addParam('flashvars','&dock=false&file=$file&logo=$logosrc&skin=$jw_base/embed/skins/modieus/modieus.swf&controlbar=$controlbar&fullscreen=$fullscreen&stretching=$stretching&image=$image&title=$title&author=$author&description=$description'); \n";
              $output .= "so.write(\"$file\"); \n";
              $output .= "</script>";
              return $output;


              Thanks a bunch man!

              I’ll now give it a try and post the result in a bit
                A MODx Fanatic
                • 8542
                • 37 Posts
                Tad sloppy in my opinion and can be done w/o continuously adding to the variable. Also, please remember to use &amp; instead of & for validation purposes. Not sure if this was from the original author or not, but it should be a must on snippets/anything that returns data.

                Here is the changed code:

                $output = '
                <script type=\"text/javascript\" src=\"" . $jw_base."embed/swfobject.js\"></script>
                <div id=\"$file\"></div>
                <script type=\"text/javascript\">
                var so = new SWFObject('" . $jw_base . "embed/player-licensed-viral.swf','mpl','$width','$height','9');
                so.addParam('allowscriptaccess','always');
                so.addParam('allowfullscreen','true');
                so.addParam('wmode','transparent');
                so.addParam('flashvars','&dock=false&file=$file&logo=$logosrc&skin=$jw_base/embed/skins/modieus/modieus.swf&controlbar=$controlbar&fullscreen=$fullscreen&stretching=$stretching&image=$image&title=$title&author=$author&description=$description');
                so.write(\"$file\");
                </script>";'
                return $output;
                
                  • 25315
                  • 68 Posts
                  This is something of an aside, but I’ve just discovered that longtail requires the purchase of license if you wish to use JW player on a site that uses a CMS.
                    • 1343 ☆ A M B ☆
                    • 2,213 Posts
                    Quote from: robrob at Aug 22, 2010, 05:14 AM

                    This is something of an aside, but I’ve just discovered that longtail requires the purchase of license if you wish to use JW player on a site that uses a CMS.

                    Care to share where you found that, as non commercial use is free.
                      Patrick | Server Wrangler
                      About Me: Website | Tweets |  MODX Hosting
                      • 25315
                      • 68 Posts
                      https://www.longtailvideo.com/order/license/

                      If you don’t buy a commercial license, you cannot use a JW Player™ on (i) a site that has ads; (ii) a corporate site; or a (iii) CMS.

                      I’m in the process of setting up a modx powered site which delivers some video content.
                      I took a closer look at their licensing requirements after getting an email from them promoting a discount. The email outlined some licensing requirements.

                      I switched over to flowplayer, which has fewer licensing restrictions for their free version.