public function importData() { // Check for request forgeries JSession::checkToken() or die(JText::_('JINVALID_TOKEN')); // check if import is allowed for this user. $user = JFactory::getUser(); if ($user->authorise('look.import', 'com_demo') && $user->authorise('core.import', 'com_demo')) { // Get the import model $model = $this->getModel('Looks'); // get the headers to import $headers = $model->getExImPortHeaders(); if (DemoHelper::checkObject($headers)) { // Load headers to session. $session = JFactory::getSession(); $headers = json_encode($headers); $session->set('look_VDM_IMPORTHEADERS', $headers); $session->set('backto_VDM_IMPORT', 'looks'); $session->set('dataType_VDM_IMPORTINTO', 'look'); // Redirect to import view. $message = JText::_('COM_DEMO_IMPORT_SELECT_FILE_FOR_LOOKS'); $this->setRedirect(JRoute::_('index.php?option=com_demo&view=import', false), $message); return; } } // Redirect to the list screen with error. $message = JText::_('COM_DEMO_IMPORT_FAILED'); $this->setRedirect(JRoute::_('index.php?option=com_demo&view=looks', false), $message, 'error'); return; }
protected function checkEditView($view) { if (DemoHelper::checkString($view)) { $views = array(); // check if this is a edit view if (in_array($view, $views)) { return true; } } return false; }
/** * Setting the toolbar */ protected function addToolBar() { JToolBarHelper::title(JText::_('COM_DEMO_IMPORT_TITLE'), 'upload'); JHtmlSidebar::setAction('index.php?option=com_demo&view=import'); if ($this->canDo->get('core.admin') || $this->canDo->get('core.options')) { JToolBarHelper::preferences('com_demo'); } // set help url for this view if found $help_url = DemoHelper::getHelpUrl('import'); if (DemoHelper::checkString($help_url)) { JToolbarHelper::help('COM_DEMO_HELP_MANAGER', false, $help_url); } }
protected function getViewRelation($view) { if (DemoHelper::checkString($view)) { $views = array('look' => 'looks', 'help_document' => 'help_documents'); // check if this is a list view if (in_array($view, $views)) { return array('edit' => false, 'view' => array_search($view, $views), 'views' => $view); } elseif (array_key_exists($view, $views)) { return array('edit' => true, 'view' => $view, 'views' => $views[$view]); } } return false; }
/** * Setting the toolbar */ protected function addToolBar() { $canDo = DemoHelper::getActions('demo'); JToolBarHelper::title(JText::_('COM_DEMO_DASHBOARD'), 'grid-2'); // set help url for this view if found $help_url = DemoHelper::getHelpUrl('demo'); if (DemoHelper::checkString($help_url)) { JToolbarHelper::help('COM_DEMO_HELP_MANAGER', false, $help_url); } if ($canDo->get('core.admin') || $canDo->get('core.options')) { JToolBarHelper::preferences('com_demo'); } }
?> </option> <?php foreach ($this->headers as $value => $option) { ?> <?php $selected = strtolower($option) == strtolower($title) || strtolower($option) == strtolower($name) ? 'selected="selected"' : ''; ?> <option value="<?php echo DemoHelper::htmlEscape($value); ?> " class="required" <?php echo $selected; ?> ><?php echo DemoHelper::htmlEscape($option); ?> </option> <?php } ?> </select> </div> </div> <?php } ?> <div class="form-actions"> <input class="btn btn-primary" type="button" value="<?php echo JText::_('COM_DEMO_IMPORT_CONTINUE'); ?>
/** * Method to save the form data. * * @param array $data The form data. * * @return boolean True on success. * * @since 1.6 */ public function save($data) { $input = JFactory::getApplication()->input; $filter = JFilterInput::getInstance(); // set the metadata to the Item Data if (isset($data['metadata']) && isset($data['metadata']['author'])) { $data['metadata']['author'] = $filter->clean($data['metadata']['author'], 'TRIM'); $metadata = new JRegistry(); $metadata->loadArray($data['metadata']); $data['metadata'] = (string) $metadata; } // Set the Params Items to data if (isset($data['params']) && is_array($data['params'])) { $params = new JRegistry(); $params->loadArray($data['params']); $data['params'] = (string) $params; } // Alter the name for save as copy if ($input->get('task') == 'save2copy') { $origTable = clone $this->getTable(); $origTable->load($input->getInt('id')); if ($data['name'] == $origTable->name) { list($name, $alias) = $this->_generateNewTitle($data['alias'], $data['name']); $data['name'] = $name; $data['alias'] = $alias; } else { if ($data['alias'] == $origTable->alias) { $data['alias'] = ''; } } $data['published'] = 0; } // Automatic handling of alias for empty fields if (in_array($input->get('task'), array('apply', 'save', 'save2new')) && (int) $input->get('id') == 0) { if ($data['alias'] == null) { if (JFactory::getConfig()->get('unicodeslugs') == 1) { $data['alias'] = JFilterOutput::stringURLUnicodeSlug($data['name']); } else { $data['alias'] = JFilterOutput::stringURLSafe($data['name']); } $table = JTable::getInstance('look', 'demoTable'); if ($table->load(array('alias' => $data['alias'])) && ($table->id != $data['id'] || $data['id'] == 0)) { $msg = JText::_('COM_DEMO_LOOK_SAVE_WARNING'); } list($name, $alias) = $this->_generateNewTitle($data['alias'], $data['name']); $data['alias'] = $alias; if (isset($msg)) { JFactory::getApplication()->enqueueMessage($msg, 'warning'); } } } // Alter the uniqe field for save as copy if ($input->get('task') == 'save2copy') { // Automatic handling of other uniqe fields $uniqeFields = $this->getUniqeFields(); if (DemoHelper::checkArray($uniqeFields)) { foreach ($uniqeFields as $uniqeField) { $data[$uniqeField] = $this->generateUniqe($uniqeField, $data[$uniqeField]); } } } if (parent::save($data)) { return true; } return false; }
/** * Save the data from the file to the database * * @param string $package Paths to the uploaded package file * * @return boolean false on failure * **/ protected function save($data, $table) { // import the data if there is any if (DemoHelper::checkArray($data['array'])) { // get user object $user = JFactory::getUser(); // remove header if it has headers $id_key = $data['target_headers']['id']; $published_key = $data['target_headers']['published']; $ordering_key = $data['target_headers']['ordering']; // get the first array set $firstSet = reset($data['array']); // check if first array is a header array and remove if true if ($firstSet[$id_key] == 'id' || $firstSet[$published_key] == 'published' || $firstSet[$ordering_key] == 'ordering') { array_shift($data['array']); } // make sure there is still values in array and that it was not only headers if (DemoHelper::checkArray($data['array']) && $user->authorise($table . '.import', 'com_demo') && $user->authorise('core.import', 'com_demo')) { // set target. $target = array_flip($data['target_headers']); // Get a db connection. $db = JFactory::getDbo(); // set some defaults $todayDate = JFactory::getDate()->toSql(); // get global action permissions $canDo = DemoHelper::getActions($table); $canEdit = $canDo->get('core.edit'); $canState = $canDo->get('core.edit.state'); $canCreate = $canDo->get('core.create'); $hasAlias = $this->getAliasesUsed($table); // prosses the data foreach ($data['array'] as $row) { $found = false; if (isset($row[$id_key]) && is_numeric($row[$id_key]) && $row[$id_key] > 0) { // raw items import & update! $query = $db->getQuery(true); $query->select('version')->from($db->quoteName('#__demo_' . $table))->where($db->quoteName('id') . ' = ' . $db->quote($row[$id_key])); // Reset the query using our newly populated query object. $db->setQuery($query); $db->execute(); $found = $db->getNumRows(); } if ($found && $canEdit) { // update item $id = $row[$id_key]; $version = $db->loadResult(); // reset all buckets $query = $db->getQuery(true); $fields = array(); // Fields to update. foreach ($row as $key => $cell) { // ignore column if ('IGNORE' == $target[$key]) { continue; } // update modified if ('modified_by' == $target[$key]) { continue; } // update modified if ('modified' == $target[$key]) { continue; } // update version if ('version' == $target[$key]) { $cell = (int) $version + 1; } // verify publish authority if ('published' == $target[$key] && !$canState) { continue; } // set to update array if (in_array($key, $data['target_headers']) && is_numeric($cell)) { $fields[] = $db->quoteName($target[$key]) . ' = ' . $cell; } elseif (in_array($key, $data['target_headers']) && is_string($cell)) { $fields[] = $db->quoteName($target[$key]) . ' = ' . $db->quote($cell); } elseif (in_array($key, $data['target_headers']) && is_null($cell)) { // if import data is null then set empty $fields[] = $db->quoteName($target[$key]) . " = ''"; } } // load the defaults $fields[] = $db->quoteName('modified_by') . ' = ' . $db->quote($user->id); $fields[] = $db->quoteName('modified') . ' = ' . $db->quote($todayDate); // Conditions for which records should be updated. $conditions = array($db->quoteName('id') . ' = ' . $id); $query->update($db->quoteName('#__demo_' . $table))->set($fields)->where($conditions); $db->setQuery($query); $db->execute(); } elseif ($canCreate) { // insert item $query = $db->getQuery(true); // reset all buckets $columns = array(); $values = array(); $version = false; // Insert columns. Insert values. foreach ($row as $key => $cell) { // ignore column if ('IGNORE' == $target[$key]) { continue; } // remove id if ('id' == $target[$key]) { continue; } // update created if ('created_by' == $target[$key]) { continue; } // update created if ('created' == $target[$key]) { continue; } // Make sure the alias is incremented if ('alias' == $target[$key]) { $cell = $this->getAlias($cell, $table); } // update version if ('version' == $target[$key]) { $cell = 1; $version = true; } // set to insert array if (in_array($key, $data['target_headers']) && is_numeric($cell)) { $columns[] = $target[$key]; $values[] = $cell; } elseif (in_array($key, $data['target_headers']) && is_string($cell)) { $columns[] = $target[$key]; $values[] = $db->quote($cell); } elseif (in_array($key, $data['target_headers']) && is_null($cell)) { // if import data is null then set empty $columns[] = $target[$key]; $values[] = "''"; } } // load the defaults $columns[] = 'created_by'; $values[] = $db->quote($user->id); $columns[] = 'created'; $values[] = $db->quote($todayDate); if (!$version) { $columns[] = 'version'; $values[] = 1; } // Prepare the insert query. $query->insert($db->quoteName('#__demo_' . $table))->columns($db->quoteName($columns))->values(implode(',', $values)); // Set the query using our newly populated query object and execute it. $db->setQuery($query); $done = $db->execute(); if ($done) { $aId = $db->insertid(); // make sure the access of asset is set DemoHelper::setAsset($aId, $table); } } else { return false; } } return true; } } return false; }
@license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html ____ _____ _____ __ __ __ __ ___ _____ __ __ ____ _____ _ _ ____ _ _ ____ (_ _)( _ )( _ )( \/ )( ) /__\ / __)( _ )( \/ )( _ \( _ )( \( )( ___)( \( )(_ _) .-_)( )(_)( )(_)( ) ( )(__ /(__)\ ( (__ )(_)( ) ( )___/ )(_)( ) ( )__) ) ( )( \____) (_____)(_____)(_/\/\_)(____)(__)(__) \___)(_____)(_/\/\_)(__) (_____)(_)\_)(____)(_)\_) (__) /------------------------------------------------------------------------------------------------------*/ // No direct access to this file defined('_JEXEC') or die('Restricted access'); $edit = "index.php?option=com_demo&view=help_documents&task=help_document.edit"; foreach ($this->items as $i => $item) { ?> <?php $canCheckin = $this->user->authorise('core.manage', 'com_checkin') || $item->checked_out == $this->user->id || $item->checked_out == 0; $userChkOut = JFactory::getUser($item->checked_out); $canDo = DemoHelper::getActions('help_document', $item, 'help_documents'); ?> <tr class="row<?php echo $i % 2; ?> "> <td class="order nowrap center hidden-phone"> <?php if ($canDo->get('help_document.edit.state')) { ?> <?php if ($this->saveOrder) { $iconClass = ' inactive'; } else { $iconClass = ' inactive tip-top" hasTooltip" title="' . JHtml::tooltipText('JORDERINGDISABLED'); }
/** * Escapes a value for output in a view script. * * @param mixed $var The output to escape. * * @return mixed The escaped value. */ public function escape($var) { if (strlen($var) > 30) { // use the helper htmlEscape method instead and shorten the string return DemoHelper::htmlEscape($var, $this->_charset, true, 30); } // use the helper htmlEscape method instead. return DemoHelper::htmlEscape($var, $this->_charset); }
@license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html ____ _____ _____ __ __ __ __ ___ _____ __ __ ____ _____ _ _ ____ _ _ ____ (_ _)( _ )( _ )( \/ )( ) /__\ / __)( _ )( \/ )( _ \( _ )( \( )( ___)( \( )(_ _) .-_)( )(_)( )(_)( ) ( )(__ /(__)\ ( (__ )(_)( ) ( )___/ )(_)( ) ( )__) ) ( )( \____) (_____)(_____)(_/\/\_)(____)(__)(__) \___)(_____)(_/\/\_)(__) (_____)(_)\_)(____)(_)\_) (__) /------------------------------------------------------------------------------------------------------*/ // No direct access to this file defined('_JEXEC') or die('Restricted access'); $edit = "index.php?option=com_demo&view=looks&task=look.edit"; foreach ($this->items as $i => $item) { ?> <?php $canCheckin = $this->user->authorise('core.manage', 'com_checkin') || $item->checked_out == $this->user->id || $item->checked_out == 0; $userChkOut = JFactory::getUser($item->checked_out); $canDo = DemoHelper::getActions('look', $item, 'looks'); ?> <tr class="row<?php echo $i % 2; ?> "> <td class="order nowrap center hidden-phone"> <?php if ($canDo->get('look.edit.state')) { ?> <?php if ($this->saveOrder) { $iconClass = ' inactive'; } else { $iconClass = ' inactive tip-top" hasTooltip" title="' . JHtml::tooltipText('JORDERINGDISABLED'); }
</a></li> <li><b><?php echo JText::_('COM_DEMO_LICENSE'); ?> :</b> <?php echo $manifest->license; ?> </li> <li><b><?php echo $manifest->copyright; ?> </b></li> </ul> <div class="clearfix"></div> <?php if (DemoHelper::checkArray($this->contributors)) { if (count($this->contributors) > 1) { ?> <h3><?php echo JText::_('COM_DEMO_CONTRIBUTORS'); ?> </h3> <?php } else { ?> <h3><?php echo JText::_('COM_DEMO_CONTRIBUTOR'); ?> </h3> <?php }
/** * Method to get header. * * @return mixed An array of data items on success, false on failure. */ public function getExImPortHeaders() { // Get a db connection. $db = JFactory::getDbo(); // get the columns $columns = $db->getTableColumns("#__demo_help_document"); if (DemoHelper::checkArray($columns)) { // remove the headers you don't import/export. unset($columns['asset_id']); unset($columns['checked_out']); unset($columns['checked_out_time']); $headers = new stdClass(); foreach ($columns as $column => $type) { $headers->{$column} = $column; } return $headers; } return false; }
public function getIcons() { // load user for access menus $user = JFactory::getUser(); // reset icon array $icons = array(); // view groups array $viewGroups = array('main' => array('png.look.add', 'png.looks', 'png.help_documents')); // view access array $viewAccess = array('look.create' => 'look.create', 'looks.access' => 'look.access', 'look.access' => 'look.access', 'looks.submenu' => 'look.submenu', 'looks.dashboard_list' => 'look.dashboard_list', 'look.dashboard_add' => 'look.dashboard_add', 'help_document.create' => 'help_document.create', 'help_documents.access' => 'help_document.access', 'help_document.access' => 'help_document.access', 'help_documents.submenu' => 'help_document.submenu', 'help_documents.dashboard_list' => 'help_document.dashboard_list'); foreach ($viewGroups as $group => $views) { $i = 0; if (DemoHelper::checkArray($views)) { foreach ($views as $view) { $add = false; if (strpos($view, '.') !== false) { $dwd = explode('.', $view); if (count($dwd) == 3) { list($type, $name, $action) = $dwd; } elseif (count($dwd) == 2) { list($type, $name) = $dwd; $action = false; } if ($action) { $viewName = $name; switch ($action) { case 'add': $url = 'index.php?option=com_demo&view=' . $name . '&layout=edit'; $image = $name . '_' . $action . '.' . $type; $alt = $name . ' ' . $action; $name = 'COM_DEMO_DASHBOARD_' . DemoHelper::safeString($name, 'U') . '_ADD'; $add = true; break; default: $url = 'index.php?option=com_categories&view=categories&extension=com_demo.' . $name; $image = $name . '_' . $action . '.' . $type; $alt = $name . ' ' . $action; $name = 'COM_DEMO_DASHBOARD_' . DemoHelper::safeString($name, 'U') . '_' . DemoHelper::safeString($action, 'U'); break; } } else { $viewName = $name; $alt = $name; $url = 'index.php?option=com_demo&view=' . $name; $image = $name . '.' . $type; $name = 'COM_DEMO_DASHBOARD_' . DemoHelper::safeString($name, 'U'); $hover = false; } } else { $viewName = $view; $alt = $view; $url = 'index.php?option=com_demo&view=' . $view; $image = $view . '.png'; $name = ucwords($view) . '<br /><br />'; $hover = false; } // first make sure the view access is set if (DemoHelper::checkArray($viewAccess)) { // setup some defaults $dashboard_add = false; $dashboard_list = false; $accessTo = ''; $accessAdd = ''; // acces checking start $accessCreate = isset($viewAccess[$viewName . '.create']) ? DemoHelper::checkString($viewAccess[$viewName . '.create']) : false; $accessAccess = isset($viewAccess[$viewName . '.access']) ? DemoHelper::checkString($viewAccess[$viewName . '.access']) : false; // set main controllers $accessDashboard_add = isset($viewAccess[$viewName . '.dashboard_add']) ? DemoHelper::checkString($viewAccess[$viewName . '.dashboard_add']) : false; $accessDashboard_list = isset($viewAccess[$viewName . '.dashboard_list']) ? DemoHelper::checkString($viewAccess[$viewName . '.dashboard_list']) : false; // check for adding access if ($add && $accessCreate) { $accessAdd = $viewAccess[$viewName . '.create']; } elseif ($add) { $accessAdd = 'core.create'; } // check if acces to view is set if ($accessAccess) { $accessTo = $viewAccess[$viewName . '.access']; } // set main access controllers if ($accessDashboard_add) { $dashboard_add = $user->authorise($viewAccess[$viewName . '.dashboard_add'], 'com_demo'); } if ($accessDashboard_list) { $dashboard_list = $user->authorise($viewAccess[$viewName . '.dashboard_list'], 'com_demo'); } if (DemoHelper::checkString($accessAdd) && DemoHelper::checkString($accessTo)) { // check access if ($user->authorise($accessAdd, 'com_demo') && $user->authorise($accessTo, 'com_demo') && $dashboard_add) { $icons[$group][$i] = new StdClass(); $icons[$group][$i]->url = $url; $icons[$group][$i]->name = $name; $icons[$group][$i]->image = $image; $icons[$group][$i]->alt = $alt; } } elseif (DemoHelper::checkString($accessTo)) { // check access if ($user->authorise($accessTo, 'com_demo') && $dashboard_list) { $icons[$group][$i] = new StdClass(); $icons[$group][$i]->url = $url; $icons[$group][$i]->name = $name; $icons[$group][$i]->image = $image; $icons[$group][$i]->alt = $alt; } } elseif (DemoHelper::checkString($accessAdd)) { // check access if ($user->authorise($accessAdd, 'com_demo') && $dashboard_add) { $icons[$group][$i] = new StdClass(); $icons[$group][$i]->url = $url; $icons[$group][$i]->name = $name; $icons[$group][$i]->image = $image; $icons[$group][$i]->alt = $alt; } } else { $icons[$group][$i] = new StdClass(); $icons[$group][$i]->url = $url; $icons[$group][$i]->name = $name; $icons[$group][$i]->image = $image; $icons[$group][$i]->alt = $alt; } } else { $icons[$group][$i] = new StdClass(); $icons[$group][$i]->url = $url; $icons[$group][$i]->name = $name; $icons[$group][$i]->image = $image; $icons[$group][$i]->alt = $alt; } $i++; } } else { $icons[$group][$i] = false; } } return $icons; }