Skip to content

Commit

Permalink
oauth
Browse files Browse the repository at this point in the history
  • Loading branch information
lucianfcorodeanu committed Jul 1, 2024
1 parent cc80cc9 commit 438fddc
Show file tree
Hide file tree
Showing 89 changed files with 226 additions and 1 deletion.
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified .php-cs-fixer.cache
100644 → 100755
Empty file.
Empty file modified .php-cs-fixer.dist.php
100644 → 100755
Empty file.
Empty file modified LICENSE
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
Empty file modified assets/1.jpg
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified assets/api-setup-screen.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified assets/mapping-screen.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified assets/sync-screen.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified composer.json
100644 → 100755
Empty file.
Empty file modified composer.lock
100644 → 100755
Empty file.
Binary file modified src/install/newsmanapp.zip
Binary file not shown.
Empty file modified src/install/newsmanapp/config.xml
100644 → 100755
Empty file.
Empty file modified src/install/newsmanapp/controllers/front/index.php
100644 → 100755
Empty file.
Empty file modified src/install/newsmanapp/controllers/front/napi.php
100644 → 100755
Empty file.
Empty file modified src/install/newsmanapp/controllers/index.php
100644 → 100755
Empty file.
Empty file modified src/install/newsmanapp/index.php
100644 → 100755
Empty file.
Empty file modified src/install/newsmanapp/lib/Client.php
100644 → 100755
Empty file.
Empty file modified src/install/newsmanapp/lib/XMLRPC.php
100644 → 100755
Empty file.
Empty file modified src/install/newsmanapp/lib/cacert.pem
100644 → 100755
Empty file.
Empty file modified src/install/newsmanapp/lib/index.php
100644 → 100755
Empty file.
Empty file modified src/install/newsmanapp/logo.gif
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified src/install/newsmanapp/logo.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
153 changes: 152 additions & 1 deletion src/install/newsmanapp/newsmanapp.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ public function getContent()

$helper = new HelperForm();

$dataOauth = array();

// Module, token and currentIndex
$helper->module = $this;
$helper->name_controller = $this->name;
Expand All @@ -121,6 +123,9 @@ public function getContent()
$helper->toolbar_scroll = true; // yes - > Toolbar is always visible on the top of the screen.
$helper->submit_action = 'submit' . $this->name;

//set oauth variables before getting them
$this->isOauth($dataOauth);

// Load current value
$mapping = Configuration::get('NEWSMAN_MAPPING');
$mappingDecoded = json_decode($mapping, true);
Expand All @@ -138,7 +143,7 @@ public function getContent()

$js = 'var newsman=' .
json_encode([
'data' => $data ? json_decode($data) : false,
'data' => is_string($data) ? json_decode($data) : false,
'mapExtra' => $mapExtra,
'mapping' => $mapping ? json_decode($mapping) : false,
'ajaxURL' => $ajaxURL,
Expand All @@ -153,6 +158,11 @@ public function getContent()
]);

$frontend = [
'oauthStep' => isset($dataOauth["oauthStep"]) ? $dataOauth["oauthStep"] : null,
'dataLists' => empty($dataOauth["dataLists"]) ? "" : $dataOauth["dataLists"],
'creds' => empty($dataOauth["creds"]) ? "" : $dataOauth["creds"],
'isOauth' => isset($dataOauth["isOauth"]) ? $dataOauth["isOauth"] : null,
'oauthUrl' => isset($dataOauth["oauthUrl"]) ? $dataOauth["oauthUrl"] : null,
'js' => $js,
'list' => $mappingDecoded['list'] ?? '',
'segment' => $mappingDecoded['segment'] ?? '',
Expand All @@ -169,6 +179,147 @@ public function getContent()
return $this->display(__FILE__, 'views/templates/admin/configuration.tpl');
}

