diff --git a/README.md b/README.md index 970871d20..be1bde531 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ The Component Builder for [Joomla](https://extensions.joomla.org/extension/compo Whether you're a seasoned [Joomla](https://extensions.joomla.org/extension/component-builder/) developer, or have just started, Component Builder will safe you lots of time and money. A real must have! -You can install it quite easily and with no limitations. On [github](https://github.com/vdm-io/Joomla-Component-Builder/releases) is the latest release (2.6.12) with **ALL** its features and **ALL** concepts totally open-source and free! +You can install it quite easily and with no limitations. On [github](https://github.com/vdm-io/Joomla-Component-Builder/releases) is the latest release (2.6.13) with **ALL** its features and **ALL** concepts totally open-source and free! > Watch Quick Build of a Hello World component in [JCB on Youtube](https://www.youtube.com/watch?v=IQfsLYIeblk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&index=45) @@ -126,13 +126,13 @@ Component Builder is mapped as a component in itself on my local development env + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Name*: [Component Builder](http://joomlacomponentbuilder.com) + *First Build*: 30th April, 2015 -+ *Last Build*: 20th January, 2018 -+ *Version*: 2.6.12 ++ *Last Build*: 23rd January, 2018 ++ *Version*: 2.6.13 + *Copyright*: Copyright (C) 2015. All Rights Reserved + *License*: GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html -+ *Line count*: **180517** -+ *Field count*: **1573** -+ *File count*: **1160** ++ *Line count*: **180832** ++ *Field count*: **1577** ++ *File count*: **1161** + *Folder count*: **186** > This **component** was build with a Joomla [Automated Component Builder](http://joomlacomponentbuilder.com). diff --git a/admin/README.txt b/admin/README.txt index 970871d20..be1bde531 100644 --- a/admin/README.txt +++ b/admin/README.txt @@ -9,7 +9,7 @@ The Component Builder for [Joomla](https://extensions.joomla.org/extension/compo Whether you're a seasoned [Joomla](https://extensions.joomla.org/extension/component-builder/) developer, or have just started, Component Builder will safe you lots of time and money. A real must have! -You can install it quite easily and with no limitations. On [github](https://github.com/vdm-io/Joomla-Component-Builder/releases) is the latest release (2.6.12) with **ALL** its features and **ALL** concepts totally open-source and free! +You can install it quite easily and with no limitations. On [github](https://github.com/vdm-io/Joomla-Component-Builder/releases) is the latest release (2.6.13) with **ALL** its features and **ALL** concepts totally open-source and free! > Watch Quick Build of a Hello World component in [JCB on Youtube](https://www.youtube.com/watch?v=IQfsLYIeblk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&index=45) @@ -126,13 +126,13 @@ Component Builder is mapped as a component in itself on my local development env + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Name*: [Component Builder](http://joomlacomponentbuilder.com) + *First Build*: 30th April, 2015 -+ *Last Build*: 20th January, 2018 -+ *Version*: 2.6.12 ++ *Last Build*: 23rd January, 2018 ++ *Version*: 2.6.13 + *Copyright*: Copyright (C) 2015. All Rights Reserved + *License*: GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html -+ *Line count*: **180517** -+ *Field count*: **1573** -+ *File count*: **1160** ++ *Line count*: **180832** ++ *Field count*: **1577** ++ *File count*: **1161** + *Folder count*: **186** > This **component** was build with a Joomla [Automated Component Builder](http://joomlacomponentbuilder.com). diff --git a/admin/compiler/joomla_3/router.php b/admin/compiler/joomla_3/router.php index e0504bcd6..5912f24cc 100644 --- a/admin/compiler/joomla_3/router.php +++ b/admin/compiler/joomla_3/router.php @@ -222,7 +222,7 @@ function ###Component###BuildRoute(&$query) function ###Component###ParseRoute($segments) { - $router = new ContentRouter; + $router = new ###Component###Router; return $router->parse($segments); } \ No newline at end of file diff --git a/admin/controllers/ajax.json.php b/admin/controllers/ajax.json.php index c9f554f5d..a2c62bfbd 100644 --- a/admin/controllers/ajax.json.php +++ b/admin/controllers/ajax.json.php @@ -48,7 +48,7 @@ class ComponentbuilderControllerAjax extends JControllerLegacy $this->registerTask('getCronPath', 'ajax'); $this->registerTask('tableColumns', 'ajax'); $this->registerTask('fieldSelectOptions', 'ajax'); - $this->registerTask('getImportScripts', 'ajax'); + $this->registerTask('getDynamicScripts', 'ajax'); $this->registerTask('getButton', 'ajax'); $this->registerTask('getButtonID', 'ajax'); $this->registerTask('getAjaxDisplay', 'ajax'); @@ -306,14 +306,14 @@ class ComponentbuilderControllerAjax extends JControllerLegacy } } break; - case 'getImportScripts': + case 'getDynamicScripts': try { $returnRaw = $jinput->get('raw', false, 'BOOLEAN'); $typeValue = $jinput->get('type', NULL, 'WORD'); if($typeValue && $user->id != 0) { - $result = $this->getModel('ajax')->getImportScripts($typeValue); + $result = $this->getModel('ajax')->getDynamicScripts($typeValue); } else { diff --git a/admin/custom/dropbox.php b/admin/custom/dropbox.php index 8f59d5da0..66543cfe1 100644 --- a/admin/custom/dropbox.php +++ b/admin/custom/dropbox.php @@ -1,10 +1,9 @@ @@ -21,16 +20,15 @@ defined('_JEXEC') or die; */ class Dropbox { - /** * final url */ protected $url; - + /** * The array for the post url */ - protected $postUrl = array( + protected $postUrl = array( "protocol" => "https://", "suddomain" => "api.", "domain" => "dropboxapi.com", @@ -39,69 +37,75 @@ class Dropbox /** * the verious pathes we need - */ - protected $domainpath = array( + */ + protected $domainpath = array( + "list_shared_links" => "sharing/list_shared_links", "list_folder" => "files/list_folder", "list_folder_continue" => "files/list_folder/continue", - "create_shared_link" => "sharing/create_shared_link", + "create_shared_link_with_settings" => "sharing/create_shared_link_with_settings", "get_shared_link_metadata" => "sharing/get_shared_link_metadata", "revoke" => "auth/token/revoke" ); /** * the target pathe to get - */ + */ protected $targetPath = false; protected $targetPathOriginal = false; /** * oauth token - */ + */ protected $oauthToken; /** * the verious pathes we need - */ + */ protected $permissionType; /** - * The loop controller in calling Dropbox API - */ - protected $continueCalling = array(); + * The array of queries for creating shared links + */ + protected $createSharedLinks = array(); + + /** + * The array of queries for getting shared links + */ + protected $getSharedLinks = array(); /** * the success switch - */ + */ protected $succes; /** * the type call - */ + */ protected $type; /** * the query for the call - */ + */ protected $query; /** * the query for the call - */ + */ protected $model; /** * the mediaData bucket - */ + */ public $mediaData = array(); /** * the error messages - */ + */ public $error_summary = array(); - + /** - * force the update to reset - * */ + * force the update to reset + **/ public $forceReset = false; /** @@ -109,8 +113,12 @@ class Dropbox */ public function __construct(JModelLegacy $model, $buildType) { + // set the first call + $this->firstCall = 'get'; // TODO (we may what to make this dynamic) + // set the second call + $this->secondCall = 'create'; // TODO (we may what to make this dynamic) // set the url at this point for now - $this->url = $this->postUrl["protocol"] . $this->postUrl["suddomain"] . $this->postUrl["domain"] . $this->postUrl["path"]; + $this->url = $this->postUrl["protocol"].$this->postUrl["suddomain"].$this->postUrl["domain"].$this->postUrl["path"]; // set the local model $this->model = $model; // set the build type @@ -135,10 +143,10 @@ class Dropbox ini_set('max_execution_time', 500); // set the oauth toke $this->oauthToken = $token; - + // set the permission type $this->permissionType = $permissiontype; - + // set the details if ($this->checkArray($details)) { @@ -147,22 +155,125 @@ class Dropbox $this->$detail = $value; } } - + // set the curent folder path if (!$this->setFolderPath()) { return false; } - // start the main factory that calles for the folder data $this->query = array("path" => $this->targetPath, "recursive" => true, "include_media_info" => true); $this->type = 'list_folder'; if ($this->makeCall()) { + if ($this->_isCurl()) + { + // run the share link builder + return $this->makeMultiExecCalls(); + } return true; } + return false; } - + + protected function makeMultiExecCalls() + { + // make the fist call + $this->multiSharedLinks($this->firstCall); + // make the second call + $this->multiSharedLinks($this->secondCall); + // make the fist call (again for safety) + $this->multiSharedLinks($this->firstCall); + // make the second call (again for safety) + $this->multiSharedLinks($this->secondCall); + } + + protected function multiSharedLinks($type) + { + switch ($type) + { + case "create": + // great links if not made already + if (count($this->createSharedLinks) > 0) + { + $url = $this->url.$this->domainpath['create_shared_link_with_settings']; + $this->type = 'create_shared_link_with_settings'; + // build return function + $storeSharedLink = function ($data, $target) { + // check if link already made + if (isset($data->error_summary) && strpos($data->error_summary, 'shared_link_already_exists') !== false) + { + $this->getSharedLinks[] = json_encode(array("path" => $target)); + } + else + { + $this->curlCallResult($data); + } + }; + // run call + return $this->multiCall($url, $type, $storeSharedLink); + } + break; + case "get": + // now get the already made links + if (count($this->getSharedLinks) > 0) + { + $url = $this->url.$this->domainpath['list_shared_links']; + $this->type = 'list_shared_links'; + // build return function + $storeSharedLink = function ($data, $target) { + // check if link not made + if (isset($data->error_summary)) + { + $this->createSharedLinks[] = json_encode(array("path" => $target, "settings" => array("requested_visibility" => "public"))); + } + else + { + $this->curlCallResult($data); + } + }; + // run call + return $this->multiCall($url, $type, $storeSharedLink); + } + break; + } + return false; + } + + protected function multiCall(&$url, $type, &$storeSharedLink) + { + $timer = 1; + $options = array(); + // set the options array and make the calls every 250 + foreach ($this->{$type."SharedLinks"} as $query) + { + $options[] = array(CURLOPT_HTTPHEADER => array('Authorization: Bearer ' . $this->oauthToken, 'Content-Type: application/json'), CURLOPT_POST => 1, CURLOPT_POSTFIELDS => $query); $timer++; + // check timer + if ($timer >= 550) + { + // run multi curl + $this->curlMultiExec($url, $options, $storeSharedLink); + // reset + $timer = 1; + $options = array(); + } + } + // make sure all was done + if ($timer > 1 && count($options)) + { + // run multi curl + $this->curlMultiExec($url, $options, $storeSharedLink); + } + // reset the values + $this->{$type."SharedLinks"} = array(); + // only if there is no errors + if (count($this->error_summary) > 0) + { + return false; + } + return true; + } + public function revokeToken($token = null) { if ($token) @@ -179,7 +290,7 @@ class Dropbox } return false; } - + protected function setFolderPath() { if ('full' == $this->permissionType && isset($this->dropboxOption) && isset($this->dropboxTarget) && $this->checkString($this->dropboxTarget)) @@ -187,8 +298,8 @@ class Dropbox if (2 == $this->dropboxOption) { // simply set the path - $this->targetPath = '/' . trim(strtolower($this->dropboxTarget), '/'); - + $this->targetPath = '/'.trim(strtolower($this->dropboxTarget), '/'); + return true; } elseif (1 == $this->dropboxOption) @@ -205,12 +316,12 @@ class Dropbox elseif ('app' == $this->permissionType) { $this->targetPath = ""; - + return true; } return false; } - + protected function makeCall() { if ($this->_isCurl()) @@ -222,48 +333,52 @@ class Dropbox return $this->makeGetCall(); } } - + protected function makeGetCall() - { + { $options = array( 'http' => array( - 'header' => "Content-Type: application/json\r\n" . - "Authorization: Bearer " . $this->oauthToken, - 'method' => "POST" + 'header' => "Content-Type: application/json\r\n". + "Authorization: Bearer ".$this->oauthToken, + 'method' => "POST" ), ); - + if ($this->checkArray($this->query)) { $this->query = json_encode($this->query); } - $options['http']['content'] = $this->query; - + // add the query + if ($this->checkString($this->query)) + { + $options['http']['content'] = $this->query; + } $context = stream_context_create($options); - $response = file_get_contents($this->url . $this->domainpath[$this->type], false, $context); + $response = file_get_contents($this->url.$this->domainpath[$this->type], false, $context); // store the result return $this->getCallResult($response); } - + protected function getCallResult($response) { if ($response === FALSE) { - $this->error_summary[] = $this->type . '_error'; + $this->error_summary[] = $this->type.'_error'; return false; } // store the result return $this->setTheResult(json_decode($response)); } - + protected function makeCurlCall() { - $headers = array('Authorization: Bearer ' . $this->oauthToken, - 'Content-Type: application/json' - ); + // do not run creat shared link this way + $headers = array('Authorization: Bearer '. $this->oauthToken, + 'Content-Type: application/json' + ); - $ch = curl_init($this->url . $this->domainpath[$this->type]); + $ch = curl_init($this->url.$this->domainpath[$this->type]); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); // check if query is set @@ -271,7 +386,11 @@ class Dropbox { $this->query = json_encode($this->query); } - curl_setopt($ch, CURLOPT_POSTFIELDS, $this->query); + // add the query + if ($this->checkString($this->query)) + { + curl_setopt($ch, CURLOPT_POSTFIELDS, $this->query); + } curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // curl_setopt($ch, CURLOPT_VERBOSE, 1); // debug @@ -283,9 +402,9 @@ class Dropbox // store the result return $this->curlCallResult($response); } - + public function curlCallResult($response) - { + { if ($this->checkJson($response)) { $response = json_decode($response); @@ -293,7 +412,7 @@ class Dropbox // store the result return $this->setTheResult($response); } - + protected function setTheResult($data) { // if there was an error stop!!! @@ -303,11 +422,11 @@ class Dropbox $this->forceReset = true; return false; } - + // deal with each type switch ($this->type) { - case "list_folder": + case "list_folder": case "list_folder_continue": if (isset($data->entries) && $this->checkArray($data->entries)) { @@ -327,15 +446,30 @@ class Dropbox return true; } } - $this->error_summary[] = $this->type . '_error'; + $this->error_summary[] = $this->type.'_error'; break; - case "create_shared_link": - if (isset($data->url) && isset($data->path) && $this->storeSharedLink($this->fixPath($data->path), str_replace('?dl=0', '?dl=1', $data->url))) + case "list_shared_links": + if (isset($data->links) && $this->checkArray($data->links)) + { + foreach ($data->links as $link) + { + if (!$this->storeSharedLink($link)) + { + // we could not stored the link + return false; + } + } + return true; + } + $this->error_summary[] = $this->type.'_error'; + break; + case "create_shared_link_with_settings": + if ($this->storeSharedLink($data)) { // we stored the link return true; } - $this->error_summary[] = $this->type . '_error'; + $this->error_summary[] = $this->type.'_error'; break; case "get_shared_link_metadata": if (isset($data->path_lower)) @@ -343,37 +477,36 @@ class Dropbox $this->targetPath = $data->path_lower; return true; } - $this->error_summary[] = $this->type . '_error'; + $this->error_summary[] = $this->type.'_error'; break; case "revoke": if (is_null($data)) { return true; } - $this->error_summary[] = $this->type . '_error'; + $this->error_summary[] = $this->type.'_error'; break; } $this->forceReset = true; return false; } - - protected function storeSharedLink($path, $url) + + protected function storeSharedLink($data) { // we need to store the url to DB - if (isset($this->mediaData[$path])) + if (isset($data->url) && isset($data->name) && isset($data->size) && (isset($data->path) || isset($data->path_lower))) { - $localListing = array(); - $localListing['id'] = 0; - $localListing['name'] = $this->mediaData[$path]['name']; - $localListing['size'] = $this->mediaData[$path]['size']; - $localListing['key'] = $path; - $localListing['url'] = $url; - $localListing['build'] = $this->build; - $localListing['external_source'] = (int) $this->sourceID; - // free some memory - unset($this->mediaData[$path]); + $path = (isset($data->path)) ? $data->path : $data->path_lower; + $localListing = array(); + $localListing['id'] = 0; + $localListing['name'] = $data->name; + $localListing['size'] = $data->size; + $localListing['key'] = $this->fixPath($path); + $localListing['url'] = str_replace('?dl=0','?dl=1',$data->url); + $localListing['build'] = $this->build; + $localListing['external_source'] = (int) $this->sourceID; // check if item already set - if ($id = $this->model->searchForId($path)) + if ($id = $this->model->searchForId($localListing['key'])) { // update item $localListing['id'] = $id; @@ -384,9 +517,9 @@ class Dropbox } protected function storeFiles($entries) - { + { foreach ($entries as $item) - { + { if (isset($item->{'.tag'}) && 'file' == $item->{'.tag'} && isset($item->name)) { $addLink = false; @@ -395,7 +528,7 @@ class Dropbox { foreach ($this->addTypes as $add) { - if (strpos($item->name, $add) !== false) + if (strpos($item->name,$add) !== false) { $addLink = true; } @@ -403,12 +536,28 @@ class Dropbox } if ($addLink && isset($item->path_lower)) { - // store media info - $this->mediaData[$this->fixPath($item->path_lower)] = array('name' => $item->name, 'size' => $item->size); - // get the shared link - $this->query = array("path" => $item->path_lower); - $this->type = 'create_shared_link'; - if (!$this->makeCall()) + // set based on first call + if ('get' === $this->firstCall) + { + // first check if shared link exist + $this->query = array("path" => $item->path_lower); + // set the type of call + $this->type = 'list_shared_links'; + } + else + { + // first check if shared link exist + $this->query = array("path" => $item->path_lower, "settings" => array("requested_visibility" => "public")); + // set the type of call + $this->type = 'create_shared_link_with_settings'; + } + // if we have curl the use multi curl execution + if ($this->_isCurl()) + { + // set query to worker + $this->{$this->firstCall."SharedLinks"}[] = json_encode($this->query); + } + elseif (!$this->makeCall()) { return false; } @@ -417,7 +566,7 @@ class Dropbox } return true; } - + protected function fixPath($path) { if ($this->checkString($this->targetPath)) @@ -426,7 +575,7 @@ class Dropbox } else { - $path = 'VDM_pLeK_h0uEr' . $path; + $path = 'VDM_pLeK_h0uEr'.$path; } return $path; } @@ -448,7 +597,7 @@ class Dropbox } return false; } - + protected function checkJson($string) { if ($this->checkString($string)) @@ -467,9 +616,85 @@ class Dropbox } return false; } - + protected function _isCurl() { return function_exists('curl_version'); } + + protected function curlMultiExec(&$url, &$_options, $callback = null) + { + if ($this->checkString($url)) + { + // make sure the thread size isn't greater than the # of _options + $threadSize = 20; + $threadSize = (sizeof($_options) < $threadSize) ? sizeof($_options) : $threadSize; + // set the options + $options = array(); + $options[CURLOPT_URL] = $url; + $options[CURLOPT_USERAGENT] = 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12'; + $options[CURLOPT_RETURNTRANSFER] = TRUE; + $options[CURLOPT_SSL_VERIFYPEER] = FALSE; + // start multi threading :) + $handle = curl_multi_init(); + // start the first batch of requests + for ($i = 0; $i < $threadSize; $i++) + { + if (isset($_options[$i])) + { + $ch = curl_init(); + foreach ($_options[$i] as $curlopt => $string) + { + $options[$curlopt] = $string; + } + curl_setopt_array($ch, $options); + curl_multi_add_handle($handle, $ch); + } + } + // we wait for all the calls to finish (should not take long) + do { + while(($execrun = curl_multi_exec($handle, $working)) == CURLM_CALL_MULTI_PERFORM); + if($execrun != CURLM_OK) + break; + // a request was just completed -- find out which one + while($done = curl_multi_info_read($handle)) + { + if (is_callable($callback)) + { + // $info = curl_getinfo($done['handle']); + // request successful. process output using the callback function. + $output = curl_multi_getcontent($done['handle']); + $callback(json_decode($output), json_decode(end($_options[$i]))->path); + } + $key = $i + 1; + if(isset($_options[$key])) + { + // start a new request (it's important to do this before removing the old one) + $ch = curl_init(); $i++; + // add options + foreach ($_options[$key] as $curlopt => $string) + { + $options[$curlopt] = $string; + } + curl_setopt_array($ch, $options); + curl_multi_add_handle($handle, $ch); + // remove options again + foreach ($_options[$key] as $curlopt => $string) + { + unset($options[$curlopt]); + } + } + // remove the curl handle that just completed + curl_multi_remove_handle($handle, $done['handle']); + } + // stop wasting CPU cycles and rest for a couple ms + usleep(10000); + } while ($working); + // close the curl multi thread + curl_multi_close($handle); + // okay done + return true; + } + return false; + } } diff --git a/admin/custom/dropboxupdater.php b/admin/custom/dropboxupdater.php index 919b4897b..44bff92d3 100644 --- a/admin/custom/dropboxupdater.php +++ b/admin/custom/dropboxupdater.php @@ -405,7 +405,7 @@ class Dropboxupdater { $this->setErrors($this->dropbox->error_summary); return false; - } + } // if this is a manual update, then revoke the token if ($this->forceUpdate) { diff --git a/admin/helpers/compiler/a_Get.php b/admin/helpers/compiler/a_Get.php index d00c53680..9e2b2020a 100644 --- a/admin/helpers/compiler/a_Get.php +++ b/admin/helpers/compiler/a_Get.php @@ -1545,7 +1545,7 @@ class Get else { // load the default - $this->customScriptBuilder[$importScripter]['import_' . $name_list] = ComponentbuilderHelper::getImportScripts($importScripter, true); + $this->customScriptBuilder[$importScripter]['import_' . $name_list] = ComponentbuilderHelper::getDynamicScripts($importScripter, true); } } } diff --git a/admin/helpers/compiler/e_Interpretation.php b/admin/helpers/compiler/e_Interpretation.php index d85b00c5e..ee510982e 100644 --- a/admin/helpers/compiler/e_Interpretation.php +++ b/admin/helpers/compiler/e_Interpretation.php @@ -2242,7 +2242,11 @@ class Interpretation extends Fields $getItem .= PHP_EOL . "\t" . $tab . "\t\$this->_item[\$pk] = \$data;"; } // check if the dispather should be added - return str_replace(array_keys($this->JEventDispatcher), array_values($this->JEventDispatcher), $getItem); + if (isset($this->JEventDispatcher) && ComponentbuilderHelper::checkArray($this->JEventDispatcher)) + { + $getItem = str_replace(array_keys($this->JEventDispatcher), array_values($this->JEventDispatcher), $getItem); + } + return $getItem; } return PHP_EOL . "\t" . $tab . "\t//" . $this->setLine(__LINE__) . "add your custom code here."; } @@ -2693,7 +2697,11 @@ class Interpretation extends Fields } } // check if the dispatcher must be set - return str_replace(array_keys($this->JEventDispatcher), array_values($this->JEventDispatcher), $methods) . PHP_EOL; + if (isset($this->JEventDispatcher) && ComponentbuilderHelper::checkArray($this->JEventDispatcher)) + { + $methods = str_replace(array_keys($this->JEventDispatcher), array_values($this->JEventDispatcher), $methods); + } + return $methods . PHP_EOL; } public function setCustomViewMethodDefaults($get, $code) @@ -2842,7 +2850,10 @@ class Interpretation extends Fields } } // check if we should load the dispatcher - $getItem = str_replace(array_keys($this->JEventDispatcher), array_values($this->JEventDispatcher), $getItem); + if (isset($this->JEventDispatcher) && ComponentbuilderHelper::checkArray($this->JEventDispatcher)) + { + $getItem = str_replace(array_keys($this->JEventDispatcher), array_values($this->JEventDispatcher), $getItem); + } // setup Globals $getItem .= $this->setCustomViewGlobals($get->global, '$item', $asBucket, "\t\t"); // setup the custom gets that returns multipal values @@ -4816,19 +4827,29 @@ class Interpretation extends Fields public function routerParseSwitch(&$view, $viewArray = null, $aliasView = true, $idView = true) { + // reset buckets + $routerSwitch = array(); $isCategory = ''; $viewTable = false; - if ($viewArray && ComponentbuilderHelper::checkArray($viewArray)) + if ($viewArray && ComponentbuilderHelper::checkArray($viewArray) && isset($viewArray['settings']) && isset($viewArray['settings']->main_get)) { - if (isset($viewArray['settings']->main_get->db_table_main) && $viewArray['settings']->main_get->db_table_main === 'categories') + // check if we have custom script for this router parse switch case + if (isset($viewArray['settings']->main_get->add_php_router_parse) && $viewArray['settings']->main_get->add_php_router_parse == 1 + && isset($viewArray['settings']->main_get->php_router_parse) && ComponentbuilderHelper::checkString($viewArray['settings']->main_get->php_router_parse)) + { + // load the custom script for the switch based on dynamic get + $routerSwitch[] = PHP_EOL . "\t\t\tcase '" . $view . "':"; + $routerSwitch[] = $this->setPlaceholders($this->setDynamicValues(base64_decode($viewArray['settings']->main_get->php_router_parse)), $this->placeholders); + $routerSwitch[] = "\t\t\t\tbreak;"; + + return implode(PHP_EOL, $routerSwitch); + } + // is this a catogory + elseif (isset($viewArray['settings']->main_get->db_table_main) && $viewArray['settings']->main_get->db_table_main === 'categories') { $isCategory = ', true'; // TODO we will keep an eye on this.... } -// elseif (isset($viewArray['settings']->main_get->gettype) && $viewArray['settings']->main_get->gettype == 2) -// { -// $idView = false; // TODO we will keep an eye on this.... -// $aliasView = false; -// } + // get the main table name elseif (isset($viewArray['settings']->main_get->main_get) && ComponentbuilderHelper::checkArray($viewArray['settings']->main_get->main_get)) { foreach ($viewArray['settings']->main_get->main_get as $get) @@ -4842,6 +4863,7 @@ class Interpretation extends Fields $viewTable = str_replace('#__' . $this->fileContentStatic['###component###'] . '_', '', $get['selection']['table']); } } + break; } } } @@ -4849,9 +4871,6 @@ class Interpretation extends Fields // add if tags is added, also for all front item views if ($aliasView) { - // build view route switch - $routerSwitch = array(); - $routerSwitch[] = PHP_EOL . "\t\t\tcase '" . $view . "':"; $routerSwitch[] = "\t\t\t\t\$vars['view'] = '" . $view . "';"; $routerSwitch[] = "\t\t\t\tif (is_numeric(\$segments[\$count-1]))"; @@ -4875,14 +4894,9 @@ class Interpretation extends Fields $routerSwitch[] = "\t\t\t\t\t}"; $routerSwitch[] = "\t\t\t\t}"; $routerSwitch[] = "\t\t\t\tbreak;"; - - return implode(PHP_EOL, $routerSwitch); } elseif ($idView) { - // build view route switch - $routerSwitch = array(); - $routerSwitch[] = PHP_EOL . "\t\t\tcase '" . $view . "':"; $routerSwitch[] = "\t\t\t\t\$vars['view'] = '" . $view . "';"; $routerSwitch[] = "\t\t\t\tif (is_numeric(\$segments[\$count-1]))"; @@ -4890,21 +4904,15 @@ class Interpretation extends Fields $routerSwitch[] = "\t\t\t\t\t\$vars['id'] = (int) \$segments[\$count-1];"; $routerSwitch[] = "\t\t\t\t}"; $routerSwitch[] = "\t\t\t\tbreak;"; - - return implode(PHP_EOL, $routerSwitch); } else { - // build view route switch - $routerSwitch = array(); - $routerSwitch[] = PHP_EOL . "\t\t\tcase '" . $view . "':"; $routerSwitch[] = "\t\t\t\t\$vars['view'] = '" . $view . "';"; $routerSwitch[] = "\t\t\t\tbreak;"; - - return implode(PHP_EOL, $routerSwitch); } - return ''; + + return implode(PHP_EOL, $routerSwitch); } public function routerBuildViews(&$view) @@ -8102,11 +8110,14 @@ class Interpretation extends Fields $query .= PHP_EOL . "\t\t}"; $query .= PHP_EOL . "\t\treturn false;"; $query .= PHP_EOL . "\t}"; + + // get the header script + $header = ComponentbuilderHelper::getDynamicScripts('headers'); // add getExImPortHeaders $query .= $this->getCustomScriptBuilder('php_import_headers', 'import_' . $viewName_list, PHP_EOL . PHP_EOL, null, true, // set a default script for those with no custom script - PHP_EOL . PHP_EOL . $this->setPlaceholders(ComponentbuilderHelper::getImportScripts('headers'), $this->placeholders)); + PHP_EOL . PHP_EOL . $this->setPlaceholders($header, $this->placeholders)); } return $query; } diff --git a/admin/helpers/componentbuilder.php b/admin/helpers/componentbuilder.php index 16bdd3081..570f04164 100644 --- a/admin/helpers/componentbuilder.php +++ b/admin/helpers/componentbuilder.php @@ -158,7 +158,7 @@ abstract class ComponentbuilderHelper return $object; } - public static function getImportScripts($type, $fieldName = false) + public static function getDynamicScripts($type, $fieldName = false) { // if field name is passed the convert to type if ($fieldName) @@ -196,7 +196,7 @@ abstract class ComponentbuilderHelper $script['display'][] = "\t\tif (\$this->getLayout() !== 'modal')"; $script['display'][] = "\t\t{"; $script['display'][] = "\t\t\t// Include helper submenu"; - $script['display'][] = "\t\t\t###-#-#-Component###Helper::addSubmenu('import');"; + $script['display'][] = "\t\t\t[[[-#-#-Component]]]Helper::addSubmenu('import');"; $script['display'][] = "\t\t}"; $script['display'][] = "\n\t\t\$paths = new stdClass;"; $script['display'][] = "\t\t\$paths->first = '';"; @@ -204,7 +204,7 @@ abstract class ComponentbuilderHelper $script['display'][] = "\n\t\t\$this->paths = &\$paths;"; $script['display'][] = "\t\t\$this->state = &\$state;"; $script['display'][] = "\t\t// get global action permissions"; - $script['display'][] = "\t\t\$this->canDo = ###-#-#-Component###Helper::getActions('import');"; + $script['display'][] = "\t\t\$this->canDo = [[[-#-#-Component]]]Helper::getActions('import');"; $script['display'][] = "\n\t\t// We don't need toolbar in the modal window."; $script['display'][] = "\t\tif (\$this->getLayout() !== 'modal')"; $script['display'][] = "\t\t{"; @@ -219,7 +219,7 @@ abstract class ComponentbuilderHelper $script['display'][] = "\t\tif(\$this->hasPackage && \$this->dataType)"; $script['display'][] = "\t\t{"; $script['display'][] = "\t\t\t\$this->headerList \t= json_decode(\$session->get(\$this->dataType.'_VDM_IMPORTHEADERS', false),true);"; - $script['display'][] = "\t\t\t\$this->headers \t\t= ###-#-#-Component###Helper::getFileHeaders(\$this->dataType);"; + $script['display'][] = "\t\t\t\$this->headers \t\t= [[[-#-#-Component]]]Helper::getFileHeaders(\$this->dataType);"; $script['display'][] = "\t\t\t// clear the data type"; $script['display'][] = "\t\t\t\$session->clear('dataType');"; $script['display'][] = "\t\t}"; @@ -245,7 +245,7 @@ abstract class ComponentbuilderHelper $script['setdata'][] = "\t**/"; $script['setdata'][] = "\tprotected function setData(\$package,\$table,\$target_headers)"; $script['setdata'][] = "\t{"; - $script['setdata'][] = "\t\tif (###-#-#-Component###Helper::checkArray(\$target_headers))"; + $script['setdata'][] = "\t\tif ([[[-#-#-Component]]]Helper::checkArray(\$target_headers))"; $script['setdata'][] = "\t\t{"; $script['setdata'][] = "\t\t\t// make sure the file is loaded\t\t"; $script['setdata'][] = "\t\t\tJLoader::import('PHPExcel', JPATH_COMPONENT_ADMINISTRATOR . '/helpers');"; @@ -283,8 +283,8 @@ abstract class ComponentbuilderHelper $script['headers'][] = "\t\t// Get a db connection."; $script['headers'][] = "\t\t\$db = JFactory::getDbo();"; $script['headers'][] = "\t\t// get the columns"; - $script['headers'][] = "\t\t\$columns = \$db->getTableColumns(\"#__###-#-#-component###_###-#-#-view###\");"; - $script['headers'][] = "\t\tif (###-#-#-Component###Helper::checkArray(\$columns))"; + $script['headers'][] = "\t\t\$columns = \$db->getTableColumns(\"#__[[[-#-#-component]]]_[[[-#-#-view]]]\");"; + $script['headers'][] = "\t\tif ([[[-#-#-Component]]]Helper::checkArray(\$columns))"; $script['headers'][] = "\t\t{"; $script['headers'][] = "\t\t\t// remove the headers you don't import/export."; $script['headers'][] = "\t\t\tunset(\$columns['asset_id']);"; @@ -314,7 +314,7 @@ abstract class ComponentbuilderHelper $script['save'][] = "\tprotected function save(\$data,\$table)"; $script['save'][] = "\t{"; $script['save'][] = "\t\t// import the data if there is any"; - $script['save'][] = "\t\tif(###-#-#-Component###Helper::checkArray(\$data['array']))"; + $script['save'][] = "\t\tif([[[-#-#-Component]]]Helper::checkArray(\$data['array']))"; $script['save'][] = "\t\t{"; $script['save'][] = "\t\t\t// get user object"; $script['save'][] = "\t\t\t\$user \t\t= JFactory::getUser();"; @@ -332,7 +332,7 @@ abstract class ComponentbuilderHelper $script['save'][] = "\t\t\t}"; $script['save'][] = "\t\t\t"; $script['save'][] = "\t\t\t// make sure there is still values in array and that it was not only headers"; - $script['save'][] = "\t\t\tif(###-#-#-Component###Helper::checkArray(\$data['array']) && \$user->authorise(\$table.'.import', 'com_###-#-#-component###') && \$user->authorise('core.import', 'com_###-#-#-component###'))"; + $script['save'][] = "\t\t\tif([[[-#-#-Component]]]Helper::checkArray(\$data['array']) && \$user->authorise(\$table.'.import', 'com_[[[-#-#-component]]]') && \$user->authorise('core.import', 'com_[[[-#-#-component]]]'))"; $script['save'][] = "\t\t\t{"; $script['save'][] = "\t\t\t\t// set target."; $script['save'][] = "\t\t\t\t\$target\t= array_flip(\$data['target_headers']);"; @@ -341,7 +341,7 @@ abstract class ComponentbuilderHelper $script['save'][] = "\t\t\t\t// set some defaults"; $script['save'][] = "\t\t\t\t\$todayDate\t\t= JFactory::getDate()->toSql();"; $script['save'][] = "\t\t\t\t// get global action permissions"; - $script['save'][] = "\t\t\t\t\$canDo\t\t\t= ###-#-#-Component###Helper::getActions(\$table);"; + $script['save'][] = "\t\t\t\t\$canDo\t\t\t= [[[-#-#-Component]]]Helper::getActions(\$table);"; $script['save'][] = "\t\t\t\t\$canEdit\t\t= \$canDo->get('core.edit');"; $script['save'][] = "\t\t\t\t\$canState\t\t= \$canDo->get('core.edit.state');"; $script['save'][] = "\t\t\t\t\$canCreate\t\t= \$canDo->get('core.create');"; @@ -356,7 +356,7 @@ abstract class ComponentbuilderHelper $script['save'][] = "\t\t\t\t\t\t\$query = \$db->getQuery(true);"; $script['save'][] = "\t\t\t\t\t\t\$query"; $script['save'][] = "\t\t\t\t\t\t\t->select('version')"; - $script['save'][] = "\t\t\t\t\t\t\t->from(\$db->quoteName('#__###-#-#-component###_'.\$table))"; + $script['save'][] = "\t\t\t\t\t\t\t->from(\$db->quoteName('#__[[[-#-#-component]]]_'.\$table))"; $script['save'][] = "\t\t\t\t\t\t\t->where(\$db->quoteName('id') . ' = '. \$db->quote(\$row[\$id_key]));"; $script['save'][] = "\t\t\t\t\t\t// Reset the query using our newly populated query object."; $script['save'][] = "\t\t\t\t\t\t\$db->setQuery(\$query);"; @@ -423,7 +423,7 @@ abstract class ComponentbuilderHelper $script['save'][] = "\t\t\t\t\t\t\t\$db->quoteName('id') . ' = ' . \$id"; $script['save'][] = "\t\t\t\t\t\t);"; $script['save'][] = "\t\t\t\t\t\t"; - $script['save'][] = "\t\t\t\t\t\t\$query->update(\$db->quoteName('#__###-#-#-component###_'.\$table))->set(\$fields)->where(\$conditions);"; + $script['save'][] = "\t\t\t\t\t\t\$query->update(\$db->quoteName('#__[[[-#-#-component]]]_'.\$table))->set(\$fields)->where(\$conditions);"; $script['save'][] = "\t\t\t\t\t\t\$db->setQuery(\$query);"; $script['save'][] = "\t\t\t\t\t\t\$db->execute();"; $script['save'][] = "\t\t\t\t\t}"; @@ -499,7 +499,7 @@ abstract class ComponentbuilderHelper $script['save'][] = "\t\t\t\t\t\t}"; $script['save'][] = "\t\t\t\t\t\t// Prepare the insert query."; $script['save'][] = "\t\t\t\t\t\t\$query"; - $script['save'][] = "\t\t\t\t\t\t\t->insert(\$db->quoteName('#__###-#-#-component###_'.\$table))"; + $script['save'][] = "\t\t\t\t\t\t\t->insert(\$db->quoteName('#__[[[-#-#-component]]]_'.\$table))"; $script['save'][] = "\t\t\t\t\t\t\t->columns(\$db->quoteName(\$columns))"; $script['save'][] = "\t\t\t\t\t\t\t->values(implode(',', \$values));"; $script['save'][] = "\t\t\t\t\t\t// Set the query using our newly populated query object and execute it."; @@ -509,7 +509,7 @@ abstract class ComponentbuilderHelper $script['save'][] = "\t\t\t\t\t\t{"; $script['save'][] = "\t\t\t\t\t\t\t\$aId = \$db->insertid();"; $script['save'][] = "\t\t\t\t\t\t\t// make sure the access of asset is set"; - $script['save'][] = "\t\t\t\t\t\t\t###-#-#-Component###Helper::setAsset(\$aId,\$table);"; + $script['save'][] = "\t\t\t\t\t\t\t[[[-#-#-Component]]]Helper::setAsset(\$aId,\$table);"; $script['save'][] = "\t\t\t\t\t\t}"; $script['save'][] = "\t\t\t\t\t}"; $script['save'][] = "\t\t\t\t\telse"; @@ -527,7 +527,7 @@ abstract class ComponentbuilderHelper { $script['view'] = array(); $script['view'][] = ""; $script['view'][] = ""; $script['view'][] = "\n