[dev] Midas addition, another try..
Robert Ribnitz
ribnitz at linuxbourg.ch
Wed Aug 20 05:32:45 PDT 2003
Hello,
here I am again, same addition, though with the following changes:
- Midas.php lines now break aorund col 75. Longer lines have been split
over multiple lines
- api.php has been beutified a little
- ad.php has been beautified a little
-------------- next part --------------
<?php
/**
* $Horde: midas/lib/Block/ad.php ribnitz at linuxbourg.ch $
*
* Provides an ad-serving block to midas (and possibly giapeto)
*
* @package horde.block
*/
class midas_ad_Block extends Horde_Block {
function midas_ad_Block($params = array())
{
$this->_params = $params;
$this->_app = 'midas';
$this->_type = 'ad';
}
function isEditable()
{
return false;
}
function _title()
{
return _("Advertising");
}
function _content()
{
global $registry;
$dummy=array();
$midas = &Midas::singleton();
$ad=$midas->viewAd($dummy);
return $ad;
}
}
-------------- next part --------------
Index: Midas.php
===================================================================
RCS file: /repository/midas/lib/Midas.php,v
retrieving revision 1.27
diff -r1.27 Midas.php
140c140,142
< $msg = sprintf('FAILED COUNTER UPDATE because of inexistant ad_id or update action request (ad_id: "%s"; actionID: "%s")', $ad_id, $actionID);
---
> $msg = sprintf('FAILED COUNTER UPDATE because of inexistant ad_id '.
> 'or update action request (ad_id: "%s"; actionID: "%s")',
> $ad_id, $actionID);
168c170,171
< $textfilter = str_replace(array('.', ',', ':', ';', '-'), ' ', $textfilter);
---
> $textfilter = str_replace(array('.', ',', ':', ';', '-'), ' ',
> $textfilter);
192a196,221
>
> // added by Robert Ribnitz, ribnitz at linuxbourg.ch
>
> function viewAd(&$ad_id, $textfilter = null)
> {
> if (empty($ad_id)) {
> $campaign_list = array();
> if (!is_null($textfilter)) {
> $campaign_list = $this->getFilteredCampaigns($textfilter);
> }
> $ad_id = $this->getRandomAdId($campaign_list);
> }
> if (is_a($ad_id, 'PEAR_Error')) {
> return "document.write('" . $ad_id->getMessage() . "');\n";
> }
> $campaign = $this->_campaigns->getCampaignDetails($ad_id);
> $img = Horde::addParameter(Horde::applicationUrl('ad.php'), 'id',
> $campaign['campaign_id']);
> $html = Horde::img($img, '', '', '');
> if (!empty($campaign['campaign_link'])) {
> $html = Horde::link(Horde::addParameter(Horde::applicationUrl(
> 'click.php'), 'id', $campaign['campaign_id']), '', '',
> '_New') . $html . '</a>';
> }
>
> $html = str_replace("'", "\\'", $html);
193a223,230
> if (!empty($html)) {
> return "$html";
> }
> return _("No ads available");
> }
>
> // end of addition
>
209c246,247
< $img = Horde::addParameter(Horde::applicationUrl('ad.php'), 'id', $campaign['campaign_id']);
---
> $img = Horde::addParameter(Horde::applicationUrl('ad.php'), 'id',
> $campaign['campaign_id']);
212c250,252
< $html = Horde::link(Horde::addParameter(Horde::applicationUrl('click.php'), 'id', $campaign['campaign_id']), '', '', '_New') . $html . '</a>';
---
> $html = Horde::link(Horde::addParameter(Horde::applicationUrl(
> 'click.php'), 'id', $campaign['campaign_id']), '', '',
> '_New') . $html . '</a>';
Index: api.php
===================================================================
RCS file: /repository/midas/lib/api.php,v
retrieving revision 1.7
diff -r1.7 api.php
15a16,19
> $_services['get_random_html_ad'] = array(
> 'args' => 'string',
> 'type' => 'array'
> );
29c33
< * Output a random ad through the api.
---
> * Output a random ad through the api, using JavaScript
45a50,67
> /**
> * Output a random ad through the api, not using Javascript
> *
> * @param optional string $textfilter A string which will be used to
> * narrow down the list of campaigns.
> */
> function _midas_get_random_html_ad($textfilter = null)
> {
> require_once dirname(__FILE__) . '/base.php';
>
> $ad_id = Horde::getFormData('id');
>
> $midas = &Midas::singleton();
> $midas->updateCounter($ad_id, MIDAS_COUNT_SHOW);
>
> return $midas->viewAd($ad_id, $textfilter);
> }
>
59,62c81,89
< 'name' => _("Ad Campaigns Summary"),
< 'type' => 'summary',
< 'params' => array(),
< ),
---
> 'name' => _("Ad Campaigns Summary"),
> 'type' => 'summary',
> 'params' => array(),
> ),
> 'ad' => array (
> 'name' => _("Show a random Advertisment"),
> 'type' => 'ad',
> 'params' => array(),
> )
More information about the dev
mailing list