Skip to content

Commit

Permalink
Merge pull request #84 from bitcero/helium
Browse files Browse the repository at this point in the history
Helium
  • Loading branch information
bitcero authored Aug 14, 2016
2 parents aca3390 + 7b4c4c5 commit 966e904
Show file tree
Hide file tree
Showing 35 changed files with 1,116 additions and 129 deletions.
7 changes: 4 additions & 3 deletions rmcommon/api/editors/tinymce/tinyeditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,11 @@ public function get_js(){
switchEditors.go(elements, "'.(isset($_COOKIE['editor']) ? $_COOKIE['editor'] : 'tinymce').'");
}
});
};
};';

initMCE("'.$this->configuration['elements'].'");
';
if('' != $this->configuration['elements']){
$rtn .= 'initMCE("'.$this->configuration['elements'].'");';
}

return $rtn;
}
Expand Down
4 changes: 2 additions & 2 deletions rmcommon/class/breadcrumb.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ public function count(){
public function render(){
global $cuIcons;

RMTemplate::get()->add_style('breadcrumb.css', 'rmcommon');
RMTemplate::getInstance()->add_style('breadcrumb.css', 'rmcommon');
ob_start();

include RMTemplate::get()->path('rmc-breadcrumb.php', 'module', 'rmcommon');
include RMTemplate::getInstance()->path('rmc-breadcrumb.php', 'module', 'rmcommon');

$ret = ob_get_clean();
return $ret;
Expand Down
4 changes: 3 additions & 1 deletion rmcommon/class/fields/editor.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ private function renderTiny()
RMTemplate::get()->add_script('quicktags.min.js', 'rmcommon');
RMTemplate::get()->add_script(RMCURL . '/api/editors/tinymce/tiny_mce.js');
RMTemplate::get()->add_inline_script(TinyEditor::getInstance()->get_js());
RMTemplate::get()->add_inline_script('edToolbar("' . $this->get('id') . '");', 1);
if('' != $this->get('id')){
RMTemplate::get()->add_inline_script('edToolbar("' . $this->get('id') . '");', 1);
}

$plugins = array();
$plugins = RMEvents::get()->run_event('rmcommon.editor.top.plugins', $plugins, 'tiny', $this->get('id'));
Expand Down
2 changes: 1 addition & 1 deletion rmcommon/class/fields/timezone.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct($caption, $name, $type = 0, $multi = 0, $selected =

$this->setIfNotSet('class', 'form-control');

$this->suppressRender(['caption','name','multiple','selected']);
$this->suppressRender(['caption','multiple','selected']);
}
public function multi(){
return $this->multi;
Expand Down
2 changes: 1 addition & 1 deletion rmcommon/class/form.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public function clear($field = '')
* @param string $css_type Content Type: email,url, etc.
* @return object
*/
public function addElement(&$element, $required = false, $css_type = '')
public function addElement($element, $required = false, $css_type = '')
{
$element->setForm($this->_name);
$ret['field'] = $element;
Expand Down
6 changes: 6 additions & 0 deletions rmcommon/class/helpers/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,12 @@ public function plugins(){
return Plugins::getInstance();
}

// Widgets handler
public function widgets(){
$widgets = Widgets::getInstance();
return $widgets;
}

/**
* @return Common
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

namespace Common\Core\Helpers;

abstract class Widget extends Attributes
abstract class WidgetAbstract extends Attributes
{
/**
* Attributes to be ignored
Expand All @@ -43,7 +43,7 @@ public function __construct($data)
{
parent::__construct($data);

$this->tpl = \RMTemplate::get();
$this->tpl = \RMTemplate::getInstance();

}

Expand Down
6 changes: 6 additions & 0 deletions rmcommon/class/helpers/WidgetInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ interface WidgetInterface
*/
public function id();

/**
* Initialize the widget
* @param mixed $parameters
*/
public function setup($parameters);

/**
* Returns the template used for this widget
* @return mixed
Expand Down
153 changes: 153 additions & 0 deletions rmcommon/class/helpers/Widgets.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
<?php
/**
* Common Utilities Framework for XOOPS
*
* Copyright © 2015 Red Mexico http://www.redmexico.com.mx
* -------------------------------------------------------------
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
* -------------------------------------------------------------
* @copyright Red Mexico (http://www.redmexico.com.mx)
* @license GNU GPL 2
* @package rmcommon
* @author Eduardo Cortés (AKA bitcero) <[email protected]>
* @url http://www.redmexico.com.mx
* @url http://www.eduardocortes.mx
*/

namespace Common\Core\Helpers;

class Widgets
{
private $widgetsProviders = array();

public function __construct()
{
$this->widgetsProviders['rmcommon'] = [
'path' => RMCPATH . '/widgets',
'namespace' => 'Common\Widgets'
];
$this->loadProviders();
}

/**
* Loads new SVG icons provider
*
* Components must use evenRmcommonRegisterIconProvider event and return an array
* with keys 'id' and 'directory'.
*
* 'id' key must have an unique identifier to load icons from 'directory'.
*
* @return bool
* @throws \Exception
*/
private function loadProviders()
{

$providers = array();
$providers = \RMEvents::get()->trigger('rmcommon.register.widgets.provider', $providers);

if (empty($providers)) {
return true;
}

foreach ($providers as $provider) {

if ($provider['id'] == '') {
continue;
}

if (!is_dir($provider['path'])) {
continue;
}

if ($provider['id'] == 'rmcommon') {
throw new \Exception(__('Illegal attempt to replace "Common Utilities" widgets provider!', 'rmcommon'));
return false;
}

$this->widgetsProviders[$provider['id']] = [
'path' => $provider['path'],
'namespace' => rtrim($provider['namespace'], '\\')
];

}

}

public function getWidgetsList($providers = [])
{

/**
* @todo: Make routines to request a widgets list and information from module
*/

}

/**
* Instantiate a new widget object from a specif provider
* @param string $provider Provider ID (e.g. rmcommon)
* @param string $widgetName Widget name. This name must correspond with file name (e.g. 'Counter')
* @return bool|string
*/
public function load($provider, $widgetName)
{

if('' == $widgetName || '' == $provider){
return false;
}

if(false === array_key_exists($provider, $this->widgetsProviders)){
trigger_error(sprintf(__('Attempt to load a widget from a non existent provider: %s', 'rmcommon'), $provider));
return false;
}

// File path
$path = $this->widgetsProviders[$provider]['path'] . '/' . $widgetName . '.php';
if(false === file_exists($path)){
trigger_error(sprintf(__('Attempt to load a non existent widget: %s', 'rmcommon'), $widgetName));
return false;
}

include_once $path;

if(false === class_exists($this->widgetsProviders[$provider]['namespace'] . '\\' . $widgetName)){
trigger_error(sprintf(__('Attempt to load a non existent widget: %s', 'rmcommon'), $widgetName));
return false;
}

$widgetClass = $this->widgetsProviders[$provider]['namespace'] . '\\' . $widgetName;
$widget = new $widgetClass();
if(false === is_subclass_of($widget, 'Common\Core\Helpers\WidgetAbstract')){
trigger_error(sprintf(__('Attempt to load a non valid widget: %s. Widgets must be extended from WidgetAbstract.', 'rmcommon'), $widgetName));
return false;
}

return $widget;

}

public static function getInstance()
{
static $instance;

if (isset($instance))
return $instance;

$instance = new Widgets();

return $instance;
}
}
26 changes: 13 additions & 13 deletions rmcommon/class/helpers/format.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,10 @@ public static function version($version, $name = false)
public static function bytes_format($size, $origin = '', $target = '', $abr = true)
{

$kb = 1024;
$mb = $kb * 1024;
$gb = $mb * 1024;
$tb = $gb * 1024;
$kb = 1000;
$mb = $kb * 1000;
$gb = $mb * 1000;
$tb = $gb * 1000;

$units = array(
'b' => 1,
Expand All @@ -223,10 +223,10 @@ public static function bytes_format($size, $origin = '', $target = '', $abr = tr
$string = array(

'b' => $abr ? __('%s b', 'rmcommon') : __('%s Bytes', 'rmcommon'),
'kb' => $abr ? __('%s Kb', 'rmcommon') : __('%s Kilobytes', 'rmcommon'),
'mb' => $abr ? __('%s Mb', 'rmcommon') : __('%s Megabytes', 'rmcommon'),
'gb' => $abr ? __('%s Gb', 'rmcommon') : __('%s Gigabytes', 'rmcommon'),
'tb' => $abr ? __('%s Tb', 'rmcommon') : __('%s Terabytes', 'rmcommon'),
'kb' => $abr ? __('%s KB', 'rmcommon') : __('%s Kilobytes', 'rmcommon'),
'mb' => $abr ? __('%s MB', 'rmcommon') : __('%s Megabytes', 'rmcommon'),
'gb' => $abr ? __('%s GB', 'rmcommon') : __('%s Gigabytes', 'rmcommon'),
'tb' => $abr ? __('%s TB', 'rmcommon') : __('%s Terabytes', 'rmcommon'),

);

Expand All @@ -237,7 +237,7 @@ public static function bytes_format($size, $origin = '', $target = '', $abr = tr
return sprintf($string[$origin], $size);

// Convert size to bytes
$bytes = $size * $units[$origin];
$size = $size * $units[$origin];
// Get bytes in target format only if $target has been provided
if ($target != '')
$result = number_format($bytes / $units[$target], 2);
Expand All @@ -246,7 +246,7 @@ public static function bytes_format($size, $origin = '', $target = '', $abr = tr
switch ($size) {

case $size < $kb:
$result = $bytes;
$result = $size;
$target = 'b';
break;
case $size < $mb:
Expand All @@ -255,15 +255,15 @@ public static function bytes_format($size, $origin = '', $target = '', $abr = tr
break;
case $size < $gb:
$result = number_format($size / $mb, 2);
$target = 'MB';
$target = 'mb';
break;
case $size < $tb:
$result = number_format($size / $gb, 2);
$target = 'GB';
$target = 'gb';
break;
default:
$result = number_format($size / $tb, 2);
$target = 'TB';
$target = 'tb';
break;

}
Expand Down
11 changes: 10 additions & 1 deletion rmcommon/class/helpers/modules.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ static public function format_module_version($version, $name = false)
* @param string|integer $id Indentifier of module. Could be dirname or numeric ID
* @return XoopsModule
*/
static public function load_module($id)
static public function load($id)
{

$module_handler = xoops_gethandler('module');
Expand All @@ -124,6 +124,15 @@ static public function load_module($id)
return $module;
}

/**
* @param $id
* @return XoopsModule
* @deprecated
*/
static function load_module($id){
return self::load($id);
}

/**
* Retrieves the list of installed modules
*
Expand Down
2 changes: 1 addition & 1 deletion rmcommon/events/rmcommon.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ static function eventRmcommonEditorTopPlugins( $plugins, $type, $id ){
}

static function eventRmcommonSmartyPlugins($plugins){
$plugins[] = RMCPATH . '/include/smarty';
$plugins['rmcommon'] = RMCPATH . '/include/smarty';
return $plugins;
}

Expand Down
1 change: 1 addition & 0 deletions rmcommon/icons/bars-chart.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions rmcommon/icons/bulb.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions rmcommon/icons/line-chart.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 966e904

Please sign in to comment.