本文整理汇总了PHP中JoomleagueHelper::removeBOM方法的典型用法代码示例。如果您正苦于以下问题:PHP JoomleagueHelper::removeBOM方法的具体用法?PHP JoomleagueHelper::removeBOM怎么用?PHP JoomleagueHelper::removeBOM使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JoomleagueHelper
的用法示例。
在下文中一共展示了JoomleagueHelper::removeBOM方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: import
public function import($table, $view)
{
JToolBarHelper::back('Back', 'index.php?option=com_joomleague&view=' . $view);
$msg = array();
$app = JFactory::getApplication();
$jinput = $app->input;
$replace = $jinput->getInt('csv-replace', 0);
$delimiter = $jinput->getString('csvdelimiter', ';');
$tblObject = JTable::getInstance($table, 'Table');
$filename = '';
$csvimport = false;
$file = JRequest::getVar('FileCSV', null, 'files', 'array');
if (isset($file['tmp_name']) && trim($file['tmp_name']) != '') {
$filename = $file['tmp_name'];
$csvimport = true;
}
if ($csvimport) {
$handle = fopen($filename, 'r');
if (!$handle) {
$msg = JText::_('COM_JOOMLEAGUE_ADMIN_IMPORT_CTRL_CANNOT_OPEN');
$this->setRedirect('index.php?option=com_joomleague&view=' . $view, $msg, 'error');
return;
}
// get fields, on first row of the file
$fields = array();
if (($data = fgetcsv($handle, 1000, $delimiter, '"')) !== FALSE) {
$numfields = count($data);
for ($c = 0; $c < $numfields; $c++) {
// here, we make sure that the field match one of the fields of table or special fields,
// otherwise, we don't add it
$value = JoomleagueHelper::removeBOM(trim($data[$c]));
if (property_exists($tblObject, $value)) {
$fields[$c] = $value;
}
}
}
// If there is no validated fields, there is a problem...
if (!count($fields)) {
$msg = JText::_('COM_JOOMLEAGUE_ADMIN_IMPORT_CTRL_ERROR_PARSING');
$this->setRedirect('index.php?option=com_joomleague&view=' . $view, $msg, 'error');
return;
} else {
$msg[] = $numfields . " fields found in first row";
$msg[] = count($fields) . " fields were kept";
}
// Now get the records, meaning the rest of the rows.
$records = array();
$row = 1;
while (($data = fgetcsv($handle, 10000, $delimiter, '"')) !== FALSE) {
$num = count($data);
if ($numfields != $num) {
$msg[] = JText::_('COM_JOOMLEAGUE_ADMIN_IMPORT_CTRL_WRONG_NUMBER_OF_FIELDS');
} else {
$r = array();
// only extract columns with validated header, from previous step.
foreach ($fields as $k => $v) {
$r[$k] = $this->_formatcsvfield($v, $data[$k]);
}
$records[] = $r;
}
$row++;
}
fclose($handle);
$msg[] = JText::_('COM_JOOMLEAGUE_ADMIN_IMPORT_CTRL_TOTAL_RECORDS_FOUND') . count($records);
// database update
if (count($records)) {
$model = $this->getModel('import');
$result = $model->import($fields, $records, $replace, $table);
$error = $result['errormsg'];
$app = JFactory::getApplication();
if ($error) {
$msgError = array();
$msgError[] = JText::_('COM_JOOMLEAGUE_GLOBAL_ERROR_CHECK');
foreach ($result['errormsg'] as $error) {
$msgError[] = $error;
}
$app->enqueueMessage(implode('<p>', $msgError), 'warning');
}
$msg[] = JText::_('COM_JOOMLEAGUE_ADMIN_IMPORT_CTRL_TOTAL_ADDED_RECORDS') . ' ' . $result['added'];
$msg[] = JText::_('COM_JOOMLEAGUE_ADMIN_IMPORT_CTRL_TOTAL_UPDATED_RECORDS') . ' ' . $result['updated'];
$msg[] = JText::_('COM_JOOMLEAGUE_ADMIN_IMPORT_CTRL_TOTAL_EXISTS_RECORDS') . ' ' . $result['exists'];
$app->enqueueMessage(implode('<p>', $msg));
}
$this->setRedirect('index.php?option=com_joomleague&view=' . $view);
}
}