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