Skip to content

Commit

Permalink
Added easyblog API
Browse files Browse the repository at this point in the history
  • Loading branch information
coolbung committed Sep 16, 2014
1 parent 558c865 commit 8b446b0
Show file tree
Hide file tree
Showing 8 changed files with 271 additions and 218 deletions.
23 changes: 23 additions & 0 deletions easyblog/easyblog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* @package API
* @version 1.5
* @author Brian Edgerton
* @link http://www.edgewebworks.com
* @copyright Copyright (C) 2011 Edge Web Works, LLC. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
*/

defined('_JEXEC') or die( 'Restricted access' );

jimport('joomla.plugin.plugin');

class plgAPIEasyblog extends ApiPlugin
{
public function __construct(&$subject, $config = array())
{
parent::__construct($subject, $config = array());

ApiResource::addIncludePath(dirname(__FILE__).'/easyblog');
}
}
17 changes: 17 additions & 0 deletions easyblog/easyblog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<extension version="2.5.0" type="plugin" group="api" method="upgrade">
<name>Api - Easyblog</name>
<version>1.0</version>
<creationDate>July 2014</creationDate>
<author>techjoomla</author>
<authorEmail>[email protected]</authorEmail>
<authorUrl>http://techjoomla.com</authorUrl>
<copyright>Techjoomla</copyright>
<license>GNU General Public License v2</license>
<description>Easyblog APIs</description>

<files>
<filename plugin="easyblog">easyblog.php</filename>
<folder>easyblog</folder>
</files>
</extension>
78 changes: 78 additions & 0 deletions easyblog/easyblog/blog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
defined('_JEXEC') or die( 'Restricted access' );
//error_reporting(E_ALL);
//ini_set('display_errors', 1);

jimport('joomla.user.user');
jimport( 'simpleschema.category' );
jimport( 'simpleschema.person' );
jimport( 'simpleschema.blog.post' );

require_once( JPATH_ROOT . '/components/com_easyblog/constants.php' );
require_once( EBLOG_HELPERS . DIRECTORY_SEPARATOR . 'date.php' );
require_once( EBLOG_HELPERS . DIRECTORY_SEPARATOR . 'helper.php' );
require_once( EBLOG_HELPERS . DIRECTORY_SEPARATOR . 'string.php' );
require_once( EBLOG_CLASSES . DIRECTORY_SEPARATOR . 'adsense.php' );

class EasyblogApiResourceBlog extends ApiResource
{

public function __construct( &$ubject, $config = array()) {

parent::__construct( $ubject, $config = array() );
$easyblog = JPATH_ROOT . '/administrator/components/com_easyblog/easyblog.php';
if (!JFile::exists($easyblog)) {
$this->plugin->setResponse( $this->getErrorResponse(404, 'Easyblog not installed') );
return;
}
require_once( JPATH_ROOT . '/components/com_easyblog/helpers/helper.php' );
}
public function delete()
{
$this->plugin->setResponse( 'in delete' );
}

public function post()
{
$input = JFactory::getApplication()->input;
$blog = EasyBlogHelper::getTable( 'Blog', 'Table' );
$post = $input->post->getArray(array());

$blog->bind($post);
$blog->created_by = $this->plugin->getUser()->id;

if (!$blog->store()) {
$this->plugin->setResponse( $this->getErrorResponse(404, $blog->getError()) );
return;
}

$item = EasyBlogHelper::getHelper( 'SimpleSchema' )->mapPost($blog, '<p><br><pre><a><blockquote><strong><h2><h3><em><ul><ol><li>');
$this->plugin->setResponse( $item );

}

public function get() {
$input = JFactory::getApplication()->input;
$model = EasyBlogHelper::getModel( 'Blog' );
$config = EasyBlogHelper::getConfig();
$id = $input->get('id', null, 'INT');

// If we have an id try to fetch the user
$blog = EasyBlogHelper::getTable( 'Blog' );
$blog->load( $id );

if (!$id) {
$this->plugin->setResponse( $this->getErrorResponse(404, 'Blog id cannot be blank') );
return;
}

if (!$blog->id) {
$this->plugin->setResponse( $this->getErrorResponse(404, 'Blog not found') );
return;
}

$item = EasyBlogHelper::getHelper( 'SimpleSchema' )->mapPost($blog, '<p><br><pre><a><blockquote><strong><h2><h3><em><ul><ol><li>');
$this->plugin->setResponse( $config->get('comment_disqus_code') );
}

}
75 changes: 75 additions & 0 deletions easyblog/easyblog/category.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
defined('_JEXEC') or die( 'Restricted access' );
//error_reporting(E_ALL);
//ini_set('display_errors', 1);

jimport('joomla.user.user');
jimport( 'simpleschema.category' );
jimport( 'simpleschema.person' );
jimport( 'simpleschema.blog.post' );

require_once( JPATH_ROOT . '/components/com_easyblog/constants.php' );
require_once( EBLOG_HELPERS . DIRECTORY_SEPARATOR . 'date.php' );
require_once( EBLOG_HELPERS . DIRECTORY_SEPARATOR . 'helper.php' );
require_once( EBLOG_HELPERS . DIRECTORY_SEPARATOR . 'string.php' );
require_once( EBLOG_CLASSES . DIRECTORY_SEPARATOR . 'adsense.php' );

