Joomla.it Forum
Joomla! 2.5 (versione con supporto terminato) => Joomla! 1.6/1.7/2.5 => : pippo30 16 Apr 2013, 09:48:37
-
salve ho fatto il componente per importare il csv
ma ho una domanda
ho usato la funzione explode
/* Split the line by comma */
if (function_exists('str_getcsv'))
$line = str_getcsv($line);
else
$user = new JUser();
$line = “nome cognome, nomeutente, email, password”;
$properties = explode(",", $line);
$user->name = $properties[0];
$user->username = $properties[1];
$user->email = $properties[2];
$user->password = $properties[3];
i campi bastano questi o deve aggigerne sono giusti per fare in modo che l'importazione avenga correttamente???
-
Ciao Marco31,
se intendi creare un utente di Joomla! credo manchi ancora qualche campo:
Il Gruppo di utenti al quale appartiene l'utente nuovo/importato
Se E un utente Bloccato
Se è un Utente Attivato
La Data di Registrazione... etc.. etc...
Non so se l'omissione di uno o di tutti i parametri sia "bloccante" dovresti solo provare.
Mi pare che in Joomla! 2.5.x le Tabelle interessate per la creazione di uno User siano 3 o poco più:
Users, UserGroups,User_Notes
E qualcos'altro mi pare... ;)
-
come mai con la modifica esce pagina bianca??
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import Joomla controller library
jimport('joomla.application.component.controller');
/**
* General Controller of JUserImporter component
*/
class JUserImporterController extends JControllerLegacy
{
/**
* display task
*
* @return void
*/
function display($cachable = false, $urlparams = array())
{
// set default view if not set
$input = JFactory::getApplication()->input;
$input->set('view', $input->getCmd('view', 'JUserImporter'));
// call parent behavior
parent::display($cachable, $urlparams);
}
/**
* Import task
*/
function importUsers($source = "c:/xampp/htdocs/users2import.csv")
{
/* Check the user file exists */
if (file_exists( $source ) && !isset($_REQUEST['srcfile'])) {
/* Open the file */
if(!file_exists($source)) $source = $_REQUEST['srcfile'];
$handle = fopen($userFile,"r");
$content = fread ($handle,filesize ( $source ));
fclose($handle);
/* Get the file, line by line */
$lines = explode("\n", $content);
/* Remove the first line (headers only) */
unset($lines[0]);
/* Counter of users added */
$added = 0;
/* Iterate through each line of the data file */
foreach ($lines as $key => $line){
/* Split the line by comma */
if (function_exists('str_getcsv'))
$line = str_getcsv($line);
else
$user = new JUser();
$line = “nome cognome, nomeutente, email, password”;
$properties = explode(",", $line);
$user->name = $properties[0];
$user->username = $properties[1];
$user->email = $properties[2];
$user->password = $properties[3];
/* Build a new user object */
$user = new JUser();
$user->id = null;
/* Set the values */
$user->name = $line[2];
$user->username = $line[12];
$user->email = $line[11];
$user->groups = array(2);
/* Build the password */
$salt = JUserHelper::genRandomPassword(32);
$crypted = JUserHelper::getCryptedPassword( preg_replace("/\s/", "", strtolower($line[13])) , $salt);
$newpassword= $crypted . ':' . $salt;
$user->password = $newpassword;
$user->usertype = "deprecated";
$user->registerDate = date('Y-m-d H:i:s');
if(!$user->save()) JError::raiseError(500,$user->getError() );
else $added++;
}
return $added;
}else{
JError::raiseError(403, JText::_('File CSV da importare mancante.'));
return false;
}
JError::raiseError(403, JText::_('Ci sono stati deli errori.'));
return false;
}
}
-
Ciao,
a occhio e croce non vedo niente, hai attivato il Debug di Joomla! Così al posto della Pagina Bianca magari leggiamo cosa accade.. :o
-
prima era così
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import Joomla controller library
jimport('joomla.application.component.controller');
/**
* General Controller of JUserImporter component
*/
class JUserImporterController extends JControllerLegacy
{
/**
* display task
*
* @return void
*/
function display($cachable = false, $urlparams = array())
{
// set default view if not set
$input = JFactory::getApplication()->input;
$input->set('view', $input->getCmd('view', 'JUserImporter'));
// call parent behavior
parent::display($cachable, $urlparams);
}
/**
* Import task
*/
function importUsers($source = "c:/xampp/htdocs/users2import.csv")
{
/* Check the user file exists */
if (file_exists( $source ) && !isset($_REQUEST['srcfile'])) {
/* Open the file */
if(!file_exists($source)) $source = $_REQUEST['srcfile'];
$handle = fopen($userFile,"r");
$content = fread ($handle,filesize ( $source ));
fclose($handle);
/* Get the file, line by line */
$lines = explode("\n", $content);
/* Remove the first line (headers only) */
unset($lines[0]);
/* Counter of users added */
$added = 0;
/* Iterate through each line of the data file */
foreach ($lines as $key => $line){
/* Split the line by comma */
if (function_exists('str_getcsv'))
$line = str_getcsv($line);
else
$line = preg_split('/,/', $line);
/* Build a new user object */
$user = new JUser();
$user->id = null;
/* Set the values */
$user->name = $line[2];
$user->username = $line[12];
$user->email = $line[11];
$user->groups = array(2);
/* Build the password */
$salt = JUserHelper::genRandomPassword(32);
$crypted = JUserHelper::getCryptedPassword( preg_replace("/\s/", "", strtolower($line[13])) , $salt);
$newpassword= $crypted . ':' . $salt;
$user->password = $newpassword;
$user->usertype = "deprecated";
$user->registerDate = date('Y-m-d H:i:s');
if(!$user->save()) JError::raiseError(500,$user->getError() );
else $added++;
}
return $added;
}else{
JError::raiseError(403, JText::_('File CSV da importare mancante.'));
return false;
}
JError::raiseError(403, JText::_('Ci sono stati deli errori.'));
return false;
}
}
-
ciao,
io sostituirei, così giusto per provare questa riga:
function importUsers($source = "c:/xampp/htdocs/users2import.csv
)
con una che punta magari a: http://localhost/xxx/import (http://localhost/xxx/import) .csv ad esempio
-
quindi l'errore (presunto) potrebbe essere qui:
$user = new JUser();
$line = “nome cognome, nomeutente, email,
password”;
$properties = explode(",", $line);
$user->name =
$properties[0];
$user->username = $properties[1];
$user->email =
$properties[2];
$user->password = $properties[3];
Hai cercato in rete altri "esempi"? giusto per confrontarli con il Codice che stai utilizzando.. :)
-
quello che funzinava l'ho messo sotto ho solo cambiato
da
if (function_exists('str_getcsv'))
$line = str_getcsv($line);
else
$line = preg_split('/,/', $line);
a
if (function_exists('str_getcsv'))
$line = str_getcsv($line);
else
$user = new JUser();
$line = “nome cognome, nomeutente, email, password”;
$properties = explode(",", $line);
$user->name = $properties[0];
$user->username = $properties[1];
$user->email = $properties[2];
$user->password = $properties[3];
-
capito??? nn è che abbia cambiato molto
-
Ma hai già aperto lo stesso topic qui:
http://forum.mrwebmaster.it/php/34374-explode.html (http://forum.mrwebmaster.it/php/34374-explode.html)
Il codice è identico e non funzionante nemmeno lì... :( :o ???
-
Al limite puoi usare come spunto questo script qui, funzionante, per la 1.5.x,:
http://www.paulferrett.com/php/joomla_user_import.phps (http://www.paulferrett.com/php/joomla_user_import.phps)
:o
-
ma li era per una cosa diversa per le virgolette sbagliate
-
Tra l'altro puoi "riprendere" spunto da qui:
http://www.zriel.com/joomla/110-import-joomla-users-from-a-csv-file-16-17-25-3 (http://www.zriel.com/joomla/110-import-joomla-users-from-a-csv-file-16-17-25-3)
Dato che una "fetta" di codice si somiglia molto ;)
-
sembra si un problema degli apici doppi sono sbagliati
-
a me nn risulta li ho cambiati
-
ho risolto ora fuziona almeno nn si vede pagina bianca
-
Bene! puoi mettere [RISOLTO] in alto nel titolo di questo Topic,
e se ti va puoi condividere con gli altri la soluzione postandola qui, anche per aiutare chi ne potrebbe in futuro aver bisogno. ;)
-
provo l'imprtazione del csv poi scrivo
-
$line = “nome cognome, nomeutente, email, password”;
erano le virgolette sbagiate vanno quelle sopra il due della tastiera
-
quello che visivamente funziona
vi allego il file php del plugin così vi rendete conto ok?? sono tutte righe di codice messe insieme usando internet ok??
function importUsers($source = "e:/xampp/htdocs/import.csv")
questo è il percoso dove deve essere salvato il file giusto??
io carico il csv li
perche mi dice file mancante se il csv c'è??
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import Joomla controller library
jimport('joomla.application.component.controller');
/**
* General Controller of JUserImporter component
*/
class JUserImporterController extends JControllerLegacy
{
/**
* display task
*
* @return void
*/
function display($cachable = false, $urlparams = array())
{
// set default view if not set
$input = JFactory::getApplication()->input;
$input->set('view', $input->getCmd('view', 'JUserImporter'));
// call parent behavior
parent::display($cachable, $urlparams);
}
/**
* Import task
*/
function importUsers($source = "e:/xampp/htdocs/import.csv")
{
/* Check the user file exists */
if (file_exists( $source ) && !isset($_REQUEST['srcfile'])) {
/* Open the file */
if(!file_exists($source)) $source = $_REQUEST['srcfile'];
$handle = fopen($source,"r");
$content = fread ($handle,filesize ( $source ));
fclose($handle);
/* Get the file, line by line */
$lines = explode("\n", $content);
/* Remove the first line (headers only) */
unset($lines[0]);
/* Counter of users added */
$added = 0;
/* Iterate through each line of the data file */
foreach ($lines as $key => $line){
/* Split the line by comma */
if (function_exists('str_getcsv'))
$line = str_getcsv($line);
else
$user = new JUser();
$line = "nome cognome, nomeutente, email, password";
$properties = explode(",",$line);
$user->name = $properties[0];
$user->username = $properties[1];
$user->email = $properties[2];
$user->password = $properties[3];
/* Build a new user object */
$user = new JUser();
$user->id = null;
/* Set the values */
$user->name = $line[2];
$user->username = $line[12];
$user->email = $line[11];
$user->groups = array(2);
/* Build the password */
$salt = JUserHelper::genRandomPassword(32);
$crypted = JUserHelper::getCryptedPassword( preg_replace("/\s/", "", strtolower($line[13])) , $salt);
$newpassword= $crypted . ':' . $salt;
$user->password = $newpassword;
$user->usertype = "deprecated";
$user->registerDate = date('Y-m-d H:i:s');
if(!$user->save()) JError::raiseError(500,$user->getError() );
else $added++;
}
return $added;
}else{
JError::raiseError(403, JText::_('File CSV da importare mancante.'));
return false;
}
JError::raiseError(403, JText::_('Ci sono stati deli errori.'));
return false;
}
}
-
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import Joomla controller library
jimport('joomla.application.component.controller');
/**
* General Controller of JUserImporter component
*/
class JUserImporterController extends JControllerLegacy
{
/**
* display task
*
* @return void
*/
function display($cachable = false, $urlparams = array())
{
// set default view if not set
$input = JFactory::getApplication()->input;
$input->set('view', $input->getCmd('view', 'JUserImporter'));
// call parent behavior
parent::display($cachable, $urlparams);
}
/**
* Import task
*/
function importUsers($source = "e:/xampp/htdocs/users2import.csv")
{
/* Check the user file exists */
/* Open the file */
if(!file_exists($source)) $source = $_REQUEST['srcfile'];
$handle = fopen($source,"r");
$content = fread ($handle,filesize ( $source ));
/* Get the file, line by line */
$lines = explode("\n", $content);
fclose($handle);
/* Counter of users added */
$added = 0;
/* Iterate through each line of the data file */
for ($i = 0; $i < count($lines); $i++){// as $key => $line){
/* Split the line by comma */
$properties = explode(",",$lines[$i]);
/* Build a new user object */
$user = new JUser();
$data = array();
$data['name'] = $properties[0];
$data['username'] = $properties[1];
$data['email'] = $properties[2];
$data['password'] = $properties[3];
// Load the users plugin group.
JPluginHelper::importPlugin('user');
/* Set the values */
$user->groups = array(2);
if (!$user->bind($data))
{
$this->setError(JText::sprintf('COM_USERS_REGISTRATION_BIND_FAILED', $user->getError()));
return false;
}
$user->registerDate = date('Y-m-d H:i:s');
if (!$user->save())
{
$this->setError(JText::sprintf('COM_USERS_REGISTRATION_SAVE_FAILED', $user->getError()));
return false;
}
else $added++;
$user = null;
}
if($added) return $added;
$this->setError(JText::sprintf('COM_USERS_REGISTRATION_SAVE_FAILED', "Ci sono stati degli errori nella importazione"));
return false;
}
}
ho usato lo stesso metodo di joomla
/* Iterate through each line of the data file */
for ($i = 0; $i < count($lines); $i++){// as $key => $line){
/* Split the line by comma */
$properties = explode(",",$lines[$i]
alla fine riga del csv una , e un carattere e funziona