plugin detection created as a widget; can't tell yet if swarmplayer is installed
authorCalin Burloiu <calin.burloiu@gmail.com>
Mon, 29 Aug 2011 12:13:26 +0000 (15:13 +0300)
committerCalin Burloiu <calin.burloiu@gmail.com>
Mon, 29 Aug 2011 12:13:36 +0000 (15:13 +0300)
12 files changed:
application/config/p2p-tube.php
application/controllers/article.php
application/controllers/catalog.php
application/controllers/video.php
application/language/english/ui_lang.php
application/libraries/Html_head_params.php
application/views/header.php
application/views/side_default.php
css/default.css
css/jquery.ui.nsvideo.css
js/jquery.ui.nsinstall.js [new file with mode: 0644]
js/jquery.ui.nsvideo.js

index 8eddbff..045f54d 100644 (file)
@@ -14,35 +14,38 @@ $config['site_name'] = 'P2P-Next UPB LivingLab';
 
 /*
 |--------------------------------------------------------------------------
-| Default Stylesheet
+| Autoload Stylesheets
 |--------------------------------------------------------------------------
 |
-| Sets the default CSS that is going to be automatically added on any HTML
+| Sets the default CSSs that are going to be automatically added on any HTML
 | page generated with 'application/views/html_begin.php' view and
 | HTML_head_params library.
 |
 | Do not include any path to the file! 'css/' is going to be used.
 |
-| Leave blank for no default stylesheet.
+| Use "array()" for no default stylesheet.
 |
 */
-$config['default_css'] = 'default.css';
+$config['autoload_css'] = array('default.css',
+                                                               'jquery-ui.css');
 
 /*
 |--------------------------------------------------------------------------
-| Default Javascript
+| Autoload Javascript
 |--------------------------------------------------------------------------
 |
-| Sets the default Javascript that is going to be automatically added in any
+| Sets the default Javascripts that are going to be automatically added in any
 | HTML page generated with 'application/views/html_begin.php' view and
 | HTML_head_params library.
 |
 | Do not include any path to the file! 'js/' is going to be used.
 |
-| Leave blank for no default javascript.
+| Use "array()" for no default javascript.
 |
 */
