implemented very simple ad rotation support, good enough for our rotating

quote banners - also included quote banners (20 from Webb, 4 new)
This commit is contained in:
Eric J. Bowersox 2001-04-19 07:24:25 +00:00
parent 609568b95c
commit e25ce3e63e
35 changed files with 354 additions and 8 deletions

View File

@ -405,6 +405,15 @@ CREATE TABLE postpublish (
INDEX display_order (on_date, postid)
);
# Advertisement (actually quote, for now) banners
CREATE TABLE adverts (
adid INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
imagepath VARCHAR(255) NOT NULL,
pathstyle SMALLINT NOT NULL DEFAULT 0,
caption VARCHAR(255),
linkurl VARCHAR(255)
);
##############################################################################
# Set table access rights
##############################################################################
@ -1331,6 +1340,33 @@ INSERT INTO refsigftr (ftr_code, is_default, is_locked, is_hidden, require_read,
(2, 0, 1, 1, 0, 10000, 63000, 'SYSA', 'System Administration', 'sysadmin'),
(3, 1, 0, 0, 1, 500, 0, 'CONF', 'Conferences', 'confops');
# Create the initial advertisements (quotes).
INSERT INTO adverts (imagepath) VALUES
('images/ads/Brown.gif'),
('images/ads/Caine.gif'),
('images/ads/Frost.gif'),
('images/ads/Keller.gif'),
('images/ads/Letterman.gif'),
('images/ads/Pooh.gif'),
('images/ads/Shakespeare.gif'),
('images/ads/Thomas.gif'),
('images/ads/WolinskiTeamwork.gif'),
('images/ads/Wonder.gif'),
('images/ads/bonaparte.gif'),
('images/ads/buscaglia.gif'),
('images/ads/dana.gif'),
('images/ads/deadpoets.gif'),
('images/ads/ford.gif'),
('images/ads/karen.gif'),
('images/ads/lynett.gif'),
('images/ads/mcauliffe.gif'),
('images/ads/midler.gif'),
('images/ads/sophocles.gif'),
('images/ads/talbert.gif'),
('images/ads/torvalds.gif'),
('images/ads/wonka.gif'),
('images/ads/worf.gif');
##############################################################################
# Database Initialization
##############################################################################

View File

@ -0,0 +1,37 @@
/*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
*
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* The Original Code is the Venice Web Communities System.
*
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core;
public interface Advertisement
{
// Image path style values.
public static final short CONTEXT_RELATIVE = 0;
public abstract int getAdID();
public abstract String getImagePath();
public abstract short getImagePathStyle();
public abstract String getCaption();
public abstract String getLinkURL();
public abstract void hit(String remote_addr);
} // end interface Advertisement

View File

@ -107,4 +107,6 @@ public interface UserContext extends SearchMode
public abstract boolean authenticateWithToken(String token) throws DataException;
public abstract Advertisement selectAd();
} // end interface UserContext

View File

@ -77,4 +77,8 @@ public interface VeniceEngine extends SearchMode
public abstract int getNumAuditRecordsPerPage();
public abstract Advertisement getAdByID(int id);
public abstract Advertisement selectAd();
} // end interface VeniceEngine

View File

@ -0,0 +1,195 @@
/*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
*
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* The Original Code is the Venice Web Communities System.
*
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core.impl;
import java.sql.*;
import java.util.Random;
import com.silverwrist.util.cachemap.*;
import com.silverwrist.venice.core.*;
import com.silverwrist.venice.db.*;
class AdvertisementImpl implements Advertisement
{
/*--------------------------------------------------------------------------------
* Static data members
*--------------------------------------------------------------------------------
*/
private static Random rng = new Random(System.currentTimeMillis());
private static CacheMap ad_cache = new CacheMap(500);
/*--------------------------------------------------------------------------------
* Attributes
*--------------------------------------------------------------------------------
*/
private DataPool datapool;
private int adid;
private String imagepath;
private short style;
private String caption;
private String linkurl;
/*--------------------------------------------------------------------------------
* Constructor
*--------------------------------------------------------------------------------
*/
protected AdvertisementImpl(DataPool datapool, ResultSet rs) throws SQLException
{
this.datapool = datapool;
this.adid = rs.getInt("adid");
this.imagepath = rs.getString("imagepath");
this.style = rs.getShort("pathstyle");
this.caption = rs.getString("caption");
this.linkurl = rs.getString("linkurl");
} // end constructor
/*--------------------------------------------------------------------------------
* Internal functions
*--------------------------------------------------------------------------------
*/
private static Advertisement getTheAd(DataPool datapool, Statement stmt, int ad_id) throws SQLException
{
Integer my_ad_id = new Integer(ad_id);
Advertisement rc = (Advertisement)(ad_cache.get(my_ad_id));
if (rc!=null)
return rc;
ResultSet rs = stmt.executeQuery("SELECT * From adverts WHERE adid = " + ad_id + ";");
if (!(rs.next()))
return null;
rc = new AdvertisementImpl(datapool,rs);
ad_cache.put(my_ad_id,rc);
return rc;
} // end getTheAd
/*--------------------------------------------------------------------------------
* Implementations from interface Advertisement
*--------------------------------------------------------------------------------
*/
public int getAdID()
{
return adid;
} // end getAdID
public String getImagePath()
{
return imagepath;
} // end getImagePath
public short getImagePathStyle()
{
return style;
} // end getImagePathStyle
public String getCaption()
{
return caption;
} // end getCaption
public String getLinkURL()
{
return linkurl;
} // end getLinkURL
public void hit(String remote_addr)
{ // this does nothing right now
} // end hit
/*--------------------------------------------------------------------------------
* Static functions for use within package
*--------------------------------------------------------------------------------
*/
static Advertisement getAdByID(DataPool datapool, int id)
{
Connection conn = null;
try
{ // get a database connection and call the internal function
conn = datapool.getConnection();
Statement stmt = conn.createStatement();
return getTheAd(datapool,stmt,id);
} // end try
catch (SQLException e)
{ // database error - no ad
return null;
} // end catch
finally
{ // make sure the connection is released before we go
if (conn!=null)
datapool.releaseConnection(conn);
} // end finally
} // end getAdByID
static Advertisement getRandomAd(DataPool datapool)
{
Connection conn = null;
try
{ // get a database connection and call the internal function
conn = datapool.getConnection();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT MAX(adid) FROM adverts;");
if (!(rs.next()))
throw new InternalStateError("getRandomAd() must be able to find MAX(adid)!");
int maximum = rs.getInt(1);
for (int i=0; i<100; i++)
{ // select an ad ID
int ad_id = rng.nextInt(maximum) + 1;
Advertisement rc = getTheAd(datapool,stmt,ad_id);
if (rc!=null)
return rc;
} // end for
// else just dump out and return null
} // end try
catch (SQLException e)
{ // database error - no ad
return null;
} // end catch
finally
{ // make sure the connection is released before we go
if (conn!=null)
datapool.releaseConnection(conn);
} // end finally
return null; // no ad
} // end getRandomAd
} // end class AdvertisementImpl

