Source Code Documentation


s2member\includes\classes\sc-files-in.inc.php


  1. <?php
  2. /**
  3. * Shortcode `[s2File /]` (inner processing routines).
  4. *
  5. * Copyright: © 2009-2011
  6. * {@link http://www.websharks-inc.com/ WebSharks, Inc.}
  7. * (coded in the USA)
  8. *
  9. * Released under the terms of the GNU General Public License.
  10. * You should have received a copy of the GNU General Public License,
  11. * along with this software. In the main directory, see: /licensing/
  12. * If not, see: {@link http://www.gnu.org/licenses/}.
  13. *
  14. * @package s2Member\s2File
  15. * @since 110926
  16. */
  17. if(realpath(__FILE__) === realpath($_SERVER["SCRIPT_FILENAME"]))
  18. exit("Do not access this file directly.");
  19.  
  20. if(!class_exists("c_ws_plugin__s2member_sc_files_in"))
  21. {
  22. /**
  23. * Shortcode `[s2File /]` (inner processing routines).
  24. *
  25. * @package s2Member\s2File
  26. * @since 110926
  27. */
  28. class c_ws_plugin__s2member_sc_files_in
  29. {
  30. /**
  31. * Handles the Shortcode for: `[s2File /]`.
  32. *
  33. * @package s2Member\s2File
  34. * @since 110926
  35. *
  36. * @attaches-to ``add_shortcode("s2File");``
  37. *
  38. * @param array $attr An array of Attributes.
  39. * @param str $content Content inside the Shortcode.
  40. * @param str $shortcode The actual Shortcode name itself.
  41. * @return str Value of requested File Download URL, streamer array element; or null on failure.
  42. */
  43. public static function sc_get_file($attr = FALSE, $content = FALSE, $shortcode = FALSE)
  44. {
  45. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  46. do_action("ws_plugin__s2member_before_sc_get_file", get_defined_vars());
  47. unset /* Unset defined __refs, __v. */($__refs, $__v);
  48.  
  49. $attr = /* Force array; trim quote entities. */ c_ws_plugin__s2member_utils_strings::trim_qts_deep((array)$attr);
  50.  
  51. $attr = shortcode_atts(array("download" => "", "download_key" => "", "stream" => "", "inline" => "", "storage" => "", "remote" => "", "ssl" => "", "rewrite" => "", "rewrite_base" => "", "skip_confirmation" => "", "url_to_storage_source" => "", "count_against_user" => "", "check_user" => "", /* Shortcode-specifics » */ "get_streamer_json" => "", "get_streamer_array" => ""), $attr);
  52.  
  53. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  54. do_action("ws_plugin__s2member_before_sc_get_file_after_shortcode_atts", get_defined_vars());
  55. unset /* Unset defined __refs, __v. */($__refs, $__v);
  56.  
  57. $get_streamer_json = filter_var($attr["get_streamer_json"], FILTER_VALIDATE_BOOLEAN);
  58. $get_streamer_array = filter_var($attr["get_streamer_array"], FILTER_VALIDATE_BOOLEAN);
  59. $get_streamer_json = $get_streamer_array = ($get_streamer_array || $get_streamer_json) ? true : false;
  60.  
  61. foreach /* Now we need to go through and a `file_` prefix to certain Attribute keys, for compatibility. */($attr as $key => $value)
  62. if(strlen($value) && in_array($key, array("download", "download_key", "stream", "inline", "storage", "remote", "ssl", "rewrite", "rewrite_base")))
  63. $config["file_".$key] = /* Set prefixed config parameter here so we can pass properly in ``$config`` array. */ $value;
  64. else if(strlen($value) && !in_array($key, array("get_streamer_json", "get_streamer_array")))
  65. $config[$key] = $value;
  66.  
  67. unset /* Ditch these now. We don't want these bleeding into Hooks/Filters anyway. */($key, $value);
  68.  
  69. if /* Looking for a File Download URL? */(!empty($config) && isset($config["file_download"]))
  70. {
  71. $_get = c_ws_plugin__s2member_files::create_file_download_url($config, $get_streamer_array);
  72.  
  73. if($get_streamer_array && $get_streamer_json && is_array($_get))
  74. $get = json_encode($_get);
  75.  
  76. else if($get_streamer_array && $get_streamer_json)
  77. $get = /* Null object value. */ "null";
  78.  
  79. else if(!empty($_get))
  80. $get = $_get;
  81. }
  82. return apply_filters("ws_plugin__s2member_sc_get_file", ((isset($get)) ? $get : null), get_defined_vars());
  83. }
  84. /**
  85. * Handles the Shortcode for: `[s2Stream /]`.
  86. *
  87. * @package s2Member\s2File
  88. * @since 130119
  89. *
  90. * @attaches-to ``add_shortcode("s2Stream");``
  91. *
  92. * @param array $attr An array of Attributes.
  93. * @param str $content Content inside the Shortcode.
  94. * @param str $shortcode The actual Shortcode name itself.
  95. * @return str HTML markup that produces an audio/video stream for a specific player.
  96. */
  97. public static function sc_get_stream($attr = FALSE, $content = FALSE, $shortcode = FALSE)
  98. {
  99. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  100. do_action("ws_plugin__s2member_before_sc_get_stream", get_defined_vars());
  101. unset /* Unset defined __refs, __v. */($__refs, $__v);
  102.  
  103. $attr = /* Force array; trim quote entities. */ c_ws_plugin__s2member_utils_strings::trim_qts_deep((array)$attr);
  104.  
  105. $attr = shortcode_atts(array("download" => "", "download_key" => "", "stream" => "yes", "inline" => "yes", "storage" => "", "remote" => "", "ssl" => "", "rewrite" => "yes", "rewrite_base" => "", "skip_confirmation" => "", "url_to_storage_source" => "yes", "count_against_user" => "yes", "check_user" => "yes", /* Shortcode-specifics »» */ "file_download" => "", /* Configuration » */ "player" => "jwplayer-v6-rtmp", "player_id" => "s2-stream-".md5(uniqid("", TRUE)), "player_path" => "/jwplayer/jwplayer.js", "player_key" => "", "player_title" => "", "player_image" => "", "player_mediaid" => "", "player_description" => "", "player_captions" => "", /* Layout » */ "player_controls" => "yes", "player_skin" => "", "player_stretching" => "uniform", "player_width" => "480", "player_height" => "270", "player_aspectratio" => "", /* Playback » */ "player_autostart" => "no", "player_fallback" => "yes", "player_mute" => "no", "player_primary" => "flash", "player_repeat" => "no", "player_startparam" => "", /* Advanced option blocks » */ "player_option_blocks" => ""), $attr);
  106. $attr["download"] = (!empty($attr["file_download"])) ? $attr["file_download"] : $attr["download"];
  107.  
  108. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  109. do_action("ws_plugin__s2member_before_sc_get_stream_after_shortcode_atts", get_defined_vars());
  110. unset /* Unset defined __refs, __v. */($__refs, $__v);
  111.  
  112. foreach /* Now we need to go through and a `file_` prefix to certain Attribute keys, for compatibility. */($attr as $key => $value)
  113. if(strlen($value) && in_array($key, array("download", "download_key", "stream", "inline", "storage", "remote", "ssl", "rewrite", "rewrite_base")))
  114. $config["file_".$key] = /* Set prefixed config parameter here so we can pass properly in ``$config`` array. */ $value;
  115. else if(strlen($value) && !in_array($key, array("file_download", "player")) && strpos($key, "player_") !== 0)
  116. $config[$key] = $value;
  117.  
  118. unset /* Ditch these now. We don't want these bleeding into Hooks/Filters anyway. */($key, $value);
  119.  
  120. if /* Looking for a File Download URL? */(!empty($config) && isset($config["file_download"]))
  121. {
  122. $_get = c_ws_plugin__s2member_files::create_file_download_url($config, TRUE);
  123.  
  124. if(is_array($_get) && !empty($_get) && $attr["player"] && file_exists($template = dirname(dirname(__FILE__))."/templates/players/".$attr["player"].".php") && $attr["player_id"] && $attr["player_path"])
  125. {
  126. $template = (file_exists(TEMPLATEPATH."/".basename($template))) ? TEMPLATEPATH."/".basename($template) : $template;
  127. $template = (file_exists(WP_CONTENT_DIR."/".basename($template))) ? WP_CONTENT_DIR."/".basename($template) : $template;
  128.  
  129. if(strpos($attr["player"], "jwplayer-v6") === 0)
  130. {
  131. $get = trim(c_ws_plugin__s2member_utilities::evl(file_get_contents($template)));
  132.  
  133. $get = preg_replace("/%%streamer%%/", $_get["streamer"], $get);
  134. $get = preg_replace("/%%prefix%%/", $_get["prefix"], $get);
  135. $get = preg_replace("/%%file%%/", $_get["file"], $get);
  136. $get = preg_replace("/%%url%%/", $_get["url"], $get);
  137.  
  138. $get = preg_replace("/%%player_id%%/", $attr["player_id"], $get);
  139. $get = preg_replace("/%%player_path%%/", $attr["player_path"], $get);
  140. $get = preg_replace("/%%player_key%%/", $attr["player_key"], $get);
  141.  
  142. $get = preg_replace("/%%player_title%%/", $attr["player_title"], $get);
  143. $get = preg_replace("/%%player_image%%/", $attr["player_image"], $get);
  144.  
  145. $get = preg_replace("/%%player_mediaid%%/", $attr["player_mediaid"], $get);
  146. $get = preg_replace("/%%player_description%%/", $attr["player_description"], $get);
  147.  
  148. if(($attr["player_captions"] = c_ws_plugin__s2member_utils_strings::trim($attr["player_captions"], null, "[]")))
  149. $get = preg_replace("/%%player_captions%%/", "[".((strpos($attr["player_captions"], ":") !== false) ? $attr["player_captions"] : base64_decode($attr["player_captions"]))."]", $get);
  150. else $get = preg_replace("/%%player_captions%%/", "[]", $get);
  151.  
  152. $get = preg_replace("/%%player_controls%%/", ((filter_var($attr["player_controls"], FILTER_VALIDATE_BOOLEAN)) ? "true" : "false"), $get);
  153. $get = preg_replace("/%%player_width%%/", ((strpos($attr["player_width"], "%") !== FALSE) ? "'".$attr["player_width"]."'" : (integer)$attr["player_width"]), $get);
  154. $get = preg_replace("/%%player_height%%/", (($attr["player_aspectratio"]) ? "''" : ((strpos($attr["player_height"], "%") !== FALSE) ? "'".$attr["player_height"]."'" : (integer)$attr["player_height"])), $get);
  155. $get = preg_replace("/%%player_aspectratio%%/", $attr["player_aspectratio"], $get);
  156. $get = preg_replace("/%%player_skin%%/", $attr["player_skin"], $get);
  157. $get = preg_replace("/%%player_stretching%%/", $attr["player_stretching"], $get);
  158.  
  159. $get = preg_replace("/%%player_autostart%%/", ((filter_var($attr["player_autostart"], FILTER_VALIDATE_BOOLEAN)) ? "true" : "false"), $get);
  160. $get = preg_replace("/%%player_fallback%%/", ((filter_var($attr["player_fallback"], FILTER_VALIDATE_BOOLEAN)) ? "true" : "false"), $get);
  161. $get = preg_replace("/%%player_mute%%/", ((filter_var($attr["player_mute"], FILTER_VALIDATE_BOOLEAN)) ? "true" : "false"), $get);
  162. $get = preg_replace("/%%player_primary%%/", $attr["player_primary"], $get);
  163. $get = preg_replace("/%%player_repeat%%/", ((filter_var($attr["player_repeat"], FILTER_VALIDATE_BOOLEAN)) ? "true" : "false"), $get);
  164. $get = preg_replace("/%%player_startparam%%/", $attr["player_startparam"], $get);
  165.  
  166. $get = preg_replace("/%%player_option_blocks%%/", ((strpos($attr["player_option_blocks"], ":") !== false) ? $attr["player_option_blocks"] : base64_decode($attr["player_option_blocks"])), $get);
  167. }
  168. }
  169. }
  170. return apply_filters("ws_plugin__s2member_sc_get_stream", ((isset($get)) ? $get : null), get_defined_vars());
  171. }
  172. }
  173. }
  174. ?>

s2member\includes\classes\sc-files-in.inc.php

Source Code Documentation