コード例 #1
0
    function build_config_page_options()
    {
        $curr_page_url = get_admin_url() . "admin.php?page=new_royalslider_settings";
        if (isset($_GET['code']) && strpos(strtolower($_SERVER["REQUEST_URI"]), 'royalslider') > -1) {
            ?>
			<script type="text/javascript">
			window.opener.processInstagramAuthCode("<?php 
            echo $_GET['code'];
            ?>
");
			window.close();
			</script>
			<?php 
            return;
        }
        $sections = array(array('id' => 'new_royalslider_config', 'title' => __('', 'new_royalslider')));
        $fields = array('new_royalslider_config' => array(array('name' => 'embed', 'label' => __('Preload CSS and JavaScript files', 'new_royalslider'), 'desc' => esc_attr(__("To include JavaScript and CSS files manually, call <?php register_new_royalslider_files(123); ?> function in your theme functions.php. It'll load all files associated with slider (instead of 123 put actual ID of your slider).", 'new_royalslider')) . ' <a href="http://dimsemenov.com/private/forum.php?to=kb/wordpress-royalslider-tutorials/wp-including-javascript-and-css-files" target="_blank">' . __('Learn more on support desk', 'new_royalslider') . '</a>', 'type' => 'multicheck', 'options' => array('posts_with_slider' => __('On posts with slider shortcode in content', 'new_royalslider'), 'home_page' => __('On home (front) page', 'new_royalslider'), 'every_page' => __('On every page (overrides all other options)', 'new_royalslider')), 'default' => array('posts_with_slider' => 'posts_with_slider')), array('name' => 'allow_authors_cap', 'label' => __('Allow editing and creating sliders for Editors and Authors', 'new_royalslider'), 'desc' => __('*this settings page is always available only to Admins', 'new_royalslider'), 'type' => 'radio', 'options' => array('yes' => 'Yes', 'no' => 'No'), 'default' => 'no'), array('name' => 'cache_refresh_time', 'label' => __('Slider cache refresh time', 'new_royalslider'), 'desc' => __('Hours. Cache is also cleared when you click on "Save Slider" button in editor', 'new_royalslider'), 'type' => 'text', 'default' => '24', 'size' => 'small'), array('name' => 'override_all_default_galleries', 'label' => __('Override all default WordPress galleries (without <code>royalslider</code> attribute in <code>[gallery]</code> shortcode)', 'new_royalslider'), 'desc' => __('Enter ID of Default Gallery slider that should be used, or leave field empty to disable this feature'), 'type' => 'text', 'default' => '', 'size' => 'small'), array('name' => 'purchase_code', 'label' => __('Purchase code', 'new_royalslider'), 'desc' => '<input type="submit" id="p-code-status" name="" class="button action" value="Check code"><br/> ' . __('Used for automatic updates. <a target="_blank" href="http://dimsemenov.com/where-to-find-purchase-code.html">Where to find CodeCanyon puchase code?</a>') . "\n<script>\njQuery(document).ready(function(\$){ \n\tvar status = \$('#p-code-status');\n\tvar input = \$(document.getElementById('new_royalslider_config[purchase_code]'));\n\tvar checkCode = function() { \n\n\t\tvar codeValue = input.val();\n\n\t\tif(!codeValue) {\n\t\t\tstatus.html('');\n\t\t\treturn;\n\t\t}\n\t\tstatus.val('Checking...   ');\n\n\t\t\$.ajax({\n\t\t\turl: '" . admin_url('admin-ajax.php') . "',\n\t\t\ttype: 'post',\n\t\t\tdata: {\n\t\t\t\taction : 'checkPurchaseCode',\n\t\t\t\tpurchase_code: codeValue,\n\t\t\t\t_ajax_nonce : '" . wp_create_nonce('new_royalslider_ajax_pcode_nonce') . "'\n\t\t\t}\n\t\t}).done(function( data ) {\n\t\t\tif(data.indexOf('[VALID_CODE]') > -1) {\n\t\t\t\talert('Thank you, the purchase code is correct. Now save settings on this page.');\n\t\t\t} else {\n\t\t\t\talert('Incorrect purchase code. If the problem persists - please contact the developer of plugin.');\n\t\t\t}\n\t\t}).error(function() {\n\t\t\talert('There was a problem with request, please refresh and try again or contact plugin support.');\n\t\t}).always(function() {\n\t\t\tisRunning = false;\n\t\t\tstatus.val('Check code');\n\t\t});\n\n \t};\n\n\n\tstatus.on('click', function(e) {\n\t\te.preventDefault();\n\t\tcheckCode();\n\t\treturn false;\n\t});\n\n\t\n});\n</script>", 'type' => 'text', 'default' => '', 'size' => 'regular'), array('name' => 'youtube_public_api_code', 'label' => __('YouTube API code', 'new_royalslider'), 'desc' => '<br/>Used to fetch YouTube cover image, title and description. <a href="http://help.dimsemenov.com/kb/wordpress-royalslider-tutorials/wp-how-to-get-youtube-api-key" target="_blank">' . __('How to get YouTube API code?', 'new_royalslider') . '</a>', 'type' => 'text', 'default' => '', 'size' => 'regular'), array('name' => 'instagram_settings_title', 'label' => __('<h3>Instagram Settings</h3>', 'new_royalslider'), 'desc' => '', 'type' => 'html', 'default' => '123', 'size' => 'small'), array('name' => 'instagram_client_id', 'label' => __('Instagram client ID', 'new_royalslider'), 'desc' => '<span style="font-style:normal;"><br/><a href="http://help.dimsemenov.com/kb/wordpress-royalslider-faq/wp-how-to-get-instagram-client-id-and-client-secret-key" target="_blank">' . __('How to get Instagram "client ID" and "client secret key"?', 'new_royalslider') . '</a><br/> ' . __('Redirect URI: ', 'new_royalslider') . '<code>' . $curr_page_url . '</code>', 'type' => 'text', 'default' => '', 'size' => 'regular'), array('name' => 'instagram_client_secret', 'label' => __('Instagram client secret key', 'new_royalslider'), 'desc' => __(''), 'type' => 'text', 'default' => '', 'size' => 'regular')));
        $login_url = '';
        require_once 'third-party/instagram.class.php';
        $oauth_token = get_option('new_royalslider_instagram_oauth_token');
        if ($oauth_token && isset($oauth_token->user)) {
            $user_data = $oauth_token->user;
        } else {
            $user_data = '';
        }
        $fields['new_royalslider_config'][] = array('name' => 'instagram_login_button', 'label' => '', 'desc' => '
            <div id="instagram-status" class="hidden"></div>
            <input type="submit" id="instagram-login" name="" class="hidden button action" value="' . __('Connect Instagram', 'new_royalslider') . '">
            <input type="submit" id="instagram-logout" name="" class="hidden button action" value="' . __('Disconnect Instagram', 'new_royalslider') . '">
            <span id="connection-status"></span>

            <style>
            #instagram-status {
            	padding: 1em 1em;
				background: rgb(236, 236, 236);
				width: 23em;
				height: 30px;
				margin-bottom: 9px;
       		}
            #instagram-status strong {
            	float: left;
            	margin: 5px;
            	display: block;
	        }
	        #instagram-status img {
		        float: left;
		    }
		    #connection-status {
		    	margin-left: 6px;
			}
            </style>
            


            <script>
            jQuery(document).ready(function($) {

            	var apiKey = $("#new_royalslider_config\\\\[instagram_client_id\\\\]").val(); 
				var apiSecret = $("#new_royalslider_config\\\\[instagram_client_secret\\\\]").val();
				var userData = $.parseJSON(\'' . json_encode($user_data) . '\');
				var redirectURL = "' . $curr_page_url . '";

				var updateUserData = function() {
					if(userData && userData.id) {
						$("#instagram-status").html("<img width=\'30\' height=\'30\' src=\'" + userData.profile_picture + "\' /><strong>" + userData.username + "</strong>").removeClass("hidden");
						$("#instagram-logout").removeClass("hidden");
					} else {
						$("#instagram-login").removeClass("hidden");
					}
				};
				updateUserData();

				var isRunning;
            	window.processInstagramAuthCode = function(code) {
            		if(isRunning) {
            			return;
            		}
            		isRunning = true;

            		$("#connection-status").html("Retrieving user data...");

            		$.ajax({
						url: "' . admin_url('admin-ajax.php') . '",
						type: "post",
						data: {
							action : "rsInstagramAuth",
							instagramCode: code,
							instagramApiKey: apiKey,
							instagramApiSecret: apiSecret,
							_ajax_nonce : "' . wp_create_nonce('new_royalslider_ajax_instagram_nonce') . '"
						}
					}).done(function( data ) {

						userData = $.parseJSON(data);
						if(userData) {
							userData = userData.user;
						}
						updateUserData();
						$("#connection-status").empty();

						$("#instagram-logout").removeClass("hidden");
						$("#instagram-login").addClass("hidden");
					}).error(function() {
						alert("There was a problem with request, please refresh and try again or contact plugin support.");
						$("#connection-status").empty();
					}).always(function() {
						isRunning = false;
					});
            	};

                $("#instagram-login").click(function(e) {
                	e.preventDefault();
                	if(isRunning) {
                		return;
                	}
                	
                	apiKey = $("#new_royalslider_config\\\\[instagram_client_id\\\\]").val(); 
					apiSecret = $("#new_royalslider_config\\\\[instagram_client_secret\\\\]").val();

					if(!apiKey) {
						alert("Please enter Instagram client ID");
						return;
					}
					if(!apiSecret) {
						alert("Please enter Instagram client secret key.");
						return;
					}
                	
                	$("#connection-status").html("Connecting to your Instagram account...");

					var loginURL = "https://api.instagram.com/oauth/authorize?client_id=" +apiKey+ "&redirect_uri="+redirectURL+"&scope=basic&response_type=code";


					window.open(loginURL, "intent", "scrollbars=yes,resizable=yes,toolbar=no,location=yes,width=550,height=420,left=" + (window.screen ? Math.round(screen.width / 2 - 275) : 50) + ",top=" + 100);
     
                });

				$("#instagram-logout").click(function(e) {
					e.preventDefault();


					if(isRunning) {
            			return false;
            		}
            		isRunning = true;
					
					$("#connection-status").html("Disconnecting...");
					$.ajax({
						url: "' . admin_url('admin-ajax.php') . '",
						type: "post",
						data: {
							action : "rsInstagramAuth",
							instagramDisconnect: true,
							_ajax_nonce : "' . wp_create_nonce('new_royalslider_ajax_instagram_nonce') . '"
						}
					}).done(function( data ) {
						$("#connection-status").empty();
						$("#instagram-status").addClass("hidden");
						$("#instagram-logout").addClass("hidden");
						$("#instagram-login").removeClass("hidden");
					}).error(function() {
						alert("There was a problem with request, please refresh and try again or contact plugin support.");
						$("#connection-status").empty();
					}).always(function() {
						isRunning = false;
					});
				});

    		});
            </script>

            ', 'type' => 'html', 'default' => '123', 'size' => 'small');
        $settings_api = RS_WeDevs_Settings_API::getInstance();
        $settings_api->set_sections($sections);
        $settings_api->set_fields($fields);
        $settings_api->admin_init();
    }
