/**
  * Method is called by
  *
  * @access	public
  */
 public function onAfterImport($context, &$xml, $options)
 {
     JLog::add(new JLogEntry(__METHOD__, JLOG::DEBUG, 'plg_j2xml_attachments'));
     JLog::add(new JLogEntry($context, JLOG::DEBUG, 'plg_j2xml_attachments'));
     if (PHP_SAPI == 'cli') {
         JLog::addLogger(array('logger' => 'echo', 'extension' => 'plg_j2xml_attachments'), JLOG::ALL & ~JLOG::DEBUG, array('plg_j2xml_attachments'));
     } else {
         JLog::addLogger(array('logger' => $options->get('logger', 'messagequeue'), 'extension' => 'plg_j2xml_attachments'), JLOG::ALL & ~JLOG::DEBUG, array('plg_j2xml_attachments'));
     }
     if (version_compare(J2XMLVersion::getShortVersion(), '15.9.5') == -1) {
         JLog::add(new JLogEntry(JText::_('PLG_J2XML_ATTACHMENTS') . ' ' . JText::_('PLG_J2XML_ATTACHMENTS_MSG_REQUIREMENTS_LIB'), JLOG::WARNING, 'plg_j2xml_attachments'));
         return false;
     }
     // Check if component is not installed
     if (!file_exists(JPATH_ADMINISTRATOR . '/components/com_attachments/attachments.php')) {
         JLog::add(new JLogEntry(JText::_('PLG_J2XML_ATTACHMENTS') . ' ' . JText::_('PLG_J2XML_ATTACHMENTS_MSG_REQUIREMENTS_COM'), JLOG::WARNING, 'plg_j2xml_attachments'));
         return false;
     }
     // Check if component is not enabled
     if (!JComponentHelper::isEnabled('com_attachments', true)) {
         JLog::add(new JLogEntry(JText::_('PLG_J2XML_ATTACHMENTS') . ' ' . JText::_('PLG_J2XML_ATTACHMENTS_MSG_REQUIREMENTS_COM'), JLOG::WARNING, 'plg_j2xml_attachments'));
         return false;
     }
     jimport('eshiol.j2xml.importer');
     $app = JFactory::getApplication();
     $db = JFactory::getDBO();
     foreach ($xml->xpath("/j2xml/attachment[parent_type = 'com_content' and parent_entity = 'article']") as $record) {
         $importer = new J2XMLImporter();
         $importer->prepareData($record, $data, $options);
         $attachment = new stdClass();
         $attachment->filename = html_entity_decode($data['filename']);
         $attachment->file_type = $data['file_type'];
         $attachment->file_size = $data['file_size'];
         $attachment->parent_type = $data['parent_type'];
         $attachment->parent_entity = $data['parent_entity'];
         $attachment->parent_id = $importer->getArticledId($data['parent_id']);
         $attachment->uri_type = $data['uri_type'];
         if ($data['uri_type'] == 'url') {
             $attachment->url = $data['url'];
             $attachment->filename_sys = '';
         } elseif (isset($data['file'])) {
             require_once JPATH_SITE . '/components/com_attachments/helper.php';
             // Get the component parameters
             jimport('joomla.application.component.helper');
             $params = JComponentHelper::getParams('com_attachments');
             // Define where the attachments go
             $upload_url = AttachmentsDefines::$ATTACHMENTS_SUBDIR;
             $upload_dir = JPATH_SITE . '/' . $upload_url;
             // Get the parent plugin manager
             JPluginHelper::importPlugin('attachments');
             $apm = getAttachmentsPluginManager();
             // Get the parent object
             $parent = $apm->getAttachmentsPlugin($attachment->parent_type);
             // Construct the system filename and url (based on entities, etc)
             $newdir = $parent->getAttachmentPath($attachment->parent_entity, $attachment->parent_id, null);
             $fullpath = $upload_dir . '/' . $newdir;
             // Make sure the directory exists
             if (!JFile::exists($fullpath)) {
                 jimport('joomla.filesystem.folder');
                 if (!JFolder::create($fullpath)) {
                     $errmsg = JText::sprintf('ATTACH_ERROR_UNABLE_TO_SETUP_UPLOAD_DIR_S', $upload_dir) . ' (ERR 34)';
                     JError::raiseError(500, $errmsg);
                 }
                 require_once JPATH_SITE . '/components/com_attachments/helper.php';
                 AttachmentsHelper::write_empty_index_html($fullpath);
             }
             $attachment->filename_sys = $fullpath . $attachment->filename;
             file_put_contents($attachment->filename_sys, base64_decode($data['file']));
             $attachment->filename_sys = utf8_encode($attachment->filename_sys);
             $attachment->filename = utf8_encode($attachment->filename);
             $attachment->url = $upload_url . '/' . $newdir . $attachment->filename;
         } else {
             JLog::add(new JLogEntry(JText::sprintf('PLG_J2XML_ATTACHMENTS_MSG_ATTACHMENT_NOT_EXPORTED', $attachment->filename), JLOG::WARNING, 'plg_j2xml_attachments'));
             return;
         }
         $attachment->url_valid = $data['url_valid'];
         $attachment->url_relative = $data['url_relative'];
         $attachment->url_verify = $data['url_verify'];
         $attachment->display_name = $data['display_name'];
         $attachment->description = $data['description'];
         $attachment->icon_filename = $data['icon_filename'];
         $attachment->access = $importer->getAccessId($data['access']);
         $attachment->state = $data['state'];
         $attachment->user_field_1 = $data['user_field_1'];
         $attachment->user_field_2 = $data['user_field_2'];
         $attachment->user_field_3 = $data['user_field_3'];
         $attachment->created = $data['created'];
         $attachment->created_by = $importer->getUserId($data['created_by'], $this->_user_id);
         $attachment->modified = $data['modified'];
         $attachment->modified_by = $importer->getUserId($data['modified_by'], 0);
         $attachment->download_count = $data['download_count'];
         $query = $db->getQuery(true);
         $query->select($db->quoteName('id'));
         $query->from($db->quoteName('#__attachments'));
         $query->where($db->quoteName('parent_type') . '=' . $db->quote($attachment->parent_type));
         $query->where($db->quoteName('parent_entity') . '=' . $db->quote($attachment->parent_entity));
         $query->where($db->quoteName('filename') . '=' . $db->quote($attachment->filename));
         $query->where($db->quoteName('uri_type') . '=' . $db->quote($attachment->uri_type));
         $db->setQuery($query);
         $id = $db->loadResult();
         if ($id) {
             $attachments->id = $id;
             if ($db->updateObject('#__attachments', $attachments, 'id')) {
                 JLog::add(new JLogEntry(JText::sprintf('PLG_J2XML_ATTACHMENTS_MSG_ATTACHMENT_IMPORTED', $attachment->filename), JLOG::INFO, 'plg_j2xml_attachments'));
             } else {
                 JLog::add(new JLogEntry(JText::sprintf('PLG_J2XML_ATTACHMENTS_MSG_ATTACHMENT_NOT_IMPORTED', $attachment->filename), JLOG::INFO, 'plg_j2xml_attachments'));
             }
         } else {
             if ($db->insertObject('#__attachments', $attachment)) {
                 JLog::add(new JLogEntry(JText::sprintf('PLG_J2XML_ATTACHMENTS_MSG_ATTACHMENT_IMPORTED', $attachment->filename), JLOG::INFO, 'plg_j2xml_attachments'));
             } else {
                 JLog::add(new JLogEntry(JText::sprintf('PLG_J2XML_ATTACHMENTS_MSG_ATTACHMENT_NOT_IMPORTED', $attachment->filename), JLOG::INFO, 'plg_j2xml_attachments'));
             }
         }
     }
     return true;
 }