-$config['default_js'] = '';
+$config['autoload_js'] = array('jquery.js',
+                                                               'jquery-ui.js',
+                                                               'jquery.ui.nsinstall.js');
 
 /*
 |--------------------------------------------------------------------------
index 27614f8..5073a5b 100644 (file)
@@ -26,13 +26,8 @@ class Article extends Article_Controller {
                
                $html_params = array('title' => $this->title.' - '
                                                                        . $this->config->item('site_name'),
-                                                       'css' => array(
-                                                               'jquery-ui.css'
-                                                       ),
-                                                       'js' => array(
-                                                               'jquery.js',
-                                                               'jquery-ui.js'
-                                                       ),
+                                                       //'css' => array(),
+                                                       //'js' => array(),
                                                        'metas' => 
                                                                array('description'=>$this->metaDescription)
                                                        );
index 4318325..0c05388 100644 (file)
@@ -43,13 +43,9 @@ class Catalog extends CI_Controller {
                
                $params = array(        'title' => $this->config->item('site_name'),
                                                        'css' => array(
-                                                               'catalog.css', 
-                                                               'jquery-ui.css'
-                                                       ),
-                                                       'js' => array(
-                                                               'jquery.js',
-                                                               'jquery-ui.js'
+                                                               'catalog.css'
                                                        ),
+                                                       //'js' => array(),
                                                        //'metas' => array('description'=>'','keywords'=>'')
                                                        );
                $this->load->library('html_head_params', $params);
@@ -71,13 +67,8 @@ class Catalog extends CI_Controller {
        public function test($page = 0)
        {
                $params = array(        'title' => 'Test - '. $this->config->item('site_name'),
-                                                       'css' => array(
-                                                               'jquery-ui.css'
-                                                               ),
-                                                       'js' => array(
-                                                               'jquery.js',
-                                                               'jquery-ui.js'
-                                                       ),
+                                                       //'css' => array(),
+                                                       //'js' => array(),
                                                        //'metas' => array('description'=>'','keywords'=>'')
                        );
                $this->load->library('html_head_params', $params);
@@ -128,13 +119,9 @@ class Catalog extends CI_Controller {
                
                $params = array(        'title' => $this->config->item('site_name'),
                                                        'css' => array(
-                                                               'catalog.css', 
-                                                               'jquery-ui.css'
-                                                       ),
-                                                       'js' => array(
-                                                               'jquery.js',
-                                                               'jquery-ui.js'
+                                                               'catalog.css'
                                                        ),
+                                                       //'js' => array(),
                                                        //'metas' => array('description'=>'','keywords'=>'')
                                                        );
                $this->load->library('html_head_params', $params);
index 5a4b9d5..019fa2c 100644 (file)
@@ -45,13 +45,10 @@ class Video extends CI_Controller {
                $params = array(        'title' => $data['video']['title'] . ' -- '
                                                                . $this->config->item('site_name'),
                                                        'css' => array(
-                                                               'jquery-ui.css',
                                                                'jquery.ui.nsvideo.css',
                                                                'video.css'
                                                        ),
                                                        'js' => array(
-                                                               'jquery.js',
-                                                               'jquery-ui.js',
                                                                'jquery.ui.nsvideo.js'
                                                        ),
                                                        //'metas' => array('description'=>'','keywords'=>'')
index af184ee..0bd140d 100644 (file)
@@ -11,6 +11,13 @@ $lang['ui_nav_menu_register'] = 'Register';
 
 $lang['ui_search'] = 'Search';
 
+// Install Video Plugins
+$lang['ui_install'] = 'Install ';
+$lang['ui_install_os_not_supported'] = ' is not supported for your operating system';
+$lang['ui_install_browser_not_supported'] = ' is not supported for your browser';
+$lang['ui_install_browser_version_not_supported'] = ' is not supported for your browser version';
+$lang['ui_install_already_installed'] = ' is installed';
+
 // Video Categories
 $lang['ui_categ_movies'] = 'Movies';
 $lang['ui_categ_tech_talks'] = 'TechTalks';
index 6723455..d729d88 100644 (file)
@@ -5,9 +5,10 @@
  * included inside the head tag like: title, stylesheets, scripts and meta
  * information.
  *
- * The constructor automatically adds the default stylesheet and default script
- * if any from 'application/config/p2p-tube.php' so they don't have to be added
- * manually.
+ * The constructor automatically adds the autoload-configured CSSs and JSs 
+ * if any from "application/config/${site_config}.php" so they don't have to be
+ * added manually. The configuration parameters are:
+ * 'autoload_css', 'autoload_js'.
  *
  * The variables are passed as data in 'application/views/html_begin.php' which
  * is going to generate the tags based on their information.
@@ -27,6 +28,8 @@ class Html_head_params {
        // Dictionary for meta tags: name => content
        public $metas;
        
+       protected $site_config = 'p2p-tube';
+       
        /**
         * Initializes member variables with the parameters provided and adds the
         * default stylesheet to member $css and the default script to
@@ -45,7 +48,11 @@ class Html_head_params {
        {
                $CI =& get_instance();
                $CI->load->helper('url');
-               $CI->load->config('p2p-tube');
+               
+               if (isset($this->site_config))
+                       $CI->load->config($this->site_config);
+               else
+               { /* TODO: no site config*/ }
                
                if (isset($params['title']))
                        $this->title = $params['title'];
