*/
require_once AWP_LIB_DIR . '/Plugin.php';
require_once AWP_INC_DIR . '/apptivo_services/News.php';
/**
* Class AWP_News
*/
class AWP_News extends AWP_Base
{
var $_plugin_activated = false;
/**
* PHP5 constructor
*/
function __construct()
{
$settings=array();
$this->_plugin_activated=false;
$settings=get_option("awp_plugins");
if(get_option("awp_plugins")!=="false"){
if($settings["news"])
$this->_plugin_activated=true;
}
}
/**
* Returns plugin instance
*
* @return AIP_Plugin_BrowserCache
*/
function &instance()
{
static $instances = array();
if (!isset($instances[0])) {
$class = __CLASS__;
$instances[0] = & new $class();
}
return $instances[0];
}
/**
* Runs plugin
*/
function run()
{
if($this->_plugin_activated){
add_action( 'widgets_init',array(&$this,'register_widget'));
add_shortcode('apptivo_news_fullview',array(&$this,'show_news_fullview'));
add_shortcode('apptivo_news_inline',array(&$this,'show_news_inline'));
add_action('the_posts',array(&$this,'check_for_shortcode'));
}
}
function check_for_shortcode($posts) {
$news_fullView=awp_check_for_shortcode($posts,'[apptivo_news_fullview');
$news_inlineView=awp_check_for_shortcode($posts,'[apptivo_news_inline');
if ($news_inlineView){
// load styles and scripts
$this->loadscripts();
}
return $posts;
}
function loadscripts()
{
wp_enqueue_script('jquery_cycleslider.js',AWP_PLUGIN_BASEURL. '/assets/js/jquery.cycle.all.latest.js',array('jquery'));
}
/* Add News */
function add_news()
{
$awp_news_options = array(
'Title' => stripslashes($_POST['awp_news_title']),
'Description' => stripslashes($_POST['awp_news_desc']),
'startdate' => gmdate(DATE_ATOM,mktime()),
'enddate' =>gmdate(DATE_ATOM,mktime(0,0,0,gmdate('m'),gmdate('d'),gmdate('Y')+20)),
'Link' => $_POST['awp_news_link'],
'publishedat' => stripslashes($_POST['awp_news_published_at']),
'publishedby' => stripslashes($_POST['awp_news_published_by']),
'imageurl' => stripslashes($_POST['awp_news_imageurl']),
'showflag' => stripslashes($_POST['awp_news_show']),
'order' => stripslashes($_POST['awp_news_order']),
);
$awp_news_options= wp_parse_args($awp_news_options,array(
'Title' => '',
'Description' => '',
'startdate' => '',
'enddate' => '',
'Link' => '',
'publishedat' =>'',
'publishedby' => '',
'imageurl' =>'',
'showflag' => '',
'order' => ''
));
extract($awp_news_options);
$Description = apply_filters('the_content', $Description);
$response = addNews(null, $Title, $Description, $isFeatured, $startdate, $imageurl, $Link, $publishedat, $publishedby, $order, $enddate,null,$imageurl);
if($response == 'E_100')
{
return 'E_100';
}
return $response->return;
}
//Update news
function update_news()
{
$newsId = $_POST['awp_tstid'];
$awp_news_options = array(
'Title' => stripslashes($_POST['awp_news_title']),
'Description' => stripslashes($_POST['awp_news_desc_update']),
'startdate' =>$_POST['startdate'],
'enddate' =>$_POST['enddate'],
'Link' => $_POST['awp_news_link'],
'publishedat' => stripslashes($_POST['awp_news_published_at']),
'publishedby' => stripslashes($_POST['awp_news_published_by']),
'imageurl' => stripslashes($_POST['awp_news_imageurl']),
'showflag' => stripslashes($_POST['awp_news_show']),
'order' => stripslashes($_POST['awp_news_order']),
);
//print_obj($awp_news_options);
$awp_news_options= wp_parse_args($awp_news_options,array(
'Title' => '',
'Description' => '',
'startdate' => '',
'enddate' => '',
'Link' => '',
'publishedat' =>'',
'publishedby' => '',
'imageurl' =>'',
'showflag' => '',
'order' => ''
));
extract($awp_news_options);
$Description = apply_filters('the_content', $Description);
$response = updateNews($newsId, $Title, $Description, $isFeatured, $startdate, $imageurl, $Link, $publishedat, $publishedby, $order, $enddate,null, $imageurl);
return $response;
}
//Delete news
function delete_news()
{
$newsId = $_REQUEST['tstid'];
$enddate=gmdate(DATE_ATOM,mktime(0,0,0,gmdate('m'),gmdate('d')-1,gmdate('Y')));
$newsId= $_REQUEST['tstid'];
$response = getNewsById($newsId);
$newsdetails = $response->return;
$response = updateNews($newsdetails->newsId,$newsdetails->newsHeadLine,$newsdetails->description, $newsdetails->isFeatured,$newsdetails->startDate,$newsdetails->pageSectionImages, $newsdetails->link, $newsdetails->publishedAt, $newsdetails->publishedBy, $newsdetails->sequenceNumber,$enddate);
return $response;
}
function options()
{
?>
For Complete instructions,see the Developer's Guide.
_plugin_activated){
echo "News Plugin is currently disabled. Please enable this in Apptivo General Settings.";
}
if (isset($_POST['awp_news_add']) && ($_POST['nogdog'] == $_SESSION['apptivo_single_news'])) { //ADD News.
$addnews_response = $this->add_news();
if(strlen(trim($_POST['awp_news_title'])) == 0 )
{
$_SESSION['awp_news_messge'] = 'Please enter a news title.';
}else if($addnews_response == 'E_100') {
$_SESSION['awp_news_messge'] = 'Invalid Keys';
}else if($addnews_response->statusCode != '1000') {
$_SESSION['awp_news_messge'] = ''.$addnews_response->statusMessage.'';
}else {
$_SESSION['awp_news_messge'] = 'News Added Successfully';
}
} else if ($_POST['awp_news_update'] == 'Update') { //Update News.
$updatenews_response = $this->update_news();
if($updatenews_response->return->statusCode != '1000')
{
$_SESSION['awp_news_messge'] = ''.$updatenews_response->return->statusMessage.'';
}else {
$_SESSION['awp_news_messge'] = 'News Updated Successfully';
}
} else if ($_REQUEST['tstmode'] == 'delete') { //Delete News.
$deletenews_response = $this->delete_news();
if($deletenews_response->return->statusCode != '1000')
{
$_SESSION['awp_news_messge'] = ''.$deletenews_response->return->statusMessage.'';
}else {
$_SESSION['awp_news_messge'] = 'News Deleted Successfully';
}
}else {
$_SESSION['awp_news_messge'] = '';
}
switch($_REQUEST['keys'])
{
case fullviewsetting:
$this->fullViewSettings();
break;
case inlineviewsetting:
$this->inlineViewSettings();
break;
default :
$this->get_all_news(); //Display All News.
if ($_REQUEST['tstmode'] == 'edit')
{
$newsId = $_REQUEST['tstid'];
$response = getNewsById($newsId);
$news = $response->return;
if($news->statusCode != '1000')
{
echo '
'.$news->methodResponse->statusMessage.'
';
}
$this->edit_news($news); // News Edit Forms
} else {
$this->news_form(); // News Create Forms.
}
break;
}
?>
save_news_settings();
echo '
Full View Settings Saved Successfully
';
}
$this->fullview_settings();
?>
save_inline_settings();
echo '
Inline View Settings Saved Successfully
';
}
$this->inlineview_settings();
?>
getAllNews();
$numberofitems = count($all_awp_news);
$itemsperpage =5;
$tpages = ceil($numberofitems/$itemsperpage);
$currentpage = intval($_GET['pageno']);
if($currentpage<=0) $currentpage = 1;
if($currentpage>=$tpages) $currentpage = $tpages;
$start = ( $currentpage - 1 ) * $itemsperpage;
$all_awp_news = array_slice( $all_awp_news, $start, $itemsperpage );
$reload = $_SERVER['PHP_SELF'].'?page=awp_news';
if (!empty($_SESSION['awp_news_messge']) && strlen(trim($_SESSION['awp_news_messge'])) != 0) :
echo '
'.$_SESSION['awp_news_messge'].'
';
endif;
if(!empty($all_awp_news[0])){
?>
$itemsperpage)
{
echo awp_paginate($reload,$currentpage,$tpages,$numberofitems);
}
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
newsId )
{
$class = "active";
}else { $class = "inactive"; }
?>
| newsHeadLine; ?> |
description))) < 30)
{
echo strip_tags(html_entity_decode($news->description));
}
else
{
$sub = strip_tags(html_entity_decode($news->description));
echo $sub = substr($sub, 0, 30).'...';
}
?>
|
link; ?> |
publishedAt; ?> |
publishedBy; ?> |
sequenceNumber; ?> |
; ?>) |
; ?>) |
Save the below settings to get the Shortcode for inline view. ';
}
?>
getAllNewsForfullView();
ob_start();
if(empty($awp_news_settings))
{
echo awp_messagelist('newsconfigure-display-page'); //News are not configured.
}else if(empty($awp_news[allnews]))
{
echo awp_messagelist('news-display-page'); //News are not found.
}else { include $awp_news['templatefile']; }
$show_news = ob_get_clean();
return $show_news;
}
function display_news()
{
$awp_news = $this->getAllNewsForInline();
$awp_news['allnews'] = array_slice($awp_news['allnews'],0,$awp_news['itemstoshow']);
unset($awp_news['templatefile']);
unset($awp_news['custom_css']);
return $awp_news;
}
//Short code for inline view
function show_news_inline()
{
$awp_news_inline_settings = get_option('awp_news_inline_settings');
$news_content = $this->getAllNewsForInline();
//$absp_news_content = $news_content;
ob_start();
if(empty($awp_news_inline_settings))
{
echo awp_messagelist('newsconfigure-display-page'); //News are not configured.
} else if(empty($news_content[allnews]))
{
echo awp_messagelist('news-display-page'); //News are not found.
}else { include $news_content['templatefile']; }
$show_news = ob_get_clean();
return $show_news;
}
function getAllNewsForInline(){
$awp_all_news=array();
$awp_news_inline_settings = get_option('awp_news_inline_settings');
$page_details = get_page($awp_news_inline_settings['page_ID']);
$response=getAllNews();
$all_awp_news = awp_convertObjToArray($response->return->newsList);
$allnews=array();
$currentdate = gmdate(DATE_ATOM,mktime());
if( count($all_awp_news)>0){
foreach($all_awp_news as $news){
if(strtotime($news->startDate)<=strtotime($currentdate) && strtotime($news->endDate)>=strtotime($currentdate)){
array_push($allnews,$news);
}
}
}
$awp_all_news = $allnews;
$order=$awp_news_inline_settings['order'];
$awp_all_news = $this->sortNewsByOrder($awp_all_news, $order);
if($awp_news_inline_settings['itemstoshow']!=0){
$numberofitems = $awp_news_inline_settings['itemstoshow'];
}
else{
$numberofitems = count($awp_all_news);
}
if($awp_news_inline_settings['template_type']=="awp_plugin_template") :
$templatefile=AWP_NEWS_TEMPLATEPATH."/".$awp_news_inline_settings['template_layout'];
else :
$templatefile=TEMPLATEPATH."/news/".$awp_news_inline_settings['template_layout'];
endif;
if (!file_exists($templatefile))
{
$templatefile = AWP_NEWS_TEMPLATEPATH."/sliderview1.php";
}
$news = array();
$news['allnews'] = $awp_all_news;
$news['custom_css'] = $awp_news_inline_settings['custom_css'];
$news['itemstoshow'] = $numberofitems;
$news['templatefile'] = $templatefile;
$news['pagelink'] = $page_details->guid;
$news['more_text'] = $awp_news_inline_settings['more_text'];
return $news;
}
function getAllNewsForfullView(){
$awp_news_settings = get_option('awp_news_settings');
if($awp_news_settings['template_type']=="awp_plugin_template") :
$templatefile=AWP_NEWS_TEMPLATEPATH."/".$awp_news_settings['template_layout'];
else :
$templatefile=TEMPLATEPATH."/news/".$awp_news_settings['template_layout'];
endif;
if (!file_exists($templatefile))
{
$templatefile = AWP_NEWS_TEMPLATEPATH."/".AWP_NEWS_DEFAULT_TEMPLATE;
}
$awp_news=array();
$response=getAllNews();
$all_awp_news = awp_convertObjToArray($response->return->newsList);
$allnews=array();
$currentdate = gmdate(DATE_ATOM,mktime());
if( count($all_awp_news)>0){
foreach($all_awp_news as $news){
if(strtotime($news->startDate)<=strtotime($currentdate) && strtotime($news->endDate)>=strtotime($currentdate)){
array_push($allnews,$news);
}
}
}
/* For Default Config*/
$news_pageid = get_option('awp_news_pageid');
if($news_pageid != '') {
if( count($allnews) == 0 || empty($allnews))
{
$allnews = dummy_news();
}
}
/* For Default Config*/
$awp_news = $allnews;
$order=$awp_news_settings['order'];
$awp_news = $this->sortNewsByOrder($awp_news,$order);
$news = array();
$news['allnews'] = $awp_news;
$news['custom_css'] = $awp_news_settings[custom_css];
$news['templatefile'] = $templatefile;
//$news['apptivo_methodresponse'] = $response->return->methodResponse;
return $news;
}
function sortNewsByOrder($awp_all_news,$order){
switch($order){
case '1':
usort($awp_all_news,'awp_creation_date_compare');
break;
case '2':
usort($awp_all_news,'awp_creation_date_compare');
$awp_all_news = array_reverse($awp_all_news);
break;
case '3':
shuffle($awp_all_news);
break;
default:
usort($awp_all_news,'awp_sort_by_sequence');
}
return $awp_all_news;
}
//Full View Settings Form
function fullview_settings() {
$awp_news_settings = get_option('awp_news_settings');
//update page content with shortcode
//themes templates
$awp_tst_themetemplates = $awp_tst_themetemplates = get_awpTemplates(TEMPLATEPATH.'/news','Plugin');
//plugin templates
$awp_tst_plugintemplates = get_awpTemplates(AWP_NEWS_TEMPLATEPATH,'Plugin');
ksort($awp_tst_plugintemplates);
if( empty($awp_news_settings) )
{
echo ' Save the below settings to get the Shortcode for full view. ';
}
?>
$_POST['awp_news_templatetype'],
'template_layout' => $news_layout,
'style' => $_POST['style'],
'custom_css' => stripslashes($_POST['custom_css']),
'order' => $_POST['order'],
'itemstoshow' => $inline_news_itemtoshow,
'more_text' => (trim($_POST['more_text'])!="")?$_POST['more_text']:AWP_DEFAULT_MORE_TEXT,
'page_ID' => $_POST['page_ID'],
);
update_option('awp_news_inline_settings', $awp_news_inline_settings);
}
//Save Testomonials Settings
function save_news_settings() {
if ($_POST['awp_news_templatetype'] == "awp_plugin_template")
$news_layout = $_POST['awp_news_plugintemplatelayout'];
else
$news_layout = $_POST['awp_news_themetemplatelayout'];
$awp_news_settings = array(
'template_type' => $_POST['awp_news_templatetype'],
'template_layout' => $news_layout,
'custom_css' => stripslashes($_POST['custom_css']),
'order' => $_POST['order'],
'page_ID' => $_POST['page_ID'],
'itemsperpage' => (!empty($_POST['itemsperpage'])) ? $_POST['itemsperpage'] : 5
);
update_option('awp_news_settings', $awp_news_settings);
}
//News Form
function news_form(){
?>
return->newsList);
$allnews=array();
$currentdate = gmdate(DATE_ATOM,mktime());
if( count($all_awp_news)>0){
foreach($all_awp_news as $news)
{
if(strtotime($news->startDate)<=strtotime($currentdate) && strtotime($news->endDate)>=strtotime($currentdate)){
array_push($allnews,$news);
}
}
}
return $allnews;
}
}
/** End Class
/**
* get ALL News.
*
* @return unknown
*/
function getAllNews()
{
$pubdate_params = array (
"arg0" => APPTIVO_BUSINESS_API_KEY,
"arg1" => APPTIVO_BUSINESS_ACCESS_KEY
);
$plugin_params = array (
"arg0" => APPTIVO_BUSINESS_API_KEY,
"arg1" => APPTIVO_BUSINESS_ACCESS_KEY
);
$response = get_data(APPTIVO_BUSINESS_SERVICES,'-news-publisheddate','-news-data','getLastPublishDate','getAllNews',$pubdate_params,$plugin_params);
return $response;
}
/**
* To Add News.
*
* @param unknown_type $newsId
* @param unknown_type $newsHeadLine
* @param unknown_type $description
* @param unknown_type $isFeatured
* @param unknown_type $startDate
* @param unknown_type $pageSectionImages
* @param unknown_type $link
* @param unknown_type $publishedAt
* @param unknown_type $publishedBy
* @param unknown_type $sequenceNumber
* @param unknown_type $endDate
* @return unknown
*/
function addNews($newsId, $newsHeadLine, $description, $isFeatured, $startDate, $pageSectionImages, $link, $publishedAt, $publishedBy, $sequenceNumber, $endDate, $creationDate, $newsImages)
{
$mktg_news = new AWP_MktNews($newsId, $newsHeadLine, $description, $isFeatured, $startDate, $pageSectionImages, $link, $publishedAt, $publishedBy, $sequenceNumber, $endDate,null,$newsImages);
$params = array (
"arg0" => APPTIVO_BUSINESS_API_KEY,
"arg1" => APPTIVO_BUSINESS_ACCESS_KEY,
"arg2" => $mktg_news
);
$response = getsoapCall(APPTIVO_BUSINESS_SERVICES,'addNews',$params);
return $response;
}
/**
* To get news for the particular newsId.
*
* @param unknown_type $newsId
* @return unknown
*/
function getNewsById($newsId)
{
$params = array (
"arg0" => APPTIVO_BUSINESS_API_KEY,
"arg1" => APPTIVO_BUSINESS_ACCESS_KEY,
"arg2" => $newsId
);
$response = getsoapCall(APPTIVO_BUSINESS_SERVICES,'getNewsByNewsId',$params);
return $response;
}
/**
* Update News.
*
* @param unknown_type $newsId
* @param unknown_type $newsHeadLine
* @param unknown_type $description
* @param unknown_type $isFeatured
* @param unknown_type $startDate
* @param unknown_type $pageSectionImages
* @param unknown_type $link
* @param unknown_type $publishedAt
* @param unknown_type $publishedBy
* @param unknown_type $sequenceNumber
* @param unknown_type $endDate
* @return unknown
*/
function updateNews($newsId, $newsHeadLine, $description, $isFeatured, $startDate, $pageSectionImages, $link, $publishedAt, $publishedBy, $sequenceNumber, $endDate = '',$creationDate = '',$newsImages = '')
{
$mktg_news = new AWP_MktNews($newsId, $newsHeadLine, $description, $isFeatured, $startDate, $pageSectionImages, $link, $publishedAt, $publishedBy, $sequenceNumber, $endDate, null,$newsImages);
$params = array (
"arg0" => APPTIVO_BUSINESS_API_KEY,
"arg1" => APPTIVO_BUSINESS_ACCESS_KEY,
"arg2" => $mktg_news
);
$response = getsoapCall(APPTIVO_BUSINESS_SERVICES,'updateNews',$params);
return $response;
}
?>