Added option to include or exclude Joomla Plugins from being compiled or exported. Added the Joomla\Utilities\ArrayHelper to helper class header. Added option to only export words if required global option fields are set. Added option to use strict field access on all exports if required global option fields are set. Fixed gh-475 by adding the option to add a github token if needed under the global options global tab, also updated the error message.

This commit is contained in:
2019-09-10 18:47:39 +02:00
parent e3f22d631c
commit 2b1e0a65fa
61 changed files with 726 additions and 330 deletions

View File

@@ -60,6 +60,20 @@ class Get
*/
public $params;
/**
* Add strict field export permissions
*
* @var boolean
*/
public $strictFieldExportPermissions = false;
/**
* Add text only export options
*
* @var boolean
*/
public $exportTextOnly = false;
/**
* The global placeholders
*
@@ -1665,7 +1679,12 @@ class Get
if (ComponentbuilderHelper::checkArray($component->addjoomla_plugins))
{
$joomla_plugins = array_map(function($array) use(&$component) {
return $this->setJoomlaPlugin($array['plugin'], $component);
// only load the plugins whose target association calles for it
if (!isset($array['target']) || $array['target'] != 2)
{
return $this->setJoomlaPlugin($array['plugin'], $component);
}
return null;
}, array_values($component->addjoomla_plugins));
}
unset($component->addjoomla_plugins);

View File

@@ -9135,11 +9135,13 @@ class Interpretation extends Fields
*/
public function setGetItemsModelMethod($viewName_single, $viewName_list, $config = array('functionName' => 'getExportData', 'docDesc' => 'Method to get list export data.', 'type' => 'export'))
{
// start the query string
$query = '';
if ($this->eximportView[$viewName_list] || 'export' !== $config['type'])
// check if this is the export method
$isExport = ('export' === $config['type']);
// check if this view has export feature, and or if this is not an export method
if ((isset($this->eximportView[$viewName_list]) && $this->eximportView[$viewName_list]) || !$isExport)
{
$isExport = ('export' === $config['type']);
$query = PHP_EOL . PHP_EOL . $this->_t(1) . "/**";
$query .= PHP_EOL . $this->_t(1) . " * " . $config['docDesc'];
$query .= PHP_EOL . $this->_t(1) . " *";
@@ -9170,6 +9172,25 @@ class Interpretation extends Fields
$query .= PHP_EOL . $this->_t(3) . "\$query->where('a.id IN (' . implode(',',\$pks) . ')');";
// add custom filtering php
$query .= $this->getCustomScriptBuilder('php_getlistquery', $viewName_single, PHP_EOL . PHP_EOL . $this->_t(1));
// first check if we export of text only is avalable
if ($this->exportTextOnly)
{
// add switch
$query .= PHP_EOL . $this->_t(3) . "//" . $this->setLine(__LINE__) . " Get global switch to activate text only export";
$query .= PHP_EOL . $this->_t(3) . "\$export_text_only = JComponentHelper::getParams('com_" . $this->componentCodeName . "')->get('export_text_only', 0);";
// first check if we have custom queries
$custom_query = $this->setCustomQuery($viewName_list, $viewName_single, $this->_t(2), true);
}
// if values were returned add the area
if (isset($custom_query) && ComponentbuilderHelper::checkString($custom_query))
{
$query .= PHP_EOL . $this->_t(3) . "//" . $this->setLine(__LINE__) . " Add these queries only if text only is required";
$query .= PHP_EOL . $this->_t(3) . "if (\$export_text_only)";
$query .= PHP_EOL . $this->_t(3) . "{";
// add the custom fields query
$query .= $custom_query;
$query .= PHP_EOL . $this->_t(3) . "}";
}
// add access levels if the view has access set
if (isset($this->accessBuilder[$viewName_single]) && ComponentbuilderHelper::checkString($this->accessBuilder[$viewName_single]))
{
@@ -9188,15 +9209,33 @@ class Interpretation extends Fields
$query .= PHP_EOL . $this->_t(3) . "if (\$db->getNumRows())";
$query .= PHP_EOL . $this->_t(3) . "{";
$query .= PHP_EOL . $this->_t(4) . "\$items = \$db->loadObjectList();";
$query .= $this->setGetItemsMethodStringFix($viewName_single, $viewName_list, $this->fileContentStatic[$this->hhh . 'Component' . $this->hhh], $this->_t(2), $isExport);
// add translations
if (!$isExport)
// set the string fixing code
$query .= $this->setGetItemsMethodStringFix($viewName_single, $viewName_list, $this->fileContentStatic[$this->hhh . 'Component' . $this->hhh], $this->_t(2), $isExport, true);
// first check if we export of text only is avalable
if ($this->exportTextOnly)
{
$query .= $this->setSelectionTranslationFix($viewName_list, $this->fileContentStatic[$this->hhh . 'Component' . $this->hhh], $this->_t(2));
$query_translations = $this->setSelectionTranslationFix($viewName_list, $this->fileContentStatic[$this->hhh . 'Component' . $this->hhh], $this->_t(3));
}
// add translations
if (isset($query_translations) && ComponentbuilderHelper::checkString($query_translations))
{
$query .= PHP_EOL . $this->_t(3) . "//" . $this->setLine(__LINE__) . " Add these translation only if text only is required";
$query .= PHP_EOL . $this->_t(3) . "if (\$export_text_only)";
$query .= PHP_EOL . $this->_t(3) . "{";
$query .= $query_translations;
$query .= PHP_EOL . $this->_t(3) . "}";
}
// add custom php to getItems method after all
$query .= $this->getCustomScriptBuilder('php_getitems_after_all', $viewName_single, PHP_EOL . PHP_EOL . $this->_t(2));
$query .= PHP_EOL . $this->_t(4) . "return \$items;";
// in privacy export we must return array of arrays
if ('privacy' === $config['type'])
{
$query .= PHP_EOL . $this->_t(4) . "return json_decode(json_encode(\$items), true);";
}
else
{
$query .= PHP_EOL . $this->_t(4) . "return \$items;";
}
$query .= PHP_EOL . $this->_t(3) . "}";
$query .= PHP_EOL . $this->_t(2) . "}";
$query .= PHP_EOL . $this->_t(2) . "return false;";
@@ -9521,7 +9560,7 @@ class Interpretation extends Fields
return '';
}
public function setCustomQuery($viewName_list, $viewName_single)
public function setCustomQuery($viewName_list, $viewName_single, $tab = '', $just_text = false)
{
if (isset($this->customBuilder[$viewName_list]) && ComponentbuilderHelper::checkArray($this->customBuilder[$viewName_list]))
{
@@ -9529,11 +9568,20 @@ class Interpretation extends Fields
foreach ($this->customBuilder[$viewName_list] as $filter)
{
// only load this if table is set
if (isset($this->customBuilderList[$viewName_list]) && ComponentbuilderHelper::checkArray($this->customBuilderList[$viewName_list]) && in_array($filter['code'], $this->customBuilderList[$viewName_list]) && isset($filter['custom']['table']) && ComponentbuilderHelper::checkString($filter['custom']['table']) && $filter['method'] == 0)
if ((isset($this->customBuilderList[$viewName_list]) && ComponentbuilderHelper::checkArray($this->customBuilderList[$viewName_list]) && in_array($filter['code'], $this->customBuilderList[$viewName_list]) && isset($filter['custom']['table']) && ComponentbuilderHelper::checkString($filter['custom']['table']) && $filter['method'] == 0)
|| ($just_text && isset($filter['custom']['table']) && ComponentbuilderHelper::checkString($filter['custom']['table']) && $filter['method'] == 0))
{
$query .= PHP_EOL . PHP_EOL . $this->_t(2) . "//" . $this->setLine(__LINE__) . " From the " . ComponentbuilderHelper::safeString(ComponentbuilderHelper::safeString($filter['custom']['table'], 'w')) . " table.";
$query .= PHP_EOL . $this->_t(2) . "\$query->select(\$db->quoteName('" . $filter['custom']['db'] . "." . $filter['custom']['text'] . "','" . $filter['code'] . "_" . $filter['custom']['text'] . "'));";
$query .= PHP_EOL . $this->_t(2) . "\$query->join('LEFT', \$db->quoteName('" . $filter['custom']['table'] . "', '" . $filter['custom']['db'] . "') . ' ON (' . \$db->quoteName('a." . $filter['code'] . "') . ' = ' . \$db->quoteName('" . $filter['custom']['db'] . "." . $filter['custom']['id'] . "') . ')');";
$query .= PHP_EOL . PHP_EOL . $this->_t(2) . $tab . "//" . $this->setLine(__LINE__) . " From the " . ComponentbuilderHelper::safeString(ComponentbuilderHelper::safeString($filter['custom']['table'], 'w')) . " table.";
// we want to at times just have the words and not the ids as well
if ($just_text)
{
$query .= PHP_EOL . $this->_t(2) . $tab . "\$query->select(\$db->quoteName('" . $filter['custom']['db'] . "." . $filter['custom']['text'] . "','" . $filter['code'] . "'));";
}
else
{
$query .= PHP_EOL . $this->_t(2) . $tab . "\$query->select(\$db->quoteName('" . $filter['custom']['db'] . "." . $filter['custom']['text'] . "','" . $filter['code'] . "_" . $filter['custom']['text'] . "'));";
}
$query .= PHP_EOL . $this->_t(2) . $tab . "\$query->join('LEFT', \$db->quoteName('" . $filter['custom']['table'] . "', '" . $filter['custom']['db'] . "') . ' ON (' . \$db->quoteName('a." . $filter['code'] . "') . ' = ' . \$db->quoteName('" . $filter['custom']['db'] . "." . $filter['custom']['id'] . "') . ')');";
}
// build the field type file
$this->setCustomFieldTypeFile($filter, $viewName_list, $viewName_single);
@@ -11804,7 +11852,7 @@ class Interpretation extends Fields
$allow[] = $this->_t(3) . "{";
$allow[] = $this->_t(4) . "//" . $this->setLine(__LINE__) . " We have to unset then (TODO)";
$allow[] = $this->_t(4) . "//" . $this->setLine(__LINE__) . " Hiddend field can not handel array value";
$allow[] = $this->_t(4) . "//" . $this->setLine(__LINE__) . " Even if we conver to json we get an error";
$allow[] = $this->_t(4) . "//" . $this->setLine(__LINE__) . " Even if we convert to json we get an error";
$allow[] = $this->_t(4) . "\$form->removeField('" . $fieldName . "');";
$allow[] = $this->_t(3) . "}";
$allow[] = $this->_t(2) . "}";
@@ -12458,7 +12506,7 @@ class Interpretation extends Fields
public function setPopulateState(&$view)
{
// rest buket
// reset buket
$state = '';
// keep track of all fields already added
$donelist = array();
@@ -12665,11 +12713,12 @@ class Interpretation extends Fields
return $checkin;
}
public function setGetItemsMethodStringFix($viewName_single, $viewName_list, $Component, $tab = '', $export = false)
public function setGetItemsMethodStringFix($viewName_single, $viewName_list, $Component, $tab = '', $export = false, $all = false)
{
// add the fix if this view has the need for it
$fix = '';
$forEachStart = '';
$fix_access = '';
// encryption switches
foreach ($this->cryptionTypes as $cryptionType)
{
@@ -12686,21 +12735,22 @@ class Interpretation extends Fields
// check if the item has permissions.
if ($coreLoad && isset($core['core.access']) && isset($this->permissionBuilder[$core['core.access']]) && ComponentbuilderHelper::checkArray($this->permissionBuilder[$core['core.access']]) && in_array($viewName_single, $this->permissionBuilder[$core['core.access']]))
{
$fix .= PHP_EOL . $this->_t(1) . $tab . $this->_t(3) . "//" . $this->setLine(__LINE__) . " Remove items the user can't access.";
$fix .= PHP_EOL . $this->_t(1) . $tab . $this->_t(3) . "\$access = (\$user->authorise('" . $core['core.access'] . "', 'com_" . $component . "." . $viewName_single . ".' . (int) \$item->id) && \$user->authorise('" . $core['core.access'] . "', 'com_" . $component . "'));";
$fix .= PHP_EOL . $this->_t(1) . $tab . $this->_t(3) . "if (!\$access)";
$fix .= PHP_EOL . $this->_t(1) . $tab . $this->_t(3) . "{";
$fix .= PHP_EOL . $this->_t(1) . $tab . $this->_t(4) . "unset(\$items[\$nr]);";
$fix .= PHP_EOL . $this->_t(1) . $tab . $this->_t(4) . "continue;";
$fix .= PHP_EOL . $this->_t(1) . $tab . $this->_t(3) . "}" . PHP_EOL;
$fix_access = PHP_EOL . $this->_t(1) . $tab . $this->_t(3) . "//" . $this->setLine(__LINE__) . " Remove items the user can't access.";
$fix_access .= PHP_EOL . $this->_t(1) . $tab . $this->_t(3) . "\$access = (\$user->authorise('" . $core['core.access'] . "', 'com_" . $component . "." . $viewName_single . ".' . (int) \$item->id) && \$user->authorise('" . $core['core.access'] . "', 'com_" . $component . "'));";
$fix_access .= PHP_EOL . $this->_t(1) . $tab . $this->_t(3) . "if (!\$access)";
$fix_access .= PHP_EOL . $this->_t(1) . $tab . $this->_t(3) . "{";
$fix_access .= PHP_EOL . $this->_t(1) . $tab . $this->_t(4) . "unset(\$items[\$nr]);";
$fix_access .= PHP_EOL . $this->_t(1) . $tab . $this->_t(4) . "continue;";
$fix_access .= PHP_EOL . $this->_t(1) . $tab . $this->_t(3) . "}" . PHP_EOL;
}
if (!$export)
// get the correct array
if ($export || $all)
{
$methodName = 'getItemsMethodListStringFixBuilder';
$methodName = 'getItemsMethodEximportStringFixBuilder';
}
else
{
$methodName = 'getItemsMethodEximportStringFixBuilder';
$methodName = 'getItemsMethodListStringFixBuilder';
}
// load the relations before modeling
if (isset($this->fieldRelations[$viewName_list]) && ComponentbuilderHelper::checkArray($this->fieldRelations[$viewName_list]))
@@ -12922,10 +12972,10 @@ class Interpretation extends Fields
}
}
// close the foreach if needed
if (ComponentbuilderHelper::checkString($fix) || $export)
if (ComponentbuilderHelper::checkString($fix) || ComponentbuilderHelper::checkString($fix_access) || $export || $all)
{
// start the loop
$forEachStart = PHP_EOL . PHP_EOL . $this->_t(1) . $tab . $this->_t(1) . "//" . $this->setLine(__LINE__) . " set values to display correctly.";
$forEachStart = PHP_EOL . PHP_EOL . $this->_t(1) . $tab . $this->_t(1) . "//" . $this->setLine(__LINE__) . " Set values to display correctly.";
$forEachStart .= PHP_EOL . $this->_t(1) . $tab . $this->_t(1) . "if (" . $Component . "Helper::checkArray(\$items))";
$forEachStart .= PHP_EOL . $this->_t(1) . $tab . $this->_t(1) . "{";
// do not add to export since it is already done
@@ -12937,19 +12987,43 @@ class Interpretation extends Fields
$forEachStart .= PHP_EOL . $this->_t(1) . $tab . $this->_t(3) . "\$user = JFactory::getUser();";
$forEachStart .= PHP_EOL . $this->_t(1) . $tab . $this->_t(2) . "}";
}
// the permissional acttion switch
$hasPermissional = false;
// add the permissional removal of values the user has not right to view or access
if (isset($this->permissionFields[$viewName_single]) && ComponentbuilderHelper::checkArray($this->permissionFields[$viewName_single]))
if ($this->strictFieldExportPermissions && isset($this->permissionFields[$viewName_single]) && ComponentbuilderHelper::checkArray($this->permissionFields[$viewName_single]))
{
$forEachStart .= PHP_EOL . $this->_t(1) . $tab . $this->_t(2) . "//" . $this->setLine(__LINE__) . " -- get global permissional control activation. (default is inactive) ---";
$forEachStart .= PHP_EOL . $this->_t(1) . $tab . $this->_t(2) . "//" . $this->setLine(__LINE__) . " to use this feature add a global option radio button to your";
$forEachStart .= PHP_EOL . $this->_t(1) . $tab . $this->_t(2) . "//" . $this->setLine(__LINE__) . " component with a value of 1 as on/activate and 0 as inactive/off";
$forEachStart .= PHP_EOL . $this->_t(1) . $tab . $this->_t(2) . "//" . $this->setLine(__LINE__) . " make sure it has the name: strict_permission_per_field";
$forEachStart .= PHP_EOL . $this->_t(1) . $tab . $this->_t(2) . "\$strict_permission_per_field = JComponentHelper::getParams('com_" . $component . "')->get('strict_permission_per_field', 0);" . PHP_EOL;
foreach ($this->permissionFields[$viewName_single] as $fieldName => $permission_options)
{
if (!$hasPermissional)
{
foreach($permission_options as $permission_option => $fieldType)
{
if (!$hasPermissional)
{
switch ($permission_option)
{
case 'access':
case 'view':
$hasPermissional = true;
break;
}
}
}
}
}
// add the notes and get the global switch
if ($hasPermissional)
{
$forEachStart .= PHP_EOL . $this->_t(1) . $tab . $this->_t(2) . "//" . $this->setLine(__LINE__) . " Get global permissional control activation. (default is inactive)";
$forEachStart .= PHP_EOL . $this->_t(1) . $tab . $this->_t(2) . "\$strict_permission_per_field = JComponentHelper::getParams('com_" . $component . "')->get('strict_permission_per_field', 0);" . PHP_EOL;
}
}
$forEachStart .= PHP_EOL . $this->_t(1) . $tab . $this->_t(2) . "foreach (\$items as \$nr => &\$item)";
$forEachStart .= PHP_EOL . $this->_t(1) . $tab . $this->_t(2) . "{";
// add the access options
$forEachStart .= $fix_access;
// add the permissional removal of values the user has not right to view or access
if (isset($this->permissionFields[$viewName_single]) && ComponentbuilderHelper::checkArray($this->permissionFields[$viewName_single]))
if ($hasPermissional)
{
$forEachStart .= PHP_EOL . $this->_t(1) . $tab . $this->_t(3) . "//" . $this->setLine(__LINE__) . " use permissional control if globaly set.";
$forEachStart .= PHP_EOL . $this->_t(1) . $tab . $this->_t(3) . "if (\$strict_permission_per_field)";

View File

@@ -12,6 +12,8 @@
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
use Joomla\Utilities\ArrayHelper;
/**
* Componentbuilder component helper.
*/
@@ -61,14 +63,14 @@ abstract class ComponentbuilderHelper
/**
* The VDM packages paths
**/
public static $vdmGithubPackagesUrl = "https://api.github.com/repos/vdm-io/JCB-Packages/git/trees/master";
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 $jcbGithubPackagesUrl = "https://api.github.com/repos/vdm-io/JCB-Community-Packages/git/trees/master";
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
@@ -76,9 +78,6 @@ abstract class ComponentbuilderHelper
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';
// not needed at this time (maybe latter)
public static $accessToken = "";
/**
* The array of constant paths
*
@@ -2413,66 +2412,163 @@ abstract class ComponentbuilderHelper
/**
* get the github repo file list
*
* @return array on success
*
*/
* 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 current Packages (public)
if (!$repoData = self::get($type))
// get the repo data
if (($repoData = self::getGithubRepoData($type, $target, 'tree')) !== false)
{
if (self::urlExists($target))
{
$repoData = self::getFileContents($target);
if (self::checkJson($repoData))
{
$test = json_decode($repoData);
if (self::checkObject($test) && isset($test->tree) && self::checkArray($test->tree) )
{
// remember to set it
self::set($type, $repoData);
}
// check if we have error message from github
elseif ($errorMessage = self::githubErrorHandeler(array('error' => null), $test))
{
if (self::checkString($errorMessage['error']))
{
JFactory::getApplication()->enqueueMessage($errorMessage['error'], 'Error');
}
$repoData = false;
}
}
else
{
$repoData = false;
}
}
else
{
JFactory::getApplication()->enqueueMessage(JText::sprintf('COM_COMPONENTBUILDER_THE_URL_S_SET_TO_RETRIEVE_THE_PACKAGES_DOES_NOT_EXIST', $target), 'Error');
}
}
// check if we could find packages
if (isset($repoData) && self::checkJson($repoData))
{
$repoData = json_decode($repoData);
if (self::checkObject($repoData) && isset($repoData->tree) && self::checkArray($repoData->tree) )
{
return $repoData->tree;
}
return $repoData->tree;
}
return false;
}
/**
* get the github error messages
*
* @return array of errors on success
*
*/
protected static function githubErrorHandeler($message, &$github)
* 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}) )
{
if ('nomemory' !== $type)
{
// remember to set it
self::set($type, $repoData);
}
}
elseif (!self::checkString($target) && 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))
{
@@ -2481,13 +2577,17 @@ abstract class ComponentbuilderHelper
// add the documentation URL
if (isset($github->documentation_url) && self::checkString($github->documentation_url))
{
$errorMessage = $errorMessage.'<br />'.$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_AN_BACCESS_TOKENB_TO_GETBIBLE_GLOBAL_OPTIONS_TO_MAKE_AUTHENTICATED_REQUESTS_AN_ACCESS_TOKEN_WITH_ONLY_PUBLIC_ACCESS_WILL_DO', $errorMessage);
$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;
@@ -2497,6 +2597,36 @@ abstract class ComponentbuilderHelper
return false;
}
/**
* set the github token
*
* @return array of errors on success
*
*/
protected static function setGithubToken($url)
{
// first check if token already set
if (strpos($url, 'access_token=') !== false)
{
// make sure the token is loaded
if (!self::checkString(self::$gitHubAccessToken))
{
// get the global settings
if (!self::checkObject(self::$params))
{
self::$params = JComponentHelper::getParams('com_componentbuilder');
}
self::$gitHubAccessToken = self::$params->get('github_access_token', null);
}
// make sure the token is loaded at this point
if (self::checkString(self::$gitHubAccessToken))
{
$url .= '&access_token=' . self::$gitHubAccessToken;
}
}
return $url;
}
/**
* get Dynamic Scripts