コード例 #1
0
bool SearchEditor::createDocument()
{
	if(EditorBase::createDocument() == false)
		return false;
	
	shared_ptr<XMLNode> root = getModuleDocument()->create(OS_MODULES_SEARCH_ROOT);
	
	m_globalParams->fillQuery();
	m_query->writeXml(root);
	setAttribute(root, m_showParams);
	setAttribute(root, m_directRun);
	setAttribute(root, m_allowRss);
	setAttribute(root, m_rssDescription);
	setAttribute(root, m_rssBody);

	return true;
}
コード例 #2
0
void XsltTransformViewer::onLoad()
{
	ViewerBase::onLoad();

	shared_ptr<XMLNode> root = getModuleDocument()->getRoot();
	if(root != nullptr)
	{
		String xmlStr = root->getAttributeString(OS_MODULES_XSLTTRANSFORM_XML);
		String xslStr = root->getAttributeString(OS_MODULES_XSLTTRANSFORM_XSL);
		String xsdStr = root->getAttributeString(OS_MODULES_XSLTTRANSFORM_XSD);

		shared_ptr<XMLDocument> document;

		if(xsdStr.empty())
		{
			document.reset(OS_NEW XMLDocument());
		}
		else
		{
			shared_ptr<XMLSchema> xsd(OS_NEW XMLSchema());
			xsd->parseString(xsdStr);

			document.reset(OS_NEW XMLDocument(xsd));
		}

		if(document->parseString(xmlStr))
		{
			shared_ptr<XMLStylesheet> transformer(OS_NEW XMLStylesheet());
			// Inizializza le funzioni del template
			getPage()->initStylesheet(transformer);

			if(transformer->parseString(xslStr))
			{
				String output;
				if(transformer->applyToString(document, output))
				{
					getControls()->add(shared_ptr<HtmlLiteral>(OS_NEW HtmlLiteral(getPage()->parseOml(output, true, false, false, omlRenderModeOsiris, getInstance().getString()))));
				}
			}
		}
	}
}
コード例 #3
0
void SearchEditor::onInit()
{
	EditorBase::onInit();

	m_rssBody->addOption(getPage()->getText(_S("plugins.components.modules.search.rssBody.full")), _S("full"));
	m_rssBody->addOption(getPage()->getText(_S("plugins.components.modules.search.rssBody.link")), _S("link"));
	m_rssBody->addOption(getPage()->getText(_S("plugins.components.modules.search.rssBody.none")), _S("none"));

	shared_ptr<XMLNode> root = getModuleDocument()->getRoot();

	if(root != nullptr)
	{
		m_query->readXml(root);

		m_showParams->setCheck(root->getAttributeBool(m_showParams->getID()));
		m_directRun->setCheck(root->getAttributeBool(m_directRun->getID()));
		m_allowRss->setCheck(root->getAttributeBool(m_allowRss->getID()));	
		m_rssDescription->setValue(root->getAttributeString(m_rssDescription->getID()));	
		m_rssBody->setValue(root->getAttributeString(m_rssBody->getID()));	
	}
}
コード例 #4
0
void FeedViewer::onLoad()
{
	ViewerBase::onLoad();

	shared_ptr<XMLNode> root = getModuleDocument()->getRoot();
	OS_ASSERT(root != nullptr);

	// Ajax:
	// - Creo un controllo per contenere quanto sotto
	// - Chiamo un "isDirect" a livello di ModuleViewer, che restituisce un "true" se son puntato diretto.
	// - Se si, leggo il parametro "mode", se è "direct" restituisco il contenuto del controllo secco via transmit-buffer
	// - Qui dumpo una chiamata ad ajax passandogli l'url di me in direct mode
	String mode = _S("direct");  // Proprietà?
	mode = _S("ajax");
	
	shared_ptr<HtmlDiv> divData(OS_NEW HtmlDiv());

	String controlID = getInstance().toUTF16();
	if(controlID.empty())
	{
		controlID = _S("preview"); // Se il modulo è in preview, non ha un'ID di istanza. Ma un ID mi serve x forza per gli eventi.
		mode = _S("direct"); // Ajax non è supportato nell'anteprima, perchè non ho un id da referenziare secco per avere il contenuto in un secondo momento.
	}
	setID(controlID);

	if(mode == _S("ajax"))
	{
		// - Chiamo un "isDirect" a livello di ModuleViewer, che restituisce un "true" se son puntato diretto.
		// - Se si, leggo il parametro "mode", se è "direct" restituisco il contenuto del controllo secco via transmit-buffer
		if(getPage()->getRequest()->getUrlParam(_W("mode")) == _W("content"))
			mode = _S("content");
		else
			mode = _S("delayed");
	}

	if( (mode == _S("direct")) || (mode == _S("content")) )
	{	
		String url = root->getAttributeString(OS_MODULES_FEED_URL);
		bool showTitle = root->getAttributeBool(OS_MODULES_FEED_SHOWTITLE);
		bool showDescription = root->getAttributeBool(OS_MODULES_FEED_SHOWDESCRIPTION);
		bool showImage = root->getAttributeBool(OS_MODULES_FEED_SHOWIMAGE);
		int32 nItems = root->getAttributeInt32(OS_MODULES_FEED_NITEMS);
		String showItemDescription = root->getAttributeString(OS_MODULES_FEED_SHOWITEMDESCRIPTION);
		String templateModel = root->getAttributeString(OS_MODULES_FEED_TEMPLATEMODEL);
		String templateCustom = root->getAttributeString(OS_MODULES_FEED_TEMPLATECUSTOM);

		shared_ptr<XMLDocument> document(OS_NEW XMLDocument());
		shared_ptr<XMLStylesheet> transformer(OS_NEW XMLStylesheet());

		try
		{
			shared_ptr<boost::asio::io_service> service = getSession()->getService();

			String output;
			String error;

			String userAgent = Engine::getDefaultHttpUserAgent();	
			document->parseUrl(url.to_ascii(), userAgent, service, Engine::instance()->createTCPSocket(service, true, true));

			shared_ptr<XMLNode> rssRoot = document->getRoot();

			if(rssRoot == nullptr)
			{
				// Error reading RSS Feed.				
				error = _S("Feed reading error.");				
			}
			else
			{		
				// Aggiungo all'xml RSS le proprietà del modulo.
				rssRoot->setAttributeString(OS_MODULES_FEED_URL, url);
				rssRoot->setAttributeBool(OS_MODULES_FEED_SHOWTITLE, showTitle);
				rssRoot->setAttributeBool(OS_MODULES_FEED_SHOWDESCRIPTION, showDescription);
				rssRoot->setAttributeBool(OS_MODULES_FEED_SHOWIMAGE, showImage);
				rssRoot->setAttributeInt32(OS_MODULES_FEED_NITEMS, nItems);
				rssRoot->setAttributeString(OS_MODULES_FEED_SHOWITEMDESCRIPTION, showItemDescription);
				rssRoot->setAttributeString(OS_MODULES_FEED_TEMPLATEMODEL, templateModel);
				
				if(templateModel.empty())
				{
					shared_ptr<XMLStylesheet> stylesheet(OS_NEW XMLStylesheet());
					if(stylesheet->parseString(templateCustom))
					{
						// Inizializza le funzioni del template
						getPage()->initStylesheet(stylesheet);

						if(stylesheet->applyToString(document, output))
						{
							//getControls()->add(shared_ptr<HtmlLiteral>(OS_NEW HtmlLiteral(getPage()->parseBBCode(output, true, false, false, false))));
						}
						else
						{
							// Transformazione fallita.
							error = _S("Transformation failed.");
						}
					}
					else
					{
						// Template custom invalido.
						error = _S("Invalid custom template.");
					}
				}
				else
				{
					shared_ptr<XMLStylesheet> stylesheet(OS_NEW XMLStylesheet());
					// Inizializza le funzioni del template
					getPage()->initStylesheet(stylesheet);

					String path = utils::makeFilePath(utils::makeFolderPath(g_componentsPath, _S("feed")), _S("feed_viewer_") + templateModel + _S(".xsl"));

					// Carica l'xsl
					if(stylesheet->parseFile(path))
					{
						if(stylesheet->applyToString(document, output))
						{
							// Qui potrei aggiungere un literal diretto, non parserizzato bb...
							//getControls()->add(shared_ptr<HtmlLiteral>(OS_NEW HtmlLiteral(getPage()->parseBBCode(output, true, false, false, false))));
						}
						else
						{
							// Transformazione fallita.
							error = _S("Transformation failed.");
						}
					}
					else
					{
						// Template non valido.
						error = _S("Invalid template.");
					}
				}

				if(output.empty() == true)
				{
					error = _S("Unknown error.");										
				}
			}

			if(error.empty() == false)
			{
				divData->setCss(_S("os_plugins_components_feed_error_reading"));
				divData->getControls()->add(shared_ptr<HtmlText>(OS_NEW HtmlText(error)));
			}
			else
			{
				divData->setCss(_S("os_plugins_components_feed_ok"));
				output = output.trim();
				//output = _S("[nobr]") + output + _S("[/nobr]");

				// Debugging
				//output = _S("[code]") + output + _S("[/code]") + output;
				
				divData->getControls()->add(shared_ptr<HtmlLiteral>(OS_NEW HtmlLiteral(getPage()->parseOml(output, true, false, false, omlRenderModeOsiris, getInstance().getString()))));
			}
		}
		catch(std::exception &e)
		{
			OS_LOG_ERROR(e.what());
		}	
	}

	if(mode == _S("direct"))
	{
		getControls()->add(divData);		
	}
	else if(mode == _S("delayed"))
	{
		String urlAjaxContent = getPage()->getPortal()->getViewObjectLink(getInstance()) + _S("&mode=content");
		divData->getControls()->add(shared_ptr<HtmlLiteral>(OS_NEW HtmlLiteral(_S("<div data-os-wait=\"center\" data-os-url=\"") + urlAjaxContent + _S("\"></div>"))));		
		getControls()->add(divData);		
	}
	else if(mode == _S("content"))
	{
		// trasmitbuffer solo di divData.
		HtmlWriter writer;
		divData->render(getPage(), writer);		
		
		getPage()->getSession()->transmitHtml(writer.getHtml().to_utf8(), httpStatusOK);
	}
}