[dev] Midas.php.diff
Robert Ribnitz
ribnitz at linuxbourg.ch
Wed Aug 20 07:16:40 PDT 2003
As requested
-------------- next part --------------
Index: Midas.php
===================================================================
RCS file: /repository/midas/lib/Midas.php,v
retrieving revision 1.27
diff -u -r1.27 Midas.php
--- Midas.php 19 Jun 2003 18:47:51 -0000 1.27
+++ Midas.php 20 Aug 2003 14:13:21 -0000
@@ -137,7 +137,9 @@
function updateCounter($ad_id = null, $actionID = null)
{
if (is_null($ad_id) || is_null($actionID)) {
- $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);
Horde::logMessage($msg, __FILE__, __LINE__, PEAR_LOG_ERR);
return false;
}
@@ -165,7 +167,8 @@
function getFilteredCampaigns($textfilter = null)
{
if (!is_array($textfilter)) {
- $textfilter = str_replace(array('.', ',', ':', ';', '-'), ' ', $textfilter);
+ $textfilter = str_replace(array('.', ',', ':', ';', '-'), ' ',
+ $textfilter);
$target_words = array_unique(preg_split('|\s+|', $textfilter));
} else {
$target_words = $textfilter;
@@ -190,7 +193,41 @@
}
return $matched_campaigns;
}
+
+ // 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);
+ if (!empty($html)) {
+ return "$html";
+ }
+ return _("No ads available");
+ }
+
+ // end of addition
+
function viewAdByJs(&$ad_id, $textfilter = null)
{
if (empty($ad_id)) {
@@ -206,10 +243,13 @@
$campaign = $this->_campaigns->getCampaignDetails($ad_id);
- $img = Horde::addParameter(Horde::applicationUrl('ad.php'), 'id', $campaign['campaign_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 = Horde::link(Horde::addParameter(Horde::applicationUrl(
+ 'click.php'), 'id', $campaign['campaign_id']), '', '',
+ '_New') . $html . '</a>';
}
$html = str_replace("'", "\\'", $html);
Index: api.php
===================================================================
RCS file: /repository/midas/lib/api.php,v
retrieving revision 1.7
diff -u -r1.7 api.php
--- api.php 22 Feb 2003 02:02:05 -0000 1.7
+++ api.php 20 Aug 2003 14:13:21 -0000
@@ -13,6 +13,10 @@
'args' => 'string',
'type' => 'array'
);
+$_services['get_random_html_ad'] = array(
+ 'args' => 'string',
+ 'type' => 'array'
+);
$_services['block'] = array(
'args' => array('type', 'params'),
@@ -26,7 +30,7 @@
/**
- * Output a random ad through the api.
+ * Output a random ad through the api, using JavaScript
*
* @param optional string $textfilter A string which will be used to
* narrow down the list of campaigns.
@@ -43,6 +47,24 @@
return $midas->viewAdByJs($ad_id, $textfilter);
}
+/**
+ * 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);
+}
+
function &_midas_block($type, $params)
{
@define('MIDAS_BASE', dirname(__FILE__) . '/..');
@@ -56,9 +78,14 @@
function _midas_blocks()
{
return array('summary' => array(
- '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