Seems like a marvelous pile of spaghetti code!
Looks fine to me.
Also, the code you showed is typical web-developer uncommented garbage.
Good code is self-evident. Shitty/obscure/irregular code needs comments. All code needs documentation. There's nothing wrong with the code that he posted as long as there's external documentation describing what things like responseView is and how it's used.
But I really have to ask.. how can one not get OO programming? There is a class, which has functionality that belongs to its "nature" (a soldier may attack() and have the getWeapon() function, etc.).
It really is easy as that... and now there are possibly dozens and hundreds of classes that work together.
Herp derp. If that's all there was to OOP, DU wouldn't be having the issues he's having.
Code:
/**
* Shows a preview of the thread creation.
*
* @return XenForo_ControllerResponse_Abstract
*/
public function actionCreateThreadPreview()
{
$this->_assertPostOnly();
$forumId = $this->_input->filterSingle('node_id', XenForo_Input::UINT);
$forumName = $this->_input->filterSingle('node_name', XenForo_Input::STRING);
$ftpHelper = $this->getHelper('ForumThreadPost');
$forum = $ftpHelper->assertForumValidAndViewable($forumId ? $forumId : $forumName);
$forumId = $forum['node_id'];
$this->_assertCanPostThreadInForum($forum);
$message = $this->getHelper('Editor')->getMessageText('message', $this->_input);
$message = XenForo_Helper_String::autoLinkBbCode($message);
$viewParams = array(
'forum' => $forum,
'message' => $message
);
return $this->responseView('XenForo_ViewPublic_Thread_CreatePreview', 'thread_create_preview', $viewParams);
}
What does responseView do and how do I use it? It appears in 103 files (and isn't in the file this piece of code is) - Which one do I want? "XenForo_ViewPublic_Thread_CreatePreview" is some parameter being passed to it, which itself is easily enough found (there are only two of them and the one in 'CreatePreview.php' seems likely) but then that has:
I can't tell you what responseView is but there
should be documentation telling you what it is.
Don't know what a JFileChooser is in Java?
http://docs.oracle.com/javase/7/docs/api/javax/swing/JFileChooser.html
Don't know what an Event Source Object is in a random jQuery plugin?
http://arshaw.com/fullcalendar/docs/event_data/Event_Source_Object/
If there is no documentation, then there's not much you can do other than read lots of code.
"XenForo_ViewPublic_Thread_CreatePreview" is an object.
Code:
class XenForo_ViewPublic_Thread_CreatePreview extends XenForo_ViewPublic_Base
{
public function renderHtml()
{
$bbCodeParser = new XenForo_BbCode_Parser(XenForo_BbCode_Formatter_Base::create('Base', array('view' => $this)));
$this->_params['messageParsed'] = new XenForo_BbCode_TextWrapper($this->_params['message'], $bbCodeParser);
}
}
This is literally the only thing in that file (and there are hundreds of files where literally, there are empty _constructs or just one function with a few lines of code). This is easy enough to understand what it's doing (parsing bbcode) but how is it even being called? Obviously through responseView... but where was that again?
You're having trouble with this because of an OOP concept called
inheritence. They're probably implementing the
template pattern, but I can't tell if XenForo_ViewPublic_Base is abstract (if PHP even has abstract classes).
This is probably fairly basic shit to someone who's been coding PHP in an OO manner but I'm just not at that level of PHP coding to "get" what the hell is actually going on here and I'd often get lost in loops looking for that thing that started it all but finding files that called other files that seemed to call other files that had things like this in them:
Code:
public function __construct(Zend_Controller_Request_Http $request, Zend_Controller_Response_Http $response, XenForo_RouteMatch $routeMatch)
{
$this->_request = $request;
$this->_response = $response;
$this->_routeMatch = $routeMatch;
$this->_input = new XenForo_Input($this->_request);
}
I'm sure this is all great code and useful in some way but I have no idea how to actually /use/ any of it. In the end, it was a choice between simply going with what I knew and getting it done, or spending another year learning the ins and outs of OOP in PHP.
That's a
constructor initializing some or all of an object's
properties. This isn't PHP specific stuff you're having problems with. I've only used PHP a bit years ago for simple CRUD operations, but I can figure out what's going on. You're struggling with the OOP.
Don't let thesheeep bully you into feeling like an idiot for not understanding OOP. It's not simple. Especially not for someone with an existing background in procedural programming. OOP isn't just a few disjointed concepts, it's an entirely different mindset and way of approaching a problem. That said, If you're going to continue to maintain these forums using this software, it would probably be in your best interests to actually learn OOP.