Dragonfly CMS v9 ⇒ Modules & Blocks :: Archives ⇒ Code help for Creating a Horoscope Module for DF: :: Archived ⇒ Community Forums ⇒ CPG Dragonfly™ CMS
Forum IndexModules & Blocks

Archived ⇒ Code help for Creating a Horoscope Module for DF:


Hello,
I wont to create a module for horoscope.
I have create the tables on database,and nod i wont to create a admin module like this ;

FORM ACTION="inserisci.php" METHOD="post"> <p>Segno zodiacale: <SELECT NAME="segno"> <OPTION VALUE="ariete" selected>Ariete</OPTION> <OPTION VALUE="toro">Toro</OPTION> ... <OPTION VALUE="pesci">Pesci</OPTION> </SELECT> <BR> La data dell'oroscopo: <INPUT NAME="giorno" TYPE="text" size="8"> / <INPUT NAME="mese" TYPE="text" size="8"> / <INPUT NAME="anno" TYPE="text" size="8"> <BR> L'oroscopo da inserire: <TEXTAREA NAME="oroscopo" cols="80" rows="7"> Inserisci qui l'oroscopo della settimana </TEXTAREA> </p> <p> <INPUT TYPE="submit" VALUE="Invia dati in Database"> </p> </FORM>

after on modules i have try to connect on database but:(

So how i can create a module about this?

webalbania.com

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Php 5.0.4 /MySQL 5.0.26/DF CMS 9.1.1.RC2


to code with dragonfly is not that easy, you cant add whatever code anywhere and hope it will do what you hoped ...

but its also not that difficult, take a simple module, like the Surveys module, there you have a file to install a module (create a database) and you will find the index.inc file in the admin folder which is used to do the admin part. Edit both files and look at how they are. Try to edit small bits to match it your goal, then test it ... learning by doing Wink as soon as i have some free time i will add a recipe about how to create an admin page at dragonfly-cookbook.com Wink

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Linux (infong 2.4) - 1.3.33 - 5.0.45-log (client: 5.0.18) - 5.2.4 - 9.1.2.1


First learn PHP with SQL, then look at here.

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
-


I had a working horoscope module, but I noticed last night that it has stopped working. Can anyone tell me if something is wrong with the code? If not I can only assume the site I'm pulling the data from has changed their setup.

Here are the 2 relavent files

phpHoroscope.class.php
<?php /** * Author: Tim Rhodes (ecomCreations.com) * Project: phpHoroscope * Version: 1.1 * Modified: 01/10/04 * File: phpHoroscope.class.php * * Purpose: * Easily retrieve and display todays, yesterdays and tomorrows * quickie and extended horoscopes from astrology.com. * * This library is free software; you can redistribute it and/or * modify it; either version 1.0, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but without any warranty; without even the implied warranty of * merchantability or fitness for a particular purpose. */ define('base', 'http://horoscopes.astrology.com'); define('qbase', base . '/daily'); define('ebase', base . '/dailylong'); class phpHoroscope { var $sign; var $date; var $quickie; var $extended; function phpHoroscope () { $this->sign = 'aquarius'; $this->date = 'today'; $this->quickie = TRUE; $this->extended = FALSE; } function safeSigns () { unset($safeSigns); return $safeSigns = array( 'aquarius', 'aries', 'cancer', 'capricorn', 'gemini', 'leo', 'libra', 'pisces', 'sagittarius', 'scorpio', 'taurus', 'virgo' ); } function safeDates () { unset($safeDates); return $dates = array( 'today', 'yesterday', 'tomorrow' ); } function setSign ($signControl) { if (empty($signControl)) { echo "error: sign is undefined!"; exit; } if (in_array($signControl, $this->safeSigns())) { $this->sign = $signControl; } else { echo "error: " . $signControl . " is not a valid sign!"; exit; } } function setDate ($dateControl) { if (empty($dateControl)) { echo "error: date is undefined!"; exit; } if (in_array($dateControl, $this->safeDates())) { $this->date = $dateControl; } else { echo "error: " . $dateControl . " is not a valid date!"; exit; } } function setQuickie () { $this->extended = FALSE; $this->quickie = TRUE; } function setExtended () { $this->quickie = FALSE; $this->extended = TRUE; } function buildUrl () { if ($this->extended) { $url = ebase; } else { $url = qbase; } if ($this->date == 'today') { $url = $url . $this->sign . '.html'; } else { $url = $url . $this->sign . substr($this->date, 0, 3) . '.html'; } return $url; } function getHoroscope () { $found = FALSE; $url = $this->buildUrl(); $file = fopen($url, 'r'); if (!$file) { echo "error: remote file '" . $url . "' could not be opened!"; exit; } while (!feof($file)) { $line = fgets($file); if (eregi("<daily_horoscope>", $line, $result)) { $found = TRUE; } elseif ($found) { $horoscope = trim($line); break; } } fclose($file); return $horoscope; } function displayHoroscope () { if (!empty($this->sign) && !empty($this->date)) { if (in_array($this->sign, $this->safeSigns()) && in_array($this->date, $this->safeDates())) { echo $this->getHoroscope(); } else { echo "error: sign and/or date are not valid!"; exit; } } else { echo "sign and/or date are undefined!"; exit; } } } ?>

Sign.php
<?php require_once("header.php"); //require_once("mainfile.php"); $module_name = basename(dirname(__FILE__)); $images = 'modules/'.$module_name.'/images/'; /** * In this example phpHoroscope is being used to * display multiple horoscopes on the same page. * * I sure hope you would know all the astrological * signs off the top of your head, but if not: * * ares, aries, cancer, capricorn, gemini, leo * libra, pisces, sagittarius, scorpio, taurus, virgo * * Note: $horoscope->setQuickie(); and setExtended(); * are used to toggle between quickie and extended * horoscope results. setQuickie(); is initialized * by default. */ require_once( BASEDIR . 'modules/' . $module_name . '/phpHoroscope.class.php'); if (isset($_GET['sid'])) { $sid = ($_GET['sid']); } else { url_redirect(getlink()); } echo '<br><h1><img src='.$images.$sid.'.gif alt="" /> '.ucfirst($sid).' - '.date("l F d Y").'</h1><br>'; echo "<br><b>Today</b><br>"; $horoscope1 = new phpHoroscope; // start phpHoroscope 1 (required) $horoscope1->setSign($sid); // set valid sign (required) $horoscope1->setDate('today'); // set valid date (required) (options: today|yesterday|tomorrow) $horoscope1->setExtended(); // toggles to extended results (optional) $horoscope1->displayHoroscope(); // display horoscope 1 results echo '<br><img src='.$images.'bar.gif align=center width=100% alt="" /></br></img>'; echo "<br><b>Tomorrow</b><br>"; $horoscope1 = new phpHoroscope; // start phpHoroscope 1 (required) $horoscope1->setSign($sid); // set valid sign (required) $horoscope1->setDate('tomorrow'); // set valid date (required) (options: today|yesterday|tomorrow) $horoscope1->setExtended(); // toggles to extended results (optional) $horoscope1->displayHoroscope(); // display horoscope 1 results echo '<br><img src='.$images.'bar.gif align=center width=100% alt="" /></br></img>'; echo "<br><b>Yesterday</b><br>"; $horoscope1 = new phpHoroscope; // start phpHoroscope 1 (required) $horoscope1->setSign($sid); // set valid sign (required) $horoscope1->setDate('yesterday'); // set valid date (required) (options: today|yesterday|tomorrow) $horoscope1->setExtended(); // toggles to extended results (optional) $horoscope1->displayHoroscope(); // display horoscope 1 results ?>

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
FreeBSD 4.10/Apache 1.3.33/MySQL4.1.15/PHP4.4.1/Dragonfly9.0.6.1


They changed their site around a bit - that's the main problem with making a scraper... I'll see if I can figure a way to update this.

Admin - Great Lakes Web Designs
Theme Designer - WebSite Guru Designs
Site Admin - Families with Food Allergies

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Linux 2.6.27-grsec/Apache 2.2.11/MySQL 5.0.67-community-log/PHP 5.2.8/DF 9.2.1


Yep, pretty simple fix.
Change function getHoroscope to:
function getHoroscope () { $found = FALSE; $url = $this->buildUrl(); $file = fopen($url, 'r'); if (!$file) { echo "error: remote file '" . $url . "' could not be opened!"; exit; } while (!feof($file)) { $line = fgets($file); if (eregi("intelliTxt", $line, $result)) { $found = TRUE; $horoscope = trim($line); break; } } fclose($file); return $horoscope; }

Full module attached

Admin - Great Lakes Web Designs
Theme Designer - WebSite Guru Designs
Site Admin - Families with Food Allergies

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Linux 2.6.27-grsec/Apache 2.2.11/MySQL 5.0.67-community-log/PHP 5.2.8/DF 9.2.1


That did the trick....thanx!!!

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
FreeBSD 4.10/Apache 1.3.33/MySQL4.1.15/PHP4.4.1/Dragonfly9.0.6.1

All times are UTC