toddlevy

.TUBE Video Curator Plugin w/ tube_vc_filter_post_pre_inser

Jul 28th, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 43.51 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: .TUBE Video Curator
  4. Plugin URI: https://www.get.tube/wordpress/tube-video-curator-plugin
  5. Author: .TUBE gTLD
  6. Author URI: https://www.get.tube
  7. Description: The .TUBE Video Curator Plugin for WordPress makes it easy to create posts from YouTube, Vimeo, and Twitch channels, and works seamlessly with most themes and custom post types.
  8. Version: 1.1.5
  9. Text Domain: tube-video-curator
  10. Domain Path: /languages/
  11. License: GPLv2 or later - http://www.gnu.org/licenses/gpl-2.0.html
  12. */
  13.  
  14.  
  15.  
  16. global $tube_video_curator;
  17. $tube_video_curator = Tube_Video_Curator::init();
  18.  
  19.  
  20. class Tube_Video_Curator {
  21.  
  22. public static $tube_dashboard;
  23.  
  24. public static $tube_settings;
  25.  
  26. public static $tube_settings_api_keys;
  27.  
  28. public static $tube_api_key_nag;
  29.  
  30. public static $tube_videos_list;
  31.  
  32. public static $tube_find_videos;
  33.  
  34. public static $tube_find_sources;
  35.  
  36. public static $tube_source_manager;
  37.  
  38. public static $tube_youtube_videos;
  39.  
  40. public static $tube_vimeo_videos;
  41.  
  42. public static $tube_twitch_videos;
  43.  
  44. public static $tube_skipped_videos;
  45.  
  46. public static $tube_embed;
  47.  
  48. public static $tube_linkify;
  49.  
  50. public static $tube_import_cron;
  51.  
  52. //public static $tube_imgur_tools;
  53.  
  54. //public static $tube_go_live;
  55.  
  56. //public static $tube_add_via_imgur;
  57.  
  58. public static $tube_add_via_url;
  59.  
  60. public static $tube_theme_filters;
  61.  
  62. public static $instance;
  63.  
  64. public static function init() {
  65.  
  66. if ( is_null( self::$instance ) )
  67. self::$instance = new Tube_Video_Curator();
  68.  
  69. return self::$instance;
  70.  
  71. }
  72.  
  73.  
  74. // Constructor
  75. function __construct() {
  76.  
  77. // set constant variables for the plugin
  78. self::set_constants();
  79.  
  80. add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
  81.  
  82. // create all the classes used by the plugin
  83. self::create_classes();
  84.  
  85. // load the text-domain
  86. add_action( 'admin_init', array( $this, 'load_tube_vc_textdomain') );
  87.  
  88. // create the Admin menu
  89. add_action( 'admin_menu', array( $this, 'create_tube_vc_admin_menu'), 9 );
  90.  
  91. // customize the admin menu
  92. add_action( 'admin_menu', array( $this, 'customize_tube_vc_admin_menu'), 99 );
  93.  
  94. // add action links to the Plugins List page
  95. add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), array( $this, 'add_tube_vc_action_links' ) );
  96.  
  97. // Init action using for testing autosync capability
  98. // add_action('init', array( $this, 'test_autosync') );
  99.  
  100. // enque the styles for the plugin
  101. add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_tube_vc_admin_styles') );
  102.  
  103. // Activation hook to set the default settings
  104. register_activation_hook( __FILE__, array( self::$tube_settings, 'set_default_plugin_settings') );
  105.  
  106. // Activation hook to set the default Find Videos settings
  107. register_activation_hook( __FILE__, array( self::$tube_find_videos, 'set_default_query_options') );
  108.  
  109. // Activation hook to set the default Find Sources settings
  110. register_activation_hook( __FILE__, array( self::$tube_find_sources, 'set_default_query_options') );
  111.  
  112. // Deactivation hook to clear the autosync cron
  113. register_deactivation_hook( __FILE__, array( self::$tube_import_cron, 'clear_scheduled_autosync_hook') );
  114.  
  115.  
  116.  
  117. // WP Ajax stuff
  118.  
  119. // Create video post
  120. add_action('wp_ajax_create_tube_video_post_via_ajax', array( $this, 'create_tube_video_post_via_ajax') );
  121. add_action('wp_ajax_nopriv_create_tube_video_post_via_ajax', array( $this, 'create_tube_video_post_via_ajax') );
  122.  
  123. // Get all terms for post type
  124. add_action('wp_ajax_get_all_terms_for_tube_video_post_type_via_ajax', array( $this, 'get_all_terms_for_tube_video_post_type_via_ajax') );
  125. add_action('wp_ajax_nopriv_get_all_terms_for_tube_video_post_type_via_ajax', array( $this, 'get_all_terms_for_tube_video_post_type_via_ajax') );
  126.  
  127. // get all taxonomies for post type
  128. add_action('wp_ajax_get_all_taxonomies_for_tube_video_post_type_via_ajax', array( $this, 'get_all_taxonomies_for_tube_video_post_type_via_ajax') );
  129. add_action('wp_ajax_nopriv_get_all_taxonomies_for_tube_video_post_type_via_ajax', array( $this, 'get_all_taxonomies_for_tube_video_post_type_via_ajax') );
  130.  
  131. // Create skipped Video post
  132. add_action('wp_ajax_create_skipped_tube_video_post_via_ajax', array( $this, 'create_skipped_tube_video_post_via_ajax') );
  133. add_action('wp_ajax_nopriv_create_skipped_tube_video_post_via_ajax', array( $this, 'create_skipped_tube_video_post_via_ajax') );
  134.  
  135. // Restore skipped video
  136. add_action('wp_ajax_restore_skipped_tube_video_post_via_ajax', array( $this, 'restore_skipped_tube_video_post_via_ajax') );
  137. add_action('wp_ajax_nopriv_restore_skipped_tube_video_post_via_ajax', array( $this, 'restore_skipped_tube_video_post_via_ajax') );
  138.  
  139.  
  140. }
  141.  
  142.  
  143. // Set up a bunch of constants used by the plugin
  144. private static function set_constants() {
  145.  
  146. $constants = array(
  147. 'TUBE_VIDEO_CURATOR_DIR' => plugin_dir_path( __FILE__ ),
  148. 'TUBE_VIDEO_CURATOR_URL' => plugin_dir_url( __FILE__ ),
  149. 'TUBE_VIDEO_CURATOR_SLUG' => 'tube-video-curator',
  150. 'TUBE_VIDEO_CURATOR_DASH_URL' => admin_url('admin.php?page=tube-video-curator'),
  151. 'TUBE_VIDEO_CURATOR_SETTINGS_URL' => admin_url('admin.php?page=tube-video-curator-settings'),
  152. 'TUBE_VIDEO_CURATOR_IMPORT_SETTINGS_URL' => admin_url('admin.php?page=tube-video-curator-settings&tab=import'),
  153. 'TUBE_VIDEO_CURATOR_API_KEYS_URL' => admin_url('admin.php?page=tube-video-curator-api-keys'),
  154. 'TUBE_VIDEO_CURATOR_VIMEO_API_KEYS_URL' => admin_url('admin.php?page=tube-video-curator-api-keys&tab=vimeo-api'),
  155. 'TUBE_VIDEO_CURATOR_TWITCH_API_KEYS_URL' => admin_url('admin.php?page=tube-video-curator-api-keys&tab=twitch-api'),
  156. 'TUBE_VIDEO_CURATOR_VIEW_SOURCES_URL' => admin_url( 'edit.php?post_type=tube_source' ),
  157. 'TUBE_VIDEO_CURATOR_FIND_SOURCES_URL' => admin_url( 'admin.php?page=tube-video-curator-find-sources' ),
  158. 'TUBE_VIDEO_CURATOR_ADD_VIA_URL_URL' => admin_url( 'admin.php?page=tube-video-curator-add-via-url' ),
  159. 'TUBE_VIDEO_CURATOR_FIND_VIDEOS_URL' => admin_url( 'admin.php?page=tube-video-curator-find-videos' ),
  160. 'TUBE_VIDEO_CURATOR_SKIPPED_VIDEOS_URL' => admin_url( 'edit.php?post_type=tube_skipped_video' ),
  161. 'TUBE_VIDEO_CURATOR_LOADER' => plugin_dir_url( __FILE__ ) . '/images/tube-loader.gif',
  162. );
  163.  
  164. foreach ( $constants as $key => $value):
  165.  
  166. if ( !defined( $key ) ) {
  167. define( $key, $value );
  168. }
  169.  
  170. endforeach;
  171. }
  172.  
  173. function load_textdomain() {
  174. load_plugin_textdomain( TUBE_VIDEO_CURATOR_SLUG, false, dirname( plugin_basename(__FILE__) ) . '/languages' );
  175. }
  176.  
  177.  
  178. private static function create_classes() {
  179.  
  180. // Get the tubeYouTubeVideos instance
  181. require_once TUBE_VIDEO_CURATOR_DIR . '/classes/class-tube-vc-youtube-videos.php';
  182. self::$tube_youtube_videos = new Tube_VC_YouTube_Videos();
  183.  
  184. // Get the Tube_Vimeo_Videos instance
  185. require_once TUBE_VIDEO_CURATOR_DIR . '/classes/class-tube-vc-vimeo-videos.php';
  186. self::$tube_vimeo_videos = new Tube_VC_Vimeo_Videos();
  187.  
  188. // Get the Tube_Twitch_Videos instance
  189. require_once TUBE_VIDEO_CURATOR_DIR . '/classes/class-tube-vc-twitch-videos.php';
  190. self::$tube_twitch_videos = new Tube_VC_Twitch_Videos();
  191.  
  192. // Get the Tube_Settings instance
  193. require_once TUBE_VIDEO_CURATOR_DIR . '/classes/class-tube-vc-settings.php';
  194. self::$tube_settings = new Tube_VC_Settings();
  195.  
  196. // Get the Tube_Settings_Api_Keys instance
  197. require_once TUBE_VIDEO_CURATOR_DIR . '/classes/class-tube-vc-settings-api-keys.php';
  198. self::$tube_settings_api_keys = new Tube_VC_Settings_Api_Keys();
  199.  
  200. // Get the Tube_Api_Key_Nag instance
  201. require_once TUBE_VIDEO_CURATOR_DIR . '/classes/class-tube-vc-api-key-nag.php';
  202. self::$tube_api_key_nag = new Tube_VC_Api_Key_Nag();
  203.  
  204. // Get the Tube_Dashboard instance
  205. require_once TUBE_VIDEO_CURATOR_DIR . '/classes/class-tube-vc-dashboard.php';
  206. self::$tube_dashboard = new Tube_VC_Dashboard();
  207.  
  208. // Get the Tube_Linkify instance
  209. require_once TUBE_VIDEO_CURATOR_DIR . '/classes/class-tube-vc-linkify.php';
  210. self::$tube_linkify = new Tube_VC_Linkify();
  211.  
  212. // Get the Tube_Videos_List instance
  213. require_once TUBE_VIDEO_CURATOR_DIR . '/classes/class-tube-vc-videos-list.php';
  214. self::$tube_videos_list = new Tube_VC_Videos_List();
  215.  
  216. // Get the Tube_Find_Videos instance
  217. require_once TUBE_VIDEO_CURATOR_DIR . '/classes/class-tube-vc-find-videos.php';
  218. self::$tube_find_videos = new Tube_VC_Find_Videos();
  219.  
  220. // Get the $tube_find_sources instance
  221. require_once TUBE_VIDEO_CURATOR_DIR . '/classes/class-tube-vc-find-sources.php';
  222. self::$tube_find_sources = new Tube_VC_Find_Sources();
  223.  
  224. // Get the tubeSources instance
  225. require_once TUBE_VIDEO_CURATOR_DIR . '/classes/class-tube-vc-source-manager.php';
  226. self::$tube_source_manager = new Tube_VC_Source_Manager();
  227.  
  228. // Get the Tube_Skipped_Videos instance
  229. require_once TUBE_VIDEO_CURATOR_DIR . '/classes/class-tube-vc-skipped-videos.php';
  230. self::$tube_skipped_videos = new Tube_VC_Skipped_Videos();
  231.  
  232. // Get the Tube_Embed instance
  233. require_once TUBE_VIDEO_CURATOR_DIR . '/classes/class-tube-vc-embed.php';
  234. self::$tube_embed = new Tube_VC_Embed();
  235.  
  236. // Get the Tube_Import_Cron instance
  237. require_once TUBE_VIDEO_CURATOR_DIR . '/classes/class-tube-vc-import-cron.php';
  238. self::$tube_import_cron = new Tube_VC_Import_Cron();
  239.  
  240. // Get the Tube_Imgur_Tools instance [FUTURE]
  241. //require_once TUBE_VIDEO_CURATOR_DIR . '/classes/FUTURE-class-tube-imgur-tools.php';
  242. //self::$tube_imgur_tools = new Tube_Imgur_Tools();
  243.  
  244. // Get the Tube_Add_Via_Imgur instance [FUTURE]
  245. //require_once TUBE_VIDEO_CURATOR_DIR . '/classes/FUTURE-class-tube-add-via-imgur.php';
  246. //self::$tube_add_via_imgur = new Tube_Add_Via_Imgur();
  247.  
  248. // Get the Tube_Go_Live instance [FUTURE]
  249. //require_once TUBE_VIDEO_CURATOR_DIR . '/classes/class-tube-go-live.php';
  250. //self::$tube_go_live = new Tube_Go_Live();
  251.  
  252. // Get the Tube_Add_Via_Url instance
  253. require_once TUBE_VIDEO_CURATOR_DIR . '/classes/class-tube-vc-add-via-url.php';
  254. self::$tube_add_via_url = new Tube_VC_Add_Via_Url();
  255.  
  256. // Get the Tube_Theme_Filters instance
  257. require_once TUBE_VIDEO_CURATOR_DIR . '/classes/class-tube-vc-theme-filters.php';
  258. self::$tube_theme_filters = new Tube_VC_Theme_Filters();
  259.  
  260. }
  261.  
  262. // function to test the autosycn
  263. function test_autosync() {
  264.  
  265. self::$tube_import_cron -> do_autosync();
  266.  
  267. }
  268.  
  269.  
  270. // Create the Admin Menu for the plugin
  271. function create_tube_vc_admin_menu() {
  272.  
  273. // Main Menu Page
  274. $menu_page = add_menu_page(
  275. __('.TUBE Video Curator', 'tube-video-curator'), // The Page title
  276. __('.TUBE Curator', 'tube-video-curator'), // The Menu Title
  277. 'publish_posts', // The capability required for access to this item
  278. TUBE_VIDEO_CURATOR_SLUG, // the slug to use for the page in the URL
  279. array( $this::$tube_dashboard, 'render_options_page_dashboard' ), // The function to call to render the page
  280. "dashicons-format-video",
  281. 58 // Position
  282. );
  283.  
  284. // Load the Styes / JS conditionally
  285. add_action( 'load-' . $menu_page, array( $this, 'load_tube_vc_admin_styles') );
  286.  
  287.  
  288. // Submenu Page: Settings
  289. $submenu_page_settings = add_submenu_page(
  290. TUBE_VIDEO_CURATOR_SLUG,
  291. '.TUBE Plugin: Plugin Settings',
  292. 'Plugin Settings',
  293. 'manage_options',
  294. TUBE_VIDEO_CURATOR_SLUG .'-settings',
  295. array( $this::$tube_settings, 'render_options_page_settings' )
  296. );
  297. // Load the Styes / JS conditionally
  298. add_action( 'load-' . $submenu_page_settings, array( $this, 'load_tube_vc_admin_styles') );
  299. add_action( 'load-' . $submenu_page_settings, array( $this::$tube_settings, 'load_tube_vc_settings_scripts') );
  300.  
  301.  
  302.  
  303. // Submenu Page: API Settings
  304. $submenu_page_api_settings = add_submenu_page(
  305. TUBE_VIDEO_CURATOR_SLUG,
  306. '.TUBE Plugin: API Keys',
  307. 'Your API Keys',
  308. 'manage_options',
  309. TUBE_VIDEO_CURATOR_SLUG .'-api-keys',
  310. array( $this::$tube_settings_api_keys, 'render_options_page_api_settings' )
  311. );
  312.  
  313. // Load the Styes / JS conditionally
  314. add_action( 'load-' . $submenu_page_api_settings, array( $this, 'load_tube_vc_admin_styles') );
  315.  
  316.  
  317. /*
  318. // Submenu Page: Go Live
  319. $submenu_page_live_stream = add_submenu_page(
  320. TUBE_VIDEO_CURATOR_SLUG,
  321. '.TUBE Plugin: Go Live',
  322. 'Go Live',
  323. 'manage_options',
  324. TUBE_VIDEO_CURATOR_SLUG .'-live-stream',
  325. array( $this::$tube_go_live, 'render_options_page_live_stream' )
  326. );
  327.  
  328.  
  329. // Submenu Page: Add Via Imgur
  330. $submenu_page_add_via_imgur = add_submenu_page(
  331. TUBE_VIDEO_CURATOR_SLUG,
  332. '.TUBE Plugin: Add Via Imgur',
  333. 'Add Via Imgur',
  334. 'manage_options',
  335. TUBE_VIDEO_CURATOR_SLUG .'-add-via-imgur',
  336. array( $this::$tube_add_via_imgur, 'render_options_page_add_via_imgur' )
  337. );
  338. */
  339.  
  340.  
  341. // Submenu Page: Add Via Url
  342. $submenu_page_add_via_url = add_submenu_page(
  343. TUBE_VIDEO_CURATOR_SLUG,
  344. '.TUBE Plugin: Add Via Url',
  345. 'Add Video Via Url',
  346. 'publish_posts',
  347. TUBE_VIDEO_CURATOR_SLUG .'-add-via-url',
  348. array( $this::$tube_add_via_url, 'render_options_page_add_via_url' )
  349. );
  350. // Using registered $page handle to hook script load
  351. add_action( 'load-' . $submenu_page_add_via_url, array( $this, 'load_tube_vc_admin_styles') );
  352. add_action( 'load-' . $submenu_page_add_via_url, array( $this, 'load_tube_vc_find_videos_scripts') );
  353. add_action( 'load-' . $submenu_page_add_via_url, array( $this::$tube_add_via_url, 'load_tube_vc_add_via_url_scripts') );
  354.  
  355.  
  356. // Submenu Page: Find Videos
  357. $submenu_page_find_videos = add_submenu_page(
  358. //$option_page,
  359. TUBE_VIDEO_CURATOR_SLUG,
  360. '.TUBE Plugin: Search for Videos',
  361. 'Search for Videos',
  362. 'publish_posts',
  363. TUBE_VIDEO_CURATOR_SLUG .'-find-videos',
  364. array( $this::$tube_find_videos, 'render_options_page_find_videos' )
  365. );
  366.  
  367. // Using registered $page handle to hook script load
  368. add_action( 'load-' . $submenu_page_find_videos, array( $this, 'load_tube_vc_admin_styles') );
  369. add_action( 'load-' . $submenu_page_find_videos, array( $this, 'load_tube_vc_find_videos_scripts') );
  370.  
  371.  
  372. // Submenu Page: Add Channels & Playlists
  373. $submenu_page_find_sources = add_submenu_page(
  374. //$option_page,
  375. TUBE_VIDEO_CURATOR_SLUG, // page is "hidden" from menus
  376. '.TUBE Plugin: Add New Channels &amp; Playlists',
  377. 'Add Channels &amp; Playlists',
  378. 'manage_options',
  379. TUBE_VIDEO_CURATOR_SLUG .'-find-sources',
  380. array( $this::$tube_find_sources, 'render_options_page_find_sources' )
  381. );
  382.  
  383. // Using registered $page handle to hook script load
  384. add_action( 'load-' . $submenu_page_find_sources, array( $this, 'load_tube_vc_admin_styles') );
  385. add_action( 'load-' . $submenu_page_find_sources, array( $this::$tube_find_sources, 'load_tube_vc_find_sources_scripts') );
  386.  
  387. }
  388.  
  389.  
  390. // Customize the Admin menu
  391. function customize_tube_vc_admin_menu(){
  392.  
  393. // customize the menu
  394. global $submenu;
  395.  
  396. if (
  397. isset( $submenu[TUBE_VIDEO_CURATOR_SLUG] )
  398. && ( current_user_can( 'manage_options' ) || current_user_can( 'publish_posts' ) )
  399.  
  400. ):
  401.  
  402. $curator_submenu = $submenu[TUBE_VIDEO_CURATOR_SLUG];
  403.  
  404. // create a separator device
  405. $separator = array(
  406. '<span class="tube-vc-menu-separator"></span>',
  407. 'publish_posts',
  408. '#',
  409. NULL
  410. );
  411.  
  412.  
  413. // change the name of first menu item
  414. $curator_submenu[0][0] = __( 'Dashboard', 'tube-video-curator' );
  415.  
  416. if( current_user_can( 'manage_options' ) ):
  417.  
  418. // Do something, for admins only
  419.  
  420. $revised_menu[] = $curator_submenu[0]; // Dashboard
  421.  
  422. $revised_menu[] = $separator;
  423.  
  424. $revised_menu[] = $curator_submenu[6]; // Your Channels
  425.  
  426. $revised_menu[] = $curator_submenu[5]; // Add Channels
  427.  
  428. $revised_menu[] = $separator;
  429.  
  430. $revised_menu[] = $curator_submenu[3]; // Add via URL
  431.  
  432. $revised_menu[] = $curator_submenu[4]; // Search Videos
  433.  
  434. $revised_menu[] = $curator_submenu[7]; // Skipped Videos
  435.  
  436. $revised_menu[] = $separator;
  437.  
  438. $revised_menu[] = $curator_submenu[1]; // Settings
  439.  
  440. $revised_menu[] = $curator_submenu[2]; // API Keys
  441.  
  442. elseif ( current_user_can( 'publish_posts' ) ):
  443.  
  444. $revised_menu[] = $curator_submenu[0]; // Dashboard
  445.  
  446. $revised_menu[] = $separator;
  447.  
  448. $revised_menu[] = $curator_submenu[3]; // Your Channels
  449.  
  450. $revised_menu[] = $separator;
  451.  
  452. $revised_menu[] = $curator_submenu[1]; // Add via URL
  453.  
  454. $revised_menu[] = $curator_submenu[2]; // Search Videos
  455.  
  456. $revised_menu[] = $curator_submenu[4]; // Skipped Videos
  457.  
  458.  
  459. endif;
  460.  
  461. $submenu[TUBE_VIDEO_CURATOR_SLUG] = $revised_menu;
  462.  
  463. endif;
  464.  
  465. }
  466.  
  467. // Returns an array of all External Video IDs (to check dupes)
  468. function get_external_video_ids($site) {
  469.  
  470. $args = array(
  471. 'posts_per_page' => -1,
  472. 'post_type' => get_post_types(),
  473. 'meta_query' => array(
  474. array(
  475. 'key' => 'tube_video_id',
  476. 'compare' => 'EXISTS',
  477. ),
  478. array(
  479. 'key' => 'tube_video_site',
  480. 'compare' => '=',
  481. 'value' => $site,
  482. ),
  483. ),
  484. );
  485.  
  486.  
  487. $posts_query = new WP_Query($args);
  488.  
  489. $ids = array();
  490.  
  491. foreach ($posts_query->posts as $post) {
  492. if($post->tube_video_id != ""){
  493.  
  494. if ( $post->post_type == 'tube_skipped_video' ):
  495. $ids[$post->tube_video_id]['status'] = 'skipped';
  496. else:
  497. $ids[$post->tube_video_id]['status'] = $post->post_status;
  498. endif;
  499.  
  500. $ids[$post->tube_video_id]['id'] = $post->ID;
  501. $ids[$post->tube_video_id]['permalink'] = get_permalink($post->ID);
  502. $ids[$post->tube_video_id]['edit'] = get_edit_post_link($post->ID);
  503.  
  504.  
  505. }
  506. }
  507.  
  508. return $ids;
  509.  
  510. }
  511.  
  512.  
  513. // Get the videos pending review (used in dashboard)
  514. function get_videos_pending_review( $args = NULL ) {
  515.  
  516. $args = array(
  517. 'posts_per_page' => -1,
  518. 'post_status' => 'pending',
  519. 'post_type' => get_option( 'tube_vc_default_import_post_type' ),
  520. 'meta_query' => array(
  521. array(
  522. 'key' => 'tube_video_id',
  523. 'compare' => 'EXISTS',
  524. ),
  525. ),
  526. );
  527.  
  528.  
  529. $posts_query = new WP_Query($args);
  530.  
  531. if ( ! $posts_query->have_posts() ):
  532. return NULL;
  533. endif;
  534.  
  535. return $posts_query;
  536.  
  537.  
  538. }
  539.  
  540.  
  541.  
  542. // Get all the taxonomies for the tube video post type (via AJAX)
  543. function get_all_taxonomies_for_tube_video_post_type_via_ajax( ) {
  544.  
  545. $taxonomies = $this -> get_all_taxonomies_for_tube_video_post_type( );
  546.  
  547. $taxonomies = json_encode($taxonomies);
  548.  
  549. echo $taxonomies;
  550.  
  551. die();
  552.  
  553. }
  554.  
  555. // Get all the taxonomies for the tube video post type
  556. function get_all_taxonomies_for_tube_video_post_type( $type = NULL ) {
  557.  
  558. // make sure there's a post type
  559. if ( ! $type && ! array_key_exists('post_type', $_POST) ):
  560. return;
  561. endif;
  562.  
  563. // if no type via argument, use the post_type from $_POST
  564. if ( ! $type ):
  565. $type = $_POST['post_type'];
  566. endif;
  567.  
  568. // Get post type taxonomies.
  569. $taxonomies = get_object_taxonomies($type);
  570.  
  571. // don't include the Nav Menu, Link Cat, or Post Format taxonomies
  572. $ignored = array( 'nav_menu', 'link_category', 'post_format' );
  573.  
  574. if ( ! $taxonomies || ( count( $taxonomies ) == 0 ) ):
  575. return NULL;
  576. endif;
  577.  
  578. foreach ( $taxonomies as $index => $taxonomy ):
  579.  
  580. if ( in_array( $taxonomy, $ignored ) ):
  581. unset( $taxonomies[$index] );
  582. endif;
  583.  
  584. endforeach;
  585.  
  586. // allow taxonomies to be filtered
  587. $taxonomies = apply_filters( 'tube_vc_filter_importable_taxonomies', $taxonomies);
  588.  
  589. if ( ! $taxonomies || ( count( $taxonomies ) == 0 ) ):
  590. return NULL;
  591. endif;
  592.  
  593. // create data about the taxonomies
  594.  
  595. foreach ( $taxonomies as $taxonomy ):
  596.  
  597. $tax_obj = get_taxonomy( $taxonomy );
  598.  
  599. $object = new stdClass();
  600.  
  601. $object->taxonomy_slug = $tax_obj->name;
  602.  
  603. $object->taxonomy_name = $tax_obj->labels->name;
  604.  
  605. $taxonomies_data[] = $object;
  606.  
  607. endforeach;
  608.  
  609. // return the taxonomies
  610. return $taxonomies_data;
  611.  
  612. }
  613.  
  614.  
  615. // Get all the terms for the tube video post type (via AJAX)
  616. function get_all_terms_for_tube_video_post_type_via_ajax( ) { // Returns an array of categories for a post type
  617.  
  618. $terms = $this -> get_all_terms_for_tube_video_post_type( $type );
  619.  
  620. $terms = json_encode($terms);
  621.  
  622. echo $terms;
  623.  
  624. die();
  625.  
  626. }
  627.  
  628.  
  629. // Get all the terms for the tube video post type
  630. function get_all_terms_for_tube_video_post_type( $type = NULL ) { // Returns an array of categories for a post type
  631.  
  632. // make sure there's a post type
  633. if ( ! $type && ! array_key_exists('post_type', $_POST) ):
  634. return;
  635. endif;
  636.  
  637. // if no type via argument, use the post_type from $_POST
  638. if ( ! $type ):
  639. $type = $_POST['post_type'];
  640. endif;
  641.  
  642. // Get all possible taxonomies
  643. $taxonomies = $this -> get_all_taxonomies_for_tube_video_post_type( $type );
  644.  
  645. // make sure there are taxonomies, or do nothing
  646. if ( ! $taxonomies || count($taxonomies) == 0 ):
  647.  
  648. return;
  649.  
  650. endif;
  651.  
  652. // placeholder for the results
  653. $results = array();
  654.  
  655. // loop through the taxonomies
  656. foreach ( $taxonomies as $taxonomy ):
  657.  
  658. $args = array(
  659. 'orderby' => 'name',
  660. 'order' => 'ASC',
  661. 'hide_empty' => false,
  662. 'exclude' => array(),
  663. 'exclude_tree' => array(),
  664. 'include' => array(),
  665. 'number' => '',
  666. 'fields' => 'all',
  667. 'slug' => '',
  668. 'parent' => '',
  669. 'hierarchical' => true,
  670. 'child_of' => 0,
  671. 'get' => '',
  672. 'name__like' => '',
  673. 'description__like' => '',
  674. 'pad_counts' => false,
  675. 'offset' => '',
  676. 'search' => '',
  677. 'cache_domain' => 'core'
  678. );
  679.  
  680. // Get the taxonomy terms
  681. $tax_terms = get_terms( $taxonomy->taxonomy_slug, $args );
  682.  
  683. // loop through the terms
  684. foreach ($tax_terms as $tax_term):
  685.  
  686. if($tax_term):
  687.  
  688. // create data object about the term
  689. $object = new stdClass();
  690.  
  691. $object->id = $tax_term->term_id;
  692.  
  693. $object->name = $tax_term->name;
  694.  
  695. $object->taxonomy_slug = $tax_term->taxonomy;
  696.  
  697. $object->taxonomy_name = $taxonomy->taxonomy_name;
  698.  
  699. // add teh term to the results
  700. $results[] = $object;
  701.  
  702. endif;
  703.  
  704. endforeach;
  705.  
  706.  
  707.  
  708. endforeach;
  709.  
  710. return $results;
  711.  
  712. }
  713.  
  714.  
  715.  
  716. // Create Tube Video post (via AJAX)
  717. function create_tube_video_post_via_ajax(){
  718.  
  719. $post_id = $this -> create_tube_video_post( $_POST );
  720.  
  721. // make sure we got a result
  722. if ( is_numeric($post_id) ):
  723.  
  724. // add the post links to the result
  725. $results['view'] = get_permalink( $post_id );
  726.  
  727. $results['edit'] = get_edit_post_link( $post_id );
  728.  
  729. $results = json_encode($results);
  730.  
  731. echo $results;
  732.  
  733. else:
  734.  
  735. echo 'error';
  736.  
  737. endif;
  738.  
  739. die();
  740.  
  741. }
  742.  
  743.  
  744.  
  745. // Create Tube Video post
  746. function create_tube_video_post( $args ){ // Setting and calling wp_insert_post();
  747.  
  748. $title = $args['title'];
  749.  
  750. //$channel_id = $args['channel_id'];
  751.  
  752. $content = $args['content'];
  753.  
  754. $id = $args['id'];
  755.  
  756. $creator_name = ($args['creator_name'] === '') ? 'unknown user':$args['creator_name'];
  757.  
  758. $author = ( ! array_key_exists('author', $args) ) ? get_option( 'tube_vc_default_import_author') : $args['author']; ;
  759.  
  760. $image_url = $args['image_url'];
  761.  
  762. $media_url = $args['media_url'];
  763.  
  764. $tags = $args['tags'];
  765.  
  766. $date = $args['date'];
  767.  
  768. $source_site = $args['site'];
  769.  
  770. $status = $args['status'];
  771.  
  772. //$descrContent = $content;
  773.  
  774. $excerpt = wp_trim_words( $content, 40 );
  775.  
  776. $auto_imported = ( array_key_exists('auto_imported', $args) ) ? 1 : NULL;
  777.  
  778.  
  779. $date_gmt_formatted = date('Y-m-d H:i:s',strtotime($date));;
  780.  
  781. $replacers = array('/%title%/', '/%description%/', '/%embed%/', '/%media_url%/', '/%thumbnail%/', '/%query%/', '/%user%/', '/%date%/');
  782.  
  783. $post_type = get_option( 'tube_vc_default_import_post_type');
  784.  
  785. // Creating new post
  786. $my_post = array(
  787. 'post_title' => $title,
  788. 'post_content' => $content,
  789. 'post_excerpt' => $excerpt,
  790. 'post_date_gmt' => $date_gmt_formatted,
  791. 'post_status' => $status,
  792. 'post_author' => $author,
  793. 'post_type' => $post_type
  794. );
  795.  
  796. $my_post = apply_filters( 'tube_vc_filter_post_pre_insert', $my_post );
  797.  
  798. $post_ID = wp_insert_post($my_post);
  799. //var_dump($post_ID);
  800. // updating post meta
  801. // if a media is detected, add its source url
  802.  
  803.  
  804. // Set the default import term, if provided
  805. $import_term_id = intval( get_option( 'tube_vc_default_import_term') );
  806.  
  807. if ( $import_term_id ):
  808.  
  809. $import_term = get_term( $import_term_id );
  810.  
  811. if ( $import_term ):
  812.  
  813. wp_set_object_terms( $post_ID, $import_term_id, $import_term->taxonomy );
  814.  
  815. endif;
  816.  
  817. endif;
  818.  
  819.  
  820. // deal with tag importing
  821. if ( $tags ):
  822.  
  823. //$taxonomy = 'category';
  824. $taxonomy = get_option( 'tube_vc_default_tag_import_taxonomy');
  825.  
  826. if ( $taxonomy ):
  827.  
  828. // create an array from the tags,if it's not an array already
  829. $tags_array = is_array( $tags ) ? $tags : explode(',', $tags);
  830.  
  831. $tags_sanitized = array();
  832.  
  833. // sanitize all the the tags
  834. foreach ( $tags_array as $tag ):
  835.  
  836. $tags_sanitized[] = esc_html( $tag );
  837.  
  838. endforeach;
  839.  
  840. wp_add_object_terms( $post_ID, $tags_sanitized, $taxonomy );
  841.  
  842. endif;
  843.  
  844. endif;
  845.  
  846. // add all the post meta
  847. add_post_meta( $post_ID, 'tube_video_oembed_url', $media_url, true );
  848.  
  849. add_post_meta( $post_ID, 'tube_video_date', $date, true );
  850.  
  851. add_post_meta( $post_ID, 'tube_video_id', $id, true );
  852.  
  853. add_post_meta( $post_ID, 'tube_video_site', $source_site, true );
  854.  
  855. add_post_meta( $post_ID, 'tube_video_creator_name', $creator_name, true );
  856.  
  857. if ($auto_imported):
  858. add_post_meta( $post_ID, 'tube_video_auto_imported', $auto_imported, true );
  859. endif;
  860.  
  861.  
  862. if( $image_url ):
  863.  
  864. add_post_meta( $post_ID, 'tube_video_image_url', $image_url, true ) || update_post_meta( $post_ID, 'tube_video_image_url', $image_url );
  865.  
  866. // Create and upload thumbnail
  867. $upload_dir = wp_upload_dir();
  868. $image_data = file_get_contents($image_url);
  869. $title_sanitized = substr(sanitize_title(stripslashes($title)), -70);
  870. $filename = $title_sanitized . '-' . $id.basename($image_url);
  871. $filename = str_replace( array('%','maxresdefault'),'', $filename);
  872.  
  873. if(wp_mkdir_p($upload_dir['path']))
  874. $file = $upload_dir['path'] . '/' . $filename;
  875. else
  876. $file = $upload_dir['basedir'] . '/' . $filename;
  877. file_put_contents($file, $image_data);
  878.  
  879. $wp_filetype = wp_check_filetype($filename, null );
  880.  
  881.  
  882. $caption = '<a href="'.$media_url.'" target="_blank">' . _x('Source', 'Text of source link in image caption', 'tube-video-curator') . '</a>';
  883.  
  884. $attachment = array(
  885. 'post_mime_type' => $wp_filetype['type'],
  886. 'post_title' => esc_html($title),
  887. 'post_excerpt' => wp_kses_post($caption),
  888. 'post_content' => '',
  889. 'post_status' => 'inherit'
  890. );
  891. $attach_id = wp_insert_attachment( $attachment, $file, $post_ID );
  892. require_once(ABSPATH . 'wp-admin/includes/image.php');
  893. $attach_data = wp_generate_attachment_metadata( $attach_id, $file );
  894. wp_update_attachment_metadata( $attach_id, $attach_data );
  895.  
  896. update_post_meta($attach_id, '_wp_attachment_image_alt', esc_html($title));
  897.  
  898. set_post_thumbnail( $post_ID, $attach_id );
  899.  
  900. endif;
  901.  
  902. return $post_ID;
  903.  
  904. }
  905.  
  906.  
  907.  
  908. // Create the skipped video post (via AJAX)
  909. function create_skipped_tube_video_post_via_ajax(){ // Reject post : insert
  910.  
  911. $title = $_POST['title'];
  912.  
  913. $content = $_POST['content'];
  914.  
  915. $creator_name = $_POST['creator_name'];
  916.  
  917. $id = $_POST['id'];
  918.  
  919. $date = $_POST['date'];
  920.  
  921. $date_gmt_formatted = date('Y-m-d H:i:s',strtotime($date));;
  922.  
  923. $media_url = $_POST['media_url'];
  924.  
  925. $source_site = $_POST['site'];
  926.  
  927. $author = ( ! array_key_exists('author', $_POST) ) ? get_option( 'tube_vc_default_import_author') : $_POST['author']; ;
  928.  
  929.  
  930. $skipped_video_post_args = array(
  931. 'post_name' => $source_site . '-' . $id,
  932. 'post_title' => $title . ' [' . $creator_name . ' | ' . $source_site . ']',
  933. 'post_content' => $content,
  934. 'post_date_gmt' => $date_gmt_formatted,
  935. 'post_status' => 'publish',
  936. //'tags_input' => $author,
  937. 'post_author' => $author,
  938. 'post_type' => 'tube_skipped_video'
  939. );
  940.  
  941. $skipped_video_post = wp_insert_post($skipped_video_post_args);
  942.  
  943. add_post_meta( $skipped_video_post, 'tube_video_oembed_url', $media_url, true );
  944. add_post_meta( $skipped_video_post, 'tube_video_date', $date, true );
  945. add_post_meta( $skipped_video_post, 'tube_video_id', $id, true );
  946. add_post_meta( $skipped_video_post, 'tube_video_site', $source_site, true );
  947. add_post_meta( $skipped_video_post, 'tube_video_creator_name', $creator_name, true );
  948. //add_post_meta( $skipped_video_post, 'tube_video_channel_id', $channel_id, true );
  949.  
  950.  
  951. if ( is_numeric($skipped_video_post) ):
  952.  
  953. $results['id'] = $skipped_video_post ;
  954.  
  955. $results['view'] = get_permalink( $skipped_video_post );
  956.  
  957. $results['edit'] = get_edit_post_link( $skipped_video_post );
  958.  
  959. $results = json_encode($results);
  960.  
  961. echo $results;
  962.  
  963. else:
  964.  
  965. echo 'error';
  966.  
  967. endif;
  968.  
  969. die();
  970. }
  971.  
  972.  
  973.  
  974. // Restore the skipped video post (via AJAX)
  975. function restore_skipped_tube_video_post_via_ajax(){ // Reject post : insert
  976.  
  977. $post_id = $_POST['postid'];
  978.  
  979. $restore_post = wp_delete_post($post_id);
  980.  
  981. if ( $restore_post ):
  982. echo 'success';
  983. else:
  984. echo 'error';
  985. endif;
  986.  
  987. die();
  988. }
  989.  
  990.  
  991. // Load the text domain
  992. function load_tube_vc_textdomain() {
  993.  
  994. load_plugin_textdomain('tube-video-curator', false, basename( dirname( __FILE__ ) ) . '/i18n' );
  995.  
  996. }
  997.  
  998.  
  999.  
  1000. // Main Tube Admin CSS
  1001. function load_tube_vc_admin_styles(){
  1002. add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_tube_vc_admin_styles') );
  1003. }
  1004.  
  1005. function enqueue_tube_vc_admin_styles() {
  1006. wp_register_style(
  1007. TUBE_VIDEO_CURATOR_SLUG,
  1008. plugins_url('/css/style.css', __FILE__),
  1009. array(),
  1010. '1.0.0'
  1011. );
  1012. wp_enqueue_style(TUBE_VIDEO_CURATOR_SLUG);
  1013.  
  1014. }
  1015.  
  1016.  
  1017.  
  1018. function load_tube_vc_find_videos_scripts(){
  1019.  
  1020. add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_find_videos_scripts') );
  1021.  
  1022. }
  1023.  
  1024.  
  1025. function enqueue_find_videos_scripts() {
  1026.  
  1027. wp_register_script(
  1028. 'tube_vc_find_videos',
  1029. plugins_url('/js/tube-vc-find-videos.js', __FILE__),
  1030. array(),
  1031. '1.0.0',
  1032. //rand(50000, 150000),
  1033. false
  1034. );
  1035. wp_enqueue_script('tube_vc_find_videos');
  1036.  
  1037. add_action( 'admin_print_scripts', array( $this, 'print_find_videos_scripts'), 99 );
  1038.  
  1039. }
  1040.  
  1041.  
  1042. function print_find_videos_scripts() {
  1043. ?>
  1044. <script type="text/javascript">
  1045. var pluginDirectory = '<?php echo plugins_url('', __FILE__); ?>';
  1046. Tube_VC_Ajax_Videos.query = '<?php echo get_option( 'tube_vc_find_videos_query', '' ); ?>';
  1047. Tube_VC_Ajax_Videos.queryType = '<?php echo get_option( 'tube_vc_find_videos_query_type', '' ); ?>';
  1048. Tube_VC_Ajax_Videos.number = '<?php echo get_option( 'tube_vc_find_videos_max_results', '' ); ?>';
  1049. Tube_VC_Ajax_Videos.currentCat = '<?php echo get_option( 'tube_vc_default_import_term', '' ); ?>';
  1050. Tube_VC_Ajax_Videos.currentTagImportTax = '<?php echo get_option( 'tube_vc_default_tag_import_taxonomy', '' ); ?>';
  1051. Tube_VC_Ajax_Videos.trans.approve = '<?php _e('Approve', 'tube-video-curator'); ?>';
  1052. Tube_VC_Ajax_Videos.trans.deny = '<?php _e('Deny', 'tube-video-curator'); ?>';
  1053. Tube_VC_Ajax_Videos.trans.needUpdate = '<?php _e('You have changed the query parameters, remember to click on Save Changes to update the results.', 'tube-video-curator'); ?>';
  1054. Tube_VC_Ajax_Videos.trans.apiWrong = '<?php _e('There is an error with your API key, it has been rejected by Google API Service.', 'tube-video-curator'); ?>';
  1055. Tube_VC_Ajax_Videos.trans.loading = '<?php _e('Loading...', 'tube-video-curator'); ?>';
  1056. Tube_VC_Ajax_Videos.trans.mediaFailed = '<?php _e('Video import failed. Please try again.', 'tube-video-curator'); ?>';
  1057. Tube_VC_Ajax_Videos.trans.mediaAdded = '<?php _e('Video added successfully.', 'tube-video-curator'); ?>';
  1058. Tube_VC_Ajax_Videos.trans.mediaRejected = '<?php _e('Video skipped successfully.', 'tube-video-curator'); ?>';
  1059. Tube_VC_Ajax_Videos.trans.restoreFailed = '<?php _e('Video restore failed. Please try again.', 'tube-video-curator'); ?>';
  1060. Tube_VC_Ajax_Videos.trans.mediaRestored = '<?php _e('Video restored successfully.', 'tube-video-curator'); ?>';
  1061. Tube_VC_Ajax_Videos.trans.videoPublishedFlag = '<?php _e('PUBLISHED', 'tube-video-curator'); ?>';
  1062. Tube_VC_Ajax_Videos.trans.videoDraftFlag = '<?php _e('DRAFT', 'tube-video-curator'); ?>';
  1063. Tube_VC_Ajax_Videos.trans.videoPendingFlag = '<?php _e('PENDING', 'tube-video-curator'); ?>';
  1064. Tube_VC_Ajax_Videos.trans.videoSkippedFlag = '<?php _e('SKIPPED', 'tube-video-curator'); ?>';
  1065. </script>
  1066.  
  1067. <?php
  1068. }
  1069.  
  1070.  
  1071.  
  1072.  
  1073.  
  1074.  
  1075. /* -----------------------------------------------------------------------------
  1076. * Render the admin page
  1077. ---------------------------------------------------------------------------- */
  1078.  
  1079. function render_options_page_find_videos() {
  1080.  
  1081. require_once(dirname(__FILE__) . '/TOSS-page-find-videos.php');
  1082.  
  1083. }
  1084.  
  1085.  
  1086.  
  1087.  
  1088.  
  1089. // add action links to the Plugins List page
  1090. function add_tube_vc_action_links ( $links ) {
  1091.  
  1092. $mylinks = array(
  1093. '<a href="' . TUBE_VIDEO_CURATOR_DASH_URL . '">Dashboard</a>',
  1094. '<a href="' . TUBE_VIDEO_CURATOR_SETTINGS_URL . '">Settings</a>'
  1095. );
  1096.  
  1097. return array_merge( $links, $mylinks );
  1098.  
  1099. }
  1100.  
  1101.  
  1102. /* -----------------------------------------------------------------------------
  1103. * Get settings values for sites & autosycn
  1104. ---------------------------------------------------------------------------- */
  1105.  
  1106.  
  1107. function get_external_site_options( $active_only = false ){
  1108.  
  1109. $sites = array();
  1110.  
  1111. $sites['youtube'] = 'YouTube';
  1112.  
  1113. $sites['vimeo'] = 'Vimeo';
  1114.  
  1115. $sites['twitch'] = 'Twitch';
  1116.  
  1117. if ( ! $active_only ):
  1118.  
  1119. return $sites;
  1120.  
  1121. endif;
  1122.  
  1123.  
  1124. // get the search site value
  1125. $search_site = get_option( 'tube_vc_find_videos_site' );
  1126.  
  1127.  
  1128. $youtube_api_key = Tube_Video_Curator::$tube_youtube_videos->get_youtube_api_key();
  1129.  
  1130. $vimeo_api_key = Tube_Video_Curator::$tube_vimeo_videos->get_vimeo_api_key();
  1131.  
  1132. $twitch_api_key = Tube_Video_Curator::$tube_twitch_videos->get_twitch_api_key();
  1133.  
  1134. if ( ! $youtube_api_key ):
  1135.  
  1136. // Remove YouTube from search options
  1137. unset( $sites['youtube'] );
  1138.  
  1139. // make sure it's not using YouTube as search site
  1140. if ( $search_site == 'youtube' ):
  1141.  
  1142. delete_option( 'tube_vc_find_videos_site' );
  1143.  
  1144. endif;
  1145.  
  1146. // check if there's a Vimeo key and update the site option if so
  1147. if ( $vimeo_api_key ):
  1148.  
  1149. update_option( 'tube_vc_find_videos_site', 'vimeo' );
  1150.  
  1151. endif;
  1152.  
  1153. endif;
  1154.  
  1155.  
  1156. if ( ! $vimeo_api_key):
  1157.  
  1158. // Remove Vimeo from search options
  1159. unset( $sites['vimeo'] );
  1160.  
  1161. // make sure it's not using Vimeo as search site
  1162. if ( $search_site == 'vimeo' ):
  1163.  
  1164. delete_option( 'tube_vc_find_videos_site' );
  1165.  
  1166. endif;
  1167.  
  1168. // check if there's a YouTube key and update the site option if so
  1169. if ( $youtube_api_key ):
  1170.  
  1171. update_option( 'tube_vc_find_videos_site', 'youtube' );
  1172.  
  1173. endif;
  1174.  
  1175. endif;
  1176.  
  1177. /*
  1178.  
  1179. if ( ! $twitch_api_key):
  1180.  
  1181. // Remove Twitch from search options
  1182. unset( $sites['twitch'] );
  1183.  
  1184. // make sure it's not using Twitch as search site
  1185. if ( $search_site == 'twitch' ):
  1186.  
  1187. delete_option( 'tube_vc_find_videos_site' );
  1188.  
  1189. endif;
  1190.  
  1191. // check if there's a YouTube key and update the site option if so
  1192. if ( $youtube_api_key ):
  1193.  
  1194. update_option( 'tube_vc_find_videos_site', 'youtube' );
  1195.  
  1196. endif;
  1197.  
  1198. endif;
  1199. */
  1200.  
  1201. return $sites;
  1202.  
  1203. }
  1204.  
  1205. function get_external_site_label( $key ){
  1206.  
  1207. $options = $this->get_external_site_options();
  1208.  
  1209. if ( ! array_key_exists($key, $options) ):
  1210. return NULL;
  1211. endif;
  1212.  
  1213. return $options[$key];
  1214.  
  1215. }
  1216.  
  1217.  
  1218. function get_feed_type_options($require_api = false){
  1219.  
  1220. $options = array();
  1221.  
  1222. $youtube_api_key = Tube_Video_Curator::$tube_youtube_videos->get_youtube_api_key();
  1223.  
  1224. if ($youtube_api_key || ! $require_api):
  1225.  
  1226. $options['youtube-channel'] = 'YouTube Channel';
  1227.  
  1228. $options['youtube-playlist'] = 'YouTube Playlist';
  1229.  
  1230. endif;
  1231.  
  1232. $vimeo_api_key = Tube_Video_Curator::$tube_vimeo_videos->get_vimeo_api_key();
  1233.  
  1234. if ($vimeo_api_key || ! $require_api):
  1235.  
  1236. $options['vimeo-username'] = 'Vimeo User';
  1237.  
  1238. $options['vimeo-channel'] = 'Vimeo Channel';
  1239.  
  1240. endif;
  1241.  
  1242.  
  1243. $twitch_api_key = Tube_Video_Curator::$tube_twitch_videos->get_twitch_api_key();
  1244.  
  1245. if ($twitch_api_key || ! $require_api):
  1246.  
  1247. $options['twitch-channel'] = 'Twitch Channel';
  1248.  
  1249. endif;
  1250.  
  1251.  
  1252. return $options;
  1253.  
  1254. }
  1255.  
  1256.  
  1257.  
  1258. function get_feed_type_label( $feed_type ){
  1259.  
  1260. $options = $this->get_feed_type_options();
  1261.  
  1262. if ( ! array_key_exists( $feed_type, $options) ):
  1263. return NULL;
  1264. endif;
  1265.  
  1266. return $options[$feed_type];
  1267.  
  1268. }
  1269.  
  1270.  
  1271. function get_auto_import_status( $video_data ){
  1272.  
  1273. $auto_import_status = get_option( 'tube_vc_default_auto_import_status');
  1274.  
  1275. $auto_import_status = apply_filters( 'tube_vc_filter_auto_import_status', $auto_import_status, $video_data );
  1276.  
  1277. return $auto_import_status;
  1278.  
  1279. }
  1280.  
  1281.  
  1282. public static function has_api_keys( $required = NULL ){
  1283.  
  1284.  
  1285. $api_keys['youtube'] = Tube_Video_Curator::$tube_youtube_videos->get_youtube_api_key();
  1286.  
  1287. $api_keys['vimeo'] = Tube_Video_Curator::$tube_vimeo_videos->get_vimeo_api_key();
  1288.  
  1289. $api_keys['twitch'] = Tube_Video_Curator::$tube_twitch_videos->get_twitch_api_key();
  1290.  
  1291. if ( $required ):
  1292.  
  1293. foreach ( $required as $is_required ):
  1294.  
  1295. // only need one match to be true
  1296. if ( $api_keys[$is_required] ) return true;
  1297.  
  1298. endforeach;
  1299.  
  1300. else:
  1301.  
  1302. foreach ( $api_keys as $key => $key_value ):
  1303.  
  1304. // only need one match to be true
  1305. if ( $key_value ) return true;
  1306.  
  1307. endforeach;
  1308.  
  1309. endif;
  1310.  
  1311. return false;
  1312.  
  1313. }
  1314.  
  1315.  
  1316. public static function no_api_keys_message( ){
  1317.  
  1318. $message = sprintf(
  1319. __('Sorry, you must have a <a href="%1$s">YouTube</a>, <a href="%2$s">Vimeo</a>, or <a href="%3$s">Twitch</a> API key to use this feature.', 'tube-video-curator'),
  1320. TUBE_VIDEO_CURATOR_API_KEYS_URL,
  1321. TUBE_VIDEO_CURATOR_VIMEO_API_KEYS_URL,
  1322. TUBE_VIDEO_CURATOR_TWITCH_API_KEYS_URL
  1323. );
  1324.  
  1325. echo wp_kses_post( '<p>' . $message . '</p>' );
  1326.  
  1327. return;
  1328.  
  1329. }
  1330.  
  1331. public static function no_youtube_or_vimeo_api_keys_message( ){
  1332.  
  1333. $message = sprintf(
  1334. __('Sorry, you must have a <a href="%1$s">YouTube</a> or <a href="%2$s">Vimeo</a> API key to use this feature.', 'tube-video-curator'),
  1335. TUBE_VIDEO_CURATOR_API_KEYS_URL,
  1336. TUBE_VIDEO_CURATOR_VIMEO_API_KEYS_URL
  1337. );
  1338.  
  1339. echo wp_kses_post( '<p>' . $message . '</p>' );
  1340.  
  1341. return;
  1342.  
  1343. }
  1344.  
  1345.  
  1346.  
  1347.  
  1348.  
  1349.  
  1350. }
Advertisement
Add Comment
Please, Sign In to add comment