-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d52bd46
Showing
24 changed files
with
1,011 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php defined( 'SYSPATH' ) or die( 'No direct script access.' ); | ||
|
||
class Controller_API_Page_Parts extends KodiCMS_Controller_API_Page_Parts {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php defined('SYSPATH') or die('No direct access allowed.'); | ||
|
||
abstract class Filter_Decorator extends KodiCMS_Filter_Decorator {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php defined('SYSPATH') or die('No direct access allowed.'); | ||
|
||
class Filter_Default extends KodiCMS_Filter_Default {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php defined( 'SYSPATH' ) or die( 'No direct script access.' ); | ||
|
||
/** | ||
* @package KodiCMS/Page_Parts | ||
* @category API | ||
* @author butschster <butschster@gmail.com> | ||
* @link http://kodicms.ru | ||
* @copyright (c) 2012-2014 butschster | ||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt | ||
*/ | ||
class KodiCMS_Controller_API_Page_Parts extends Controller_System_Api { | ||
|
||
public function get_get() | ||
{ | ||
$page_id = $this->param('pid', NULL, TRUE); | ||
|
||
$parts = Model_API::factory('api_page_part') | ||
->get_all($page_id, $this->fields); | ||
|
||
$this->response($parts); | ||
} | ||
|
||
public function rest_get() | ||
{ | ||
return $this->get_get(); | ||
} | ||
|
||
public function rest_put() | ||
{ | ||
$id = $this->param('id', NULL, TRUE); | ||
$part = ORM::factory('page_part', (int) $id); | ||
|
||
$response = $part | ||
->values($this->params()) | ||
->save() | ||
->object(); | ||
|
||
$response['is_developer'] = (int) Auth::has_permissions('administrator, developer'); | ||
$this->response($response); | ||
} | ||
|
||
public function rest_post() | ||
{ | ||
$part = ORM::factory('page_part'); | ||
|
||
$response = $part | ||
->values($this->params()) | ||
->save() | ||
->as_array(); | ||
|
||
$response['is_developer'] = (int) Auth::has_permissions('administrator, developer'); | ||
$this->response($response); | ||
} | ||
|
||
public function rest_delete() | ||
{ | ||
$id = $this->param('id', NULL, TRUE); | ||
|
||
$part = ORM::factory('page_part', (int) $id); | ||
$part->delete(); | ||
} | ||
|
||
public function post_reorder() | ||
{ | ||
if (!ACL::check('parts.reorder')) | ||
{ | ||
return; | ||
} | ||
|
||
$ids = $this->param('ids', array()); | ||
ORM::factory('page_part')->sort($ids); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php defined('SYSPATH') or die('No direct access allowed.'); | ||
|
||
abstract class KodiCMS_Filter_Decorator { | ||
|
||
/** | ||
* @param string $text | ||
* @return string | ||
*/ | ||
abstract public function apply($text); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php defined('SYSPATH') or die('No direct access allowed.'); | ||
|
||
class KodiCMS_Filter_Default extends Filter_Decorator { | ||
|
||
/** | ||
* @param string $text | ||
* @return string | ||
*/ | ||
public function apply($text) | ||
{ | ||
return $text; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php defined( 'SYSPATH' ) or die( 'No direct access allowed.' ); | ||
|
||
/** | ||
* @package KodiCMS/Page_Parts | ||
* @category Model/Api | ||
* @author butschster <butschster@gmail.com> | ||
* @link http://kodicms.ru | ||
* @copyright (c) 2012-2014 butschster | ||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt | ||
*/ | ||
class KodiCMS_Model_API_Page_Part extends Model_API { | ||
|
||
protected $_table_name = 'page_parts'; | ||
protected $_secured_columns = array( | ||
'content', 'content_html' | ||
); | ||
|
||
public function get_all($page_id, $fields = array()) | ||
{ | ||
$fields = $this->prepare_param($fields); | ||
|
||
$parts = DB::select('id', 'name') | ||
->select_array($this->filtered_fields($fields)) | ||
->from($this->table_name()) | ||
->where('page_id', '=', (int) $page_id) | ||
->order_by('position') | ||
->cache_tags(array('page_parts')) | ||
->cached((int) Config::get('cache', 'page_parts')) | ||
->execute() | ||
->as_array(); | ||
|
||
$is_developer = (int) Auth::has_permissions('administrator, developer'); | ||
|
||
foreach ($parts as & $part) | ||
{ | ||
$part['is_developer'] = $is_developer; | ||
} | ||
|
||
return $parts; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?php defined('SYSPATH') or die('No direct access allowed.'); | ||
|
||
/** | ||
* @package KodiCMS/Page_Parts | ||
* @category Model | ||
* @author butschster <butschster@gmail.com> | ||
* @link http://kodicms.ru | ||
* @copyright (c) 2012-2014 butschster | ||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt | ||
*/ | ||
class KodiCMS_Model_Page_Part extends ORM | ||
{ | ||
const PART_NOT_PROTECTED = 0; | ||
const PART_PROTECTED = 1; | ||
|
||
protected $_reload_on_wakeup = FALSE; | ||
|
||
protected $_belongs_to = array( | ||
'page' => array( | ||
'model' => 'page', | ||
'foreign_key' => 'page_id' | ||
) | ||
); | ||
|
||
public function labels() | ||
{ | ||
return array( | ||
'name' => __('Parn name'), | ||
'filter_id' => __('Filter'), | ||
'content' => __('Content'), | ||
'content_html' => __('HTML content'), | ||
'is_protected' => __('Is protected'), | ||
'is_expanded' => __('Is expanded'), | ||
'is_indexable' => __('Is indexable') | ||
); | ||
} | ||
|
||
public function rules() | ||
{ | ||
return array( | ||
'name' => array( | ||
array('not_empty'), | ||
array('max_length', array(':value', 50)) | ||
) | ||
); | ||
} | ||
|
||
public function before_save() | ||
{ | ||
if ($this->filter_id === NULL) | ||
{ | ||
$this->filter_id = Config::get('site', 'default_html_editor'); | ||
} | ||
|
||
if ($this->is_protected === NULL) | ||
{ | ||
$this->is_protected = self::PART_NOT_PROTECTED; | ||
} | ||
|
||
if ($this->name === NULL) | ||
{ | ||
$this->name = 'part'; | ||
} | ||
|
||
if ($this->filter_id !== NULL) | ||
{ | ||
$filter = WYSIWYG::get_filter($this->filter_id); | ||
$this->content_html = $filter->apply($this->content); | ||
} | ||
|
||
Observer::notify('part_before_save', $this); | ||
|
||
return TRUE; | ||
} | ||
|
||
public function after_save() | ||
{ | ||
Observer::notify('part_after_save', $this); | ||
|
||
Cache::instance()->delete_tag('page_parts'); | ||
return parent::after_save(); | ||
} | ||
|
||
public function after_delete($id) | ||
{ | ||
Cache::instance()->delete_tag('page_parts'); | ||
return parent::after_save(); | ||
} | ||
|
||
public function sort(array $positions) | ||
{ | ||
foreach ($positions as $pos => $id) | ||
{ | ||
DB::update($this->table_name()) | ||
->set(array( | ||
'position' => $pos | ||
)) | ||
->where('id', '=', $id) | ||
->execute($this->_db); | ||
} | ||
|
||
Cache::instance()->delete_tag('page_parts'); | ||
|
||
return $this; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php defined('SYSPATH') or die('No direct access allowed.'); | ||
|
||
/** | ||
* @package KodiCMS/Page_Parts | ||
* @category Widget | ||
* @author butschster <butschster@gmail.com> | ||
* @link http://kodicms.ru | ||
* @copyright (c) 2012-2014 butschster | ||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt | ||
*/ | ||
class KodiCMS_Model_Widget_Part { | ||
|
||
public $block = NULL; | ||
protected $_html = NULL; | ||
|
||
public function __construct($block, $html) | ||
{ | ||
$this->block = $block; | ||
$this->_html = $html; | ||
} | ||
|
||
public function __toString() | ||
{ | ||
return (string) $this->_html; | ||
} | ||
} |
Oops, something went wrong.