Settings';
array_unshift($links, $settings_link);
return $links;
}
}
add_filter("plugin_action_links_".plugin_basename(__FILE__), 'aklamator_plugin_settings_link' );
/*
* Activation Hook
*/
register_activation_hook( __FILE__, 'set_up_options' );
function set_up_options(){
add_option('aklamatorApplicationID', '');
add_option('aklamatorPoweredBy', '');
add_option('aklamatorSingleWidgetID', '');
add_option('aklamatorPageWidgetID', '');
add_option('aklamatorSingleWidgetTitle', '');
}
/*
* Uninstall Hook
*/
register_uninstall_hook(__FILE__, 'aklamator_uninstall');
function aklamator_uninstall()
{
if (get_option('aklamatorApplicationID')) {
delete_option('aklamatorApplicationID');
}
if (get_option('aklamatorPoweredBy')) {
delete_option('aklamatorPoweredBy');
}
if(get_options('aklamatorSingleWidgetID')){
delete_options('aklamatorSingleWidgetID');
}
if(get_options('aklamatorPageWidgetID')){
delete_options('aklamatorPageWidgetID');
}
if(get_options('aklamatorSingleWidgetTitle')){
delete_options('aklamatorSingleWidgetTitle');
}
}
if( !function_exists("bottom_of_every_post")){
function bottom_of_every_post($content){
/* we want to change `the_content` of posts, not pages
and the text file must exist for this to work */
if (is_single()){
$widget_id = get_option('aklamatorSingleWidgetID');
}elseif (is_page()) {
$widget_id = get_option('aklamatorPageWidgetID');
}else{
/* if `the_content` belongs to a page or our file is missing
the result of this filter is no change to `the_content` */
return $content;
}
$title = "";
if(get_option('aklamatorSingleWidgetTitle') !== ''){
$title .= "
". get_option('aklamatorSingleWidgetTitle'). "
";
}
/* append the text file contents to the end of `the_content` */
return $content . $title ."
" . " ";
}
}
class AklamatorWidget
{
public $aklamator_url;
public $api_data;
public function __construct()
{
$this->aklamator_url = "http://aklamator.com/";
if (is_admin()) {
add_action("admin_menu", array(
&$this,
"adminMenu"
));
add_action('admin_init', array(
&$this,
"setOptions"
));
if (get_option('aklamatorApplicationID') !== '') {
$this->api_data = $this->addNewWebsiteApi();
}
}
if (get_option('aklamatorSingleWidgetID') !== 'none') {
if (get_option('aklamatorSingleWidgetID') == '') {
if ($this->api_data->data[0]) {
update_option('aklamatorSingleWidgetID', $this->api_data->data[0]->uniq_name);
}
}
add_filter('the_content', 'bottom_of_every_post');
}
if (get_option('aklamatorPageWidgetID') !== 'none') {
if (get_option('aklamatorPageWidgetID') == '') {
if ($this->api_data->data[0]) {
update_option('aklamatorPageWidgetID', $this->api_data->data[0]->uniq_name);
}
}
add_filter('the_content', 'bottom_of_every_post');
}
}
function setOptions()
{
register_setting('aklamator-options', 'aklamatorApplicationID');
register_setting('aklamator-options', 'aklamatorPoweredBy');
register_setting('aklamator-options', 'aklamatorSingleWidgetID');
register_setting('aklamator-options', 'aklamatorPageWidgetID');
register_setting('aklamator-options', 'aklamatorSingleWidgetTitle');
}
public function adminMenu()
{
add_menu_page('Aklamator Digital PR', 'Aklamator PR', 'manage_options', 'aklamator-digital-pr', array(
$this,
'createAdminPage'
), content_url() . '/plugins/aklamator-digital-pr/images/aklamator-icon.png');
}
public function getSignupUrl()
{
return $this->aklamator_url . 'registration/publisher?utm_source=wordpress&utm_medium=admin&e=' . urlencode(get_option('admin_email')) . '&pub=' . preg_replace('/^www\./','',$_SERVER['SERVER_NAME']).
'&un=' . urlencode(wp_get_current_user()->display_name);
}
private function addNewWebsiteApi()
{
if (!is_callable('curl_init')) {
return;
}
$service = $this->aklamator_url . "wp-authenticate/user";
$p['ip'] = $_SERVER['REMOTE_ADDR'];
$p['domain'] = site_url();
$p['source'] = "wordpress";
$p['AklamatorApplicationID'] = get_option('aklamatorApplicationID');
$client = curl_init();
curl_setopt($client, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($client, CURLOPT_HEADER, 0);
curl_setopt($client, CURLOPT_RETURNTRANSFER, true);
curl_setopt($client, CURLOPT_URL, $service);
if (!empty($p)) {
curl_setopt($client, CURLOPT_POST, count($p));
curl_setopt($client, CURLOPT_POSTFIELDS, http_build_query($p));
}
$data = curl_exec($client);
curl_close($client);
$data = json_decode($data);
return $data;
}
public function createAdminPage()
{
$code = get_option('aklamatorApplicationID');
$ak_home_url = 'http://aklamator.com';
$ak_dashboard_url = 'http://aklamator.com/dashboard';
?>