Files
roi-theme/wp-content/plugins/rss-feed/functions.php
root a22573bf0b Commit inicial - WordPress Análisis de Precios Unitarios
- WordPress core y plugins
- Tema Twenty Twenty-Four configurado
- Plugin allow-unfiltered-html.php simplificado
- .gitignore configurado para excluir wp-config.php y uploads

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-03 21:04:30 -06:00

836 lines
31 KiB
PHP
Executable File

<?php
function get_included_categories($categories)
{
$all_cat=array();
foreach($categories as $cat)
{
$parents2=get_parents_list($cat);
foreach($parents2 as $p)
if(!in_array($p,$all_cat))
$all_cat[]=$p;
}
return $all_cat;
}
function get_parents_list($cat)
{
global $table_prefix,$db;
$taxonomy=$db->db_selectOne($table_prefix."term_taxonomy","parent","taxonomy='category' and term_id=".$cat);
$parents=array();
if($taxonomy!==false)
{
if($taxonomy["parent"]!=0)
{
$parents2=get_parents_list($taxonomy["parent"]);
foreach($parents2 as $p)
$parents[]=$p;
}
}
else
die("cateory not found:".$cat);
$parents[]=$cat;
return $parents;
}
function sub_string_max($str,$max=100)
{
if(strlen($str)>$max)
return "<p title='".mb_convert_encoding($str, 'ISO-8859-1', 'UTF-8')."'>".mb_convert_encoding(substr($str,0,$max, 'ISO-8859-1', 'UTF-8'))."...</p>";
return "<p>".mb_convert_encoding($str, 'ISO-8859-1', 'UTF-8')."</p>";
}
function get_cat_tree($curParent=0)
{
global $table_prefix,$db;
$categories=array();
$taxonomy=$db->db_select($table_prefix."term_taxonomy","term_taxonomy_id ,term_id,taxonomy","taxonomy='category' and parent=".$curParent);
if($taxonomy!==false)
foreach($taxonomy as $t)
{
$cat=$db->db_selectOne($table_prefix."terms","term_id,name","term_id='".$t["term_id"]."'");
if($cat!==false)
$categories[]=array("id"=>$cat["term_id"],"title"=>htmlentities($cat["name"]),"childs"=>get_cat_tree($t["term_taxonomy_id"]));
}
return $categories;
}
function xml_str_encode($str)
{
return str_replace("&","&amp;",str_replace("&amp;","&",str_replace("&#39;","'",mb_convert_encoding(strip_tags(str_replace("</p>","<br>",$str, 'ISO-8859-1', 'UTF-8'),"<br>")))));
}
function xml_str($str)
{
return "<![CDATA[ ".str_replace("&","&amp;",str_replace("&amp;","&",str_replace("&#39;","'",html_entity_decode(strip_tags(str_replace("</p>","<br>",$str),"<br>")))))." ]]>";
}
function xml_str2($str)
{
return "<![CDATA[ ".str_replace("&","&amp;",str_replace("&amp;","&",str_replace("&#39;","'",mb_convert_encoding(strip_tags(str_replace("</p>","<br>",$str, 'ISO-8859-1', 'UTF-8'),"<br>")))))." ]]>";
}
function xml_str0($str)
{
return "<![CDATA[ ".strip_tags(str_replace("</p>","<br>",$str),"<p><br>")." ]]>";
}
function display_cat_tree($categories_lis,$field,$level=0)
{
if($level==0)
{
echo '<ul class="cat-checklist category-checklist">';
}
else
echo ' <ul class="children" style="margin-left:20px">';
foreach($categories_lis as $cat)
{
if(in_array($cat["id"],explode(",",$field["value"])))
$checked="checked='checked'";
else
$checked='';
?>
<li id='category-<?php echo $cat["id"];?>' class="popular-category">
<label class="selectit"><input value="<?php echo $cat["id"];?>" type="checkbox" name="<?php echo $field["name"];?>[]" id="in-category-<?php echo $cat["id"];?>" <?php echo $checked;?> /> <?php echo $cat["title"];?></label>
<?php
if(sizeof($cat["childs"])>0)
{
display_cat_tree($cat["childs"],$field,$level+1);
}
}
echo "</ul>";
}
function display_cat_select($categories_lis,$field,$level=0)
{
if($level==0)
echo "<select name='".$field["name"]."' id='".$field["name"]."' class='postform' >
<option value='0'>All Categories</option>";
foreach($categories_lis as $cat)
{
if($cat["id"]==$field["value"])
$checked="selected='selected'";
else
$checked='';
?>
<option class="level-<?php echo $level;?>" value="<?php echo $cat["id"];?>" <?php echo $checked;?>>
<?php for($i=0;$i<$level;$i++) echo "&nbsp;&nbsp;&nbsp;"; echo $cat["title"];?></option>
<?php
if(sizeof($cat["childs"])>0)
{
display_cat_select($cat["childs"],$field,$level+1);
}
}
if($level==0)
echo "</select>";
}
function get_m_template($template_name)
{
if(defined("AUTOSERVICES__PLUGIN_DIR"))
return file_get_contents(AUTOSERVICES__PLUGIN_DIR."templates/".$template_name.".php");
else
return file_get_contents("templates/".$template_name.".php");
}
function get_extension($str)
{
/*$array = explode('.', $str);
$extension = end($array);*/
return strtolower(pathinfo($str, PATHINFO_EXTENSION));
}
function seo_string($string, $separator = '-')
{
$string = preg_replace("`\[.*\]`U","",$string);
$string = preg_replace('`&(amp;)?#?[a-z0-9]+;`i',$separator,$string);
$string = htmlentities($string, ENT_COMPAT, 'utf-8');
$string = preg_replace( "`&([a-z])(acute|uml|circ|grave|ring|cedil|slash|tilde|caron|lig|quot|rsquo);`i","\\1", $string );
$string = preg_replace( array("`[^a-z0-9]`i","`[-]+`") , $separator, $string);
return strtolower(trim($string, $separator));
return $string;
}
function display_html_content($str)
{
$str=nl2br(htmlentities($str));
$str=str_replace("&lt;/div&gt;","&lt;/div&gt;<br>",$str);
$str=str_replace("&lt;/p&gt;","&lt;/p&gt;<br>",$str);
$str=str_replace("&lt;/tr&gt;","&lt;/tr&gt;<br>",$str);
$str=str_replace("&lt;/table&gt;","&lt;/table&gt;<br>",$str);
$str=str_replace("&lt;html&gt;","&lt;html&gt;<br>",$str);
$str=str_replace("&lt;body&gt;","&lt;body;<br>",$str);
$str=str_replace("&lt;/head&gt;","&lt;/head&gt;<br>",$str);
$str=str_replace("&lt;/form&gt;","&lt;/form&gt;<br>",$str);
$str=str_replace("&lt;form&gt;","<br>&lt;form&gt;",$str);
$str=str_replace("&lt;script&gt;","<br>&lt;script&gt;",$str);
$str=str_replace("&lt;/script&gt;","&lt;/script&gt;<br>",$str);
$str=str_replace("&lt;/ul&gt;","&lt;/ul&gt;<br>",$str);
return $str;
}
function ago($timestamp){
if($timestamp==0)
return "Non";
$difference = time() - $timestamp;
$periods = array("second", "minute", "heure", "jour", "semaine", "mois", "years", "decade");
$lengths = array("60","60","24","7","4.35","12","10");
for($j = 0; $difference >= $lengths[$j]; $j++)
$difference /= $lengths[$j];
$difference = round($difference);
if($j>=4)
return date("m/d/Y",$timestamp);
if($difference != 1) $periods[$j].= "s";
$text = "$difference $periods[$j]";
return $text;
}
function sec2hms ($sec, $padHours = false)
{
$hms = "";
$hours = intval(intval($sec) / 3600);
$hms .= ($padHours)
? str_pad($hours, 2, "0", STR_PAD_LEFT). ":"
: $hours. ":";
$minutes = intval(($sec / 60) % 60);
$hms .= str_pad($minutes, 2, "0", STR_PAD_LEFT). ":";
$seconds = intval($sec % 60);
$hms .= str_pad($seconds, 2, "0", STR_PAD_LEFT);
return $hms;
}
function get_proc ($request_url,$context)
{
$curl = curl_init() ;
curl_setopt( $curl , CURLOPT_URL , $request_url ) ;
curl_setopt( $curl , CURLOPT_HEADER, 1 ) ;
curl_setopt( $curl , CURLOPT_CUSTOMREQUEST , $context['http']['method'] ) ;
curl_setopt( $curl , CURLOPT_SSL_VERIFYPEER , false ) ;
curl_setopt( $curl , CURLOPT_RETURNTRANSFER , true ) ;
curl_setopt( $curl , CURLOPT_HTTPHEADER , $context['http']['header'] ) ;
curl_setopt( $curl , CURLOPT_TIMEOUT , 5 ) ;
$res1 = curl_exec( $curl ) ;
$res2 = curl_getinfo( $curl ) ;
curl_close( $curl ) ;
$str_json = substr( $res1, $res2['header_size'] ) ;
// echo $str_json . "\n";
return $str_json;
}
function get_twitter_details($name)
{
$tries=0;
$dict_aa[0]=array();
$bearer_token = 'AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA' ;
$request_url = 'https://api.twitter.com/1.1/users/lookup.json' ;
$params = array(
"screen_name" => $name,
"stringify_ids" => "true",
"count" => 1,
);
if( $params ) {
$request_url .= '?' . http_build_query( $params ) ;
}
$context = array(
'http' => array(
'method' => 'GET' ,
'header' => array(
'Authorization: Bearer ' . $bearer_token ,
) ,
) ,
) ;
if($tries<3 && !isset($dict_aa[0]["description"]))
{
$tries++;
sleep(1);
$str_json = get_proc ($request_url,$context);
$dict_aa = json_decode ($str_json,true);
}
return $dict_aa;
}
function random_user_agent_mobile() {
return "User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0";
return "Mozilla/5.0 (Linux; Android 7.0; SM-G930V Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.125 Mobile Safari/537.36";
}
function random_user_agent() {
// return random_user_agent_mobile();
return "User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0";
$browser_freq = array (
"Internet Explorer" => 24.3
);
$browser_strings = array (
"Internet Explorer" => array (
"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)",
"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)",
"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/5.0)",
"Mozilla/4.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/5.0)",
"Mozilla/1.22 (compatible; MSIE 10.0; Windows 3.1)",
"Mozilla/5.0 (Windows; U; MSIE 9.0; WIndows NT 9.0; en-US))",
"Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US)",
"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 7.1; Trident/5.0)",
"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; Media Center PC 6.0; InfoPath.3; MS-RTC LM 8; Zune 4.7)",
"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; Media Center PC 6.0; InfoPath.3; MS-RTC LM 8; Zune 4.7",
"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Zune 4.0; InfoPath.3; MS-RTC LM 8; .NET4.0C; .NET4.0E)",
"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 2.0.50727; Media Center PC 6.0)",
"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 2.0.50727; Media Center PC 6.0)",
"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0; .NET CLR 2.0.50727; SLCC2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Zune 4.0; Tablet PC 2.0; InfoPath.3; .NET4.0C; .NET4.0E)",
"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0",
"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; chromeframe/11.0.696.57)",
"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0) chromeframe/10.0.648.205",
"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0; Trident/5.0; chromeframe/11.0.696.57)",
"Mozilla/5.0 ( ; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)",
"Mozilla/4.0 (compatible; MSIE 9.0; Windows NT 5.1; Trident/5.0)",
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 7.1; Trident/5.0; .NET CLR 2.0.50727; SLCC2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C)",
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; AskTB5.5)",
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; InfoPath.2; .NET4.0C; .NET4.0E)",
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Win64; x64; Trident/5.0; .NET CLR 2.0.50727; SLCC2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C)",
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; FDM; .NET CLR 1.1.4322; .NET4.0C; .NET4.0E; Tablet PC 2.0)",
"Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0; Media Center PC 4.0; SLCC1; .NET CLR 3.0.04320)",
"Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; SLCC1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 1.1.4322)",
"Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; InfoPath.2; SLCC1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 2.0.50727)",
"Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727)",
"Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 5.0; Trident/4.0; InfoPath.1; SV1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 3.0.04506.30)",
"Mozilla/5.0 (compatible; MSIE 7.0; Windows NT 5.0; Trident/4.0; FBSMTWB; .NET CLR 2.0.34861; .NET CLR 3.0.3746.3218; .NET CLR 3.5.33652; msn OptimizedIE8;ENUS)",
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.2; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)",
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; Media Center PC 6.0; InfoPath.2; MS-RTC LM 8)",
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; Media Center PC 6.0; InfoPath.2; MS-RTC LM 8",
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; Media Center PC 6.0; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C)",
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; InfoPath.3; .NET4.0C; .NET4.0E; .NET CLR 3.5.30729; .NET CLR 3.0.30729; MS-RTC LM 8)",
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; InfoPath.2)",
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Zune 3.0)",
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; msn OptimizedIE8;ZHCN)",
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; MS-RTC LM 8; InfoPath.3; .NET4.0C; .NET4.0E) chromeframe/8.0.552.224",
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; MS-RTC LM 8; .NET4.0C; .NET4.0E; Zune 4.7; InfoPath.3)",
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; MS-RTC LM 8; .NET4.0C; .NET4.0E; Zune 4.7)",
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; MS-RTC LM 8)",
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; Zune 4.0)",
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; .NET4.0E; MS-RTC LM 8; Zune 4.7)",
)
);
$max=0;
$roll=0;
$rcount=0;
$roll=0;
$browser_type=0;
foreach($browser_freq as $k=>$v) $max += $v;
$roll = rand(0,$max);
foreach($browser_freq as $k=>$v) if (($roll <= ($rcount += $v)) and (!$browser_type)) $browser_type = $k;
$user_agent_array = $browser_strings[$browser_type];
shuffle($user_agent_array);
$user_agent = $user_agent_array[0];
return $user_agent;
}
function get_random_referrer()
{
$ref=array("http://www.google.com/","","http://google.com/","http://facebook.com/","http://www.facebook.com/","http://yahoo.com/","http://www.yahoo.com/","http://google.fr/","http://yahoo.fr/","http://google.es/","http://www.yahoo.com/","http://msn.com/","http://bing.com/","http://hotmail.com/","http://www.bing.com/","http://yahoo.com/","http://yahoo.com/","http://yahoo.com/","http://yahoo.com/","http://yahoo.com/");
$rand_key = array_rand($ref, 1);
return $ref[$rand_key];
}
function delete_spaces($content)
{
//return preg_replace("![\s\t\n\r]+!", " ", $content);
$content=str_replace("\n","<br>",$content);
$content=str_replace("\r"," ",$content);
$content=str_replace("\t"," ",$content);
return $content;
}
function get_google_feed($row)
{
$scraper=new curlManager();
$row["content"]=$scraper->getContent($row["url"]);
$xml=simplexml_load_string($row["content"]) or die("Error: the url doesn't content a valid xml data.<br>
<a href='".$row["url"]."' target='_blank'>".$row["url"]."</a>");
if(!isset($xml->title))
die("Error: the url doesn't content a valid xml data.<br>
<a href='".$row["url"]."' target='_blank'>".$row["url"]."</a>");
$str='<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">';
$str.="<channel>";
if($row["name"]=="")
$row["name"]=strip_tags($xml->title);
if($row["description"]=="")
$row["description"]=$row["name"];
$str.="<title>".xml_str($row["name"])."</title>";
$str.="<description>".xml_str($row["description"])."</description>";
$str.="<link>".feed_url($row["url"])."</link>";
$str.="<generator>".feed_url($row["domain_link"])."</generator>";
$str.="<lastBuildDate>".gmdate("D, d M Y H:i:s")." GMT</lastBuildDate>";
$str.='<atom:link href="'.$row["actual_link"].'" rel="self" type="application/rss+xml"/>';
$str.='<language>'.xml_str("es").'</language>';
$found=0;
foreach($xml->entry as $entry)
{
$tab=explode("url=",$entry->link["href"]);
if(!isset($tab[1]))
$url=$entry->link["href"];
else
{
$url=$tab[1];
$tabs2=explode("&",$url);
if(isset($tabs2[1]))
$url=$tabs2[0];
else
$url=$url;
}
$url=urldecode($url);
$url_dump=parse_url($url);
$cnt=$scraper->getContent($url);
$row["nb_analyse"]--;
if($row["nb_analyse"]==-1)
break;
if($cnt!="error")
{
$domain=get_domain_name($url_dump["host"]);
$row["domain"]=trim($row["domain"]);
if($row["domain"]!="" && !preg_match('|'.$row["domain"].'|i', $url, $rowd))
continue;
$img=get_image($cnt);
if($domain!="facebook" && $domain!="twitter")
if(!preg_match('|\:\/\/|i', $img, $row0))
continue;
if(preg_match('|\.png|i', $img, $row0))
$type="image/png";
else
$type="image/jpeg";
$str.='<item>';
$str.="<title>".xml_str($entry->title)."</title>";
$str.="<description>".xml_str($entry->content)."</description>";
$str.="<link>".feed_url($url)."</link>";
$str.='<guid isPermaLink="false">'.feed_url($url).'</guid>';
$str.="<dc:creator><![CDATA[ ".$domain." ]]></dc:creator>";
$str.="<pubDate>".gmdate("D, d M Y H:i:s",strtotime($entry->published))." GMT</pubDate>";
if($img)
$str.='<enclosure url="'.feed_url($img).'" length="0" type="'.$type.'" />';
$str.='</item>';
$row["nb_items"]--;
$found++;
if($row["nb_items"]==0)
break;
}
}
$str.="</channel>";
$str.="</rss>";
$scraper->close();
$row["content2"]=$str;
return $row;
}
function get_twitter_feed($row)
{
$tab=explode(".com/",$row["url"]);
if(!isset($tab[1]))
die("Error:url is not valid twitter page");
$tab=explode("/",$tab[1]);
$tab=explode("?",$tab[0]);
$_REQUEST["url"]="https://www.twitter.com/".$tab[0];
$dict_aa=get_twitter_details($tab[0]);
if(!isset($dict_aa[0]["description"]))
die("can't find description please by sure that you anetr a valid public twitter url.<br> If the url ".$row["url"]." is valid please try again ");
$title=$dict_aa[0]["screen_name"];
$desc=$dict_aa[0]["description"];
if($row["name"]=="")
$row["name"]=strip_tags($title);
if($row["description"]=="")
$row["description"]=$desc;
$row["url"]=$_REQUEST["url"];
$i=0;
$str='<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">';
$str.="<channel>";
$str.="<title>".xml_str0($row["name"])."</title>";
$str.="<description>".xml_str0($row["description"])."</description>";
$str.="<link>".feed_url($row["url"])."</link>";
$str.="<generator>".feed_url($row["domain_link"])."</generator>";
$str.="<lastBuildDate>".gmdate("D, d M Y H:i:s")." GMT</lastBuildDate>";
$str.='<atom:link href="'.$row["actual_link"].'" rel="self" type="application/rss+xml"/>';
$str.='<language>'.xml_str("es").'</language>';
$found=0;
$items=get_tweets($row,$tab[0]);
foreach($items as $item)
{
$item["full_text"]=remove_emoji(str_replace("\n","<br>",$item["full_text"]));
$str.='<item>';
$str.="<title>".xml_str0(extract_title($item["full_text"]))."</title>";
$str.="<description>".xml_str0($item["full_text"])."</description>";
$str.="<link>".feed_url(str_replace("touch","www",$item["url"]))."</link>";
$str.='<guid isPermaLink="false">https://twitter.com/i/web/status/'.$item["post_id"].'</guid>';
$str.="<dc:creator><![CDATA[ ".$item["creator"]." ]]></dc:creator>";
$str.="<pubDate>".gmdate("D, d M Y H:i:s",$item["time"])." GMT</pubDate>";
if($item["image"])
$str.='<media:content url="'.feed_url($item["image"]).'" medium="image" />';
$str.='</item>';
$row["nb_items"]--;
$found++;
if($row["nb_items"]==0)
break;
}
$str.="</channel>";
$str.="</rss>";
$row["content2"]=$str;
return $row;
}
function get_tweets($row,$name)
{
$dict_aa[0]=array();
$tries=0;
$bearer_token = 'AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA' ;
$request_url = 'https://api.twitter.com/1.1/statuses/user_timeline.json' ;
$params = array(
"screen_name" => $name,
"tweet_mode" => "extended",
"count" => $row["nb_analyse"],
);
if( $params ) {
$request_url .= '?' . http_build_query( $params ) ;
}
$context = array(
'http' => array(
'method' => 'GET' ,
'header' => array(
'Authorization: Bearer ' . $bearer_token ,
) ,
) ,
) ;
if($tries<3 && !isset($dict_aa[0]["text"]))
{
$tries++;
sleep(1);
$str_json = get_proc ($request_url,$context);
$dict_aa = json_decode ($str_json,true);
}
foreach($dict_aa as $item)
{
$url="https://twitter.com/i/web/status/".$item["id"];
if(isset($item["entities"]["urls"]) && isset($item["entities"]["urls"][0]["expanded_url"]))
{
$url=$item["entities"]["urls"][0]["expanded_url"];
}
$pict="";
if(isset($item["entities"]["media"]) && isset($item["entities"]["media"][0]["media_url"]))
{
$pict=$item["entities"]["media"][0]["media_url"];
}
$items[]=array("creator"=>$name,"time"=>strtotime($item["created_at"]),"post_id"=>$item["id"],"full_text"=>$item["full_text"],"image"=>$pict,"url"=>$url);
}
return $items;
}
function get_fcebook_feed($row)
{
$scraper=new curlManager();
$tab=explode(".com/",$row["url"]);
if(!isset($tab[1]))
die("Error:url is not valid facebook page");
$tab=explode("/",$tab[1]);
$tab=explode("?",$tab[0]);
$row["url"]="https://touch.facebook.com/pg/".$tab[0]."/posts";
$content=delete_spaces($scraper->getContent($row["url"]));
if(!preg_match('|<title>(.*?)</(.*?)name="description" content="(.*?)"|i', $content, $rowd))
die("Error: page url is not valid or not public");
if($row["name"]=="")
$row["name"]=utf8_encode(strip_tags($rowd[1]));
if($row["description"]=="")
$row["description"]=utf8_encode($rowd[3]);
if(!preg_match('|see_more_cards_id",href:"(.*?)"|i', $content, $rowd))
die("Error: page url is not valid or not public.<br> can't find see_more_cards_id");
$nb_posts=$row["nb_analyse"];
if(!preg_match('|page_id=(.*?)\&|i', $rowd[1], $rowd0))
die("Error: page url is not valid or not public.<br> can't find see_more_cards_id");
$page_id=$rowd0[1];
$page_url_id="https://www.facebook.com/".$page_id."/posts/";
$rowd[1]=str_replace("num_to_fetch=4","num_to_fetch=".$nb_posts,$rowd[1]);
$url="https://touch.facebook.com/".$rowd[1];
//touch.facebook.com//page_content_list_view/more/?page_id=536742113101486&start_cursor=0%7B%22timeline_cursor%22%3A%22AQHRvJntZcK-dQHoKIfaGJVKF7iENv5h5Riga2F59YvReUBWa0Mml3o_5ntVmJepDFD1X2CL8qAJ_H8-JiX6FD08VArBa87EVNirc-h9nxTbdgZDHQ5mQhtcczjPoQ2L_gg2%22%2C%22timeline_section_cursor%22%3Anull%2C%22has_next_page%22%3Atrue%7D&num_to_fetch=20&surface_type=posts_tab
$cnt=$scraper->getContent($url);
$json=json_decode(trim(str_replace("for (;;);","",$cnt)));
if(!isset($json->payload))
die("Error: page url is not valid or not public.<br> can't find payload");
if(!isset($json->payload->actions))
die("Error: page url is not valid or not public.<br> can't find payload->actions");
if(!isset($json->payload->actions[0]->html))
die("Error: page url is not valid or not public.<br> can't find payload->actions[0]->html");
$posts_ids=array();
if(preg_match_all('|C-R">(.*?)<(.*?)<abbr>(.*?)</(.*?)story_fbid=(.*?)\&|i', $content." ".$json->payload->actions[0]->html, $rows))
{
foreach($rows[1] as $k=>$v)
{
if(in_array($rows[5][$k],$posts_ids))
continue;
$posts_ids[]=$rows[5][$k];
$url=$page_url_id.$rows[5][$k];
/*$cntn=$scraper->getContent($url);
if(!preg_match('|</header>(.*?)</div></div>(.*?)<footer|i', $cntn, $out))
die("can't find content in the post:". $item["url"]);
$cnt=strip_tags($out[1], '<br><p>');
$img="";
if(preg_match('|background-image: url\(\&\#039;(.*?)\&\#03|i', $cntn, $out2))
$img=urldecode(str_replace(" ","",str_replace("\\","%",$out2[1])));
$items[]=array("creator"=>$rows[1][$k],"time"=>convert_fb_time($rows[3][$k]),"url"=>$page_url_id.$rows[5][$k],"content"=>$cnt,"img"=>$img,"post_id"=>$rows[5][$k]);*/
$items[]=array("creator"=>$rows[1][$k],"time"=>convert_fb_time($rows[3][$k]),"url"=>$url,"post_id"=>$rows[5][$k]);
}
}
usort($items,"cmp_raj_time");
$i=0;
$str='<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">';
$str.="<channel>";
$str.="<title>".xml_str0($row["name"])."</title>";
$str.="<description>".xml_str0($row["description"])."</description>";
$str.="<link>".feed_url($row["url"])."</link>";
$str.="<generator>".feed_url($row["domain_link"])."</generator>";
$str.="<lastBuildDate>".gmdate("D, d M Y H:i:s")." GMT</lastBuildDate>";
$str.='<atom:link href="'.$row["actual_link"].'" rel="self" type="application/rss+xml"/>';
$str.='<language>'.xml_str("es").'</language>';
$found=0;
foreach($items as $item)
{
$row["nb_analyse"]--;
if($row["nb_analyse"]==-1)
break;
$cntn=delete_spaces($scraper->getContent($item["url"]));
$img="";
if(preg_match('|property="og:image" content="(.*?)"|i', $cntn, $out))
$img=urldecode(str_replace(" ","",str_replace("\\","%",$out[1])));
if(!preg_match('|posts/'.$item["post_id"].'"><i(.*?)<noscript|i', $cntn, $out))
{
if(preg_match('|property="og:description" content="(.*?)"|i', $cntn, $out2))
$desc=$out2[1];
else
die("can't find content in the post:". $item["url"]);
}
else
$desc="<i ".$out[1];
$cnt=str_replace("See more","",strip_tags($desc, '<br><p>'));
$cnt=str_replace("?","_-_",$cnt);
$cnt=mb_convert_encoding($cnt, 'ISO-8859-1', 'UTF-8');
$cnt=str_replace("?","",$cnt);
$cnt=str_replace("_-_","?",$cnt);
$str.='<item>';
$str.="<title>".xml_str0(extract_title($cnt))."</title>";
$str.="<description>".xml_str0($cnt)."</description>";
$str.="<link>".feed_url($item["url"])."</link>";
$str.='<guid isPermaLink="false">https://www.facebook.com/'.$page_id.'_'.$item["post_id"].'</guid>';
$str.="<dc:creator><![CDATA[ ".$item["creator"]." ]]></dc:creator>";
$str.="<pubDate>".gmdate("D, d M Y H:i:s",$item["time"])." GMT</pubDate>";
if($img)
$str.='<media:content url="'.feed_url($img).'" medium="image" />';
$str.='</item>';
$row["nb_items"]--;
$found++;
if($row["nb_items"]==0)
break;
}
$str.="</channel>";
$str.="</rss>";
$scraper->close();
$row["content2"]=$str;
return $row;
}
function convert_fb_time($date)
{
$hours["hrs"]=$hours["hr"]=$hours["h"]=3600;
$hours["mins"]=$hours["min"]=$hours["m"]=60;
$hours["seconds"]=$hours["second"]=$hours["secs"]=$hours["sec"]=$hours["s"]=1;
$tab=explode(" at ",$date);
if(!isset($tab[1]))
{
$tab=explode(" ",$date);
if(!isset($hours[trim($tab[1])]))
die("invalid date time ".$date);
$seconds_ago=$hours[trim($tab[1])] * (int) $tab[0];
return (time()-$seconds_ago);
}
$day=$tab[0];
$hour=$tab[1];
$tabs2=explode(" ",$day);
if(sizeof($tabs2)==2)
$day.=" ".date("Y");
$date=$day." ".$hour;
return strtotime($date);
}
function feed_url($url)
{
return str_replace("&","&amp;",str_replace("&amp;","&",$url));
}
function get_domain_name($str)
{
$tab=explode(".",trim(strtolower($str)));
if(isset($tab[3]))
return $tab[2];
if(isset($tab[2]))
return $tab[1];
return $str;
}
function get_image($cnt)
{
$cnt=str_replace("'",'"',$cnt);
$cnt=str_replace(" =",'=',$cnt);
$cnt=str_replace("= ",'=',$cnt);
$cnt=str_replace("twitter:image","og:image",$cnt);
if(preg_match('|og\:image(.*?) content="(.*?)"|i', $cnt, $row))
{
return $row[2];
}
return "";
}
function cmp_raj_time($a, $b)
{
return strcmp($b["time"], $a["time"]);
}
function extract_title($cntn)
{
$tab=explode("\n",$cntn);
$tab=explode("</p",$tab[0]);
$tab=explode("<br",$tab[0]);
$tab=explode(".",$tab[0]);
if(strlen($tab[0])>120)
return substr($tab[0],0,117)."...";
return $tab[0];
}
function remove_emoji($string) {
// Match Emoticons
$regex_emoticons = '/[\x{1F600}-\x{1F64F}]/u';
$clear_string = preg_replace($regex_emoticons, '', $string);
// Match Miscellaneous Symbols and Pictographs
$regex_symbols = '/[\x{1F300}-\x{1F5FF}]/u';
$clear_string = preg_replace($regex_symbols, '', $clear_string);
// Match Transport And Map Symbols
$regex_transport = '/[\x{1F680}-\x{1F6FF}]/u';
$clear_string = preg_replace($regex_transport, '', $clear_string);
// Match Miscellaneous Symbols
$regex_misc = '/[\x{2600}-\x{26FF}]/u';
$clear_string = preg_replace($regex_misc, '', $clear_string);
// Match Dingbats
$regex_dingbats = '/[\x{2700}-\x{27BF}]/u';
$clear_string = preg_replace($regex_dingbats, '', $clear_string);
return $clear_string;
}
?>