first
This commit is contained in:
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Nextend\Framework\Content;
|
||||
|
||||
abstract class AbstractPlatformContent {
|
||||
|
||||
/**
|
||||
* @param $keyword
|
||||
*
|
||||
* @return array links
|
||||
* $links[] = array(
|
||||
* 'title' => '',
|
||||
* 'link' => '',
|
||||
* 'info' => ''
|
||||
* );
|
||||
*/
|
||||
abstract public function searchLink($keyword);
|
||||
|
||||
|
||||
/**
|
||||
* @param $keyword
|
||||
*
|
||||
* @return array links
|
||||
* $links[] = array(
|
||||
* 'title' => '',
|
||||
* 'description' => '',
|
||||
* 'image' => '',
|
||||
* 'link' => '',
|
||||
* 'info' => ''
|
||||
* );
|
||||
*/
|
||||
abstract public function searchContent($keyword);
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Nextend\Framework\Content;
|
||||
|
||||
use Nextend\Framework\Content\Joomla\JoomlaContent;
|
||||
use Nextend\Framework\Content\WordPress\WordPressContent;
|
||||
|
||||
class Content {
|
||||
|
||||
/**
|
||||
* @var AbstractPlatformContent
|
||||
*/
|
||||
private static $platformContent;
|
||||
|
||||
public function __construct() {
|
||||
self::$platformContent = new WordPressContent();
|
||||
}
|
||||
|
||||
public static function searchLink($keyword) {
|
||||
return self::$platformContent->searchLink($keyword);
|
||||
}
|
||||
|
||||
public static function searchContent($keyword) {
|
||||
return self::$platformContent->searchContent($keyword);
|
||||
}
|
||||
}
|
||||
|
||||
new Content();
|
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Nextend\Framework\Content;
|
||||
|
||||
|
||||
use Nextend\Framework\Controller\Admin\AdminAjaxController;
|
||||
use Nextend\Framework\Request\Request;
|
||||
|
||||
class ControllerAjaxContent extends AdminAjaxController {
|
||||
|
||||
public function actionSearchLink() {
|
||||
$this->validateToken();
|
||||
|
||||
$keyword = Request::$REQUEST->getVar('keyword', '');
|
||||
$this->response->respond(Content::searchLink($keyword));
|
||||
}
|
||||
|
||||
public function actionSearchContent() {
|
||||
$this->validateToken();
|
||||
|
||||
$keyword = Request::$REQUEST->getVar('keyword', '');
|
||||
$this->response->respond(Content::searchContent($keyword));
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace Nextend\Framework\Content\WordPress;
|
||||
|
||||
use Nextend\Framework\Content\AbstractPlatformContent;
|
||||
use WP_Query;
|
||||
use function get_post_thumbnail_id;
|
||||
use function get_post_type;
|
||||
use function get_post_type_object;
|
||||
use function get_the_excerpt;
|
||||
use function get_the_ID;
|
||||
use function get_the_permalink;
|
||||
use function get_the_title;
|
||||
use function wp_get_attachment_url;
|
||||
|
||||
class WordPressContent extends AbstractPlatformContent {
|
||||
|
||||
public function searchLink($keyword) {
|
||||
|
||||
$the_query = new WP_Query('post_type=any&posts_per_page=20&post_status=publish&s=' . $keyword);
|
||||
|
||||
$links = array();
|
||||
if ($the_query->have_posts()) {
|
||||
while ($the_query->have_posts()) {
|
||||
$the_query->the_post();
|
||||
|
||||
$link = array(
|
||||
'title' => get_the_title(),
|
||||
'link' => get_the_permalink(),
|
||||
'info' => get_post_type_object(get_post_type())->labels->singular_name
|
||||
);
|
||||
|
||||
$links[] = $link;
|
||||
|
||||
}
|
||||
}
|
||||
/* Restore original Post Data */
|
||||
wp_reset_postdata();
|
||||
|
||||
return $links;
|
||||
}
|
||||
|
||||
public function searchContent($keyword) {
|
||||
|
||||
$the_query = new WP_Query('post_type=any&posts_per_page=20&post_status=publish&s=' . $keyword);
|
||||
|
||||
$links = array();
|
||||
if ($the_query->have_posts()) {
|
||||
while ($the_query->have_posts()) {
|
||||
$the_query->the_post();
|
||||
|
||||
$link = array(
|
||||
'title' => get_the_title(),
|
||||
'description' => get_the_excerpt(),
|
||||
'image' => wp_get_attachment_url(get_post_thumbnail_id(get_the_ID())),
|
||||
'link' => get_the_permalink(),
|
||||
'info' => get_post_type_object(get_post_type())->labels->singular_name
|
||||
);
|
||||
|
||||
$links[] = $link;
|
||||
|
||||
}
|
||||
}
|
||||
/* Restore original Post Data */
|
||||
wp_reset_postdata();
|
||||
|
||||
return $links;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user