forked from joomla/Component-Builder
7358 lines
243 KiB
PHP
7358 lines
243 KiB
PHP
<?php
|
|
/**
|
|
* @package Joomla.Component.Builder
|
|
*
|
|
* @created 30th April, 2015
|
|
* @author Llewellyn van der Merwe <http://www.joomlacomponentbuilder.com>
|
|
* @github Joomla Component Builder <https://github.com/vdm-io/Joomla-Component-Builder>
|
|
* @copyright Copyright (C) 2015 - 2020 Vast Development Method. All rights reserved.
|
|
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
|
*/
|
|
|
|
// No direct access to this file
|
|
defined('_JEXEC') or die('Restricted access');
|
|
|
|
use Joomla\CMS\Language\Language;
|
|
use Joomla\Registry\Registry;
|
|
use Joomla\String\StringHelper;
|
|
use Joomla\Utilities\ArrayHelper;
|
|
|
|
/**
|
|
* Componentbuilder component helper
|
|
*/
|
|
abstract class ComponentbuilderHelper
|
|
{
|
|
/**
|
|
* Composer Switch
|
|
*
|
|
* @var array
|
|
*/
|
|
protected static $composer = array();
|
|
|
|
/**
|
|
* The Main Active Language
|
|
*
|
|
* @var string
|
|
*/
|
|
public static $langTag;
|
|
|
|
/**
|
|
* The Global Site Event Method.
|
|
**/
|
|
public static function globalEvent($document)
|
|
{
|
|
// the Session keeps track of all data related to the current session of this user
|
|
self::loadSession();
|
|
}
|
|
|
|
|
|
/**
|
|
* Locked Libraries (we can not have these change)
|
|
**/
|
|
public static $libraryNames = array(1 => 'No Library', 2 => 'Bootstrap v4', 3 => 'Uikit v3', 4 => 'Uikit v2', 5 => 'FooTable v2', 6 => 'FooTable v3');
|
|
|
|
/**
|
|
* Array of php fields Allowed (16)
|
|
**/
|
|
public static $phpFieldArray = array('', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'x', 'HEADER');
|
|
|
|
/**
|
|
* The global params
|
|
**/
|
|
protected static $params = false;
|
|
|
|
/**
|
|
* The global updater
|
|
**/
|
|
protected static $globalUpdater = array();
|
|
|
|
/**
|
|
* The local company details
|
|
**/
|
|
protected static $localCompany = array();
|
|
|
|
/**
|
|
* The snippet paths
|
|
**/
|
|
public static $snippetPath = 'https://raw.githubusercontent.com/vdm-io/Joomla-Component-Builder-Snippets/master/';
|
|
public static $snippetsPath = 'https://api.github.com/repos/vdm-io/Joomla-Component-Builder-Snippets/git/trees/master';
|
|
|
|
/**
|
|
* The VDM packages paths
|
|
**/
|
|
public static $vdmGithubPackageUrl = "https://github.com/vdm-io/JCB-Packages/raw/master/";
|
|
public static $vdmGithubPackagesUrl = "https://api.github.com/repos/vdm-io/JCB-Packages/git/trees/master";
|
|
|
|
/**
|
|
* The JCB packages paths
|
|
**/
|
|
public static $jcbGithubPackageUrl = "https://github.com/vdm-io/JCB-Community-Packages/raw/master/";
|
|
public static $jcbGithubPackagesUrl = "https://api.github.com/repos/vdm-io/JCB-Community-Packages/git/trees/master";
|
|
|
|
/**
|
|
* The bolerplate paths
|
|
**/
|
|
public static $bolerplatePath = 'https://raw.githubusercontent.com/vdm-io/boilerplate/jcb/';
|
|
public static $bolerplateAPI = 'https://api.github.com/repos/vdm-io/boilerplate/git/trees/jcb';
|
|
|
|
/**
|
|
* The array of constant paths
|
|
*
|
|
* JPATH_SITE is meant to represent the root path of the JSite application,
|
|
* just as JPATH_ADMINISTRATOR is mean to represent the root path of the JAdministrator application.
|
|
*
|
|
* JPATH_BASE is the root path for the current requested application.... so if you are in the administrator application:
|
|
*
|
|
* JPATH_BASE == JPATH_ADMINISTRATOR
|
|
*
|
|
* If you are in the site application:
|
|
*
|
|
* JPATH_BASE == JPATH_SITE
|
|
*
|
|
* If you are in the installation application:
|
|
*
|
|
* JPATH_BASE == JPATH_INSTALLATION.
|
|
*
|
|
* JPATH_ROOT is the root path for the Joomla install and does not depend upon any application.
|
|
*
|
|
* @var array
|
|
*/
|
|
public static $constantPaths = array(
|
|
// The path to the administrator folder.
|
|
'JPATH_ADMINISTRATOR' => JPATH_ADMINISTRATOR,
|
|
// The path to the installed Joomla! site, or JPATH_ROOT/administrator if executed from the backend.
|
|
'JPATH_BASE' => JPATH_BASE,
|
|
// The path to the cache folder.
|
|
'JPATH_CACHE' => JPATH_CACHE,
|
|
// The path to the administration folder of the current component being executed.
|
|
'JPATH_COMPONENT_ADMINISTRATOR' => JPATH_COMPONENT_ADMINISTRATOR,
|
|
// The path to the site folder of the current component being executed.
|
|
'JPATH_COMPONENT_SITE' => JPATH_COMPONENT_SITE,
|
|
// The path to the current component being executed.
|
|
'JPATH_COMPONENT' => JPATH_COMPONENT,
|
|
// The path to folder containing the configuration.php file.
|
|
'JPATH_CONFIGURATION' => JPATH_CONFIGURATION,
|
|
// The path to the installation folder.
|
|
'JPATH_INSTALLATION' => JPATH_INSTALLATION,
|
|
// The path to the libraries folder.
|
|
'JPATH_LIBRARIES' => JPATH_LIBRARIES,
|
|
// The path to the plugins folder.
|
|
'JPATH_PLUGINS' => JPATH_PLUGINS,
|
|
// The path to the installed Joomla! site.
|
|
'JPATH_ROOT' => JPATH_ROOT,
|
|
// The path to the installed Joomla! site.
|
|
'JPATH_SITE' => JPATH_SITE,
|
|
// The path to the templates folder.
|
|
'JPATH_THEMES' => JPATH_THEMES
|
|
);
|
|
|
|
/**
|
|
* get the class method or property
|
|
*
|
|
* @input int The method/property ID
|
|
* @input string The target type
|
|
*
|
|
* @returns string on success
|
|
**/
|
|
public static function getClassCode($id, $type)
|
|
{
|
|
if ('property' === $type || 'method' === $type)
|
|
{
|
|
// Get a db connection.
|
|
$db = JFactory::getDbo();
|
|
// Get user object
|
|
$user = JFactory::getUser();
|
|
// Create a new query object.
|
|
$query = $db->getQuery(true);
|
|
// get method
|
|
if ('method' === $type)
|
|
{
|
|
$query->select($db->quoteName(array('a.comment','a.name','a.visibility','a.arguments','a.code')));
|
|
}
|
|
// get property
|
|
elseif ('property' === $type)
|
|
{
|
|
$query->select($db->quoteName(array('a.comment','a.name','a.visibility','a.default')));
|
|
}
|
|
$query->from($db->quoteName('#__componentbuilder_class_' . $type,'a'));
|
|
$query->where($db->quoteName('a.id') . ' = ' . (int) $id);
|
|
// Implement View Level Access
|
|
if (!$user->authorise('core.options', 'com_componentbuilder'))
|
|
{
|
|
$columns = $db->getTableColumns('#__componentbuilder_class_' . $type);
|
|
if(isset($columns['access']))
|
|
{
|
|
$groups = implode(',', $user->getAuthorisedViewLevels());
|
|
$query->where('a.access IN (' . $groups . ')');
|
|
}
|
|
}
|
|
$db->setQuery($query);
|
|
$db->execute();
|
|
if ($db->getNumRows())
|
|
{
|
|
// get the code
|
|
$code = $db->loadObject();
|
|
// combine method values
|
|
$combinded = array();
|
|
// add comment if set
|
|
if (self::checkString($code->comment))
|
|
{
|
|
$comment = array_map('trim', (array) explode(PHP_EOL, base64_decode($code->comment)));
|
|
$combinded[] = "\t" . implode(PHP_EOL . "\t ", $comment);
|
|
}
|
|
// build method
|
|
if ('method' === $type)
|
|
{
|
|
// set the method signature
|
|
if (self::checkString($code->arguments))
|
|
{
|
|
$combinded[] = "\t" . $code->visibility . ' function ' . $code->name . '(' . base64_decode($code->arguments) . ')';
|
|
}
|
|
else
|
|
{
|
|
$combinded[] = "\t" . $code->visibility . ' function ' . $code->name . '()';
|
|
}
|
|
// set the method code
|
|
$combinded[] = "\t" . "{";
|
|
// add code if set
|
|
if (self::checkString(trim($code->code)))
|
|
{
|
|
$combinded[] = base64_decode($code->code);
|
|
}
|
|
else
|
|
{
|
|
$combinded[] = "\t\t// add your code here";
|
|
}
|
|
$combinded[] = "\t" . "}";
|
|
}
|
|
else
|
|
{
|
|
if (self::checkString($code->default))
|
|
{
|
|
$code->default = base64_decode($code->default);
|
|
if (is_int($code->default))
|
|
{
|
|
// set the class property
|
|
$combinded[] = "\t" . $code->visibility . ' $' . $code->name . ' = ' . (int) $code->default . ';';
|
|
}
|
|
elseif (is_float($code->default))
|
|
{
|
|
// set the class property
|
|
$combinded[] = "\t" . $code->visibility . ' $' . $code->name . ' = ' . (float) $code->default . ';';
|
|
}
|
|
elseif (('false' === $code->default || 'true' === $code->default)
|
|
|| (self::checkString($code->default) && (strpos($code->default, 'array(') !== false || strpos($code->default, '"') !== false)))
|
|
{
|
|
// set the class property
|
|
$combinded[] = "\t" . $code->visibility . ' $' . $code->name . ' = ' . $code->default . ';';
|
|
}
|
|
elseif (self::checkString($code->default) && strpos($code->default, '"') === false)
|
|
{
|
|
// set the class property
|
|
$combinded[] = "\t" . $code->visibility . ' $' . $code->name . ' = "' . $code->default . '";';
|
|
}
|
|
else
|
|
{
|
|
// set the class property
|
|
$combinded[] = "\t" . $code->visibility . ' $' . $code->name . ';';
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// set the class property
|
|
$combinded[] = "\t" . $code->visibility . ' $' . $code->name . ';';
|
|
}
|
|
}
|
|
// return the code
|
|
return implode(PHP_EOL, $combinded);
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* extract Boilerplate Class Extends
|
|
*
|
|
* @input string The class as a string
|
|
* @input string The type of class/extension
|
|
*
|
|
* @returns string on success
|
|
**/
|
|
public static function extractBoilerplateClassExtends(&$class, $type)
|
|
{
|
|
if (($strings = self::getAllBetween($class, 'class ', '}')) !== false && self::checkArray($strings))
|
|
{
|
|
foreach ($strings as $string)
|
|
{
|
|
if (($extends = self::getBetween($string, 'extends ', '{')) !== false && self::checkString($extends))
|
|
{
|
|
return trim($extends);
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* extract Boilerplate Class Header
|
|
*
|
|
* @input string The class as a string
|
|
* @input string The class being extended
|
|
* @input string The type of class/extension
|
|
*
|
|
* @returns string on success
|
|
**/
|
|
public static function extractBoilerplateClassHeader(&$class, $extends, $type)
|
|
{
|
|
if (($string = self::getBetween($class, "defined('_JEXEC')", 'extends ' . $extends)) !== false && self::checkString($string))
|
|
{
|
|
$headArray = explode(PHP_EOL, $string);
|
|
if (self::checkArray($headArray) && count($headArray) > 3)
|
|
{
|
|
// remove first since it still has the [or die;] string in it
|
|
array_shift($headArray);
|
|
// remove the last since it has the class declaration
|
|
array_pop($headArray);
|
|
// at this point we have the class comment still in as part of the header, lets remove that
|
|
$last = count($headArray);
|
|
while ($last > 0)
|
|
{
|
|
$last--;
|
|
if (isset($headArray[$last]) && strpos($headArray[$last], '*') !== false)
|
|
{
|
|
unset($headArray[$last]);
|
|
}
|
|
else
|
|
{
|
|
// moment the comment stops, we break out
|
|
$last = 0;
|
|
}
|
|
}
|
|
// make sure we only return if we have values
|
|
if (self::checkArray($headArray))
|
|
{
|
|
return implode(PHP_EOL, $headArray);
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* extract Boilerplate Class Comment
|
|
*
|
|
* @input string The class as a string
|
|
* @input string The class being extended
|
|
* @input string The type of class/extension
|
|
*
|
|
* @returns string on success
|
|
**/
|
|
public static function extractBoilerplateClassComment(&$class, $extends, $type)
|
|
{
|
|
if (($string = self::getBetween($class, "defined('_JEXEC')", 'extends ' . $extends)) !== false && self::checkString($string))
|
|
{
|
|
$headArray = explode(PHP_EOL, $string);
|
|
if (self::checkArray($headArray) && count($headArray) > 3)
|
|
{
|
|
$comment = array();
|
|
// remove the last since it has the class declaration
|
|
array_pop($headArray);
|
|
// at this point we have the class comment still in as part of the header, lets remove that
|
|
$last = count($headArray);
|
|
while ($last > 0)
|
|
{
|
|
$last--;
|
|
if (isset($headArray[$last]) && strpos($headArray[$last], '*') !== false)
|
|
{
|
|
$comment[$last] = $headArray[$last];
|
|
}
|
|
else
|
|
{
|
|
// moment the comment stops, we break out
|
|
$last = 0;
|
|
}
|
|
}
|
|
// make sure we only return if we have values
|
|
if (self::checkArray($comment))
|
|
{
|
|
// set the correct order
|
|
ksort($comment);
|
|
$replace = array('Foo' => '[[[Plugin_name]]]', '[PACKAGE_NAME]' => '[[[Plugin]]]', '1.0.0' => '[[[plugin.version]]]', '1.0' => '[[[plugin.version]]]');
|
|
// now update with JCB placeholders
|
|
return str_replace(array_keys($replace), array_values($replace), implode(PHP_EOL, $comment));
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* extract Boilerplate Class Properties & Methods
|
|
*
|
|
* @input string The class as a string
|
|
* @input string The class being extended
|
|
* @input string The type of class/extension
|
|
* @input int The plugin groups
|
|
*
|
|
* @returns string on success
|
|
**/
|
|
public static function extractBoilerplateClassPropertiesMethods(&$class, $extends, $type, $plugin_group = null)
|
|
{
|
|
$bucket = array('property' => array(), 'method' => array());
|
|
// get the class code, and remove the head
|
|
$codeArrayTmp = explode('extends ' . $extends, $class);
|
|
// make sure we have the correct result
|
|
if (self::checkArray($codeArrayTmp) && count($codeArrayTmp) == 2)
|
|
{
|
|
// the triggers
|
|
$triggers = array('public' => 1, 'protected' => 2, 'private' => 3);
|
|
$codeArray = explode(PHP_EOL, $codeArrayTmp[1]);
|
|
unset($codeArrayTmp);
|
|
// clean the code
|
|
self::cleanBoilerplateCode($codeArray);
|
|
// temp bucket
|
|
$name = null;
|
|
$arg = null;
|
|
$target = null;
|
|
$visibility = null;
|
|
$tmp = array();
|
|
$comment = array();
|
|
// load method
|
|
$loadCode = function (&$bucket, &$target, &$name, &$arg, &$visibility, &$tmp, &$comment) use($type, $plugin_group){
|
|
$_tmp = array(
|
|
'name' => $name,
|
|
'visibility' => $visibility,
|
|
'extension_type' => $type
|
|
);
|
|
// build filter
|
|
$filters = array('extension_type' => $type);
|
|
// add more data based on target
|
|
if ('method' === $target && self::checkArray($tmp))
|
|
{
|
|
// clean the code
|
|
self::cleanBoilerplateCode($tmp);
|
|
// only load if there are values
|
|
if (self::checkArray($tmp, true))
|
|
{
|
|
$_tmp['code'] = implode(PHP_EOL, $tmp);
|
|
}
|
|
else
|
|
{
|
|
$_tmp['code'] = '';
|
|
}
|
|
// load arguments only if set
|
|
if (self::checkString($arg))
|
|
{
|
|
$_tmp['arguments'] = $arg;
|
|
}
|
|
}
|
|
elseif ('property' === $target)
|
|
{
|
|
// load default only if set
|
|
if (self::checkString($arg))
|
|
{
|
|
$_tmp['default'] = $arg;
|
|
}
|
|
}
|
|
// load comment only if set
|
|
if (self::checkArray($comment, true))
|
|
{
|
|
$_tmp['comment'] = implode(PHP_EOL, $comment);
|
|
}
|
|
// load the group target
|
|
if ($plugin_group)
|
|
{
|
|
$_tmp['joomla_plugin_group'] = $plugin_group;
|
|
$filters['joomla_plugin_group'] = $plugin_group;
|
|
}
|
|
// load the local values
|
|
if (($locals = self::getLocalBoilerplate($name, $target, $type, $filters)) !== false)
|
|
{
|
|
foreach ($locals as $key => $value)
|
|
{
|
|
$_tmp[$key] = $value;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
$_tmp['id'] = 0;
|
|
$_tmp['published'] = 1;
|
|
$_tmp['version'] = 1;
|
|
}
|
|
// store the data based on target
|
|
$bucket[$target][] = $_tmp;
|
|
};
|
|
// now we start loading
|
|
foreach($codeArray as $line)
|
|
{
|
|
if ($visibility && $target && $name && strpos($line, '/**') !== false)
|
|
{
|
|
$loadCode($bucket, $target, $name, $arg, $visibility, $tmp, $comment);
|
|
// reset loop buckets
|
|
$name = null;
|
|
$arg = null;
|
|
$target = null;
|
|
$visibility = null;
|
|
$tmp = array();
|
|
$comment = array();
|
|
}
|
|
// load the comment before method/property
|
|
if (!$visibility && !$target && !$name && strpos($line, '*') !== false)
|
|
{
|
|
$comment[] = rtrim($line);
|
|
}
|
|
else
|
|
{
|
|
if (!$visibility && !$target && !$name)
|
|
{
|
|
// get the line values
|
|
$lineArray = array_values(array_map('trim', preg_split('/\s+/', trim($line))));
|
|
// check if we are at the main line
|
|
if (isset($lineArray[0]) && isset($triggers[$lineArray[0]]))
|
|
{
|
|
$visibility = $lineArray[0];
|
|
if (strpos($line, 'function') !== false)
|
|
{
|
|
$target = 'method';
|
|
// get the name
|
|
$name = trim(self::getBetween($line, 'function ', '('));
|
|
// get the arguments
|
|
$arg = trim(self::getBetween($line, ' ' . $name . '(', ')'));
|
|
}
|
|
else
|
|
{
|
|
$target = 'property';
|
|
if (strpos($line, '=') !== false)
|
|
{
|
|
// get the name
|
|
$name = trim(self::getBetween($line, '$', '='));
|
|
// get the default
|
|
$arg = trim(self::getBetween($line, '=', ';'));
|
|
}
|
|
else
|
|
{
|
|
// get the name
|
|
$name = trim(self::getBetween($line, '$', ';'));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
$tmp[] = rtrim($line);
|
|
}
|
|
}
|
|
}
|
|
// check if a last method is still around
|
|
if ($visibility && $target && $name)
|
|
{
|
|
$loadCode($bucket, $target, $name, $arg, $visibility, $tmp, $comment);
|
|
// reset loop buckets
|
|
$name = null;
|
|
$arg = null;
|
|
$target = null;
|
|
$visibility = null;
|
|
$tmp = array();
|
|
$comment = array();
|
|
}
|
|
return $bucket;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
protected static function getLocalBoilerplate($name, $table, $extension_type, $filters = array())
|
|
{
|
|
if ('property' === $table || 'method' === $table)
|
|
{
|
|
// Get a db connection.
|
|
$db = JFactory::getDbo();
|
|
// Create a new query object.
|
|
$query = $db->getQuery(true);
|
|
// get method
|
|
$query->select($db->quoteName(array('a.id','a.published','a.version')));
|
|
$query->from($db->quoteName('#__componentbuilder_class_' . $table,'a'));
|
|
$query->where($db->quoteName('a.name') . ' = ' . $db->quote($name));
|
|
$query->where($db->quoteName('a.extension_type') . ' = ' . $db->quote($extension_type));
|
|
// add more filters
|
|
if (self::checkArray($filters))
|
|
{
|
|
foreach($filters as $where => $value)
|
|
{
|
|
if (is_numeric($value))
|
|
{
|
|
$query->where($db->quoteName('a.' . $where) . ' = ' . $value);
|
|
}
|
|
else
|
|
{
|
|
$query->where($db->quoteName('a.' . $where) . ' = ' . $db->quote($value));
|
|
}
|
|
}
|
|
}
|
|
$db->setQuery($query);
|
|
$db->execute();
|
|
if ($db->getNumRows())
|
|
{
|
|
// get the code
|
|
return $db->loadAssoc();
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
protected static function cleanBoilerplateCode(&$code)
|
|
{
|
|
// remove the first lines until a { is found
|
|
$key = 0;
|
|
$found = false;
|
|
while (!$found)
|
|
{
|
|
if (isset($code[$key]))
|
|
{
|
|
if (strpos($code[$key], '{') !== false)
|
|
{
|
|
unset($code[$key]);
|
|
// only remove the first } found
|
|
$found = true;
|
|
}
|
|
// remove empty lines
|
|
elseif (!self::checkString(trim($code[$key])))
|
|
{
|
|
unset($code[$key]);
|
|
}
|
|
}
|
|
// check next line
|
|
$key++;
|
|
// stop loop at line 30 (really this should never happen)
|
|
if ($key > 30)
|
|
{
|
|
$found = true;
|
|
}
|
|
}
|
|
// reset all keys
|
|
$code = array_values($code);
|
|
// remove last lines until }
|
|
$last = count($code);
|
|
while ($last > 0)
|
|
{
|
|
$last--;
|
|
if (isset($code[$last]))
|
|
{
|
|
if (strpos($code[$last], '}') !== false)
|
|
{
|
|
unset($code[$last]);
|
|
// only remove the first } found
|
|
$last = 0;
|
|
}
|
|
// remove empty lines
|
|
elseif (!self::checkString(trim($code[$last])))
|
|
{
|
|
unset($code[$last]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Making class or function name safe
|
|
*
|
|
* @input string The name you would like to make safe
|
|
*
|
|
* @returns string on success
|
|
**/
|
|
public static function safeClassFunctionName($name)
|
|
{
|
|
// remove numbers if the first character is a number
|
|
if (is_numeric(substr($name, 0, 1)))
|
|
{
|
|
$name = self::replaceNumbers($name);
|
|
}
|
|
// remove all spaces and strange characters
|
|
return trim(preg_replace("/[^A-Za-z0-9_-]/", '', $name));
|
|
}
|
|
|
|
/**
|
|
* The field builder switch
|
|
**/
|
|
protected static $fieldNameBuilder = false;
|
|
|
|
/**
|
|
* Making field names safe
|
|
*
|
|
* @input string The you would like to make safe
|
|
* @input boolean The switch to return an ALL UPPER CASE string
|
|
* @input string The string to use in white space
|
|
*
|
|
* @returns string on success
|
|
**/
|
|
public static function safeFieldName($string, $allcap = false, $spacer = '_')
|
|
{
|
|
// get global value
|
|
if (self::$fieldNameBuilder === false)
|
|
{
|
|
self::$fieldNameBuilder = JComponentHelper::getParams('com_componentbuilder')->get('field_name_builder', 1);
|
|
}
|
|
// use the new convention
|
|
if (2 == self::$fieldNameBuilder)
|
|
{
|
|
// 0nly continue if we have a string
|
|
if (self::checkString($string))
|
|
{
|
|
// check that the first character is not a number
|
|
if (is_numeric(substr($string, 0, 1)))
|
|
{
|
|
$string = self::replaceNumbers($string);
|
|
}
|
|
// remove all other strange characters
|
|
$string = trim($string);
|
|
$string = preg_replace('/'.$spacer.'+/', ' ', $string);
|
|
$string = preg_replace('/\s+/', ' ', $string);
|
|
// Transliterate string
|
|
$string = self::transliterate($string);
|
|
// remove all and keep only characters and numbers
|
|
$string = preg_replace("/[^A-Za-z0-9 ]/", '', $string);
|
|
// replace white space with underscore (SAFEST OPTION)
|
|
$string = preg_replace('/\s+/', $spacer, $string);
|
|
// return all caps
|
|
if ($allcap)
|
|
{
|
|
return strtoupper($string);
|
|
}
|
|
// default is to return lower
|
|
return strtolower($string);
|
|
}
|
|
// not a string
|
|
return '';
|
|
}
|
|
// return all caps
|
|
if ($allcap)
|
|
{
|
|
return self::safeString($string, 'U');
|
|
}
|
|
// use the default (original behaviour/convention)
|
|
return self::safeString($string);
|
|
}
|
|
|
|
/**
|
|
* The type builder switch
|
|
**/
|
|
protected static $typeNameBuilder = false;
|
|
|
|
/**
|
|
* Making field type name safe
|
|
*
|
|
* @input string The you would like to make safe
|
|
*
|
|
* @returns string on success
|
|
**/
|
|
public static function safeTypeName($string)
|
|
{
|
|
// get global value
|
|
if (self::$typeNameBuilder === false)
|
|
{
|
|
self::$typeNameBuilder = JComponentHelper::getParams('com_componentbuilder')->get('type_name_builder', 1);
|
|
}
|
|
// use the new convention
|
|
if (2 == self::$typeNameBuilder)
|
|
{
|
|
// 0nly continue if we have a string
|
|
if (self::checkString($string))
|
|
{
|
|
// check that the first character is not a number
|
|
if (is_numeric(substr($string, 0, 1)))
|
|
{
|
|
$string = self::replaceNumbers($string);
|
|
}
|
|
// Transliterate string
|
|
$string = self::transliterate($string);
|
|
// remove all and keep only characters and numbers and point (TODO just one point)
|
|
$string = trim(preg_replace("/[^A-Za-z0-9\.]/", '', $string));
|
|
// best is to return lower (for all string equality in compiler)
|
|
return strtolower($string);
|
|
}
|
|
// not a string
|
|
return '';
|
|
}
|
|
// use the default (original behaviour/convention)
|
|
return self::safeString($string);
|
|
}
|
|
|
|
/*
|
|
* Get the Array of Existing Validation Rule Names
|
|
*
|
|
* @return array
|
|
*/
|
|
public static function getExistingValidationRuleNames($lowercase = false)
|
|
{
|
|
// get the items
|
|
$items = self::get('_existing_validation_rules_VDM', null);
|
|
if (!$items)
|
|
{
|
|
// load the file class
|
|
jimport('joomla.filesystem.file');
|
|
jimport('joomla.filesystem.folder');
|
|
// set the path to the form validation rules
|
|
$path = JPATH_LIBRARIES . '/src/Form/Rule';
|
|
// check if the path exist
|
|
if (!JFolder::exists($path))
|
|
{
|
|
return false;
|
|
}
|
|
// we must first store the current working directory
|
|
$joomla = getcwd();
|
|
// go to that folder
|
|
chdir($path);
|
|
// load all the files in this path
|
|
$items = JFolder::files('.', '\.php', true, true);
|
|
// change back to Joomla working directory
|
|
chdir($joomla);
|
|
// make sure we have an array
|
|
if (!self::checkArray($items))
|
|
{
|
|
return false;
|
|
}
|
|
// remove the Rule.php from the name
|
|
$items = array_map( function ($name) {
|
|
return str_replace(array('./','Rule.php'), '', $name);
|
|
}, $items);
|
|
// store the names for next run
|
|
self::set('_existing_validation_rules_VDM', json_encode($items));
|
|
}
|
|
// make sure it is no longer json
|
|
if (self::checkJson($items))
|
|
{
|
|
$items = json_decode($items, true);
|
|
}
|
|
// check if the names should be all lowercase
|
|
if ($lowercase)
|
|
{
|
|
$items = array_map( function($item) {
|
|
return strtolower($item);
|
|
}, $items);
|
|
}
|
|
return $items;
|
|
}
|
|
|
|
/**
|
|
* Get the snippet contributor details
|
|
*
|
|
* @param string $filename The file name
|
|
* @param string $type The type of file
|
|
*
|
|
* @return array On success the contributor details
|
|
*
|
|
*/
|
|
public static function getContributorDetails($filename, $type = 'snippet')
|
|
{
|
|
// start loading the contributor details
|
|
$contributor = array();
|
|
// get the path & content
|
|
switch ($type)
|
|
{
|
|
case 'snippet':
|
|
$path = self::$snippetPath.$filename;
|
|
// get the file if available
|
|
$content = self::getFileContents($path);
|
|
if (self::checkJson($content))
|
|
{
|
|
$content = json_decode($content, true);
|
|
}
|
|
break;
|
|
default:
|
|
// only allow types that are being targeted
|
|
return false;
|
|
break;
|
|
}
|
|
// see if we have content and all needed details
|
|
if (isset($content) && self::checkArray($content)
|
|
&& isset($content['contributor_company'])
|
|
&& isset($content['contributor_name'])
|
|
&& isset($content['contributor_email'])
|
|
&& isset($content['contributor_website']))
|
|
{
|
|
// got the details from file
|
|
return array('contributor_company' => $content['contributor_company'] ,'contributor_name' => $content['contributor_name'], 'contributor_email' => $content['contributor_email'], 'contributor_website' => $content['contributor_website'], 'origin' => 'file');
|
|
}
|
|
// get the global settings
|
|
if (!self::checkObject(self::$params))
|
|
{
|
|
self::$params = JComponentHelper::getParams('com_componentbuilder');
|
|
}
|
|
// get the global company details
|
|
if (!self::checkArray(self::$localCompany))
|
|
{
|
|
// Set the person sharing information (default VDM ;)
|
|
self::$localCompany['company'] = self::$params->get('export_company', 'Vast Development Method');
|
|
self::$localCompany['owner'] = self::$params->get('export_owner', 'Llewellyn van der Merwe');
|
|
self::$localCompany['email'] = self::$params->get('export_email', 'joomla@vdm.io');
|
|
self::$localCompany['website'] = self::$params->get('export_website', 'https://www.vdm.io/');
|
|
}
|
|
// default global
|
|
return array('contributor_company' => self::$localCompany['company'] ,'contributor_name' => self::$localCompany['owner'], 'contributor_email' => self::$localCompany['email'], 'contributor_website' => self::$localCompany['website'], 'origin' => 'global');
|
|
}
|
|
|
|
/**
|
|
* Get the library files
|
|
*
|
|
* @param int $id The library id to target
|
|
*
|
|
* @return array On success the array of files that belong to this library
|
|
*
|
|
*/
|
|
public static function getLibraryFiles($id)
|
|
{
|
|
// get the library files, folders, and urls
|
|
$files = array();
|
|
// Get a db connection.
|
|
$db = JFactory::getDbo();
|
|
// Create a new query object.
|
|
$query = $db->getQuery(true);
|
|
$query->select($db->quoteName(array('b.name','a.addurls','a.addfolders','a.addfiles')));
|
|
$query->from($db->quoteName('#__componentbuilder_library_files_folders_urls','a'));
|
|
$query->join('LEFT', $db->quoteName('#__componentbuilder_library', 'b') . ' ON (' . $db->quoteName('a.library') . ' = ' . $db->quoteName('b.id') . ')');
|
|
$query->where($db->quoteName('a.library') . ' = ' . (int) $id);
|
|
$db->setQuery($query);
|
|
$db->execute();
|
|
if ($db->getNumRows())
|
|
{
|
|
// prepare the files
|
|
$result = $db->loadObject();
|
|
// first we load the URLs
|
|
if (self::checkJson($result->addurls))
|
|
{
|
|
// convert to array
|
|
$result->addurls = json_decode($result->addurls, true);
|
|
// set urls
|
|
if (self::checkArray($result->addurls))
|
|
{
|
|
// build media folder path
|
|
$mediaPath = '/media/' . strtolower( preg_replace('/\s+/', '-', self::safeString($result->name, 'filename', ' ', false)));
|
|
// load the urls
|
|
foreach($result->addurls as $url)
|
|
{
|
|
if (isset($url['url']) && self::checkString($url['url']))
|
|
{
|
|
// set the path if needed
|
|
if (isset($url['type']) && $url['type'] > 1)
|
|
{
|
|
$fileName = basename($url['url']);
|
|
// build sub path
|
|
if (strpos($fileName, '.js') !== false)
|
|
{
|
|
$path = '/js';
|
|
}
|
|
elseif (strpos($fileName, '.css') !== false)
|
|
{
|
|
$path = '/css';
|
|
}
|
|
else
|
|
{
|
|
$path = '';
|
|
}
|
|
// set the path to library file
|
|
$url['path'] = $mediaPath . $path . '/' . $fileName; // we need this for later
|
|
}
|
|
// if local path is set, then use it first
|
|
if (isset($url['path']))
|
|
{
|
|
// load document script
|
|
$files[md5($url['path'])] = '(' . JText::_('URL') . ') ' . basename($url['url']) . ' - ' . JText::_('COM_COMPONENTBUILDER_LOCAL');
|
|
}
|
|
// check if link must be added
|
|
if (isset($url['url']) && ((isset($url['type']) && $url['type'] == 1) || (isset($url['type']) && $url['type'] == 3) || !isset($url['type'])))
|
|
{
|
|
// load url also if not building document
|
|
$files[md5($url['url'])] = '(' . JText::_('URL') . ') ' . basename($url['url']) . ' - ' . JText::_('COM_COMPONENTBUILDER_LINK');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// load the local files
|
|
if (self::checkJson($result->addfiles))
|
|
{
|
|
// convert to array
|
|
$result->addfiles = json_decode($result->addfiles, true);
|
|
// set files
|
|
if (self::checkArray($result->addfiles))
|
|
{
|
|
foreach($result->addfiles as $file)
|
|
{
|
|
if (isset($file['file']) && isset($file['path']))
|
|
{
|
|
$path = '/'.trim($file['path'], '/');
|
|
// check if path has new file name (has extetion)
|
|
$pathInfo = pathinfo($path);
|
|
if (isset($pathInfo['extension']) && $pathInfo['extension'])
|
|
{
|
|
// load document script
|
|
$files[md5($path)] = '(' . JText::_('COM_COMPONENTBUILDER_FILE') . ') ' . $file['file'];
|
|
}
|
|
else
|
|
{
|
|
// load document script
|
|
$files[md5($path.'/'.trim($file['file'],'/'))] = '(' . JText::_('COM_COMPONENTBUILDER_FILE') . ') ' . $file['file'];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// load the files in the folder
|
|
if (self::checkJson($result->addfolders))
|
|
{
|
|
// convert to array
|
|
$result->addfolders = json_decode($result->addfolders, true);
|
|
// set folder
|
|
if (self::checkArray($result->addfolders))
|
|
{
|
|
// get the global settings
|
|
if (!self::checkObject(self::$params))
|
|
{
|
|
self::$params = JComponentHelper::getParams('com_componentbuilder');
|
|
}
|
|
// reset bucket
|
|
$bucket = array();
|
|
// get custom folder path
|
|
$customPath = '/'.trim(self::$params->get('custom_folder_path', JPATH_COMPONENT_ADMINISTRATOR.'/custom'), '/');
|
|
// get all the file paths
|
|
foreach ($result->addfolders as $folder)
|
|
{
|
|
if (isset($folder['path']) && isset($folder['folder']))
|
|
{
|
|
$_path = '/'.trim($folder['path'], '/');
|
|
$customFolder = '/'.trim($folder['folder'], '/');
|
|
if (isset($folder['rename']) && 1 == $folder['rename'])
|
|
{
|
|
if ($_paths = self::getAllFilePaths($customPath.$customFolder))
|
|
{
|
|
$bucket[$_path] = $_paths;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
$path = $_path.$customFolder;
|
|
if ($_paths = self::getAllFilePaths($customPath.$customFolder))
|
|
{
|
|
$bucket[$path] = $_paths;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// now load the script
|
|
if (self::checkArray($bucket))
|
|
{
|
|
foreach ($bucket as $root => $paths)
|
|
{
|
|
// load per path
|
|
foreach($paths as $path)
|
|
{
|
|
$files[md5($root.'/'.trim($path, '/'))] = '(' . JText::_('COM_COMPONENTBUILDER_FOLDER') . ') ' . basename($path) . ' - ' . basename($root);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// return files if found
|
|
if (self::checkArray($files))
|
|
{
|
|
return $files;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Fix the path to work in the JCB script <-- (main issue here)
|
|
* Since we need / slash in all paths, for the JCB script even if it is Windows
|
|
* and since MS works with both forward and back slashes
|
|
* we just convert all slashes to forward slashes
|
|
*
|
|
* THIS is just my hack (fix) if you know a better way! speak-up!
|
|
*
|
|
* @param mix $values the array of paths or the path as a string
|
|
* @param array $targets paths to target
|
|
*
|
|
* @return string
|
|
*
|
|
*/
|
|
public static function fixPath(&$values, $targets = array())
|
|
{
|
|
// if multiple to gets searched and fixed
|
|
if (self::checkArray($values) && self::checkArray($targets))
|
|
{
|
|
foreach ($targets as $target)
|
|
{
|
|
if (isset($values[$target]) && strpos($values[$target], '\\') !== false)
|
|
{
|
|
$values[$target] = str_replace('\\', '/', $values[$target]);
|
|
}
|
|
}
|
|
}
|
|
// if just a string
|
|
elseif (self::checkString($values) && strpos($values, '\\') !== false)
|
|
{
|
|
$values = str_replace('\\', '/', $values);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* get all the file paths in folder and sub folders
|
|
*
|
|
* @param string $folder The local path to parse
|
|
* @param array $fileTypes The type of files to get
|
|
*
|
|
* @return void
|
|
*
|
|
*/
|
|
public static function getAllFilePaths($folder, $fileTypes = array('\.php', '\.js', '\.css', '\.less'), $recurse = true, $full = true)
|
|
{
|
|
if (JFolder::exists($folder))
|
|
{
|
|
// we must first store the current woking directory
|
|
$joomla = getcwd();
|
|
// we are changing the working directory to the componet path
|
|
chdir($folder);
|
|
// make sure we have file type filter
|
|
if (self::checkArray($fileTypes))
|
|
{
|
|
// get the files
|
|
foreach ($fileTypes as $type)
|
|
{
|
|
// get a list of files in the current directory tree
|
|
$files[] = JFolder::files('.', $type, $recurse, $full);
|
|
}
|
|
}
|
|
elseif (self::checkString($fileTypes))
|
|
{
|
|
// get a list of files in the current directory tree
|
|
$files[] = JFolder::files('.', $fileTypes, $recurse, $full);
|
|
}
|
|
else
|
|
{
|
|
// get a list of files in the current directory tree
|
|
$files[] = JFolder::files('.', '.', $recurse, $full);
|
|
}
|
|
// change back to Joomla working directory
|
|
chdir($joomla);
|
|
// return array of files
|
|
return array_map( function($file) { return str_replace('./', '/', $file); }, (array) self::mergeArrays($files));
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* get all component IDs
|
|
*/
|
|
public static function getComponentIDs()
|
|
{
|
|
// Get a db connection.
|
|
$db = JFactory::getDbo();
|
|
// Create a new query object.
|
|
$query = $db->getQuery(true);
|
|
$query->select($db->quoteName(array('id')));
|
|
$query->from($db->quoteName('#__componentbuilder_joomla_component'));
|
|
$query->where($db->quoteName('published') . ' >= 1'); // do not backup trash
|
|
$db->setQuery($query);
|
|
$db->execute();
|
|
if ($db->getNumRows())
|
|
{
|
|
return $db->loadColumn();
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Autoloader
|
|
*/
|
|
public static function autoLoader($type = 'compiler')
|
|
{
|
|
// load the type classes
|
|
if ('smart' !== $type)
|
|
{
|
|
foreach (glob(JPATH_ADMINISTRATOR."/components/com_componentbuilder/helpers/".$type."/*.php") as $autoFile)
|
|
{
|
|
require_once $autoFile;
|
|
}
|
|
}
|
|
// load only if compiler
|
|
if ('compiler' === $type)
|
|
{
|
|
// import the Joomla librarys
|
|
jimport('joomla.filesystem.file');
|
|
jimport('joomla.filesystem.folder');
|
|
jimport('joomla.filesystem.archive');
|
|
jimport('joomla.application.component.modellist');
|
|
// include class to minify js
|
|
require_once JPATH_ADMINISTRATOR.'/components/com_componentbuilder/helpers/js.php';
|
|
}
|
|
// load only if smart
|
|
if ('smart' === $type)
|
|
{
|
|
// import the Joomla libraries
|
|
jimport('joomla.filesystem.file');
|
|
jimport('joomla.filesystem.folder');
|
|
jimport('joomla.filesystem.archive');
|
|
jimport('joomla.application.component.modellist');
|
|
}
|
|
// load this for all
|
|
jimport('joomla.application');
|
|
}
|
|
|
|
/**
|
|
* The dynamic builder of views, tables and fields
|
|
**/
|
|
public static function dynamicBuilder(&$data, $type)
|
|
{
|
|
self::autoLoader('extrusion');
|
|
$extruder = new Extrusion($data);
|
|
}
|
|
|
|
/*
|
|
* Convert repeatable field to subform
|
|
*
|
|
* @param array $item The array to convert
|
|
* @param string $name The main field name
|
|
*
|
|
* @return array
|
|
*/
|
|
public static function convertRepeatable($item, $name)
|
|
{
|
|
// continue only if we have an array
|
|
if (self::checkArray($item))
|
|
{
|
|
$bucket = array();
|
|
foreach ($item as $key => $values)
|
|
{
|
|
foreach ($values as $nr => $value)
|
|
{
|
|
if (!isset($bucket[$name . $nr]) || !self::checkArray($bucket[$name . $nr]))
|
|
{
|
|
$bucket[$name . $nr] = array();
|
|
}
|
|
$bucket[$name . $nr][$key] = $value;
|
|
}
|
|
}
|
|
return $bucket;
|
|
}
|
|
return $item;
|
|
}
|
|
|
|
/*
|
|
* Convert repeatable field to subform
|
|
*
|
|
* @param object $item The item to update
|
|
* @param array $searcher The fields to check and update
|
|
* @param array $updater To update the local table
|
|
*
|
|
* @return void
|
|
*/
|
|
public static function convertRepeatableFields($object, $searcher, $updater = array())
|
|
{
|
|
// update the repeatable fields
|
|
foreach ($searcher as $key => $sleutel)
|
|
{
|
|
if (isset($object->{$key}))
|
|
{
|
|
$isJson = false;
|
|
if (self::checkJson($object->{$key}))
|
|
{
|
|
$object->{$key} = json_decode($object->{$key}, true);
|
|
$isJson = true;
|
|
}
|
|
// check if this is old values for repeatable fields
|
|
if (self::checkArray($object->{$key}) && isset($object->{$key}[$sleutel]))
|
|
{
|
|
// load it back
|
|
$object->{$key} = self::convertRepeatable($object->{$key}, $key);
|
|
// add to global updater
|
|
if (
|
|
self::checkArray($object->{$key}) && self::checkArray($updater) &&
|
|
(
|
|
( isset($updater['table']) && isset($updater['val']) && isset($updater['key']) ) ||
|
|
( isset($updater['unique']) && isset($updater['unique'][$key]) && isset($updater['unique'][$key]['table']) && isset($updater['unique'][$key]['val']) && isset($updater['unique'][$key]['key']) )
|
|
)
|
|
)
|
|
{
|
|
$_key = null;
|
|
$_value = null;
|
|
$_table = null;
|
|
// check if we have unique id table for this repeatable/subform field
|
|
if ( isset($updater['unique']) && isset($updater['unique'][$key]) && isset($updater['unique'][$key]['table']) && isset($updater['unique'][$key]['val']) && isset($updater['unique'][$key]['key']) )
|
|
{
|
|
$_key = $updater['unique'][$key]['key'];
|
|
$_value = $updater['unique'][$key]['val'];
|
|
$_table = $updater['unique'][$key]['table'];
|
|
}
|
|
elseif ( isset($updater['table']) && isset($updater['val']) && isset($updater['key']) )
|
|
{
|
|
$_key = $updater['key'];
|
|
$_value = $updater['val'];
|
|
$_table = $updater['table'];
|
|
}
|
|
// continue only if values are valid
|
|
if (self::checkString($_table) && self::checkString($_key) && $_value > 0)
|
|
{
|
|
// set target table & item
|
|
$target = trim($_table) . '.' . trim($_key) . '.' . trim($_value);
|
|
if (!isset(self::$globalUpdater[$target]))
|
|
{
|
|
self::$globalUpdater[$target] = new stdClass;
|
|
self::$globalUpdater[$target]->{$_key} = (int) $_value;
|
|
}
|
|
// load the new subform values to global updater
|
|
self::$globalUpdater[$target]->{$key} = json_encode($object->{$key});
|
|
}
|
|
}
|
|
}
|
|
// no set back to json if came in as json
|
|
if ($isJson && self::checkArray($object->{$key}))
|
|
{
|
|
$object->{$key} = json_encode($object->{$key});
|
|
}
|
|
// remove if not json or array
|
|
elseif (!self::checkArray($object->{$key}) && !self::checkJson($object->{$key}))
|
|
{
|
|
unset($object->{$key});
|
|
}
|
|
}
|
|
}
|
|
return $object;
|
|
}
|
|
|
|
/**
|
|
* Run Global Updater if any are set
|
|
*
|
|
* @return void
|
|
*
|
|
*/
|
|
public static function runGlobalUpdater()
|
|
{
|
|
// check if any updates are set to run
|
|
if (self::checkArray(self::$globalUpdater))
|
|
{
|
|
// get the database object
|
|
$db = JFactory::getDbo();
|
|
foreach (self::$globalUpdater as $tableKeyID => $object)
|
|
{
|
|
// get the table
|
|
$table = explode('.', $tableKeyID);
|
|
// update the item
|
|
$db->updateObject('#__componentbuilder_' . (string) $table[0] , $object, (string) $table[1]);
|
|
}
|
|
// rest updater
|
|
self::$globalUpdater = array();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Copy Any Item (only use for direct database copying)
|
|
*
|
|
* @param int $id The item to copy
|
|
* @param string $table The table and model to copy from and with
|
|
* @param array $config The values that should change
|
|
*
|
|
* @return boolean True if success
|
|
*
|
|
*/
|
|
public static function copyItem($id, $type, $config = array())
|
|
{
|
|
// only continue if we have an id
|
|
if ((int) $id > 0)
|
|
{
|
|
// get the model
|
|
$model = self::getModel($type);
|
|
$app = \JFactory::getApplication();
|
|
// get item
|
|
if ($item = $model->getItem($id))
|
|
{
|
|
// update values that should change
|
|
if (self::checkArray($config))
|
|
{
|
|
foreach($config as $key => $value)
|
|
{
|
|
if (isset($item->{$key}))
|
|
{
|
|
$item->{$key} = $value;
|
|
}
|
|
}
|
|
}
|
|
// clone the object
|
|
$data = array();
|
|
foreach ($item as $key => $value)
|
|
{
|
|
$data[$key] = $value;
|
|
}
|
|
// reset some values
|
|
$data['id'] = 0;
|
|
$data['version'] = 1;
|
|
if (isset($data['tags']))
|
|
{
|
|
$data['tags'] = null;
|
|
}
|
|
if (isset($data['associations']))
|
|
{
|
|
$data['associations'] = array();
|
|
}
|
|
// remove some unneeded values
|
|
unset($data['params']);
|
|
unset($data['asset_id']);
|
|
unset($data['checked_out']);
|
|
unset($data['checked_out_time']);
|
|
// Attempt to save the data.
|
|
if ($model->save($data))
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* the basic localkey
|
|
**/
|
|
protected static $localkey = false;
|
|
|
|
/**
|
|
* get the localkey
|
|
**/
|
|
public static function getLocalKey()
|
|
{
|
|
if (!self::$localkey)
|
|
{
|
|
// get the basic key
|
|
self::$localkey = md5(self::getCryptKey('basic', 'localKey34fdWEkl'));
|
|
}
|
|
return self::$localkey;
|
|
}
|
|
|
|
/**
|
|
* indent HTML
|
|
*/
|
|
public static function indent($html)
|
|
{
|
|
// load the class
|
|
require_once JPATH_ADMINISTRATOR.'/components/com_componentbuilder/helpers/indenter.php';
|
|
// set new indenter
|
|
$indenter = new Indenter();
|
|
// return indented html
|
|
return $indenter->indent($html);
|
|
}
|
|
|
|
public static function checkFileType($file, $sufix)
|
|
{
|
|
// now check if the file ends with the sufix
|
|
return $sufix === "" || ($sufix == substr(strrchr($file, "."), -strlen($sufix)));
|
|
}
|
|
|
|
public static function imageInfo($path, $request = 'type')
|
|
{
|
|
// set image
|
|
$image = JPATH_SITE.'/'.$path;
|
|
// check if exists
|
|
if (file_exists($image) && $result = @getimagesize($image))
|
|
{
|
|
// return type request
|
|
switch ($request)
|
|
{
|
|
case 'width':
|
|
return $result[0];
|
|
break;
|
|
case 'height':
|
|
return $result[1];
|
|
break;
|
|
case 'type':
|
|
$extensions = array(
|
|
IMAGETYPE_GIF => "gif",
|
|
IMAGETYPE_JPEG => "jpg",
|
|
IMAGETYPE_PNG => "png",
|
|
IMAGETYPE_SWF => "swf",
|
|
IMAGETYPE_PSD => "psd",
|
|
IMAGETYPE_BMP => "bmp",
|
|
IMAGETYPE_TIFF_II => "tiff",
|
|
IMAGETYPE_TIFF_MM => "tiff",
|
|
IMAGETYPE_JPC => "jpc",
|
|
IMAGETYPE_JP2 => "jp2",
|
|
IMAGETYPE_JPX => "jpx",
|
|
IMAGETYPE_JB2 => "jb2",
|
|
IMAGETYPE_SWC => "swc",
|
|
IMAGETYPE_IFF => "iff",
|
|
IMAGETYPE_WBMP => "wbmp",
|
|
IMAGETYPE_XBM => "xbm",
|
|
IMAGETYPE_ICO => "ico"
|
|
);
|
|
return $extensions[$result[2]];
|
|
break;
|
|
case 'attr':
|
|
return $result[3];
|
|
break;
|
|
case 'all':
|
|
default:
|
|
return $result;
|
|
break;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* set the session defaults if not set
|
|
**/
|
|
protected static function setSessionDefaults()
|
|
{
|
|
// noting for now
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* check if it is a new hash
|
|
**/
|
|
public static function newHash($hash, $name = 'backup', $type = 'hash', $key = '', $fileType = 'txt')
|
|
{
|
|
// make sure we have a hash
|
|
if (self::checkString($hash))
|
|
{
|
|
// first get the file path
|
|
$path_filename = self::getFilePath('path', $name.$type, $fileType, $key, JPATH_COMPONENT_ADMINISTRATOR);
|
|
// set as read if not already set
|
|
if ($content = self::getFileContents($path_filename, false))
|
|
{
|
|
if ($hash == $content)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
// set the hash
|
|
return self::writeFile($path_filename, $hash);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
protected static $pkOwnerSearch = array(
|
|
'company' => 'COM_COMPONENTBUILDER_DTCOMPANYDTDDSDD',
|
|
'owner' => 'COM_COMPONENTBUILDER_DTOWNERDTDDSDD',
|
|
'email' => 'COM_COMPONENTBUILDER_DTEMAILDTDDSDD',
|
|
'website' => 'COM_COMPONENTBUILDER_DTWEBSITEDTDDSDD',
|
|
'license' => 'COM_COMPONENTBUILDER_DTLICENSEDTDDSDD',
|
|
'copyright' => 'COM_COMPONENTBUILDER_DTCOPYRIGHTDTDDSDD'
|
|
);
|
|
|
|
/**
|
|
* get the JCB package owner details display
|
|
**/
|
|
public static function getPackageOwnerDetailsDisplay(&$info, $trust = false)
|
|
{
|
|
$hasOwner = false;
|
|
$ownerDetails = '<h2 class="module-title nav-header">' . JText::_('COM_COMPONENTBUILDER_PACKAGE_OWNER_DETAILS') . '</h2>';
|
|
$ownerDetails .= '<dl class="uk-description-list-horizontal">';
|
|
// load the list items
|
|
foreach (self::$pkOwnerSearch as $key => $dd)
|
|
{
|
|
if ($value = self::getPackageOwnerValue($key, $info))
|
|
{
|
|
$ownerDetails .= JText::sprintf($dd, $value);
|
|
// check if we have a owner/source name
|
|
if (('owner' === $key || 'company' === $key) && !$hasOwner)
|
|
{
|
|
$hasOwner = true;
|
|
$owner = $value;
|
|
}
|
|
}
|
|
}
|
|
$ownerDetails .= '</dl>';
|
|
|
|
// provide some details to how the user can get a key
|
|
if ($hasOwner && isset($info['getKeyFrom']['buy_link']) && self::checkString($info['getKeyFrom']['buy_link']))
|
|
{
|
|
$ownerDetails .= '<hr />';
|
|
$ownerDetails .= JText::sprintf('COM_COMPONENTBUILDER_BGET_THE_KEY_FROMB_A_SSA', 'class="btn btn-primary" href="'.$info['getKeyFrom']['buy_link'].'" target="_blank" title="get a key from '.$owner.'"', $owner);
|
|
}
|
|
// add more custom links
|
|
elseif ($hasOwner && isset($info['getKeyFrom']['buy_links']) && self::checkArray($info['getKeyFrom']['buy_links']))
|
|
{
|
|
$buttons = array();
|
|
foreach ($info['getKeyFrom']['buy_links'] as $keyName => $link)
|
|
{
|
|
$buttons[] = JText::sprintf('COM_COMPONENTBUILDER_BGET_THE_KEY_FROM_SB_FOR_A_SSA', $owner, 'class="btn btn-primary" href="'.$link.'" target="_blank" title="get a key from '.$owner.'"', $keyName);
|
|
}
|
|
$ownerDetails .= '<hr />';
|
|
$ownerDetails .= implode('<br />', $buttons);
|
|
}
|
|
// return the owner details
|
|
if (!$hasOwner)
|
|
{
|
|
$ownerDetails = '<h2>' . JText::_('COM_COMPONENTBUILDER_PACKAGE_OWNER_DETAILS_NOT_FOUND') . '</h2>';
|
|
if (!$trust)
|
|
{
|
|
$ownerDetails .= '<p style="color: #922924;">' . JText::_('COM_COMPONENTBUILDER_BE_CAUTIOUS_DO_NOT_CONTINUE_UNLESS_YOU_TRUST_THE_ORIGIN_OF_THIS_PACKAGE') . '</p>';
|
|
}
|
|
}
|
|
return '<div>'.$ownerDetails.'</div>';
|
|
}
|
|
|
|
public static function getPackageOwnerValue($key, &$info)
|
|
{
|
|
$source = (isset($info['source']) && isset($info['source'][$key])) ? 'source' : ((isset($info['getKeyFrom']) && isset($info['getKeyFrom'][$key])) ? 'getKeyFrom' : false);
|
|
if ($source && self::checkString($info[$source][$key]))
|
|
{
|
|
return $info[$source][$key];
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* get the JCB package component key status
|
|
**/
|
|
public static function getPackageComponentsKeyStatus(&$info)
|
|
{
|
|
// check the package key status
|
|
if (!isset($info['key']))
|
|
{
|
|
if (isset($info['getKeyFrom']) && isset($info['getKeyFrom']['owner']))
|
|
{
|
|
// this just confirms it for older packages
|
|
$info['key'] = true;
|
|
}
|
|
else
|
|
{
|
|
// this just confirms it for older packages
|
|
$info['key'] = false;
|
|
}
|
|
}
|
|
return $info['key'];
|
|
}
|
|
|
|
protected static $compOwnerSearch = array(
|
|
'ul' => array (
|
|
'companyname' => 'COM_COMPONENTBUILDER_ICOMPANYI_BSB',
|
|
'author' => 'COM_COMPONENTBUILDER_IAUTHORI_BSB',
|
|
'email' => 'COM_COMPONENTBUILDER_IEMAILI_BSB',
|
|
'website' => 'COM_COMPONENTBUILDER_IWEBSITEI_BSB',
|
|
),
|
|
'other' => array(
|
|
'license' => 'COM_COMPONENTBUILDER_HFOUR_CLASSNAVHEADERLICENSEHFOURPSP',
|
|
'copyright' => 'COM_COMPONENTBUILDER_HFOUR_CLASSNAVHEADERCOPYRIGHTHFOURPSP'
|
|
)
|
|
);
|
|
|
|
/**
|
|
* get the JCB package component details display
|
|
**/
|
|
public static function getPackageComponentsDetailsDisplay(&$info)
|
|
{
|
|
// check if these components need a key
|
|
$needKey = self::getPackageComponentsKeyStatus($info);
|
|
if (isset($info['name']) && self::checkArray($info['name']))
|
|
{
|
|
$cAmount = count((array) $info['name']);
|
|
$class2 = ($cAmount == 1) ? 'span12' : 'span6';
|
|
$counter = 1;
|
|
$display = array();
|
|
foreach ($info['name'] as $key => $value)
|
|
{
|
|
// set the name
|
|
$name= $value . ' v' . $info['component_version'][$key];
|
|
if ($cAmount > 1 && $counter == 3)
|
|
{
|
|
$display[] = '</div>';
|
|
$counter = 1;
|
|
}
|
|
if ($cAmount > 1 && $counter == 1)
|
|
{
|
|
$display[] = '<div>';
|
|
}
|
|
$display[] = '<div class="well well-small ' . $class2 . '">';
|
|
$display[] = '<h3>';
|
|
$display[] = $name;
|
|
if ($needKey)
|
|
{
|
|
$display[] = ' - <em>' . JText::sprintf('COM_COMPONENTBUILDER_PAIDLOCKED') . '</em>';
|
|
}
|
|
else
|
|
{
|
|
$display[] = ' - <em>' . JText::sprintf('COM_COMPONENTBUILDER_FREEOPEN') . '</em>';
|
|
}
|
|
$display[] = '</h3><h4>';
|
|
$display[] = $info['short_description'][$key];
|
|
$display[] = '</h4>';
|
|
$display[] = '<ul class="uk-list uk-list-striped">';
|
|
// load the list items
|
|
foreach (self::$compOwnerSearch['ul'] as $li => $value)
|
|
{
|
|
if (isset($info[$li]) && isset($info[$li][$key]))
|
|
{
|
|
$display[] = '<li>'.JText::sprintf($value, $info[$li][$key]).'</li>';
|
|
}
|
|
}
|
|
$display[] = '</ul>';
|
|
// if we have a source link we add it
|
|
if (isset($info['joomla_source_link']) && self::checkArray($info['joomla_source_link']) && isset($info['joomla_source_link'][$key]) && self::checkString($info['joomla_source_link'][$key]))
|
|
{
|
|
$display[] = '<a class="uk-button uk-button-mini uk-width-1-1 uk-margin-small-bottom " href="'.$info['joomla_source_link'][$key].'" target="_blank" title="Source Code for Joomla Component ('.$name.')">source code</a>';
|
|
}
|
|
// load other
|
|
foreach (self::$compOwnerSearch['other'] as $other => $value)
|
|
{
|
|
if (isset($info[$other]) && isset($info[$other][$key]))
|
|
{
|
|
$display[] = JText::sprintf($value, $info[$other][$key]);
|
|
}
|
|
}
|
|
$display[] = '</div>';
|
|
|
|
$counter++;
|
|
}
|
|
// close the div if needed
|
|
if ($cAmount > 1)
|
|
{
|
|
$display[] = '</div>';
|
|
}
|
|
return implode("\n",$display);
|
|
}
|
|
return '<div>'.JText::_('COM_COMPONENTBUILDER_NO_COMPONENT_DETAILS_FOUND_SO_IT_IS_NOT_SAFE_TO_CONTINUE').'</div>';
|
|
}
|
|
|
|
/**
|
|
* get the database table columns
|
|
**/
|
|
public static function getDbTableColumns($tableName, $as, $type)
|
|
{
|
|
// Get a db connection.
|
|
$db = JFactory::getDbo();
|
|
// get the columns
|
|
$columns = $db->getTableColumns("#__" . $tableName);
|
|
// set the type (multi or single)
|
|
$unique = '';
|
|
if (1 == $type)
|
|
{
|
|
$unique = self::safeString($tableName) . '_';
|
|
}
|
|
if (self::checkArray($columns))
|
|
{
|
|
// build the return string
|
|
$tableColumns = array();
|
|
foreach ($columns as $column => $typeCast)
|
|
{
|
|
$tableColumns[] = $as . "." . $column . ' AS ' . $unique . $column;
|
|
}
|
|
return implode("\n", $tableColumns);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* get the view table columns
|
|
**/
|
|
public static function getViewTableColumns($admin_view, $as, $type)
|
|
{
|
|
// Get a db connection.
|
|
$db = JFactory::getDbo();
|
|
|
|
// Create a new query object.
|
|
$query = $db->getQuery(true);
|
|
$query->select($db->quoteName(array('a.addfields', 'b.name_single')));
|
|
$query->from($db->quoteName('#__componentbuilder_admin_fields', 'a'));
|
|
$query->join('LEFT', $db->quoteName('#__componentbuilder_admin_view', 'b') . ' ON (' . $db->quoteName('a.admin_view') . ' = ' . $db->quoteName('b.id') . ')');
|
|
$query->where($db->quoteName('b.published') . ' = 1');
|
|
$query->where($db->quoteName('a.admin_view') . ' = ' . (int) $admin_view);
|
|
|
|
// Reset the query using our newly populated query object.
|
|
$db->setQuery($query);
|
|
$db->execute();
|
|
if ($db->getNumRows())
|
|
{
|
|
$result = $db->loadObject();
|
|
$tableName = '';
|
|
if (1 == $type)
|
|
{
|
|
$tableName = self::safeString($result->name_single) . '_';
|
|
}
|
|
$addfields = json_decode($result->addfields, true);
|
|
if (self::checkArray($addfields))
|
|
{
|
|
// reset all buckets
|
|
$field = array();
|
|
$fields = array();
|
|
// get data
|
|
foreach ($addfields as $nr => $value)
|
|
{
|
|
$tmp = self::getFieldNameAndType((int) $value['field']);
|
|
if (self::checkArray($tmp))
|
|
{
|
|
$field[$nr] = $tmp;
|
|
}
|
|
// insure it is set to alias if needed
|
|
if (isset($value['alias']) && $value['alias'] == 1)
|
|
{
|
|
$field[$nr]['name'] = 'alias';
|
|
}
|
|
// remove a field that is not being stored in the database
|
|
if (!isset($value['list']) || $value['list'] == 2)
|
|
{
|
|
unset($field[$nr]);
|
|
}
|
|
}
|
|
// add the basic defaults
|
|
$fields[] = $as . ".id AS " . $tableName . "id";
|
|
$fields[] = $as . ".asset_id AS " . $tableName . "asset_id";
|
|
// load data
|
|
foreach ($field as $n => $f)
|
|
{
|
|
if (self::checkArray($f))
|
|
{
|
|
$fields[] = $as . "." . $f['name'] . " AS " . $tableName . $f['name'];
|
|
}
|
|
}
|
|
// add the basic defaults
|
|
$fields[] = $as . ".published AS " . $tableName . "published";
|
|
$fields[] = $as . ".created_by AS " . $tableName . "created_by";
|
|
$fields[] = $as . ".modified_by AS " . $tableName . "modified_by";
|
|
$fields[] = $as . ".created AS " . $tableName . "created";
|
|
$fields[] = $as . ".modified AS " . $tableName . "modified";
|
|
$fields[] = $as . ".version AS " . $tableName . "version";
|
|
$fields[] = $as . ".hits AS " . $tableName . "hits";
|
|
if (0) // TODO access is not set here but per/view in the form linking this admin view to which these field belong to the components (boooo I know but that is the case and so we can't ever really know at this point if this view has access set)
|
|
{
|
|
$fields[] = $as . ".access AS " . $tableName . "access";
|
|
}
|
|
$fields[] = $as . ".ordering AS " . $tableName . "ordering";
|
|
// return the field of this view
|
|
return implode("\n", $fields);
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public static function getFieldNameAndType($id, $spacers = false)
|
|
{
|
|
// Get a db connection.
|
|
$db = JFactory::getDbo();
|
|
|
|
// Create a new query object.
|
|
$query = $db->getQuery(true);
|
|
|
|
// Order it by the ordering field.
|
|
$query->select($db->quoteName(array('a.name', 'a.xml')));
|
|
$query->select($db->quoteName(array('c.name'), array('type_name')));
|
|
$query->from('#__componentbuilder_field AS a');
|
|
$query->join('LEFT', $db->quoteName('#__componentbuilder_fieldtype', 'c') . ' ON (' . $db->quoteName('a.fieldtype') . ' = ' . $db->quoteName('c.id') . ')');
|
|
$query->where($db->quoteName('a.id') . ' = '. $db->quote($id));
|
|
|
|
// Reset the query using our newly populated query object.
|
|
$db->setQuery($query);
|
|
$db->execute();
|
|
if ($db->getNumRows())
|
|
{
|
|
// Load the results as a list of stdClass objects (see later for more options on retrieving data).
|
|
$field = $db->loadObject();
|
|
// load the values form params
|
|
$field->xml = json_decode($field->xml);
|
|
$field->type_name = self::safeTypeName($field->type_name);
|
|
$load = true;
|
|
// if category then name must be catid (only one per view)
|
|
if ($field->type_name === 'category')
|
|
{
|
|
$name = 'catid';
|
|
}
|
|
// if tag is set then enable all tag options for this view (only one per view)
|
|
elseif ($field->type_name === 'tag')
|
|
{
|
|
$name = 'tags';
|
|
}
|
|
// don't add spacers or notes
|
|
elseif (!$spacers && ($field->type_name == 'spacer' || $field->type_name == 'note'))
|
|
{
|
|
// make sure the name is unique
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
$name = self::safeFieldName(self::getBetween($field->xml,'name="','"'));
|
|
}
|
|
|
|
// use field core name only if not found in xml
|
|
if (!self::checkString($name))
|
|
{
|
|
$name = self::safeFieldName($field->name);
|
|
}
|
|
return array('name' => $name, 'type' => $field->type_name);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* validate that a placeholder is unique
|
|
**/
|
|
public static function validateUniquePlaceholder($id, $name, $bool = false)
|
|
{
|
|
// make sure no padding is set
|
|
$name = preg_replace("/[^A-Za-z0-9_]/", '', $name);
|
|
// this list may grow as we find more cases that break the compiler (just open an issue on github)
|
|
if (in_array($name, array('component', 'view', 'views')))
|
|
{
|
|
// check if we must return boolean
|
|
if (!$bool)
|
|
{
|
|
return array (
|
|
'message' => JText::_('COM_COMPONENTBUILDER_SORRY_THIS_PLACEHOLDER_IS_ALREADY_IN_USE_IN_THE_COMPILER'),
|
|
'status' => 'danger');
|
|
}
|
|
return false;
|
|
}
|
|
// add the padding (needed)
|
|
$name = '[[[' . trim($name) . ']]]';
|
|
if (self::placeholderIsSet($id, $name))
|
|
{
|
|
// check if we must return boolean
|
|
if (!$bool)
|
|
{
|
|
return array (
|
|
'message' => JText::_('COM_COMPONENTBUILDER_SORRY_THIS_PLACEHOLDER_IS_ALREADY_IN_USE'),
|
|
'status' => 'danger');
|
|
}
|
|
return false;
|
|
}
|
|
// check if we must return boolean
|
|
if (!$bool)
|
|
{
|
|
return array (
|
|
'name' => $name,
|
|
'message' => JText::_('COM_COMPONENTBUILDER_GREAT_THIS_PLACEHOLDER_WILL_WORK'),
|
|
'status' => 'success');
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* search for placeholder in table
|
|
**/
|
|
protected static function placeholderIsSet($id, $name)
|
|
{
|
|
// query the table for result array
|
|
if (($results = self::getPlaceholderTarget($id, $name)) !== false)
|
|
{
|
|
// check if we must continue the search
|
|
foreach ($results as $_id => $target)
|
|
{
|
|
if ($name === $target)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* get placeholder target
|
|
**/
|
|
protected static function getPlaceholderTarget($id, $name)
|
|
{
|
|
// Get a db connection.
|
|
$db = JFactory::getDbo();
|
|
// Create a new query object.
|
|
$query = $db->getQuery(true);
|
|
$query->select($db->quoteName(array('id', 'target')));
|
|
$query->from($db->quoteName('#__componentbuilder_placeholder'));
|
|
$query->where($db->quoteName('target') . ' = '. $db->quote($name));
|
|
// check if we have id
|
|
if (is_numeric($id))
|
|
{
|
|
$query->where($db->quoteName('id') . ' <> ' . (int) $id);
|
|
}
|
|
$db->setQuery($query);
|
|
$db->execute();
|
|
if ($db->getNumRows())
|
|
{
|
|
return $db->loadAssocList('id', 'target');
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* The array of dynamic content
|
|
*
|
|
* @var array
|
|
*/
|
|
protected static $dynamicContent = array(
|
|
// The banners by size
|
|
'banner' => array(
|
|
'728-90' => array(
|
|
'<a href="https://vdm.bz/joomla-volunteers" target="_blank" title="Joomla! Volunteers Portal"><img src="https://cdn.joomla.org/volunteers/joomla-heart-wide.gif" alt="Joomla! Volunteers Portal" width="728" height="90" border="0"></a>',
|
|
'<a href="https://vdm.bz/joomla-magazine" target="_blank" title="Joomla! Community Magazine | Because community matters..."><img alt="Joomla! Community Magazine | Because community matters..." src="https://magazine.joomla.org/images/banners/JCM_2010_728x90.png" width="728" height="90" border="0" /></a>',
|
|
'<a href="https://vdm.bz/jcb-sponsor-tlwebdesign" target="_blank" title="tlwebdesign a JCB sponsor | Because community matters..."><img alt="tlwebdesign a JCB sponsor | Because community matters..." src="https://www.joomlacomponentbuilder.com/images/banners/tlwebdesign_jcb_sponsor_728_90.png" width="728" height="90" border="0" /></a>',
|
|
'<a href="https://vdm.bz/jcb-sponsor-vdm" target="_blank" title="VDM a JCB sponsor | Because community matters..."><img alt="VDM a JCB sponsor | Because community matters..." src="https://www.joomlacomponentbuilder.com/images/banners/vdm_jcb_sponsor_728_90.gif" width="728" height="90" border="0" /></a>'
|
|
),
|
|
'160-600' => array(
|
|
'<a href="https://vdm.bz/joomla-volunteers" target="_blank" title="Joomla! Volunteers Portal"><img src="https://cdn.joomla.org/volunteers/joomla-heart-tall.gif" alt="Joomla! Volunteers Portal" width="160" height="600" border="0"></a>',
|
|
'<a href="https://vdm.bz/joomla-magazine" target="_blank" title="Joomla! Community Magazine | Because community matters..."><img src="https://magazine.joomla.org/images/banners/JCM_2010_120x600.png" alt="Joomla! Community Magazine | Because community matters..." width="120" height="600" border="0"/></a>'
|
|
)
|
|
),
|
|
// The build-gif by size
|
|
'builder-gif' => array(
|
|
'707-400' => array(
|
|
'<img src="components/com_componentbuilder/assets/images/ajax-loader.gif" />'
|
|
)
|
|
)
|
|
);
|
|
|
|
/**
|
|
* get the dynamic content
|
|
*
|
|
* @param string $type The type of content
|
|
* @param string $size The size of the content
|
|
*
|
|
* @return string on success
|
|
*
|
|
*/
|
|
public static function getDynamicContent($type, $size, $default = '')
|
|
{
|
|
if (isset(self::$dynamicContent[$type]) && isset(self::$dynamicContent[$type][$size]) && ($nr = self::checkArray(self::$dynamicContent[$type][$size])))
|
|
{
|
|
// get the random item number
|
|
$get = (int) rand(0, --$nr);
|
|
// return found content
|
|
return self::$dynamicContent[$type][$size][$get];
|
|
}
|
|
return $default;
|
|
}
|
|
|
|
/**
|
|
* Returns a GUIDv4 string
|
|
*
|
|
* Thanks to Dave Pearson (and other)
|
|
* https://www.php.net/manual/en/function.com-create-guid.php#119168
|
|
*
|
|
* Uses the best cryptographically secure method
|
|
* for all supported platforms with fallback to an older,
|
|
* less secure version.
|
|
*
|
|
* @param bool $trim
|
|
* @return string
|
|
*/
|
|
public static function GUID ($trim = true)
|
|
{
|
|
// Windows
|
|
if (function_exists('com_create_guid') === true)
|
|
{
|
|
if ($trim === true)
|
|
{
|
|
return trim(com_create_guid(), '{}');
|
|
}
|
|
return com_create_guid();
|
|
}
|
|
|
|
// set the braces if needed
|
|
$lbrace = $trim ? "" : chr(123); // "{"
|
|
$rbrace = $trim ? "" : chr(125); // "}"
|
|
|
|
// OSX/Linux
|
|
if (function_exists('openssl_random_pseudo_bytes') === true)
|
|
{
|
|
$data = openssl_random_pseudo_bytes(16);
|
|
$data[6] = chr(ord($data[6]) & 0x0f | 0x40); // set version to 0100
|
|
$data[8] = chr(ord($data[8]) & 0x3f | 0x80); // set bits 6-7 to 10
|
|
return $lbrace . vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4)) . $lbrace;
|
|
}
|
|
|
|
// Fallback (PHP 4.2+)
|
|
mt_srand((double)microtime() * 10000);
|
|
$charid = strtolower(md5(uniqid(rand(), true)));
|
|
$hyphen = chr(45); // "-"
|
|
$guidv4 = $lbrace.
|
|
substr($charid, 0, 8).$hyphen.
|
|
substr($charid, 8, 4).$hyphen.
|
|
substr($charid, 12, 4).$hyphen.
|
|
substr($charid, 16, 4).$hyphen.
|
|
substr($charid, 20, 12).
|
|
$rbrace;
|
|
return $guidv4;
|
|
}
|
|
|
|
/**
|
|
* Validate the Globally Unique Identifier ( and check if table already has this identifier)
|
|
*
|
|
* @param string $guid
|
|
* @param string $table
|
|
* @param int $id
|
|
* @return bool
|
|
*/
|
|
public static function validGUID ($guid, $table = null, $id = 0)
|
|
{
|
|
// check if we have a string
|
|
if (self::validateGUID($guid))
|
|
{
|
|
// check if table already has this identifier
|
|
if (self::checkString($table))
|
|
{
|
|
// Get the database object and a new query object.
|
|
$db = \JFactory::getDbo();
|
|
$query = $db->getQuery(true);
|
|
$query->select('COUNT(*)')
|
|
->from('#__componentbuilder_' . (string) $table)
|
|
->where($db->quoteName('guid') . ' = ' . $db->quote($guid));
|
|
|
|
// remove this item from the list
|
|
if ($id > 0)
|
|
{
|
|
$query->where($db->quoteName('id') . ' <> ' . (int) $id);
|
|
}
|
|
|
|
// Set and query the database.
|
|
$db->setQuery($query);
|
|
$duplicate = (bool) $db->loadResult();
|
|
|
|
if ($duplicate)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Validate the Globally Unique Identifier
|
|
*
|
|
* Thanks to Lewie
|
|
* https://stackoverflow.com/a/1515456/1429677
|
|
*
|
|
* @param string $guid
|
|
* @return bool
|
|
*/
|
|
protected static function validateGUID ($guid)
|
|
{
|
|
// check if we have a string
|
|
if (self::checkString($guid))
|
|
{
|
|
return preg_match("/^(\{)?[a-f\d]{8}(-[a-f\d]{4}){4}[a-f\d]{8}(?(1)\})$/i", $guid);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
|
|
/**
|
|
* Tab/spacer bucket (to speed-up the build)
|
|
*
|
|
* @var array
|
|
*/
|
|
protected static $tabSpacerBucket = array();
|
|
|
|
/**
|
|
* Set tab/spacer
|
|
*
|
|
* @var string
|
|
*/
|
|
protected static $tabSpacer = "\t";
|
|
|
|
/**
|
|
* Set the tab/space
|
|
*
|
|
* @param int $nr The number of tag/space
|
|
*
|
|
* @return string
|
|
*
|
|
*/
|
|
public static function _t($nr)
|
|
{
|
|
// check if we already have the string
|
|
if (!isset(self::$tabSpacerBucket[$nr]))
|
|
{
|
|
// get the string
|
|
self::$tabSpacerBucket[$nr] = str_repeat(self::$tabSpacer, (int) $nr);
|
|
}
|
|
// return stored string
|
|
return self::$tabSpacerBucket[$nr];
|
|
}
|
|
|
|
|
|
/**
|
|
* the Butler
|
|
**/
|
|
public static $session = array();
|
|
|
|
/**
|
|
* the Butler Assistant
|
|
**/
|
|
protected static $localSession = array();
|
|
|
|
/**
|
|
* start a session if not already set, and load with data
|
|
**/
|
|
public static function loadSession()
|
|
{
|
|
if (!isset(self::$session) || !self::checkObject(self::$session))
|
|
{
|
|
self::$session = JFactory::getSession();
|
|
}
|
|
// set the defaults
|
|
self::setSessionDefaults();
|
|
}
|
|
|
|
/**
|
|
* give Session more to keep
|
|
**/
|
|
public static function set($key, $value)
|
|
{
|
|
if (!isset(self::$session) || !self::checkObject(self::$session))
|
|
{
|
|
self::$session = JFactory::getSession();
|
|
}
|
|
// set to local memory to speed up program
|
|
self::$localSession[$key] = $value;
|
|
// load to session for later use
|
|
return self::$session->set($key, self::$localSession[$key]);
|
|
}
|
|
|
|
/**
|
|
* get info from Session
|
|
**/
|
|
public static function get($key, $default = null)
|
|
{
|
|
if (!isset(self::$session) || !self::checkObject(self::$session))
|
|
{
|
|
self::$session = JFactory::getSession();
|
|
}
|
|
// check if in local memory
|
|
if (!isset(self::$localSession[$key]))
|
|
{
|
|
// set to local memory to speed up program
|
|
self::$localSession[$key] = self::$session->get($key, $default);
|
|
}
|
|
return self::$localSession[$key];
|
|
}
|
|
|
|
|
|
/**
|
|
* get field type properties
|
|
*
|
|
* @return array on success
|
|
*
|
|
*/
|
|
public static function getFieldTypeProperties($value, $type, $settings = array(), $xml = null, $db_defaults = false)
|
|
{
|
|
// Get a db connection.
|
|
$db = JFactory::getDbo();
|
|
|
|
// Create a new query object.
|
|
$query = $db->getQuery(true);
|
|
$query->select($db->quoteName(array('properties', 'short_description', 'description')));
|
|
// load database default values
|
|
if ($db_defaults)
|
|
{
|
|
$query->select($db->quoteName(array('datadefault', 'datadefault_other', 'datalenght', 'datalenght_other', 'datatype', 'has_defaults', 'indexes', 'null_switch', 'store')));
|
|
}
|
|
$query->from($db->quoteName('#__componentbuilder_fieldtype'));
|
|
$query->where($db->quoteName('published') . ' = 1');
|
|
$query->where($db->quoteName($type) . ' = '. $value);
|
|
|
|
// Reset the query using our newly populated query object.
|
|
$db->setQuery($query);
|
|
$db->execute();
|
|
if ($db->getNumRows())
|
|
{
|
|
$result = $db->loadObject();
|
|
$properties = json_decode($result->properties, true);
|
|
$field = array(
|
|
'subform' => array(),
|
|
'nameListOptions' => array(),
|
|
'php' => array(),
|
|
'values' => "<field ",
|
|
'values_description' => '<table class="uk-table uk-table-hover uk-table-striped uk-table-condensed">',
|
|
'short_description' => $result->short_description,
|
|
'description' => $result->description);
|
|
// number pointer
|
|
$nr = 0;
|
|
// php tracker (we must try to load alteast 17 rows
|
|
$phpTracker = array();
|
|
// value to check since there are false and null values even 0 in the values returned
|
|
$confirmation = '8qvZHoyuFYQqpj0YQbc6F3o5DhBlmS-_-a8pmCZfOVSfANjkmV5LG8pCdAY2JNYu6cB';
|
|
// set the headers
|
|
$field['values_description'] .= '<thead><tr><th class="uk-text-right">' . JText::_('COM_COMPONENTBUILDER_PROPERTY') . '</th><th>' . JText::_('COM_COMPONENTBUILDER_EXAMPLE') . '</th><th>' . JText::_('COM_COMPONENTBUILDER_DESCRIPTION') . '</th></thead><tbody>';
|
|
foreach ($properties as $property)
|
|
{
|
|
$example = (isset($property['example']) && self::checkString($property['example'])) ? $property['example'] : '';
|
|
$field['values_description'] .= '<tr><td class="uk-text-right"><code>' . $property['name'] . '</code></td><td>' . $example . '</td><td>' . $property['description'] . '</td></tr>';
|
|
// check if we should load the value
|
|
$value = self::getValueFromXMLstring($xml, $property['name'], $confirmation);
|
|
// check if this is a php field
|
|
$addPHP = false;
|
|
if (strpos($property['name'], 'type_php') !== false)
|
|
{
|
|
$addPHP = true;
|
|
// set the line number
|
|
$phpLine = (int) preg_replace('/[^0-9]/', '', $property['name']);
|
|
// set the key
|
|
$phpKey = trim(preg_replace('/[0-9]+/', '', $property['name']), '_');
|
|
// start array if not already set
|
|
if (!isset($field['php'][$phpKey]))
|
|
{
|
|
$field['php'][$phpKey] = array();
|
|
$field['php'][$phpKey]['value'] = array();
|
|
$field['php'][$phpKey]['desc'] = $property['description'];
|
|
// start tracker
|
|
$phpTracker[$phpKey] = 1;
|
|
}
|
|
}
|
|
// was the settings for the property passed
|
|
if(self::checkArray($settings) && isset($settings[$property['name']]))
|
|
{
|
|
// add the xml values
|
|
$field['values'] .= PHP_EOL . "\t" . $property['name'] . '="'. $settings[$property['name']] . '" ';
|
|
// add the json values
|
|
if ($addPHP)
|
|
{
|
|
$field['php'][$phpKey]['value'][$phpLine] = $settings[$property['name']];
|
|
$phpTracker[$phpKey]++;
|
|
}
|
|
else
|
|
{
|
|
$field['subform']['properties'.$nr] = array('name' => $property['name'], 'value' => $settings[$property['name']], 'desc' => $property['description']);
|
|
}
|
|
}
|
|
elseif (!$xml || $confirmation !== $value)
|
|
{
|
|
// add the xml values
|
|
$field['values'] .= PHP_EOL."\t" . $property['name'] . '="' . ($confirmation !== $value) ? $value : $example .'" ';
|
|
// add the json values
|
|
if ($addPHP)
|
|
{
|
|
$field['php'][$phpKey]['value'][$phpLine] = ($confirmation !== $value) ? $value : $example;
|
|
$phpTracker[$phpKey]++;
|
|
}
|
|
else
|
|
{
|
|
$field['subform']['properties' . $nr] = array('name' => $property['name'], 'value' => ($confirmation !== $value) ? $value : $example, 'desc' => $property['description']);
|
|
}
|
|
}
|
|
// add the name List Options
|
|
if (!$addPHP)
|
|
{
|
|
$field['nameListOptions'][$property['name']] = $property['name'];
|
|
}
|
|
// increment the number
|
|
$nr++;
|
|
}
|
|
// check if all php is loaded using the tracker
|
|
if (self::checkString($xml) && isset($phpTracker) && self::checkArray($phpTracker))
|
|
{
|
|
foreach ($phpTracker as $phpKey => $start)
|
|
{
|
|
if ($start < 30)
|
|
{
|
|
// we must search for more code in the xml just incase
|
|
foreach(range(2, 30) as $t_nr)
|
|
{
|
|
$get_ = $phpKey . '_' . $t_nr;
|
|
if (!isset($field['php'][$phpKey]['value'][$t_nr]) && ($value = self::getValueFromXMLstring($xml, $get_, $confirmation)) !== $confirmation)
|
|
{
|
|
$field['php'][$phpKey]['value'][$t_nr] = $value;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$field['values'] .= PHP_EOL . "/>";
|
|
$field['values_description'] .= '</tbody></table>';
|
|
// load the database defaults if set and wanted
|
|
if ($db_defaults && isset($result->has_defaults) && $result->has_defaults == 1)
|
|
{
|
|
$field['database'] = array(
|
|
'datatype' => $result->datatype,
|
|
'datadefault' => $result->datadefault,
|
|
'datadefault_other' => $result->datadefault_other,
|
|
'datalenght' => $result->datalenght,
|
|
'datalenght_other' => $result->datalenght_other,
|
|
'indexes' => $result->indexes,
|
|
'null_switch' => $result->null_switch,
|
|
'store' => $result->store
|
|
);
|
|
}
|
|
// return found field options
|
|
return $field;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public static function getValueFromXMLstring(&$xml, &$get, $confirmation = '')
|
|
{
|
|
if (self::checkString($xml))
|
|
{
|
|
// if we have a PHP value, we must base64 decode it
|
|
if (strpos($get, 'type_php') !== false)
|
|
{
|
|
return self::openValidBase64(self::getBetween($xml, $get.'="', '"', $confirmation));
|
|
}
|
|
return self::getBetween($xml, $get . '="', '"', $confirmation);
|
|
}
|
|
return $confirmation;
|
|
}
|
|
|
|
|
|
/**
|
|
* get field types properties
|
|
*
|
|
* @return array on success
|
|
*
|
|
*/
|
|
public static function getFieldTypesProperties($targets = array(), $filter = array(), $exclude = array(), $type = 'id', $operator = 'IN')
|
|
{
|
|
// Get a db connection.
|
|
$db = JFactory::getDbo();
|
|
|
|
// Create a new query object.
|
|
$query = $db->getQuery(true);
|
|
$query->select($db->quoteName(array('id','properties')));
|
|
$query->from($db->quoteName('#__componentbuilder_fieldtype'));
|
|
$query->where($db->quoteName('published') . ' = 1');
|
|
// make sure we have ids (or get all)
|
|
if ('IN_STRINGS' === $operator || 'NOT IN_STRINGS' === $operator)
|
|
{
|
|
$query->where($db->quoteName($type) . ' ' . str_replace('_STRINGS', '', $operator) . ' ("' . implode('","',$targets) . '")');
|
|
}
|
|
else
|
|
{
|
|
$query->where($db->quoteName($type) . ' ' . $operator . ' (' . implode(',',$targets) . ')');
|
|
}
|
|
// Reset the query using our newly populated query object.
|
|
$db->setQuery($query);
|
|
$db->execute();
|
|
if ($db->getNumRows())
|
|
{
|
|
$_types = array();
|
|
$_properties = array();
|
|
$types = $db->loadObjectList('id');
|
|
foreach ($types as $id => $type)
|
|
{
|
|
$properties = json_decode($type->properties);
|
|
foreach ($properties as $property)
|
|
{
|
|
if (!isset($_types[$id]))
|
|
{
|
|
$_types[$id] = array();
|
|
}
|
|
// add if no objection is found
|
|
$add = true;
|
|
// check if we have exclude
|
|
if (self::checkArray($exclude) && in_array($property->name, $exclude))
|
|
{
|
|
continue;
|
|
}
|
|
// check if we have filter
|
|
if (self::checkArray($filter))
|
|
{
|
|
foreach($filter as $key => $val)
|
|
{
|
|
if (!isset($property->$key) || $property->$key != $val)
|
|
{
|
|
$add = false;
|
|
}
|
|
}
|
|
}
|
|
// now add the property
|
|
if ($add)
|
|
{
|
|
$_types[$id][$property->name] = array('name' => ucfirst($property->name), 'example' => $property->example, 'description' => $property->description);
|
|
// set mandatory
|
|
if (isset($property->mandatory) && $property->mandatory == 1)
|
|
{
|
|
$_types[$id][$property->name]['mandatory'] = true;
|
|
}
|
|
else
|
|
{
|
|
$_types[$id][$property->name]['mandatory'] = false;
|
|
}
|
|
// set translatable
|
|
if (isset($property->translatable) && $property->translatable == 1)
|
|
{
|
|
$_types[$id][$property->name]['translatable'] = true;
|
|
}
|
|
else
|
|
{
|
|
$_types[$id][$property->name]['translatable'] = false;
|
|
}
|
|
$_properties[$property->name] = $_types[$id][$property->name]['name'];
|
|
}
|
|
}
|
|
}
|
|
|
|
// return found types & properties
|
|
return array('types' => $_types, 'properties' => $_properties);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
|
|
/**
|
|
* The zipper method
|
|
*
|
|
* @param string $workingDIR The directory where the items must be zipped
|
|
* @param string $filepath The path to where the zip file must be placed
|
|
*
|
|
* @return bool true On success
|
|
*
|
|
*/
|
|
public static function zip($workingDIR, &$filepath)
|
|
{
|
|
// store the current joomla working directory
|
|
$joomla = getcwd();
|
|
|
|
// we are changing the working directory to the component temp folder
|
|
chdir($workingDIR);
|
|
|
|
// the full file path of the zip file
|
|
$filepath = JPath::clean($filepath);
|
|
|
|
// delete an existing zip file (or use an exclusion parameter in JFolder::files()
|
|
JFile::delete($filepath);
|
|
|
|
// get a list of files in the current directory tree
|
|
$files = JFolder::files('.', '', true, true);
|
|
$zipArray = array();
|
|
// setup the zip array
|
|
foreach ($files as $file)
|
|
{
|
|
$tmp = array();
|
|
$tmp['name'] = str_replace('./', '', $file);
|
|
$tmp['data'] = JFile::read($file);
|
|
$tmp['time'] = filemtime($file);
|
|
$zipArray[] = $tmp;
|
|
}
|
|
|
|
// change back to joomla working directory
|
|
chdir($joomla);
|
|
|
|
// get the zip adapter
|
|
$zip = JArchive::getAdapter('zip');
|
|
|
|
//create the zip file
|
|
if ($zip->create($filepath, $zipArray))
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
|
|
/**
|
|
* Write a file to the server
|
|
*
|
|
* @param string $path The path and file name where to safe the data
|
|
* @param string $data The data to safe
|
|
*
|
|
* @return bool true On success
|
|
*
|
|
*/
|
|
public static function writeFile($path, $data)
|
|
{
|
|
$klaar = false;
|
|
if (self::checkString($data))
|
|
{
|
|
// open the file
|
|
$fh = fopen($path, "w");
|
|
if (!is_resource($fh))
|
|
{
|
|
return $klaar;
|
|
}
|
|
// write to the file
|
|
if (fwrite($fh, $data))
|
|
{
|
|
// has been done
|
|
$klaar = true;
|
|
}
|
|
// close file.
|
|
fclose($fh);
|
|
}
|
|
return $klaar;
|
|
}
|
|
|
|
|
|
/**
|
|
* Remove folders with files
|
|
*
|
|
* @param string $dir The path to folder to remove
|
|
* @param boolean $ignore The folders and files to ignore and not remove
|
|
*
|
|
* @return boolean True in all is removed
|
|
*
|
|
*/
|
|
public static function removeFolder($dir, $ignore = false)
|
|
{
|
|
if (JFolder::exists($dir))
|
|
{
|
|
$it = new RecursiveDirectoryIterator($dir);
|
|
$it = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST);
|
|
// remove ending /
|
|
$dir = rtrim($dir, '/');
|
|
// now loop the files & folders
|
|
foreach ($it as $file)
|
|
{
|
|
if ('.' === $file->getBasename() || '..' === $file->getBasename()) continue;
|
|
// set file dir
|
|
$file_dir = $file->getPathname();
|
|
// check if this is a dir or a file
|
|
if ($file->isDir())
|
|
{
|
|
$keeper = false;
|
|
if (self::checkArray($ignore))
|
|
{
|
|
foreach ($ignore as $keep)
|
|
{
|
|
if (strpos($file_dir, $dir.'/'.$keep) !== false)
|
|
{
|
|
$keeper = true;
|
|
}
|
|
}
|
|
}
|
|
if ($keeper)
|
|
{
|
|
continue;
|
|
}
|
|
JFolder::delete($file_dir);
|
|
}
|
|
else
|
|
{
|
|
$keeper = false;
|
|
if (self::checkArray($ignore))
|
|
{
|
|
foreach ($ignore as $keep)
|
|
{
|
|
if (strpos($file_dir, $dir.'/'.$keep) !== false)
|
|
{
|
|
$keeper = true;
|
|
}
|
|
}
|
|
}
|
|
if ($keeper)
|
|
{
|
|
continue;
|
|
}
|
|
JFile::delete($file_dir);
|
|
}
|
|
}
|
|
// delete the root folder if not ignore found
|
|
if (!self::checkArray($ignore))
|
|
{
|
|
return JFolder::delete($dir);
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
|
|
/**
|
|
* The github access token
|
|
**/
|
|
protected static $gitHubAccessToken = "";
|
|
|
|
/**
|
|
* The github repo get data errors
|
|
**/
|
|
public static $githubRepoDataErrors = array();
|
|
|
|
/**
|
|
* get the github repo file list
|
|
*
|
|
* @return array on success
|
|
*
|
|
*/
|
|
public static function getGithubRepoFileList($type, $target)
|
|
{
|
|
// get the repo data
|
|
if (($repoData = self::getGithubRepoData($type, $target, 'tree')) !== false)
|
|
{
|
|
return $repoData->tree;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* get the github repo file list
|
|
*
|
|
* @return array on success
|
|
*
|
|
*/
|
|
public static function getGithubRepoData($type, $url, $target = null, $return_type = 'object')
|
|
{
|
|
// always reset errors per/request
|
|
self::$githubRepoDataErrors = array();
|
|
// get the current Packages (public)
|
|
if ('nomemory' === $type || !$repoData = self::get($type))
|
|
{
|
|
// add the token if not already added
|
|
$_url = self::setGithubToken($url);
|
|
// check if the url exist
|
|
if (self::urlExists($_url))
|
|
{
|
|
// get the data from github
|
|
if (($repoData = self::getFileContents($_url)) !== false && self::checkJson($repoData))
|
|
{
|
|
$github_returned = json_decode($repoData);
|
|
if (self::checkString($target) &&
|
|
( (self::checkObject($github_returned) && isset($github_returned->{$target}) && self::checkArray($github_returned->{$target})) ||
|
|
(self::checkArray($github_returned) && isset($github_returned[$target]) && self::checkArray($github_returned[$target])) ))
|
|
{
|
|
if ('nomemory' !== $type)
|
|
{
|
|
// remember to set it
|
|
self::set($type, $repoData);
|
|
}
|
|
}
|
|
elseif (!self::checkString($target) && (self::checkArray($github_returned) || (self::checkObject($github_returned) && !isset($github_returned->message))))
|
|
{
|
|
if ('nomemory' !== $type)
|
|
{
|
|
// remember to set it
|
|
self::set($type, $repoData);
|
|
}
|
|
}
|
|
// check if we have error message from github
|
|
elseif (($errorMessage = self::githubErrorHandeler(array('error' => null), $github_returned, $type)) !== false)
|
|
{
|
|
if (isset($errorMessage['error']) && self::checkString($errorMessage['error']))
|
|
{
|
|
// set the error in the application
|
|
JFactory::getApplication()->enqueueMessage($errorMessage['error'], 'Error');
|
|
// set the error also in the class encase it is and Ajax call
|
|
self::$githubRepoDataErrors[] = $errorMessage['error'];
|
|
}
|
|
return false;
|
|
}
|
|
elseif (self::checkString($target))
|
|
{
|
|
// setup error string
|
|
$error = JText::sprintf('COM_COMPONENTBUILDER_THE_URL_S_SET_TO_RETRIEVE_THE_PACKAGES_DID_NOT_RETURN_S_DATA', $url, $target);
|
|
// set the error in the application
|
|
JFactory::getApplication()->enqueueMessage($error, 'Error');
|
|
// set the error also in the class encase it is and Ajax call
|
|
self::$githubRepoDataErrors[] = $error;
|
|
// we are done here
|
|
return false;
|
|
}
|
|
elseif ('nomemory' !== $type)
|
|
{
|
|
// setup error string
|
|
$error = JText::sprintf('COM_COMPONENTBUILDER_THE_URL_S_SET_TO_RETRIEVE_THE_PACKAGES_DID_NOT_RETURN_S_DATA', $url, $type);
|
|
// set the error in the application
|
|
JFactory::getApplication()->enqueueMessage($error, 'Error');
|
|
// set the error also in the class encase it is and Ajax call
|
|
self::$githubRepoDataErrors[] = $error;
|
|
// we are done here
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
// setup error string
|
|
$error = JText::sprintf('COM_COMPONENTBUILDER_THE_URL_S_SET_TO_RETRIEVE_THE_PACKAGES_DID_NOT_RETURN_VALID_DATA', $url, $type);
|
|
// set the error in the application
|
|
JFactory::getApplication()->enqueueMessage($error, 'Error');
|
|
// set the error also in the class encase it is and Ajax call
|
|
self::$githubRepoDataErrors[] = $error;
|
|
// we are done here
|
|
return false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// setup error string
|
|
$error = JText::sprintf('COM_COMPONENTBUILDER_THE_URL_S_SET_TO_RETRIEVE_THE_PACKAGES_DOES_NOT_RETURN_ANY_DATA', $url);
|
|
// set the error in the application
|
|
JFactory::getApplication()->enqueueMessage($error, 'Error');
|
|
// set the error also in the class encase it is and Ajax call
|
|
self::$githubRepoDataErrors[] = $error;
|
|
// we are done here
|
|
return false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// setup error string
|
|
$error = JText::sprintf('COM_COMPONENTBUILDER_THE_URL_S_SET_TO_RETRIEVE_THE_PACKAGES_DOES_NOT_EXIST', $url);
|
|
// set the error in the application
|
|
JFactory::getApplication()->enqueueMessage($error, 'Error');
|
|
// set the error also in the class encase it is and Ajax call
|
|
self::$githubRepoDataErrors[] = $error;
|
|
// we are done here
|
|
return false;
|
|
}
|
|
}
|
|
// check if we could find packages
|
|
if (isset($repoData) && self::checkJson($repoData))
|
|
{
|
|
if ('object' === $return_type)
|
|
{
|
|
return json_decode($repoData);
|
|
}
|
|
elseif ('array' === $return_type)
|
|
{
|
|
return json_decode($repoData, true);
|
|
}
|
|
return $repoData;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* get the github error messages
|
|
*
|
|
* @return array of errors on success
|
|
*
|
|
*/
|
|
protected static function githubErrorHandeler($message, &$github, $type)
|
|
{
|
|
if (self::checkObject($github) && isset($github->message) && self::checkString($github->message))
|
|
{
|
|
// set the message
|
|
$errorMessage = $github->message;
|
|
// add the documentation URL
|
|
if (isset($github->documentation_url) && self::checkString($github->documentation_url))
|
|
{
|
|
$errorMessage = $errorMessage . '<br />' . $github->documentation_url;
|
|
}
|
|
// check the message
|
|
if (strpos($errorMessage, 'Authenticated') !== false)
|
|
{
|
|
if ('nomemory' === $type)
|
|
{
|
|
$type = 'data';
|
|
}
|
|
// add little more help if it is an access token issue
|
|
$errorMessage = JText::sprintf('COM_COMPONENTBUILDER_SBR_YOU_CAN_ADD_A_BGITHUB_ACCESS_TOKENB_TO_COMPONENTBUILDER_GLOBAL_OPTIONS_TO_MAKE_AUTHENTICATED_REQUESTS_TO_GITHUB_AN_ACCESS_TOKEN_WITH_ONLY_PUBLIC_ACCESS_WILL_DO_TO_RETRIEVE_S', $errorMessage, $type);
|
|
}
|
|
// set error notice
|
|
$message['error'] = $errorMessage;
|
|
// we have error message
|
|
return $message;
|
|
}
|
|
return |