Пример #1
0
        function showGenNTSettings($ntOpts)
        {
            global $nxs_snapSetPgURL, $nxs_plurl, $nxs_gOptions;
            $ntInfo = $this->ntInfo;
            // V2 Auth
            if (isset($_GET['code']) && $_GET['code'] != '' && isset($_GET['state']) && substr($_GET['state'], 0, 7) == 'nxs-li-') {
                $at = $_GET['code'];
                $ii = str_replace('nxs-li-', '', $_GET['state']);
                echo "----=={ oAuth 2.0 Wordflow }==----<br/>-= This is normal technical authorization info that will dissapear (Unless you get some errors) =- <br/><br/><br/>";
                $gGet = $_GET;
                unset($gGet['code']);
                unset($gGet['state']);
                unset($gGet['post_type']);
                $sturl = explode('?', $nxs_snapSetPgURL);
                $nxs_snapSetPgURL = $sturl[0] . (!empty($gGet) ? '?' . http_build_query($gGet) : '');
                $nto = $ntOpts[$ii];
                $wprg = array();
                $wprg['sslverify'] = false;
                if (isset($nto['liAPIKey'])) {
                    echo "-=";
                    prr($nto);
                    // die();
                    $tknURL = 'https://www.linkedin.com/uas/oauth2/accessToken?grant_type=authorization_code&code=' . $at . '&redirect_uri=' . urlencode($nxs_snapSetPgURL) . '&client_id=' . $nto['liAPIKey'] . '&client_secret=' . $nto['liAPISec'];
                    $response = wp_remote_post($tknURL, $wprg);
                    prr($tknURL);
                    if (is_object($response) && isset($response->errors)) {
                        prr($response);
                        die;
                    }
                    if (is_array($response) && stripos($response['body'], '"error":') !== false) {
                        prr($response['body']);
                        prr(json_decode($response['body'], true));
                        die;
                    }
                    $resp = json_decode($response['body'], true);
                    prr($resp);
                    if (!is_array($resp) || empty($resp['access_token'])) {
                        prr($resp);
                        die;
                    }
                    if (function_exists('get_option')) {
                        $currTime = time() + get_option('gmt_offset') * HOUR_IN_SECONDS;
                    } else {
                        $currTime = time();
                    }
                    $nto['liAccessToken'] = $resp['access_token'];
                    $nto['liAccessTokenSecret'] = 'No Need for oAuth V2';
                    $nto['liOAuthVerifier'] = 'No Need for oAuth V2';
                    $nto['liAccessTokenExp'] = $currTime + $resp['expires_in'];
                    echo "<br/>----=={ Expires: " . date('Y-m-d H:i:s', $nto['liAccessTokenExp']) . " }==---- <br/>";
                    $tknURL = 'https://api.linkedin.com/v1/people/~:(id,first-name,last-name)?format=json&oauth2_access_token=' . $nto['liAccessToken'];
                    $response = wp_remote_get($tknURL, $wprg);
                    prr($tknURL);
                    prr($response);
                    $user = json_decode($response['body'], true);
                    if (!empty($user['id'])) {
                        $nto['liUserID'] = $user['id'];
                        $nto['liUserInfo'] = $user['firstName'] . $user['lastName'] . (!empty($user['id']) ? " (" . $user['id'] . ")" : '');
                        $nto['isV2'] = true;
                        if (function_exists('get_option')) {
                            $nxs_gOptions = get_option('NS_SNAutoPoster');
                        }
                        if (!empty($nxs_gOptions)) {
                            $nxs_gOptions['li'][$ii] = $nto;
                            prr($nto);
                            nxs_settings_save($nxs_gOptions);
                        }
                        ?>
<script type="text/javascript">window.location = "<?php 
                        echo $nxs_snapSetPgURL;
                        ?>
"</script>      
        <?php 
                    }
                }
                die;
            }
            // V1 Auth
            if (isset($_GET['auth']) && $_GET['auth'] == 'li') {
                require_once 'apis/liOAuth.php';
                $options = $ntOpts[$_GET['acc']];
                $api_key = $options['liAPIKey'];
                $api_secret = $options['liAPISec'];
                $callback_url = $nxs_snapSetPgURL . "&auth=lia&acc=" . $_GET['acc'];
                $li_oauth = new nsx_LinkedIn($api_key, $api_secret, $callback_url);
                $request_token = $li_oauth->getRequestToken();
                //echo "####"; prr($request_token); die();
                if (!is_object($request_token)) {
                    echo "### LinkedIn Authorization Error:";
                    prr($request_token);
                    if (is_string($request_token) && stripos($request_token, 'timestamp') !== false) {
                        echo "Your Server Time: " . date('m/d/Y h:i:s a');
                        echo " Correct Time: " . date('m/d/Y h:i:s a', nxs_ntp_time('t1.timegps.net'));
                    }
                    die;
                }
                $options['liOAuthToken'] = $request_token->key;
                $options['liOAuthTokenSecret'] = $request_token->secret;
                // prr($li_oauth);
                switch ($li_oauth->http_code) {
                    case 200:
                        $url = $li_oauth->generateAuthorizeUrl();
                        $optionsG = get_option('NS_SNAutoPoster');
                        $optionsG['li'][$_GET['acc']] = $options;
                        update_option('NS_SNAutoPoster', $optionsG);
                        echo '<script type="text/javascript">window.location = "' . $url . '"</script>';
                        break;
                    default:
                        echo '<br/><b style="color:red">Could not connect to LinkedIn. Refresh the page or try again later.</b>';
                        die;
                }
                die;
            }
            if (isset($_GET['auth']) && $_GET['auth'] == 'lia') {
                require_once 'apis/liOAuth.php';
                $options = $ntOpts[$_GET['acc']];
                $api_key = $options['liAPIKey'];
                $api_secret = $options['liAPISec'];
                $li_oauth = new nsx_LinkedIn($api_key, $api_secret);
                $li_oauth->request_token = new nsx_trOAuthConsumer($options['liOAuthToken'], $options['liOAuthTokenSecret'], 1);
                $li_oauth->oauth_verifier = $_REQUEST['oauth_verifier'];
                $li_oauth->getAccessToken($_REQUEST['oauth_verifier']);
                $options['liOAuthVerifier'] = $_REQUEST['oauth_verifier'];
                $options['liAccessToken'] = $li_oauth->access_token->key;
                $options['liAccessTokenSecret'] = $li_oauth->access_token->secret;
                try {
                    $xml_response = $li_oauth->getProfile("~:(id,first-name,last-name)");
                } catch (Exception $o) {
                    prr($o);
                    die("<span style='color:red;'>ERROR: Authorization Error</span>");
                }
                if (stripos($xml_response, '<first-name>') !== false) {
                    $userinfo = CutFromTo($xml_response, '<id>', '</id>') . " - " . CutFromTo($xml_response, '<first-name>', '</first-name>') . " " . CutFromTo($xml_response, '<last-name>', '</last-name>');
                } else {
                    $userinfo = '';
                }
                if ($userinfo != '') {
                    $options['liUserInfo'] = $userinfo;
                    $optionsG = get_option('NS_SNAutoPoster');
                    $optionsG['li'][$_GET['acc']] = $options;
                    update_option('NS_SNAutoPoster', $optionsG);
                    echo '<script type="text/javascript">window.location = "' . $nxs_snapSetPgURL . '"</script>';
                    die;
                }
                prr($xml_response);
                die("<span style='color:red;'>ERROR: Something is Wrong with your LinkedIn account</span>");
            }
            ?>
    
    <div class="nxs_box">
      <div class="nxs_box_header"> 
        <div class="nsx_iconedTitle" style="margin-bottom:1px;background-image:url(<?php 
            echo $nxs_plurl;
            ?>
img/<?php 
            echo $ntInfo['lcode'];
            ?>
16.png);"><?php 
            echo $ntInfo['name'];
            ?>
          <?php 
            $cbo = count($ntOpts);
            ?>
 
          <?php 
            if ($cbo > 1) {
                ?>
<div class="nsBigText"><?php 
                echo "(" . ($cbo == '0' ? 'No' : $cbo) . " ";
                _e('accounts', 'social-networks-auto-poster-facebook-twitter-g');
                echo ")";
                ?>
</div><?php 
            }
            ?>
        </div>
      </div>
      <div class="nxs_box_inside">
        <?php 
            foreach ($ntOpts as $indx => $pbo) {
                if (trim($pbo['nName'] == '')) {
                    $pbo['nName'] = !empty($pbo[$ntInfo['defNName']]) ? $pbo[$ntInfo['defNName']] : 'LinkedIn';
                }
                if (!isset($pbo[$ntInfo['lcode'] . 'OK']) || $pbo[$ntInfo['lcode'] . 'OK'] == '') {
                    $pbo[$ntInfo['lcode'] . 'OK'] = isset($pbo['liAccessToken']) && $pbo['liAccessTokenSecret'] != '' ? '1' : '';
                }
                ?>
          <p style="margin:0px;margin-left:5px;"> <img id="<?php 
                echo $ntInfo['code'] . $indx;
                ?>
LoadingImg" style="display: none;" src='<?php 
                echo $nxs_plurl;
                ?>
img/ajax-loader-sm.gif' />
            <input value="0" name="<?php 
                echo $ntInfo['lcode'];
                ?>
[<?php 
                echo $indx;
                ?>
][apDo<?php 
                echo $ntInfo['code'];
                ?>
]" type="hidden" />             
            <?php 
                if ((int) $pbo['do' . $ntInfo['code']] == 1 && isset($pbo['catSel']) && (int) $pbo['catSel'] == 1) {
                    ?>
 <input type="radio" name="<?php 
                    echo $ntInfo['lcode'];
                    ?>
[<?php 
                    echo $indx;
                    ?>
][apDo<?php 
                    echo $ntInfo['code'];
                    ?>
]" id="rbtn<?php 
                    echo $ntInfo['lcode'] . $indx;
                    ?>
" value="1" checked="checked" onmouseout="nxs_hidePopUpInfo('popOnlyCat');" onmouseover="nxs_showPopUpInfo('popOnlyCat', event);" /> <?php 
                } else {
                    ?>
            
            <input value="1" name="<?php 
                    echo $ntInfo['lcode'];
                    ?>
[<?php 
                    echo $indx;
                    ?>
][apDo<?php 
                    echo $ntInfo['code'];
                    ?>
]" type="checkbox" <?php 
                    if ((int) $pbo['do' . $ntInfo['code']] == 1 && $pbo['catSel'] != '1') {
                        echo "checked";
                    }
                    ?>
 />
           <?php 
                }
                ?>
            <?php 
                if (isset($pbo['catSel']) && (int) $pbo['catSel'] == 1) {
                    ?>
 <span onmouseout="nxs_hidePopUpInfo('popOnlyCat');" onmouseover="nxs_showPopUpInfo('popOnlyCat', event);"><?php 
                    echo "*[" . (substr_count($pbo['catSelEd'], ",") + 1) . "]*";
                    ?>
</span><?php 
                }
                ?>
            <?php 
                if (isset($pbo['rpstOn']) && (int) $pbo['rpstOn'] == 1) {
                    ?>
 <span onmouseout="nxs_hidePopUpInfo('popReActive');" onmouseover="nxs_showPopUpInfo('popReActive', event);"><?php 
                    echo "*[R]*";
                    ?>
</span><?php 
                }
                ?>
            <strong><?php 
                _e('Auto-publish to', 'social-networks-auto-poster-facebook-twitter-g');
                ?>
 <?php 
                echo $ntInfo['name'];
                ?>
 <i style="color: #005800;"><?php 
                if ($pbo['nName'] != '') {
                    echo "(" . $pbo['nName'] . ")";
                }
                ?>
</i></strong>
          &nbsp;&nbsp;<?php 
                if ($ntInfo['tstReq'] && (!isset($pbo[$ntInfo['lcode'] . 'OK']) || $pbo[$ntInfo['lcode'] . 'OK'] == '')) {
                    ?>
<b style="color: #800000"><?php 
                    _e('Attention requred. Unfinished setup', 'social-networks-auto-poster-facebook-twitter-g');
                    ?>
 ==&gt;</b><?php 
                }
                ?>
 <?php 
                if (!empty($pbo['grpID'])) {
                    ?>
<b style="color: #800000"><?php 
                    _e('Attention requred. Groups are no longer supported by LinkedIn Native API', 'social-networks-auto-poster-facebook-twitter-g');
                    ?>
 ==&gt;</b><?php 
                }
                ?>
 <a id="do<?php 
                echo $ntInfo['code'] . $indx;
                ?>
AG" href="#" onclick="doGetHideNTBlock('<?php 
                echo $ntInfo['code'];
                ?>
' , '<?php 
                echo $indx;
                ?>
');return false;">[<?php 
                _e('Show Settings', 'social-networks-auto-poster-facebook-twitter-g');
                ?>
]</a>&nbsp;&nbsp;
          <a href="#" onclick="doDelAcct('<?php 
                echo $ntInfo['lcode'];
                ?>
', '<?php 
                echo $indx;
                ?>
', '<?php 
                if (isset($pbo['bgBlogID'])) {
                    echo $pbo['nName'];
                }
                ?>
');return false;">[<?php 
                _e('Remove Account', 'social-networks-auto-poster-facebook-twitter-g');
                ?>
]</a>
          </p><div id="nxsNTSetDiv<?php 
                echo $ntInfo['code'] . $indx;
                ?>
"></div><?php 
                //$pbo['ntInfo'] = $ntInfo; $this->showNTSettings($indx, $pbo);
            }
            ?>
      </div>
    </div> <?php 
        }
Пример #2
0
        function showGenNTSettings($ntOpts)
        {
            global $nxs_snapThisPageUrl, $nxs_plurl;
            $ntInfo = array('code' => 'LI', 'lcode' => 'li', 'name' => 'LinkedIn', 'defNName' => 'ulName', 'tstReq' => true);
            if (isset($_GET['auth']) && $_GET['auth'] == 'li') {
                require_once 'apis/liOAuth.php';
                $options = $ntOpts[$_GET['acc']];
                $api_key = $options['liAPIKey'];
                $api_secret = $options['liAPISec'];
                $callback_url = $nxs_snapThisPageUrl . "&auth=lia&acc=" . $_GET['acc'];
                $li_oauth = new nsx_LinkedIn($api_key, $api_secret, $callback_url);
                $request_token = $li_oauth->getRequestToken();
                //echo "####"; prr($request_token); die();
                $options['liOAuthToken'] = $request_token->key;
                $options['liOAuthTokenSecret'] = $request_token->secret;
                // prr($li_oauth);
                switch ($li_oauth->http_code) {
                    case 200:
                        $url = $li_oauth->generateAuthorizeUrl();
                        $optionsG = get_option('NS_SNAutoPoster');
                        $optionsG['li'][$_GET['acc']] = $options;
                        update_option('NS_SNAutoPoster', $optionsG);
                        echo '<script type="text/javascript">window.location = "' . $url . '"</script>';
                        break;
                    default:
                        echo '<br/><b style="color:red">Could not connect to LinkedIn. Refresh the page or try again later.</b>';
                        die;
                }
                die;
            }
            if (isset($_GET['auth']) && $_GET['auth'] == 'lia') {
                require_once 'apis/liOAuth.php';
                $options = $ntOpts[$_GET['acc']];
                $api_key = $options['liAPIKey'];
                $api_secret = $options['liAPISec'];
                $li_oauth = new nsx_LinkedIn($api_key, $api_secret);
                $li_oauth->request_token = new nsx_trOAuthConsumer($options['liOAuthToken'], $options['liOAuthTokenSecret'], 1);
                $li_oauth->oauth_verifier = $_REQUEST['oauth_verifier'];
                $li_oauth->getAccessToken($_REQUEST['oauth_verifier']);
                $options['liOAuthVerifier'] = $_REQUEST['oauth_verifier'];
                $options['liAccessToken'] = $li_oauth->access_token->key;
                $options['liAccessTokenSecret'] = $li_oauth->access_token->secret;
                try {
                    $xml_response = $li_oauth->getProfile("~:(id,first-name,last-name)");
                } catch (Exception $o) {
                    prr($o);
                    die("<span style='color:red;'>ERROR: Authorization Error</span>");
                }
                if (stripos($xml_response, '<first-name>') !== false) {
                    $userinfo = CutFromTo($xml_response, '<id>', '</id>') . " - " . CutFromTo($xml_response, '<first-name>', '</first-name>') . " " . CutFromTo($xml_response, '<last-name>', '</last-name>');
                } else {
                    $userinfo = '';
                }
                if ($userinfo != '') {
                    $options['liUserInfo'] = $userinfo;
                    $optionsG = get_option('NS_SNAutoPoster');
                    $optionsG['li'][$_GET['acc']] = $options;
                    update_option('NS_SNAutoPoster', $optionsG);
                    echo '<script type="text/javascript">window.location = "' . $nxs_snapThisPageUrl . '"</script>';
                    die;
                }
                prr($xml_response);
                die("<span style='color:red;'>ERROR: Something is Wrong with your LinkedIn account</span>");
            }
            ?>
    
    <div class="nxs_box">
      <div class="nxs_box_header"> 
        <div class="nsx_iconedTitle" style="margin-bottom:1px;background-image:url(<?php 
            echo $nxs_plurl;
            ?>
img/<?php 
            echo $ntInfo['lcode'];
            ?>
16.png);"><?php 
            echo $ntInfo['name'];
            ?>
          <?php 
            $cbo = count($ntOpts);
            ?>
 <?php 
            wp_nonce_field('ns' . $ntInfo['code'], 'ns' . $ntInfo['code'] . '_wpnonce');
            ?>
          <?php 
            if ($cbo > 1) {
                ?>
<div class="nsBigText"><?php 
                echo "(" . ($cbo == '0' ? 'No' : $cbo) . " ";
                _e('accounts', 'nxs_snap');
                echo ")";
                ?>
</div><?php 
            }
            ?>
        </div>
      </div>
      <div class="nxs_box_inside">
        <?php 
            foreach ($ntOpts as $indx => $pbo) {
                if (trim($pbo['nName'] == '')) {
                    $pbo['nName'] = $pbo[$ntInfo['defNName']];
                }
                if (!isset($pbo[$ntInfo['lcode'] . 'OK']) || $pbo[$ntInfo['lcode'] . 'OK'] == '') {
                    $pbo[$ntInfo['lcode'] . 'OK'] = isset($pbo['liAccessToken']) && $pbo['liAccessTokenSecret'] != '' ? '1' : '';
                }
                ?>
          <p style="margin:0px;margin-left:5px;">
            <input value="1" name="<?php 
                echo $ntInfo['lcode'];
                ?>
[<?php 
                echo $indx;
                ?>
][apDo<?php 
                echo $ntInfo['code'];
                ?>
]" onchange="doShowHideBlocks('<?php 
                echo $ntInfo['code'];
                ?>
');" type="checkbox" <?php 
                if ((int) $pbo['do' . $ntInfo['code']] == 1) {
                    echo "checked";
                }
                ?>
 /> <?php 
                if ((int) $pbo['catSel'] == 1) {
                    ?>
   <span onmouseout="nxs_hidePopUpInfo('popOnlyCat');" onmouseover="nxs_showPopUpInfo('popOnlyCat', event);"><?php 
                    echo "*[" . (substr_count($pbo['catSelEd'], ",") + 1) . "]*";
                    ?>
</span><?php 
                }
                ?>
            <strong><?php 
                _e('Auto-publish to', 'nxs_snap');
                ?>
 <?php 
                echo $ntInfo['name'];
                ?>
 <i style="color: #005800;"><?php 
                if ($pbo['nName'] != '') {
                    echo "(" . $pbo['nName'] . ")";
                }
                ?>
</i></strong>
          &nbsp;&nbsp;<?php 
                if ($ntInfo['tstReq'] && (!isset($pbo[$ntInfo['lcode'] . 'OK']) || $pbo[$ntInfo['lcode'] . 'OK'] == '')) {
                    ?>
<b style="color: #800000"><?php 
                    _e('Attention requred. Unfinished setup', 'nxs_snap');
                    ?>
 ==&gt;</b><?php 
                }
                ?>
<a id="do<?php 
                echo $ntInfo['code'] . $indx;
                ?>
A" href="#" onclick="doShowHideBlocks2('<?php 
                echo $ntInfo['code'] . $indx;
                ?>
');return false;">[<?php 
                _e('Show Settings', 'nxs_snap');
                ?>
]</a>&nbsp;&nbsp;
          <a href="#" onclick="doDelAcct('<?php 
                echo $ntInfo['lcode'];
                ?>
', '<?php 
                echo $indx;
                ?>
', '<?php 
                if (isset($pbo['bgBlogID'])) {
                    echo $pbo['nName'];
                }
                ?>
');return false;">[<?php 
                _e('Remove Account', 'nxs_snap');
                ?>
]</a>
          </p><?php 
                $this->showNTSettings($indx, $pbo);
            }
            ?>
      </div>
    </div> <?php 
        }