/**
  * Constructor
  *
  * @param   object  &$subject  The object to observe
  * @param   array   $config    An optional associative array of configuration settings.
  *                             Recognized key values include 'name', 'group', 'params', 'language'
  *                             (this list is not meant to be comprehensive).
  */
 public function __construct(&$subject, $config = array())
 {
     parent::__construct($subject, $config);
     if (JDEBUG) {
         JLog::addLogger(array('text_file' => 'j2xml.php', 'extension' => 'plg_j2xml_rebuildlinks'), JLog::ALL, array('plg_j2xml_rebuildlinks'));
     }
     JLog::add(new JLogEntry(__METHOD__, JLOG::DEBUG, 'plg_j2xml_rebuildlinks'));
     if (version_compare(J2XMLVersion::getShortVersion(), '16.1.1') == -1) {
         JLog::add(new JLogEntry(JText::_('PLG_J2XML_REBUILDLINKS') . ' ' . JText::_('PLG_J2XML_REBUILDLINKS_MSG_REQUIREMENTS_LIB'), JLOG::WARNING, 'plg_j2xml_rebuildlinks'));
     }
     // Get the parameters.
     if (isset($config['params'])) {
         if ($config['params'] instanceof Registry) {
             $this->_params = $config['params'];
         } else {
             $this->_params = version_compare(JPlatform::RELEASE, '12', 'ge') ? new Registry() : new JRegistry();
             $this->_params->loadString($config['params']);
         }
     }
     $user = JFactory::getUser();
     $this->_user_id = $user->get('id');
     $lang = JFactory::getLanguage();
     $lang->load('plg_j2xml_rebuildlinks', JPATH_SITE, null, false, false) || $lang->load('plg_j2xml_rebuildlinks', JPATH_ADMINISTRATOR, null, false, false) || $lang->load('plg_j2xml_rebuildlinks', JPATH_SITE, null, true) || $lang->load('plg_j2xml_rebuildlinks', JPATH_ADMINISTRATOR, null, true);
 }
Exemplo n.º 2
0
 /**
  * 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;
 }
Exemplo n.º 3
0
 /**
  * Send xml data to
  * @param string $remote_url
  * @param string $xml
  * @param string $username
  * @param string $password
  * @param int $debug when 1 (or 2) will enable debugging of the underlying xmlrpc call (defaults to 0)
  * @return xmlrpcresp obj instance
  */
 private static function _xmlrpc_j2xml_send($remote_url, $xml, $username, $password, $debug = 0)
 {
     $protocol = '';
     $GLOBALS['xmlrpc_internalencoding'] = 'UTF-8';
     $client = new xmlrpc_client($remote_url);
     $client->return_type = 'xmlrpcvals';
     $client->request_charset_encoding = 'UTF-8';
     $client->user_agent = J2XMLVersion::$PRODUCT . ' ' . J2XMLVersion::getFullVersion();
     $client->setDebug($debug);
     $msg = new xmlrpcmsg('j2xml.import');
     $p1 = new xmlrpcval(base64_encode($xml), 'base64');
     $msg->addparam($p1);
     $p2 = new xmlrpcval($username, 'string');
     $msg->addparam($p2);
     $p3 = new xmlrpcval($password, 'string');
     $msg->addparam($p3);
     $res = $client->send($msg, 0);
     if (!$res->faultcode()) {
         return $res;
     }
     if ($res->faultString() == "Didn't receive 200 OK from remote server. (HTTP/1.1 301 Foun)") {
         $res = $client->send($msg, 0, $protocol = 'http11');
         if (!$res->faultcode()) {
             return $res;
         }
     }
     if ($res->faultString() == "Didn't receive 200 OK from remote server. (HTTP/1.1 303 See other)") {
         $headers = http_parse_headers($res->raw_data);
         $client = new xmlrpc_client($headers['Location']);
         $client->return_type = 'xmlrpcvals';
         $client->request_charset_encoding = 'UTF-8';
         $client->user_agent = J2XMLVersion::$PRODUCT . ' ' . J2XMLVersion::getFullVersion();
         $client->setDebug($debug);
         $res = $client->send($msg, 0, $protocol);
     }
     return $res;
 }
