$number){ $string = substr($string,0,$number).'...'; } return $string; } /** * Transforms the raw SimpleXMLElement array into a 3 dimensional array * Return: Array */ function aXMLreader_show_data($array,$return=array(),$parent=''){ global $list_count; $children = $array->children(); foreach($children as $child){ $strchild = trim(strval($child)); if(!empty($strchild)){ 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,$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'); } /** * 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.'] |