コード例 #2
0
 function build_config_page_options()
 {
     $sections = array(array('id' => 'new_royalslider_config', 'title' => __('', 'new_royalslider')));
     $fields = array('new_royalslider_config' => array(array('name' => 'embed', 'label' => __('Preload CSS and JavaSript files:', 'new_royalslider'), 'desc' => esc_attr(__("To include JavaScript and CSS files manually, call <?php register_new_royalslider_files(123); ?> function in your theme functions.php. It'll load all files associated with slider (instead of 123 put actual ID of your slider).", 'new_royalslider')) . ' <a href="http://dimsemenov.com/private/forum.php?to=kb/wordpress-royalslider-tutorials/wp-including-javascript-and-css-files" target="_blank">' . __('Learn more on support desk', 'new_royalslider') . '</a>', 'type' => 'multicheck', 'options' => array('posts_with_slider' => __('On posts with slider shortcode in content', 'new_royalslider'), 'home_page' => __('On home (front) page', 'new_royalslider'), 'every_page' => __('On every page (overrides all other options)', 'new_royalslider')), 'default' => array('posts_with_slider' => 'posts_with_slider')), array('name' => 'allow_authors_cap', 'label' => __('Allow editing and creating sliders for Editors and Authors', 'new_royalslider'), 'desc' => __('*this settings page is always available only to Admins', 'new_royalslider'), 'type' => 'radio', 'options' => array('yes' => 'Yes', 'no' => 'No'), 'default' => 'no'), array('name' => 'cache_refresh_time', 'label' => __('Slider cache refresh time', 'new_royalslider'), 'desc' => __('In hours. Cache is also cleared when you click on Save slider button in editor', 'new_royalslider'), 'type' => 'text', 'default' => '24', 'size' => 'small'), array('name' => 'override_all_default_galleries', 'label' => __('Override all default WordPress galleries in posts (without adding <code>royalslider</code> attribute to <code>[gallery]</code> shortcode)<br/>You can still add this attribute to your galleries if you want to override default.', 'new_royalslider'), 'desc' => __('Enter ID of Default Gallery slider that should be used, or leave field empty to disable this feature'), 'type' => 'text', 'default' => '', 'size' => 'small')));
     $settings_api = RS_WeDevs_Settings_API::getInstance();
     $settings_api->set_sections($sections);
     $settings_api->set_fields($fields);
     $settings_api->admin_init();
 }