/** compute URL for a background image based on current time and index * * this routine returns a URL to be used as a background image. The * URL is different depending on the time of day and the $index parameter. * The latter is thought to be the position of the current item in the * main navigation (starting at 1) or 0 in case no item in the main * navigation is current. * * Configuration is done via two parameters: * the path in $this->config['header_banners_directory'] and * the interval in $this->config['header_banners_interval']. * * The interval is expressed in minutes. It means that a particular page * has the same background image for the duration of the interval and * another one in the next interval. The banners directory is supposed * to contain banner files of the correct dimensions, e.g. 980x170. * * If the specified directory starts with a '/' it is assumed to start in * the data root, e.g. something like /areas/exemplum/banners. This will * eventually lead to a URL of the form * /file.php/areas/exemplum/banners/mentha-banner.jpg using * was_file_url() * * If the specified directory does NOT start with a '/' it is assumed to * be a directory relative to the directory where index.php and friends * live, unless it starts with program/ in which case it is a static dir * somewhere in the program hierarchy. This is done via was_url(). * * @param int $index indicates current main navigation item or 0 for none * @param bool $fully_qualified if TRUE forces the URL to contain a scheme, authority etc. * @return string ready to use URL * @uses was_file_url() * @uses was_url() */ function cornelia_get_background_url($index, $fully_qualified = FALSE) { global $CFG; // // 0 -- sanity checks // $path = trim($this->config['header_banners_directory']); $interval = intval($this->config['header_banners_interval']); if (empty($path) || $interval <= 0) { return FALSE; } if (!utf8_validate($path) || strpos('/' . $path . '/', '/../') !== FALSE) { logger(sprintf("%s.%s(): invalid path '%s'; bailing out", __CLASS__, __FUNCTION__, $path)); return FALSE; } // // 1 -- where to find the files? // if (substr($path, 0, 1) == '/') { $full_path = $CFG->datadir . $path; } elseif (substr($path, 0, 8) == 'program/') { $full_path = $CFG->progdir . substr($path, 7); } else { $full_path = $CFG->dir . '/' . $path; } // get rid of trailing slash if any if (substr($full_path, -1) == '/') { $full_path = substr($full_path, 0, -1); } if (($handle = @opendir($full_path)) === FALSE) { logger(sprintf("%s.%s(): cannot open directory '%s'", __CLASS__, __FUNCTION__, $path)); return FALSE; } // // 2 -- scan the directory for graphics files (skip the thumbnails) // $prefix_len = strlen(THUMBNAIL_PREFIX); $extensions = explode(',', str_replace(array('.', ' '), '', $CFG->filemanager_images)); $files = array(); while (($entryname = readdir($handle)) !== FALSE) { $full_entryname = $full_path . '/' . $entryname; if ($entryname == '.' || $entryname == '..' || $entryname == 'index.html' || is_link($full_entryname) || !is_file($full_entryname)) { continue; } // we are now fairly sure $entryname is a genuine file. check extension (if any) if (strpos($entryname, '.') === FALSE) { $ext = ''; } else { $components = explode('.', $entryname); $ext = utf8_strtolower(array_pop($components)); unset($components); } if (array_search($ext, $extensions) === FALSE) { // not an image file, next please continue; } if (substr($entryname, 0, $prefix_len) == THUMBNAIL_PREFIX) { // thumbnail, next please continue; } if (($image_info = @getimagesize($full_entryname)) === FALSE) { // not an image, next please continue; } $files[] = $entryname; } closedir($handle); // // 3 -- is there any image at all? // if (($n = sizeof($files)) <= 0) { return FALSE; } if ($n == 1) { $entryname = $files[0]; // Looks like Ford T: choice of 1 } else { // use a different image every $interval minutes $entryname = $files[($index + time() / (60 * $interval)) % $n]; } if (substr($path, 0, 1) == '/') { return was_file_url($path . '/' . $entryname, $fully_qualified); } else { return was_url($path . '/' . $entryname, $fully_qualified); } }
/** construct an image tag with the area logo * * This constructs HTML-code that displays the logo, * maybe in the form of a clickable map. * * This routine honours the preview_mode by replacing the * URLs with a bare "#" in order to prevent the visiter * to actually surf away from a preview * * @param string $m left margin for increased readability * @return string constructed image tag * @todo should we take path_info into account here too???? how about /area/aaa/node/nnn instead of /aaa/nnn??? */ function get_logo($m = '') { global $WAS_SCRIPT_NAME, $USER; if (!isset($this->config['logo_image'])) { return ''; } // 1 -- prepare common attributes for logo image (alt height title width and also src $attributes = array('title' => isset($this->config['logo_title']) ? $this->config['logo_title'] : $this->area_record['title'], 'alt' => isset($this->config['logo_alt']) ? $this->config['logo_alt'] : t('alt_logo', $this->domain)); if (isset($this->config['logo_width'])) { $attributes['width'] = $this->config['logo_width']; } if (isset($this->config['logo_height'])) { $attributes['height'] = $this->config['logo_height']; } $src = was_url($this->config['logo_image']); // apply some heuristics to perhaps qualify the src path // 2 -- maybe build one or more hotspots or otherwise create a simple clickable logo $hotspots = $this->config['logo_hotspots']; if ($hotspots > 0) { // logo is a clickable map with at least 1 hotspot $mapname = "logo_hotspots"; $attributes['usemap'] = '#' . $mapname; $logo = $this->rosalina_hotspot_map($USER->is_logged_in, $mapname, $hotspots, $this->config, $m) . $m . html_img($src, $attributes); } else { $title = $this->area_record['title']; $params = array('area' => $this->area_id); $href = was_node_url(NULL, $params, $title, $this->preview_mode); $logo = $m . html_a($href, NULL, NULL, html_img($src, $attributes)); } return $logo; }
/** construct an anchor from a node record * * This constructs an array with key-value-pairs that can be used to * construct an HTML anchor tag. At least the following keys are created * in the resulting array: 'href', 'title' and 'anchor'. The latter is either * the text or a referenct to an image that is supposed to go between the * opening A-tag and closing A-tag. Furtermore an optional key is created: target. * The contents of the input array $attributes is merged into the result. * * If the parameter $textonly is TRUE the key 'anchor' is always text. * If $textonly is NOT TRUE, the 'anchor' may refer to an image. * * Note that the link text is always non-empty. If the node record has an * empty link_text, the word 'node' followed by the node_id is returned. * (Otherwise it will be hard to make an actual clickable link). * * Note that we attempt to create 'friendly' URLs, ie. URLs that look very * much like a plain path, e.g. * http://www.exemplum.eu/index.php/3/Information_about_the_school.html rather than * http://www.exemplum.eu/index.php?node=3 * When bookmarking a page, the part 'Information_about_the_school.html' makes it * easier to recognise the bookmark than when it is just some number. * Choice for friendly URLs is made in the global (site) configuration. * * @param array $node_record the node record to convert * @param array $attributes optional attributes to add to the HTML A-tag * @param bool $textonly if TRUE, no clickable images will be returned * @return string an HTML A-tag that links to the node OR to the external link (if any) * @uses was_node_url() */ function node2anchor($node_record, $attributes = NULL, $textonly = FALSE) { $node_id = intval($node_record['node_id']); $title = $node_record['title']; $link_text = $node_record['link_text']; if (empty($link_text)) { $link_text = "[ " . strval($node_id) . " ]"; } $params = NULL; $href = was_node_url($node_record, $params, $title, $this->preview_mode); if (!is_array($attributes)) { $attributes = array(); } $attributes['title'] = $title; if (!empty($node_record['link_target'])) { $attributes['target'] = $node_record['link_target']; } if ($textonly || empty($node_record['link_image'])) { $anchor = $link_text; } else { $img_attr = array('width' => intval($node_record['link_image_width']), 'height' => intval($node_record['link_image_height']), 'alt' => $link_text); $anchor = html_img(was_url($node_record['link_image']), $img_attr); } return html_a($href, $params, $attributes, $anchor); }
/** add a navigation bar / tool bar for a snapshot * * this bar contains the following elements: * - double arrow left links to the first snapshot in the series * - left arrow links to the previous snapshot in the series * - up arrow links to the thumbnails overview * - right arrow links to the next snapshot in the series * - double right arrow links to the last snapshot in the series * - position indicator (snapshot i from n snapshots) in the form: i/n * * @param int $snapshot_index indicates which element of $snapshots contains the current snapshot * @return void navigation bar added to output * @todo clean up this ugly code */ function add_snapshot_navbar($snapshot_index, $m = ' ') { $images = array(0 => array('black' => 'llb.png', 'gray' => 'llg.png', 'title' => t('move_first_title', $this->domain), 'alt' => t('move_first_alt', $this->domain)), 1 => array('black' => 'lb.png', 'gray' => 'lg.png', 'title' => t('move_prev_title', $this->domain), 'alt' => t('move_prev_alt', $this->domain)), 2 => array('black' => 'ub.png', 'gray' => 'ug.png', 'title' => t('move_up_title', $this->domain), 'alt' => t('move_up_alt', $this->domain)), 3 => array('black' => 'rb.png', 'gray' => 'rg.png', 'title' => t('move_next_title', $this->domain), 'alt' => t('move_next_alt', $this->domain)), 4 => array('black' => 'rrb.png', 'gray' => 'rrg.png', 'title' => t('move_last_title', $this->domain), 'alt' => t('move_last_alt', $this->domain))); $current = $snapshot_index - 1; // array is 0-based, index is 1-based $last = sizeof($this->snapshots) - 1; $nav[0] = 0; $nav[1] = $current > 0 ? $current - 1 : ($current < 0 ? $last : $current); $nav[2] = NULL; $nav[3] = $current < $last ? $current + 1 : $current; $nav[4] = $last; $this->theme->add_content($m . html_tag('div', array('class' => 'snapshot_toolbar'))); foreach ($nav as $id => $index) { $attributes = array('width' => 16, 'height' => 16, 'title' => $images[$id]['title'], 'alt' => $images[$id]['alt']); if ($current < 0) { if ($id == 1) { $attributes['title'] = t('move_last_title', $this->domain); $attributes['alt'] = t('move_last_alt', $this->domain); } elseif ($id == 3) { $attributes['title'] = t('move_first_title', $this->domain); $attributes['alt'] = t('move_first_alt', $this->domain); } } if (is_null($index)) { // special case: this yields the snapshots overview (thumbnails) if ($current < 0) { // and thsi IS the snapshots overview (thumbnails): use gray icon $img = html_img(was_url('program/modules/snapshots/' . $images[$id]['gray']), $attributes); } else { $img = html_img(was_url('program/modules/snapshots/' . $images[$id]['black']), $attributes); } $params = array('variant' => '1'); $caption = ''; } elseif ($index === $current) { $params = array('snapshot' => $index + 1); $attributes['alt'] = t('move_current_alt', $this->domain); $attributes['title'] = t('move_current_title', $this->domain); $img = html_img(was_url('program/modules/snapshots/' . $images[$id]['gray']), $attributes); $caption = $this->snapshots[$index]['key']; } else { $params = array('snapshot' => $index + 1); $img = html_img(was_url('program/modules/snapshots/' . $images[$id]['black']), $attributes); $caption = $this->snapshots[$index]['key']; } $href = was_node_url($this->theme->node_record, $params, $caption, $this->theme->preview_mode); $this->theme->add_content($m . ' ' . html_a($href, NULL, NULL, $img)); } // at this point we add another button with a link to the slideshow code $attributes = array('width' => 16, 'height' => 16, 'title' => t('slideshow_title', $this->domain), 'alt' => t('slideshow_alt', $this->domain)); $img = html_img(was_url('program/modules/snapshots/sb.png'), $attributes); $href = sprintf('javascript:show_start(%d);', max(0, $current)); $slideshow = str_replace('\'', '\\\'', html_a($href, NULL, NULL, $img)); $this->theme->add_content($m . ' <script type="text/javascript"><!--'); $this->theme->add_content($m . ' ' . sprintf('document.write(\'%s\');', $slideshow)); $this->theme->add_content($m . ' //--></script>'); if ($current >= 0) { // not in thumbnails overview $params = array('{SNAPSHOT}' => $current + 1, '{SNAPSHOTS}' => sizeof($this->snapshots), '{CAPTION}' => $this->snapshots[$current]['key']); $this->theme->add_content($m . ' ' . html_tag('span', array('class' => 'snapshot_status'), t('snapshot_status', $this->domain, $params))); } $this->theme->add_content($m . '</div>'); }