Example #1
0
    /** @see WP_Widget::widget */
    function widget($args, $instance)
    {
        extract($args);
        $widget_title = $instance['widget_title'];
        if (isset($instance['auto_play'])) {
            $auto_play = 'true';
        } else {
            $auto_play = 'false';
        }
        $info = crInstGetInfo(user_id(), access_token());
        echo $before_widget;
        echo $before_title . $widget_title . $after_title;
        echo '<div class="instagram-wrap">';
        echo crInstShowInfo($info, array('website' => true, 'media' => true, 'followers' => true, 'following' => true, 'profile_pic' => true), $this->avatar_width);
        echo crInstShowWidgetData(crInstGetSelfFeed(access_token()), $info, $this->display_photos, $this->item_width, "sIntSelfFeed", $instance['display_caption']);
        echo '</div>';
        ?>
		<script type="text/javascript">
			jQuery(document).ready(function($){
				$("a[data-rel^='sIntSelfFeed']").prettyPhoto({
					hook: 'data-rel',
					autoplay_slideshow: <?php 
        echo $auto_play;
        ?>
,
					social_tools: false
				});
			});
		</script>
<?php 
        echo $after_widget;
    }
Example #2
0
function createMenu($data)
{
    $access_token = access_token();
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" . $access_token);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $tmpInfo = curl_exec($ch);
    if (curl_errno($ch)) {
        return curl_error($ch);
    }
    curl_close($ch);
    return $tmpInfo;
}
Example #3
0
 function acquire_poll($url)
 {
     // acquire request token and access token for future requests
     $token_string = request_token();
     $token_string2 = access_token($token_string);
     $tokens = form_tokens($token_string, $token_string2);
     
     // retrieve poll's 16-character id
     $id = extract_id($url);
     
     // access this poll
     $poll = access_poll($id, $tokens);
     
     // format poll data
     $xml_array = parse($poll);
     
     // store tokens for future use in submitting poll
     $xml_array['tokens'] = $tokens;
     
     return $xml_array;
 }
<?php

$access_token = access_token($db);
$url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=' . $access_token;
$query_sql = "SELECT wxid FROM " . $ecs->table('users') . " WHERE user_id = '{$order['user_id']}'";
$ret_w = $db->getRow($query_sql);
$wxid = $ret_w['wxid'];
$query_sql = "SELECT * FROM " . $ecs->table('order_goods') . "  WHERE `order_id` = '{$order['order_id']}'";
$order_goods = $db->getAll($query_sql);
$orders = $db->getRow("SELECT * FROM " . $ecs->table('order_info') . " WHERE `user_id` = '{$order['user_id']}' AND `order_id` = '{$order['order_id']}'");
if (!empty($order_goods)) {
    foreach ($order_goods as $v) {
        if (empty($v['goods_attr'])) {
            $shopinfo .= $v['goods_name'] . '(' . $v['goods_number'] . '),';
        } else {
            $shopinfo .= $v['goods_name'] . '(' . $v['goods_attr'] . ')(' . $v['goods_number'] . '),';
        }
    }
    $shopinfo = substr($shopinfo, 0, strlen($shopinfo) - 1);
}
$wxch_address = "\r\n收件地址:" . $orders['address'];
$wxch_consignee = "\r\n收件人:" . $orders['consignee'];
$sql = "SELECT * FROM wxch_order WHERE id = 1";
$cfg_order = $db->getRow($sql);
$cfg_baseurl = $db->getOne("SELECT cfg_value FROM wxch_cfg WHERE cfg_name = 'baseurl'");
$cfg_murl = $db->getOne("SELECT cfg_value FROM wxch_cfg WHERE cfg_name = 'murl'");
$w_title = $cfg_order['title'];
$w_description = '商品信息:' . $shopinfo . "\r\n总金额:" . $orders['money_paid'] . "\r\n快递公司:" . $order['shipping_name'] . ' 单号:' . $order['invoice_no'] . $wxch_consignee . $wxch_address;
$w_url = $cfg_baseurl . $cfg_murl . 'user.php?act=order_detail&order_id=' . $order['order_id'] . '&wxid=' . $wxid;
if ($orders['pay_status'] == 0) {
    $pay_status = '支付状态:未付款';
         	consumer key: <?php echo htmlspecialchars($tmhOAuth->config['consumer_key']) ?></p>
         
         	<p>User Token: <?php echo htmlspecialchars($oauth_creds['oauth_token']) ?><br />
         	User Secret: <?php echo htmlspecialchars($oauth_creds['oauth_token_secret']) ?></p>
         	<?php*/
     }
     return false;
 }
 $params = uri_params();
 if (!isset($params['oauth_token'])) {
     // Step 1: Request a temporary token and
     // Step 2: Direct the user to the authorize web page
     request_token($tmhOAuth);
 } else {
     // Step 3: This is the code that runs when Twitter redirects the user to the callback. Exchange the temporary token for a permanent access token
     $oauth_creds = access_token($tmhOAuth);
     if ($oauth_creds && isset($oauth_creds['oauth_token']) && !empty($oauth_creds['oauth_token']) && isset($oauth_creds['oauth_token_secret']) && !empty($oauth_creds['oauth_token_secret'])) {
         // yay we're connected to twitter!
         // write these to the database so we can do stuff on the backend.
         $twitter_account->update('twitter_name', $oauth_creds['screen_name']);
         $twitter_account->update('twitter_id', $oauth_creds['user_id']);
         $twitter_account->update('user_key', $oauth_creds['oauth_token']);
         $twitter_account->update('user_secret', $oauth_creds['oauth_token_secret']);
         $twitter_account->update('last_checked', time());
         set_message('Successfully connected to Twitter');
         redirect_browser(module_social_twitter::link_open($social_twitter_id));
     } else {
         echo 'Failed to connect to twitter';
         echo $tmhOAuth->response['response'];
     }
 }
