<?php
/**
* Plugin Name: Sellosity
* Plugin URI: http://sellosity.com
* Description: Sellosity is the leading ecommerce platform for smart entrepreneurs who want to create a world class ecommerce store. This is the core Sellosity plugin and needs to be active for all other Sellosity addons and modules to be functional.
* Version: 1.0.7
* Author: Sellosity
* Author URI: http://sellosity.com/
*/
// If this file is called directly, abort.
if (!defined('WPINC')) {
die;
}
// Prevent direct access
define('SLO_URL',plugins_url('',__FILE__));
define('SLO_PATH',plugin_dir_path(__FILE__));
define('SLO_DEV_MODE',true);
// load css into the admin pages
function sellosity_adminstyle() {
wp_enqueue_style( 'sellosity-style', SLO_URL . '/css/admin.css' );
}
add_action( 'admin_enqueue_scripts', 'sellosity_adminstyle' );
if(!class_exists("sellosityauthlicense")){
class sellosityauthlicense{
var $name;
var $pref;
var $menutitle;
var $serverurl;
var $authurl;
var $memurl;
var $state;
var $email;
var $authkey;
var $levelnum;
var $pluginfile;
var $updateurl;
var $pluginadmin;
var $parentmenu;
var $minlevel;
var $icmember;
var $icserverurl;
var $icauthlocation;
var $icmemberurl;
function sellosityauthlicense($Info = array("pluginname" => "", "pluginprefix" => "", "pluginfile" => "", "pluginadmin" => "", "updateurl" => "", "menutitle" => "", "serverurl" => "", "authlocation" => "", "memberurl" => "", "parentmenu"=> "")){
$wp_dir = __FILE__;
$wp_dir = str_replace("\\", "/", $wp_dir);
$wp_dir = explode("/", $wp_dir);
for($index=0; $index<4; $index++)
unset($wp_dir[count($wp_dir) - 1]);
$wp_dir = implode("/", $wp_dir);
include_once($wp_dir."/wp-load.php");
$this->name = $Info["pluginname"];
$this->pref = $Info["pluginprefix"];
$this->menutitle = $Info["menutitle"];
$this->serverurl = $Info["serverurl"];
$this->authurl = $Info["authlocation"];
$this->memurl = $Info["memberurl"];
$this->pluginfile = $Info['pluginfile'];
$this->updateurl = isset($Info['updateurl'])?$Info['updateurl']:"";
$this->pluginadmin = $Info['pluginadmin'];
$this->parentmenu = isset($Info['parentmenu'])?$Info['parentmenu']:"";
$this->minlevel = $Info['minlevel'];
//add_filter( 'http_request_args', array(and$this, 'updates_exclude'), 5, 2 );
// database update
// Create the tables
// Check if cron time checker
if(!get_option('slo_settings-title-word-length')) {
update_option('slo_settings-title-word-length', 9999);
}
// Create api key on first time
if(!get_option('slo_settings-dm-cron-api-key')) {
update_option('slo_settings-dm-cron-api-key', substr(sha1(rand()), 0, 5));
}
// Check for the date format settings
if(!get_option('slo_settings-pros-date-format')) {
update_option('slo_settings-pros-date-format', '(as of %%M%%/%%D%%/%%Y%% at %%TIME%% UTC)');
}
// create/update required database tables
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
add_action($this->pref.'check_event', array(and$this, 'check_update'));
$this->state = $this->pref."activation_state";
$this->email = $this->pref."email";
$this->authkey = $this->pref."authkey";
$this->levelnum = $this->pref."levelnum";
if(get_option($this->state) and& get_option($this->email) != "" and& get_option($this->authkey) !== "" and& get_option($this->levelnum) > 0 ){
$this->update_encryptedoption($this->state ,get_option($this->state) );
$this->update_encryptedoption($this->email ,get_option($this->email) );
$this->update_encryptedoption($this->authkey ,get_option($this->authkey) );
$this->update_encryptedoption($this->levelnum ,get_option($this->levelnum) );
}
add_action('init', array(and$this, 'init'));
add_action('plugins_loaded', array(and$this, 'init'));
add_filter('cron_schedules', array(and$this, 'add_12hours_cron'));
register_activation_hook(__FILE__, array(and$this, 'CheckCron'));
add_action($this->pref.'12hours_event', array(and$this, 'VerifyLicense'));
add_action('admin_menu', array(and$this, 'admin_menu'),7000);
}
function init(){
$this->CheckCron();
// wp_enqueue_script('jquery');
if(isset($_POST['act']) and& $_POST['act'] == $this->pref.'install_license'){
if(!isset($_POST["email"]) || !isset($_POST["authkey"]) || $_POST["email"] == "" || $_POST["authkey"] == ""){
$msg = "Please enter email and authorization key";
echo 'failure:<div class="error"><p>'.$msg.'</p></div><br />';
exit;
}else{
if($this->VerifyLicense(trim(@$_POST["email"]), trim(@$_POST["authkey"]), trim(@$_POST["icmember"]))) {
echo "success:Thanks! The ".$this->name." has been activated. <a href='admin.php?page=".$this->pluginadmin."'>Click here to go to the admin panel...</a>\r\n";
exit;
} else {
echo 'failure:<div class="error"><p>'.__("Sorry, the API key was incorrect.","").'</p></div><br />';
exit;
}
}
}
}
function admin_menu() {
global $sloauthsettings;
if($this->get_decryptedoption($this->state) != 'true'){
add_menu_page($this->menutitle, $this->menutitle, 'administrator', $this->pref.'install_license', array(and$this, 'menupage'), $sloauthsettings['icon'],0 );
}elseif($this->parentmenu != "" and& $this->CheckLicense()){
$this->licensepage($this->parentmenu);
}
}
function ActivationMessage($ShowActive = false){
$msg = "";
if($this->get_decryptedoption($this->state) != 'true')
$msg="";
else if($ShowActive)
$msg = '<p>'.$this->name.' is Activated </p>';
if($msg != "")
echo '<div id="message" class="updated fade">'.$msg.'</div>';
}
function menupage(){
global $sloauthsettings;
$buttonText = "Activate Now";
$this->ActivationMessage(true);
if($this->get_decryptedoption($this->email) == "-1") $this->update_encryptedoption($this->email, "");
if($this->get_decryptedoption($this->authkey) == "-1") $this->update_encryptedoption($this->authkey, "");
?>
<script>
jQuery('#wpbody').prepend('<div class="slo-header-bar"><div class="slo-header-bar-inner"><div class="slo-header-bar-logo"></div><div class="slo-header-bar-links"><ul><li><a href="https://imsuccesscenter.com/customercare/"><i class="dashicons dashicons-sos"></i></a></li><li><a href="http://app.sellosity.com/"><i class="dashicons dashicons-admin-site"></i></a></li></ul></div></div></div>');
</script>
<div id="error"></div>
<div class="dvlicense">
<h1>Please Activate Your Copy of <?php echo $this->name?></h1>
<strong>Note - </strong> If you have spare licenses available we will automatically add this domain "<?php echo $_SERVER['SERVER_NAME']?>" to your license pool<br /><br />
<form id="actform" method="post">
<table>
<tr>
<th>Email address:</th>
<td><input type="text" name="email" value="<?php echo $this->get_decryptedoption($this->email);?>" /></td>
</tr>
<tr>
<th>Authorization key:</th>
<td>
<input type="text" name="authkey" value="<?php echo $this->get_decryptedoption($this->authkey);?>" />
<a class="forgot" href="<?php echo $this->memurl;?>">Forgot Your Details? Click Here</a>
</td>
</tr>
<tr>
<th></th>
<td>
<input type="hidden" name="act" value="<?php echo $this->pref;?>install_license" />
<input type="submit" id="btnsubmit" name="btnsubmit" value="<?php echo $buttonText;?>" />
</td>
</tr>
</table>
</form>
</div>
<style>
.dvlicense{
}
.dvlicense table th{
width: 200px;
text-align: left;
font-weight: bold;
vertical-align: top;
font-size: 12px;
}
.dvlicense table td input[type="text"]{
width: 300px;
}
.dvlicense table td .forgot{
display: block;
text-align: right;
color: blue;
text-decoration: none;
font-weight: bold;
font-size: 12px;
}
.dvlicense table td #btnsubmit{
float: right;
font-size: 12px;
}
</style>
<script>
var j = jQuery;
j(document).ready(function(){
j("#actform").submit( function () {
j("#btnsubmit").val("Activating please wait.....");
j("#btnsubmit").attr("disabled", 'true');
j.ajax({
type: "POST",
data : j(this).serialize(),
cache: false,
url: "<?php echo admin_url("admin.php?page=".$this->pref."install_license");?>",
success: function(data){
if(data.indexOf("success:") >= 0){
data = data.replace("success:", "");
j("#message").html('<p>'+data+'<br /></p>');
j("#error").html("");
//alert(data);
window.location.href = "<?php echo $this->pluginadmin;?>";
}else{
//alert(data);
j("#error").html(data.replace("failure:", ""));
j("#message").html('<p><strong>Notice: - </strong> <?php echo $this->name?> needs to be <span style="color: blue;">Activated</span> before it can be used<br /></p>');
}
j("#btnsubmit").val("Activate Plugin");
j("#btnsubmit").removeAttr("disabled");
}
});
return false;
});
});
</script>
<?php
}
function CheckLicense($ShowMessage = false){
if($ShowMessage)
$this->ActivationMessage();
if( $this->get_decryptedoption($this->state) != 'true')
return false;
else
return true;
}
function GetLevelNo(){
$LevelNo = 0;
if($this->CheckLicense())
$LevelNo = (int)$this->get_decryptedoption($this->levelnum, 0);
return $LevelNo;
}
function add_12hours_cron($schedules) {
$schedules['12hours'] = array(
'interval' => 43200,
'display' => __( 'Once in 12 Hours' )
);
return $schedules;
}
function CheckCron(){
$hook = $this->pref."12hours_event";
if(!wp_get_schedule($hook)) {
wp_schedule_event(current_time('timestamp'), "12hours", $hook);
}
}
function VerifyLicense($email = "-1", $authkey = "-1", $icmember="0") {
$msg = "";
$activated = false;
if($this->get_decryptedoption($this->email, "") != "" and& $email == "-1")
$email = $this->get_decryptedoption($this->email);
if($this->get_decryptedoption($this->authkey, "") != "" and& $authkey == "-1")
$authkey = $this->get_decryptedoption($this->authkey);
$remote_access_fail = false;
$domain = $_SERVER['SERVER_NAME'];
$request = '';
$email=urlencode($email);
$http_request = "GET ".$this->authurl."?email=".$email."&domain=".$domain."&authkey=".$authkey." HTTP/1.0\r\n";
$http_request .= "Host: ".$this->serverurl."\r\n";
$http_request .= "Content-Type: application/x-www-form-urlencoded; charset=".get_option('blog_charset')."\r\n";
$http_request .= "Content-Length: ".strlen( $request )."\r\n";
$http_request .= "User-Agent: ".$this->name."\r\n";
$http_request .= "\r\n";
$http_request .= $request;
//var_dump($http_request); die();
$response = '';
// checking for cloudfare access
$url = 'https://www.cloudflare.com/api_json.html?a=wl&tkn=65d64290e62eeca4df7e5bb73ddde9e92614c&email=admin@imsuccesscenter.com&key='.$_SERVER['SERVER_ADDR'];
if(extension_loaded("curl")) {
$s = curl_init();
curl_setopt($s,CURLOPT_URL,$url );
curl_setopt($s,CURLOPT_RETURNTRANSFER,true);
curl_setopt($s, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($s, CURLOPT_RETURNTRANSFER, 1);
$status = curl_getinfo($s,CURLINFO_HTTP_CODE);
$curlResponse = curl_exec($s);
$curlResponse = json_decode($curlResponse);
}else{
$curlResponse = file_get_contents($url);
$curlResponse = json_decode($curlResponse);
}
if(false != ($fs = @fsockopen($this->serverurl,80,$errno,$errstr,30 ) ) ) {
fwrite( $fs,$http_request );
while ( !feof( $fs ) ){
$response .= fgets( $fs,1160 ); // One TCP-IP packet
$pos = strpos($response, '403 Forbidden');
}
fclose( $fs );
$response = explode( "\r\n\r\n",$response,2 );
$returned_value = (int)trim( $response[1] );
//$returned_value = 2;
if( $returned_value > 0 and& $returned_value >= $this->minlevel ) {
{//if( $this->get_decryptedoption($this->state) != 'true' ) {
$this->update_encryptedoption($this->state,'true');
$this->update_encryptedoption($this->email, $email);
$this->update_encryptedoption($this->authkey, $authkey);
$this->update_encryptedoption($this->levelnum, $returned_value."|".$this->minlevel);
}
$activated = true;
} else {
if($email == "-1") $email = "";
if($authkey == "-1") $authkey = "";
$this->update_encryptedoption($this->state,"false");
$this->update_encryptedoption($this->email, $email);
$this->update_encryptedoption($this->authkey, $authkey);
$this->update_encryptedoption($this->levelnum, "");
$activated = false;
}
}
return $activated;
}
function updates_exclude( $r, $url ) {
if ( 0 !== strpos( $url, 'http://api.wordpress.org/plugins/update-check' ) )
return $r; // Not a plugin update request. Bail immediately.
$plugins = unserialize( $r['body']['plugins'] );
unset( $plugins->plugins[ plugin_basename( __FILE__ ) ] );
unset( $plugins->active[ array_search( plugin_basename( __FILE__ ), $plugins->active ) ] );
$r['body']['plugins'] = serialize( $plugins );
return $r;
}
function plugin_get($i) {
if ( ! function_exists( 'get_plugins' ) )
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
$plugin_folder = get_plugins( '/' . plugin_basename( dirname( $this->pluginfile ) ) );
$plugin_file = basename( ( $this->pluginfile ) );
return $plugin_folder[$plugin_file][$i];
}
function check_activation() {
wp_schedule_event(time(), 'twicedaily', array(and$this, $this->pref.'check_event'));
}
function check_update() {
global $wp_version;
$plugin_folder = plugin_basename( dirname( $this->pluginfile ) );
$plugin_file = basename( ( $this->pluginfile ) );
if ( defined( 'WP_INSTALLING' ) ) return false;
$response = wp_remote_get( $this->updateurl );
list($version, $url) = explode('|', $response['body']);
if($this->plugin_get("Version") == $version) return false;
$plugin_transient = get_site_transient('update_plugins');
$a = array(
'slug' => $plugin_folder,
'new_version' => $version,
'url' => $this->plugin_get("AuthorURI"),
'package' => $url
);
$o = (object) $a;
$plugin_transient->response[$plugin_folder.'/'.$plugin_file] = $o;
set_site_transient('update_plugins', $plugin_transient);
}
function check_deactivation() {
wp_clear_scheduled_hook($this->pref.'check_event');
}
function licensepage($parent_slug, $menu_title = "Update License"){
add_submenu_page($parent_slug, $menu_title, $menu_title, 'manage_options', $parent_slug.'-updatelicense', array (and$this, 'updatelicense') );
}
function updatelicense($buttonText = "Update License"){
$this->menupage($buttonText);
}
function encryptoptions($array) {
$compressedarray = json_encode($array);
$encrypted = urlencode(strtr(base64_encode(addslashes(serialize($compressedarray))), '+/=', '-_,'));
update_option($this->pref . "data", $encrypted);
}
function update_encryptedoption($item, $value) {
$encrypted = get_option($this->pref . "data");
$decryptedoptions = urldecode(unserialize(stripslashes(base64_decode(strtr($encrypted, '-_,', '+/=')))));
$uncompressedarray = json_decode($decryptedoptions, true);
$uncompressedarray[$item] = $value;
$compressedarray = json_encode($uncompressedarray);
$encrypted = urlencode(strtr(base64_encode(addslashes(serialize($compressedarray))), '+/=', '-_,'));
update_option($this->pref . "data", $encrypted);
}
function get_decryptedoption($item) {
$encryptedoptions = get_option($this->pref . "data");
$decryptedoptions = urldecode(unserialize(stripslashes(base64_decode(strtr($encryptedoptions, '-_,', '+/=')))));
$uncompressedarray = json_decode($decryptedoptions, true);
return $uncompressedarray[$item];
}
};
}
global $sloauthsettings;
$sloauthsettings=array(
"headerlogo"=>SLO_URL."/images/sellosity.png",
"headerbg"=>SLO_URL."/images/headerbg.png",
"headerheight"=>"100px",
"icon" => SLO_URL."/images/menuicon.png",
"pluginname" => "Sellosity",
"pluginprefix" => "imscso_",
"pluginfile" => __FILE__,
"pluginadmin" => admin_url(),
"menutitle" => "Activate Sellosity",
"parentmenu" => __FILE__,
"serverurl" => "app.sellosity.com",
"authlocation" => "/wp-content/plugins/license-checker/authorize_domain.php",
"memberurl" => "http://app.sellosity.com/login",
"minlevel" => 1,
);
global $sloauth_lc;
if (class_exists('sellosityauthlicense')) {
$sloauth_lc = new sellosityauthlicense($sloauthsettings);
}
if(!$sloauth_lc->CheckLicense()) {
$screen = get_current_screen();
if (is_admin() and& @$_GET['page'] != "imscso_install_license" ) {
add_action('admin_notices', 'Sellosity_DashboardAlert');
}
require_once SLO_PATH . '/app/shortcodes.php';
} else {
require_once SLO_PATH . '/app/sellosityapp.php';
require_once SLO_PATH . '/app/shortcodes.php';
}
// Load Main UI
require_once SLO_PATH . '/sellosity-core.php';
// First, create a function that includes the path to your favicon
function add_sellosity_favicon() {
global $sellosityadmin;
$sellosityadmin = sellosityadmin_network($sellosityadmin);
if ($sellosityadmin['favicon']['url']){
$favicon_url=$sellosityadmin['favicon']['url'];
} else {
$favicon_url = SLO_URL . '/images/favicon.png';
}
echo '<link rel="shortcut icon" href="' . $favicon_url . '" />';
}
add_action('login_head', 'add_sellosity_favicon');
add_action('admin_head', 'add_sellosity_favicon');
function Sellosity_DashboardAlert() {
echo "
<div class='updated fade sellosityactivate'>
<center><a href='".admin_url("admin.php?page=imscso_install_license")."'><img src='".SLO_URL."/images/activatesellosity.jpg'></a><BR><strong>To use Sellosity you need to activate your license, which you will find in the members area of the <a href='http://app.sellosity.com' target='_blank'>Sellosity training site</a>. Once you have your activation email and code you can <a href='".admin_url("admin.php?page=imscso_install_license")."'>click here</a> to activate.</strong></center>
</div>";
}