00001 <?php
00002
00015
00016
00017 class OpenAdsConnection {
00019 var $installPath;
00020
00022 var $config;
00023
00025 var $errors;
00026
00028 var $plugin;
00029
00035 function OpenAdsConnection(&$plugin, $installPath) {
00036 $this->plugin =& $plugin;
00037 $this->installPath = $installPath;
00038 $this->errors = array();
00039 }
00040
00041 function getConfigFilename() {
00042 $variablesScriptPath = $this->installPath . '/variables.php';
00043 if (!file_exists($variablesScriptPath)) return null;
00044 require_once($variablesScriptPath);
00045 return $this->installPath . '/var/' . getHostName() . '.conf.php';
00046 }
00047
00048 function isConfigured() {
00049 return file_exists($this->getConfigFilename());
00050 }
00051
00052 function loadConfig() {
00053 $fp = null;
00054 $config = @parse_ini_file($this->getConfigFilename(), true);
00055 if (!$config) {
00056 $this->errors[] = Locale::translate('plugins.generic.openads.error.configFileNotFound', array('filename' => $configFilename));
00057 return false;
00058 }
00059
00060 if ( !isset($config['database']['type']) ||
00061 $config['database']['type'] != 'mysql' ||
00062 !isset($config['database']['username']) ||
00063 !isset($config['database']['password']) ||
00064 !isset($config['database']['name']) ||
00065 !isset($config['table']['prefix'])
00066 ) {
00067
00068 $this->errors[] = Locale::translate('plugins.generic.openads.error.missingParameter');
00069 return false;
00070 }
00071
00072 $this->config = $config;
00073
00074 return true;
00075 }
00076
00077 function getErrors() {
00078 return $this->errors;
00079 }
00080
00081 function getAds() {
00082 $conn =& $this->getConnection();
00083 $result = mysql_query('SELECT * FROM ' . $this->config['table']['prefix'] . 'zones', $conn);
00084
00085 $returner = array();
00086 $this->plugin->import('Ad');
00087 while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
00088 $ad =& new Ad($this);
00089 $ad->setName($row['zonename']);
00090 $ad->setAdId($row['zoneid']);
00091 $returner[] =& $ad;
00092 unset($ad);
00093 }
00094
00095 mysql_free_result($result);
00096 mysql_close($conn);
00097 return $returner;
00098 }
00099
00103 function &getConnection() {
00104 $dbPort = !empty($this->config['database']['port'])?((int) $this->config['database']['port']):3306;
00105
00106 $dbHost = $this->config['database']['host'];
00107 $conn = mysql_connect ($dbHost . ':' . $dbPort, $this->config['database']['username'], $this->config['database']['password']);
00108
00109 if (!$conn) {
00110 $this->errors[] = Locale::translate('plugins.generic.openads.error.dbConnectionError');
00111 $returner = false;
00112 return $returner;
00113 }
00114 mysql_select_db ($this->config['database']['name'], $conn);
00115 return $conn;
00116 }
00117
00118 function getAdHtml($adId) {
00119 if (!$adId) return '';
00120 require_once($this->installPath . '/phpadsnew.inc.php');
00121 if (!isset($phpAds_context)) $phpAds_context = array();
00122 $result = view_raw ("zone:$adId", 0, '', '', '0', $phpAds_context);
00123 return $result['html'];
00124 }
00125 }
00126
00127 ?>