* @version 1.0
*/
class social_essentials
{
/**
* Plugin title is displayed in admin section at the page of plugin options
*
* @page_title (string)
*/
var $page_title;
/**
* Menu title of plugin in admin section
*
* @menu_title (string)
*/
var $menu_title;
/**
* Access level for plugin
*
* @access_level (int)
*/
var $access_level;
/**
* Where in admin panel a link to plugin is displayed
*
* @add_page_to (int)
*/
var $add_page_to;
/**
* Plugin's description which is displayed below the title in admin section at the page of plugin's options.
*
* @short_description (string)
*/
var $short_description;
/**
* Site admin twitter name
*
* @twitter_username (string)
*/
var $twitter_username;
/**
* Facebook API key
*
* @feb_app_id (string)
*/
var $feb_app_id = '';
/**
* Enable or disable "Call to action text"
*
* @call_to_action (bool)
*/
var $call_to_action;
/**
* Style of call to action text bold
*
* @call_to_action_text_style (bool)
*/
var $call_to_action_text_style_bold;
/**
* Style of call to action text italic
*
* @call_to_action_text_style (bool)
*/
var $call_to_action_text_style_italic;
/**
* Style of call to action text underline
*
* @call_to_action_text_style (bool)
*/
var $call_to_action_text_style_underline;
/**
* Hex color ['#000000']
*
* @text_call_to_action_color (string)
*/
var $text_call_to_action_color;
/**
* Contains the name of html tag ['h1','h2', ...]
*
* @call_to_action_text_size (string)
*/
var $call_to_action_text_size;
/**
* Position of call to actiob text ['left', 'right']
*
* @call_to_action_position (string)
*/
var $call_to_action_position;
/**
* Call to action text
*
* @call_to_action_text (string)
*/
var $call_to_action_text;
/**
* Buttons icons aligment ['left', 'right', 'center', 'float left', 'float right']
*
* @icon_aligment (string)
*/
var $icon_aligment;
/**
* Buttons icon size ['small', 'large']
*
* @icon_size (string)
*/
var $icon_size;
/**
* Cutom css field
*
* @custom_css (string)
*/
var $custom_css;
/**
* Button names separated by comma
*
* @buttons_order (string)
*/
var $buttons_order;
/**
* ULR to arrow image
*
* @text_call_to_action_arrow (string)
*/
var $text_call_to_action_arrow;
/**
* Contains section of page where should be buttons placed
*
* @display (array)
*/
var $display = array();
/**
* Content button names in items keys
*
* @show_buttons (array)
*/
var $show_buttons = array();
/**
* Count of RSS feed posts in sidebar
*
* @count_posts (int)
*/
var $count_posts = 5;
/**
* Method initialize object of a class with variables from wp-option table
*
* @return void
*/
function social_essentials()
{
if (get_option('se_show_twitter')) $this->show_buttons['twitter'] = get_option('se_show_twitter');
if (get_option('se_show_fb_like')) $this->show_buttons['fb_like'] = get_option('se_show_fb_like');
if (get_option('se_show_fb_share')) $this->show_buttons['fb_share'] = get_option('se_show_fb_share');
if (get_option('se_show_google')) $this->show_buttons['google'] = get_option('se_show_google');
if (get_option('se_show_pinterest')) $this->show_buttons['pinterest'] = get_option('se_show_pinterest');
if (get_option('se_show_stumbleupon')) $this->show_buttons['stumbleupon'] = get_option('se_show_stumbleupon');
if (get_option('se_display_above_posts')) $this->display['above_posts'] = get_option('se_display_above_posts');
if (get_option('se_display_below_posts')) $this->display['below_posts'] = get_option('se_display_below_posts');
if (get_option('se_display_above_pages')) $this->display['above_pages'] = get_option('se_display_above_pages');
if (get_option('se_display_below_pages')) $this->display['below_pages'] = get_option('se_display_below_pages');
if (get_option('se_display_above_home')) $this->display['above_home'] = get_option('se_display_above_home');
if (get_option('se_display_below_home')) $this->display['below_home'] = get_option('se_display_below_home');
$this->icon_size = get_option('se_icon_size');
$this->icon_aligment = get_option('se_icon_aligment');
$this->call_to_action_text = get_option('se_call_to_action_text');
$this->call_to_action_position = get_option('se_call_to_action_position');
$this->call_to_action_text_size = get_option('se_call_to_action_text_size');
$this->text_call_to_action_color = get_option('se_text_call_to_action_color');
$this->call_to_action_text_style_bold = get_option('se_call_to_action_text_style_bold');
$this->call_to_action_text_style_italic = get_option('se_call_to_action_text_style_italic');
$this->call_to_action_text_style_underline = get_option('se_call_to_action_text_style_underline');
$this->call_to_action = get_option('se_call_to_action');
$this->text_call_to_action_arrow = get_option('se_text_call_to_action_arrow');
$this->twitter_username = get_option('se_settings_twitter_username');
$this->feb_app_id = get_option('se_settings_fb_app_id');
$this->custom_css = get_option('se_custom_css');
$this->buttons_order = get_option('se_buttons_order');
add_action( 'wp_ajax_se_preview', array(&$this, 'preview_buttons' ));
add_action( 'wp_ajax_se_stats', array(&$this, 'get_stats_table' ));
add_action( 'wp_ajax_se_stats_top', array(&$this, 'get_stats_top_table' ));
add_action( 'wp_ajax_se_stats_last_top', array(&$this, 'get_stats_top_table' ));
add_action( 'wp_ajax_se_stats_last', array(&$this, 'get_stats_top_table' ));
add_filter( 'the_content', array(&$this, 'generate_buttons' ));
add_action( 'update_stats', array(&$this, 'update_stats'));
}
/**
* Method which defines what section in admin panel loads a link for plugin settings
*
* @return void
*/
function add_admin_menu()
{
add_menu_page($this->page_title, $this->menu_title, $this->access_level, basename(__FILE__), array(&$this, 'stats_page'));
add_submenu_page(basename(__FILE__), "Setup - Social Essentials", "Setup", "activate_plugins", 'Setup', array(&$this, 'admin_page'));
}
/**
* This method checks current plugin options and generates html for share buttons
*
* @return string html for share buttons
*/
function generate_buttons($content, $preview = false, $options = array())
{
if (!$preview)
global $post;
if (!empty($options))
{
foreach ($options as $option => $value)
{
$this->{$option} = $value;
}
}
$html = '
';
$plink = (!$preview) ? get_permalink($post->ID) : $preview;
$eplink = (!$preview) ? urlencode($plink) : urlencode($preview);
$ptitle = (!$preview) ? get_the_title($post->ID) : $this->page_title;
$eptitle = (!$preview) ? str_replace(array(">","<"), "", $ptitle) : $this->page_title;
if (!empty($this->show_buttons) && (!empty($this->display) || $preview))
{
foreach (explode(',', $this->buttons_order) as $button)
{
if (!empty($this->show_buttons[trim($button)]))
{
switch (trim($button))
{
case 'twitter':
$layout = $this->icon_size == 'small' ? 'horizontal' : 'vertical' ;
$html .= '
';
break;
case 'fb_like':
$layout = $this->icon_size == 'small' ? 'button_count' : 'box_count' ;
$html .= '
';
break;
case 'fb_share':
if ($this->icon_size == "large" )
{
$tp = "box_count";
} else $tp= "button_count";
$html .= '
';
break;
case 'google':
if ($this->icon_size == "large" ) $tp="tall"; else $tp="small";
$classSize = $this->icon_size == 'large' ? 'size-box' : 'size-small';
$html .= '
';
$html .= '';
break;
case 'pinterest':
$classSize = $this->icon_size == 'small' ? 'horizontal' : 'vertical' ;
$html .= '
';
break;
case 'stumbleupon':
$classSize = $this->icon_size == 'small' ? 1 : 5 ;
$dim = $this->icon_size == 'small' ? 'width:100px; height: 30px;' : 'width:70px; height: 60px;';
$html .= '
';
break;
}
}
}
if ($this->call_to_action)
{
$classes = array();
if (!empty($this->call_to_action_text_style_bold)) array_push($classes, 'se_bold');
if (!empty($this->call_to_action_text_style_italic)) array_push($classes, 'se_italic');
if (!empty($this->call_to_action_text_style_underline)) array_push($classes, 'se_underline');
switch ($this->call_to_action_position)
{
case 'left':
$call_to_action_html = '<'.$this->call_to_action_text_size.' class="'.implode(' ', $classes).'" style="color:'.$this->text_call_to_action_color.'; float:left;">'.$this->call_to_action_text.''.$this->call_to_action_text_size.'>';
$html = '
'.$call_to_action_html.((!empty($this->text_call_to_action_arrow)) ? '

' : '
').$html;
break;
case 'right':
$call_to_action_html = '<'.$this->call_to_action_text_size.' class="'.implode(' ', $classes).'" style="color:'.$this->text_call_to_action_color.'; float:right;">'.$this->call_to_action_text.''.$this->call_to_action_text_size.'>';
$html .= ((!empty($this->text_call_to_action_arrow)) ? '
' : '
').$call_to_action_html.'
';
break;
}
}
$html .= '
';
if ($this->icon_aligment == 'left' || $this->icon_aligment == 'right' || $this->icon_aligment == 'center') $html .= '';
if (!$preview)
{
foreach ($this->display as $key => $display)
{
switch ($key)
{
case 'above_posts':
if ($post->post_type == 'post' && !is_home()) $content = $html.$content;
break;
case 'below_posts':
if ($post->post_type == 'post' && !is_home()) $content .= $html;
break;
case 'above_page':
if ($post->post_type == 'page' && !is_home()) $content = $html.$content;
break;
case 'below_page':
if ($post->post_type == 'page' && !is_home()) $content .= $html;
break;
case 'above_home':
if (is_home()) $content = $content.$html;
break;
case 'below_home':
if (is_home()) $content .= $html;
break;
}
}
}
else $content .= $html;
if ($this->custom_css)
{
$content .= '';
}
}
return $content;
}
/**
* This method checks current plugin options and generates html for share buttons
*
* @return string html for share buttons
*/
function preview_buttons()
{
$myposts = get_posts(array( 'numberposts' => 1));
$options = array();
if ($_POST)
{
if ($_POST['show_twitter']) $options['show_buttons']['twitter'] = $_POST['show_twitter'];
if ($_POST['show_fb_like']) $options['show_buttons']['fb_like'] = $_POST['show_fb_like'];
if ($_POST['show_fb_share']) $options['show_buttons']['fb_share'] = $_POST['show_fb_share'];
if ($_POST['show_google']) $options['show_buttons']['google'] = $_POST['show_google'];
if ($_POST['show_pinterest']) $options['show_buttons']['pinterest'] = $_POST['show_pinterest'];
if ($_POST['show_stumbleupon']) $options['show_buttons']['stumbleupon'] = $_POST['show_stumbleupon'];
if ($_POST['display_above_posts']) $options['display']['above_posts'] = $_POST['display_above_posts'];
if ($_POST['display_below_posts']) $options['display']['below_posts'] = $_POST['display_below_posts'];
if ($_POST['display_above_pages']) $options['display']['above_pages'] = $_POST['display_above_pages'];
if ($_POST['display_below_pages']) $options['display']['below_pages'] = $_POST['display_below_pages'];
if ($_POST['display_above_home']) $options['display']['above_home'] = $_POST['display_above_home'];
if ($_POST['display_below_home']) $options['display']['below_home'] = $_POST['display_below_home'];
$options['icon_size'] = $_POST['icon_size'];
$options['icon_aligment'] = $_POST['icon_aligment'];
$options['call_to_action_text'] = $_POST['call_to_action_text'];
$options['call_to_action_position'] = $_POST['call_to_action_position'];
$options['call_to_action_text_size'] = $_POST['call_to_action_text_size'];
$options['text_call_to_action_color'] = $_POST['text_call_to_action_color'];
$options['call_to_action_text_style_bold'] = $_POST['call_to_action_text_style_bold'];
$options['call_to_action_text_style_italic'] = $_POST['call_to_action_text_style_italic'];
$options['call_to_action_text_style_underline'] = $_POST['call_to_action_text_style_underline'];
$options['call_to_action'] = $_POST['call_to_action'];
$options['text_call_to_action_arrow'] = $_POST['text_call_to_action_arrow'];
$options['twitter_username'] = $_POST['settings_twitter_username'];
$options['feb_app_id'] = $_POST['settings_fb_app_id'];
$options['custom_css'] = $_POST['custom_css'];
$options['buttons_order'] = $_POST['buttons_order'];
}
exit($this->generate_buttons('', 'http://imimpact.com/', $options));
}
/**
* This method attaches css file for plugin
*
* @return void
*/
function init()
{
wp_enqueue_style('social-essentials', WP_PLUGIN_URL . '/social-essentials/style.css');
wp_enqueue_script('social-essentials', WP_PLUGIN_URL . '/social-essentials/script.js', array('jquery', 'jquery-ui-core', 'jquery-ui-sortable', 'jquery-ui-draggable'), '1.0');
wp_enqueue_style( 'farbtastic' );
wp_enqueue_script( 'farbtastic' );
}
/**
* Plugin activation. Adds default settings in wp-options table
*
* @return void
*/
function activate()
{
add_option('se_show_twitter', '0');
add_option('se_show_fb_like', '0');
add_option('se_show_fb_share', '0');
add_option('se_show_google', '0');
add_option('se_show_pinterest', '0');
add_option('se_show_stumbleupon', '0');
add_option('se_icon_size', 'small');
add_option('se_icon_aligment', 'left');
add_option('se_call_to_action_text', '');
add_option('se_call_to_action_position', 'right');
add_option('se_call_to_action_text_size', 'h4');
add_option('se_text_call_to_action_color', '#000');
add_option('se_call_to_action_text_style_bold', '1');
add_option('se_call_to_action_text_style_italic', '');
add_option('se_call_to_action_text_style_underline', '');
add_option('se_call_to_action', '0');
add_option('se_display_above_posts', '0');
add_option('se_display_below_posts', '0');
add_option('se_display_above_pages', '0');
add_option('se_display_below_pages', '0');
add_option('se_display_above_home', '0');
add_option('se_display_below_home', '0');
add_option('se_settings_twitter_username', '');
add_option('se_settings_fb_app_id', '');
add_option('se_custom_css', '#call_to_action h4{padding:0px 5px;}');
add_option('se_text_call_to_action_arrow', '');
add_option('se_buttons_order', 'twitter, fb_like, fb_share, google, pinterest, stumbleupon');
wp_schedule_event(time(), 'daily', 'update_stats');
}
/**
* Plugin deactivation. Removes default settings from wp-options table
*
* @return void
*/
function deactivate()
{
delete_option('se_show_twitter');
delete_option('se_show_fb_like');
delete_option('se_show_fb_share');
delete_option('se_show_google');
delete_option('se_show_pinterest');
delete_option('se_show_stumbleupon');
delete_option('se_icon_size');
delete_option('se_icon_aligment');
delete_option('se_call_to_action_text');
delete_option('se_call_to_action_position');
delete_option('se_call_to_action_text_size');
delete_option('se_text_call_to_action_color');
delete_option('se_call_to_action_text_style_bold');
delete_option('se_call_to_action_text_style_italic');
delete_option('se_call_to_action_text_style_underline');
delete_option('se_call_to_action');
delete_option('se_display_above_posts');
delete_option('se_display_below_posts');
delete_option('se_display_above_pages');
delete_option('se_display_below_pages');
delete_option('se_display_above_home');
delete_option('se_display_below_home');
delete_option('se_settings_twitter_username');
delete_option('se_settings_fb_app_id');
delete_option('se_custom_css');
delete_option('se_text_call_to_action_arrow');
delete_option('se_buttons_order');
wp_clear_scheduled_hook('update_stats');
}
/**
* Method for admin page plugin (main function of the class)
*
* @return void
*/
function admin_page()
{
?>
page_title;?> - Setup
Configuration successfully saved.
view_options_page();
echo '
';
}
/**
* Method for loading of plugin's options view in admin section
*
* @return void
*/
function view_options_page()
{
?>
| '.ucfirst($type).' |
Facebook like |
Facebook share |
Twitter |
Google +1 |
Stumbleupon |
Pinterest |
Total |
';
$posts_array = get_posts(array('post_status' => 'publish', 'post_type' => $type));
foreach ($posts_array as $post) :
$share_all_data = json_decode(get_post_meta($post->ID, 'share_all_data', true), true);
$html .= '
|
'.$post->post_title.'
|
'.$share_all_data['like_count'].'
|
'.$share_all_data['share_count'].'
|
'.$share_all_data['twitter'].'
|
'.$share_all_data['plusone'].'
|
'.$share_all_data['stumble'].'
|
'.$share_all_data['pinit'].'
|
'.$share_all_data['count'].'
|
';
endforeach;
$html .= '';
if ($_POST) exit($html); else echo $html;
}
function get_stats_top_table($type = 'post')
{
$type = (isset($_POST['type'])) ? $_POST['type'] : $type;
$posts_array = get_posts(array('post_status' => 'publish', 'post_type' => $type));
foreach ($posts_array as $key=>$post) :
$share_all_data = json_decode(get_post_meta($post->ID, 'share_all_data', true), true);
$posts_array[$key]->share_count = $share_all_data['count'];
endforeach;
usort($posts_array, array(&$this, "sort"));
$html .='
| '.ucfirst($type).' |
Facebook like |
Facebook share |
Twitter |
Google +1 |
Stumbleupon |
Pinterest |
Total |
';
foreach ($posts_array as $key => $post) :
$share_all_data = json_decode(get_post_meta($post->ID, 'share_all_data', true), true);
$html .='
|
'.$post->post_title.'
|
'.$share_all_data['like_count'].'
|
'.$share_all_data['share_count'].'
|
'.$share_all_data['twitter'].'
|
'.$share_all_data['plusone'].'
|
'.$share_all_data['stumble'].'
|
'.$share_all_data['pinit'].'
|
'.$share_all_data['count'].'
|
';
if ($key > 9) break;
endforeach;
$html .= '
';
if ($_POST) exit($html); else echo $html;
}
function get_stats_last_top_table($type = 'post')
{
$type = (isset($_POST['type'])) ? $_POST['type'] : $type;
$posts_array = get_posts(array('post_status' => 'publish', 'post_type' => $type));
foreach ($posts_array as $key=>$post) :
$posts_array[$key]->share_count = get_post_meta($post->ID, 'share_count', true);
endforeach;
usort($posts_array, array(&$this, "sort"));
$html .= '
| '.ucfirst($type).' |
Facebook like |
Facebook share |
Twitter |
Google +1 |
Stumbleupon |
Pinterest |
Total |
';
foreach ($posts_array as $key => $post) :
$counts = json_decode(get_post_meta($post->ID, 'share_data', true), true);
$html .= '
|
'.$post->post_title.'
|
'.$this->array_sum_key($counts ,'like_count').'
|
'.$this->array_sum_key($counts ,'share_count').'
|
'.$this->array_sum_key($counts ,'twitter').'
|
'.$this->array_sum_key($counts ,'plusone').'
|
'.$this->array_sum_key($counts ,'stumble').'
|
'.$this->array_sum_key($counts ,'pinit').'
|
'.$post->share_count.'
|
';
if ($key > 9) break;
endforeach;
$html .= '
';
if ($_POST) exit($html); else echo $html;
}
function get_stats_last_table($type = 'post')
{
$type = (isset($_POST['type'])) ? $_POST['type'] : $type;
$posts_array = get_posts(array('post_status' => 'publish', 'post_type' => $type));
$html .= '
| '.ucfirst($type).' |
Facebook like |
Facebook share |
Twitter |
Google +1 |
Stumbleupon |
Pinterest |
Total |
';
if (!empty($posts_array)):
foreach ($posts_array as $key => $post) :
$counts = json_decode(get_post_meta($post->ID, 'share_data', true), true);
$html .= '
|
'.$post->post_title.'
|
'.$this->array_sum_key($counts ,'like_count').'
|
'.$this->array_sum_key($counts ,'share_count').'
|
'.$this->array_sum_key($counts ,'twitter').'
|
'.$this->array_sum_key($counts ,'plusone').'
|
'.$this->array_sum_key($counts ,'stumble').'
|
'.$this->array_sum_key($counts ,'pinit').'
|
'.get_post_meta($post->ID, 'share_count', true).'
|
';
endforeach;
endif;
$html .= '
';
if ($_POST) exit($html); else echo $html;
}
function update_stats()
{
$types = array(
'post',
'page'
);
foreach ($types as $type)
{
$posts_array = get_posts(array('post_status' => 'publish', 'post_type' => $type));
foreach ($posts_array as $key=>$post) :
$xml = simplexml_load_string(file_get_contents('https://api.facebook.com/method/fql.query?query=select%20%20like_count,%20total_count,%20share_count,%20click_count%20from%20link_stat%20where%20url=%22'.
get_permalink($post->ID).'%22'));
$json = json_encode($xml);
$array = json_decode($json,TRUE);
$counts = $this->slick_stats_count(get_permalink($post->ID));
$data = array(
'like_count' => $array['link_stat']['like_count'],
'share_count' => $array['link_stat']['share_count'],
'twitter' => $counts['twitter'],
'plusone' => $counts['plusone'],
'stumble' => $counts['stumble'],
'pinit' => $counts['pinit'],
'count' => array_sum($counts) + $array['link_stat']['like_count'] + $array['link_stat']['share_count'],
'time' => time()
);
$share_data = get_post_meta($post->ID, 'share_data', true);
if (empty($share_data))
{
add_post_meta($post->ID, 'share_data', json_encode($data));
add_post_meta($post->ID, 'share_all_data', json_encode($data));
add_post_meta($post->ID, 'share_count', $data['count']);
}
else
{
update_post_meta($post->ID, 'share_all_data', json_encode($data));
$share_data = json_decode($share_data, true);
$data = array(
'like_count' => $array['link_stat']['like_count'] - $this->array_sum_key($share_data, 'like_count'),
'share_count' => $array['link_stat']['share_count'] - $this->array_sum_key($share_data, 'share_count'),
'twitter' => $counts['twitter'] - $this->array_sum_key($share_data, 'twitter'),
'plusone' => $counts['plusone'] - $this->array_sum_key($share_data, 'plusone'),
'stumble' => $counts['stumble'] - $this->array_sum_key($share_data, 'stumble'),
'pinit' => $counts['pinit'] - $this->array_sum_key($share_data, 'pinit'),
'count' => array_sum($counts) + $array['link_stat']['like_count'] + $array['link_stat']['share_count'] - get_post_meta($post->ID, 'share_count', true),
'time' => time()
);
array_push($share_data, $data);
foreach ($share_data as $key=>$item)
{
if (strtotime('- 1 month') > strtotime($item['time']))
{
unset($share_data[$key]);
}
}
$new_count = 0;
foreach ($share_data as $item)
{
$new_count += $item['count'];
}
update_post_meta($post->ID, 'share_data', json_encode($share_data));
update_post_meta($post->ID, 'share_count', $new_count);
}
endforeach;
}
}
function array_sum_key( $arr, $index = null ){
if(!is_array( $arr ) || sizeof( $arr ) < 1){
return 0;
}
$ret = 0;
foreach( $arr as $id => $data ){
if ($id == $index)
$ret += (isset( $arr[$index] )) ? $arr[$index] : 0;
}
return $ret;
}
function sort($a,$b) {
if ($a->share_count == $b->share_count) {
return 0;
} else {
if($a->share_count < $b->share_count) {
return 1;
} else {
return -1;
}
}
}
function slick_stats_count($link){
$url = $link;
@$json = file_get_contents("http://api.sharedcount.com/?url=" . rawurlencode($link));
$counts = json_decode($json, true);
$count = Array();
$count['twitter'] = $counts["Twitter"];
$count['plusone'] = $counts["GooglePlusOne"];
$count['stumble'] = $counts["StumbleUpon"];
$url_json = esc_url_raw('http://api.pinterest.com/v1/urls/count.json?callback=&url='.$link, array('http', 'https'));
$response = wp_remote_get($url_json);
$code = wp_remote_retrieve_response_code($response);
$pinit = 0;
if ($code == 200){
$data = $response['body'];
$data = str_replace(')', '', str_replace('(', '', $data));
$data = json_decode($data);
$pinit = $data->{'count'} != '' ? $data->{'count'} : 0 ;
}
$count['pinit'] = $pinit;
return $count;
}
}
class RssItem {
var $title;
var $link;
var $descroption;
var $guid;
var $pubdate;
function RssItem ($aa)
{
foreach ($aa as $k=>$v)
$this->$k = $aa[$k];
}
}
function readDatabase($filename)
{
$data = file_get_contents($filename);
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parse_into_struct($parser, $data, $values, $tags);
xml_parser_free($parser);
foreach ($tags as $key=>$val) {
if ($key == "item") {
$molranges = $val;
for ($i=0; $i < count($molranges); $i+=2) {
$offset = $molranges[$i] + 1;
$len = $molranges[$i + 1] - $offset;
$tdb[] = parseMol(array_slice($values, $offset, $len));
}
} else {
continue;
}
}
return $tdb;
}
function parseMol($mvalues)
{
for ($i=0; $i < count($mvalues); $i++) {
(!empty($mvalues[$i]["value"])) ? $mol[$mvalues[$i]["tag"]] = $mvalues[$i]["value"] : $mol[$mvalues[$i]["tag"]] = '';
}
return new RssItem($mol);
}
function sub_text($text,$maxwords = 10, $maxchar = 0) {
$words = explode(' ',$text);
$text='';
foreach ($words as $key => $word) {
if ($maxwords)
{
if ($key != $maxwords)
{
$text.=' '.$word;
}
else
{
$text.='...';
break;
}
}
if ($maxchar)
{
if (mb_strlen($text.' '.$word)<$maxchar) {
$text.=' '.$word;
}
else {
$text.='...';
break;
}
}
}
return $text;
}
?>