'widget_AppStore_Widget', 'description' => 'Zeigt die Top 10 der AppStore Charts' );
$this->WP_Widget('AppStore_Widget', 'Appstore', $widget_ops);
if ( is_active_widget(false, false, $this->id_base) )
add_action( 'wp_head', array(&$this, 'recent_widget_style') );
}
function recent_widget_style() {
//
echo '';
}
function widget($args, $instance) {
extract($args, EXTR_SKIP);
$wtitle = apply_filters('widget_title', empty( $instance['title'] ) ? __( 'Top 10 Apps' ) : $instance['title']);
//$freePaid = apply_filters('widget_title', empty( $instance['freePaid'] ) ? __( 'free' ) : $instance['freePaid']);
$topCount = apply_filters('widget_title', empty( $instance['topCount'] ) ? __( '10' ) : $instance['topCount']);
$freePaid = attribute_escape($instance['freePaid']) ;
$Country = attribute_escape($instance['Country']) ;
echo $before_widget .$before_title . $wtitle . $after_title;
$doc = new DOMDocument();
if ($freePaid == "free") {
$feed = RSS_TOPFREE.$Country."/lang=de_de/limit=".$topCount."/xml";
} else {
$feed = RSS_TOPPAID.$Country."/lang=de_de/limit=".$topCount."/xml";
}
$feedUpdateIntervall = $instance['feedUpdateIntervall'];
if ($feedUpdateIntervall == "") {
$feedUpdateIntervall = 60*60*60;
} else {
$feedUpdateIntervall = $feedUpdateIntervall*60*60;
}
echo $instance['feedUpdateTime'].'
';
if ((time() - $feedUpdateIntervall) < $instance['feedUpdateTime']) {
//echo "Cache
";
$doc = $instance['feedCache'];
} else {
//echo'Load
';
$doc->load($feed);
$instance['feedCache'] = $doc;
$instance['feedUpdateTime'] = time();
}
//echo $instance['feedUpdateTime'].'
';
$appList = '
';
foreach ($doc->getElementsByTagName('entry') as $node) {
$title = htmlspecialchars($node->getElementsByTagName('name')->item(0)->nodeValue);
$id = ExtractID(utf8_encode($node->getElementsByTagName('id')->item(0)->nodeValue));
$price = htmlspecialchars($node->getElementsByTagName('price')->item(0)->nodeValue);
$sellerName = htmlspecialchars(utf8_encode($node->getElementsByTagName('artist')->item(0)->nodeValue));
$image = utf8_encode($node->getElementsByTagName('image')->item(0)->nodeValue);
$afflink = WP_PLUGIN_URL."/".PLUGIN_BASE_DIRECTORY."/AppStore.php?appid=".$id;
$appList .= '-
'.$title.'
';
}
$appList .= "
";
echo $appList;
echo $after_widget;
}
function update($new_instance, $old_instance) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['freePaid'] = strip_tags($new_instance['freePaid']);
$instance['topCount'] = strip_tags($new_instance['topCount']);
$instance['Country'] = strip_tags($new_instance['Country']);
$instance['feedUpdateIntervall'] = strip_tags($new_instance['feedUpdateIntervall']);
$instance['feedCache'] = '';
$instance['feedUpdateTime'] = '';
return $instance;
}
function form($instance) {
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'freePaid' => '', 'topCount' => '', 'Country' => '', 'feedCache' => '', 'feedUpdateTime' => '', 'feedUpdateIntervall' => '' ) );
$title = attribute_escape($instance['title']);
$freePaid = attribute_escape($instance['freePaid']) ;
$topCount = attribute_escape($instance['topCount']) ;
$Country = attribute_escape($instance['Country']) ;
$feedCache = attribute_escape($instance['feedCache']) ;
$feedUpdateTime = attribute_escape($instance['feedUpdateTime']) ;
$feedUpdateIntervall= attribute_escape($instance['feedUpdateIntervall']) ;
if ($freePaid == "free" ) {
$checked = "checked" ;
} else {
$checked = "" ;
}
if ($topCount == "" ) {
$topCount = "10" ;
}
if ($title == "" ) {
$title = "Top Apps" ;
}
if ($Country == "" ) {
$Country = "143445" ;
}
if ($feedUpdateIntervall == "" ) {
$feedUpdateIntervall = "60" ;
}
$Countries = array(
143445 => "Austria",
143443 => "Germany",
143452 => "Netherlands",
143441 => "USA",
143469 => "Russia",
143444 => "UK",
143459 => "Switzerland",
143465 => "China",
143448 => "Greece",
143450 => "Italy",
143461 => "New Zealand"
);
asort($Countries);
?>