sDefaultAccountApiUrl);
}
$this->load_epaper_options();
$this->oView = new stdClass();
$this->sPage = isset($_GET['page'])?$_GET['page']:NULL;
$this->sDefaultLang = $this->getBlogDefaultLanguage();
//Epaper API
$this->oChannelApi = new EpaperChannelApi();
$this->oAccountApi = new EpaperApikeyApi();
$this->oEpaperApi = new EpaperApi();
ini_set('max_execution_time', 120);
ini_set("soap.wsdl_cache_enabled", 1);
ini_set("soap.wsdl_cache_ttl", 86400);
$this->is_registered();
if($bRegisterActions == true):
//ajax-action
add_action( 'wp_ajax_nopriv_epaper_ajax', array( $this, 'fetchAjaxRequest' ) );
add_action( 'wp_ajax_epaper_ajax', array( $this, 'fetchAjaxRequest' ) );
//load plugin translations
add_action( 'init', array( $this, 'plugin_textdomain' ) );
//load styles and scripts
add_action( 'init', array( $this, 'action_admin_init_register_styles_and_scripts' ) );
add_filter('the_posts', array( $this,'filter_posts_conditionally_add_scripts_and_styles'));
//custom actions
add_action('admin_menu', array( $this,'action_epaper_integration_menu'));
add_shortcode('ePaper', array( $this,'shortcode_epaper'));
if($this->is_registered() == true):
add_action( 'widgets_init', create_function('', 'return register_widget("EpaperWidgetClass");') );
add_filter('mce_external_plugins', array ($this,'addScriptToTinymce' ) );
add_filter('mce_buttons', array ($this,'registerTgTinyButton' ) );
add_action('init', array($this, 'updatePlugin'));
endif;
add_action('add_meta_boxes', array( $this, 'action_add_metabox_epaper' ) );
// drop a warning on each page of the admin when 1000grad-epaper hasn't been configured
add_action( 'admin_notices', array( $this, 'showRegistrationInfo' ) );
endif;
}
//returns current plugin-version
public static function getPluginVersion(){
return self::$sPluginVersion;
}
//update plugin
public function updatePlugin(){
if(!isset($this->aEpaperOptions['update_infos']) || (((time() - $this->aEpaperOptions['update_infos']) / 86400) > 30)):
$this->oAccountApi->updatePluginInfos();
$this->aEpaperOptions['update_infos'] = time();
update_option($this->sEpaperOptionIndex, $this->aEpaperOptions);
endif;
}
public function get($sVar){
return $this->{$sVar};
}
public function set($sVar, $sValue){
$this->{$sVar} = $sValue;
return true;
}
//registers plugin-button in tinymce-editor
function registerTgTinyButton($aButtons) {
array_push($aButtons, "|", "tg_tiny_button");
return $aButtons;
}
//adds js-script to tinymce-editor
function addScriptToTinymce($aPluginArray) {
$aPluginArray['tg_tiny_button'] = plugins_url($this->sBasePluginPath.'/js/tg_tinymce.js');
return $aPluginArray;
}
//initialize default plugin-configuration
private function load_epaper_options(){
$this->aEpaperOptions = get_option($this->sEpaperOptionIndex);
if($this->aEpaperOptions == false):
$this->aEpaperOptions = array(
'wordpressapi' => TGE_PLUGIN_ACCOUNT_API_URI);
update_option($this->sEpaperOptionIndex, $this->aEpaperOptions);
endif;
}
//returns registered status
public function is_registered(){
$this->apikey = isset($this->aEpaperOptions['apikey'])?$this->aEpaperOptions['apikey']:NULL;
if (!empty($this->apikey)) {
$this->bIsRegistered = true;
} else {
$this->bIsRegistered = false;
}
return $this->bIsRegistered;
}
//loads plugin translation file
public function plugin_textdomain() {
load_plugin_textdomain('1000grad-epaper', false, '1000grad-epaper/lang');
}
//registers (the pathes of) admin-specific styles and scripts
public function action_admin_init_register_styles_and_scripts() {
wp_register_style('style_colorbox', plugins_url($this->sBasePluginPath.'colorbox/colorbox.css'));
wp_register_style('tg_styles', plugins_url($this->sBasePluginPath.'css/tg_styles.css'));
wp_register_script('jquery_migrate', plugins_url($this->sBasePluginPath.'js/jquery_migrate.js'));
wp_register_script('jquery2', plugins_url($this->sBasePluginPath.'js/jquery.2.0.3.js'));
wp_register_script('tg_script_js', plugins_url($this->sBasePluginPath.'js/tg_script.js'), array('jquery')); // benötigt jquery
wp_register_script('js_colorbox_min', plugins_url($this->sBasePluginPath.'colorbox/jquery.colorbox-min.js'), array('jquery'));
wp_register_script('colorbox-epaper', plugins_url($this->sBasePluginPath.'js/colorbox-epaper.js'), array('jquery'));
wp_register_script('uploadify_js', plugins_url($this->sBasePluginPath.'js/uploadify/jquery.uploadify.js'), array('jquery2'));
}
//init scripts and styles
public function filter_posts_conditionally_add_scripts_and_styles ($posts)
{
if (!empty($posts)) {
wp_enqueue_style('tg_styles');
wp_enqueue_script('jquery');
wp_enqueue_script('js_colorbox_min', plugins_url('1000grad-epaper/colorbox/jquery.colorbox-min.js'), array('jquery'));
wp_enqueue_script('colorbox-epaper', plugins_url('1000grad-epaper/js/colorbox-epaper.js'), array('jquery'));
wp_enqueue_style('style_colorbox', plugins_url('1000grad-epaper/colorbox/colorbox.css'));
return $posts;
}
return $posts;
}
//registers and enqueues plugin-specific styles.
public function action_enqueue_scripts_for_all_adminpages()
{
switch($this->sPage):
case 'epaper_channels':
wp_enqueue_script('jquery2');
wp_enqueue_script('jquery_migrate');
wp_enqueue_script('uploadify_js');
default:
wp_enqueue_style('style_colorbox');
wp_enqueue_style('uploadify');
wp_enqueue_style('tg_styles');
wp_enqueue_script('js_colorbox_min');
wp_enqueue_script('colorbox-epaper');
wp_enqueue_script('tg_script_js');
wp_localize_script( 'tg_script_js', 'TGELocalData', array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'tge_nonce' => wp_create_nonce( 'epaper_ajax-nonce' ),
));
break;
endswitch;
}
//integrate epaper-plugin to main-menu
public function action_epaper_integration_menu()
{
add_action( 'admin_enqueue_scripts', array($this,'action_enqueue_scripts_for_all_adminpages' ));
add_menu_page(
'ePaper',
'1000°ePaper',
'upload_files',
'epaper_channels',
array($this, 'adminpage_epaper_channels'),
plugins_url($this->sBasePluginPath."img/1000grad_icon.png")
);
if ($this->bIsRegistered === false):
add_submenu_page(
'epaper_channels',
'ePaper '.__('Registration','1000grad-epaper'),
__('Registration','1000grad-epaper'),
'upload_files',
'epaper_apikey',
array($this, 'adminpage_epaper_apikey')
);
else:
add_submenu_page(
'epaper_channels', // parent
'ePaper '.__('Manage Subscription','1000grad-epaper'),
__('Manage Subscription','1000grad-epaper'),
'upload_files',
'epaper_subscription',
array($this, 'adminpage_epaper_subscription')
);
endif;
add_options_page( '1000°ePaper', '1000°ePaper', 'upload_files','epaper_settings', array($this,'adminpage_epaper_settings'));
}
//add metabox to page|post-editor
public function action_add_metabox_epaper()
{
if ($this->bIsRegistered === true) {
add_meta_box('epaper_editorbox', '1000°ePaper', array($this, 'meta_box_epaper'), 'post', 'side', 'high');
add_meta_box('epaper_editorbox', '1000°ePaper', array($this, 'meta_box_epaper'), 'page', 'side', 'high');
return true;
}
return false;
}
//shows registration-info, if isRegistered == false
public function showRegistrationInfo()
{
if ($this->bIsRegistered === false && !isset($_POST['registration_key_requested']) && (!isset($_GET['email']) && !isset($_GET['code']) )) {
$sMessage = sprintf("%s
%s", __( "1000°ePaper is not registered yet.", '1000grad-epaper' ), sprintf(__( "Please %sregister your installation%s.", '1000grad-epaper' ),
"", ""));
$this->showInfo($sMessage);
}
}
//shortcode function of plugin
public function shortcode_epaper($aArgs)
{
if ($this->bIsRegistered === true) {
$iChannel = (isset($aArgs['nr']) && !empty($aArgs['nr']))?$aArgs['nr']:1;
$iPage = (isset($aArgs['page']) && !empty($aArgs['page']))?$aArgs['page']:1;
$oChannels = $this->getChannels();
$oChannel = isset($oChannels->channels[($iChannel-1)])?$oChannels->channels[($iChannel-1)]:NULL;
if($oChannel == NULL) return false;
$sClass = (isset($aArgs['class']) && !empty($aArgs['class']))?$aArgs['class']:'alignleft';
$sLink = $this->getEpaperLink($oChannel, NULL, array('class' => $sClass, 'page' => $iPage));
$this->bUseMainTemplate = false;
$this->oView->class = $sClass;
$this->oView->link = $sLink;
ob_start();
$this->showContent();
$sShortcodeContent = ob_get_contents();
ob_end_clean();
return $sShortcodeContent;
}
return false;
}
//registration-adminpage
public function adminpage_epaper_apikey()
{
isset($_POST['register_account'])?$this->sendRegistrationEmail():NULL;
$this->oView->registration_error = false;
$this->oView->email_submitted = true;
$this->oView->message = NULL;
$this->oView->registration_code_entered = false;
switch(isset($_GET['code'])):
case true:
$this->oView->code = trim(htmlspecialchars($_GET['code']));
$this->oView->email = trim(htmlspecialchars($_GET['email']));
$this->oView->registration_code_entered = true;
try {
$oResult = ($this->oAccountApi->sendCodeGetApikey($this->oView->email, $this->oView->code));
} catch (SoapFault $e) {
$this->showWarning("error on receiving apikey. ".$e->getMessage());
die();
}
if ($oResult == false):
$this->showWarning(sprintf('%s %s', __("ePaper Registration fault.", '1000grad-epaper'), __("Please type in the confirmation code you was receiving via email.", '1000grad-epaper')));
else:
$oResult = json_decode($oResult);
$this->aEpaperOptions['email'] = $this->oView->email;
$this->aEpaperOptions['url'] = $oResult->apiurl;
$this->aEpaperOptions['apikey'] = $oResult->apikey;
$this->aEpaperOptions['apikey_as'] = $oResult->apikey_as;
update_option($this->sEpaperOptionIndex, $this->aEpaperOptions);
$this->bIsRegistered = true;
$this->showInfo(sprintf('%s', __("
Now you can use this ePaper Plugin!
", '1000grad-epaper'))); endif; $this->oView->registration_error = ($oResult==false)?true:false; break; case false: if(isset($this->aEpaperOptions['email']) && $this->aEpaperOptions['email'] != ""): $this->oView->email_submitted = true; else: $this->oView->email_submitted = false; endif; break; endswitch; $this->aTemplateVars = array('TITLE' => __("1000°ePaper Registration","1000grad-epaper")); $this->sTemplate = 'adminpage_epaper_apikey'; $this->bUseMainTemplate = true; $this->showContent(); } //registration-email private function sendRegistrationEmail(){ $sEmail = trim(htmlspecialchars($_POST['apikey_email'])); $bAgb = isset($_POST['agb'])?true:false; $bNewsletter = isset($_POST['newsletter'])?true:false; $sLanguage = __("en",'1000grad-epaper'); global $wp_version; $sWordpressVersion = $wp_version; $sPhpVersion = phpversion(); $sAdminUrl = admin_url(); $sSubject = "wordpress"; $sWordpressCode = ""; $aEpaperOptions = array( 'email' => $sEmail, 'text' => $sSubject, 'agb' => ($bAgb === true)?'yes':'no', 'wordpressapi' => TGE_PLUGIN_ACCOUNT_API_URI, 'newsletter' => ($bNewsletter === true)?'yes':'no' ); update_option($this->sEpaperOptionIndex, $aEpaperOptions); try { $sResponseMessage = $this->oAccountApi->getRegistrationCodeByEmail($sEmail, $sSubject, $sAdminUrl, NULL, NULL, $sWordpressCode, ($bAgb === true)?'yes':'no', ($bNewsletter === true)?'yes':'no', $sWordpressVersion ,$sPhpVersion, $sLanguage); if(isset($sResponseMessage['info'])): $sMessage = $sResponseMessage['info']; $this->showInfo($sMessage); elseif(isset($sResponseMessage['error'])): $sMessage = $sResponseMessage['error']; $this->showWarning($sMessage); endif; } catch (SoapFault $e) { $this->showWarning("error on receiving apikey. ".$e->getMessage()); die(); } } //subscription-adminpage public function adminpage_epaper_subscription() { try { $sLanguage = substr(get_bloginfo ( 'language' ), 0, 2); $sPPButton = $this->oAccountApi->getPPButtonCode(($sLanguage != NULL && $sLanguage != false)?$sLanguage:'en'); }catch(SoapFault $e){ $this->showWarning("error while connecting to account-api ".$e->getMessage()); die(); } if(is_object($sPPButton) && get_class($sPPButton) == 'WP_Error' && $this->bKeyRefreshed == false): $this->bKeyRefreshed = true; $this->oAccountApi->refreshKeys(); $this->load_epaper_options(); $this->adminpage_epaper_subscription(); return false; endif; $this->oView->button_code = (is_string($sPPButton))?json_decode($sPPButton):array(); $this->aTemplateVars = array('TITLE' => sprintf('%s - %s', $this->sDefaultTitle, __("Manage Your Subscription",'1000grad-epaper'))); $this->showContent(); } //settings-adminpage public function adminpage_epaper_settings() { $this->oView->feedback_sent = false; $this->aTemplateVars = array('TITLE' => sprintf('%s - %s',$this->sDefaultTitle, 'Settings')); global $tge_plugin_data; $tge_plugin_data = get_plugin_data(__FILE__); //save settings if (isset($_GET['epaper-settings-save'])) $this->saveEpaperSettings(); if (isset($_POST['feedback'])): $this->saveEpaperFeedback(); endif; $this->sTemplate = "adminpage_epaper_settings"; $this->showContent(); } //action of feedback-form private function saveEpaperFeedback(){ $sText = $_POST['text']; global $wp_version; $sLanguage = __("en",'1000grad-epaper'); $sWordpressVersion = $wp_version; $sPhpVersion = phpversion(); $sPluginVersion = $this->getPluginVersion(); $this->oView->feedback_sent = $this->oAccountApi->sendFeedback($this->aEpaperOptions['email'], $sText, NULL, admin_url(), NULL, NULL,$sWordpressVersion, $sPhpVersion, $sLanguage, $sPluginVersion ); } //saving epaper-settings private function saveEpaperSettings(){ $this->aEpaperOptions['url'] = htmlspecialchars($_GET['epaper_url']); $this->aEpaperOptions['wordpressapi'] = htmlspecialchars($_GET['epaper_wordpressapi']); $this->aEpaperOptions['apikey'] = htmlspecialchars($_GET['epaper_apikey']); $this->aEpaperOptions['apikey_as'] = htmlspecialchars($_GET['apikey_as']); update_option($this->sEpaperOptionIndex, $this->aEpaperOptions); } //returns object of user-channels public function getChannels($bUpdate = NULL){ if(isset($this->aEpaperOptions[$this->sEpaperOptionsChannelConfig]) && $bUpdate == false) return json_decode($this->aEpaperOptions[$this->sEpaperOptionsChannelConfig]); $oChannels = $this->getChannelConfigObject(); $this->aEpaperOptions[$this->sEpaperOptionsChannelConfig] = json_encode($oChannels); update_option($this->sEpaperOptionIndex, $this->aEpaperOptions); return $oChannels; } //returns info-object of user-channel public function getChannelInfos($iChannelId = NULL, $bForceRefresh = false){ if($iChannelId == NULL) return false; if($bForceRefresh): $oChannel = json_decode($this->oChannelApi->getChannelInfo($this->aEpaperOptions['apikey'], $iChannelId)); return $oChannel; else: $oChannelConfig = $this->getChannelConfigObject()->channels; foreach($oChannelConfig as $iIndex => $oChannel): if($oChannel->id == $iChannelId) return $oChannel; endforeach; endif; return false; } //returns info-object of user-epaper public function getEpaperInfos($iEpaperId = NULL, $bForceRefresh = false){ if($iEpaperId == NULL) return false; if($bForceRefresh): $oEpaper = json_decode($this->oEpaperApi->returnEpaperInfos($this->aEpaperOptions['apikey'], $iEpaperId)); return $oEpaper; else: $oChannelConfig = $this->getChannelConfigObject()->channels; foreach($oChannelConfig as $iIndex => $oChannel): if($oChannel->epaperInfo->id == $iEpaperId) return $oChannel->epaperInfo; endforeach; endif; return false; } //channel-list public function adminpage_epaper_channels(){ $this->clearAllChannelPreviewImages(); $this->oView->bAgbWasAccepted = $this->agbWasAccepted(); $this->oView->sAdminUrl = get_admin_url(); if($this->bIsRegistered == true) $this->oView->channelobject = $this->getChannelConfigObject(true); $this->aTemplateVars = array('TITLE' => $this->sDefaultTitle); $this->bUseMainTemplate = true; $this->sTemplate = 'adminpage_epaper_channels'; $this->showContent(); } //backend warning-box public function showWarning($sMessage){ $this->aTemplateVars = array('MESSAGE' => $sMessage); $this->bUseMainTemplate = false; $this->sTemplate = 'adminpage_epaper_warning'; $this->showContent(); } //backend info-box public function showInfo($sMessage){ $this->aTemplateVars = array('MESSAGE' => $sMessage); $this->bUseMainTemplate = false; $this->sTemplate = 'adminpage_epaper_info'; $this->showContent(); } //metabox public function meta_box_epaper() { $this->oView->channelobject = $this->getChannels(); $this->bUseMainTemplate = false; $this->showContent(); } //returns default-link of empty channel public function getEpaperDefaultLink(){ return isset($this->aEpaperOptions[$this->sEpaperOptionsChannelDefaultUrl]->url)?$this->aEpaperOptions[$this->sEpaperOptionsChannelDefaultUrl]->url:$this->defaultFallback; } //returns link to epaper public function getEpaperLink($channel = NULL, $epaper = NULL, $aConfig = array()){ //$epaper can be integer or object (epaper_id | oEpaper) //$channel can be integer or object (channel_id | oChannel //link == 0 => overlay, link == 1 => extern $iDefault = 0; if($channel == NULL) return false; $oChannelInfo = is_object($channel)?$channel:$this->getChannelInfos($channel); $epaper = ($epaper == NULL)?$oChannelInfo->id_epaper:$epaper; $oEpaperInfo = is_object($epaper)?$epaper:$this->getEpaperInfos($epaper); if(isset($oEpaperInfo->settings->add_export_info)): $oLinksettings = json_decode($oEpaperInfo->settings->add_export_info); $iLinkType = isset($oLinksettings->linktype)?$oLinksettings->linktype:$iDefault; else: $iLinkType = 0; endif; if($oEpaperInfo == NULL){ $sEpaperLink = $this->getEpaperDefaultLink(); $sClass = 'class="ePaper"'; $sImageSrc = sprintf('%s%s',$this->getEpaperDefaultLink(), $this->sDefaultPreviewImage); }else{ $iPage = isset($aConfig['page'])?$aConfig['page']:NULL; $sEpaperLink = sprintf('%s%s', $oChannelInfo->url, ($iPage != NULL)?sprintf('#%u', $iPage):NULL); $sClass = ($iLinkType == 0)?'class="ePaper"':NULL; $sImageSrc = sprintf('%s%s', $oChannelInfo->url, $this->sDefaultPreviewImage); } $aImageSrc = $this->getChannelPreviewImage($oChannelInfo->id, $sImageSrc); $sParameter = is_user_logged_in()?sprintf('%s%u',"?rnd=",rand(1000,9999)):NULL; return sprintf('