[dev] Midas Ad lbock tested, possibly also usable for giapeto..
Robert Ribnitz
ribnitz at linuxbourg.ch
Tue Aug 19 12:53:41 PDT 2003
Hello,
after a few misunderstandings, I finally got the Midas Ad block (ie. a
Block that serves a random Midas Ad) up and running.
Attached files are diff -u output, ad.php is all new (goes to
midas/lib/Block).
yours
Robert
-------------- 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 19 Aug 2003 19:47:59 -0000
@@ -190,10 +190,9 @@
}
return $matched_campaigns;
}
-
- function viewAdByJs(&$ad_id, $textfilter = null)
- {
- if (empty($ad_id)) {
+
+ function getAdLink(&$ad_id,$textfilter = null) {
+ if (empty($ad_id)) {
$campaign_list = array();
if (!is_null($textfilter)) {
$campaign_list = $this->getFilteredCampaigns($textfilter);
@@ -208,12 +207,19 @@
$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);
-
+ return $html;}
+
+ function viewAd(&$ad_id,$textfilter = null) {
+ $html=$this->getAdLink($ad_id,$textfilter);
+ if (!empty($html)) {
+ return $html;
+ }
+ return _("No Ads available");
+ }
+
+ function viewAdByJs(&$ad_id, $textfilter = null)
+ {
+ $html=$this->getAdLink($ad_id,$textfilter);
if (!empty($html)) {
return "document.write('$html');\n";
}
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 19 Aug 2003 19:47:59 -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'),
@@ -43,6 +47,23 @@
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__) . '/..');
@@ -60,5 +81,10 @@
'type' => 'summary',
'params' => array(),
),
+ 'ad' => array (
+ 'name' => _("Show a random Advertisment"),
+ 'type' => 'ad',
+ 'params' => array(),
+ )
);
}
-------------- next part --------------
<?php
/**
* $Horde: midas/lib/Block/summary.php,v 1.1 2003/02/22 01:58:51 chuck Exp $
*
* @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;
}
}
More information about the dev
mailing list