@@ -68,10 +75,10 @@ class Html_head_params {
                        $this->metas = array();
                        
                // Default parameters from configuration file
-               if ($CI->config->item('default_css') != '')
-                       $this->css[] = $CI->config->item('default_css');
-               if ($CI->config->item('default_js') != '')
-                       $this->js[] = $CI->config->item('default_js');
+               $this->css = array_merge(
+                       $CI->config->item('autoload_css'), $this->css);
+               $this->js = array_merge(
+                       $CI->config->item('autoload_js'), $this->js);
                
                // URL correct prefixes
                foreach ($this->css as $i => $val)
index dccb112..3e9342d 100644 (file)
@@ -27,7 +27,7 @@ endif ?>
 
 <div id="header">
        <!-- TODO: resize logo image-->
-       <a href="<?php site_url() ?>" id="logo"><img src="<?php echo site_url('img/p2p-next--big.png') ?>" alt="P2P-Next" width="119" height="48" /></a>
+       <a href="<?php echo site_url() ?>" id="logo"><img src="<?php echo site_url('img/p2p-next--big.png') ?>" alt="P2P-Next" width="119" height="48" /></a>
        <form id="quick-search">
                <label for="quick-search-box"><?php echo $this->lang->line('ui_search') . ': ' ?></label>
                <input type="text" id="quick-search-box" name="quick-search-box" disabled="disabled" value="not yet implemented" />
index a6d0589..95b69e4 100644 (file)
@@ -1,25 +1,32 @@
 <div class="ui-widget ui-widget-content ui-widget-header ui-corner-all">
-       <div id="container-install-swarmplayer" class="container-install">
-               <a id="install-swarmplayer" href="<?php echo site_url('install-plugins#SwarmPlayer') ?>">Install SwarmPlayer Plugin</a>
-       </div>
-       <div id="container-install-nextsharepc" class="container-install">
-               <a id="install-nextsharepc" href="<?php echo site_url('install-plugins#NextSharePC') ?>">Install NextSharePC Plugin</a>
-       </div>
+       <div id="container-install-swarmplayer" class="container-install"></div>
+       <div id="container-install-nextsharepc" class="container-install"></div>
 </div>
 
 <script type="text/javascript">
        $(function() {
-               $('#install-swarmplayer')
-                       .button({
-                   icons: {
-                       primary: "ui-icon-arrowthickstop-1-s"
-                   }
-               });
-               $('#install-nextsharepc')
-                       .button({
-                   icons: {
-                       primary: "ui-icon-arrowthickstop-1-s"
-                   }
-               });
+               var msgLocalized = {
+                       "none": "<?php echo $this->lang->line('ui_install') ?>",
+                       "os not supported": "<?php echo $this->lang->line('ui_install_os_not_supported') ?>",
+                       "browser not supported": "<?php echo $this->lang->line('ui_install_browser_not_supported') ?>",
+                       "browser version not supported": "<?php echo $this->lang->line('ui_install_browser_version_not_supported') ?>",
+                       "already installed": "<?php echo $this->lang->line('ui_install_already_installed') ?>"
+               };
+
+        $('#container-install-swarmplayer')
+               .nsinstall({
+                               "type": "ns-html5",
+                               "installLink": "<?php echo site_url('install-plugins#SwarmPlayer') ?>",
+                               hideIfAlreadyInstalled: false,
+                               msg: msgLocalized
+               });
+
+        $('#container-install-nextsharepc')
+               .nsinstall({
+                               "type": "ns-vlc",
+                               "installLink": "<?php echo site_url('install-plugins#NextSharePC') ?>",
+                               hideIfAlreadyInstalled: false,
+                               msg: msgLocalized
+               });
        });
 </script>
\ No newline at end of file
index 7f7507e..e1abafa 100644 (file)
@@ -38,6 +38,13 @@ h1
        margin-top: 8px;
        margin-bottom: 8px;
 }