public function isOauth(&$data, $checkOnlyIsOauth = false){
require_once dirname(__FILE__) . '/lib/Client.php';

if (!is_array($data)) {
$data = array();
}

$redirUri = urlencode("https://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]);
$redirUri = str_replace("amp%3B", "", $redirUri);
$data["oauthUrl"] = "https://newsman.app/admin/oauth/authorize?response_type=code&client_id=nzmplugin&nzmplugin=Opencart&scope=api&redirect_uri=" . $redirUri;

//oauth processing

$error = "";
$dataLists = array();
$data["oauthStep"] = 1;
$viewState = array();

if(!empty($_GET["error"])){
switch($error){
case "access_denied":
$error = "Access is denied";
break;
case "missing_lists":
$error = "There are no lists in your NewsMAN account";
break;
}
}else if(!empty($_GET["code"])){

$authUrl = "https://newsman.app/admin/oauth/token";

$code = $_GET["code"];

$redirect = "https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];

$body = array(
"grant_type" => "authorization_code",
"code" => $code,
"client_id" => "nzmplugin",
"redirect_uri" => $redirect
);

$ch = curl_init($authUrl);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);

$response = curl_exec($ch);

if (curl_errno($ch)) {
$error .= 'cURL error: ' . curl_error($ch);
}

curl_close($ch);

if ($response !== false) {

$response = json_decode($response);

$data["creds"] = json_encode(array(
"newsman_userid" => $response->user_id,
"newsman_apikey" => $response->access_token
)
);

foreach($response->lists_data as $list => $l){
$dataLists[] = array(
"list_id" => $l->list_id,
"list_name" => $l->name
);
}

$data["dataLists"] = $dataLists;

$data["oauthStep"] = 2;
} else {
$error .= "Error sending cURL request.";
}
}

if(!empty($_POST["oauthstep2"]) && $_POST['oauthstep2'] == 'Y')
{
if(empty($_POST["newsman_list"]) || $_POST["newsman_list"] == 0)
{
$step = 1;
}
else
{
$creds = stripslashes($_POST["creds"]);
$creds = html_entity_decode($creds);
$creds = json_decode($creds, true);

$client = new Newsman_Client($creds["newsman_userid"], $creds["newsman_apikey"]);
$ret = $client->remarketing->getSettings($_POST["newsman_list"]);

$remarketingId = $ret["site_id"] . "-" . $ret["list_id"] . "-" . $ret["form_id"] . "-" . $ret["control_list_hash"];

//set feed
$url = "https://" . $_SERVER['SERVER_NAME'] . "/index.php?route=module/newsman_import&newsman=products.json&apikey=" . $creds["newsman_apikey"];

try{
$ret = $client->feeds->setFeedOnList($_POST["newsman_list"], $url, $_SERVER['SERVER_NAME'], "NewsMAN");
}
catch(Exception $ex)
{
//the feed already exists
}

$settings = array();
$settings['list_id'] = $_POST["newsman_list"];
$settings['NEWSMAN_API_KEY'] = $creds["newsman_apikey"];
$settings['NEWSMAN_USER_ID'] = $creds["newsman_userid"];

Configuration::updateValue('NEWSMAN_API_KEY', $settings['NEWSMAN_API_KEY']);
Configuration::updateValue('NEWSMAN_USER_ID', $settings['NEWSMAN_USER_ID']);
Configuration::updateValue(
'NEWSMAN_DATA',
json_encode(array('lists' => $dataLists, 'segments' => array()))
);
$mapping = array(
"list" => $settings["list_id"],
"remarketingid" => $remarketingId,
"remarketingenabled" => "1"
);
$mapping = json_encode($mapping);
Configuration::updateValue('NEWSMAN_MAPPING', $mapping);
}
}

$_apiKey = Configuration::get('NEWSMAN_API_KEY');

if(empty($_apiKey))
{
$data["isOauth"] = true;
}
else{
$data["isOauth"] = false;
}
}