Beispiel #2
0
 /**
  * Entry point for the script
  *
  * @return  void
  *
  * @since   2.5.1
  */
 public function doExecute()
 {
     // Merge the default translation with the current translation
     $lang = JFactory::getLanguage();
     $lang->load('lib_j2xml', JPATH_SITE, null, false, false) || $lang->load('lib_j2xml', JPATH_ADMINISTRATOR, null, false, false) || $lang->load('lib_j2xml', JPATH_SITE, null, true) || $lang->load('lib_j2xml', JPATH_ADMINISTRATOR, null, true);
     $filename = $this->input->get('f', null, '');
     if (!$filename) {
         echo "Usage /usr/bin/php /path/to/site/cli/j2xml.php -f j2xml_file.xml";
         exit(1);
     }
     if (!file_exists($filename)) {
         echo "File {$filename} not found";
         exit(1);
     }
     JLog::addLogger(array('text_file' => 'j2xml.php', 'extension' => 'com_j2xml'), JLog::ALL, array('lib_j2xml', 'cli_j2xml'));
     JLog::addLogger(array('logger' => 'echo', 'extension' => 'com_j2xml'), JLOG::ALL & ~JLOG::DEBUG, array('lib_j2xml', 'cli_j2xml'));
     if (!($data = implode(gzfile($filename)))) {
         $data = file_get_contents($filename);
     }
     libxml_use_internal_errors(true);
     $xml = simplexml_load_string($data);
     if (!$xml) {
         $errors = libxml_get_errors();
         foreach ($errors as $error) {
             $msg = $error->code . ' - ' . $error->message . ' at line ' . $error->line;
             switch ($error->level) {
                 default:
                 case LIBXML_ERR_WARNING:
                     $this->out(sprintf('%d - %s at line %d', $error->message, $error->line, 'message'));
                     break;
                 case LIBXML_ERR_ERROR:
                     $this->out(sprintf('%d - %s at line %d', $error->message, $error->line, 'notice'));
                     break;
                 case LIBXML_ERR_FATAL:
                     $this->out(sprintf('%d - %s at line %d', $error->message, $error->line, 'error'));
                     break;
             }
         }
         libxml_clear_errors();
         exit(0);
     }
     if (!$xml) {
         $this->out(JText::sprintf('LIB_J2XML_MSG_FILE_FORMAT_UNKNOWN'), 'error');
         exit(0);
     }
     $dispatcher = JDispatcher::getInstance();
     JPluginHelper::importPlugin('j2xml');
     $results = $dispatcher->trigger('onBeforeImport', array('cli_j2xml', &$xml));
     if (!$xml) {
         $this->out(JText::sprintf('LIB_J2XML_MSG_FILE_FORMAT_UNKNOWN'), 'error');
     } elseif (strtoupper($xml->getName()) != 'J2XML') {
         $this->out(JText::sprintf('LIB_J2XML_MSG_FILE_FORMAT_UNKNOWN'), 'error');
     } elseif (!isset($xml['version'])) {
         $this->out(JText::sprintf('LIB_J2XML_MSG_FILE_FORMAT_UNKNOWN'), 'error');
     } else {
         jimport('eshiol.j2xml.importer');
         $xmlVersion = $xml['version'];
         $version = explode(".", $xmlVersion);
         $xmlVersionNumber = $version[0] . substr('0' . $version[1], strlen($version[1]) - 1) . substr('0' . $version[2], strlen($version[2]) - 1);
         if ($xmlVersionNumber == 120500) {
             set_time_limit(120);
             $params = JComponentHelper::getParams('com_j2xml');
             J2XMLImporter::import($xml, $params);
         } else {
             $this->out(JText::sprintf('LIB_J2XML_MSG_FILE_FORMAT_NOT_SUPPORTED', $xmlVersion), 'error');
         }
     }
 }