+.container-install-in-widget
+{
+       width: 320px;
+       margin: 0 auto;
+       margin-top: 8px;
+       margin-bottom: 8px;
+}
 
 #nav-menu
 {/*
@@ -169,6 +176,8 @@ h1
 #main dt
 {
        font-weight: bold;
+       margin-top: 1em;
+       margin-bottom: 0.5em;
 }
 
 #content
index 11b6f8b..4034399 100644 (file)
@@ -58,7 +58,6 @@
 }
 .ui-button-text
 {
-       width: 2em;
        height: 1.4em;
        padding-top: 0.5em !important;
        padding-bottom: 0 !important;
diff --git a/js/jquery.ui.nsinstall.js b/js/jquery.ui.nsinstall.js
new file mode 100644 (file)
index 0000000..78c6189
--- /dev/null
@@ -0,0 +1,298 @@
+/*
+ * jQuery UI Install NextShare Video Plugins 1.0.0 beta
+ *
+ * Copyright 2011, Călin-Andrei Burloiu
+ * Dual licensed under the MIT or GPL Version 2 licenses.
+ * http://jquery.org/license
+ * 
+ * This file constains code created by Riccardo Petrocco and Arno Bakker
+ * from http://swarmplayer.p2p-next.org.
+ *
+ * Depends:
+ *   jquery.ui.core.js
+ *   jquery.ui.widget.js
+ */
+(function( $, undefined ) {
+
+$.widget( "ui.nsinstall", {
+       version: "1.0.0 beta",
+       options: {
+               type: "ns-html5",       // "ns-html5" or "ns-vlc",
+               installLink: "",
+               hideIfAlreadyInstalled: true,
+               
+               error: "none",
+               msg: {
+                       "none": "Install ",
+                       "os not supported": " is not supported for your operating system",
+                       "browser not supported": " is not supported for your browser",
+                       "browser version not supported": " is not supported for your browser version",
+                       "already installed": " is installed"
+               }
+       },
+       
+       _create: function() {
+               var widget = this;
+               var platform = widget.platform();
+               
+               // Check platform support conditions and create content.
+               // NextSharePC
+               if (widget.options.type == "ns-vlc")
+               {
+                       if (platform.osName !== 'MacOS' && platform.osName !== 'Windows')
+                       {
+                               widget.options.error = "os not supported";
+                       }
+                       else
+                       {
+                               if (platform.browserName == 'Firefox')
+                               {
+                                       if (platform.browserVersion < 3.5)
+                                               widget.options.error = "browser version not supported";
+                               }
+                               else if (platform.browserName == 'Internet Explorer')
+                               {
+                                       if (platform.browserVersion < 7.0)
+                                       {
+                                               widget.options.error = "browser version not supported"; 
+                                       }
+                               }
+                               else
+                                       widget.options.error = "browser not supported";
+                       }
+                       
+                       if (widget.isNextSharePCAlreadyInstalled())
+                               widget.options.error = "already installed";
+                       
+                       if (widget.options.error !== "already installed"
+                                       || (widget.options.error === "already installed"
+                                       && ! widget.options.hideIfAlreadyInstalled) )
+                               widget._createNextSharePCInstall();
+               }
+               // SwarmPlayer
+               else if (widget.options.type == "ns-html5")
+               {
+                       if (platform.osName !== 'MacOS' && platform.osName !== 'Windows'
+                               && platform.osName !== 'Ubuntu Linux'
+                               && platform.osName !== 'Linux')
+                       {
+                               widget.options.error = "os not supported";
+                       }
+                       else
+                       {
+                               if (platform.browserName == 'Firefox')
+                               {
+                                       if (platform.browserVersion < 3.5)
+                                               widget.options.error = "browser version not supported";
+                               }
+                               else if (platform.browserName == 'Internet Explorer')
+                               {
+                                       if (platform.browserVersion < 7.0)
+                                       {
+                                               widget.options.error = "browser version not supported"; 
+                                       }
+                               }
+                               else
+                                       widget.options.error = "browser not supported";
+                       }
+                       
+                       if (widget.isSwarmPlayerAlreadyInstalled())
+                               widget.options.error = "already installed";
+                       
+                       if (widget.options.error !== "already installed"
+                                       || (widget.options.error === "already installed"
+                                       && ! widget.options.hideIfAlreadyInstalled) )
+                               widget._createSwarmPlayerInstall();
+               }
+       },
+       
+       _createSwarmPlayerInstall: function() {
+               var widget = this;
+               
+               if (widget.options.error == 'none')
+               {
+                       var $installLink = $('<a id="install-swarmplayer" href="'
+                                       + widget.options.installLink + '">'
+                                       + widget.options.msg[widget.options.error] + ' SwarmPlayer Plugin</a>')
+                               .appendTo(widget.element);
+                       
+                       $installLink
+                               .button({
+                           icons: {
+                               primary: "ui-icon-arrowthickstop-1-s"
+                           }
+                       });
+               }
+               else if (widget.options.error == 'already installed')
+               {
+                       $box
+                               .html('<div class="ui-widget">'
+                                               + '<div style="padding: 0 .7em;" class="ui-state-highlight ui-corner-all">' 
+                                               + '<p style="text-align: center"><span style="float: left; margin-right: .3em;" class="ui-icon ui-icon-info"></span>' 
+                                               + '<span id="install-swarmplayer-msg"></span></p>'
+                                       + '</div>'
+                               + '</div>');
+                       
+                       var msg = 'SwarmPlayer ' + widget.options.msg[widget.options.error];
+                       $('#install-swarmplayer-msg').html(msg);
+               }
+               else
+               {
+                       var $box = $('<div id="install-swarmplayer"></div>')
+                               .appendTo(widget.element);
+                       
+                       $box
+                               .html('<div class="ui-widget">'
+                                               + '<div style="padding: 0 .7em;" class="ui-state-error ui-corner-all">' 
+                                               + '<p style="text-align: center"><span style="float: left; margin-right: .3em;" class="ui-icon ui-icon-alert"></span>' 
+                                               + '<span id="install-swarmplayer-msg"></span></p>'
+                                       + '</div>'
+                               + '</div>');
+                       
+                       var msg = 'SwarmPlayer ' + widget.options.msg[widget.options.error];
+                       $('#install-swarmplayer-msg').html(msg);
+               }
+               
+       },
+       
+       _createNextSharePCInstall: function() {
+               var widget = this;
+               
+               if (widget.options.error == 'none')
+               {
+                       var $installLink = $('<a id="install-nextsharepc" href="'
+                                       + widget.options.installLink + '">'
+                                       + widget.options.msg[widget.options.error] + ' NextSharePC Plugin</a>')
+                               .appendTo(widget.element);
+                       
+                       $installLink
+                               .button({
+                           icons: {
+                               primary: "ui-icon-arrowthickstop-1-s"
+                           }
+                       });
+               }
+               else if (widget.options.error == 'already installed')
+               {
+                       var $box = $('<div id="install-nextsharepc"></div>')
+                               .appendTo(widget.element);
+                       
+                       $box
+                       .html('<div class="ui-widget">'
+                                       + '<div style="padding: 0 .7em;" class="ui-state-highlight ui-corner-all">' 
+                                       + '<p style="text-align: center"><span style="float: left; margin-right: .3em;" class="ui-icon ui-icon-info"></span>' 
+                                       + '<span id="install-nextsharepc-msg"></span></p>'
+                               + '</div>'
+                       + '</div>');
+                       
+                       var msg = 'NextSharePC ' + widget.options.msg[widget.options.error];
+                       $('#install-nextsharepc-msg').html(msg);
+               }
+               else
+               {
+                       var $box = $('<div id="install-nextsharepc"></div>')
+                               .appendTo(widget.element);
+                       
+                       $box
+                               .html('<div class="ui-widget">'
+                                               + '<div style="padding: 0 .7em;" class="ui-state-error ui-corner-all">' 
+                                               + '<p style="text-align: center"><span style="float: left; margin-right: .3em;" class="ui-icon ui-icon-alert"></span>' 
+                                               + '<span id="install-nextsharepc-msg"></span></p>'
+                                       + '</div>'
+                               + '</div>');
+                       
+                       var msg = 'NextSharePC ' + widget.options.msg[widget.options.error];
+                       $('#install-nextsharepc-msg').html(msg);
+               }
+       },
+       
+       _destroy: function() {
+               this.element.html('');
+       },
+       
+       _setOption: function( key, value ) {
+               // TODO
+               if ( key === "TODO" ) {
+                       
+               }
+
+               this._super( "_setOption", key, value );
+       },
+       
+       isNextSharePCAlreadyInstalled: function() {
+               for (var i=0; i<navigator.plugins.length; i++)
+               {
+                       if (navigator.plugins.item(i).name.indexOf('NextSharePC') != -1)
+                               return true;
+               }
+               
+               return false;
+       },
+       
+       isSwarmPlayerAlreadyInstalled: function() {
+               return false;
+       },
+       
+       platform: function() {
+               var browserName="Unknown";
+               var browserVersion=-1;
+               var osName="Unknown";
+               var archName="Unknown";
+               
+               if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent))
+               { 
+                       var ffbrowserVersion=new Number(RegExp.$1);
+                       browserName = "Firefox";
+                       browserVersion = ffbrowserVersion;
+               }
+               else if (/MSIE (\d+\.\d+);/.test(navigator.userAgent))
+               { 
+                       var iebrowserVersion=new Number(RegExp.$1);
+                       browserName = "Internet Explorer";
+                       browserVersion = iebrowserVersion;
+               }
+               else if (/Chrome[\/\s](\d+\.\d+)/.test(navigator.userAgent)) 
+               {
+                   // Must come before Safari, Chrome says it's Safari too. 
+                       var chbrowserVersion=new Number(RegExp.$1);
+                       browserName = "Chrome";
+                       browserVersion = chbrowserVersion;
+               }
+               else if (/Safari[\/\s](\d+\.\d+)/.test(navigator.userAgent))
+               { 
+                       var sfbrowserVersion=new Number(RegExp.$1);
+                       browserName = "Safari";
+                       browserVersion = sfbrowserVersion;
+               }
+               else if (/Iceweasel[\/\s](\d+\.\d+)/.test(navigator.userAgent))
+               { 
+                   // Iceweasel should be compatible with Firefox
+                       var ffbrowserVersion=new Number(RegExp.$1);
+                       browserName = "Firefox";
+                       browserVersion = ffbrowserVersion;
+               }
+               else if (/Namoroka[\/\s](\d+\.\d+)/.test(navigator.userAgent))
+               { 
+                   // Namoroka should be compatible with Firefox
+                       var ffbrowserVersion=new Number(RegExp.$1);
+                       browserName = "Firefox";
+                       browserVersion = ffbrowserVersion;
+               }
+
+
+               if (navigator.userAgent.indexOf("Win")!=-1) osName="Windows";
+               else if (navigator.userAgent.indexOf("Mac")!=-1) osName="MacOS";
+               else if (navigator.userAgent.indexOf("Ubuntu")!=-1) osName="Ubuntu Linux";
+               else if (navigator.userAgent.indexOf("Linux")!=-1) osName="Linux";
+               else if (navigator.userAgent.indexOf("X11")!=-1) osName="UNIX";
+               
+               if (navigator.userAgent.indexOf("Intel Mac")!=-1) archName="Intel";
+               else if (navigator.userAgent.indexOf("PPC Mac")!=-1) archName="PowerPC";
+               else if (navigator.userAgent.indexOf("Linux i686")!=-1) archName="i686";
+               else if (navigator.userAgent.indexOf("Linux x86_64")!=-1) archName="x86_64";
+
+               return {browserName: browserName, browserVersion: browserVersion, osName: osName, archName: archName};
+       }
+});
+
+})( jQuery );
\ No newline at end of file
index ccb461d..ccf9a13 100644 (file)
@@ -199,6 +199,15 @@ $.widget( "ui.nsvideo", {
                
                widget.$videoContainer.html('');
                
+               // Install buttons or not supported message if required
+               var $installContainer = $('<div class="container-install-in-widget"></div>')
+                       .appendTo(widget.$videoContainer);
+               $installContainer
+                       .nsinstall({
+                               type: widget.options.type,
+                               hideIfAlreadyInstalled: true
+                       });
+               
                var width = widget.options.width;
                var height = widget.options.height;
                
@@ -833,6 +842,9 @@ $.widget( "ui.nsvideo", {
                },
                
                pause: function() {
+                       if (typeof widget.$video[0].playlist === 'undefined')
+                               return widget;
+                       
                        if (widget.$video[0].playlist.isPlaying)
                                widget.$video[0].playlist.togglePause();