? openads.admin.inc Index: openads.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/openads/openads.module,v retrieving revision 1.7.2.4.2.1 diff -U3 -r1.7.2.4.2.1 openads.module --- openads.module 14 Apr 2008 12:01:16 -0000 1.7.2.4.2.1 +++ openads.module 14 May 2008 17:12:11 -0000 @@ -1,4 +1,4 @@ - 'OpenX (Openads) adserver configuration', - 'description' => 'Configure OpenX (Openads) AdServer integration behavior and appearance.', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('openads_admin_settings'), - 'access callback' => 'user_access', - 'access arguments' => array('administer site configuration'), - 'type' => MENU_NORMAL_ITEM, // optional - ); - - return $items; -} - -/** - * Implemenation of hook_settings(). - */ -function openads_admin_settings() { - $form = array(); - - $form['adserver'] = array( - '#type' => 'fieldset', - '#title' => t('Adserver settings'), - '#description' => t('Select which delivery method to use - Javascript, Remote, Local or XML-RPC. Note Javascript will be used if caching is enabled and the current user is not logged in.'), - '#collapsible' => TRUE, - ); - - if (variable_get('openads_delivery_method', 'js') == 'xmlrpc') { - $PEAR_missing = $openads_xmlrpc_missing = FALSE; - if (!@include('XML/RPC.php')) { - $PEAR_missing = TRUE; - } - if (!@include('openads-xmlrpc.inc.php')) { - $openads_xmlrpc_missing = TRUE; - } - } - - $form['adserver']['openads_delivery_method'] = array( - '#type' => 'radios', - '#title' => t('Delivery Method'), - '#description' => t('Select the delivery method to use.
Note: To use the Local method OpenX and your banners must be stored on the same machine with the same top level domain.
Note: To use XML-RPC method you must have the PEAR XML-RPC package installed and the OpenX openads-xmlrpc.inc.php file must be in your PHP include path. '. ($PEAR_missing ? '
PEAR XML-RPC appears to not be installed! You must install the PEAR XML-RPC package.' : '') . ($openads_xmlrpc_missing ? '
opeands-xmlrpc.inc.php file appears to not be installed! You must put the file openads-xmlrpc.inc.php from the OpenX installation files into your PHP path.' : ''), array('@link' => 'http://pear.php.net/package/XML_RPC')), - '#options' => array('js' => 'Javascript', 'remote' => 'Remote', 'local' => 'Local', 'xmlrpc' => 'XML-RPC'), - '#default_value' => variable_get('openads_delivery_method', 'js'), - ); - - $form['adserver']['openads_use_text_below_image'] = array( - '#type' => 'checkbox', - '#title' => t('Enable OpenX "Text below Image"'), - '#description' => t('OpenX is able to show a user defined text below each banner. Click this checkbox to enable this feature. Only availble on Javascript, Local and XML-RPC delivery methods.'), - '#default_value' => variable_get('openads_use_text_below_image', 0), - ); - $form['adserver']['server_access_paths'] = array( - '#type' => 'fieldset', - '#title' => t('OpenX Server Access Paths'), - '#description' => t('This group of settings defines access paths to specific elements of your OpenX server. These settings are located on your OpenX server at Settings -> Main Settings -> Delivery Settings'), - ); - $form['adserver']['server_access_paths']['openads_delivery_url'] = array( - '#type' => 'textfield', - '#default_value' => variable_get('openads_delivery_url', ''), - '#title' => t('The OpenX delivery url'), - '#description' => t('The OpenX server address, for example "ads.example.org/delivery". "http://" is automatically prefixed.'), - '#required' => TRUE, - ); - $form['adserver']['server_access_paths']['openads_delivery_url_https'] = array( - '#type' => 'textfield', - '#default_value' => variable_get('openads_delivery_url_https', ''), - '#title' => t('The OpenX https delivery url'), - '#description' => t('The OpenX server address, for example "ads.example.org/delivery". "https://" is automatically prefixed.') - ); - - $form['adserver']['javascript_options'] = array( - '#type' => 'fieldset', - '#title' => t('Javascript options'), - '#description' => t('The following options affect the Javascript invocation method.'), - '#collapsible' => TRUE, - '#collapsed' => TRUE, - ); - $form['adserver']['javascript_options']['openads_js_delivery_filename'] = array( - '#type' => 'textfield', - '#default_value' => variable_get('openads_js_delivery_filename', 'ajs.php'), - '#title' => t('The OpenX JavaScript delivery filename'), - '#description' => t('The OpenX JavaScript delivery filename for example "ajs.php"'), - '#required' => TRUE, - ); - - $form['adserver']['remote_options'] = array( - '#type' => 'fieldset', - '#title' => t('Remote options'), - '#description' => t('The following options affect the Remote invocation method.'), - '#collapsible' => TRUE, - '#collapsed' => TRUE, - ); - $form['adserver']['remote_options']['openads_remote_delivery_click_filename'] = array( - '#type' => 'textfield', - '#default_value' => variable_get('openads_remote_delivery_click_filename', 'ck.php'), - '#title' => t('The OpenX Remote delivery click filename'), - '#description' => t('The OpenX Remote delivery click filename for example "ck.php"') - ); - $form['adserver']['remote_options']['openads_remote_delivery_view_filename'] = array( - '#type' => 'textfield', - '#default_value' => variable_get('openads_remote_delivery_view_filename', 'avw.php'), - '#title' => t('The OpenX Remote delivery view filename'), - '#description' => t('The OpenX Remote delivery view filename for example "avw.php"') - ); - - $form['adserver']['local_options'] = array( - '#type' => 'fieldset', - '#title' => t('Local options'), - '#description' => t('The following options affect the Local invocation method.'), - '#collapsible' => TRUE, - '#collapsed' => TRUE, - ); - $form['adserver']['local_options']['openads_local_delivery_base_path'] = array( - '#type' => 'textfield', - '#default_value' => variable_get('openads_local_delivery_base_path', ''), - '#title' => t('The OpenX Local delivery base path'), - '#description' => t('The base path of the OpenX installation for example "/opt/www/openx.example.com"') - ); - $form['adserver']['local_options']['openads_local_delivery_filename'] = array( - '#type' => 'textfield', - '#default_value' => variable_get('openads_local_delivery_filename', 'alocal.php'), - '#title' => t('The OpenX Local delivery filename'), - '#description' => t('The OpenX Local delivery filename for example "alocal.php"') - ); - - $form['adserver']['xmlrpc_options'] = array( - '#type' => 'fieldset', - '#title' => t('XML-RPC options'), - '#description' => t('The following options affect the XML-RPC invocation method.'), - '#collapsible' => TRUE, - '#collapsed' => TRUE, - ); - $form['adserver']['xmlrpc_options']['openads_xmlrpc_delivery_filename'] = array( - '#type' => 'textfield', - '#default_value' => variable_get('openads_xmlrpc_delivery_filename', 'axmlrpc.php'), - '#title' => t('The OpenX XML-RPC delivery filename'), - '#description' => t('The OpenX XML-RPC delivery filename for example "axmlrpc.php"') - ); - $form['adserver']['xmlrpc_options']['openads_xmlrpc_port'] = array( - '#type' => 'textfield', - '#title' => t('XML-RPC Port'), - '#description' => t('If your XML-RPC server is on a non-standard port, specify it here.'), - '#default_value' => variable_get('openads_xmlrpc_port', 80), - '#size' => 4, - ); - $form['adserver']['xmlrpc_options']['openads_xmlrpc_use_ssl'] = array( - '#type' => 'checkbox', - '#title' => t('Use SSL'), - '#description' => t('If you wish to use SSL to connect to your OpenX XML-RPC server, check this option'), - '#default_value' => variable_get('openads_xmlrpc_use_ssl', ''), - ); - $form['adserver']['xmlrpc_options']['openads_xmlrpc_timeout'] = array( - '#type' => 'textfield', - '#title' => t('Timeout'), - '#description' => t('Set the timeout in seconds to connect to the OpenX XML-RPC server'), - '#default_value' => variable_get('openads_xmlrpc_timeout', 2), - '#size' => 4, + 'file' => 'openads.admin.inc', + 'title' => 'OpenX (Openads) adserver configuration', + 'description' => 'Configure OpenX (Openads) AdServer integration behavior and appearance.', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('openads_admin_settings'), + 'access callback' => 'user_access', + 'access arguments' => array('administer site configuration'), + 'type' => MENU_NORMAL_ITEM, // optional ); - $form['publisher'] = array( - '#type' => 'fieldset', - '#title' => t('Publisher'), - '#description' => t('The following settings can be copied from the publisher page of your OpenX adserver.'), - '#collapsible' => TRUE, - ); - $form['publisher']['openads_id'] = array( - '#type' => 'textfield', - '#default_value' => variable_get('openads_id', ''), - '#title' => t('Publisher ID'), - '#description' => t("This is the publisher ID of the publisher you wish to serve ads from."), - '#required' => TRUE, - '#size' => 6, - ); - $form['publisher']['openads_num_zones'] = array( - '#type' => 'textfield', - '#default_value' => variable_get('openads_num_zones', '5'), - '#title' => t('The number of zones defined'), - '#description' => t('This is the number of zones you can enter below'), - '#size' => 6, - ); - - $form['openads_zones'] = array( - '#theme' => 'openads_admin_settings_form', - '#type' => 'fieldset', - '#title' => t('Zones'), - '#description' => t('Configure your zones here. '. - ''. - 'Once you have convigured your zones, you can invoke them within your templates using either the '. - 'index number (0-4, for example, this is the first column) or by the names you gave your zones. '. - 'The according code is <?php print openads_invoke(0);> or <?php print openads_invoke("my zone name");>'), - '#collapsible' => TRUE, - ); - $zones = openads_get_zones(); - $roles = user_roles(); - $i = 0; - foreach ($zones as $zone) { - $form['openads_zones'][$i]['openads_zones_id_'. $i] = array( - '#type' => 'textfield', - '#default_value' => $zone['id'], - '#size' => 6, - ); - $form['openads_zones'][$i]['openads_zones_name_'. $i] = array( - '#type' => 'textfield', - '#default_value' => $zone['name'], - '#size' => 20, - ); - $form['openads_zones'][$i]['openads_zones_code_'. $i] = array( - '#type' => 'textfield', - '#default_value' => $zone['code'], - '#size' => 10, - ); - foreach ($roles as $key => $display) { - $element_key = 'openads_zones_roles_'. $key .'_'. $i; - $form['openads_zones'][$i][$element_key] = array( - '#type' => 'checkbox', - '#default_value' => $zone['roles'][$key], - ); - } - $i++; - } - - return system_settings_form($form); + return $items; } /** @@ -353,7 +140,7 @@ } $output .= theme('table', $header, $rows); - return $output; + return $output; } /** @@ -367,8 +154,8 @@ $blocks[$index] = array( 'info' => t('OpenX Zone '. $zone['id'] .' ('. ($zone['name'] != '' ? $zone['name'] : 'untitled') .')'), 'cache' => BLOCK_NO_CACHE, - 'weight' => 0, - 'enabled' => 0, + 'weight' => 0, + 'enabled' => 0, 'region' => 'left' ); } @@ -381,8 +168,8 @@ 'content' => theme('openads_block', $delta) ); return $block; - } -} + } +} /** * Theme function for openads_block() @@ -406,7 +193,7 @@ '; drupal_set_html_head($channel); - drupal_add_js(drupal_get_path('module', 'openads') .'/openads.js'); + drupal_add_js(drupal_get_path('module', 'openads') .'/openads.js'); } /** @@ -417,14 +204,14 @@ } /** - * Returns all stored zones + * Returns all stored zones */ function openads_get_zones() { static $ret = NULL; if ($ret) { return $ret; } - + $c = variable_get('openads_num_zones', 5); $ret = array(); for ($i = 0; $i < $c; $i ++) { @@ -462,7 +249,7 @@ * Builds and returns at_channel content */ function openads_channel() { - return theme('openads_channel'); + return theme('openads_channel'); } /** @@ -472,7 +259,7 @@ global $user; $url = check_plain($_GET['q']); $channel[] = variable_get('openads_id', '') .'/'. $url; - + if ($user) { if ($user->uid == 1) { $channel[] = 'type_admin'; @@ -480,14 +267,14 @@ foreach ($user->roles as $roleid => $rolename) { $channel[] = 'type_'. str_replace(' ', '_', $rolename); } - } - - $channel[] = 'url_'. $url; + } + + $channel[] = 'url_'. $url; return implode(',', $channel); } /** - * Builds the call to OpenX + * Builds the call to OpenX */ function openads_invoke($index_or_key) { $zone = openads_get_zone($index_or_key); @@ -503,7 +290,7 @@ return ''; } } - + return theme('openads_invoke', $id, $code); }