Example #6
0
}
// Step 4: Now the user has authenticated, do something with the permanent token and secret we received
function verify_credentials($tmhOAuth)
{
    $tmhOAuth->config['user_token'] = $_SESSION['access_token']['oauth_token'];
    $tmhOAuth->config['user_secret'] = $_SESSION['access_token']['oauth_token_secret'];
    $code = $tmhOAuth->request('GET', $tmhOAuth->url('1/account/verify_credentials'));
    if ($code == 200) {
        echo $tmhOAuth->response['response'];
    } else {
        outputError($tmhOAuth);
    }
}
/* Auth Flow */
if (isset($_REQUEST['wipe'])) {
    // Logging out
    wipe();
    return;
}
if (isset($_REQUEST['start'])) {
    // Let's start the OAuth dance
    request_token($tmhOAuth);
} elseif (isset($_REQUEST['oauth_verifier'])) {
    access_token($tmhOAuth);
} elseif (isset($_SESSION['access_token'])) {
    // Some credentials already stored in this browser session.
    verify_credentials($tmhOAuth);
} else {
    // User's not logged in.
    echo json_encode(array('loggedin' => false));
}
Example #7
0
function wxdownMediAapi($mediaid, $openid)
{
    if (!empty($mediaid)) {
        $access_token = access_token();
        file_put_contents('aa.txt', $access_token);
        file_put_contents('bb.txt', $mediaid);
        //下载图片
        $url = "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token={$access_token}&media_id={$mediaid}";
        $data = file_get_contents($url);
        if (!empty($data)) {
            $filename = 'user_' . $openid . '.jpg';
            file_put_contents('./uploads/' . $filename, $data);
            return $filename;
        }
    } else {
        return false;
    }
}
function sInstDisplayMediaInfo($media_id)
{
    if (sIntCheckCache("mediainfo.json")) {
        return sIntReadCache("mediainfo.json");
    }
    $apiurl = "https://api.instagram.com/v1/media/" . $media_id . "?access_token=" . access_token();
    if (function_exists('curl_exec') && function_exists('curl_init')) {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $apiurl);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $response = curl_exec($curl);
        curl_close($curl);
        $data = json_decode($response, true);
        file_put_contents(simply_instagram_plugin_path . '/cache-api/mediainfo.json', $response);
    } else {
        $response = wp_remote_get($apiurl, array('timeout' => 20));
        $data = json_decode($response['body'], true);
        file_put_contents(simply_instagram_plugin_path . '/cache-api/mediainfo.json', $response['body']);
    }
    return $data;
    echo $data['data']['1']['filter'];
}
    function option_page_simply_instagram()
    {
        if (isset($_GET['tab'])) {
            $_GET['tab'];
        } else {
            //wp_redirect( 'options-general.php?page=' . $this->plugin_options_key . '&tab=' . $this->si_general_settings . '&noheader=true' );
            //exit;
        }
        /**
         * Save info to database
         * v1.2.5 uses wp options	 
         */
        if (isset($_GET['access_token']) && isset($_GET['id'])) {
            //$wpdb->insert( $wpdb->prefix . "instagram", array( 'access_token' => $_GET['access_token'], 'user_id' => $_GET['id'] ) );
            update_option('si_access_token', $_GET['access_token']);
            update_option('si_user_id', $_GET['id']);
        }
        /*
         * Info query to check if database
         * has record.
         */
        //$info = $wpdb->get_results("select * from " . $wpdb->prefix . "instagram");
        $info = array('si_access_token' => get_option('si_access_token'), 'si_user_id' => get_option('si_user_id'));
        if (isset($_POST['sIntLogout']) == "log_out") {
            /** 
             * v.1.2.6 Delete from wp options
             */
            //$wpdb->query("delete from " . $wpdb->prefix . "instagram");
            delete_option('si_access_token');
            delete_option('si_user_id');
            ?>
 <meta http-equiv="refresh" content="0;url=<?php 
            echo get_admin_url() . 'options-general.php?page=simply-instagram';
            ?>
"> <?php 
        }
        ?>
		<div class="wrap">
		 	<h2><?php 
        echo __('Simply Instagram Settings', 'simply-instagram');
        ?>
</h2>			 	
		 	
		 	<?php 
        if (!$info['si_access_token'] && !$info['si_user_id']) {
            ?>
 
				<?php 
            if ($_GET['access_token'] == "" && $_GET['id'] == "") {
                ?>
					<div class="error">
					 <p><?php 
                echo __('You did not authorize Simply Instagram. This plugin will not work without your authorization.', 'simply-instagram');
                ?>
 </p>
					</div>
				<?php 
            }
            ?>
				<a href=" <?php 
            echo sInstLogin('?return_uri=' . base64_encode(get_admin_url() . 'options-general.php?page=simply-instagram'));
            ?>
 "><img src="<?php 
            echo plugins_url() . '/simply-instagram/images/instagram-login.jpg';
            ?>
" alt="<?php 
            echo __('Login to Instagram and authorize Simply Instagram plugin', 'simply-instagram');
            ?>
" /></a>
			<?php 
        } else {
            ?>
				<?php 
            if (isset($_GET['access_token']) && $_GET['id']) {
                ?>
 <meta http-equiv="refresh" content="0;url=<?php 
                echo get_admin_url() . 'options-general.php?page=simply-instagram';
                ?>
"> <?php 
            }
            ?>
				
				<iframe src="https://instagram.com/accounts/logout/" width="0" height="0">Logout</iframe>
				<?php 
            $user_info = sInstGetInfo(user_id(), access_token());
            //print_r( $user_info );
            ?>
				<div id="sInts-welcome">
				<img src="<?php 
            echo $user_info['data']['profile_picture'];
            ?>
" id="si_profile_photo"/>
				<p id="si_username"><?php 
            echo __('Welcome', 'simply-instagram');
            ?>
 <?php 
            echo $user_info['data']['full_name'];
            ?>
!</p>
				
				
				<form name="itw_logout" method="post" action="<?php 
            echo str_replace('%7E', '~', htmlentities(get_admin_url() . 'options-general.php?page=simply-instagram'));
            ?>
">
				<input type="hidden" name="sIntLogout" value="log_out">
				<input type="submit" class="button" value="Log out" name="logout" onclick="" >
				</form>
				
				</div> 
			
			<?php 
        }
        ?>
	
			
			<?php 
        /**
         *
         * If not yet authorized, hide all tabs
         *
         */
        if (get_option('si_access_token') && get_option('si_user_id')) {
            ?>
			
			<?php 
            $tab = isset($_GET['tab']) ? $_GET['tab'] : $this->general_settings_key;
            ?>
		 	
			<?php 
            $this->plugin_options_tabs();
            ?>
	
						
			<form method="post" action="options.php?noheader=true">
				<?php 
            wp_nonce_field('update-options');
            ?>
				<?php 
            settings_fields($tab);
            ?>
				<?php 
            do_settings_sections($tab);
            ?>
				<?php 
            submit_button();
            ?>
			</form>
			
			<?php 
            if ($tab === $this->about_settings_key) {
                ?>
			
			<h3><?php 
                echo __('API RESPONSE', 'simply-instagram');
                ?>
</h3>
			<p><?php 
                echo __('The following will display API response from Instagram API Server. Please use cache module in order to work.', 'simply-instagram');
                ?>
</p>
			
			<p><strong><?php 
                echo __('Self Feed', 'simply-instagram');
                ?>
</strong>: <?php 
                echo sIntCheckResponse("selffeed.json");
                ?>
</p>
			<p><strong><?php 
                echo __('Recent Media', 'simply-instagram');
                ?>
</strong>: <?php 
                echo sIntCheckResponse("recentmedia.json");
                ?>
</p>
			<p><strong><?php 
                echo __('Likes', 'simply-instagram');
                ?>
</strong>: <?php 
                echo sIntCheckResponse("likes.json");
                ?>
</p>
			<p><strong><?php 
                echo __('Followers', 'simply-instagram');
                ?>
</strong>: <?php 
                echo sIntCheckResponse("followers.json");
                ?>
</p>
			<p><strong><?php 
                echo __('Following', 'simply-instagram');
                ?>
</strong>: <?php 
                echo sIntCheckResponse("following.json");
                ?>
</p>
			<p><strong><?php 
                echo __('Following Info', 'simply-instagram');
                ?>
</strong>: <?php 
                echo sIntCheckResponse("followinginfo.json");
                ?>
</p>
			<p><strong><?php 
                echo __('Currently Popular', 'simply-instagram');
                ?>
</strong>: <?php 
                echo sIntCheckResponse("popular.json");
                ?>
</p>
			<br/>
			
			<h3><?php 
                echo __('RATE THIS PLUGIN', 'simply-instagram');
                ?>
</h3>
			<p><a href="http://wordpress.org/support/view/plugin-reviews/simply-instagram" target="_blank" class="tooltip" title="Rate this plugin in Wordpress.org"> <img src="<?php 
                echo plugins_url();
                ?>
/simply-instagram/images/rate.png" ></a></p><br/>
			
			<h3><strong id="help"><?php 
                echo __('HELP THIS PLUGIN', 'simply-instagram');
                ?>
</strong></h3><p style="text-align: justify !important;"><strong><?php 
                echo __('You can help improve this plugin by donating any amount you want or rate this plugin in Wordpress.org.', 'simply-instagram');
                ?>
</strong></p>
			
			<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
				<input type="hidden" name="cmd" value="_s-xclick">
				<input type="hidden" name="hosted_button_id" value="BUDCX2S6SJ3ZG">
				<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
				<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
		 	</form>
		 
				<script>
				
				//remove save button if in about tab
				jQuery(document).ready( function(){
					jQuery("#submit").css( 'display', 'none' );
				});
				
				</script>
			<?php 
            }
            ?>
			
			<?php 
            if ($tab === $this->shortcode_settings_key) {
                ?>
				<script>
				
				//remove save button if in shortcode tab
				jQuery(document).ready( function(){
					jQuery("#submit").css( 'display', 'none' );
				});
				
				function displayVals() {
				      var endpoints = jQuery("select[name=endpoints]").val();// || [];
				      var type = jQuery("select[name=type]").val();// || [];
				      var size = jQuery("select[name=size]").val();
				      var display = jQuery("select[name=totalphoto]").val();
				      var presentation = jQuery("select[name=presentation]").val();
				      var displayoption = jQuery("select[name=displayoption]").val();
				      var showphotographer = jQuery("select[name=showphotographer]").val();
				      var photocomment = jQuery("select[name=photocomment]").val();
				      var stat = jQuery("select[name=stat]").val();
				      var photocaption = jQuery("select[name=photocaption]").val();
				      var displaycomment = jQuery("select[name=displaycomment]").val();
				      
				      if( endpoints == "media" ){
				        jQuery("p#generated-sc").html(  '[simply_instagram endpoints="' + endpoints + '" type="popular" size="' + size + '" presentation="' + presentation + '" display="' + display + '" displayoption="' + displayoption + '" showphotographer="' + showphotographer + '" photocomment="' + photocomment + '" stat="' + stat + '" photocaption="' + photocaption + '" displaycomment="' + displaycomment + '"]' );
				        jQuery("select[name=type]").attr( "disabled", true );
				      }else{
				      	jQuery("p#generated-sc").html( '[simply_instagram endpoints="' + endpoints + '" type="' + type + '" size="' + size + '" presentation="' + presentation + '" display="' + display + '" displayoption="' + displayoption + '" showphotographer="' + showphotographer + '" photocomment="' + photocomment + '" stat="' + stat + '" photocaption="' + photocaption + '" displaycomment="' + displaycomment + '"]' );
				      	jQuery("select[name=type]").attr( "disabled", false );
				      }
				    }		    
				
				    jQuery("select[name=endpoints]").change(displayVals);
				    jQuery("select[name=type]").change(displayVals);
				    jQuery("select[name=size]").change(displayVals);
				    jQuery("select[name=totalphoto]").change(displayVals);
				    jQuery("select[name=presentation]").change(displayVals);
				    jQuery("select[name=displayoption]").change(displayVals);
				    jQuery("select[name=showphotographer]").change(displayVals);
				    jQuery("select[name=photocomment]").change(displayVals);
				    jQuery("select[name=stat]").change(displayVals);
				    jQuery("select[name=photocaption]").change(displayVals);
				    jQuery("select[name=displaycomment]").change(displayVals);
				    displayVals();
				</script>
			<?php 
            }
            ?>
			
			<?php 
        }
        /* End of hiding tabs when not authorized */
        ?>
		</div>
		<?php 
    }
    /** @see WP_Widget::widget */
    function widget($args, $instance)
    {
        extract($args);
        $widget_title = $instance['widget_title'];
        $short_desc = $instance['short_desc'];
        echo $before_widget;
        echo $before_title . $widget_title . $after_title;
        echo '<p>' . $short_desc . '</p>' . '<div class="clear"></div>';
        echo sInstShowWidgetData(sInstGetRecentMedia(user_id(), access_token()), $instance['max_display'], $instance['size'], "sInstRecentMediaWid", $instance['display_caption'], $instance['open_instagram']);
        ?>
	<script type="text/javascript" charset="utf-8">	  
	  jQuery(document).ready(function(){
	    jQuery("a[rel^='sInstRecentMediaWid']").prettyPhoto({
	    	autoplay_slideshow: <?php 
        echo $instance['auto_play'];
        ?>
,
	    	social_tools:false,
	    	theme: '<?php 
        echo $instance['theme'];
        ?>
',
	    	});
	    jQuery('.si-tooltip').tooltipster();
	  });
	</script>
	<?php 
        echo $after_widget;
    }
