'logotool/logo',
'callback' => 'logotool_logo',
'access' => TRUE,
'type' => MENU_CALLBACK
);
$items[] = array('title' => 'logotool info',
'path' => 'admin/settings/logotool/logos',
'callback' => 'logotool_logos',
'access' => user_access('administer logotool'),
'type' => MENU_NORMAL_ITEM
);
}
return $items;
} // logotool_menu
/**
* Implementation of hook_settings
*/
function logotool_settings() {
$form['logo1'] = array(
'#type' => 'fieldset',
'#title' => t('Logo Tool Settings:'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['logo1']['logotool_path'] = array(
'#type' => 'textfield',
'#title' => t('Path to default/ main logo'),
'#default_value' => variable_get('logotool_path', 'misc/druplicon.png'),
'#description' => t('The path to the file you would like to use as your default/ main logo.'),
);
$form['logo1']['logotool_folder'] = array(
'#type' => 'textfield',
'#title' => t('Path to your logos folder'),
'#default_value' => variable_get('logotool_folder', LT_CWD),
'#description' => t('The path to a folder which will contain your logos.'),
);
$form['logo1']['logotool_display'] = array(
'#type' => 'select',
'#title' => t('Display mode'),
'#default_value' => variable_get('logotool_display', 0),
'#options' => array(0 => 'Normal mode', 1 => 'Random logos', 2 => 'Specified logos', 3 => 'Specified AND Random logos'),
'#description' => t('Normal mode: Displays the default/ main logo on every page.
Random logos: Displays a random logo on every page refresh.
Specified logos: Displays a specific logo on each specified page from the
information below, pages not specified will display the default/ main logo.
Specified AND Random logos: Displays a specific logo on each specified page from the
information below, pages not specified will display a random logo.
'
),
);
$form['logo1']['logotool_pages'] = array(
'#type' => 'textarea',
'#title' => t('Specific logos for specific pages'),
'#default_value' => variable_get('logotool_pages', ''),
'#cols' => 45,
'#rows' => 50,
'#description' => t('Specify here pages which will have a specific logo, any pages not specified
will display the default/ main logo.
Structure your entries like this:
node/1|logo1.jpg
node/2|logo5.jpg
admin*|admin.png
Note that you don\'t have to specify the full path to your logos, it is taken from the folder
setting above and also note that a \'|\' separates the address from it\'s logo
and a newline separates each entry.
The wildcard character \'*\' can be
used to apply the logo recursively as in the example above. \'admin*\' will match menu item \'admin\'
and everything above it. \'admin/*\' however will only match what\'s above the admin menu item but
NOT THAT ITEM ITSELF.
Exact matches always take preference over wildcard entries, so it\'s
possible to use:
node/add*|createcontent.png
node/add/story|addstory.png
If you\'re mixing wildcards entries please be aware that the first valid match takes priority, so
you\'ll need to structure those entries first come, first served like this:
admin/settings*|settings.png
admin*|admin.png
Groups: Also specify here pages which will have a specific logo according to their group.
For groups, structure your entries like this:
group:21|logo1.jpg
group:72|logo5.jpg
group:105|admin.png
'
),
);
if (!is_dir(variable_get('logotool_folder', LT_CWD))) {
drupal_set_message(t('Incorrect path set for logo folder'), 'error');
}
else {
$result = file_scan_directory(variable_get('logotool_folder', LT_CWD), '.*', array('.', '..', 'CVS', 'placelogosinhere'));
if (!$result) {
drupal_set_message(t('Logo folder is empty/ files cannot be read by the server?'), 'error');
}
logotool_check();
}
return $form;
} // logotool_settings
/**
* Implementation of hook_init
*/
function logotool_init() {
switch (variable_get('logotool_display', 0)) {
case '0':
variable_set('logotool_logo', variable_get('logotool_path', 'misc/druplicon.png'));
break;
case '1':
$logos = file_scan_directory(variable_get('logotool_folder', LT_CWD), '.*', array('.', '..', 'CVS', 'placelogosinhere'));
variable_set('logotool_logo', array_rand($logos));
break;
case '2':
// Straight test for match
$path = preg_quote($_GET['q'], '/');
preg_match("/$path\|(.*)/i", variable_get('logotool_pages', ''), $match);
//=========================================================
// Test for group ID - need to convert to string so program
// doesn't try to match '0' alone
//=========================================================
if (!$match) {
$ggid = '00';
$gid = logotool_getgroup();
if ($gid != 0) {
$ggid = ( string ) $gid;
}
preg_match("/group\:$ggid\|(.*)/i", variable_get('logotool_pages', ''), $match);
}
//
// Test for aliases
if (!$match) {
$path = preg_quote(drupal_get_path_alias($_GET['q']), '/');
preg_match("/$path\|(.*)/i", variable_get('logotool_pages', ''), $match);
}
// Test for wildcards
if (!$match) {
preg_match_all("/(.*)\*\|(.*)/", variable_get('logotool_pages', ''), $wildcards);
foreach ($wildcards[1] as $no => $path) {
$path = preg_quote($path, '/');
preg_match("/$path.*/", $_GET['q'], $match);
if ($match) {
$match[1] = $wildcards[2][$no];
break;
}
}
}
// If there's a match, set the logo variable
if ($match) {
$logo = trim(variable_get('logotool_folder', LT_CWD).'/'.$match['1']);
variable_set('logotool_logo', $logo);
}
// Else set the logo to default (unless the image display routine is calling this function)
elseif ($_GET['q'] != 'logotool/logo') {
variable_set('logotool_logo', variable_get('logotool_path', 'misc/druplicon.png'));
}
break;
case '3':
// Straight test for match
$path = preg_quote($_GET['q'], '/');
preg_match("/$path\|(.*)/i", variable_get('logotool_pages', ''), $match);
//=========================================================
// Test for group ID - need to convert to string so program
// doesn't try to match '0' alone
//=========================================================
if (!$match) {
$ggid = '00';
$gid = logotool_getgroup();
if ($gid != 0) {
$ggid = ( string ) $gid;
}
preg_match("/group\:$ggid\|(.*)/i", variable_get('logotool_pages', ''), $match);
}
//
// Test for aliases
if (!$match) {
$path = preg_quote(drupal_get_path_alias($_GET['q']), '/');
preg_match("/$path\|(.*)/i", variable_get('logotool_pages', ''), $match);
}
// Test for wildcards
if (!$match) {
preg_match_all("/(.*)\*\|(.*)/", variable_get('logotool_pages', ''), $wildcards);
foreach ($wildcards[1] as $no => $path) {
$path = preg_quote($path, '/');
preg_match("/$path.*/", $_GET['q'], $match);
if ($match) {
$match[1] = $wildcards[2][$no];
break;
}
}
}
// If there's a match, set the logo variable
if ($match) {
$logo = trim(variable_get('logotool_folder', LT_CWD).'/'.$match['1']);
variable_set('logotool_logo', $logo);
}
// Else set the logo to random (unless the image display routine is calling this function)
elseif ($_GET['q'] != 'logotool/logo') {
$logos = file_scan_directory(variable_get('logotool_folder', LT_CWD), '.*', array('.', '..', 'CVS', 'placelogosinhere'));
variable_set('logotool_logo', array_rand($logos));
}
break;
} // end switch
} // logotool_init
/**
* Returns the site logo
*/
function logotool_logo() {
$logo = $_GET['logo'] ? variable_get('logotool_folder', LT_CWD).'/'.str_replace('../', '', $_GET['logo']) : variable_get('logotool_logo', '');
$info = image_get_info($logo);
$headers = array('Content-Type: '.$info['mime_type']);
foreach ($headers as $header) {
header($header);
}
$im = @readfile($logo);
if (!$im) {
$im = imagecreate(175, 20);
$bg = imagecolorallocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 255, 0, 0);
imagestring($im, 5, 2, 1, "Error Creating Logo", $textcolor);
header("Content-type: image/png");
imagepng($im);
imagedestroy($im);
}
} // logotool_logo
/**
* Returns a list of the logos contained in 'logotool_folder'
*/
function logotool_logos() {
$result = file_scan_directory(variable_get('logotool_folder', LT_CWD), '.*', array('.', '..', 'CVS', 'placelogosinhere'));
if (!$result) {
drupal_set_message(t('Logo folder is either empty or the logo files cannot be read by the server'), 'error');
$list[] = array(array('data' => 'None Found'));
}
else {
foreach ($result as $a) {
$file = str_replace(array('/'), array('\/'), $a->basename);
preg_match_all("/(.*)\|$file/", variable_get('logotool_pages', ''), $match);
$count = count($match['0']);
if (!$count) {
$list[] = array(array('data' => $a->basename), array('data' => ''), array('data' => '
', 'align' => 'center'));
}
unset($flag);
foreach ($match[0] as $no => $m) {
if (!$flag) {
$list[] = array(array('data' => $a->basename, 'rowspan' => $count), array('data' => $match[1][$no]), array('data' => '
', 'align' => 'center', 'rowspan' => $count));
$flag = TRUE;
}
else {
$list[] = array(array('data' => $match[1][$no]));
}
}
}
}
logotool_check();
return theme('table', array('Filename', 'Path', 'Logo'), $list, array('border' => '1'));
} // logotool_logos
/**
* Checks that all the logos specified actually exist in the logo folder
*/
function logotool_check() {
preg_match_all("/.*\|(.*)/", variable_get('logotool_pages', ''), $match);
foreach ($match['0'] as $no => $m) {
if (!is_file(trim(variable_get('logotool_folder', LT_CWD).'/'.$match[1][$no]))) {
drupal_set_message(t('Entry: \'%file\' is incorrect, logo either does not exist or is not readable by the server', array('%file' => $m)), 'error');
}
}
} // logotool_check
/**
* Returns groupID
*/
function logotool_getgroup () {
global $user;
$uid = $user->uid;
$gid = 0;
$nodeID = 0;
$uri_request_id = $_SERVER['REQUEST_URI'];
$arg = explode("/", $uri_request_id);
$group_node = og_get_group_context();
$gid02 = $group_node->nid;
$gid = $gid02;
if ($gid02 === null) $gid = 0;
//
// If the above doesn't get the groupID, then we start trying stuff
//
if ($gid == 0) {
// http://www.mysite.com/node/79
if (arg(0) == 'node' && is_numeric(arg(1)) && is_null(arg(2))) {
$nodeID = (int)arg(1);
//
// If this is an anonymous user;
//
// if ($uid == 0) {
// $gid = logotool_getanongid($nodeID);
// } else {
// $gid = logotool_getgid($nodeID, $uid);
// }
// Actually, I think we should always search by node alone.
$gid = logotool_getanongid($nodeID);
}
// http://www.mysite.com/node/79/edit
// http://www.mysite.com/node/79/outline
// http://www.mysite.com/node/79/track
if (arg(0) == 'node' && is_numeric(arg(1)) && (arg(2) == 'edit' || arg(2) == 'outline' || arg(2) == 'track' ) ) {
$nodeID = (int)arg(1);
//
// If this is an anonymous user;
//
// if ($uid == 0) {
// $gid = logotool_getanongid($nodeID);
// } else {
// $gid = logotool_getgid($nodeID, $uid);
// }
// Actually, I think we should always search by node alone.
$gid = logotool_getanongid($nodeID);
}
// Here we get the gid directly
//
// http://www.mysite.com/og/users/72
// http://www.mysite.com/og/manage/72
if (arg(0) == 'og' && is_numeric(arg(2)) && is_null(arg(3))) {
$gid = (int)arg(2);
}
// og_calendar
//
// http://www.mysite.com/og_calendar/72
if (arg(0) == 'og_calendar' && is_numeric(arg(1)) && is_null(arg(2))) {
$gid = (int)arg(1);
}
// og_forum
// 0 1 2 3
// http://www.mysite.com/og_forum/39/72?edit[og_groups][]=72
if ($arg[1] == 'og_forum' && strpos($arg[3], 'og_groups') !== false && (!is_null($arg[3])) ) {
$subsections = explode("=", $arg[3]);
$gid = (int)$subsections[1];
}
// og create nodes
// 0 1 2 3
// http://www.mysite.com/node/add/forum?edit[og_groups][]=72
// http://www.mysite.com/node/add/simplenews?edit[og_groups][]=72
// http://www.mysite.com/node/add/webform?edit[og_groups][]=72
// http://www.mysite.com/node/add/video?edit[og_groups][]=72
// http://www.mysite.com/node/add/page?edit[og_groups][]=72
// http://www.mysite.com/node/add/blog?edit[og_groups][]=72
// http://www.mysite.com/node/add/event?edit[og_groups][]=72
// http://www.mysite.com/node/add/poll?edit[og_groups][]=72
if ($arg[1] == 'node' && strpos($arg[3], 'og_groups') !== false && (!is_null($arg[3])) ) {
$subsections = explode("=", $arg[3]);
$gid = (int)$subsections[1];
}
} // end $gid if
return $gid;
} // logotool_getgroup()
function logotool_getgid($nodeID, $uid) {
// This will return a $gid based upon the $nodeID and $uid supplied
$gid = 0;
$result = db_query("select node_access.gid from node_access INNER JOIN og_uid ON node_access.gid = og_uid.nid WHERE node_access.nid = $nodeID AND og_uid.uid = $uid");
while($t = db_fetch_object($result)) {
$gid = $t->gid;
}
return $gid;
} // end logotool_getgid()
function logotool_getanongid($nodeID) {
// This will return $gid based upon the $nodeID alone -- this is for anonymous users
$gid = 0;
//
// First let's see if this nodeID is a group itself
//
$result = db_query("select og.nid from og WHERE og.nid = $nodeID");
while($t = db_fetch_object($result)) {
$gid = $t->nid;
}
//
// If not, then search the node_access table realm
//
if ($gid == 0) {
$result = db_query("select node_access.gid from node_access WHERE node_access.nid = $nodeID");
while($t = db_fetch_object($result)) {
$gid = $t->gid;
}
}
return $gid;
} // end logotool_getanongid()