View File

@ -1345,6 +1345,13 @@ class UserContextImpl implements UserContext, UserBackend
} // end authenticateWithToken
public Advertisement selectAd()
{
// just get a random ad for now
return AdvertisementImpl.getRandomAd(datapool);
} // end selectAd
/*--------------------------------------------------------------------------------
* Implementations from interface UserBackend
*--------------------------------------------------------------------------------

View File

@ -1567,6 +1567,19 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
} // end getNumAuditRecordsPerPage
public Advertisement getAdByID(int id)
{
return AdvertisementImpl.getAdByID(datapool,id);
} // end getAdByID
public Advertisement selectAd()
{
// just get a random ad for now
return AdvertisementImpl.getRandomAd(datapool);
} // end selectAd
/*--------------------------------------------------------------------------------
* Implementations from interface EngineBackend
*--------------------------------------------------------------------------------

View File

@ -608,7 +608,7 @@ public abstract class VeniceServlet extends HttpServlet
Variables.flushCookies(request,response);
if (content!=null)
{ // display the content!
BaseJSPData base = new BaseJSPData(getMyLocation(request,engine,user,rdat),content);
BaseJSPData base = new BaseJSPData(engine,user,getMyLocation(request,engine,user,rdat),content);
base.transfer(ctxt,rdat);
} // end if
@ -663,7 +663,7 @@ public abstract class VeniceServlet extends HttpServlet
catch (ServletMultipartException e)
{ // this is an error message we need to generate and just bail out on
logger.error("ServletMultipartException caught in doVenicePost!",e);
BaseJSPData base = new BaseJSPData(getMyLocation(request,engine,user,rdat),
BaseJSPData base = new BaseJSPData(engine,user,getMyLocation(request,engine,user,rdat),
new ErrorBox(null,"Internal Error: " + e.getMessage(),null));
base.transfer(ctxt,rdat);
return;
@ -712,7 +712,7 @@ public abstract class VeniceServlet extends HttpServlet
Variables.flushCookies(request,response);
if (content!=null)
{ // display the content!
BaseJSPData base = new BaseJSPData(getMyLocation(request,engine,user,rdat),content);
BaseJSPData base = new BaseJSPData(engine,user,getMyLocation(request,engine,user,rdat),content);
base.transfer(ctxt,rdat);
} // end if

View File

@ -22,6 +22,7 @@ import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.log4j.*;
import com.silverwrist.venice.core.*;
import com.silverwrist.venice.servlets.Variables;
import com.silverwrist.venice.servlets.format.menus.LeftMenu;
@ -40,6 +41,8 @@ public class BaseJSPData
*--------------------------------------------------------------------------------
*/
private VeniceEngine engine; // the Venice engine
private UserContext user; // user context
private String location; // location string to use for this page
private VeniceContent content; // the actual content
private boolean login_links = true; // show login links up top?
@ -49,8 +52,10 @@ public class BaseJSPData
*--------------------------------------------------------------------------------
*/
public BaseJSPData(String location, VeniceContent content)
public BaseJSPData(VeniceEngine engine, UserContext user, String location, VeniceContent content)
{
this.engine = engine;
this.user = user;
this.location = location;
this.content = content;
@ -116,6 +121,47 @@ public class BaseJSPData
} // end transfer
public void renderBannerAd(Writer out, RenderData rdat) throws IOException
{
Advertisement advert;
if (user.isLoggedIn())
advert = user.selectAd();
else
advert = engine.selectAd();
if (advert==null)
{ // no advert found - bail out now!
out.write("&nbsp;");
return;
} // end if
String full_image_path;
if (advert.getImagePathStyle()==Advertisement.CONTEXT_RELATIVE)
{ // return the full image path
full_image_path = rdat.getContextRelativePath(advert.getImagePath());
} // end if
else
{ // can't render the ad - just punt
out.write("&nbsp;");
return;
} // end else
// Write the banner ad.
String url = advert.getLinkURL();
String capt = advert.getCaption();
if (url!=null)
out.write("<A HREF=\"" + url + "\">");
out.write("<IMG SRC=\"" + full_image_path + "\" ALT=\"");
if (capt!=null)
out.write(capt);
out.write("\" ALIGN=RIGHT WIDTH=468 HEIGHT=60 HSPACE=2 VSPACE=2 BORDER=0>");
if (url!=null)
out.write("</A>");
} // end renderBannerAd
public void renderMenu(HttpSession session, Writer out, RenderData rdat) throws IOException
{
ComponentRender menu = Variables.getMenu(session);

View File

@ -190,6 +190,15 @@ public class RenderData
} // end getStaticIncludePath
public String getContextRelativePath(String name)
{
StringBuffer buf = new StringBuffer(request.getContextPath());
if (name.charAt(0)!='/')
buf.append('/');
return buf.append(name).toString();
} // end getContextRelativePath
public String getStdFontTag(String color, int size)
{
return rconf.getStdFontTag(color,size);

View File

@ -55,10 +55,7 @@
<TD ALIGN=RIGHT WIDTH=150>
<% if (rdat.useHTMLComments()) { %><!-- Banner Ad --><% } %>
<%-- BEGIN TEMP - Banner Ad code --%>
<IMG SRC="/venice/images/sample-banner.gif" ALT="Banner Ad - 468x60" ALIGN=RIGHT
WIDTH=468 HEIGHT=60 HSPACE=2 VSPACE=2>
<%-- END TEMP - Banner Ad Code --%>
<% basedat.renderBannerAd(out,rdat); %>
</TD>
</TR>

BIN
web/images/ads/Brown.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

BIN
web/images/ads/Caine.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

BIN
web/images/ads/Frost.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

BIN
web/images/ads/Keller.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

BIN
web/images/ads/Pooh.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

BIN
web/images/ads/Thomas.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

BIN
web/images/ads/Wonder.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

BIN
web/images/ads/dana.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

BIN
web/images/ads/ford.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

BIN
web/images/ads/karen.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

BIN
web/images/ads/lynett.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

BIN
web/images/ads/midler.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

BIN
web/images/ads/talbert.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

BIN
web/images/ads/torvalds.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

BIN
web/images/ads/wonka.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

BIN
web/images/ads/worf.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB