function nxs_save_ntwrksOpts($networks)
 {
     if (function_exists('nxs_settings_save')) {
         nxs_settings_save($networks);
     }
     if (function_exists('get_option')) {
         if (!empty($networks)) {
             update_option('NS_SNAutoPoster', $networks);
         }
     }
 }
        function showGenNTSettings($ntOpts)
        {
            global $nxs_plurl, $nxs_snapSetPgURL, $nxs_gOptions;
            $ntInfo = $this->ntInfo;
            if (isset($_GET['auth']) && $_GET['auth'] == $ntInfo['lcode']) {
                require_once 'apis/scOAuth.php';
                $options = $ntOpts[$_GET['acc']];
                $consumer_key = $options['appKey'];
                $consumer_secret = $options['appSec'];
                $callback_url = $nxs_snapSetPgURL . "&auth=" . $ntInfo['lcode'] . "a&acc=" . $_GET['acc'];
                $tum_oauth = new wpScoopITOAuth($consumer_key, $consumer_secret);
                $tum_oauth->baseURL = 'https://www.flickr.com/services';
                $tum_oauth->request_token_path = '/oauth/request_token';
                $tum_oauth->access_token_path = '/oauth/access_token';
                $request_token = $tum_oauth->getReqToken($callback_url);
                $options['oAuthToken'] = $request_token['oauth_token'];
                $options['oAuthTokenSecret'] = $request_token['oauth_token_secret'];
                switch ($tum_oauth->http_code) {
                    case 200:
                        $url = 'https://www.flickr.com/services/oauth/authorize?oauth_token=' . $options['oAuthToken'];
                        if (function_exists('get_option')) {
                            $nxs_gOptions = get_option('NS_SNAutoPoster');
                        }
                        if (!empty($nxs_gOptions)) {
                            $nxs_gOptions[$ntInfo['lcode']][$_GET['acc']] = $options;
                            nxs_settings_save($nxs_gOptions);
                        }
                        echo '<br/><br/>All good?! Redirecting ..... <script type="text/javascript">window.location = "' . $url . '"</script>';
                        break;
                    default:
                        echo '<br/><b style="color:red">Could not connect to Flickr. Refresh the page or try again later.</b>';
                        die;
                }
                die;
            }
            if (isset($_GET['auth']) && $_GET['auth'] == $ntInfo['lcode'] . 'a') {
                require_once 'apis/scOAuth.php';
                $options = $ntOpts[$_GET['acc']];
                $consumer_key = $options['appKey'];
                $consumer_secret = $options['appSec'];
                $tum_oauth = new wpScoopITOAuth($consumer_key, $consumer_secret, $options['oAuthToken'], $options['oAuthTokenSecret']);
                //prr($tum_oauth);
                $tum_oauth->baseURL = 'https://www.flickr.com/services';
                $tum_oauth->request_token_path = '/oauth/request_token';
                $tum_oauth->access_token_path = '/oauth/access_token';
                $access_token = $tum_oauth->getAccToken($_GET['oauth_verifier']);
                prr($access_token);
                $options['accessToken'] = $access_token['oauth_token'];
                $options['accessTokenSec'] = $access_token['oauth_token_secret'];
                if (function_exists('get_option')) {
                    $nxs_gOptions = get_option('NS_SNAutoPoster');
                }
                if (!empty($nxs_gOptions)) {
                    $nxs_gOptions[$ntInfo['lcode']][$_GET['acc']] = $options;
                    nxs_settings_save($nxs_gOptions);
                }
                $tum_oauth = new wpScoopITOAuth($consumer_key, $consumer_secret, $options['accessToken'], $options['accessTokenSec']);
                echo "OK. Let's Get Profile: ";
                prr($access_token);
                $params = array('format' => 'php_serial', 'method' => 'flickr.urls.getUserProfile');
                $uinfo = $tum_oauth->makeReq('https://api.flickr.com/services/rest/', $params);
                // prr($uinfo);die();
                if (is_array($uinfo) && isset($uinfo['user'])) {
                    $options['appAppUserName'] = $access_token['username'] . "(" . urldecode($access_token['fullname']) . ")";
                    $options['appAppUserID'] = urldecode($uinfo['user']['nsid']);
                    $options['userURL'] = urldecode($uinfo['user']['url']);
                    if (function_exists('get_option')) {
                        $nxs_gOptions = get_option('NS_SNAutoPoster');
                    }
                    if (!empty($nxs_gOptions)) {
                        $nxs_gOptions[$ntInfo['lcode']][$_GET['acc']] = $options;
                        nxs_settings_save($nxs_gOptions);
                    }
                }
                //die();
                if (!empty($options['appAppUserID'])) {
                    $gGet = $_GET;
                    unset($gGet['auth']);
                    unset($gGet['acc']);
                    unset($gGet['oauth_token']);
                    unset($gGet['oauth_verifier']);
                    unset($gGet['post_type']);
                    $sturl = explode('?', $nxs_snapSetPgURL);
                    $nxs_snapSetPgURL = $sturl[0] . (!empty($gGet) ? '?' . http_build_query($gGet) : '');
                    echo '<br/><br/>All good?! Redirecting ..... <script type="text/javascript">window.location = "' . $nxs_snapSetPgURL . '"</script>';
                    break;
                    die;
                } else {
                    die("<span style='color:red;'>ERROR: Authorization Error: <span style='color:darkred; font-weight: bold;'>" . print_r($uinfo, true) . "</span></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', 'nxs_snap');
                echo ")";
                ?>
</div><?php 
            }
            ?>
        </div>
      </div>
      <div class="nxs_box_inside">
        <?php 
            foreach ($ntOpts as $indx => $pbo) {
                if (trim($pbo['nName'] == '')) {
                    $pbo['nName'] = $ntInfo['name'];
                }
                if (!isset($pbo[$ntInfo['lcode'] . 'OK']) || $pbo[$ntInfo['lcode'] . 'OK'] == '') {
                    $pbo[$ntInfo['lcode'] . 'OK'] = isset($pbo['appAppUserID']) && $pbo['appAppUserID'] > 1 ? '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' />

            <?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="0" name="<?php 
                    echo $ntInfo['lcode'];
                    ?>
[<?php 
                    echo $indx;
                    ?>
][apDo<?php 
                    echo $ntInfo['code'];
                    ?>
]" type="hidden" />
            <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', '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;
                ?>
AG" href="#" onclick="doGetHideNTBlock('<?php 
                echo $ntInfo['code'];
                ?>
' , '<?php 
                echo $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><div id="nxsNTSetDiv<?php 
                echo $ntInfo['code'] . $indx;
                ?>
"></div><?php 
                //$pbo['ntInfo'] = $ntInfo; $this->showNTSettings($indx, $pbo);
            }
            ?>
      </div>
    </div> <?php 
        }
Esempio n. 3
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 
        }
Esempio n. 4
0
 function nxs_doPublishToDA($postID, $options)
 {
     $ntCd = 'DA';
     $ntCdL = 'da';
     $ntNm = 'deviantART';
     if (!is_array($options)) {
         $options = maybe_unserialize(get_post_meta($postID, $options, true));
     }
     $addParams = nxs_makeURLParams(array('NTNAME' => $ntNm, 'NTCODE' => $ntCd, 'POSTID' => $postID, 'ACCNAME' => $options['nName']));
     $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES);
     if ($blogTitle == '') {
         $blogTitle = home_url();
     }
     $ii = $options['ii'];
     if (!isset($options['pType'])) {
         $options['pType'] = 'im';
     }
     if ($options['pType'] == 'sh') {
         sleep(rand(1, 10));
     }
     $logNT = '<span style="color:#800000">deviantART</span> - ' . $options['nName'];
     $snap_ap = get_post_meta($postID, 'snap' . $ntCd, true);
     $snap_ap = maybe_unserialize($snap_ap);
     if ($options['pType'] != 'aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) {
         $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true);
         if ($snap_isAutoPosted != '2') {
             nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:' . $postID, 'Already posted. No reason for posting duplicate' . ' |' . $uqID);
             return;
         }
     }
     $message = array('message' => '', 'link' => '', 'imageURL' => '', 'videoURL' => '');
     if ($postID == '0') {
         echo "Testing ... <br/><br/>";
         $message['description'] = 'Test Post, Description';
         $message['title'] = 'Test Post - Title';
         $message['url'] = home_url();
     } else {
         nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1'));
         $post = get_post($postID);
         if (!$post) {
             return;
         }
         $options['daTitleFormat'] = nsFormatMessage($options['daTitleFormat'], $postID, $addParams);
         $options['daTextFormat'] = nsFormatMessage($options['daTextFormat'], $postID, $addParams);
         // prr($options['daTextFormat']); echo $postID;
         $extInfo = ' | PostID: ' . $postID . " - " . (isset($post) && is_object($post) ? $post->post_title : '');
     }
     //## Actual Post
     $ntToPost = new nxs_class_SNAP_DA();
     $ret = $ntToPost->doPostToNT($options, $message);
     // echo "~~~"; prr($ret); echo "+++";
     //## Save Session
     if (empty($options['ck'])) {
         $options['ck'] = '';
     }
     if (!empty($ret) && is_array($ret) && !empty($ret['ck']) && !empty($ret['ck']) && serialize($ret['ck']) != $options['ck']) {
         $options['ck'] = serialize($ret['ck']);
         $options['mh'] = serialize($ret['mh']);
         if (function_exists('get_option')) {
             $nxs_gOptions = get_option('NS_SNAutoPoster');
         }
         if (!empty($nxs_gOptions)) {
             $nxs_gOptions['da'][$ii] = $options;
             nxs_settings_save($nxs_gOptions);
         }
     }
     //## Process Results
     if (!is_array($ret) || $ret['isPosted'] != '1') {
         //## Error
         if ($postID == '0') {
             prr($ret);
         }
         nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true), $extInfo);
     } else {
         // ## All Good - log it.
         if ($postID == '0') {
             nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted ');
             echo _e('OK - Message Posted, please see your ' . $logNT . ' Page. ', 'social-networks-auto-poster-facebook-twitter-g');
         } else {
             nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPosted' => '1', 'pgID' => $ret['postID'], 'postURL' => $ret['postURL'], 'pDate' => date('Y-m-d H:i:s')));
             nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo);
         }
     }
     //## Return Result
     if ($ret['isPosted'] == '1') {
         return 200;
     } else {
         return print_r($ret, true);
     }
 }
Esempio n. 5
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-bg-') {
                $at = $_GET['code'];
                $ii = str_replace('nxs-bg-', '', $_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['APIKey'])) {
                    echo "-=";
                    prr($nto);
                    // die();
                    $tknURL = 'https://www.googleapis.com/oauth2/v3/token?code=' . $at . '&redirect_uri=' . urlencode($nxs_snapSetPgURL) . '&scope=&client_id=' . $nto['APIKey'] . '&client_secret=' . $nto['APISec'] . '&grant_type=authorization_code';
                    $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['AccessToken'] = $resp['access_token'];
                    $nto['AccessTokenSecret'] = 'No Need for oAuth V2';
                    $nto['OAuthVerifier'] = 'No Need for oAuth V2';
                    $nto['AccessTokenExp'] = $currTime + $resp['expires_in'];
                    $nto['RefreshToken'] = $resp['refresh_token'];
                    echo "<br/>----=={ Expires: " . date('Y-m-d H:i:s', $nto['AccessTokenExp']) . " }==---- <br/>";
                    if (!empty($nto['bgBlogID'])) {
                        if (substr($nto['bgBlogID'], 0, 4) == 'http') {
                            $tknURL = 'https://www.googleapis.com/blogger/v3/blogs/byurl/?url=' . $nto['bgBlogID'] . '?access_token=' . $nto['AccessToken'];
                        } else {
                            $tknURL = 'https://www.googleapis.com/blogger/v3/blogs/' . $nto['bgBlogID'] . '?access_token=' . $nto['AccessToken'];
                        }
                    }
                    $response = wp_remote_get($tknURL, $wprg);
                    prr($tknURL);
                    prr($response);
                    $user = json_decode($response['body'], true);
                    prr($user);
                    if (!empty($user['url'])) {
                        $nto['blogURL'] = $user['url'];
                        $nto['bgBlogID'] = $user['id'];
                        $nto['blogInfo'] = $user['name'] . " [" . $user['id'] . "] (" . $user['url'] . ")";
                        if (function_exists('get_option')) {
                            $nxs_gOptions = get_option('NS_SNAutoPoster');
                        }
                        if (!empty($nxs_gOptions)) {
                            $nxs_gOptions['bg'][$ii] = $nto;
                            prr($nto);
                            nxs_settings_save($nxs_gOptions);
                        }
                        ?>
<script type="text/javascript">window.location = "<?php 
                        echo $nxs_snapSetPgURL;
                        ?>
"</script>      
        <?php 
                    }
                }
                die;
            }
            ?>
    
    <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']] : 'Blogger';
                }
                if (!isset($pbo[$ntInfo['lcode'] . 'OK']) || $pbo[$ntInfo['lcode'] . 'OK'] == '') {
                    $pbo[$ntInfo['lcode'] . 'OK'] = isset($pbo['AccessToken']) && $pbo['AccessTokenSecret'] != '' ? '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 (!class_exists('nxsAPI_GP') && !empty($pbo['bgUName']) && empty($pbo['APIKey'])) {
                    ?>
<b style="color: #800000"><?php 
                    _e('Attention requred. "ClientLogin" authentication method is no longer supported by Blogger', '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 
        }
Esempio n. 6
0
        function showGenNTSettings($ntOpts)
        {
            global $nxs_snapSetPgURL, $nxs_plurl, $nxs_gOptions;
            $ntInfo = $this->ntInfo;
            if (isset($_GET['auth']) && $_GET['auth'] == 'tr') {
                require_once 'apis/trOAuth.php';
                $options = $ntOpts[$_GET['acc']];
                $consumer_key = $options['trConsKey'];
                $consumer_secret = $options['trConsSec'];
                $callback_url = $nxs_snapSetPgURL . "&auth=tra&acc=" . $_GET['acc'];
                $tum_oauth = new TumblrOAuth($consumer_key, $consumer_secret);
                prr($tum_oauth);
                $request_token = $tum_oauth->getRequestToken($callback_url);
                echo "####";
                prr($request_token);
                $options['trOAuthToken'] = $request_token['oauth_token'];
                $options['trOAuthTokenSecret'] = $request_token['oauth_token_secret'];
                // prr($tum_oauth ); die();
                switch ($tum_oauth->http_code) {
                    case 200:
                        $url = $tum_oauth->getAuthorizeURL($options['trOAuthToken']);
                        if (function_exists('get_option')) {
                            $nxs_gOptions = get_option('NS_SNAutoPoster');
                        }
                        if (!empty($nxs_gOptions)) {
                            $nxs_gOptions['tr'][$_GET['acc']] = $options;
                            nxs_settings_save($nxs_gOptions);
                        }
                        echo '<script type="text/javascript">window.location = "' . $url . '"</script>';
                        break;
                    default:
                        echo '<br/><b style="color:red">Could not connect to Tumblr. Refresh the page or try again later.</b>';
                        die;
                }
                die;
            }
            if (isset($_GET['auth']) && $_GET['auth'] == 'tra') {
                require_once 'apis/trOAuth.php';
                $options = $ntOpts[$_GET['acc']];
                prr($options);
                $consumer_key = $options['trConsKey'];
                $consumer_secret = $options['trConsSec'];
                $tum_oauth = new TumblrOAuth($consumer_key, $consumer_secret, $options['trOAuthToken'], $options['trOAuthTokenSecret']);
                $options['trAccessTocken'] = $tum_oauth->getAccessToken($_REQUEST['oauth_verifier']);
                // prr($_GET);  prr($_REQUEST);   prr($options['trAccessTocken']);
                $tum_oauth = new TumblrOAuth($consumer_key, $consumer_secret, $options['trAccessTocken']['oauth_token'], $options['trAccessTocken']['oauth_token_secret']);
                if (function_exists('get_option')) {
                    $nxs_gOptions = get_option('NS_SNAutoPoster');
                }
                if (!empty($nxs_gOptions)) {
                    $nxs_gOptions['tr'][$_GET['acc']] = $options;
                    nxs_settings_save($nxs_gOptions);
                }
                $userinfo = $tum_oauth->get('http://api.tumblr.com/v2/user/info');
                prr($userinfo);
                prr($tum_oauth);
                // prr($url); die();
                if (is_array($userinfo->response->user->blogs)) {
                    foreach ($userinfo->response->user->blogs as $blog) {
                        if (stripos($blog->url, $options['trPgID']) !== false) {
                            $gGet = $_GET;
                            unset($gGet['auth']);
                            unset($gGet['acc']);
                            unset($gGet['oauth_token']);
                            unset($gGet['oauth_verifier']);
                            unset($gGet['post_type']);
                            $sturl = explode('?', $nxs_snapSetPgURL);
                            $nxs_snapSetPgURL = $sturl[0] . (!empty($gGet) ? '?' . http_build_query($gGet) : '');
                            echo '<script type="text/javascript">window.location = "' . $nxs_snapSetPgURL . '"</script>';
                            die;
                        }
                    }
                    prr($userinfo);
                    die("<span style='color:red;'>ERROR: Authorized USER don't have access to the specified blog: <span style='color:darkred; font-weight: bold;'>" . $options['trPgID'] . "</span></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', 'nxs_snap');
                echo ")";
                ?>
</div><?php 
            }
            ?>
        </div>
      </div>
      <div class="nxs_box_inside">
        <?php 
            foreach ($ntOpts as $indx => $pbo) {
                if (trim($pbo['nName'] == '')) {
                    $pbo['nName'] = str_ireplace('https://', '', str_ireplace('http://', '', $pbo['trURL']));
                }
                if (!isset($pbo[$ntInfo['lcode'] . 'OK']) || $pbo[$ntInfo['lcode'] . 'OK'] == '') {
                    $pbo[$ntInfo['lcode'] . 'OK'] = isset($pbo['trOAuthTokenSecret']) && $pbo['trOAuthTokenSecret'] != '' ? '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', '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;
                ?>
AG" href="#" onclick="doGetHideNTBlock('<?php 
                echo $ntInfo['code'];
                ?>
' , '<?php 
                echo $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><div id="nxsNTSetDiv<?php 
                echo $ntInfo['code'] . $indx;
                ?>
"></div><?php 
                //$pbo['ntInfo'] = $ntInfo; $this->showNTSettings($indx, $pbo);
            }
            ?>
      </div>
    </div> <?php 
        }
Esempio n. 7
0
        function showGenNTSettings($ntOpts)
        {
            global $nxs_snapSetPgURL, $nxs_plurl;
            $ntInfo = array('code' => 'FB', 'lcode' => 'fb', 'name' => 'Facebook', 'defNName' => 'dlUName', 'tstReq' => true);
            if (isset($_GET['code']) && $_GET['code'] != '' && isset($_GET['state']) && substr($_GET['state'], 0, 7) == 'nxs-fb-') {
                $at = $_GET['code'];
                $ii = str_replace('nxs-fb-', '', $_GET['state']);
                echo "-= This is normal technical authorization info that will dissapear (Unless you get some errors) =- <br/><br/><br/>";
                $gGet = array();
                if (!empty($_SERVER['QUERY_STRING'])) {
                    parse_str($_SERVER['QUERY_STRING'], $gGet);
                } elseif (!empty($_SERVER['argv'][0])) {
                    parse_str($_SERVER['argv'][0], $gGet);
                } else {
                    $gGet = $_GET;
                    prr($_GET);
                    unset($gGet['post_type']);
                }
                prr($gGet);
                unset($gGet['code']);
                unset($gGet['state']);
                prr($gGet);
                $sturl = explode('?', $nxs_snapSetPgURL);
                $nxs_snapSetPgURL = $sturl[0] . (!empty($gGet) ? '?' . http_build_query($gGet) : '');
                $fbo = $ntOpts[$ii];
                $wprg = array();
                $response = wp_remote_get('https://graph.facebook.com/nextscripts', $wprg);
                if (is_wp_error($response) && isset($response->errors['http_request_failed']) && stripos($response->errors['http_request_failed'][0], 'SSL') !== false) {
                    prr($response->errors);
                    $wprg['sslverify'] = false;
                }
                if (isset($fbo['fbPgID'])) {
                    echo "-=";
                    prr($fbo);
                    // die();
                    $tknURL = 'https://graph.facebook.com/oauth/access_token?client_id=' . $fbo['fbAppID'] . '&state=nxs-fb-' . $ii . '&redirect_uri=' . urlencode($nxs_snapSetPgURL) . '&client_secret=' . $fbo['fbAppSec'] . '&code=' . $at;
                    $response = wp_remote_get($tknURL, $wprg);
                    prr($tknURL);
                    if (is_object($response) && isset($response->errors) || is_array($response) && stripos($response['body'], '"error":') !== false) {
                        prr($response);
                        die;
                    }
                    parse_str($response['body'], $params);
                    $at = $params['access_token'];
                    prr($response);
                    prr($params);
                    $response = wp_remote_get('https://graph.facebook.com/oauth/access_token?client_secret=' . $fbo['fbAppSec'] . '&client_id=' . $fbo['fbAppID'] . '&grant_type=fb_exchange_token&fb_exchange_token=' . $at, $wprg);
                    if (is_object($response) && isset($response->errors)) {
                        prr($response);
                        die;
                    }
                    parse_str($response['body'], $params);
                    $at = $params['access_token'];
                    $fbo['fbAppAuthToken'] = $at;
                    $appsecret_proof = hash_hmac('sha256', $fbo['fbAppAuthToken'], $fbo['fbAppSec']);
                    $aacct = array('access_token' => $fbo['fbAppAuthToken'], 'appsecret_proof' => $appsecret_proof, 'method' => 'get');
                    $res = wp_remote_get("https://graph.facebook.com/me?" . http_build_query($aacct, null, '&'));
                    if (is_wp_error($res) || empty($res['body'])) {
                        echo "Can't get Facebook User.";
                        prr($res);
                        die;
                    } else {
                        $user = json_decode($res['body'], true);
                        if (empty($user)) {
                            echo "Can't get Facebook User. JSON Error. ";
                            prr($res);
                            die;
                        } else {
                            if (!empty($user['id'])) {
                                echo "-= Got user: "******"-= Authorizing Page =-";
                                if (!is_numeric($page_id) && stripos($fbo['fbURL'], '/groups/') != false) {
                                    //$fbPgIDR = wp_remote_get('nxs.php?g='.$fbo['fbURL']); // TODO - how to replace
                                    $fbPgIDR = trim($fbPgIDR['body']);
                                    $page_id = $fbPgIDR != '' ? $fbPgIDR : $page_id;
                                }
                                $aacct = array('access_token' => $fbo['fbAppAuthToken'], 'appsecret_proof' => $appsecret_proof, 'method' => 'get');
                                $fbo['destType'] = '';
                                echo "https://graph.facebook.com/{$page_id}?fields=access_token&" . http_build_query($aacct, null, '&');
                                $res = wp_remote_get("https://graph.facebook.com/{$page_id}?fields=access_token&" . http_build_query($aacct, null, '&'));
                                prr($res);
                                if (is_wp_error($res) || empty($res['body'])) {
                                    echo "Can't get Page Token.";
                                    prr($res);
                                    die;
                                } else {
                                    $token = json_decode($res['body'], true);
                                    if (empty($token)) {
                                        echo "Can't get Page Token. JSON Error. ";
                                        prr($res);
                                        die;
                                    } else {
                                        if (!empty($token['error'])) {
                                            if (!empty($token['error']['message'])) {
                                                $errMsg = $token['error']['message'];
                                                if (stripos($errMsg, 'Unknown fields: access_token') !== false || stripos($errMsg, 'Cannot query users by their username') !== false || stripos($errMsg, 'node type (User)') !== false) {
                                                    $token['access_token'] = $fbo['fbAppAuthToken'];
                                                    $fbo['destType'] = stripos($fbo['fbURL'], '/groups/') != false ? 'gr' : 'pr';
                                                } else {
                                                    if (stripos($errMsg, 'Unsupported get request') !== false) {
                                                        echo "<b style='color:red;'>Error </b>: Your Facebook URL ( <i>" . $fbo['fbURL'] . "</i> ) is either incorrect or authorzing user don't have rights to post there.<br/>";
                                                    }
                                                    echo '<br/>Reported Error: ', $errMsg, "\n";
                                                    die;
                                                }
                                            }
                                        }
                                        if (!empty($token['access_token'])) {
                                            $fbo['fbAppPageAuthToken'] = $token['access_token'];
                                        } else {
                                            echo "Can't get Page Token. NO TOKEN RETURNED. Are you sure that user you are trying to authorize is an admin of the page? This message means user was authorized as profile, but page refused to return authorization token. This usually happens when user has <b>no rights</b> to post to that page. ";
                                            prr($res);
                                            die;
                                        }
                                    }
                                }
                            } else {
                                echo "Can't get User. NO USER RETURNED. ";
                                prr($res);
                                die;
                            }
                        }
                    }
                    if (!empty($user['id'])) {
                        $fbo['fbAppAuthUser'] = $user['id'];
                        $fbo['fbAppAuthUserName'] = $user['name'] . (!empty($user['username']) ? " (" . $user['username'] . ")" : '');
                        if (function_exists('get_option')) {
                            $nxs_gOptions = get_option('NS_SNAutoPoster');
                        }
                        if (!empty($nxs_gOptions)) {
                            $nxs_gOptions['fb'][$ii] = $fbo;
                            nxs_settings_save($nxs_gOptions);
                        }
                        ?>
<script type="text/javascript">window.location = "<?php 
                        echo $nxs_snapSetPgURL;
                        ?>
"</script>      
      <?php 
                    }
                    die;
                }
            }
            $ntParams = array('ntInfo' => $ntInfo, 'nxs_plurl' => $nxs_plurl, 'ntOpts' => $ntOpts, 'chkField' => 'fbAppAuthUser');
            nxs_showListRow($ntParams);
        }
Esempio n. 8
0
        function showGenNTSettings($ntOpts)
        {
            global $nxs_plurl, $nxs_snapSetPgURL, $nxs_gOptions;
            $ntInfo = $this->ntInfo;
            if (isset($_GET['code']) && $_GET['code'] != '' && (isset($_GET['state']) && stripos($_GET['state'], 'ap-') !== false)) {
                $at = $_GET['code'];
                $to = explode('-', $_GET['state']);
                $_GET['acc'] = $to[1];
                echo "-= This is normal technical authorization info that will dissapear (Unless you get some errors) =- <br/><br/><br/>";
                $fbo = $ntOpts[$_GET['acc']];
                $wprg = array();
                $response = wp_remote_get('https://graph.facebook.com/nextscripts', $wprg);
                echo $nxs_snapSetPgURL . '&auth=ap&acc=' . $_GET['acc'] . "||";
                if (stripos($nxs_snapSetPgURL, 'page=NextScripts_SNAP.php') === false) {
                    $newURL = explode('?', $nxs_snapSetPgURL);
                    $nxs_snapSetPgURL = $newURL[0];
                }
                if (is_wp_error($response) && isset($response->errors['http_request_failed']) && stripos($response->errors['http_request_failed'][0], 'SSL') !== false) {
                    prr($response->errors);
                    $wprg['sslverify'] = false;
                }
                if (isset($fbo['appID'])) {
                    echo "-=";
                    prr($fbo);
                    $wprg['body'] = array('client_id' => $fbo['appID'], 'client_secret' => $fbo['appSec'], 'grant_type' => 'authorization_code', 'redirect_uri' => $nxs_snapSetPgURL, 'state' => 'ap-' . $_GET['acc'], 'code' => $at);
                    prr($wprg);
                    $response = wp_remote_post('https://account.app.net/oauth/access_token', $wprg);
                    if (is_object($response) && isset($response->errors) || is_array($response) && stripos($response['body'], '"error":') !== false) {
                        prr($response);
                        die;
                    }
                    $params = json_decode($response['body'], true);
                    $fbo['apAppAuthToken'] = $params['access_token'];
                    if ($params['user_id'] > 0) {
                        $fbo['appAppUserID'] = $params['user_id'];
                        $fbo['appAppUserName'] = $params['username'];
                    }
                    if ($params['user_id'] > 0) {
                        if (function_exists('get_option')) {
                            $nxs_gOptions = get_option('NS_SNAutoPoster');
                        }
                        if (!empty($nxs_gOptions)) {
                            $nxs_gOptions['ap'][$_GET['acc']] = $fbo;
                            nxs_settings_save($nxs_gOptions);
                        }
                        ?>
<script type="text/javascript">window.location = "<?php 
                        echo $nxs_snapSetPgURL;
                        ?>
"</script>      
       <?php 
                    }
                    die;
                }
            }
            ?>
    
    <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', 'nxs_snap');
                echo ")";
                ?>
</div><?php 
            }
            ?>
        </div>
      </div>
      <div class="nxs_box_inside">
        <?php 
            foreach ($ntOpts as $indx => $pbo) {
                if (trim($pbo['nName'] == '')) {
                    $pbo['nName'] = 'App.Net';
                }
                if (!isset($pbo[$ntInfo['lcode'] . 'OK']) || $pbo[$ntInfo['lcode'] . 'OK'] == '') {
                    $pbo[$ntInfo['lcode'] . 'OK'] = isset($pbo['appAppUserID']) && $pbo['appAppUserID'] > 1 ? '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', '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;
                ?>
AG" href="#" onclick="doGetHideNTBlock('<?php 
                echo $ntInfo['code'];
                ?>
' , '<?php 
                echo $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><div id="nxsNTSetDiv<?php 
                echo $ntInfo['code'] . $indx;
                ?>
"></div><?php 
                //$pbo['ntInfo'] = $ntInfo; $this->showNTSettings($indx, $pbo);
            }
            ?>
      </div>
    </div> <?php 
        }