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

Improvements and fixes #103

Merged
merged 1 commit into from Nov 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions rmcommon/ajax/blocks.php
Expand Up @@ -161,7 +161,7 @@ function configure_block(){
'multiple' => null,
'selected' => $block->sections(),
'subpages' => null,
'dirname' => false,
'dirnames' => false,
'selectedSubs' => $block->subpages(),
'dirnames' => false
]);
Expand Down Expand Up @@ -219,7 +219,12 @@ function save_block_config(){
}

// Set modules
$block->sections($bk_mod);
if($bk_mod[0] == '-1'){
$block->sections([-1]);
} else {
$block->sections($bk_mod);
}

// Set Groups
$block->setReadGroups($bk_groups);

Expand Down
1 change: 1 addition & 0 deletions rmcommon/blocks.php
Expand Up @@ -140,6 +140,7 @@ function show_rm_blocks()
RMTemplate::getInstance()->add_script('blocks.min.js', 'rmcommon');
RMTemplate::getInstance()->add_script('jkmenu.js', 'rmcommon');
RMTemplate::getInstance()->add_style('forms.min.css', 'rmcommon', ['id' => 'forms-css']);
RMTemplate::getInstance()->add_script('forms.js', 'rmcommon', ['id' => 'forms-js', 'footer' => 1]);
RMTemplate::getInstance()->add_script('jquery-ui.min.js', 'rmcommon', array('directory' => 'include'));

if (!$rmc_config['blocks_enable']) {
Expand Down
15 changes: 11 additions & 4 deletions rmcommon/class/License.php
Expand Up @@ -31,21 +31,28 @@

class License extends \RMObject
{
public function __construct($id = null)
public function __construct($id = null, $type = null)
{
$this->db = \XoopsDatabaseFactory::getDatabaseConnection();
$this->_dbtable = $this->db->prefix("mod_rmcommon_licensing");
$this->setNew();
$this->initVarsFromTable();
if ($id==null){

$this->setVarType('data', XOBJ_DTYPE_SOURCE);

if ($id == null) {
return;
}

if(is_string($id)){
$filters = null;
if (is_string($id)) {
$this->primary = 'identifier';
if (null != $type) {
$filters = ['type' => $type];
}
}

if ($this->loadValues($id)){
if ($this->loadValues($id, $filters)) {
$this->unsetNew();
}

Expand Down
2 changes: 1 addition & 1 deletion rmcommon/class/blocksfunctions.php
Expand Up @@ -151,7 +151,7 @@ static function get_blocks($groupid, $mid = 0, $toponlyblock = false, $visible =
}
$mid = (int)$mid;
if (!empty($mid)) {
$sql .= ' AND m.mid IN (-1,' . $mid;
$sql .= ' AND m.mid IN (0,' . $mid;
if ($toponlyblock) {
$sql .= ',1';
}
Expand Down
2 changes: 1 addition & 1 deletion rmcommon/class/fields/groups.class.php
Expand Up @@ -26,7 +26,7 @@ class RMFormGroups extends RMFormElement

/**
* Constructor de la clase
* @param string $caption Texto de la etiqueta
* @param mixed $caption Texto de la etiqueta
* @param string $name Nombre del campo
*/
function __construct($caption, $name='', $multi=0, $type=0, $cols=2, $selected=array()){
Expand Down
37 changes: 26 additions & 11 deletions rmcommon/class/fields/modules.class.php
Expand Up @@ -26,7 +26,7 @@ class RMFormModules extends RMFormElement
* If you wish to exclude system from modules list then you need to pass the
* parameter 'system' as null or false to avoid it.
*
* @param string $caption
* @param mixed $caption
* @param string $name Nombre del campo
* @param int $multi Selecciona multiple activada o desactivada
* @param int $type 0 = Select, 1 = Tabla
Expand All @@ -39,6 +39,7 @@ class RMFormModules extends RMFormElement
*/
function __construct($caption, $name = '', $multi = 0, $type = 0, $selected = null, $cols = 2, $insert = null, $dirnames = true, $subpages = 0)
{
global $common;

if (is_array($caption)) {
parent::__construct($caption);
Expand All @@ -65,19 +66,32 @@ function __construct($caption, $name = '', $multi = 0, $type = 0, $selected = nu
}
}

if($this->has('selected')){
$this->set('value', $this->get('selected'));
}

$this->setIfNotSet('type', $type ? 'radio' : 'select');
$this->setIfNotSet('selected', []);
$this->setIfNotSet('value', []);

if(false == is_array($this->get('value'))){
$this->set('value', [$this->get('value')]);
}

$this->setIfNotSet('dirnames', true);

$this->suppressList[] = 'insert';
$this->suppressList[] = 'dirnames';
$this->suppressList[] = 'subpages';
$this->suppressList[] = 'selectedSubs';
$this->suppressList[] = 'value';
$this->suppressList[] = 'selected';
$this->suppressList[] = 'name';
$this->suppressList[] = 'system';

!defined('RM_FRAME_APPS_CREATED') ? define('RM_FRAME_APPS_CREATED', 1) : '';

// Add rmcommon form scripts
$common->template()->add_script('forms.js', 'rmcommon', ['footer' => 1]);
}

public function multi()
Expand Down Expand Up @@ -191,11 +205,11 @@ function render()
}

$type = $this->get('type');
$selected = $this->get('selected');
$selected = $this->get('value');

if ($type == 'radio' || $type == 'checkbox') {
// Add js script
RMTemplate::getInstance()->add_script('modules_field.js', 'rmcommon', array('directory' => 'include'));
// RMTemplate::getInstance()->add_script('modules_field.js', 'rmcommon', array('directory' => 'include'));

$pagesOptions = array();
$attributes = $this->renderAttributeString();
Expand All @@ -212,16 +226,17 @@ function render()
$i = 1;
foreach ($modules as $k => $v) {
$app = RMModules::load_module($k);
if($app)
$subpages = $app->getInfo('subpages');

$rtn .= "<li>";
$rtn .= "<input $attributes name=\"".sprintf($name, $k)."\"
value='$k'" .
($k == -1 ? "data-checkbox='" . $this->get('id') . "-module-item'" : " data-oncheck='" . $this->get('id') . "-module-item'") . "
id='" . $this->get('id') . "-$k'" .
(is_array($selected) && in_array($k, $selected) ? " checked" : '') .
($this->has('subpages') ? " data-checkbox='" . $this->get('id') . "-module-item-$k'" : '') . "> ";
($k == -1 ? " data-all" : " data-module=\"$k\"") .
" id='" . $this->get('id') . "-$k'" .
(is_array($selected) && in_array($k, $selected) ? " checked" : '') . "> ";

if ($this->has('subpages') && $k>-1)
if (1 == $k || (false == empty($subpages) && $this->has('subpages') && $k > -1))
$rtn .= '<a href="#">' . $v . '</a>';
else
$rtn .= $v;
Expand Down Expand Up @@ -255,7 +270,7 @@ function render()
foreach ($subpages as $page => $caption) {
$rtns .= "<li class='checkbox'>
<label>
<input type='checkbox' data-oncheck='".$this->get('id')."-module-item-" . $k . "' name='" . sprintf($name, $k) . "[subpages][$page]' id='subpages-$k-$page' value='$page'" . (is_array($subpages) && @in_array($page, $selectedSubs[$k]) ? " checked='checked'" : '') . " /> $caption</label></li>";
<input type='checkbox' data-parent='" . $k . "' name='" . sprintf($name, $k) . "[subpages][$page]' id='subpages-$k-$page' value='$page'" . (is_array($subpages) && @in_array($page, $selectedSubs[$k]) ? " checked='checked'" : '') . " /> $caption</label></li>";
$j++;
$cr++;
}
Expand Down Expand Up @@ -296,7 +311,7 @@ function render()

$rtn = "<select $attributes>";
foreach ($modules as $k => $v) {
$rtn .= "<option value='$k'" . (is_array($selected) ? (in_array($k, $selected) ? " selected" : '') : '') . ">$v</option>";
$rtn .= "<option value='$k'" . (is_array($selected) ? (in_array($k, $selected) ? " value" : '') : '') . ">$v</option>";
}
$rtn .= "</select>";

Expand Down
6 changes: 5 additions & 1 deletion rmcommon/class/helpers/Common.php
Expand Up @@ -158,7 +158,11 @@ public function format()
*/
public function timeFormat($format = '')
{
return RMTimeFormatter::get($format);
$formater = RMTimeFormatter::get($format);
if('' != $format){
$formater->format = $format;
}
return $formater;
}

/**
Expand Down
2 changes: 0 additions & 2 deletions rmcommon/class/helpers/modules.class.php
Expand Up @@ -177,8 +177,6 @@ static function build_modules_cache()

$modules = XoopsLists::getModulesList();

print_r($modules);

}

/**
Expand Down
12 changes: 7 additions & 5 deletions rmcommon/class/imageresizer.php
Expand Up @@ -293,13 +293,15 @@ static public function resize( $file, $params ){
$image->type = $formats[ $data[2] - 1 ];
$image->mime = $data['mime'];

$ratio = $image->width < $image->height ? $image->width / $image->height : $image->height / $image->width;
//$ratio = $image->width < $image->height ? $image->width / $image->height : $image->height / $image->width;
$ratio = $image->width / $image->height;

if ( !isset($params->width) )
$params->width = (int)($params->height * $ratio);
if ( !isset($params->width) || $params->width <= 0 )
$params->width = (int)($params->height * $ratio);//$ratio >= 1 ? (int)($params->height * $ratio) : (int)($params->height / $ratio);

if ( !isset($params->height) )
$params->height = (int)($params->width * $ratio);

if ( !isset($params->height) || $params->height <= 0 )
$params->height = (int)($params->width / $ratio); //$ratio >= 1 ? (int)($params->width / $ratio) : (int)($params->width / $ratio);

$size_ratio = max( $params->width / $image->width, $params->height / $image->height );

Expand Down
20 changes: 19 additions & 1 deletion rmcommon/class/object.php
Expand Up @@ -915,14 +915,32 @@ protected function initVarsFromTable()
* Cargaa los valores de un objeto desde la base de datos
* en base a su clave primaria
* @param mixed $id Valor a buscar en la clave primaria
* @param array $filters Additional filters for searches
* @return bool
*/
protected function loadValues($id)
protected function loadValues($id, $filters = null)
{

$id = $this->escape($id);

$sql = "SELECT * FROM $this->_dbtable WHERE `$this->primary`='$id'";

/**
* Added on Sep-05-2017
*/
if(null != $filters && is_array($filters) && false == empty($filters)){
foreach($filters as $column => $value){
$column = $this->escape($column);
$value = $this->escape($value);

if('' == $column){
continue;
}

$sql .= " AND `$column`=" . (is_numeric($value) ? $value : "'$value'");
}
}

$result = $this->db->query($sql);
if ($this->db->getRowsNum($result) <= 0) return false;

Expand Down
1 change: 0 additions & 1 deletion rmcommon/class/template.php
Expand Up @@ -552,7 +552,6 @@ public function add_script($file, $element = '', $options = array(), $owner = ''
} else {

$script_url = $this->generate_url($file, $element, $owner == 'theme' ? 'theme-js' : 'js', $directory, $version);

}

if ($script_url == '')
Expand Down
8 changes: 4 additions & 4 deletions rmcommon/class/timeformatter.php
Expand Up @@ -11,7 +11,7 @@
class RMTimeFormatter
{
private $time = 0;
private $format = '';
public $format = '';

/**
* Initialize this class
Expand Down Expand Up @@ -65,7 +65,7 @@ public function format($time=0, $format='', $offset = true){

$format = $format=='' ? $this->format : $format;

if ($format=='' || $time<0){
if ($format=='' || $time<0){echo $format;
trigger_error(__('You must provide a valid time and format value to use RMTimeFormatter::format() method','rmcommon'));
return null;
}
Expand Down Expand Up @@ -150,7 +150,7 @@ public function months($time=0){

}

public function ago( $time ){
public function ago( $time, $format = '%m%-%d%-%Y% %h%:%i%:%s%' ){

if(false == is_numeric($time)){
$time = strtotime($time);
Expand Down Expand Up @@ -191,7 +191,7 @@ public function ago( $time ){

}

return $this->format();
return $this->format($time, $format);

}

Expand Down
2 changes: 1 addition & 1 deletion rmcommon/css/modules.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.