Example #11
0
function create_menu($db)
{
    access_token($db);
    $ret = $db->getRow("SELECT `access_token` FROM `wxch_config`");
    $access_token = $ret['access_token'];
    if (strlen($access_token) >= 64) {
        $url = 'https://api.weixin.qq.com/cgi-bin/menu/create?access_token=' . $access_token;
        $data = array();
        $sql = "SELECT * FROM  `wxch_menu` WHERE  `aid` =0";
        $data['first'] = $db->getAll($sql);
        foreach ($data['first'] as $k => $v) {
            if (empty($data['first'][$k]['name'])) {
                unset($data['first'][$k]);
            } else {
                $data['first'][$k]['name'] = urlencode($v['name']);
                if ($v['menu_type'] == 'click') {
                    $data['first'][$k]['array'] = array('type' => $v['menu_type'], 'name' => $data['first'][$k]['name'], 'key' => $v['value']);
                } elseif ($v['menu_type'] == 'view') {
                    $data['first'][$k]['array'] = array('type' => $v['menu_type'], 'name' => $data['first'][$k]['name'], 'url' => $v['value']);
                }
            }
        }
        $sql = "SELECT * FROM  `wxch_menu` WHERE  `aid` =1";
        $data['second1'] = $db->getAll($sql);
        $second1 = 'no';
        foreach ($data['second1'] as $k => $v) {
            if (empty($data['second1'][$k]['name'])) {
                unset($data['second1'][$k]);
            } else {
                $v['value'] = urlencode($v['value']);
                $v['name'] = urlencode($v['name']);
                if ($v['menu_type'] == 'click') {
                    $array1[] = array('type' => $v['menu_type'], 'name' => $v['name'], 'key' => $v['value']);
                } elseif ($v['menu_type'] == 'view') {
                    $array1[] = array('type' => $v['menu_type'], 'name' => $v['name'], 'url' => $v['value']);
                }
                $second1 = 'yes';
            }
        }
        $sql = "SELECT * FROM  `wxch_menu` WHERE  `aid` =2";
        $data['second2'] = $db->getAll($sql);
        $second2 = 'no';
        foreach ($data['second2'] as $k => $v) {
            if (empty($data['second2'][$k]['name'])) {
                unset($data['second2'][$k]);
            } else {
                $v['value'] = urlencode($v['value']);
                $v['name'] = urlencode($v['name']);
                if ($v['menu_type'] == 'click') {
                    $array2[] = array('type' => $v['menu_type'], 'name' => $v['name'], 'key' => $v['value']);
                } elseif ($v['menu_type'] == 'view') {
                    $array2[] = array('type' => $v['menu_type'], 'name' => $v['name'], 'url' => $v['value']);
                }
                $second2 = 'yes';
            }
        }
        $sql = "SELECT * FROM  `wxch_menu` WHERE  `aid` =3";
        $data['second3'] = $db->getAll($sql);
        $second3 = 'no';
        foreach ($data['second3'] as $k => $v) {
            if (empty($data['second3'][$k]['name'])) {
                unset($data['second3'][$k]);
            } else {
                $v['value'] = urlencode($v['value']);
                $v['name'] = urlencode($v['name']);
                if ($v['menu_type'] == 'click') {
                    $array3[] = array('type' => $v['menu_type'], 'name' => $v['name'], 'key' => $v['value']);
                } elseif ($v['menu_type'] == 'view') {
                    $array3[] = array('type' => $v['menu_type'], 'name' => $v['name'], 'url' => $v['value']);
                }
                $second3 = 'yes';
            }
        }
        if ($second1 == 'yes') {
            $sarr1 = array('name' => $data['first'][0]['name'], 'sub_button' => $array1);
        } elseif ($second1 == 'no') {
            $sarr1 = $data['first'][0]['array'];
        }
        if ($second2 == 'yes') {
            $sarr2 = array('name' => $data['first'][1]['name'], 'sub_button' => $array2);
        } elseif ($second2 == 'no') {
            $sarr2 = $data['first'][1]['array'];
        }
        if ($second3 == 'yes') {
            $sarr3 = array('name' => $data['first'][2]['name'], 'sub_button' => $array3);
        } elseif ($second3 == 'no') {
            $sarr3 = $data['first'][2]['array'];
        }
        $arr = array('button' => array($sarr1, $sarr2, $sarr3));
        $menu = urldecode(json_encode($arr));
        $ret_json = curl_grab_page($url, $menu);
        $ret = json_decode($ret_json);
        if (!$ret->errcode == '0') {
            $access_token = new_access_token($db);
            $url = 'https://api.weixin.qq.com/cgi-bin/menu/create?access_token=' . $access_token;
            $ret_json = curl_grab_page($url, $menu);
            $ret = json_decode($ret_json);
        }
        return $ret;
    } else {
        $access_token = new_access_token($db);
        return FALSE;
    }
}
Example #12
0
function option_page_crum_simple_instagram()
{
    if (isset($_POST['sIntClearCache'])) {
        sIntClearCache();
        echo '<div id="message" class="updated fade"><p>Cache folder has been cleanup!</p></div>';
    }
    //check jpeg compression value
    if (isset($_POST['JPEGCompression'])) {
        if ($_POST['JPEGCompression'] > 100 || $_POST['JPEGCompression'] < 10) {
            update_option('JPEGCompression', '80');
        } else {
            update_option('JPEGCompression', $_POST['JPEGCompression']);
        }
    }
    global $wpdb;
    /**
     * Save info to database
     * v1.2.5 uses wp options	 
     */
    if (isset($_GET['access_token']) && isset($_GET['id'])) {
        update_option('si_access_token', $_GET['access_token']);
        update_option('si_user_id', $_GET['id']);
    }
    /*
     * Info query to check if database
     * has record.
     */
    $info = array('si_access_token' => get_option('si_access_token'), 'si_user_id' => get_option('si_user_id'));
    if (isset($_POST['sIntLogout']) == "log_out") {
        delete_option('si_access_token');
        delete_option('si_user_id');
        ?>
 <meta http-equiv="refresh" content="0;url=<?php 
        echo get_admin_url() . 'options-general.php?page=crum-instagram';
        ?>
"> <?php 
    }
    ?>
	<div class="wrap">
	<div id="icon-plugins" class="icon32"></div><h2> Instagram</h2>	
	<?php 
    if (!$info['si_access_token'] && !$info['si_user_id']) {
        ?>
 
		<?php 
        if ($_GET['access_token'] == "" && $_GET['id'] == "") {
            ?>
			<div class="error">
			 <p>You did not authorize  Instagram. This plugin will not work without your authorization. </p>
			</div>
		<?php 
        }
        ?>
	<a href=" <?php 
        echo crInstLogin('?return_uri=' . base64_encode(get_admin_url() . 'options-general.php?page=crum-instagram'));
        ?>
 "><img src="<?php 
        echo plugin_dir_url(__FILE__) . 'images/instagram-login.jpg';
        ?>
" title="Login to Instagram and authorize  Instagram plugin" alt="Login to Instagram and authorize  Instagram plugin" /></a>
	<?php 
        ?>
	<?php 
    } else {
        ?>
	<?php 
        if (isset($_GET['access_token']) && $_GET['id']) {
            ?>
 <meta http-equiv="refresh" content="0;url=<?php 
            echo get_admin_url() . 'options-general.php?page=crum-instagram';
            ?>
"> <?php 
        }
        ?>
	
	<iframe src="https://instagram.com/accounts/logout/" width="0" height="0">Logout</iframe>
	<?php 
        $user = crInstGetInfo(user_id(), access_token());
        ?>
	<div id="sInts-welcome">Welcome <?php 
        echo $user['data']['full_name'];
        ?>
. You can start using Instagram widget. You can find it in Apperance -> Widgets</div>

	<form name="itw_logout" method="post" action="<?php 
        echo str_replace('%7E', '~', htmlentities(get_admin_url() . 'options-general.php?page=crum-instagram'));
        ?>
">
	<input type="hidden" name="sIntLogout" value="log_out">
	<input type="submit" class="button" value="Log out" name="logout" onclick="" >
	</form>

	<!-- END CSS -->
	</div>

    <?php 
    }
    ?>

	<?php 
}
Example #13
0
function ask_for_pin()
{
    echo 'What was the Pin Code?: ';
    $handle = fopen("php://stdin", "r");
    $data = fgets($handle);
    return trim($data);
}
function access_token($tmhOAuth, $pin)
{
    $code = $tmhOAuth->user_request(array('method' => 'POST', 'url' => $tmhOAuth->url('oauth/access_token', ''), 'params' => array('oauth_verifier' => trim($pin))));
    if ($code == 200) {
        $oauth_creds = $tmhOAuth->extract_params($tmhOAuth->response['response']);
        // print tokens
        echo <<<EOM
Congratulations, below is the user token and secret for {$oauth_creds['screen_name']}.
Use these to make authenticated calls to Twitter using the application with
consumer key: {$tmhOAuth->config['consumer_key']}

User Token: {$oauth_creds['oauth_token']}
User Secret: {$oauth_creds['oauth_token_secret']}

EOM;
    } else {
        echo "There was an error communicating with Twitter. {$tmhOAuth->response['response']}" . PHP_EOL;
    }
    die;
}
welcome();
request_token($tmhOAuth);
access_token($tmhOAuth, ask_for_pin());
Example #14
0
<?php

