Adding a URL to quotes

OK, I figured out where in the quotes modules to modify the admin form to add a text field for specifying a URL (which will be attached to the Author's name on a quote), but beyond that I am getting lost tracking functions through the Dolphin code. It looks like in BxQuotesModule.php the part which calls outside the module itself to display the quotes on the site is the function parseHtmlByTemplateName.

I tracked that back to BxDolTemplate.php but from there on... man args get passed around among a BUNCH of different functions, and I can't seem to find the point at which the HTML is generated and output. Can anyone point me in the right direction? (spaghetti-ish code, hah)

Thanks!

Quote · 25 Mar 2010

The part that displays the quote is in BxQuotesModule.php

It's the service call function at line 31 serviceGetQuoteUnit. It handles the output.

https://www.deanbassett.com
Quote · 25 Mar 2010

The part that displays the quote is in BxQuotesModule.php

It's the service call function at line 31 serviceGetQuoteUnit. It handles the output.

That still passes off the details to process_line_output() and parseHtmlByTemplateName(). I tried modifying the process_line_output call which takes Author as an arg to hard-code in the <a> tags, and the output that resulted on the site was DISPLAYING the <a> tags, rather than rendering them as a link. So, somewhere in the code I need to tell it to not to change the HTML tags to their &gt and %lt counterparts. If this makes sense :)

Quote · 25 Mar 2010

The function loads an array with the values to be passed to the template.

$aVariables = array (
'unit_text' => $sUnitText,
'author' => $sUnitAuthor,
'URL' => $sTheURL
);

Add a 3'd value to that which will be the url.

The function called there parseHtmlByTemplateName specifies what template to use which is unit and the above variable array that is to be used to replace keys in the template.

Then modify the template these values are passed to which is in modules\boonex\quotes\templates\base\unit.html

<div class="quote_div">
<div class="daily_quotes">
<i>&quot;__unit_text__&quot;</i><br />
<p class="author"><a href="__URL__">__author__</a></p>
</div>
<div class="clear_both"></div>
</div>


Hope that helps clear up how this works.

https://www.deanbassett.com
Quote · 25 Mar 2010

Thanks, that does lay out a clear roadmap. I figured out where all to make modifications in that BxQuotModules.php file, but hadn't tracked things all the way to the template file yet.

Gracias!

Quote · 25 Mar 2010

Just thought of something: I would like to make URLs optional. I set up an if-else statement to direct it to a different template by name like this:

return $sCss . $this->_oTemplate->parseHtmlByTemplateName('unit', $aVariables);

versus

return $sCss . $this->_oTemplate->parseHtmlByTemplateName('unitnolink', $aVariables);

And now have two template files (unit.html and unitnolink.html) -- one return is called if the URL value is empty and the other is called if it has something in it (a link). Does that look right? The whole code snippet is here:

    $sUnitText = process_text_output($oQuoteUnit['Text']);
    $sUnitAuthor = process_line_output($oQuoteUnit['Author']);
    $sUnitAuthorURL = process_line_output($oQuoteUnit['AuthorURL']);
   
    if ($sUnitAuthorURL != "") { // there's a link
            $aVariables = array (
            'unit_text' => $sUnitText,
                'author' => $sUnitAuthor,
              'authorurl' => $sUnitAuthorURL
            );

            $sCss = $this->_oTemplate->addCss('unit.css', true);
            return $sCss . $this->_oTemplate->parseHtmlByTemplateName('unit', $aVariables);
        } else { // no link
            $aVariables = array (
            'unit_text' => $sUnitText,
                'author' => $sUnitAuthor
            );
   
            $sCss = $this->_oTemplate->addCss('unit.css', true);
            return $sCss . $this->_oTemplate->parseHtmlByTemplateName('unitnolink', $aVariables);
        }

However that seems to have succeeded in only showing NO quotes. The template files have only this in them:

unit.html
<div class="quote_div">
	<div class="daily_quotes">
		<i>"__unit_text__"</i><br />
		<p class="author"><a href=__authorurl__>__author__</a></p>
	</div>
	<div class="clear_both"></div>
</div>

and

unitnolink.html
<div class="quote_div">
	<div class="daily_quotes">
		<i>"__unit_text__"</i><br />
		<p class="author">__author__</p>
	</div>
	<div class="clear_both"></div>
</div>

Ideas on what I'm doing wrong?

Quote · 26 Mar 2010

You created another template. so you need to add that to the list of templates used by the module.

modules\boonex\quotes\classes\BxQuotesTemplate.php

Add the template name to this line

$this->_aTemplates = array('unit', 'adm_unit');


Like so.


$this->_aTemplates = array('unit','unitnolink', 'adm_unit');



That is the only thing i can think of you might have missed. The code looks fine.

https://www.deanbassett.com
Quote · 26 Mar 2010

Good deal, thanks. One last thing I found out I needed to change was in the BxQuotesDb.php file, I had to add my new AuthorURL field from the database to the query string. After that, voila, it worked.

Thanks, deano! Pretty simple little change, but I learned quite a bit more about how Dolphin is put together :)

Quote · 26 Mar 2010
 
 
Below is the legacy version of the Boonex site, maintained for Dolphin.Pro 7.x support.
The new Dolphin solution is powered by UNA Community Management System.