Added sharing of snippets option and started adding get snippets custom admin view gh-92. Fixed gh-153 published settings for categories.

This commit is contained in:
2017-11-16 06:37:32 +02:00
parent 1cc40dbfe4
commit f34e1b19f8
37 changed files with 1372 additions and 124 deletions

View File

@ -1711,20 +1711,22 @@ class ComponentbuilderModelAjax extends JModelList
// Create a new query object.
$query = $db->getQuery(true);
$query->select($db->quoteName(array('name', 'heading', 'usage', 'description', 'type', 'snippet', 'url')));
$query->from($db->quoteName('#__componentbuilder_snippet'));
$query->where($db->quoteName('published') . ' = 1');
$query->where($db->quoteName('id') . ' = '. (int) $id);
$query->select($db->quoteName(array('a.name', 'a.heading', 'a.usage', 'a.description', 'b.name', 'a.snippet', 'a.url', 'c.name'), array('name', 'heading', 'usage', 'description', 'type', 'snippet', 'url', 'library')));
$query->from($db->quoteName('#__componentbuilder_snippet', 'a'));
// From the componentbuilder_snippet_type table.
$query->join('LEFT', $db->quoteName('#__componentbuilder_snippet_type', 'b') . ' ON (' . $db->quoteName('a.type') . ' = ' . $db->quoteName('b.id') . ')');
// From the componentbuilder_library table.
$query->join('LEFT', $db->quoteName('#__componentbuilder_library', 'c') . ' ON (' . $db->quoteName('a.library') . ' = ' . $db->quoteName('c.id') . ')');
$query->where($db->quoteName('a.published') . ' >= 1');
$query->where($db->quoteName('a.id') . ' = '. (int) $id);
// Reset the query using our newly populated query object.
$db->setQuery($query);
$db->execute();
if ($db->getNumRows())
{
$model = ComponentbuilderHelper::getModel('snippets');
$snippet = $db->loadObject();
$snippet->type = JText::_($model->selectionTranslation($snippet->type,'type'));
$snippet->snippet = base64_decode($snippet->snippet);
$snippet->snippet = base64_decode($snippet->snippet);
// return found snippet settings
return $snippet;
}

View File

@ -151,21 +151,25 @@ class JFormFieldSnippets extends JFormFieldList
{
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select($db->quoteName(array('a.id','a.name','a.type'),array('id','snippet_name','type')));
$query->from($db->quoteName('#__componentbuilder_snippet', 'a'));
$query->where($db->quoteName('a.published') . ' = 1');
$query->order('a.name ASC');
$query->select($db->quoteName(array('a.id','a.name','b.name','c.name'),array('id','snippet_name','type','library')));
$query->from($db->quoteName('#__componentbuilder_snippet', 'a'));
// From the componentbuilder_snippet_type table.
$query->join('LEFT', $db->quoteName('#__componentbuilder_snippet_type', 'b') . ' ON (' . $db->quoteName('a.type') . ' = ' . $db->quoteName('b.id') . ')');
// From the componentbuilder_library table.
$query->join('LEFT', $db->quoteName('#__componentbuilder_library', 'c') . ' ON (' . $db->quoteName('a.library') . ' = ' . $db->quoteName('c.id') . ')');
$query->where($db->quoteName('a.published') . ' >= 1');
$query->order('c.ordering ASC');
$query->order('b.name ASC');
$db->setQuery((string)$query);
$items = $db->loadObjectList();
$options = array();
if ($items)
{
$options[] = JHtml::_('select.option', '', 'Select an option');
$model = ComponentbuilderHelper::getModel('snippets');
foreach($items as $item)
{
$type = $model->selectionTranslation($item->type,'type');
$options[] = JHtml::_('select.option', $item->id, $item->snippet_name . ' (' . JText::_($type) . ')' );
$lib = (ComponentbuilderHelper::checkString($item->library)) ? ' (' . $item->library . ')' :'';
$options[] = JHtml::_('select.option', $item->id, $item->type . ' - ' . $item->snippet_name . $lib );
}
}
return $options;

View File

@ -385,11 +385,14 @@ function getSnippetDetails(id){
getSnippetDetails_server(id).done(function(result) {
if(result.snippet){
var description = '';
if (result.description.length > 0)
{
if (result.description.length > 0) {
description = '<p>'+result.description+'</p>';
}
var code = '<div id="snippet-code"><b>'+result.name+' ('+result.type+')</b> <a href="'+result.url+'" target="_blank" >see more details</a><br /><em>'+result.heading+'</em><br /><textarea id="snippet" class="span12" rows="11">'+result.snippet+'</textarea></div>';
var library = '';
if (result.library.length > 0) {
library = ' <b>('+result.library+')</b>';
}
var code = '<div id="snippet-code"><b>'+result.name+' ('+result.type+')</b> <a href="'+result.url+'" target="_blank" >see more details'+library+'</a><br /><em>'+result.heading+'</em><br /><textarea id="snippet" class="span12" rows="11">'+result.snippet+'</textarea></div>';
jQuery('#snippet-code').remove();
jQuery('.snippet-code').append(code);
// make sure the code block is active

View File

@ -739,13 +739,13 @@
default="0">
<!-- Option Set. -->
<option value="0">
COM_COMPONENTBUILDER_JOOMLA_COMPONENT_NO</option>
COM_COMPONENTBUILDER_JOOMLA_COMPONENT_DO_NOT_ADD</option>
<option value="2">
COM_COMPONENTBUILDER_JOOMLA_COMPONENT_BOTH</option>
COM_COMPONENTBUILDER_JOOMLA_COMPONENT_ADD_BOTH_VTWO_AMP_VTHREE</option>
<option value="1">
COM_COMPONENTBUILDER_JOOMLA_COMPONENT_VTWO</option>
COM_COMPONENTBUILDER_JOOMLA_COMPONENT_ADD_UIKIT_VTWO</option>
<option value="3">
COM_COMPONENTBUILDER_JOOMLA_COMPONENT_VTHREE</option>
COM_COMPONENTBUILDER_JOOMLA_COMPONENT_ADD_UIKIT_VTHREE</option>
</field>
<!-- Note_mysql_tweak_options Field. Type: Note. A None Database Field. (joomla) -->
<field type="note" name="note_mysql_tweak_options" label="COM_COMPONENTBUILDER_JOOMLA_COMPONENT_NOTE_MYSQL_TWEAK_OPTIONS_LABEL" description="COM_COMPONENTBUILDER_JOOMLA_COMPONENT_NOTE_MYSQL_TWEAK_OPTIONS_DESCRIPTION" heading="h4" class="alert alert-info note_mysql_tweak_options" />

View File

@ -118,11 +118,14 @@ function getSnippetDetails(id){
getSnippetDetails_server(id).done(function(result) {
if(result.snippet){
var description = '';
if (result.description.length > 0)
{
if (result.description.length > 0) {
description = '<p>'+result.description+'</p>';
}
var code = '<div id="snippet-code"><b>'+result.name+' ('+result.type+')</b> <a href="'+result.url+'" target="_blank" >see more details</a><br /><em>'+result.heading+'</em><br /><textarea id="snippet" class="span12" rows="11">'+result.snippet+'</textarea></div>';
var library = '';
if (result.library.length > 0) {
library = ' <b>('+result.library+')</b>';
}
var code = '<div id="snippet-code"><b>'+result.name+' ('+result.type+')</b> <a href="'+result.url+'" target="_blank" >see more details'+library+'</a><br /><em>'+result.heading+'</em><br /><textarea id="snippet" class="span12" rows="11">'+result.snippet+'</textarea></div>';
jQuery('#snippet-code').remove();
jQuery('.snippet-code').append(code);
// make sure the code block is active

View File

@ -463,11 +463,14 @@ function getSnippetDetails(id){
getSnippetDetails_server(id).done(function(result) {
if(result.snippet){
var description = '';
if (result.description.length > 0)
{
if (result.description.length > 0) {
description = '<p>'+result.description+'</p>';
}
var code = '<div id="snippet-code"><b>'+result.name+' ('+result.type+')</b> <a href="'+result.url+'" target="_blank" >see more details</a><br /><em>'+result.heading+'</em><br /><textarea id="snippet" class="span12" rows="11">'+result.snippet+'</textarea></div>';
var library = '';
if (result.library.length > 0) {
library = ' <b>('+result.library+')</b>';
}
var code = '<div id="snippet-code"><b>'+result.name+' ('+result.type+')</b> <a href="'+result.url+'" target="_blank" >see more details'+library+'</a><br /><em>'+result.heading+'</em><br /><textarea id="snippet" class="span12" rows="11">'+result.snippet+'</textarea></div>';
jQuery('#snippet-code').remove();
jQuery('.snippet-code').append(code);
// make sure the code block is active

View File

@ -118,11 +118,14 @@ function getSnippetDetails(id){
getSnippetDetails_server(id).done(function(result) {
if(result.snippet){
var description = '';
if (result.description.length > 0)
{
if (result.description.length > 0) {
description = '<p>'+result.description+'</p>';
}
var code = '<div id="snippet-code"><b>'+result.name+' ('+result.type+')</b> <a href="'+result.url+'" target="_blank" >see more details</a><br /><em>'+result.heading+'</em><br /><textarea id="snippet" class="span12" rows="11">'+result.snippet+'</textarea></div>';
var library = '';
if (result.library.length > 0) {
library = ' <b>('+result.library+')</b>';
}
var code = '<div id="snippet-code"><b>'+result.name+' ('+result.type+')</b> <a href="'+result.url+'" target="_blank" >see more details'+library+'</a><br /><em>'+result.heading+'</em><br /><textarea id="snippet" class="span12" rows="11">'+result.snippet+'</textarea></div>';
jQuery('#snippet-code').remove();
jQuery('.snippet-code').append(code);
// make sure the code block is active

View File

@ -0,0 +1,150 @@
<?php
/*--------------------------------------------------------------------------------------------------------| www.vdm.io |------/
__ __ _ _____ _ _ __ __ _ _ _
\ \ / / | | | __ \ | | | | | \/ | | | | | | |
\ \ / /_ _ ___| |_ | | | | _____ _____| | ___ _ __ _ __ ___ ___ _ __ | |_ | \ / | ___| |_| |__ ___ __| |
\ \/ / _` / __| __| | | | |/ _ \ \ / / _ \ |/ _ \| '_ \| '_ ` _ \ / _ \ '_ \| __| | |\/| |/ _ \ __| '_ \ / _ \ / _` |
\ / (_| \__ \ |_ | |__| | __/\ V / __/ | (_) | |_) | | | | | | __/ | | | |_ | | | | __/ |_| | | | (_) | (_| |
\/ \__,_|___/\__| |_____/ \___| \_/ \___|_|\___/| .__/|_| |_| |_|\___|_| |_|\__| |_| |_|\___|\__|_| |_|\___/ \__,_|
| |
|_|
/-------------------------------------------------------------------------------------------------------------------------------/
@version 2.6.x
@created 30th April, 2015
@package Component Builder
@subpackage get_snippets.php
@author Llewellyn van der Merwe <http://vdm.bz/component-builder>
@github Joomla Component Builder <https://github.com/vdm-io/Joomla-Component-Builder>
@copyright Copyright (C) 2015. All Rights Reserved
@license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html
Builds Complex Joomla Components
/-----------------------------------------------------------------------------------------------------------------------------*/
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import the Joomla modellist library
jimport('joomla.application.component.modellist');
/**
* Componentbuilder Model for Get_snippets
*/
class ComponentbuilderModelGet_snippets extends JModelList
{
/**
* Model user data.
*
* @var strings
*/
protected $user;
protected $userId;
protected $guest;
protected $groups;
protected $levels;
protected $app;
protected $input;
protected $uikitComp;
/**
* Method to build an SQL query to load the list data.
*
* @return string An SQL query
*/
protected function getListQuery()
{
// Get the current user for authorisation checks
$this->user = JFactory::getUser();
$this->userId = $this->user->get('id');
$this->guest = $this->user->get('guest');
$this->groups = $this->user->get('groups');
$this->authorisedGroups = $this->user->getAuthorisedGroups();
$this->levels = $this->user->getAuthorisedViewLevels();
$this->app = JFactory::getApplication();
$this->input = $this->app->input;
$this->initSet = true;
// Make sure all records load, since no pagination allowed.
$this->setState('list.limit', 0);
// Get a db connection.
$db = JFactory::getDbo();
// Create a new query object.
$query = $db->getQuery(true);
// Get from #__componentbuilder_snippet as a
$query->select($db->quoteName(
array('a.id','a.heading','a.name','a.url','a.created','a.modified'),
array('id','heading','name','url','created','modified')));
$query->from($db->quoteName('#__componentbuilder_snippet', 'a'));
// Get from #__componentbuilder_snippet_type as b
$query->select($db->quoteName(
array('b.name'),
array('type')));
$query->join('LEFT', ($db->quoteName('#__componentbuilder_snippet_type', 'b')) . ' ON (' . $db->quoteName('a.type') . ' = ' . $db->quoteName('b.id') . ')');
// Get from #__componentbuilder_library as c
$query->select($db->quoteName(
array('c.name'),
array('library')));
$query->join('LEFT', ($db->quoteName('#__componentbuilder_library', 'c')) . ' ON (' . $db->quoteName('a.library') . ' = ' . $db->quoteName('c.id') . ')');
// return the query object
return $query;
}
/**
* Method to get an array of data items.
*
* @return mixed An array of data items on success, false on failure.
*/
public function getItems()
{
$user = JFactory::getUser();
// check if this user has permission to access items
if (!$user->authorise('get_snippets.access', 'com_componentbuilder'))
{
$app = JFactory::getApplication();
$app->enqueueMessage(JText::_('Not authorised!'), 'error');
// redirect away if not a correct (TODO for now we go to default view)
$app->redirect('index.php?option=com_componentbuilder');
return false;
}
// load parent items
$items = parent::getItems();
// Get the global params
$globalParams = JComponentHelper::getParams('com_componentbuilder', true);
// Convert the parameter fields into objects.
if (ComponentbuilderHelper::checkArray($items))
{
foreach ($items as $nr => &$item)
{
// Always create a slug for sef URL's
$item->slug = (isset($item->alias) && isset($item->id)) ? $item->id.':'.$item->alias : $item->id;
}
}
// return items
return $items;
}
/**
* Get the uikit needed components
*
* @return mixed An array of objects on success.
*
*/
public function getUikitComp()
{
if (isset($this->uikitComp) && ComponentbuilderHelper::checkArray($this->uikitComp))
{
return $this->uikitComp;
}
return false;
}
}

View File

@ -53,6 +53,120 @@ class ComponentbuilderModelSnippets extends JModelList
}
parent::__construct($config);
}
public $user;
/**
* Method to build the export package
*
* @return bool on success.
*/
public function shareSnippets($pks)
{
// setup the query
if (ComponentbuilderHelper::checkArray($pks))
{
// Get the user object.
if (!ComponentbuilderHelper::checkObject($this->user))
{
$this->user = JFactory::getUser();
}
// Create a new query object.
if (!ComponentbuilderHelper::checkObject($this->_db))
{
$this->_db = JFactory::getDBO();
}
$query = $this->_db->getQuery(true);
// Select some fields
$query->select($this->_db->quoteName(
array('a.name','a.heading','a.description','a.usage','a.snippet','a.url','b.name','c.name','a.created','a.modified'),
array('name','heading','description','usage','snippet','url','type','library','created','modified')
));
// From the componentbuilder_snippet table
$query->from($this->_db->quoteName('#__componentbuilder_snippet', 'a'));
// From the componentbuilder_snippet_type table.
$query->join('LEFT', $this->_db->quoteName('#__componentbuilder_snippet_type', 'b') . ' ON (' . $this->_db->quoteName('a.type') . ' = ' . $this->_db->quoteName('b.id') . ')');
// From the componentbuilder_library table.
$query->join('LEFT', $this->_db->quoteName('#__componentbuilder_library', 'c') . ' ON (' . $this->_db->quoteName('a.library') . ' = ' . $this->_db->quoteName('c.id') . ')');
$query->where('a.id IN (' . implode(',',$pks) . ')');
// Implement View Level Access
if (!$this->user->authorise('core.options', 'com_componentbuilder'))
{
$groups = implode(',', $this->user->getAuthorisedViewLevels());
$query->where('a.access IN (' . $groups . ')');
}
// Order the results by ordering
$query->order('a.ordering ASC');
// Load the items
$this->_db->setQuery($query);
$this->_db->execute();
if ($this->_db->getNumRows())
{
// load the items from db
$items = $this->_db->loadObjectList();
// check if we have items
if (ComponentbuilderHelper::checkArray($items))
{
// get the shared paths
$this->fullPath = rtrim(ComponentbuilderHelper::getFolderPath('path', 'sharepath', JFactory::getConfig()->get('tmp_path')), '/') . '/snippets';
// remove old folder with the same name
if (JFolder::exists($this->fullPath))
{
// remove if old folder is found
ComponentbuilderHelper::removeFolder($this->fullPath);
}
// create the full path
JFolder::create($this->fullPath);
// set zip path
$this->zipPath = $this->fullPath .'.zip';
// remove old zip files with the same name
if (JFile::exists($this->zipPath))
{
// remove file if found
JFile::delete($this->zipPath);
}
// set params
$this->params = JComponentHelper::getParams('com_componentbuilder');
// Set the person sharing information (default VDM ;)
$info = array();
$info['company'] = $this->params->get('export_company', 'Vast Development Method');
$info['owner'] = $this->params->get('export_owner', 'Llewellyn van der Merwe');
$info['email'] = $this->params->get('export_email', 'joomla@vdm.io');
$info['website'] = $this->params->get('export_website', 'https://www.vdm.io/');
// prep the item
foreach($items as $item)
{
// just unlock the snippet
$item->snippet = base64_decode($item->snippet);
// load the company detail to each snippet
$item->contributor_company = $info['company'];
$item->contributor_name = $info['owner'];
$item->contributor_email = $info['email'];
$item->contributor_website = $info['website'];
// now store the snippet info
ComponentbuilderHelper::writeFile($this->fullPath . '/' .ComponentbuilderHelper::safeString($item->library . ' - (' . $item->type . ') ' . $item->name, 'filename', '', false). '.json', json_encode($item, JSON_PRETTY_PRINT));
}
// zip the folder
if (!ComponentbuilderHelper::zip($this->fullPath, $this->zipPath))
{
return false;
}
// remove the folder
if (!ComponentbuilderHelper::removeFolder($this->fullPath))
{
return false;
}
return true;
}
}
}
return false;
}
/**