class EasyblogApiResourceCategory extends ApiResource
{

public function __construct( &$ubject, $config = array()) {

parent::__construct( $ubject, $config = array() );
$easyblog = JPATH_ROOT . '/administrator/components/com_easyblog/easyblog.php';
if (!JFile::exists($easyblog)) {
$this->plugin->setResponse( $this->getErrorResponse(404, 'Easyblog not installed') );
return;
}
require_once( JPATH_ROOT . '/components/com_easyblog/helpers/helper.php' );
}
public function delete()
{
$this->plugin->setResponse( 'in delete' );
}

public function post()
{
$this->plugin->setResponse( 'in post' );
}

public function get() {
$input = JFactory::getApplication()->input;
$model = EasyBlogHelper::getModel( 'Blog' );
$category = EasyBlogHelper::getTable( 'Category', 'Table' );
$id = $input->get('id', null, 'INT');
$search = $input->get('search', null, 'STRING');
$posts = array();

$category->load($id);

// private category shouldn't allow to access.
$privacy = $category->checkPrivacy();

if(! $privacy->allowed )
{
$this->plugin->setResponse( $this->getErrorResponse(404, 'Category not found') );
return;
}

$catIds = array();
$catIds[] = $category->id;
EasyBlogHelper::accessNestedCategoriesId($category, $catIds);

$sorting = $this->plugin->params->get( 'sorting' , 'latest' );
$total = (int) $this->plugin->params->get( 'total' , 20 );
$rows = $model->getBlogsBy( 'category' , $catIds , $sorting , $total, EBLOG_FILTER_PUBLISHED, $search );

foreach ($rows as $k => $v) {
$item = EasyBlogHelper::getHelper( 'SimpleSchema' )->mapPost($v, '', 100, array('text'));
$posts[] = $item;
}

$this->plugin->setResponse( $posts );
}

}
73 changes: 73 additions & 0 deletions easyblog/easyblog/latest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
defined('_JEXEC') or die( 'Restricted access' );
//error_reporting(E_ALL);
//ini_set('display_errors', 1);

jimport('joomla.user.user');
jimport( 'simpleschema.category' );
jimport( 'simpleschema.person' );
jimport( 'simpleschema.blog.post' );

require_once( JPATH_ROOT . '/components/com_easyblog/constants.php' );
require_once( EBLOG_HELPERS . DIRECTORY_SEPARATOR . 'date.php' );
require_once( EBLOG_HELPERS . DIRECTORY_SEPARATOR . 'helper.php' );
require_once( EBLOG_HELPERS . DIRECTORY_SEPARATOR . 'string.php' );
require_once( EBLOG_CLASSES . DIRECTORY_SEPARATOR . 'adsense.php' );

class EasyblogApiResourceLatest extends ApiResource
{

public function __construct( &$ubject, $config = array()) {

parent::__construct( $ubject, $config = array() );
$easyblog = JPATH_ROOT . '/administrator/components/com_easyblog/easyblog.php';
if (!JFile::exists($easyblog)) {
$this->plugin->setResponse( $this->getErrorResponse(404, 'Easyblog not installed') );
return;
}
require_once( JPATH_ROOT . '/components/com_easyblog/helpers/helper.php' );
}
public function delete()
{
$this->plugin->setResponse( 'in delete' );
}

public function post()
{
$this->plugin->setResponse( 'in post' );
}

public function get() {
$input = JFactory::getApplication()->input;
$model = EasyBlogHelper::getModel( 'Blog' );
$id = $input->get('id', null, 'INT');
$search = $input->get('search', null, 'STRING');
$posts = array();

// If we have an id try to fetch the user
$blog = EasyBlogHelper::getTable( 'Blog' );
$blog->load( $id );

if ($id) {
if(!$blog->id) {
$this->plugin->setResponse( $this->getErrorResponse(404, 'Blog not found') );
return;
}

$this->plugin->setResponse( $blog );
} else {

$sorting = $this->plugin->params->get( 'sorting' , 'latest' );
$total = (int) $this->plugin->params->get( 'total' , 20 );
$rows = $model->getBlogsBy( $sorting , '' , $sorting , $total, EBLOG_FILTER_PUBLISHED, $search );

foreach ($rows as $k => $v) {
$item = EasyBlogHelper::getHelper( 'SimpleSchema' )->mapPost($v, '', 100, array('text'));
$posts[] = $item;
}

$this->plugin->setResponse( $posts );
}
}

}
7 changes: 5 additions & 2 deletions users/users.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@

class plgAPIUsers extends ApiPlugin
{
public function __construct()
public function __construct(&$subject, $config = array())
{
parent::__construct();
parent::__construct($subject, $config = array());

ApiResource::addIncludePath(dirname(__FILE__).'/users');

// Set the login resource to be public
$this->setResourceAccess('login', 'public');
}
}
73 changes: 0 additions & 73 deletions users/users/users_delete.php

This file was deleted.

Loading

0 comments on commit 8b446b0

Please sign in to comment.