Current File : /home/lifechur/carp-wp-2.0.9/carp-wp.php
<?php
/*
Plugin Name: CaRP/WP
Plugin URI: http://www.geckotribe.com/rss/carp/CaRP-WP/
Version: 2.0.9
Author: <a href="http://antone.geckotribe.com/alpha-gecko/">Antone Roundy</a>
Description: CaRP/WP is a WordPress plugin that, working with <a href="http://www.geckotribe.com/rss/carp/">CaRP</a>, enables you to display RSS feeds, including Amazon.com affiliate feeds and YouTube feeds, in your WordPress posts and pages.

CaRP/WP requires CaRP, which is NOT open source software.
YouTube features require CaRP Evolution 4.0 or higher.

http://www.geckotribe.com/rss/carp/

Copyright 2008-16 Antone Roundy (go-wordpress@geckotribe.com)

CaRP/WP is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, version 2 of the License.

This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.  See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this
program.  If not, see <http://www.gnu.org/licenses/>.
*/

$carp_wp_url = get_bloginfo('wpurl').'/wp-content/plugins/carp-wp/';
$carp_wp_admin_options_name = "carp_wp_plugin_admin_options";
$carp_wp_version = '2.0.9';
$carp_wp_options='';

function carp_wp_load_options($defaults=0) {
	global $carp_wp_options, $carp_wp_admin_options_name;
	if (is_array($carp_wp_options)) return $carp_wp_options;
	$carp_wp_options = array(
		'install_path'=>'',
		'theme'=>'carp-wp-theme.php',
		
		'youtube_theme'=>'carp-wp-youtube-theme.php',
		
		'widget_theme'=>'carp-wp-widget-theme.php',
		'default_widget_content'=>'',
		
		'error_types'=> array(
			'CaRP/WP Errors'=>1,
			'CaRP Errors'=>1,
			'PHP Errors'=>1
		),
		
		'wp_page_types' => array(
			'is_home' => array(
				'on' => 0,
				'label' => 'Homepage'),
			'is_single' => array(
				'on' => 1,
				'label' => 'Single Blog Post'),
			'is_author' => array(
				'on' => 0,
				'label' => 'Author Page'),
			'is_category' => array(
				'on' => 0,
				'label' => 'Category Archive'),
			'is_tag' => array(
				'on' => 0,
				'label' => 'Tag Archive'),
			'is_date' => array(
				'on' => 0,
				'label' => 'Date Archive'),
			'is_search' => array(
				'on' => 0,
				'label' => 'Search Results'),
			'is_feed' => array(
				'on' => 0,
				'label' => 'RSS/Atom Feeds'),
			'is_page' => array(
				'on' => 0,
				'label' => 'Page')
		),

		'amazon_associate_tag'=>'',
		'amazon_search_type'=>'popular',
		'amazon_threshold'=>5,
		'amazon_no_customer_tags'=>1
	);
	
	if (!$defaults) {
		$saved_options = get_option($carp_wp_admin_options_name);
		if (!empty($saved_options))
			foreach ($carp_wp_options as $key => $option) if (isset($saved_options[$key])) $carp_wp_options[$key]=$saved_options[$key];
	}
	
	return $carp_wp_options;
}


function carp_wp_print_admin_options() {
	include dirname(__FILE__).'/inc/admin.php';
}


if (!function_exists('carp_wp_admin_menu')) {
	function carp_wp_admin_menu() {
		if (function_exists('add_options_page')) {
			add_options_page('CaRP/WP', 'CaRP/WP', 9, basename(__FILE__), 'carp_wp_print_admin_options');
		}
	}
}


function carp_wp_error($msg) {
	global $carp_wp_options;
	carp_wp_load_options();
	return ($carp_wp_options['error_types']['CaRP/WP Errors']=='1')?"<br /><b>[CaRP/WP] $msg</b><br />":'';
}


$carp_wp_entities=array(
	'&#038;'=>'&amp;'
);


