Skip to content

Commit 4fcc3ee

Browse files
committed
Refactored resources to move init code to plugin, added image upload resource
1 parent 9aa5872 commit 4fcc3ee

File tree

5 files changed

+54
-40
lines changed

5 files changed

+54
-40
lines changed

easyblog/easyblog.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
22
/**
33
* @package API
4-
* @version 1.5
5-
* @author Brian Edgerton
6-
* @link http://www.edgewebworks.com
7-
* @copyright Copyright (C) 2011 Edge Web Works, LLC. All rights reserved.
4+
* @version 1.5.1
5+
* @author Techjoomla
6+
* @link http://techjoomla.com
7+
* @copyright Copyright (C) 2014 Techjoomla. All rights reserved.
88
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
99
*/
1010

@@ -18,9 +18,22 @@ public function __construct(&$subject, $config = array())
1818
{
1919
parent::__construct($subject, $config = array());
2020

21+
$easyblog = JPATH_ROOT . '/administrator/components/com_easyblog/easyblog.php';
22+
if (!JFile::exists($easyblog)) {
23+
ApiError::raiseError(404, 'Easyblog not installed');
24+
return;
25+
}
26+
27+
// Set resources & access
2128
ApiResource::addIncludePath(dirname(__FILE__).'/easyblog');
2229
$this->setResourceAccess('latest', 'public', 'get');
2330
$this->setResourceAccess('category', 'public', 'get');
2431
$this->setResourceAccess('blog', 'public', 'get');
32+
33+
// Load Easyblog language & bootstrap files
34+
$language = JFactory::getLanguage();
35+
$language->load('com_easyblog');
36+
require_once( JPATH_ROOT . '/components/com_easyblog/constants.php' );
37+
require_once( EBLOG_HELPERS . '/helper.php' );
2538
}
2639
}

easyblog/easyblog/blog.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,15 @@
88
jimport( 'simpleschema.person' );
99
jimport( 'simpleschema.blog.post' );
1010

11-
require_once( JPATH_ROOT . '/components/com_easyblog/constants.php' );
12-
require_once( EBLOG_HELPERS . DIRECTORY_SEPARATOR . 'date.php' );
13-
require_once( EBLOG_HELPERS . DIRECTORY_SEPARATOR . 'helper.php' );
14-
require_once( EBLOG_HELPERS . DIRECTORY_SEPARATOR . 'string.php' );
15-
require_once( EBLOG_CLASSES . DIRECTORY_SEPARATOR . 'adsense.php' );
11+
require_once( EBLOG_HELPERS . '/date.php' );
12+
require_once( EBLOG_HELPERS . '/string.php' );
13+
require_once( EBLOG_CLASSES . '/adsense.php' );
1614

1715
class EasyblogApiResourceBlog extends ApiResource
1816
{
1917

2018
public function __construct( &$ubject, $config = array()) {
21-
2219
parent::__construct( $ubject, $config = array() );
23-
$easyblog = JPATH_ROOT . '/administrator/components/com_easyblog/easyblog.php';
24-
if (!JFile::exists($easyblog)) {
25-
$this->plugin->setResponse( $this->getErrorResponse(404, 'Easyblog not installed') );
26-
return;
27-
}
28-
require_once( JPATH_ROOT . '/components/com_easyblog/helpers/helper.php' );
2920
}
3021

3122
public function post()

easyblog/easyblog/category.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,15 @@
88
jimport( 'simpleschema.person' );
99
jimport( 'simpleschema.blog.post' );
1010

11-
require_once( JPATH_ROOT . '/components/com_easyblog/constants.php' );
12-
require_once( EBLOG_HELPERS . DIRECTORY_SEPARATOR . 'date.php' );
13-
require_once( EBLOG_HELPERS . DIRECTORY_SEPARATOR . 'helper.php' );
14-
require_once( EBLOG_HELPERS . DIRECTORY_SEPARATOR . 'string.php' );
15-
require_once( EBLOG_CLASSES . DIRECTORY_SEPARATOR . 'adsense.php' );
11+
require_once( EBLOG_HELPERS . '/date.php' );
12+
require_once( EBLOG_HELPERS . '/string.php' );
13+
require_once( EBLOG_CLASSES . '/adsense.php' );
1614

1715
class EasyblogApiResourceCategory extends ApiResource
1816
{
1917

2018
public function __construct( &$ubject, $config = array()) {
21-
2219
parent::__construct( $ubject, $config = array() );
23-
$easyblog = JPATH_ROOT . '/administrator/components/com_easyblog/easyblog.php';
24-
if (!JFile::exists($easyblog)) {
25-
$this->plugin->setResponse( $this->getErrorResponse(404, 'Easyblog not installed') );
26-
return;
27-
}
28-
require_once( JPATH_ROOT . '/components/com_easyblog/helpers/helper.php' );
2920
}
3021

3122
public function get() {

easyblog/easyblog/image.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
defined('_JEXEC') or die( 'Restricted access' );
3+
//error_reporting(E_ALL);
4+
//ini_set('display_errors', 1);
5+
6+
jimport('joomla.user.user');
7+
8+
class EasyblogApiResourceImage extends ApiResource
9+
{
10+
11+
public function __construct( &$ubject, $config = array()) {
12+
parent::__construct( $ubject, $config = array() );
13+
}
14+
15+
public function post()
16+
{
17+
$controller = new EasyBlogControllerMedia;
18+
$op = $controller->upload();
19+
20+
// No setResponse needed since the upload method spits JSON and dies
21+
}
22+
23+
public function get() {
24+
$this->plugin->setResponse( $this->getErrorResponse(404, __FUNCTION__ . ' not supported' ) );
25+
}
26+
27+
}

easyblog/easyblog/latest.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,16 @@
88
jimport( 'simpleschema.person' );
99
jimport( 'simpleschema.blog.post' );
1010

11-
require_once( JPATH_ROOT . '/components/com_easyblog/constants.php' );
12-
require_once( EBLOG_HELPERS . DIRECTORY_SEPARATOR . 'date.php' );
13-
require_once( EBLOG_HELPERS . DIRECTORY_SEPARATOR . 'helper.php' );
14-
require_once( EBLOG_HELPERS . DIRECTORY_SEPARATOR . 'string.php' );
15-
require_once( EBLOG_CLASSES . DIRECTORY_SEPARATOR . 'adsense.php' );
11+
require_once( EBLOG_HELPERS . '/date.php' );
12+
require_once( EBLOG_HELPERS . '/string.php' );
13+
require_once( EBLOG_CLASSES . '/adsense.php' );
1614

1715
class EasyblogApiResourceLatest extends ApiResource
1816
{
1917

2018
public function __construct( &$ubject, $config = array()) {
21-
2219
parent::__construct( $ubject, $config = array() );
23-
$easyblog = JPATH_ROOT . '/administrator/components/com_easyblog/easyblog.php';
24-
if (!JFile::exists($easyblog)) {
25-
$this->plugin->setResponse( $this->getErrorResponse(404, 'Easyblog not installed') );
26-
return;
27-
}
28-
require_once( JPATH_ROOT . '/components/com_easyblog/helpers/helper.php' );
20+
2921
}
3022

3123
public function get() {

0 commit comments

Comments
 (0)