Bei Aktivierung dieses Plugins wird automatisch eine Seite mit Hotelbewertungen und Angeboten generiert.
Author: ab-in-den-urlaub
Version: 1.7
*/
// default settings
define('CONTENT_4_PARTNERS_VERSION', '1.7');
define('CONTENT_4_PARTNERS_HOST', 'webservice.ab-in-den-urlaub.de');
define('CONTENT_4_PARTNERS_PORT', '80');
define('CONTENT_4_PARTNERS_DIR', '');
define('CONTENT_4_PARTNERS_USER', '');
define('CONTENT_4_PARTNERS_PASSWORD', '');
define('CONTENT_4_PARTNERS_DEFAULT_ID', '');
define('CONTENT_4_PARTNERS_CACHE_LIFETIME', 3600);
define('CONTENT_4_PARTNERS_CACHE_USE', '1');
define('CONTENT_4_PARTNERS_NAMESPACE', 'Partner');
define('CONTENT_4_PARTNERS_PERMALINKS_USE', '0');
define('CONTENT_4_PARTNERS_BEGINTAG', '');
define('CONTENT_4_PARTNERS_ENDTAG', '');
define('CONTENT_4_PARTNERS_REDIRECTOR_PATH', 'wp-content/plugins/ab-in-den-urlaubde-content-4-partners/redirect.php');
define('CONTENT_4_PARTNERS_PERMALINK_STRUCTURE', '/([a-zA-Z+-/]*)/([0-9-]*).*$');
// max cache lifetime in seconds (one day = 86400 seconds)
define('CONTENT_4_PARTNERS_CACHE_MAX_LIFETIME', 86400);
// default plugin setting names
define('CONTENT_4_PARTNERS_SETTINGS_GROUP', 'content_4_partners_settings_options');
define('CONTENT_4_PARTNERS_SETTINGS', 'content_4_partners_settings');
// registration data for plugin
define('CONTENT_4_PARTNERS_REGDATA_GROUP', 'content_4_partners_regdata_options');
define('CONTENT_4_PARTNERS_REGDATA', 'content_4_partners_regdata');
// default cache settings
define('CONTENT_4_PARTNERS_DEFAULT_CACHE_LIFETIME', 3600);
define('CONTENT_4_PARTNERS_CACHE_KEY_PREFIX', 'content_4_partners_');
// helper for finding this plugin when links are added to plugin actions
static $content4partners_plugin;
/**
* Content 4 Partners Plugin.
*/
class Content4Partners
{
// cached options, always get options via $this->getOptions() !!!!
var $options = null;
/**
* Creates new content 4 partners plugin.
*/
function Content4Partners()
{
// register admin hooks
add_action('admin_init', array(&$this, 'hookAdminInit'));
add_action('admin_menu', array(&$this, 'hookAdminMenu'));
// register activation/deactivation hooks
register_activation_hook(__FILE__, array(&$this, 'hookAdminPluginActivate'));
register_deactivation_hook(__FILE__, array(&$this, 'hookAdminPluginDeactivate'));
// register short cuts
add_shortcode('content4partners', array(&$this, 'shortCodeContent4Partners'));
// register plugin action hooks
add_filter('plugin_action_links', array(&$this, 'hookAddPluginAction'), 10, 2);
// register title hook
add_filter('wp_title', array(&$this, 'hookWpTitle'), 99, 3);
// to manipulate the behavior of the wpseo-plugin
// user can decide if he wants the wpseo to manipulate the title as well
if (1 == get_post_meta($this->getPageId(), '_wpseo_edit_only', true)) {
$optionsseo = get_option('wpseo_options');
// if there are no wpseo_options the wpseo-plugin may not installed
if (false === $optionsseo) {
update_post_meta($this->getPageId(), '_wpseo_edit_title', trim($this->getTitleForId($this->getRegionId())) . ' | ' . get_bloginfo());
} else {
update_post_meta($this->getPageId(), '_wpseo_edit_title', trim($this->getTitleForId($this->getRegionId())) . ' ' . $optionsseo['wp_seo_title_separator'] . ' ' . get_bloginfo());
}
}
add_filter('rewrite_rules_array', array(&$this, 'insertRewriteRules'));
}
/**
* do not insert
-Tags, remove
-Tags * @param string $content */ function wpautopnobr($content) { $result = wpautop($content, false); // remove p-Tags $offsetBegin = strpos($result, CONTENT_4_PARTNERS_BEGINTAG); $offsetEnd = strpos($result, CONTENT_4_PARTNERS_ENDTAG); if($offsetBegin !== false && $offsetEnd !== false){ $length = $offsetEnd - $offsetBegin + strlen(CONTENT_4_PARTNERS_ENDTAG); if ($length > 0) { $c4pContentOriginal = substr($result, $offsetBegin, $length); $c4pContent = substr($result, $offsetBegin, $length); $c4pContent = str_replace('
', '', $c4pContent); $c4pContent = str_replace('
', '', $c4pContent); $result = str_replace($c4pContentOriginal, $c4pContent, $result); } } return $result; } /** * This method is called when the shortcode [content4partners] is * found in any content. * * @param $attributes * @param $content */ function shortCodeContent4Partners($attributes, $content = null) { // aktiviere unseren eigenen Filter remove_filter('the_content', 'wpautop'); add_filter('the_content', array(&$this, 'wpautopnobr'), 99); $id = $this->getRegionId($attributes); // check again if (is_null($id)) { return "Keine Region ID angegeben."; } else { return $this->getContent($id); } } /** * Gets the content for given region id. * * @param $id the region id */ function getContent($id) { $useCache = $this->getCacheUse(); $key = CONTENT_4_PARTNERS_CACHE_KEY_PREFIX . $id; if ($useCache) { $content = get_transient($key); if ($content !== false && !empty($content)) { return $content; } } $content = CONTENT_4_PARTNERS_BEGINTAG; $content .= $this->getContentFromRegionId($id); $content .= CONTENT_4_PARTNERS_ENDTAG; if ($useCache && !empty($content)) { $cacheLifetime = $this->getCacheLifetime(); set_transient($key, $content, $cacheLifetime); } if (empty($content)) { $content = "Fehler beim Abrufen der Daten !"; } return $content; } /** * Grabs content for given url. * * @param $url * @return */ function getContentFromRegionId($regionId, $action = null) { $options = $this->getOptions(); if (CONTENT_4_PARTNERS_HOST == '') { // no valid host return ''; } if (!isset($action)) { $action = $options['action']; } $content = ''; $url = 'tcp://' . CONTENT_4_PARTNERS_HOST; $fp = fsockopen($url, CONTENT_4_PARTNERS_PORT, $errno, $errstr, 30); if (!$fp) { // TODO error handling ? return $content; } else { $get = CONTENT_4_PARTNERS_DIR . '/xml.php?namespace=' . $options['namespace'] . '&action=' . $action . '¶m[]=' . $options['user'] . '¶m[]=' . $options['password'] . '¶m[]=' . $regionId; if ($action == 'getPage') { $get .= '¶m[]=wordpress' . CONTENT_4_PARTNERS_VERSION; } fwrite($fp, "GET " . $get . " HTTP/1.0\r\nHost: " . CONTENT_4_PARTNERS_HOST . "\r\nAccept: */*\r\n\r\n"); $started = false; while (!feof($fp)) { $line = trim(fgets($fp, 1024)); if ($started) { $content .= $line . "\r\n"; } elseif (strlen($line) == 0) { $started = true; } } fclose($fp); // replace placeholders with page id $pageId = $this->getPageId(); if ($pageId !== false) { $content = preg_replace('|##page_id##|', $pageId, $content); } } return $content; } /** * Gets plugin options. * * @return plugin options */ function getOptions() { if (!isset($this->options)) { $this->options = get_option(CONTENT_4_PARTNERS_SETTINGS); } if (!is_array($this->options)){ $this->options = array(); } // check values $this->options['namespace'] = (isset($this->options['namespace']) ? $this->options['namespace'] : CONTENT_4_PARTNERS_NAMESPACE); $this->options['action'] = (isset($this->options['action']) ? $this->options['action'] : 'getPage'); $this->options['user'] = (isset($this->options['user']) ? $this->options['user'] : CONTENT_4_PARTNERS_USER); $this->options['password'] = (isset($this->options['password']) ? $this->options['password'] : CONTENT_4_PARTNERS_PASSWORD); $this->options['cache_use'] = (isset($this->options['cache_use']) ? $this->options['cache_use'] : CONTENT_4_PARTNERS_CACHE_USE); $this->options['cache_lifetime'] = (isset($this->options['cache_lifetime']) ? $this->options['cache_lifetime'] : CONTENT_4_PARTNERS_CACHE_LIFETIME); $this->options['acfpid'] = (isset($this->options['acfpid']) ? $this->options['acfpid'] : CONTENT_4_PARTNERS_DEFAULT_ID); $this->options['permalink_use'] = (isset($this->options['permalink_use']) ? $this->options['permalink_use'] : CONTENT_4_PARTNERS_PERMALINKS_USE); return $this->options; } /** * Gets lifetime of cache. * * @return cache lifetime */ function getCacheLifetime() { $options = $this->getOptions(); return intval($options['cache_lifetime']); } /** * Returns true if cache is enabled otherwise false. * * @return true if cache is enabled */ function getCacheUse() { $options = $this->getOptions(); if (array_key_exists('cache_use', $options)) { $useCache = $options['cache_use'] == '1' ? true : false; } return $useCache; } /** * Gets the region id, will check GET and POST and params array if supplied. * * @return region id */ function getRegionId($params = null) { $id = null; // check if parameter id is within get parameters if (array_key_exists('acfpid', $_GET)) { $id = $_GET['acfpid']; } elseif (array_key_exists('acfpid', $_POST)) { // check if parameter id is within post parameters $id = $_POST['acfpid']; } elseif (isset($params) && is_array($params) && array_key_exists('acfpid', $params)) { // check if parameter id is in attributes of shortcode $id = $params['acfpid']; } // check for default region id if (empty($id)) { $options = $this->getOptions(); $id = $options['acfpid']; } if (empty($id)) { $id = null; } return $id; } /** * Gets page id. * * @return page id */ function getPageId() { $id = false; $currentPage = get_page_by_title(get_the_title()); if (!is_null($currentPage)) { $id = $currentPage->ID; } if ($id === false) { $options = $this->getOptions(); if (array_key_exists('page_id', $options)) { $id = intval($options['page_id']); } } return $id; } /** * Gets the title for given region id. * * @param $id region id * @return title of region */ function getTitleForId($id) { return $this->getContentFromRegionId($id, 'getPageTitle'); } /** * Flushs cache. */ function flushCache() { global $wpdb; // delete entries from options table straight by sql query // cache keys match pattern "_transient*content_4_partners_$id" $query = " DELETE from " . $wpdb->options . " WHERE option_name like '%_transient%%content_4_partners_%'"; $wpdb->query($query); } /** * get partner by login and password * * returns true when login exists or false on error * if the result is false, the login is failed * * @param string $login * @param string $password * * @return boolean */ function loginExists($login, $password) { global $wpdb; global $wp_version; $options = $this->getOptions(); $loginResult = ''; $url = 'tcp://' . CONTENT_4_PARTNERS_HOST; $fp = fsockopen($url, CONTENT_4_PARTNERS_PORT, $errno, $errstr, 30); if (!$fp) { // TODO error handling ? return false; } else { $get = CONTENT_4_PARTNERS_DIR . '/xml.php?namespace=' . $options['namespace'] . '&action=login¶m[]=' . $login . '¶m[]=' . $password . '&NoCache=1'; fwrite($fp, "GET " . $get . " HTTP/1.0\r\nHost: " . CONTENT_4_PARTNERS_HOST . "\r\nAccept: */*\r\n\r\n"); $started = false; while (!feof($fp)) { $line = trim(fgets($fp, 1024)); if ($started) { $loginResult .= $line . "\r\n"; } elseif (strlen($line) == 0) { $started = true; } } fclose($fp); } if (strpos($loginResult, 'C4PP holds an automatic generated hotel page.
weitere Funktionen |
web.config file were writable, we could do this automatically, but it isn’t so this is the url rewrite rule you should have in your web.config file. Click in the field and press CTRL + a to select all. Then insert this rule inside of the /<configuration>/<system.webServer>/<rewrite>/<rules> element in web.config file.') ?>
web.config file writable for us to generate rewrite rules automatically, do not forget to revert the permissions after rule has been saved.') ?>
using_index_permalinks()) && !$writable) { ?>.htaccess file were writable, we could do this automatically, but it isn’t so these are the mod_rewrite rules you should have in your .htaccess file. Click in the field and press CTRL + a to select all.') ?>