From f3eefce5fa0888fb3b5984db583843947c952a9a Mon Sep 17 00:00:00 2001
From: Helior Colorado <me@helior.info>
Date: Wed, 15 Feb 2012 12:05:42 -0800
Subject: [PATCH] Added libraries support

Added videojs_get_path() to replace most direct references to the "videojs_directory" variable
---
 videojs.install |    2 +-
 videojs.module  |   26 +++++++++++++++++++++++---
 2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/videojs.install b/videojs.install
index da4c82c..1cf8d4a 100644
--- a/videojs.install
+++ b/videojs.install
@@ -15,7 +15,7 @@ function videojs_requirements($phase) {
     $videojs_version = videojs_get_version();
     if ($videojs_version == NULL) {
       $requirements['videojs']['value'] = t('Not found');
-      $requirements['videojs']['description'] = t('Missing the Video.js library. Please <a href="@videojs-url">download Video.js</a> and extract it into the %directory directory.', array('@videojs-url' => url('http://videojs.com'), '%directory' => variable_get('videojs_directory', 'sites/all/libraries/video-js')));
+      $requirements['videojs']['description'] = t('Missing the Video.js library. Please <a href="@videojs-url">download Video.js</a> and extract it into the %directory directory. or any other suitable path for libraries.', array('@videojs-url' => url('http://videojs.com'), '%directory' => variable_get('videojs_directory', 'sites/all/libraries/video-js')));
       $requirements['videojs']['severity'] = REQUIREMENT_ERROR;
     }
     elseif (version_compare($videojs_version, '3', '>=')) {
diff --git a/videojs.module b/videojs.module
index f9ec8bd..b9d206c 100644
--- a/videojs.module
+++ b/videojs.module
@@ -73,6 +73,26 @@ function videojs_field_formatter_info() {
 }
 
 /**
+ * Get the path to the video.js external library.
+ *
+ * @return
+ *   The path to the directory where video.js library is located.
+ */
+function videojs_get_path() {
+  // Libraries API integration
+  if (function_exists('libraries_get_path')) {
+    $directory = libraries_get_path('video-js');
+  }
+
+  // Fallback to configurable path
+  if (!file_exists($directory . '/video.js')) {
+    $directory = variable_get('videojs_directory', 'sites/all/libraries/video-js');
+  }
+
+  return $directory;
+}
+
+/**
  * Add the Video.js library to the page.
  *
  * @param $add
@@ -84,7 +104,7 @@ function videojs_field_formatter_info() {
 function videojs_add($add = TRUE) {
   static $added = FALSE;
 
-  $directory = variable_get('videojs_directory', 'sites/all/libraries/video-js');
+  $directory = videojs_get_path();
   $return = FALSE;
   if (file_exists($directory .'/video.js')) {
     $filepath = $directory .'/video.js';
@@ -95,7 +115,7 @@ function videojs_add($add = TRUE) {
     $videojs_js = drupal_get_path('module', 'videojs') .'/theme/videojs.js';
     $videojs_css = drupal_get_path('module', 'videojs') .'/theme/videojs.css';
     $settings = array('videojs' => array(
-        'swfPath' => base_path() . variable_get('videojs_directory', 'sites/all/libraries/video-js'),
+        'swfPath' => base_path() . videojs_get_path(),
         'autoPlay' => (int) variable_get('videojs_autoplay', ''),
         ));
     if ($add) {
@@ -134,7 +154,7 @@ function videojs_get_version($directory = NULL) {
   $version = NULL;
 
   if (!isset($directory)) {
-    $directory = variable_get('videojs_directory', 'sites/all/libraries/video-js');
+    $directory = videojs_get_path();
   }
 
   if (!file_exists($directory .'/video.js')) {
-- 
1.7.6