Exemplo n.º 4
0
 /**
  * Before save content method
  * Article is passed by value.
  * Method is called right before the content is saved
  *
  * @param	string		The context of the content passed to the plugin (added in 1.6)
  * @param	object		A JTableContent object
  * @param	bool		If the content is just about to be created
  * @since   2.5
  */
 public function onContentBeforeSave($context, $article, $isNew)
 {
     $plg_context = $this->params->get('context', -1);
     if ($plg_context == -1 && (!class_exists('J2XMLVersion') || version_compare(J2XMLVersion::getShortVersion(), '13.8.3') == -1)) {
         JLog::add(new JLogEntry(JText::_('PLG_CONTENT_SETIMAGES') . ' ' . JText::_('PLG_CONTENT_SETIMAGES_MSG_REQUIREMENTS_LIB')), JLOG::WARNING, 'plg_content_setimages');
         return true;
     }
     if ($plg_context == -1 && $context != "lib_j2xml.article" && $context != "cli_j2xml.article" && $context != "com_j2xml.article" || $plg_context == 1 && $context != "com_content.article") {
         return true;
     }
     if ($embedded = $this->params->get('embedded', 0)) {
         $this->embeddedImages($article->introtext, $embedded == 1);
         $this->embeddedImages($article->fulltext, $embedded == 1);
     }
     if ($external = $this->params->get('external', 0)) {
         $this->externalImages($article->introtext, $external == 1);
         $this->externalImages($article->fulltext, $external == 1);
     }
     $images = json_decode($article->images);
     $intro_ok = false;
     if (!$images->image_fulltext) {
         if ($fulltext_mode = $this->params->get('image_fulltext', false)) {
             if ($fulltext_mode == 3) {
                 self::getImage($article->fulltext, $src, $title, $alt);
             } else {
                 if ($fulltext_mode == 2) {
                     self::getImage($article->fulltext, $src, $title, $alt);
                     if (!$src) {
                         self::getImage($article->introtext, $src, $title, $alt);
                         $intro_ok = true;
                     }
                 } else {
                     if ($fulltext_mode == 1) {
                         self::getImage($article->introtext, $src, $title, $alt);
                         $intro_ok = true;
                     }
                 }
             }
             $images->image_fulltext = $src;
             if ($float_fulltext = $this->params->get('float_fulltext', false)) {
                 $images->float_fulltext = $float_fulltext;
             }
             if ($this->params->get('image_fulltext_alt', false)) {
                 $images->image_fulltext_alt = $alt;
             }
             if ($this->params->get('image_fulltext_caption', false)) {
                 $images->image_fulltext_caption = $title;
             }
         }
     }
     if (!$images->image_intro) {
         if ($this->params->get('image_intro', false)) {
             if ($intro_ok) {
                 $images->image_intro = $images->image_fulltext;
                 if ($float_intro = $this->params->get('float_intro', false)) {
                     $images->float_intro = $float_intro;
                 }
                 if ($this->params->get('image_intro_alt', false)) {
                     $images->image_intro_alt = $images->image_fulltext_alt;
                 }
                 if ($this->params->get('image_intro_caption', false)) {
                     $images->image_intro_caption = $images->image_fulltext_caption;
                 }
             } else {
                 if ($this->params->get('image_intro', false)) {
                     self::getImage($article->introtext, $src, $title, $alt);
                     $images->image_intro = $src;
                     if ($float_intro = $this->params->get('float_intro', false)) {
                         $images->float_intro = $float_intro;
                     }
                     if ($this->params->get('image_intro_alt', false)) {
                         $images->image_intro_alt = $alt;
                     }
                     if ($this->params->get('image_intro_caption', false)) {
                         $images->image_intro_caption = $title;
                     }
                 }
             }
         }
     }
     $article->images = json_encode($images);
     return true;
 }