thefile, array(&$this, 'ap_activate') ); register_deactivation_hook( $this->thefile, array(&$this, 'ap_deactivate') ); //print_r('test'); if (is_admin()) { add_action( 'admin_init', array(&$this, 'ap_register_settings') ); //print_r($_GET['page']); if (isset($_GET['page']) && in_array($_GET['page'], $this->hook)){ //print_r('test'); add_action('admin_head', array(&$this,'ap_admin_head_addition')); add_action('admin_print_scripts',array(&$this, 'ap_admin_scripts')); } } add_action('wp_head',array(&$this, 'ap_load_jquery_intheme')); add_action('wp_dashboard_setup', array(&$this,'ap_rsswidget_setup')); } //***** let's do some housekeeping //define the option name saved in the database and return it value also function ap_get_option($which='array',$xsettings=''){ $name = "ap_{$this->codename}_options"; //name option in database switch($which){ case 'string': return $name; break; case 'array': $options = get_option($name); return $options; break; case 'settings': $setnm = $name; if (!empty($xsettings)) $setnm .= '-'.$xsettings; $setnm .= '-inwhite'; return $setnm; break; } } //on activation add default options to databaseoptions function ap_activate(){ if (!$this->ap_get_option('array')){ $funcnm = "ap_{$this->codename}_defaults"; if (function_exists($funcnm)){ $defaults = $funcnm(); }else{ $defaults = array(); } $name = $this->ap_get_option('string'); add_option($name,$defaults,'','yes'); } } //on deactivation unregister options and remove options function ap_deactivate(){ $optionname = $this->ap_get_option('string'); $options = $this->ap_get_option('array'); $setname = $this->ap_get_option('settings'); unregister_setting( $setname, $optionname, '' ); if ($options['clean_deact']) delete_option($optionname); } //register settings in white list before saving in db function ap_register_settings(){ $optionname = $this->ap_get_option('string'); $setname = $this->ap_get_option('settings'); $sanitization = "ap_{$this->codename}_sanitize"; register_setting( $setname, $optionname, $sanitization ); } //css for options page function ap_admin_head_addition(){ //$theurl = WP_PLUGIN_URL .'/'. str_replace(basename( $this->thefile),"",plugin_basename($this->thefile)); //$admin_stylesheet_url = $theurl.'options/dashboard/dashboard.css'; //echo ''; echo ''; } //load wp scripts for sortable boxes function ap_admin_scripts() { wp_enqueue_script('postbox'); wp_enqueue_script('dashboard'); } //load jquery in them //jQuery - load? function ap_load_jquery_intheme(){ $options = $this->ap_get_option('array'); if ($options['jquery']){ wp_enqueue_script('jquery'); } } // functions to build options pages function ap_postbox($id, $title, $content) { ?>
'; } function ap_mainbox($boxid,$boxtitle,$boxcontent){ ?>
ap_pldb_rsswidget.";
return;
}
include_once(ABSPATH . WPINC . '/feed.php');
// Get a SimplePie feed object
$rss = fetch_feed('http://www.amberpanther.com/feed/');
// Figure out how many total items there are, but limit it to 5.
$maxitems = $rss->get_item_quantity(5);
// Build an array of all the items, starting with element 0 (first element).
$rss_items = $rss->get_items(0, $maxitems);
if ($maxitems != 0){
echo '';
}
}
function ap_excerpt($text, $limit=250, $end = ' […]') {
if(strlen($text) > $limit){
$text = substr($text, 0, $limit);
$text = substr($text, 0, -(strlen(strrchr($text,' '))));
$text .= $end;
}
return $text;
}
function ap_rsswidget_setup() {
$options = get_option('ap_pldb_rsswidget');
$opt = $this->ap_get_option('array');
if ( (!$options || $options['showrss']) && !$opt['backend']['rss_ondash'])
wp_add_dashboard_widget( 'ap_db_rsswidget-news' , 'AmberPanther News' , array(&$this, 'ap_db_rsswidget'));
}
//array handling
//remove by key:
function ap_array_remove_key(){
$args = func_get_args();
return array_diff_key($args[0],array_flip(array_slice($args,1)));
}
// remove by value:
function ap_array_remove_value(){
$args = func_get_args();
return array_diff($args[0],array_slice($args,1));
}
function ap_array_merge_recursive_distinct($array1, $array2 = null){
$merged = (array)$array1;
if (is_array($array2)){
foreach ($array2 as $key => $val){
if (is_array($array2[$key]))
$merged[$key] = is_array($merged[$key]) ? $this->ap_array_merge_recursive_distinct($merged[$key], $array2[$key]) : $array2[$key];
else
$merged[$key] = $val;
}
}
return $merged;
}
//image exists
function ap_image_exists($url=''){
$exists = false;
$handle = @fopen($url,'r');
if ( $handle ){
$exists = true;
@fclose($handle);
}
return $exists;
}
// class ends
}
}
?>