MortgageNews_Embedded
Class MortgageNews_Embedded.
Source Source
File: mortgage-news-widget/inc/MortgageNews_Embedded.php
class MortgageNews_Embedded
{
/**
* Embedded widget.
*
* @access public
* @since 1.0.0
*/
public function embedded()
{
$widget_id = isset($_GET['embeddedid']) ? sanitize_text_field($_GET['embeddedid']) : '';
$type = isset($_GET['type']) ? sanitize_text_field($_GET['type']) : 'bullets';
header('Access-Control-Allow-Origin: *');
echo $this->_embedded($type, $widget_id);
wp_die();
}
/**
* Embedded.
*
* @access protected
* @param string $type type of embedded
* @param string $widget_id Widget ID
* @since 1.0.0
*
* @return string embedded html or blocking message
*/
protected function _embedded($type, $widget_id)
{
switch ($type) {
case 'bullets':
return $this->embedded_bullets($widget_id);
case 'scroller':
return $this->embedded_scroller($widget_id);
case 'text':
return $this->embedded_text($widget_id);
default:
return $this->embedded_bullets($widget_id);
}
}
/**
* Callback function of mortgage news bullets.
* @access public
* @param string $widget_id Widget ID
* @since 1.0.0
* @return string embedded html or blocking message
*/
public function embedded_bullets($widget_id)
{
if (MortgageNewsWidget::$is_active_mortgage_platform) {
$website = new MortgageNews_Websites();
$this->set_website('news_bullet', $widget_id);
if ($website->check_uri('news_bullet', $widget_id)) {
return $this->embedded_bullets_html();
} else {
return $this->block_embed_message();
}
} else {
return $this->embedded_bullets_html();
}
}
/**
* HTML of bullets.
* @access public
* @since 1.0.0
* @return string embedded html or blocking message
*/
public function embedded_bullets_html()
{
$news_bullets = $this->get_scroller_data();
if (!empty($news_bullets) && is_array($news_bullets)) {
$html = '<div class="mortgage-news-container centered mainNewsContent">';
$html .= '<span class="mortgage-news-prev">⬆</span>';
$html .= '<ul class="mortgage-news-list">';
foreach ($news_bullets as $key => $value) {
$html .= '<li>' . $value['title'] . '<a href="' . $value['link'] . '">' . esc_html__('Read more...', 'MortgageNewsWidget') . '</a></li>';
}
$html .= '</ul>';
$html .= '<span class="mortgage-news-next">⬇</span>';
$html .= '</div>';
return $html;
} else {
return '<p>' . esc_html__('Data Not Found', 'MortgageNewsWidget') . '</p>';
}
}
/**
* Callback function of mortgage news scroller.
* @access public
* @param string $widget_id Widget ID
* @since 1.0.0
* @return string embedded html or blocking message
*/
public function embedded_scroller($widget_id)
{
$option = isset($_GET['option']) && !empty($_GET['option']) ? sanitize_text_field($_GET['option']) : 'scroller-1';
$type = 'news_' . $option;
if (MortgageNewsWidget::$is_active_mortgage_platform) {
$website = new MortgageNews_Websites();
$this->set_website($type, $widget_id);
if ($website->check_uri($type, $widget_id)) {
return $this->scroller_type_html($option);
} else {
return $this->block_embed_message();
}
} else {
return $this->scroller_type_html($option);
}
}
/**
* Get data for scrollers.
* @access private
* @since 1.0.0
* @return array {
* News.
* @type string 'title' new title
* @type string 'link' new link
* }
*/
private function get_scroller_data()
{
$news = new MortgageNews();
return $news->get_news();
}
/**
* Get html scroller by type.
*
* @access protected
* @param string $option Type of scroller.
* @since 1.0.0
* @return string embedded html
*/
protected function scroller_type_html($option)
{
$scroller = $this->get_scroller_data();
switch ($option) {
case 'scroller-1':
ob_start();
$this->scroller_html_type1($scroller);
return ob_get_clean();
case 'scroller-2':
ob_start();
$this->scroller_html_type2($scroller);
return ob_get_clean();
case 'scroller-3':
ob_start();
$this->scroller_html_type3($scroller);
return ob_get_clean();
case 'scroller-4':
ob_start();
$this->scroller_html_type4($scroller);
return ob_get_clean();
default :
ob_start();
$this->scroller_html_type1($scroller);
return ob_get_clean();
}
}
/**
* HTML of scroller type 1.
* @access public
* @param array $scroller mortgage news
* @since 1.0.0
*/
public function scroller_html_type1($scroller)
{
?>
<div class="demo-box">
<div class="bn-breaking-news newsTicker-scroller-1" id="newsTicker-scroller-1">
<div class="bn-label"><?php echo esc_attr__('Mortgage news', 'MortgageNewsWidget'); ?></div>
<div class="bn-news">
<ul>
<?php if(is_array($scroller)):
foreach ($scroller as $post) { ?>
<li><a target="_blank" href="<?php echo $post['link'] ?>">
<span><?php echo $post['title'] ?></span>
</a>
</li>
<?php } endif; ?>
</ul>
</div>
<div class="bn-controls">
<button type="button"><span class="bn-arrow bn-prev"></span></button>
<button type="button"><span class="bn-action"></span></button>
<button type="button"><span class="bn-arrow bn-next"></span></button>
</div>
</div>
</div>
<?php
}
/**
* HTML of scroller type 2.
* @access public
* @param array $scroller mortgage news
* @since 1.0.0
*/
public function scroller_html_type2($scroller)
{
?>
<section class="demo-section-box">
<div class="section-container">
<div class="bn-breaking-news mt-30 bg-transparent newsTicker-scroller-2" id="newsTicker-scroller-2">
<div class="bn-news brand-name">
<ul>
<?php if(is_array($scroller)):
foreach ($scroller as $post) { ?>
<li><a target="_blank" href="<?php echo $post['link'] ?>">
<span><?php echo $post['title'] ?></span>
</a>
</li>
<?php } endif; ?>
</ul>
</div>
<div class="bn-controls">
<button type="button" class="btn-theme"><span class="bn-arrow bn-prev"></span></button>
<button type="button" class="w-80 btn-theme"><span class="bn-action"></span></button>
<button type="button" class="btn-theme"><span class="bn-arrow bn-next"></span></button>
</div>
</div>
</div>
</section>
<?php
}
/**
* HTML of scroller type 3.
* @access public
* @param array $scroller mortgage news
* @since 1.0.0
*/
public function scroller_html_type3($scroller)
{
?>
<div class="demo-box">
<div class="bn-breaking-news newsTicker-scroller-3" id="newsTicker-scroller-3">
<div class="bn-label"><?php echo esc_attr__('Mortgage news', 'MortgageNewsWidget'); ?></div>
<div class="bn-news">
<ul>
<?php if(is_array($scroller)):
foreach ($scroller as $post) { ?>
<li><a target="_blank" href="<?php echo $post['link'] ?>">
<span><?php echo $post['title'] ?></span>
</a>
</li>
<?php } endif; ?>
</ul>
</div>
<div class="bn-controls">
<button type="button"><span class="bn-arrow bn-prev"></span></button>
<button type="button"><span class="bn-action"></span></button>
<button type="button"><span class="bn-arrow bn-next"></span></button>
</div>
</div>
</div>
<?php
}
/**
* HTML of scroller type 4.
* @access public
* @param array $scroller mortgage news
* @since 1.0.0
*/
public function scroller_html_type4($scroller)
{
?>
<div class="modern-ticker">
<div class="bn-breaking-news newsTicker-scroller-4" id="newsTicker-scroller-4">
<div class="bn-label"><?php echo esc_attr__('Mortgage news', 'MortgageNewsWidget'); ?></div>
<div class="bn-news">
<ul>
<?php if(is_array($scroller)):
foreach ($scroller as $post) { ?>
<li><a target="_blank" href="<?php echo $post['link'] ?>">
<span><?php echo $post['title'] ?></span>
</a>
</li>
<?php } endif;?>
</ul>
</div>
<div class="bn-controls">
<button type="button"><span class="bn-arrow bn-prev"></span></button>
<button type="button"><span class="bn-action"></span></button>
<button type="button"><span class="bn-arrow bn-next"></span></button>
</div>
</div>
</div>
<?php
}
/**
* Callback function of embedded text.
* @access public
* @param string $widget_id Widget ID
* @since 1.0.0
*
* @return string embedded html or blocking message
*/
public function embedded_text($widget_id)
{
$option = isset($_GET['option']) && !empty($_GET['option']) ? sanitize_text_field($_GET['option']) : 'text';
$type = 'news_' . $option;
if (MortgageNewsWidget::$is_active_mortgage_platform) {
$website = new MortgageNews_Websites();
$this->set_website($type, $widget_id);
if ($website->check_uri($type, $widget_id)) {
return $this->plain_text_html($option);
} else {
return $this->block_embed_message();
}
} else {
return $this->plain_text_html($option);
}
}
/**
* Get html text by type.
*
* @access protected
* @since 1.0.0
*
* @param string $option Type of plaintext
*
* @return string plain text embedded
*/
protected function plain_text_html($option){
$data = $this->get_scroller_data();
if ('plaintext' === $option) {
return $this->plain_text($data, 'plaintext');
} else {
return $this->plain_text($data);
}
}
/**
* HTML of text.
*
* @access public
* @param array $data News.
* @param string $output list or plain text.
* @since 1.0.0
*
* @return string html
*/
public function plain_text($data, $output = 'list')
{
if ('plaintext' === $output) {
$text = '';
foreach ($data as $value) {
$text .= $value['title'] . ',' . $value['link'] . ';';
}
return $text;
} else {
$html = '<ul>';
foreach ($data as $rate) {
$html .= '<li><a target="_blank" href="'. $rate['link'] .'">';
$html .= '<span>'. $rate['title'] .'</span>';
$html .= '</a>';
$html .= '</li>';
}
$html .= '</ul>';
return $html;
}
}
/**
* Blocking message.
*
* @access protected
* @since 1.0.0
* @return string Blocking message.
*/
protected function block_embed_message()
{
return '<p>' . esc_html__('Unfortunately you cannot embed this code. Please contact support.', 'MortgageNewsWidget') . '</p>';
}
/**
* Set website data.
*
* @access public
* @param string $embed Type of embedded widget.
* @param string $widget_id Widget ID.
* @since 1.0.0
*
*/
protected function set_website($embed, $widget_id)
{
$website = new MortgageNews_Websites();
$website->update_uri($embed, $widget_id);
}
}
Methods Methods
- _embedded — Embedded.
- block_embed_message — Blocking message.
- embedded — Embedded widget.
- embedded_bullets — Callback function of mortgage news bullets.
- embedded_bullets_html — HTML of bullets.
- embedded_scroller — Callback function of mortgage news scroller.
- embedded_text — Callback function of embedded text.
- get_scroller_data — Get data for scrollers.
- plain_text — HTML of text.
- plain_text_html — Get html text by type.
- scroller_html_type1 — HTML of scroller type 1.
- scroller_html_type2 — HTML of scroller type 2.
- scroller_html_type3 — HTML of scroller type 3.
- scroller_html_type4 — HTML of scroller type 4.
- scroller_type_html — Get html scroller by type.
- set_website — Set website data.
Changelog Changelog
| Version | Description |
|---|---|
| 1.0.0 | Introduced. |