function carp_wp_content($content,$isWidget=0,$widget_before_title='',$widget_after_title='') {
	global $carp_wp_options,$carp_wp_url,$carpoutput,$youtubeconf,$carp_wp_entities,$carpversion,$carpconf;
	
	carp_wp_load_options();
	
	if (strpos($content,'[carpwp:')!==false) {
		$is_active=$isWidget ||
			((is_home() && ($carp_wp_options['wp_page_types']['is_home']['on']=='1')) ||
			(is_single() && ($carp_wp_options['wp_page_types']['is_single']['on']=='1')) ||
			(is_author() && ($carp_wp_options['wp_page_types']['is_author']['on']=='1')) ||
			(is_category() && ($carp_wp_options['wp_page_types']['is_category']['on']=='1')) ||
			(is_date() && ($carp_wp_options['wp_page_types']['is_date']['on']=='1')) ||
			(is_feed() && ($carp_wp_options['wp_page_types']['is_feed']['on']=='1')) ||
			(is_search() && ($carp_wp_options['wp_page_types']['is_search']['on']=='1')) ||
			(is_page() && ($carp_wp_options['wp_page_types']['is_page']['on']=='1'))
		);

		if (isset($carp_wp_options['install_path']{0})) {
			if (file_exists($carp_wp_options['install_path'])) {
				if (function_exists('carpconfreset')) MyCarpConfReset();
				else include_once $carp_wp_options['install_path'];
				$carpconf['widget_before_title']=$widget_before_title;
				$carpconf['widget_after_title']=$widget_after_title;
				CarpConf('outputformat', 2);
				$carpoutput='';
				CarpConf('carperrors',($carp_wp_options['error_types']['CaRP Errors']=='1')?2:0);
				CarpConf('phperrors',($carp_wp_options['error_types']['PHP Errors']=='1')?(E_ERROR|E_WARNING|E_PARSE):0);
				CarpConf('encodingout', get_bloginfo('charset'));
				
				if (isset($carp_wp_options[$isWidget?'widget_theme':'theme']{0})) CarpLoadTheme($carp_wp_options[$isWidget?'widget_theme':'theme']);
				
				$aggregate=array();
				
				if (isset($carpoutput{0})) {
					$content.="<br /><b>$carpoutput</b><br />";
					$carpoutput='';
				}
				for ($i=strpos($content,'[carpwp:'), $j=strlen($content); ($i<$j) && ($i!==false); $i=strpos($content,'[carpwp:', $i)) {
					$end=strpos($content,'[/carpwp]',$i);
					if ($end==FALSE) {
						$content.=carp_wp_error('ERROR: End tag ([/carpwp]) not found.');
						break;
					}
					$len=$end+9-$i;
					
					if ($is_active) {
						$ip8=$i+8;
						$cbsp=strpos($content,'{',$ip8);
						if ($cbsp==FALSE) {
							$content.=carp_wp_error('ERROR: "{" not found after command name.');
							break;
						}
						$cmd=substr($content,$ip8,$cbsp-$ip8);
						$ebp=strpos($content,'}',$cbsp+2)+1;
						if ($ebp==1) {
							$content.=carp_wp_error('ERROR: "}" not found after command parameter.');
							break;
						}
						$val=@html_entity_decode(strtr(substr($content,$cbsp+1,$ebp-($cbsp+2)),$carp_wp_entities),ENT_QUOTES,$charset);
						if (isset($val{0})) {
							$confs=explode("\n",preg_replace("#<(/p|br)\\b[^>]*>[\r\n]+#","\n",
								@html_entity_decode(strtr(substr($content,$ebp+1,$end-$ebp-1),$carp_wp_entities),ENT_QUOTES,$charset)));
							if (substr($cmd,0,7)=='youtube') {
								CarpLoadPlugin('youtube.php');
								CarpLoadTheme($carp_wp_options['youtube_theme']);
							}
							if (is_array($confs)) foreach ($confs as $conf) if (strpos($conf,'=')) {
								list($k,$v)=explode('=',$conf,2);
								$k=preg_replace('/^<[^>]*>/','',$k);
								if ($k=='feed') {
									$tq=strpos($v,'}',1);
									$url=substr($v,1,$tq-1);
									$v=substr($v,$tq+1);
									$cache=$val.'-'.md5($url);
									if (($fc=strpos($v,','))!==false) $aggregate[$url]=array($cache, trim(substr($v,$fc+1)));
									else $aggregate[$url]=$cache;
								} else if ($k=='theme') CarpLoadTheme(trim($v));
								else if (substr($k,0,7)=='amazon_') $carp_wp_options[$k]=$v;
								else if (substr($k,0,8)=='youtube-') $youtubeconf[substr($k,8)]=$v;
								else CarpConf($k,$v);
								if (isset($carpoutput{0})) {
									$content.="<br /><b>$carpoutput</b><br />";
									$carpoutput='';
								}
							}
							
							switch($cmd) {
							case 'feed': CarpCacheShow($val); break;
							case 'aggregate':
							case 'interleave':
								if (count($aggregate)) {
									$caches=CarpGroupFilter($aggregate);
									if (($cmd=='aggregate')||(floor($carpversion{0})<4)) CarpAggregate($caches);
									else CarpInterleave($caches);
								} else $carpoutput='<br />[CaRP/WP] Error: No feeds specified.<br />';
								break;
							case 'amazon':
								CarpConfAdd('descriptiontags', '|br|img|a|/a');
								CarpConf('iorder','desc');
								if ($carp_wp_options['amazon_no_customer_tags']) {
									CarpLoadPlugin('replacetext.php');
									ReplaceTextConf2(1,'desc',1,'Customer tags.*$','');
								}
								$query='http://www.amazon.com/rss/tag/'.str_replace('+','%20',urlencode($val)).
									'/'.$carp_wp_options['amazon_search_type'].'?tag='.urlencode($carp_wp_options['amazon_associate_tag']).
									'&threshold='.$carp_wp_options['amazon_threshold'].'&length='.max($carpconf['maxitems'],8);
								CarpCacheShow($query);
								break;
							case 'youtube-tag':
								CarpCacheShow('http://www.youtube.com/rss/tag/'.urlencode($val).'.rss');
								break;
							case 'youtube-user':
								CarpCacheShow('http://www.youtube.com/rss/user/'.urlencode($val).'/videos.rss');
								break;
							default:
								$content.=carp_wp_error("Error: Unknown command: $cmd.");
							}
						} else $content.=carp_wp_error("Error: No argument specified to $cmd.");
					} else $carpoutput='';
					$content=substr($content,0,$i).$carpoutput.substr($content,$i+$len);

					$i+=($cl=strlen($carpoutput));
					$j+=$cl-$len;
					$carpoutput='';
				}
			} else $content.=carp_wp_error('ERROR: "carp.php" not found at the location indicated. Please check your configuration.');
		} else $content.=carp_wp_error('ERROR: Path to "carp.php" not indicated. Please complete your configuration.');
	}
	return $content;
}

function carp_wp_widget($args) {
	global $posts;
	$content=is_single()?get_post_meta($posts[0]->ID,'carpwp',true):'';
	if (!isset($content{0})) {
		global $carp_wp_options;
		carp_wp_load_options();
		$content=$carp_wp_options['default_widget_content'];
	}
	if (isset($content{0})) {
		extract($args);
        echo $before_widget;
		echo $content=carp_wp_content($content,1,$before_title,$after_title);
		echo $after_widget;
	}
}

function carp_wp_init() {
	if (!function_exists("register_sidebar_widget")) return;
	register_sidebar_widget('CaRP/WP', 'carp_wp_widget');
}

add_action('activate_carp-wp/carp-wp.php', 'carp_wp_load_options');
add_action('admin_menu', 'carp_wp_admin_menu');
add_filter('the_content', 'carp_wp_content');
add_action('plugins_loaded', 'carp_wp_init');

return;
?>