Beispiel #3
0
 function clean()
 {
     // Check for request forgeries
     JSession::checkToken('get') or die(JText::_('JINVALID_TOKEN'));
     //		$params = JComponentHelper::getParams('com_j2xml');
     $hostname = JFactory::getURI()->getHost();
     if ($hostname == 'localhost' && JRequest::getCmd('d3v3l0p', '0') === '1') {
         jimport('eshiol.j2xml.importer');
         J2XMLImporter::clean();
         $app = JFactory::getApplication('administrator');
         $app->enqueueMessage(JText::_('COM_J2XML_MSG_CLEANED', 'info'));
     }
     $this->setRedirect('index.php?option=com_j2xml');
 }
Beispiel #4
0
 function import()
 {
     // Check for request forgeries
     JRequest::checkToken() or jexit('Invalid Token');
     JLog::addLogger(array('logger' => 'messagequeue'), JLOG::ALL, array('j2xml'));
     $app = JFactory::getApplication('administrator');
     $msg = '';
     $db = JFactory::getDBO();
     $date = JFactory::getDate();
     $now = $date->toSQL();
     $params = JComponentHelper::getParams('com_j2xml');
     libxml_use_internal_errors(true);
     //Retrieve file details from uploaded file, sent from upload form:
     $file = JRequest::getVar('file_upload', null, 'files', 'array');
     if ($file['name']) {
         $filename = $file['tmp_name'];
     } else {
         $params = JComponentHelper::getParams('com_j2xml');
         $root = $params->get('root');
         if (!$root) {
             $root = $_SERVER['DOCUMENT_ROOT'];
         }
         if (strrpos($root, DS) === strlen($root) - 1) {
             $root = substr($root, strlen($root) - 1);
         }
         $filename = $root . JRequest::getVar('remote_file', null);
         $filename = str_replace('/', DS, $filename);
     }
     if (!($data = implode(gzfile($filename)))) {
         $data = file_get_contents($filename);
     }
     $data = substr($data, strpos($data, '<?xml version="1.0" encoding="UTF-8" ?>'));
     $data = self::stripInvalidXml($data);
     if (!defined('LIBXML_PARSEHUGE')) {
         define(LIBXML_PARSEHUGE, 524288);
     }
     // Syahrul Sazli Shaharir
     $xml = simplexml_load_string($data, 'SimpleXMLElement', LIBXML_PARSEHUGE);
     if (!$xml) {
         $errors = libxml_get_errors();
         foreach ($errors as $error) {
             $msg = $error->code . ' - ' . $error->message . ' at line ' . $error->line;
             switch ($error->level) {
                 default:
                 case LIBXML_ERR_WARNING:
                     $app->enqueueMessage($msg, 'message');
                     break;
                 case LIBXML_ERR_ERROR:
                     $app->enqueueMessage($msg, 'notice');
                     break;
                 case LIBXML_ERR_FATAL:
                     $app->enqueueMessage($msg, 'error');
                     break;
             }
         }
         libxml_clear_errors();
         $this->setRedirect('index.php?option=com_j2xml');
     }
     if (!$xml) {
         $app->enqueueMessage(JText::sprintf('LIB_J2XML_MSG_FILE_FORMAT_UNKNOWN'), 'error');
         return false;
     }
     $dispatcher = JDispatcher::getInstance();
     JPluginHelper::importPlugin('j2xml');
     $results = $dispatcher->trigger('onBeforeImport', array('com_j2xml.cpanel', &$xml));
     if (!$xml) {
         $app->enqueueMessage(JText::sprintf('LIB_J2XML_MSG_FILE_FORMAT_UNKNOWN'), 'error');
     } elseif (strtoupper($xml->getName()) != 'J2XML') {
         $app->enqueueMessage(JText::sprintf('LIB_J2XML_MSG_FILE_FORMAT_UNKNOWN'), 'error');
     } elseif (!isset($xml['version'])) {
         $app->enqueueMessage(JText::sprintf('LIB_J2XML_MSG_FILE_FORMAT_UNKNOWN'), 'error');
     } else {
         jimport('eshiol.j2xml.importer');
         $xmlVersion = $xml['version'];
         $version = explode(".", $xmlVersion);
         $xmlVersionNumber = $version[0] . substr('0' . $version[1], strlen($version[1]) - 1) . substr('0' . $version[2], strlen($version[2]) - 1);
         if ($xmlVersionNumber == 120500) {
             set_time_limit(120);
             $params = JComponentHelper::getParams('com_j2xml');
             J2XMLImporter::import($xml, $params);
         } else {
             $app->enqueueMessage(JText::sprintf('LIB_J2XML_MSG_FILE_FORMAT_NOT_SUPPORTED', $xmlVersion), 'error');
         }
     }
     $this->setRedirect('index.php?option=com_j2xml');
 }