private function jsonOut($output)
{
header('Content-Type: application/json');
Expand Down
Empty file modified src/install/newsmanapp/views/index.php
100644 → 100755
Empty file.
Empty file modified src/install/newsmanapp/views/js/NewsmanRemarketingActionLib.js
100644 → 100755
Empty file.
Empty file modified src/install/newsmanapp/views/js/index.php
100644 → 100755
Empty file.
Empty file modified src/install/newsmanapp/views/js/newsman.js
100644 → 100755
Empty file.
74 changes: 74 additions & 0 deletions src/install/newsmanapp/views/templates/admin/configuration.tpl
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,79 @@
* @license http://www.apache.org/licenses/LICENSE-2.0
-->
<div id="configuration_form" class="defaultForm form-horizontal newsmanapp">

{if $newsmanapp.isOauth}
<div id="contentOauth" style="margin: 20px;">
<!--oauth step-->
{if $newsmanapp.oauthStep == 1}
<form method="post" enctype="multipart/form-data">
<input type="hidden" name="newsman_oauth" value="Y" />
<input type="hidden" name="step" value="1" />
<table class="form-table newsmanTable newsmanTblFixed newsmanOauth">
<tr>
<td>
<p class="description"><b>Connect your site with NewsMAN for:</b></p>
</td>
</tr>
<tr>
<td>
<p class="description">- Subscribers Sync</p>
</td>
</tr>
<tr>
<td>
<p class="description">- Ecommerce Remarketing</p>
</td>
</tr>
<tr>
<td>
<p class="description">- Create and manage forms</p>
</td>
</tr>
<tr>
<td>
<p class="description">- Create and manage popups</p>
</td>
</tr>
<tr>
<td>
<p class="description">- Connect your forms to automation</p>
</td>
</tr>
</table>
<div style="padding-top: 5px;">
<a style="background: #ad0100" href="{$newsmanapp.oauthUrl}"
class="button button-primary btn btn-primary">Login with NewsMAN</a>
</div>
</form>
<!--List step-->
{elseif $newsmanapp.oauthStep == 2}
<form method="post" enctype="multipart/form-data">
<input type="hidden" name="oauthstep2" value="Y" />
<input type="hidden" name="step" value="1" />
<input type="hidden" name="creds" value="{$newsmanapp.creds|escape:'html'}" />
<table class="form-table newsmanTable newsmanTblFixed newsmanOauth">
<tr>
<td>
<select name="newsman_list" id="">
<option value="0">-- select list --</option>
{foreach from=$newsmanapp.dataLists item=l}
<option value="{$l.list_id}">
{$l.list_name}
</option>
{/foreach}
</select>
</td>
</tr>
</table>

<div style="padding-top: 5px;">
<button type="submit" style="background: #ad0100" class="button button-primary btn btn-primary">Save</button>
</div>
</form>
{/if}
</div>
{else}
<div class="panel" id="fieldset_0">
<div class="panel-heading">
<i class="icon-cogs"></i>API Settings
Expand Down Expand Up @@ -132,6 +205,7 @@
</div>
</div>
</form>
{/if}

<div class="modal" id="notificationsM" tabindex="-1">
<div class="modal-dialog" role="document">
Expand Down
Empty file modified src/install/newsmanapp/views/templates/admin/index.php
100644 → 100755
Empty file.
Empty file modified src/install/newsmanapp/views/templates/index.php
100644 → 100755
Empty file.
Empty file modified src/install/newsmanfetch.php
100644 → 100755
Empty file.
Empty file modified src/obsolete/newsman.zip
100644 → 100755
Empty file.
Empty file modified src/obsolete/newsman/config.xml
100644 → 100755
Empty file.
Empty file modified src/obsolete/newsman/config_ro.xml
100644 → 100755
Empty file.
Empty file modified src/obsolete/newsman/index.php
100644 → 100755
Empty file.
Empty file modified src/obsolete/newsman/lib/Client.php
100644 → 100755
Empty file.
Empty file modified src/obsolete/newsman/lib/XMLRPC.php
100644 → 100755
Empty file.
Empty file modified src/obsolete/newsman/lib/cacert.pem
100644 → 100755
Empty file.
Empty file modified src/obsolete/newsman/lib/index.php
100644 → 100755
Empty file.
Empty file modified src/obsolete/newsman/logo.gif
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified src/obsolete/newsman/logo.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified src/obsolete/newsman/newsman.php
100644 → 100755
Empty file.
Empty file modified src/obsolete/newsman/translations/ro.php
100644 → 100755
Empty file.
Empty file modified src/obsolete/newsman/views/index.php
100644 → 100755
Empty file.
Empty file modified src/obsolete/newsman/views/js/index.php
100644 → 100755
Empty file.
Empty file modified src/obsolete/newsman/views/js/newsman.js
100644 → 100755
Empty file.
Empty file modified src/obsolete/newsmanfetch.php
100644 → 100755
Empty file.
Empty file modified src/obsolete/newsmanremarketing.zip
100644 → 100755
Empty file.
Empty file modified src/obsolete/newsmanremarketing/LICENSE
100644 → 100755
Empty file.
Empty file modified src/obsolete/newsmanremarketing/README.md
100644 → 100755
Empty file.
Empty file modified src/obsolete/newsmanremarketing/assets/1.jpg
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified src/obsolete/newsmanremarketing/config.xml
100644 → 100755
Empty file.
Empty file modified src/obsolete/newsmanremarketing/config_ro.xml
100644 → 100755
Empty file.
Empty file.
Empty file modified src/obsolete/newsmanremarketing/controllers/admin/index.php
100644 → 100755
Empty file.
Empty file modified src/obsolete/newsmanremarketing/controllers/front/ajax.php
100644 → 100755
Empty file.
Empty file modified src/obsolete/newsmanremarketing/controllers/front/index.php
100644 → 100755
Empty file.
Empty file modified src/obsolete/newsmanremarketing/controllers/index.php
100644 → 100755
Empty file.
Empty file modified src/obsolete/newsmanremarketing/index.php
100644 → 100755
Empty file.
Empty file modified src/obsolete/newsmanremarketing/logo.gif
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified src/obsolete/newsmanremarketing/logo.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified src/obsolete/newsmanremarketing/newsmanremarketing.php
100644 → 100755
Empty file.
Empty file modified src/obsolete/newsmanremarketing/translations/en.php
100644 → 100755
Empty file.
Empty file modified src/obsolete/newsmanremarketing/translations/index.php
100644 → 100755
Empty file.
Empty file modified src/obsolete/newsmanremarketing/views/css/index.php
100644 → 100755
Empty file.
Empty file.
Empty file modified src/obsolete/newsmanremarketing/views/css/newsman.css
100644 → 100755
Empty file.
Empty file modified src/obsolete/newsmanremarketing/views/img/add_to_cart_icon.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified src/obsolete/newsmanremarketing/views/img/checkout_icon.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified src/obsolete/newsmanremarketing/views/img/ga_logo.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified src/obsolete/newsmanremarketing/views/img/index.php
100644 → 100755
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified src/obsolete/newsmanremarketing/views/img/purchase_icon.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified src/obsolete/newsmanremarketing/views/img/stats.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified src/obsolete/newsmanremarketing/views/index.php
100644 → 100755
Empty file.
Empty file.
Empty file modified src/obsolete/newsmanremarketing/views/js/index.php
100644 → 100755
Empty file.
Empty file modified src/obsolete/newsmanremarketing/views/js/jquery-1.12.4.min.js
100644 → 100755
Empty file.
Empty file modified src/obsolete/newsmanremarketing/views/js/jquery-2.x.min.js
100644 → 100755
Empty file.
Empty file.
Empty file.
Empty file modified src/obsolete/newsmanremarketing/views/templates/admin/index.php
100644 → 100755
Empty file.
Empty file modified src/obsolete/newsmanremarketing/views/templates/index.php
100644 → 100755
Empty file.
Empty file modified tools/php-cs-fixer/composer.json
100644 → 100755
Empty file.
Empty file modified tools/php-cs-fixer/composer.lock
100644 → 100755
Empty file.

0 comments on commit 438fddc

Please sign in to comment.