include 'index.php';
if ($last_checkin[1] == 401) {
    get_code();
}
if ($_GET['code']) {
    $token = access_token($_GET['code']);
    $last_checkin = get_checkins($token[0]['access_token']);
    sql_connect($connection, $token[0]['access_token']);
    echo "<p class='text-center'>" . $last_checkin[0]['response']['checkins']['items'][0]['venue']['location']['formattedAddress'][0] . "</p>";
}
Example #15
0
    } else {
        echo "There was an error communicating with Twitter. {$tmhOAuth->response['response']}" . PHP_EOL;
        die;
    }
}
function access_token($tmhOAuth, $pin)
{
    $code = $tmhOAuth->request('POST', $tmhOAuth->url('oauth/access_token', ''), array('oauth_verifier' => trim($pin)));
    if ($code == 200) {
        $oauth_creds = $tmhOAuth->extract_params($tmhOAuth->response['response']);
        // print tokens
        echo <<<EOM
Congratulations, below is the user token and secret for {$oauth_creds['screen_name']}.
Use these to make authenticated calls to Twitter using the application with
consumer key: {$tmhOAuth->config['consumer_key']}

User Token: {$oauth_creds['oauth_token']}
User Secret: {$oauth_creds['oauth_token_secret']}

EOM;
    } else {
        echo "There was an error communicating with Twitter. {$tmhOAuth->response['response']}" . PHP_EOL;
    }
    var_dump($tmhOAuth);
    die;
}
welcome();
request_token($tmhOAuth);
$pin = tmhUtilities::read_input('What was the Pin Code?: ');
access_token($tmhOAuth, $pin);
Example #16
0
    //echo $auth;
    //echo $url;
    return connect($url, null, $auth);
}
function refresh_token($refresh, $auth_header)
{
    $url = "https://api.fitbit.com/oauth2/token";
    $access_token_settings = http_build_query(array('grant_type' => 'refresh_token', 'refresh_token' => $refresh));
    return connect($url, $access_token_settings, $auth_header);
    // POST https://api.fitbit.com/oauth2/token
    // Authorization: Basic Y2xpZW50X2lkOmNsaWVudCBzZWNyZXQ=
    // Content-Type: application/x-www-form-urlencoded
    // grant_type=refresh_token&refresh_token=abcdef01234567890abcdef01234567890abcdef01234567890abcdef0123456
}
if ($_GET['code']) {
    $json_cred = access_token($_GET['code'], $auth_header);
    $usr = profile($json_cred[0]['access_token']);
    $act = activity($json_cred[0]['access_token']);
    $rsh = refresh_token($json_cred[0]['refresh_token'], $auth_header);
    //var_dump($json_cred);
    echo "<h1 style='color:orange;'>";
    //echo $json_cred[0]['access_token'];
    echo (int) (2.20462 * $usr[0]['user']['weight']) . " lb <br />";
    echo $usr[0]['user']['averageDailySteps'] . " Average steps a day.<br />";
    echo "Distance: " . number_format(0.62137 * $act[0]['summary']['distances'][0]['distance'], 2, '.', '') . " Miles";
    echo "</h1>";
    echo "<h2 style='color:green;'>ACS_TKN: " . $rsh[0]['access_token'] . "</h2>";
    echo "<h2 style='color:green;'>RFSH_TKN: " . $rsh[0]['refresh_token'] . "</h2>";
    //echo json_encode($rsh, JSON_PRETTY_PRINT);
    //var_dump($act);
    // - - - - - - - - - - - - -- - - - - - -  S Q L -  - -- - - - - - - - -- - - -