Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api development till package 1.8.4 #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions easyblog/components/com_easyblog/helpers/simpleschema.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
<?php
/**
* @package EasyBlog
* @copyright Copyright (C) 2011 Stack Ideas Private Limited. All rights reserved.
* @license GNU/GPL, see LICENSE.php
*
* EasyBlog is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/

defined('_JEXEC') or die('Restricted access');
jimport( 'simpleschema.blog.post' );

class EasyBlogSimpleSchemaHelper
class EasyBlogSimpleSchemaHelper11
{
public function mapPost($row, $strip_tags='', $text_length=0, $skip=array()) {
$config = EasyBlogHelper::getConfig();
Expand All @@ -23,11 +34,17 @@ public function mapPost($row, $strip_tags='', $text_length=0, $skip=array()) {
$formatDate = false;
}
$blog->created = $created->toMySQL();
$blog->text = $row->intro . $row->content;

if( $config->get( 'main_rss_content' ) == 'introtext' )
{
$blog->text = ( !empty( $row->intro ) ) ? $row->intro : $row->content;
}
else
{
$blog->text = $row->intro . $row->content;

$config->set('max_video_width', 320);
$config->set('max_video_width', 180);
$blog->text = EasyBlogHelper::getHelper( 'Videos' )->processVideos( $blog->text );
}
$blog->text = EasyBlogHelper::getHelper( 'Videos' )->strip( $blog->text );
$blog->text = EasyBlogGoogleAdsense::stripAdsenseCode( $blog->text );

$category = EasyBlogHelper::getTable( 'Category', 'Table' );
Expand Down Expand Up @@ -64,12 +81,8 @@ public function mapPost($row, $strip_tags='', $text_length=0, $skip=array()) {

$item->category->categoryid = $category->id;
$item->category->title = $category->title;

$item->url = JURI::root() . trim(EasyBlogRouter::_('index.php?option=com_easyblog&view=entry&id=' . $blog->id ), '/');

// Tags
$modelPT = EasyBlogHelper::getModel( 'PostTag' );
$item->tags = $modelPT->getBlogTags($blog->id);

$item->url = JURI::root() . trim('index.php?option=com_easyblog&view=entry&id=' . $blog->id, '/');

foreach ($skip as $v) {
unset($item->$v);
Expand Down
35 changes: 30 additions & 5 deletions easyblog/easyblog.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,50 @@ class plgAPIEasyblog extends ApiPlugin
public function __construct(&$subject, $config = array())
{
parent::__construct($subject, $config = array());

/*load language file for plugin frontend*/
$lang = JFactory::getLanguage();
$lang->load('plg_api_easyblog', JPATH_ADMINISTRATOR,'',true);

