Exemplo n.º 1
0
bool CUserPageBuilder::CreatePageArticle(int iUserID, CUser& PageOwner, CGuideEntry &Article)
{
	bool bSuccess = false;
	int ih2g2ID = 0;
	// if we have a page owner and can get their masthead then try to
	// initialise it in an appropriate way for the user page
	// are these flags right ???
	if (!PageOwner.IsEmpty() &&
		PageOwner.GetMasthead(&ih2g2ID) &&
		ih2g2ID > 0)
	{
		CUser* pViewingUser = m_InputContext.GetCurrentUser();
		bSuccess = Article.Initialise(ih2g2ID, m_InputContext.GetSiteID(), pViewingUser, true, true, true, true);
	}
	// now check if the XSLT parser finds any errors in the XML
	// if it does then try to fail gracefully by keeping the rest of the page
	// and just not displaying the masthead
	if (bSuccess)
	{
		CTDVString sArticleXML;
		CTDVString sErrors;
		CTDVString sErrorLine;
		int iLine;
		int iChar;

		// get the article in text form and see if the xslt parser chokes on it
		bSuccess = Article.GetAsString(sArticleXML);
//		OutputDebugString(sArticleXML);
		bSuccess = bSuccess && m_InputContext.GetParsingErrors(sArticleXML, &sErrors, &sErrorLine, &iLine, &iChar);
		if (!bSuccess)
		{
			// XSLT object had parse errors, so keep the ARTICLEINFO stuff
			// but throw away anything else inside the ARTICLE tag
			CTDVString sArticleInfoXML;
			int iLeftPos, iRightPos;

			iLeftPos = sArticleXML.FindText("<ARTICLEINFO");
			iRightPos = sArticleXML.FindText("</ARTICLEINFO>");
			if (iLeftPos >= 0 && iRightPos >= 0 && iRightPos >= iLeftPos)
			{
				// adjust right pos to end of tag
				iRightPos += 14;
				sArticleInfoXML = sArticleXML.Mid(iLeftPos, iRightPos - iLeftPos);
			}
			else
			{
				// no article info available
				// TODO: could try to construct it from other data
				sArticleInfoXML = "<ARTICLEINFO></ARTICLEINFO>";
			}
			bSuccess = Article.RemoveTagContents("ARTICLE");
			TDVASSERT(bSuccess, "RemoveTagContents(...) failed in CUserPageBuilder::CreatePageArticle(...)");
			// insert an ERROR tag with a type and some contents that can be used by the stylesheet or
			// ignored as it sees fit
			sArticleXML = "<ERROR TYPE='XML-PARSE-ERROR'>Error parsing GuideML</ERROR>";
			bSuccess = Article.AddInside("ARTICLE", sArticleXML);
			bSuccess = bSuccess && Article.AddInside("ARTICLE", sArticleInfoXML);
		}
	}
	// return the object, or NULL if couldn't make one
	return bSuccess;
}
Exemplo n.º 2
0
bool CUserPageBuilder::CreateUserInterface(CUser* pViewer, CUser& Owner, CGuideEntry& Masthead, CPageUI &Interface)
{
	// TODO: will need to take into account viewing users preferences at some
	// point if they are allowed to switch off some buttons

	bool bSuccess = Interface.Initialise(pViewer);
	// I've guessed at what the URLs might look like => should the url
	// parameters be filled in at this time as well?
	if (bSuccess)
	{
		bool bDiscuss = true;
		bool bEdit = false;
		bool bViewerActive = false;
		int iViewerID = 0;
		int iOwnerID = 0;
		int iForumID = 0;

		// get the ID of the forum if we have been given a masthead article and
		// it actually has a forum (which it should)
		if (!Masthead.IsEmpty())
		{
			iForumID = Masthead.GetForumID();
		}
		if (iForumID == 0)
		{
			bDiscuss = false;
		}
		// check if we have a registered viewer and also if this happens to be their
		// own home page and set the appropriate button flags
		if (pViewer != NULL && pViewer->GetActive(&bViewerActive) && bViewerActive)
		{
			if (pViewer->GetUserID(&iViewerID) &&
				!Owner.IsEmpty() &&
				Owner.GetUserID(&iOwnerID) &&
				iViewerID == iOwnerID &&
				iViewerID != 0)
			{
				// also if this is their own home page they have
				// an edit page button
				bEdit = true;
			}
		}
		// TODO: forum ID seems to not work???
		CTDVString sDiscuss = "AddThread?forum=";
		sDiscuss << iForumID << "&amp;article=";
		int ih2g2ID = 0;
		CTDVString sEditLink = "";

		// get masthead ID if there is one
		if (!Owner.IsEmpty())
		{
			ih2g2ID = Owner.GetMasthead();
		}
		else if (!Masthead.IsEmpty())
		{
			ih2g2ID = Masthead.GetH2G2ID();
		}
		sEditLink << "/UserEdit" << ih2g2ID << "?Masthead=1";
		sDiscuss << ih2g2ID;
		// now set the apppropriate buttons in the UI object
		// currently you only get the eidt page button if this is actually your homepage, i.e. you
		// wont get it if you have editor status
		bSuccess =	Interface.SetDiscussVisibility(bDiscuss, sDiscuss) &&
					Interface.SetEditPageVisibility(bEdit, sEditLink);
		// TODO: may wish to fail in this case, but just log the error currently
		TDVASSERT(bSuccess, "Couldn't set a visibility option in CUserPageBuilder::CreateUserInterface()");
	}
	// if something went wrong then delete object and return NULL
	// return object or NULL for failure
	return bSuccess;
}