Advertisement
Guest User

Untitled

a guest
Jan 30th, 2013
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.39 KB | None | 0 0
  1. <?php
  2. error_reporting(E_ALL);
  3. /*
  4. Plugin Name: Youtube Content for me
  5. Plugin URI: http://testingg.com
  6. Description: A Plugin that embeds Youtube Video Player with a Playlist as Content
  7. Version: 1.0
  8. Author: Mark @ Offso
  9. Author URI: http://tsting.com
  10. License: GPL2
  11. */
  12.  
  13.  
  14. class Youtube_Content_class {
  15.  
  16. public $options;
  17.  
  18.  
  19. public function __construct(){
  20. //delete_option('youtube_plugin_options');
  21. $this->options = get_option('youtube_plugin_options');
  22. $this->register_settings_and_fields();
  23.  
  24. //$variable_ = get_option('youtube_plugin_options');
  25. // print_r($options);
  26.  
  27. //print_r($variable_['youtube_keyword']);
  28.  
  29. }
  30.  
  31.  
  32.  
  33.  
  34. public function add_menu_page(){
  35.  
  36. add_options_page('Youtube Content Settings', 'Youtube Content Settings', 'administrator', __FILE__, array('Youtube_Content_class', 'display_options_page'));
  37.  
  38. }
  39.  
  40. public function display_options_page(){
  41.  
  42. ?>
  43. <div class="wrap">
  44. <?php screen_icon(); ?>
  45. <h2>Youtube Content Settings</h2>
  46.  
  47. <?php // $test = get_option('youtube_plugin_options'); /************ get option value ?>
  48. <!-- <pre> <?php // print_r($test); ?>
  49. </pre>
  50. -->
  51.  
  52. <form action="options.php" method="post">
  53.  
  54. <?php settings_fields('youtube_plugin_options'); ?>
  55. <?php do_settings_sections(__FILE__); ?>
  56.  
  57. <p class="submit">
  58. <input type="submit" name="submit" class="button-primary" value="Save Settings" />
  59. </p>
  60.  
  61. </form>
  62. </div>
  63. <?php
  64.  
  65.  
  66. }
  67.  
  68.  
  69. public function register_settings_and_fields(){
  70.  
  71. register_setting( 'youtube_plugin_options', 'youtube_plugin_options'/*, array($this, 'youtube_validate_settings')*/); // has 3rd paramater that is optionnal callback
  72. //get_option('youtube_plugin_options'); /*** access the value */
  73. add_settings_section('youtube_main_section', 'Youtube Main Settings', array($this, 'youtube_main_section_callback'), __FILE__); // id, title, callback function, page to display
  74. add_settings_field('youtube_keyword', 'Keyword to Match: ', array($this, 'youtube_keyword_setting'), __FILE__, 'youtube_main_section', array( 'label_for' => 'brammo' ) );
  75. add_settings_field('youtube_author', 'Username (Optional): ', array($this, 'youtube_author_setting'), __FILE__, 'youtube_main_section');
  76. add_settings_field('youtube_content', 'Content to Match: ', array($this, 'youtube_content_setting'), __FILE__, 'youtube_main_section');
  77. add_settings_field('youtube_width', 'Player Width: ', array($this, 'youtube_width'), __FILE__, 'youtube_main_section');
  78. add_settings_field('youtube_height', 'Player Height: ', array($this, 'youtube_height'), __FILE__, 'youtube_main_section');
  79. add_settings_field('youtube_number_of_videos', 'Number of Videos to Display: ', array($this, 'youtube_number_of_videos'), __FILE__, 'youtube_main_section');
  80. add_settings_field('youtube_preview', 'Preview Videos: ', array($this, 'youtube_preview'), __FILE__, 'youtube_main_section');
  81.  
  82. }
  83.  
  84.  
  85. public function youtube_main_section_callback(){
  86.  
  87. }
  88.  
  89. /*
  90. public function youtube_validate_settings($plugin_options){
  91.  
  92.  
  93.  
  94. if ( !isset($this->options['youtube_keyword']) && !isset($this->options['youtube_author']) && !isset($this->options['youtube_content']) && !isset($this->options['youtube_width']) && !isset($this->options['youtube_height'])) {
  95. $plugin_options['youtube_keyword'] = "aaaa";
  96. $plugin_options['youtube_author'] = "brammo";
  97. $plugin_options['youtube_content'] = "by_keyword";
  98. $plugin_options['youtube_width'] = 200;
  99. $plugin_options['youtube_height'] = 200;
  100. } else {
  101. $plugin_options['youtube_keyword'] = $this->options['youtube_keyword'];
  102. $plugin_options['youtube_author'] = $this->options['youtube_author'];
  103. $plugin_options['youtube_content'] = $this->options['youtube_content'];
  104. $plugin_options['youtube_width'] = $this->options['youtube_width'];
  105. $plugin_options['youtube_height'] = $this->options['youtube_height'];
  106. }
  107.  
  108. return $plugin_options;
  109. }
  110. */
  111.  
  112.  
  113.  
  114. /************* Inputs boxes here *******/
  115.  
  116. // keyword heading
  117. public function youtube_keyword_setting(){
  118. // print_r($options);
  119.  
  120. echo "<input name='youtube_plugin_options[youtube_keyword]' type='text' value='{$this->options['youtube_keyword']}' placeholder='brammo' />";
  121.  
  122. }
  123.  
  124. public function youtube_author_setting(){
  125.  
  126. echo "<input name='youtube_plugin_options[youtube_author]' type='text' value='{$this->options['youtube_author']}' placeholder='Not required' />";
  127.  
  128. }
  129.  
  130.  
  131. // content_by heading
  132. public function youtube_content_setting(){
  133.  
  134. $items = array('by_channel', 'by_keyword');
  135. echo "<select name='youtube_plugin_options[youtube_content]' value='{$this->options['youtube_content']}' />";
  136. foreach ($items as $item) {
  137. $selected = ( $this->options['youtube_content'] === $item ) ? 'selected="selected"' : '';
  138. echo "<option value='$item' $selected>$item</option>";
  139. }
  140. echo "</select>";
  141.  
  142. }
  143.  
  144. // Player width heading
  145. public function youtube_width(){
  146.  
  147. echo "<input name='youtube_plugin_options[youtube_width]' value='{$this->options['youtube_width']}' type='number' min='200' max='500' />";
  148.  
  149. }
  150.  
  151. public function youtube_height(){
  152.  
  153. echo "<input name='youtube_plugin_options[youtube_height]' value='{$this->options['youtube_height']}' type='number' min='200' max='500' />";
  154.  
  155. }
  156.  
  157. public function youtube_number_of_videos(){
  158.  
  159. echo "<input name='youtube_plugin_options[youtube_number_of_videos]' value='{$this->options['youtube_number_of_videos']}' type='number' min='5' max='20' />";
  160.  
  161. }
  162.  
  163. // Player width heading
  164. public function youtube_preview(){
  165.  
  166. // print_r($this->options['youtube_keyword']);
  167. ?>
  168. <button name="searchButton" type="button" value="Search for eminem we made you" onclick="searchClicked()"/>
  169. Results:<br/>
  170. <div id="videoResultsDiv"></div>
  171. <script type="text/javascript">
  172. function searchClicked()
  173. {
  174. jQuery("#videoResultsDiv").html("Loading YouTube videos ...");
  175.  
  176. var script = jQuery("<script/>",{
  177. "id" : "jsonScript",
  178. "type": "text/javascript",
  179. "src" : "http://gdata.youtube.com/feeds/api/videos?" +
  180. "&alt=json-in-script" +
  181. "&q=<?php echo $this->options['youtube_keyword']?>"+
  182. "&author=<?php echo $this->options['youtube_author'] ?>" +
  183. "&max-results=<?php echo $this->options['youtube_number_of_videos'] ?>" +
  184. "&callback=showMyVideos" +
  185. "&orderby=relevance" +
  186. "&sortorder=descending" +
  187. "&format=5" +
  188. "&fmt=18"
  189. });
  190. jQuery("head").append(script);
  191. }
  192.  
  193. function getVideoId(url)
  194. {
  195. return url.substring(url.indexOf("=")+1,url.lastIndexOf("&"));
  196. }
  197.  
  198. var testing = [];
  199. var vid;
  200.  
  201. function showMyVideos(data)
  202. {
  203. var feed = data.feed;
  204. var entries = feed.entry || [];
  205. var html = ["<ul>"];
  206. for (var i = 0; i < entries.length; i++)
  207. {
  208. var entry = entries[i];
  209. var playCount = entry.yt$statistics.viewCount.valueOf() + " views";
  210. var title = entry.title.$t;
  211. var vid = (getVideoId(entry.link[0].href));
  212. testing[i] = vid;
  213. var lnk = "<a href = '" + entry.link[0].href + "'>link</a>";
  214. html.push("<li>", title, ", ", playCount, ", ", lnk, "</li>");
  215. }
  216.  
  217.  
  218. html.push("</ul>");
  219. jQuery("#videoResultsDiv").html(html.join(""));
  220. }
  221.  
  222. jQuery(document).ready(function($) {
  223. searchClicked();
  224. });
  225. </script>
  226.  
  227. <?php } //youtube_preview
  228.  
  229.  
  230. public function playershow(){
  231.  
  232. $pl= "'" ?>
  233. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2/swfobject.js"></script>
  234. <script type="text/javascript">
  235. var ytplayer_playlist=[];
  236. var ytplayer_playitem = 0;
  237. swfobject.addLoadEvent(ytplayer_render_player);
  238. swfobject.addLoadEvent(ytplayer_render_playlist);
  239. function ytplayer_render_player()
  240. {
  241. swfobject.embedSWF
  242. ("http://www.youtube.com/v/" + ytplayer_playlist[ytplayer_playitem] + "&enablejsapi=1&rel=0&fs=1&version=3",
  243. "ytplayer_div1",
  244. "<?php echo $this->options['youtube_width']; ?>",
  245. "<?php echo $this->options['youtube_height']; ?>",
  246. "10",
  247. null,
  248. null,
  249. {allowScriptAccess:"always",allowFullScreen:"true"},
  250. {id:"ytplayer_object"});
  251. }
  252. function ytplayer_render_playlist()
  253. {
  254. for(var i=0;i<ytplayer_playlist.length;i++)
  255. {
  256. var img=document.createElement("img");
  257. img.src="http://img.youtube.com/vi/" + ytplayer_playlist[i] + "/default.jpg";
  258. var a=document.createElement("a");
  259. a.href="#ytplayer";
  260.  
  261. a.onclick=(function(j)
  262. {
  263. return function()
  264. {
  265. ytplayer_playitem=j;
  266. ytplayer_playlazy(1000);
  267. };
  268. })(i);
  269. a.appendChild(img);
  270. document.getElementById("ytplayer_div2").appendChild(a);
  271. }
  272. }
  273. function ytplayer_playlazy(delay)
  274. {
  275. if (typeof ytplayer_playlazy.timeoutid != "undefined")
  276. {
  277. window.clearTimeout(ytplayer_playlazy.timeoutid);
  278. }
  279. ytplayer_playlazy.timeoutid=window.setTimeout(ytplayer_play, delay);
  280. }
  281. function ytplayer_play()
  282. {
  283. var o=document.getElementById("ytplayer_object");
  284. if (o)
  285. {
  286. o.loadVideoById(ytplayer_playlist[ytplayer_playitem]);
  287. }
  288. }
  289.  
  290. function onYouTubePlayerReady(playerid)
  291. {
  292. var o=document.getElementById("ytplayer_object");
  293. if (o)
  294. {
  295. o.addEventListener("onStateChange", "ytplayerOnStateChange");
  296. o.addEventListener("onError", "ytplayerOnError");
  297. }
  298. }
  299.  
  300. function ytplayerOnStateChange(state)
  301. {
  302. if (state==0)
  303. {
  304. ytplayer_playitem += 1;
  305. ytplayer_playitem %= ytplayer_playlist.length;
  306. ytplayer_playlazy(5000);
  307. }
  308. }
  309.  
  310. function ytplayerOnError(error)
  311. {
  312. if (error)
  313. {
  314. ytplayer_playitem += 1;
  315. ytplayer_playitem %= ytplayer_playlist.length;
  316. ytplayer_playlazy(5000);
  317. }
  318. }
  319. var numb="<?php echo $this->options['youtube_number_of_videos'] ?>";
  320. var varr = testing;
  321. for (x=0; x<numb; x++) {
  322. ytplayer_playlist.push(varr[x]);
  323.  
  324. }
  325. </script>
  326. <?php echo "'"; ?>
  327. <?php $l1= "'"; ?> <a name="ytplayer"></a> <?php echo "'"; ?>
  328. <?php $l2= "'"; ?> <div id="ytplayer_div1">You need Flash player 10+ and JavaScript enabled to view this video.</div><?php echo "'"; ?>
  329. <?php $l3= "'"; ?> <div id="ytplayer_div2"></div> <?php echo "'"; ?>
  330.  
  331. <?php return "<div class=\"main_box\">".$l1.$pl.$l2."<div style=\"float:none;width:488px;overflow-x:scroll;\">".$l3."</div>"."</div>";
  332. }
  333.  
  334. } // end Youtube_Content_class
  335.  
  336.  
  337.  
  338. /****
  339. *
  340. *
  341. TRIGGERS ADMIN OPTION ON DASHBOARD
  342. *
  343. */
  344.  
  345.  
  346.  
  347.  
  348. add_action('admin_menu', 'youtube_content_menu');
  349.  
  350. function youtube_content_menu() {
  351.  
  352. Youtube_Content_class::add_menu_page();
  353.  
  354. }
  355.  
  356.  
  357.  
  358. add_action('admin_init', 'youtube_register_settings');
  359.  
  360. function youtube_register_settings(){
  361. new Youtube_Content_class();
  362. }
  363.  
  364. function load_javascripts()
  365. {
  366. // register first script
  367. wp_register_script( 'google-script', 'http://www.google.com/jsapi', array(), null, false );
  368. // wp_register_script( 'user-script', plugins_url( '/js/youtube-script.js', __FILE__ ), array( 'jquery' ) );
  369.  
  370. // then enque it
  371. wp_enqueue_script( 'google-script' );
  372. // wp_enqueue_script( 'user-script' );
  373. }
  374. add_action('init','load_javascripts');
  375.  
  376.  
  377.  
  378.  
  379. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement