Added Captcha field type. Started adding the crowdin integration.

This commit is contained in:
2019-05-15 19:39:27 +02:00
parent a23f1fe79a
commit 80c588a33a
60 changed files with 4849 additions and 3870 deletions

View File

@@ -32,6 +32,225 @@ class ComponentbuilderControllerApi extends JControllerForm
parent::__construct($config);
}
/**
* The methods that are allowed to be called
*
* @var array
*/
protected $allowedMethods = array('compileInstall', 'translate');
/**
* The local methods that should be triggered
*
* @var array
*/
protected $localMethodTrigger = array('compileInstall' => '_autoloader');
/**
* Run the Translator
*
* @return mix
*/
public function translator()
{
// get params first
if (!isset($this->params) || !ComponentbuilderHelper::checkObject($this->params))
{
$this->params = JComponentHelper::getParams('com_componentbuilder');
}
// get model
$model = $this->getModel('api');
// check if user has the right
$user = $this->getApiUser();
// get components that have translation tools
if ($user->authorise('core.admin', 'com_componentbuilder') && ($components = $model->getTranslationLinkedComponents()) !== false)
{
// the message package
$message = array();
// make sure to not unlock
$unlock = false;
// get messages
$callback = function($messages) use (&$message, &$unlock) {
// unlock messages if needed
if ($unlock) {
$messages = ComponentbuilderHelper::unlock($messages);
}
// check if we have any messages
if (ComponentbuilderHelper::checkArray($messages)) {
$message[] = implode("<br />\n", $messages);
} else {
// var_dump($messages); // error debug message
}
};
// we have two options, doing them one at a time, or using curl to do them somewhat asynchronously
if (count ( (array) $components) > 1 && function_exists('curl_version'))
{
// line up the translations
foreach ($components as $component)
{
ComponentbuilderHelper::setWorker($component, 'translate');
}
// make sure to unlock
$unlock = true;
// run workers
ComponentbuilderHelper::runWorker('translate', 1, $callback);
}
else
{
foreach ($components as $component)
{
$model->translate($component);
}
// check if we have any messages
$callback($model->messages);
}
// return messages if found
if (ComponentbuilderHelper::checkArray($message))
{
echo implode("<br />\n", $message);
}
else
{
echo 1;
}
// clear session
JFactory::getApplication()->getSession()->destroy();
jexit();
}
// clear session
JFactory::getApplication()->getSession()->destroy();
// return bool
echo 0;
jexit();
}
/**
* Run the Expansion
*
* @return mix
*/
public function expand()
{
// get params first
if (!isset($this->params) || !ComponentbuilderHelper::checkObject($this->params))
{
$this->params = JComponentHelper::getParams('com_componentbuilder');
}
// check if expansion is enabled
$method = $this->params->get('development_method', 1);
// check what kind of return values show we give
$returnOptionsBuild = $this->params->get('return_options_build', 2);
if (2 == $method)
{
// get expansion components
$expansion = $this->params->get('expansion', null);
// check if they are set
if (ComponentbuilderHelper::checkObject($expansion))
{
// check if user has the right
$user = $this->getApiUser();
// the message package
$message = array();
if ($user->authorise('core.admin', 'com_componentbuilder'))
{
// make sure to not unlock
$unlock = false;
// get messages
$callback = function($messages) use (&$message, &$unlock) {
// unlock messages if needed
if ($unlock) {
$messages = ComponentbuilderHelper::unlock($messages);
}
// check if we have any messages
if (ComponentbuilderHelper::checkArray($messages)) {
$message[] = implode("<br />\n", $messages);
} else {
// var_dump($messages); // error debug message
}
};
// we have two options, doing them one at a time, or using curl to do them somewhat asynchronously
if (count ( (array) $expansion) > 1 && function_exists('curl_version'))
{
// set workers
foreach ($expansion as $component)
{
ComponentbuilderHelper::setWorker($component, 'compileInstall');
}
// make sure to unlock
$unlock = true;
// run workers
ComponentbuilderHelper::runWorker('compileInstall', 1, $callback);
}
else
{
// get model
$model = $this->getModel('api');
// load the compiler
$this->_autoloader();
// set workers
foreach ($expansion as $component)
{
// compile and install
$model->compileInstall($component);
}
// check if we have any messages
$callback($model->messages);
}
// return messages if found
if (1== $returnOptionsBuild && ComponentbuilderHelper::checkArray($message))
{
echo implode("<br />\n", $message);
}
else
{
echo 1;
}
// clear session
JFactory::getApplication()->getSession()->destroy();
jexit();
}
// check if message is to be returned
if (1== $returnOptionsBuild)
{
// clear session
JFactory::getApplication()->getSession()->destroy();
jexit('Access Denied!');
}
}
}
// clear session
JFactory::getApplication()->getSession()->destroy();
// check if message is to be returned
if (1== $returnOptionsBuild)
{
jexit('Expansion Disabled! Expansion can be enabled by your system administrator in the global Options of JCB under the Development Method tab.');
}
// return bool
echo 0;
jexit();
}
/**
* Get API User
*
* @return object
*/
protected function getApiUser()
{
// return user object
return JFactory::getUser($this->params->get('api', 0, 'INT'));
}
/**
* Load the needed script
*
* @return void
*/
protected function _autoloader()
{
// include component compiler
require_once JPATH_ADMINISTRATOR.'/components/com_componentbuilder/helpers/compiler.php';
}
public function backup()
{
@@ -193,123 +412,7 @@ class ComponentbuilderControllerApi extends JControllerForm
return;
}
/**
* Run the Expansion
*
* @return mix
*/
public function expand()
{
// get params first
if (!isset($this->params) || !ComponentbuilderHelper::checkObject($this->params))
{
$this->params = JComponentHelper::getParams('com_componentbuilder');
}
// check if expansion is enabled
$method = $this->params->get('development_method', 1);
// check what kind of return values show we give
$returnOptionsBuild = $this->params->get('return_options_build', 2);
if (2 == $method)
{
// get expansion components
$expansion = $this->params->get('expansion', null);
// check if they are set
if (ComponentbuilderHelper::checkObject($expansion))
{
// check if user has the right
$user = $this->getApiUser();
// the message package
$message = array();
if ($user->authorise('core.admin', 'com_componentbuilder'))
{
// make sure to not unlock
$unlock = false;
// get messages
$callback = function($messages) use (&$message, &$unlock) {
// unlock messages if needed
if ($unlock) {
$messages = ComponentbuilderHelper::unlock($messages);
}
// check if we have any messages
if (ComponentbuilderHelper::checkArray($messages)) {
$message[] = implode("<br />\n", $messages);
} else {
// var_dump($messages); // error debug message
}
};
// we have two options, doing them one at a time, use using curl to do tome somewhat asynchronously
if (count ( (array) $expansion) > 1 && function_exists('curl_version'))
{
// set workers
foreach ($expansion as $component)
{
ComponentbuilderHelper::setWorker($component, 'compileInstall');
}
// make sure to unlock
$unlock = true;
// run workers
ComponentbuilderHelper::runWorker('compileInstall', 1, $callback);
}
else
{
// get model
$model = $this->getModel('api');
// load the compiler
$this->_autoloader();
// set workers
foreach ($expansion as $component)
{
// compile and install
$model->compileInstall($component);
}
// check if we have any messages
$callback($model->messages);
}
// return messages if found
if (1== $returnOptionsBuild && ComponentbuilderHelper::checkArray($message))
{
echo implode("<br />\n", $message);
}
else
{
echo 1;
}
// clear session
JFactory::getApplication()->getSession()->destroy();
jexit();
}
// check if message is to be returned
if (1== $returnOptionsBuild)
{
// clear session
JFactory::getApplication()->getSession()->destroy();
jexit('Access Denied!');
}
}
}
// clear session
JFactory::getApplication()->getSession()->destroy();
// check if message is to be returned
if (1== $returnOptionsBuild)
{
jexit('Expansion Disabled! Expansion can be enabled by your system administrator in the global Options of JCB under the Development Method tab.');
}
// return bool
echo 0;
jexit();
}
/**
* Get API User
*
* @return object
*/
protected function getApiUser()
{
// return user object
return JFactory::getUser($this->params->get('api', 0, 'INT'));
}
/**
* Run worker request
*
@@ -337,25 +440,35 @@ class ComponentbuilderControllerApi extends JControllerForm
// check the for a string
if (1 == $type && ComponentbuilderHelper::checkObject($dataValues) && ComponentbuilderHelper::checkString($task))
{
// get params first
if (!isset($this->params) || !ComponentbuilderHelper::checkObject($this->params))
{
$this->params = JComponentHelper::getParams('com_componentbuilder');
}
// get model
$model = $this->getModel('api');
// open the compile Install function
if ('compileInstall' === $task)
// check if allowed and method exist and is callable
if (in_array($task, $this->allowedMethods) && method_exists($model, $task) && is_callable(array($model, $task)))
{
// load the compiler
$this->_autoloader();
// compile and install
$model->compileInstall($dataValues);
// return locked values
echo ComponentbuilderHelper::lock($model->messages);
// clear session
JFactory::getApplication()->getSession()->destroy();
jexit();
// trigger local method
if (isset($this->localMethodTrigger[$task]))
{
// run the local method
$this->{$this->localMethodTrigger[$task]}();
}
// run the model method
$result = $model->{$task}($dataValues);
// check if we have messages
if (ComponentbuilderHelper::checkArray($model->messages))
{
// return locked values
echo ComponentbuilderHelper::lock($model->messages);
// clear session
JFactory::getApplication()->getSession()->destroy();
jexit();
}
elseif ($result)
{
echo 1;
// clear session
JFactory::getApplication()->getSession()->destroy();
jexit();
}
}
}
}
@@ -366,16 +479,6 @@ class ComponentbuilderControllerApi extends JControllerForm
jexit();
}
/**
* Load the needed script
*
* @return void
*/
protected function _autoloader()
{
// include component compiler
require_once JPATH_ADMINISTRATOR.'/components/com_componentbuilder/helpers/compiler.php';
}
/**
* Method to check if you can edit an existing record.

View File

@@ -2612,7 +2612,7 @@ abstract class ComponentbuilderHelper
'sessionhandler', 'spacer', 'sql', 'subform', 'tag', 'tel', 'templatestyle', 'text', 'textarea', 'timezone', 'url', 'user', 'usergroup'
),
'plain' => array(
'cachehandler', 'calendar', 'checkbox', 'chromestyle', 'color', 'componentlayout', 'contenttype', 'editor', 'editors',
'cachehandler', 'calendar', 'checkbox', 'chromestyle', 'color', 'componentlayout', 'contenttype', 'editor', 'editors', 'captcha',
'email', 'file', 'headertag', 'helpsite', 'hidden', 'integer', 'language', 'media', 'menu', 'menuitem', 'meter', 'modulelayout',
'moduleorder', 'moduletag', 'number', 'password', 'range', 'rules', 'tag', 'tel', 'text', 'textarea', 'timezone', 'url', 'user', 'usergroup'
),
@@ -4459,6 +4459,115 @@ abstract class ComponentbuilderHelper
return implode("\n", $table);
}
/**
* Change to nice fancy date
*/
public static function fancyDate($date)
{
if (!self::isValidTimeStamp($date))
{
$date = strtotime($date);
}
return date('jS \o\f F Y',$date);
}
/**
* get date based in period past
*/
public static function fancyDynamicDate($date)
{
if (!self::isValidTimeStamp($date))
{
$date = strtotime($date);
}
// older then year
$lastyear = date("Y", strtotime("-1 year"));
$tragetyear = date("Y", $date);
if ($tragetyear <= $lastyear)
{
return date('m/d/y', $date);
}
// same day
$yesterday = strtotime("-1 day");
if ($date > $yesterday)
{
return date('g:i A', $date);
}
// just month day
return date('M j', $date);
}
/**
* Change to nice fancy day time and date
*/
public static function fancyDayTimeDate($time)
{
if (!self::isValidTimeStamp($time))
{
$time = strtotime($time);
}
return date('D ga jS \o\f F Y',$time);
}
/**
* Change to nice fancy time and date
*/
public static function fancyDateTime($time)
{
if (!self::isValidTimeStamp($time))
{
$time = strtotime($time);
}
return date('(G:i) jS \o\f F Y',$time);
}
/**
* Change to nice hour:minutes time
*/
public static function fancyTime($time)
{
if (!self::isValidTimeStamp($time))
{
$time = strtotime($time);
}
return date('G:i',$time);
}
/**
* set the date as 2004/05 (for charts)
*/
public static function setYearMonth($date)
{
if (!self::isValidTimeStamp($date))
{
$date = strtotime($date);
}
return date('Y/m', $date);
}
/**
* set the date as 2004/05/03 (for charts)
*/
public static function setYearMonthDay($date)
{
if (!self::isValidTimeStamp($date))
{
$date = strtotime($date);
}
return date('Y/m/d', $date);
}
/**
* Check if string is a valid time stamp
*/
public static function isValidTimeStamp($timestamp)
{
return ((int) $timestamp === $timestamp)
&& ($timestamp <= PHP_INT_MAX)
&& ($timestamp >= ~PHP_INT_MAX);
}
public static function jsonToString($value, $sperator = ", ", $table = null, $id = 'id', $name = 'name')
{

View File

@@ -88,6 +88,7 @@ COM_COMPONENTBUILDER_THE_URL_S_SET_TO_RETRIEVE_THE_PACKAGES_DOES_NOT_EXIST="The
COM_COMPONENTBUILDER_THIS_PACKAGE_HAS_NO_KEY="This package has no key."
COM_COMPONENTBUILDER_TO_CHANGE_THE_PACKAGE_OWNER_DEFAULTS_OPEN_THE_BJCB_GLOBAL_OPTIONSB_GO_TO_THE_BCOMPANYB_TAB_AND_ADD_THE_CORRECT_COMPANY_DETAILS_THERE="To change the package owner defaults. Open the <b>JCB Global Options</b>, go to the <b>Company</b> tab and add the correct company details there."
COM_COMPONENTBUILDER_TO_CHANGE_THE_PACKAGE_OWNER_DEFAULTS_OPEN_THE_JCB_GLOBAL_OPTIONS_GO_TO_THE_COMPANY_TAB_AND_ADD_THE_CORRECT_COMPANY_DETAILS_THERE="To change the package owner defaults. Open the JCB Global Options, go to the Company tab and add the correct company details there."
COM_COMPONENTBUILDER_TRANSLATOR_MODULE_NOT_READYBR_THIS_AREA_IS_STILL_UNDER_PRODUCTION_HOPEFULLY_WITH_NEXT_UPDATE="Translator Module not ready!<br />This area is still under production, hopefully with next update."
COM_COMPONENTBUILDER_WEBSITE_S="Website: %s"
COM_COMPONENTBUILDER_YOUR_DATA_IS_ENCRYPTED_WITH_A_AES_ONE_HUNDRED_AND_TWENTY_EIGHT_BIT_ENCRYPTION_USING_THE_ABOVE_THIRTY_TWO_CHARACTER_KEY_WITHOUT_THIS_KEY_IT_WILL_TAKE_THE_CURRENT_TECHNOLOGY_WITH_A_BRUTE_FORCE_ATTACK_METHOD_MORE_THEN_A_HREFHTTPRANDOMIZECOMHOWLONGTOHACKPASS_TARGET_BLANK_TITLEHOW_LONG_TO_HACK_PASSSEVEN_HUNDRED_ZERO_ZERO_ZERO_ZERO_ZERO_ZERO_ZERO_ZERO_ZERO_ZEROA_YEARS_TO_CRACK_THEORETICALLY_UNLESS_THEY_HAVE_THIS_KEY_ABOVE_SO_DO_KEEP_IT_SAFE="Your data is encrypted with a AES 128 bit encryption using the above 32 character key. Without this key it will take the current technology with a brute force attack method more then <a href="http://random-ize.com/how-long-to-hack-pass/" target="_blank" title="How long to hack pass">700 000 000 000 000 000 000 000 000 000 000</a> years to crack theoretically. Unless they have this key above, so do keep it safe."
COM_COMPONENTBUILDER_YOU_DO_NOT_HAVE_PERMISSION_TO_ACCESS_THE_SERVER_DETAILS_BS_DENIEDB_PLEASE_CONTACT_YOUR_SYSTEM_ADMINISTRATOR_FOR_MORE_INFO="You do not have permission to access the server details (<b>%s - denied</b>), please contact your system administrator for more info."

View File

@@ -161,6 +161,32 @@ class ComponentbuilderModelApi extends JModelItem
protected $compiler;
public function getTranslationLinkedComponents()
{
// Get a db connection.
$db = JFactory::getDbo();
// Create a new query object.
$query = $db->getQuery(true);
// for now we only have crowdin
$query->select($db->quoteName(array('id', 'translation_tool', 'crowdin_account_api_key', 'crowdin_project_api_key' ,'crowdin_project_identifier', 'crowdin_username')));
$query->from($db->quoteName('#__componentbuilder_joomla_component'));
$query->where($db->quoteName('translation_tool') . ' > 0');
$query->where($db->quoteName('published') . ' >= 1');
$db->setQuery($query);
$db->execute();
if ($db->getNumRows())
{
return $db->loadObjectList();
}
return false;
}
public function translate($component)
{
$this->messages[] = JText::_('COM_COMPONENTBUILDER_TRANSLATOR_MODULE_NOT_READYBR_THIS_AREA_IS_STILL_UNDER_PRODUCTION_HOPEFULLY_WITH_NEXT_UPDATE');
return false;
}
public function compileInstall($component)
{
$values = array(
@@ -190,7 +216,7 @@ class ComponentbuilderModelApi extends JModelItem
if (1 == $published && $checked_out == 0)
{
// start up Compiler
$this->compiler = new Compiler($values);
$this->compiler = new Compiler($values);
if($this->compiler)
{
// component was compiled