Update release_checking.php
This commit is contained in:
parent
318a87154c
commit
5e8cf2655f
|
@ -1,4 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* @package Joomla.CMS
|
* @package Joomla.CMS
|
||||||
* @subpackage com_release_checking
|
* @subpackage com_release_checking
|
||||||
|
@ -13,9 +13,9 @@ defined('_JEXEC') or die('Restricted access');
|
||||||
use Joomla\CMS\Language\Language;
|
use Joomla\CMS\Language\Language;
|
||||||
use Joomla\Registry\Registry;
|
use Joomla\Registry\Registry;
|
||||||
use Joomla\String\StringHelper;
|
use Joomla\String\StringHelper;
|
||||||
use Joomla\Utilities\ArrayHelper;
|
use Joomla\Utilities\ArrayHelper;
|
||||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -120,14 +120,14 @@ abstract class Release_checkingHelper
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $contributors;
|
return $contributors;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Can be used to build help urls.
|
* Can be used to build help urls.
|
||||||
**/
|
**/
|
||||||
public static function getHelpUrl($view)
|
public static function getHelpUrl($view)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -138,234 +138,234 @@ abstract class Release_checkingHelper
|
||||||
// load user for access menus
|
// load user for access menus
|
||||||
$user = JFactory::getUser();
|
$user = JFactory::getUser();
|
||||||
// load the submenus to sidebar
|
// load the submenus to sidebar
|
||||||
|
|
||||||
if ($user->authorise('release_check.access', 'com_release_checking') && $user->authorise('release_check.submenu', 'com_release_checking'))
|
if ($user->authorise('release_check.access', 'com_release_checking') && $user->authorise('release_check.submenu', 'com_release_checking'))
|
||||||
{
|
{
|
||||||
JHtmlSidebar::addEntry(JText::_('COM_RELEASE_CHECKING_SUBMENU_RELEASE_CHECKS'), 'index.php?option=com_release_checking&view=release_checks', $submenu === 'release_checks');
|
JHtmlSidebar::addEntry(JText::_('COM_RELEASE_CHECKING_SUBMENU_RELEASE_CHECKS'), 'index.php?option=com_release_checking&view=release_checks', $submenu === 'release_checks');
|
||||||
}
|
|
||||||
if ($user->authorise('joomla_version.access', 'com_release_checking') && $user->authorise('joomla_version.submenu', 'com_release_checking'))
|
|
||||||
{
|
|
||||||
JHtmlSidebar::addEntry(JText::_('COM_RELEASE_CHECKING_SUBMENU_JOOMLA_VERSIONS'), 'index.php?option=com_release_checking&view=joomla_versions', $submenu === 'joomla_versions');
|
|
||||||
}
|
}
|
||||||
}
|
if ($user->authorise('joomla_version.access', 'com_release_checking') && $user->authorise('joomla_version.submenu', 'com_release_checking'))
|
||||||
|
{
|
||||||
/**
|
JHtmlSidebar::addEntry(JText::_('COM_RELEASE_CHECKING_SUBMENU_JOOMLA_VERSIONS'), 'index.php?option=com_release_checking&view=joomla_versions', $submenu === 'joomla_versions');
|
||||||
* Prepares the xml document
|
}
|
||||||
*/
|
}
|
||||||
public static function xls($rows, $fileName = null, $title = null, $subjectTab = null, $creator = 'Joomla Component Builder', $description = null, $category = null,$keywords = null, $modified = null)
|
|
||||||
{
|
/**
|
||||||
// set the user
|
* Prepares the xml document
|
||||||
$user = JFactory::getUser();
|
*/
|
||||||
// set fileName if not set
|
public static function xls($rows, $fileName = null, $title = null, $subjectTab = null, $creator = 'Joomla com_release_checking', $description = null, $category = null,$keywords = null, $modified = null)
|
||||||
if (!$fileName)
|
{
|
||||||
{
|
// set the user
|
||||||
$fileName = 'exported_'.JFactory::getDate()->format('jS_F_Y');
|
$user = JFactory::getUser();
|
||||||
}
|
// set fileName if not set
|
||||||
// set modified if not set
|
if (!$fileName)
|
||||||
if (!$modified)
|
{
|
||||||
{
|
$fileName = 'exported_'.JFactory::getDate()->format('jS_F_Y');
|
||||||
$modified = $user->name;
|
}
|
||||||
}
|
// set modified if not set
|
||||||
// set title if not set
|
if (!$modified)
|
||||||
if (!$title)
|
{
|
||||||
{
|
$modified = $user->name;
|
||||||
$title = 'Book1';
|
}
|
||||||
}
|
// set title if not set
|
||||||
// set tab name if not set
|
if (!$title)
|
||||||
if (!$subjectTab)
|
{
|
||||||
{
|
$title = 'Book1';
|
||||||
$subjectTab = 'Sheet1';
|
}
|
||||||
}
|
// set tab name if not set
|
||||||
|
if (!$subjectTab)
|
||||||
// make sure we have the composer classes loaded
|
{
|
||||||
self::composerAutoload('phpspreadsheet');
|
$subjectTab = 'Sheet1';
|
||||||
|
}
|
||||||
// Create new Spreadsheet object
|
|
||||||
$spreadsheet = new Spreadsheet();
|
// make sure we have the composer classes loaded
|
||||||
|
self::composerAutoload('phpspreadsheet');
|
||||||
// Set document properties
|
|
||||||
$spreadsheet->getProperties()
|
// Create new Spreadsheet object
|
||||||
->setCreator($creator)
|
$spreadsheet = new Spreadsheet();
|
||||||
->setCompany('Joomla Component Builder')
|
|
||||||
->setLastModifiedBy($modified)
|
// Set document properties
|
||||||
->setTitle($title)
|
$spreadsheet->getProperties()
|
||||||
->setSubject($subjectTab);
|
->setCreator($creator)
|
||||||
// The file type
|
->setCompany('Joomla')
|
||||||
$file_type = 'Xls';
|
->setLastModifiedBy($modified)
|
||||||
// set description
|
->setTitle($title)
|
||||||
if ($description)
|
->setSubject($subjectTab);
|
||||||
{
|
// The file type
|
||||||
$spreadsheet->getProperties()->setDescription($description);
|
$file_type = 'Xls';
|
||||||
}
|
// set description
|
||||||
// set keywords
|
if ($description)
|
||||||
if ($keywords)
|
{
|
||||||
{
|
$spreadsheet->getProperties()->setDescription($description);
|
||||||
$spreadsheet->getProperties()->setKeywords($keywords);
|
}
|
||||||
}
|
// set keywords
|
||||||
// set category
|
if ($keywords)
|
||||||
if ($category)
|
{
|
||||||
{
|
$spreadsheet->getProperties()->setKeywords($keywords);
|
||||||
$spreadsheet->getProperties()->setCategory($category);
|
}
|
||||||
}
|
// set category
|
||||||
|
if ($category)
|
||||||
// Some styles
|
{
|
||||||
$headerStyles = array(
|
$spreadsheet->getProperties()->setCategory($category);
|
||||||
'font' => array(
|
}
|
||||||
'bold' => true,
|
|
||||||
'color' => array('rgb' => '1171A3'),
|
// Some styles
|
||||||
'size' => 12,
|
$headerStyles = array(
|
||||||
'name' => 'Verdana'
|
'font' => array(
|
||||||
));
|
'bold' => true,
|
||||||
$sideStyles = array(
|
'color' => array('rgb' => '1171A3'),
|
||||||
'font' => array(
|
'size' => 12,
|
||||||
'bold' => true,
|
'name' => 'Verdana'
|
||||||
'color' => array('rgb' => '444444'),
|
));
|
||||||
'size' => 11,
|
$sideStyles = array(
|
||||||
'name' => 'Verdana'
|
'font' => array(
|
||||||
));
|
'bold' => true,
|
||||||
$normalStyles = array(
|
'color' => array('rgb' => '444444'),
|
||||||
'font' => array(
|
'size' => 11,
|
||||||
'color' => array('rgb' => '444444'),
|
'name' => 'Verdana'
|
||||||
'size' => 11,
|
));
|
||||||
'name' => 'Verdana'
|
$normalStyles = array(
|
||||||
));
|
'font' => array(
|
||||||
|
'color' => array('rgb' => '444444'),
|
||||||
// Add some data
|
'size' => 11,
|
||||||
if (($size = self::checkArray($rows)) !== false)
|
'name' => 'Verdana'
|
||||||
{
|
));
|
||||||
$i = 1;
|
|
||||||
|
// Add some data
|
||||||
// Based on data size we adapt the behaviour.
|
if (($size = self::checkArray($rows)) !== false)
|
||||||
$xls_mode = 1;
|
{
|
||||||
if ($size > 3000)
|
$i = 1;
|
||||||
{
|
|
||||||
$xls_mode = 3;
|
// Based on data size we adapt the behaviour.
|
||||||
$file_type = 'Csv';
|
$xls_mode = 1;
|
||||||
}
|
if ($size > 3000)
|
||||||
elseif ($size > 2000)
|
{
|
||||||
{
|
$xls_mode = 3;
|
||||||
$xls_mode = 2;
|
$file_type = 'Csv';
|
||||||
}
|
}
|
||||||
|
elseif ($size > 2000)
|
||||||
// Set active sheet and get it.
|
{
|
||||||
$active_sheet = $spreadsheet->setActiveSheetIndex(0);
|
$xls_mode = 2;
|
||||||
foreach ($rows as $array)
|
}
|
||||||
{
|
|
||||||
$a = 'A';
|
// Set active sheet and get it.
|
||||||
foreach ($array as $value)
|
$active_sheet = $spreadsheet->setActiveSheetIndex(0);
|
||||||
{
|
foreach ($rows as $array)
|
||||||
$active_sheet->setCellValue($a.$i, $value);
|
{
|
||||||
if ($xls_mode != 3)
|
$a = 'A';
|
||||||
{
|
foreach ($array as $value)
|
||||||
if ($i == 1)
|
{
|
||||||
{
|
$active_sheet->setCellValue($a.$i, $value);
|
||||||
$active_sheet->getColumnDimension($a)->setAutoSize(true);
|
if ($xls_mode != 3)
|
||||||
$active_sheet->getStyle($a.$i)->applyFromArray($headerStyles);
|
{
|
||||||
$active_sheet->getStyle($a.$i)->getAlignment()->setHorizontal(PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER);
|
if ($i == 1)
|
||||||
}
|
{
|
||||||
elseif ($a === 'A')
|
$active_sheet->getColumnDimension($a)->setAutoSize(true);
|
||||||
{
|
$active_sheet->getStyle($a.$i)->applyFromArray($headerStyles);
|
||||||
$active_sheet->getStyle($a.$i)->applyFromArray($sideStyles);
|
$active_sheet->getStyle($a.$i)->getAlignment()->setHorizontal(PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER);
|
||||||
}
|
}
|
||||||
elseif ($xls_mode == 1)
|
elseif ($a === 'A')
|
||||||
{
|
{
|
||||||
$active_sheet->getStyle($a.$i)->applyFromArray($normalStyles);
|
$active_sheet->getStyle($a.$i)->applyFromArray($sideStyles);
|
||||||
}
|
}
|
||||||
}
|
elseif ($xls_mode == 1)
|
||||||
$a++;
|
{
|
||||||
}
|
$active_sheet->getStyle($a.$i)->applyFromArray($normalStyles);
|
||||||
$i++;
|
}
|
||||||
}
|
}
|
||||||
}
|
$a++;
|
||||||
else
|
}
|
||||||
{
|
$i++;
|
||||||
return false;
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
// Rename worksheet
|
{
|
||||||
$spreadsheet->getActiveSheet()->setTitle($subjectTab);
|
return false;
|
||||||
|
}
|
||||||
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
|
|
||||||
$spreadsheet->setActiveSheetIndex(0);
|
// Rename worksheet
|
||||||
|
$spreadsheet->getActiveSheet()->setTitle($subjectTab);
|
||||||
// Redirect output to a client's web browser (Excel5)
|
|
||||||
header('Content-Type: application/vnd.ms-excel');
|
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
|
||||||
header('Content-Disposition: attachment;filename="' . $fileName . '.' . strtolower($file_type) .'"');
|
$spreadsheet->setActiveSheetIndex(0);
|
||||||
header('Cache-Control: max-age=0');
|
|
||||||
// If you're serving to IE 9, then the following may be needed
|
// Redirect output to a client's web browser (Excel5)
|
||||||
header('Cache-Control: max-age=1');
|
header('Content-Type: application/vnd.ms-excel');
|
||||||
|
header('Content-Disposition: attachment;filename="' . $fileName . '.' . strtolower($file_type) .'"');
|
||||||
// If you're serving to IE over SSL, then the following may be needed
|
header('Cache-Control: max-age=0');
|
||||||
header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
|
// If you're serving to IE 9, then the following may be needed
|
||||||
header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
|
header('Cache-Control: max-age=1');
|
||||||
header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
|
|
||||||
header ('Pragma: public'); // HTTP/1.0
|
// If you're serving to IE over SSL, then the following may be needed
|
||||||
|
header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
|
||||||
$writer = IOFactory::createWriter($spreadsheet, $file_type);
|
header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
|
||||||
$writer->save('php://output');
|
header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
|
||||||
jexit();
|
header ('Pragma: public'); // HTTP/1.0
|
||||||
}
|
|
||||||
|
$writer = IOFactory::createWriter($spreadsheet, $file_type);
|
||||||
/**
|
$writer->save('php://output');
|
||||||
* Get CSV Headers
|
jexit();
|
||||||
*/
|
}
|
||||||
public static function getFileHeaders($dataType)
|
|
||||||
{
|
/**
|
||||||
// make sure we have the composer classes loaded
|
* Get CSV Headers
|
||||||
self::composerAutoload('phpspreadsheet');
|
*/
|
||||||
// get session object
|
public static function getFileHeaders($dataType)
|
||||||
$session = JFactory::getSession();
|
{
|
||||||
$package = $session->get('package', null);
|
// make sure we have the composer classes loaded
|
||||||
$package = json_decode($package, true);
|
self::composerAutoload('phpspreadsheet');
|
||||||
// set the headers
|
// get session object
|
||||||
if(isset($package['dir']))
|
$session = JFactory::getSession();
|
||||||
{
|
$package = $session->get('package', null);
|
||||||
// only load first three rows
|
$package = json_decode($package, true);
|
||||||
$chunkFilter = new PhpOffice\PhpSpreadsheet\Reader\chunkReadFilter(2,1);
|
// set the headers
|
||||||
// identify the file type
|
if(isset($package['dir']))
|
||||||
$inputFileType = IOFactory::identify($package['dir']);
|
{
|
||||||
// create the reader for this file type
|
// only load first three rows
|
||||||
$excelReader = IOFactory::createReader($inputFileType);
|
$chunkFilter = new PhpOffice\PhpSpreadsheet\Reader\chunkReadFilter(2,1);
|
||||||
// load the limiting filter
|
// identify the file type
|
||||||
$excelReader->setReadFilter($chunkFilter);
|
$inputFileType = IOFactory::identify($package['dir']);
|
||||||
$excelReader->setReadDataOnly(true);
|
// create the reader for this file type
|
||||||
// load the rows (only first three)
|
$excelReader = IOFactory::createReader($inputFileType);
|
||||||
$excelObj = $excelReader->load($package['dir']);
|
// load the limiting filter
|
||||||
$headers = array();
|
$excelReader->setReadFilter($chunkFilter);
|
||||||
foreach ($excelObj->getActiveSheet()->getRowIterator() as $row)
|
$excelReader->setReadDataOnly(true);
|
||||||
{
|
// load the rows (only first three)
|
||||||
if($row->getRowIndex() == 1)
|
$excelObj = $excelReader->load($package['dir']);
|
||||||
{
|
$headers = array();
|
||||||
$cellIterator = $row->getCellIterator();
|
foreach ($excelObj->getActiveSheet()->getRowIterator() as $row)
|
||||||
$cellIterator->setIterateOnlyExistingCells(false);
|
{
|
||||||
foreach ($cellIterator as $cell)
|
if($row->getRowIndex() == 1)
|
||||||
{
|
{
|
||||||
if (!is_null($cell))
|
$cellIterator = $row->getCellIterator();
|
||||||
{
|
$cellIterator->setIterateOnlyExistingCells(false);
|
||||||
$headers[$cell->getColumn()] = $cell->getValue();
|
foreach ($cellIterator as $cell)
|
||||||
}
|
{
|
||||||
}
|
if (!is_null($cell))
|
||||||
$excelObj->disconnectWorksheets();
|
{
|
||||||
unset($excelObj);
|
$headers[$cell->getColumn()] = $cell->getValue();
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
}
|
$excelObj->disconnectWorksheets();
|
||||||
return $headers;
|
unset($excelObj);
|
||||||
}
|
break;
|
||||||
return false;
|
}
|
||||||
}
|
}
|
||||||
|
return $headers;
|
||||||
/**
|
}
|
||||||
* Load the Composer Vendor phpspreadsheet
|
return false;
|
||||||
*/
|
}
|
||||||
protected static function composephpspreadsheet()
|
|
||||||
{
|
/**
|
||||||
// load the autoloader for phpspreadsheet
|
* Load the Composer Vendor phpspreadsheet
|
||||||
require_once JPATH_SITE . '/libraries/phpspreadsheet/vendor/autoload.php';
|
*/
|
||||||
// do not load again
|
protected static function composephpspreadsheet()
|
||||||
self::$composer['phpspreadsheet'] = true;
|
{
|
||||||
|
// load the autoloader for phpspreadsheet
|
||||||
return true;
|
require_once JPATH_SITE . '/libraries/phpspreadsheet/vendor/autoload.php';
|
||||||
|
// do not load again
|
||||||
|
self::$composer['phpspreadsheet'] = true;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue