$number){
$string = substr($string,0,$number).'...';
}
return $string;
}
/**
* Transforms all urls and e-mail adresses into clickable links and transforms images in html img tags
* Return: string
*/
function aXMLreader_makeclickable($text)
{
$return = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text);
$return = preg_replace_callback("#([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", 'aXMLreader_parsetag', $return);
$return = preg_replace("#([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1@\\2", $return);
return $return;
}
function aXMLreader_parsetag($matches){
$ext = array('jpg', 'png', 'gif', 'bmp');
if(in_array(substr($matches[0],-3,3),$ext)){
return '';
}
else{
return ''.$matches[0].'';
}
}
/**
* Transforms the raw SimpleXMLElement array into a 3 dimensional array
* Return: Array
*/
function aXMLreader_show_data($array,$return=array(),$parent=''){
global $list_count, $pluginvars;
$children = $array->children();
foreach($children as $key => $child){
$strchild = trim(strval($child));
if(!empty($strchild) && !in_array($key,$pluginvars['remove_tag'])){
if(empty($parent)){
$return[strtolower($child->getName())][0] = $strchild;
}else{
if(!isset($list_count[$parent])){ $list_count[$parent] = 1; }
$return[$parent][$list_count[$parent]][] = $strchild;
}
}
if(false !== $child->children()){
$return = aXMLreader_show_data($child,$return,strtolower($child->getName()));
}
}
if(count($children) != 0){
$list_count[$parent]++;
}
return $return;
}
/**
* Transforms the array from aXMLreader_show_data into two arrays, which can be used in str_replace
* Return: A array containing two arrays: patterns & replacements
*/
function aXMLreader_create_replace_arrays($array, $row_delimiter, $item_delimiter){
global $plugindata;
$pattern = $replace = array();
foreach($array as $key => $value){
foreach($value as $key2 => $value2){
if(is_array($value2)){
$array[$key][$key2] = implode($item_delimiter,aXMLreader_makeclickable($array[$key][$key2]));
}
}
$pattern[] = '['.$plugindata['shortnicename'].':'.$key.']';
$replace[] = implode($row_delimiter,$array[$key]);
}
return array('pattern' => $pattern, 'replace' => $replace);
}
//
// Back end plugin code
//
/**
* Write the admin link in the Settings menu
* Return: -
*/
function aXMLreader_AdminMenu(){
global $plugindata;
add_options_page($plugindata['fullname'], $plugindata['shortname'], 9, $plugindata['nicename'], 'aXMLreader_AdminPage');
add_action('admin_init', 'register_aXMLreader_settings');
}
/**
* Register allowed settings fields
*/
function register_aXMLreader_settings() {
global $plugindata;
register_setting($plugindata['nicename'], $plugindata['nicename'].'_feed');
register_setting($plugindata['nicename'], $plugindata['nicename'].'_itemdel');
register_setting($plugindata['nicename'], $plugindata['nicename'].'_rowdel');
register_setting($plugindata['nicename'], $plugindata['nicename'].'_hidetag');
}
/**
* Show the admin page to manage feeds
* Return: - (echo is used)
*/
function aXMLreader_AdminPage(){
global $plugindata;
echo '
| '.__('XML tag', 'advanced-xml-reader').' | '.__('Value', 'advanced-xml-reader').' | '.__('How to use in a post', 'advanced-xml-reader').' |
| '.$key.' | '.$tmpvalue.' | ['.$plugindata['shortnicename'].':'.$key.'] |
';
}
//
//Front end plugin code
//
/**
* Replaces the tags used in posts in real values
* Return: $text (string)
*/
function aXMLreader_ParseTags($text){
global $plugindata, $patterns, $replacements, $pluginvars;
if($feed = get_option($plugindata['nicename'].'_feed')){
$curl = new CURL();
//$curl->enableCache();
$data = $curl->get($feed);
$xml = new SimpleXmlElement($data, LIBXML_NOCDATA);
$pluginvars['remove_tag'] = explode(',',str_replace(' ','',get_option($plugindata['nicename'].'_hidetag')));
$taglist = aXMLreader_create_replace_arrays(aXMLreader_show_data($xml),get_option($plugindata['nicename'].'_rowdel'),get_option($plugindata['nicename'].'_itemdel'));
//aXMLreader_multiarray_walk($xml,'aXMLreader_fill_replace_arrays');
$text = str_replace($taglist['pattern'], $taglist['replace'], $text);
}
return $text;
}
?>