' . __( 'Settings', 'allegrato' ) . '';
$new_links = array_merge( $links, $new_links );
return $new_links;
};
}
add_action( 'plugin_action_links_' . plugin_basename(__FILE__), 'addLinksOnPluginsView' );
/*** Activation/Deactivation process ***/
if ( !class_exists( 'AllegratoActivator' ) )
{
$path = dirname( __FILE__ );
if ( file_exists( "$path/allegrato_activator.php" ) )
{
require_once("$path/allegrato_activator.php");
}
}
if ( !function_exists( 'allegratoActivatePlugin' ) )
{
function allegratoActivatePlugin()
{
$activator = new AllegratoActivator();
$activator->activate();
}
}
if ( !function_exists( 'allegratoDeactivatePlugin' ) )
{
function allegratoDeactivatePlugin()
{
$activator = new AllegratoActivator();
$activator->deactivate();
}
}
register_activation_hook( plugin_basename(__FILE__), 'allegratoActivatePlugin' );
register_deactivation_hook( plugin_basename(__FILE__), 'allegratoDeactivatePlugin' );
/*** Options Page ***/
if ( !function_exists( 'addPluginOptionsPage' ) )
{
function addPluginOptionsPage()
{
if ( function_exists( 'add_options_page' ) )
{
add_options_page( 'Allegrato', 'Allegrato', 'edit_pages', 'allegrato.php', 'callShowOptionsPage' );
}
}
}
if ( !function_exists( 'callShowOptionsPage' ) )
{
function callShowOptionsPage()
{
$allegratoWebapiKeyAllegro = get_option( 'allegrato_webapi_key_allegro' );
$allegratoWebapiLoginAllegro = get_option( 'allegrato_webapi_login_allegro' );
$allegratoWebapiPasswordAllegro = get_option( 'allegrato_webapi_password_allegro' );
$allegratoWebapiSiteAllegro = get_option( 'allegrato_webapi_site_allegro' );
$allegratoWebapiCountryAllegro = get_option( 'allegrato_webapi_country_allegro' );
$resultSitesInfo = array();
$resultCountries = array();
if( $allegratoWebapiKeyAllegro != false )
{
if( $allegratoWebapiCountryAllegro == false )
{
$allegratoWebapiCountryAllegro = AllegratoAllegroSoapClient::COUNTRY_PL;
}
try
{
$accessData = array(
'login' => get_option( 'allegrato_webapi_login_allegro' ),
'password' => get_option( 'allegrato_webapi_password_allegro' ),
'webapi_key' => get_option( 'allegrato_webapi_key_allegro' ),
'country' => $allegratoWebapiCountryAllegro,
);
$client = new AllegratoAllegroSoapClient( $accessData );
$resultSitesInfo = $client->doGetSitesInfo();
$resultCountries = $client->doGetCountries();
}
catch( Exception $e)
{
$errorMessages = $e->getMessage();
echo "
";
}
}
else
{
echo "" . __( 'Please fill in access data for your account. First you will have to save your WebApi key.', 'allegrato' ) . "
";
}
$disabled = '';
if( $allegratoWebapiKeyAllegro == false ):
$disabled = "disabled='disabled' ";
endif;
echo "";
echo "";
echo __( 'To be able to use allegro widgets you will have to gain ', 'allegrato' );
echo "
" . __( 'allegro WebApi key', 'allegrato' ) . ". ";
echo __( 'If you don\'t have it use ', 'allegrato' );
echo "
" . __( "that form.", 'allegrato' ) . ".";
echo "
";
echo "";
$adminUrl = get_admin_url();
echo "
{$adminUrl}admin-ajax.php";
$ajaxNonce = wp_create_nonce( 'allegrato_test_remote_system_allegro', 'allegrato_test_remote_system_allegro_wpnonce' );
echo "
{$ajaxNonce}";
echo "
";
}
}
add_action( 'wp_ajax_allegrato_test_remote_system_allegro', 'allegratoTestRemoteSystemAllegro' );
if ( !class_exists( 'AllegratoSoapClientAllegro' ) )
{
$path = dirname( __FILE__ );
if ( file_exists( "$path/classes/allegro/allegratosoapclientallegro.php" ) )
{
require_once( "$path/classes/allegro/allegratosoapclientallegro.php" );
}
}
if ( !class_exists( 'AllegratoCachedClientAllegro' ) )
{
$path = dirname( __FILE__ );
if ( file_exists( "$path/classes/allegro/allegratocachedclientallegro.php" ) )
{
require_once( "$path/classes/allegro/allegratocachedclientallegro.php" );
}
}
function allegratoTestRemoteSystemAllegro()
{
if ( check_ajax_referer( 'allegrato_test_remote_system_allegro' ) )
{
$accessData = array(
'login' => $_POST['allegrato_webapi_login_allegro'],
'password' => $_POST['allegrato_webapi_password_allegro'],
'webapi_key' => $_POST['allegrato_webapi_key_allegro'],
'country' => $_POST['allegrato_webapi_country_allegro'],
);
try
{
$client = new AllegratoAllegroSoapClient( $accessData );
$resultCountries = $client->login();
echo json_encode( array( 'type' => 'feedback', 'text' => __( 'Successfull log-in. Your access data is correct. Please save it now.', 'allegrato' ) ) );
die();
}
catch( Exception $e )
{
echo json_encode( array( 'type' => 'error', 'text' => $e->getMessage() ) );
die();
}
}
echo json_encode( array( 'type' => 'error', 'text' => 'Podczas przetwarzania wystąpiły błędy z nonce.' ) );
die();
}
function allegratoFetchMyAuctionsAllegro()
{
$accessData = array(
'login' => get_option( 'allegrato_webapi_login_allegro' ),
'password' => get_option( 'allegrato_webapi_password_allegro' ),
'webapi_key' => get_option( 'allegrato_webapi_key_allegro' ),
'country' => get_option( 'allegrato_webapi_country_allegro' ),
);
$client = new AllegratoCachedClientAllegro( new AllegratoAllegroSoapClient( $accessData ) );
$auctions = $client->doGetUserItems();
return $auctions;
}
function allegratoFetchSitesAllegro()
{
$accessData = array(
'login' => get_option( 'allegrato_webapi_login_allegro' ),
'password' => get_option( 'allegrato_webapi_password_allegro' ),
'webapi_key' => get_option( 'allegrato_webapi_key_allegro' ),
'country' => get_option( 'allegrato_webapi_country_allegro' ),
);
$client = new AllegratoCachedClientAllegro( new AllegratoAllegroSoapClient( $accessData ) );
$sites = $client->doGetSitesInfo();
return $sites;
}
add_action( 'admin_menu', 'addPluginOptionsPage' );
add_action( 'admin_init', 'registerAllegratoSettings' );
add_action( 'init', 'allegratoInit' );
function allegratoInit()
{
$pluginDir = basename(dirname(__FILE__));
load_plugin_textdomain('allegrato', false, "$pluginDir/translations");
}
if ( !function_exists( 'registerAllegratoSettings' ) )
{
function registerAllegratoSettings()
{
$activator = new AllegratoActivator();
foreach( $activator->getOptions() as $option )
{
register_setting( 'allegrato', $option );
}
}
}
/*** Activation/Deactivation process ***/
if ( !class_exists( 'AllegratoMyAuctionsAllegro' ) )
{
$path = dirname( __FILE__ );
if ( file_exists( "$path/widgets/allegrato_my_auctions_allegro.php" ) )
{
require_once("$path/widgets/allegrato_my_auctions_allegro.php");
}
}