$easyblog = JPATH_ROOT . '/administrator/components/com_easyblog/easyblog.php';
if (!JFile::exists($easyblog) || !JComponentHelper::isEnabled('com_easysocial', true)) {
if (!JFile::exists($easyblog) || !JComponentHelper::isEnabled('com_easyblog', true)) {
ApiError::raiseError(404, 'Easyblog not installed');
return;
}


//load helper file
require_once JPATH_SITE.'/plugins/api/easyblog/helper/simpleschema.php';
// Load Easyblog language & bootstrap files
$language = JFactory::getLanguage();
$language->load('com_easyblog');
require_once( JPATH_ROOT . '/components/com_easyblog/constants.php' );
require_once( EBLOG_HELPERS . '/helper.php' );

$xml = JFactory::getXML(JPATH_ADMINISTRATOR .'/components/com_easyblog/easyblog.xml');
$version = (string)$xml->version;

if($version<5)
{
require_once( JPATH_ROOT . '/components/com_easyblog/constants.php' );
require_once( JPATH_ROOT . '/components/com_easyblog/helpers/helper.php' );
ApiResource::addIncludePath(dirname(__FILE__).'/easyblog4');
}
else
{
ApiResource::addIncludePath(dirname(__FILE__).'/easyblog5');
require_once JPATH_ADMINISTRATOR.'/components/com_easyblog/includes/easyblog.php';
require_once JPATH_ADMINISTRATOR.'/components/com_easyblog/includes/constants.php' ;
//require_once JPATH_ADMINISTRATOR.'/components/com_easyblog/includes/gettable/gettable.php' ;
require_once( JPATH_ADMINISTRATOR.'/components/com_easyblog/includes'. '/date/date.php' );
require_once( JPATH_ADMINISTRATOR.'/components/com_easyblog/includes'. '/string/string.php' );
require_once( JPATH_ADMINISTRATOR.'/components/com_easyblog/includes'. '/adsense/adsense.php' );
}

// Set resources & access
ApiResource::addIncludePath(dirname(__FILE__).'/easyblog');
$this->setResourceAccess('latest', 'public', 'get');
$this->setResourceAccess('category', 'public', 'get');
$this->setResourceAccess('blog', 'public', 'get');
$this->setResourceAccess('blog', 'public', 'post');
$this->setResourceAccess('comments', 'public', 'get');
$this->setResourceAccess('easyblog_users', 'public', 'get');

$config = EasyBlogHelper::getConfig();
if ($config->get('main_allowguestcomment')) {
Expand Down
29 changes: 25 additions & 4 deletions easyblog/easyblog.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<extension version="2.5.0" type="plugin" group="api" method="upgrade">
<name>Api - Easyblog</name>
<version>1.6</version>
<version>1.8.4</version>
<creationDate>10/11/2014</creationDate>
<author>Techjoomla</author>
<authorEmail>extensions@techjoomla.com</authorEmail>
<authorUrl>www.techjoomla.com</authorUrl>
<copyright>Techjoomla. All rights reserved.</copyright>
<license>http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL</license>
<description>Easyblog APIs</description>
<scriptfile>script.php</scriptfile>
<description>PLG_API_EASYBLOG_DESCRIPTION</description>
<files>
<filename plugin="easyblog">easyblog.php</filename>
<folder>easyblog</folder>
<folder>easyblog4</folder>
<folder>easyblog5</folder>
<folder>helper</folder>
<folder>components</folder>
<folder>libraries</folder>
</files>

<languages folder="language">
<language tag="en-GB">en-GB/en-GB.plg_api_easyblog.ini</language>
<language tag="en-GB">en-GB/en-GB.plg_api_easyblog.sys.ini</language>
</languages>

<config>
<fields name="params">
<fieldset name="advanced">
<field
name="retain_tags"
type="text"
default=""
label="HTML Tags to retain"
description="Comma separated list of tags (p,br,h1,h2,h3,img......) to allow in the API, so that the mobile app will be able to show the relevant content. Note that not all tags will work, and some tags may not have the desired effects since tags are handled differently between browsers and apps. Eg: Retaining the iframe tag might not ensure that the iframe is always displayed correctly, but allowing the iframe tag is necessary if you have embedded videos in your blogs"
filter="string"
size="50" />
</fieldset>
</fields>
</config>
</extension>
146 changes: 146 additions & 0 deletions easyblog/easyblog4/blog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
<?php
/**
* @package API plugins
* @copyright Copyright (C) 2009 2014 Techjoomla, Tekdi Technologies Pvt. Ltd. All rights reserved.
* @license GNU GPLv2 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
* @link http://www.techjoomla.com
*/

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

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

require_once( EBLOG_HELPERS . '/date.php' );
require_once( EBLOG_HELPERS . '/string.php' );
require_once( EBLOG_CLASSES . '/adsense.php' );

//for image upload
require_once( EBLOG_CLASSES . '/mediamanager.php' );
require_once( EBLOG_HELPERS . '/image.php' );
require_once( EBLOG_CLASSES . '/easysimpleimage.php' );
require_once( EBLOG_CLASSES . '/mediamanager/local.php' );
require_once( EBLOG_CLASSES . '/mediamanager/types/image.php' );

class EasyblogApiResourceBlog extends ApiResource
{

public function __construct( &$ubject, $config = array()) {
parent::__construct( $ubject, $config = array() );
}
public function delete()
{
$this->plugin->setResponse($this->delete_blog());
}
public function post()
{
$input = JFactory::getApplication()->input;
$blog = EasyBlogHelper::getTable( 'Blog', 'Table' );
$post = $input->post->getArray(array());
$log_user = $this->plugin->get('user')->id;
$createTag = array();
$res = new stdClass;

//code for upload
$blog->bind($post,true);

$blog->permalink = str_replace('+','-',$blog->title);
//for publish unpublish blog.
$blog->published = $post['published'];
//create tags for blog
$createTag = $post['tags'];

//$blog->write_content = 1;
//$blog->write_content_hidden = 1;

$blog->created_by = $log_user;

$blog->created = date("Y-m-d h:i:s");
$blog->publish_up = date("Y-m-d h:i:s");

//$blog->created = EasyBlogHelper::getDate();
//get date from app
//$blog->publish_up = EasyBlogHelper::getDate();

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

if (!$blog->store()) {
$this->plugin->setResponse( $this->getErrorResponse(404, $blog->getError()) );
return;
}
//create tags for blog called the function
$blog->processTags( $createTag, 1 );
$blog->processTrackbacks();
//$item = EasyBlogHelper::getHelper( 'SimpleSchema' )->mapPost($blog, '<p><br><pre><a><blockquote><strong><h2><h3><em><ul><ol><li>');
$scm_obj = new EasyBlogSimpleSchema_4();
$item = $scm_obj->mapPost($v,'', 100, array('text'));

$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, JText::_( 'PLG_API_EASYBLOG_BLOG_ID_MESSAGE' )) );
return;
}

if (!$blog->id)
{
$this->plugin->setResponse( $this->getErrorResponse(404, JText::_( 'PLG_API_EASYBLOG_BLOG_NOT_FOUND_MESSAGE' )) );
return;
}

//$item = EasyBlogHelper::getHelper( 'SimpleSchema' )->mapPost($blog, '<p><br><pre><a><blockquote><strong><h2><h3><em><ul><ol><li><iframe>');
$scm_obj = new EasyBlogSimpleSchema_4();
$item = $scm_obj->mapPost($blog, '<p><br><pre><a><blockquote><strong><h2><h3><em><ul><ol><li><iframe>');

$item->isowner = ( $blog->created_by == $this->plugin->get('user')->id )?true:false;
$item->allowcomment = $blog->allowcomment;

$item->allowsubscribe = $blog->subscription;

// Tags
$modelPT = EasyBlogHelper::getModel( 'PostTag' );
$item->tags = $modelPT->getBlogTags($blog->id);

//created by vishal - for show extra images
//$item->text = preg_replace('/"images/i', '"'.JURI::root().'images', $item->text );
$item->text = str_replace('href="','href="'.JURI::root(),$item->text);
$item->text = str_replace('src="','src="'.JURI::root(),$item->text);

$this->plugin->setResponse( $item );
}
public function delete_blog()
{
$app = JFactory::getApplication();
$id = $app->input->get('id',0,'INT');
$blog = EasyBlogHelper::getTable( 'Blog', 'Table' );
$blog->load( $id );
if(!$blog->id || !$id)
{
$res->status =0;
$res->message=JText::_( 'PLG_API_EASYBLOG_BLOG_NOT_EXISTS_MESSAGE' );
return $res;
}
else
{
$val = $blog->delete($id);
$re->status = $val;
$res->message=JText::_( 'PLG_API_EASYBLOG_DELETE_MESSAGE' );
return $res;
}
}
}
Loading