PHP if element exists, add width; if not, don't

serdar0303

New Member
I'm setting up a horizontally scrolling site, with Index Exhibit. One section needs to have a video, which I can't set up in the Indexhibit CMS backend (where it would add it to the wide div's width), so I need to add it to the PHP generation file. Basically, it needs to check if an element with the ID \[code\]vid\[/code\] is present. If so, it should add the \[code\]vid_width\[/code\] and \[code\]vid_right_padding\[/code\] to the final width, \[code\]final_img_container\[/code\]. If not, it should be left out. The website with the video can be found here: http://www.allisonnavon.com/index.php?/projects/the-alka-seltzer-challenge/ As you can see here, the width is perfect, but when other pages are loaded, there is a huge 800 extra pixels on the right end of each project.Here is the code:\[code\]<?php if (!defined('SITE')) exit('No direct script access allowed');/*** Horizontal Format** Exhbition format* Originally created for SharoneLifschitz.com* * @version 1.1* @author Vaska */$DO = new Horizontally;$exhibit['exhibit'] = $DO->createExhibit();$exhibit['dyn_css'] = $DO->dynamicCSS();class Horizontally{ // PADDING AND TEXT WIDTH ADJUSTMENTS UP HERE!!! var $picture_block_padding_right = 25; var $text_width = 250; var $text_padding_right = 75; var $vid_width = 800; var $vid_padding_right = 25; var $final_img_container = 0; // do not adjust this one function createExhibit() { $OBJ =& get_instance(); global $rs; $pages = $OBJ->db->fetchArray("SELECT * FROM ".PX."media, ".PX."objects_prefs WHERE media_ref_id = '$rs[id]' AND obj_ref_type = 'exhibit' AND obj_ref_type = media_obj_type ORDER BY media_order ASC, media_id ASC"); if (!$pages) return $rs['content']; $s = ''; $a = ''; $w = 0; $this->final_img_container = ($rs['content'] != '') ? ($this->text_padding_right + $this->text_width + $this->vid_padding_right + $this->vid_width) : 0; foreach ($pages as $go) { $title = ($go['media_title'] == '') ? '' : "<div class='title'>" . $go['media_title'] . "</div>"; $title .= ($go['media_caption'] == '') ? '' : "<div class='caption'>" . $go['media_caption'] . "</div>"; $temp_x = $go['media_x'] + $this->picture_block_padding_right; $this->final_img_container += ($go['media_x'] + $this->picture_block_padding_right); $a .= "<div class='picture_holder' style='width: {$temp_x}px;'>\n"; $a .= "<div class='picture' style='width: {$go[media_x]}px;'>\n"; $a .= "<img src='" . BASEURL . GIMGS . "/$go[media_file]' width='$go[media_x]' height='$go[media_y]' alt='" . BASEURL . GIMGS . "/$go[media_file]' />\n"; $a .= "<div class='captioning'>$title</div>\n"; $a .= "</div>\n"; $a .= "</div>\n\n"; } $s .= "<div class='text'><div class='scroller'><span><a href='javascript:void(0);' class='prev'>&laquo;</a></span><span class='title'><a href='javascript:void(0);' class='origin'><%title%></a></span><span><a href='javascript:void(0);' class='next'>&raquo;</a></span></div><div id='img-container'>\n"; if ($rs['content'] != '') $s .= "<div id='text'>" . $rs['content'] . "</div>\n"; $s .= $a; $s .= "<div style='clear: left;'><!-- --></div>"; $s .= "</div></div>\n"; return $s; } function dynamicCSS() { return "#img-container { width: " . ($this->final_img_container + 1) . "px; }#img-container #text { float: left; width: " . ($this->text_width + $this->text_padding_right) . "px; }#img-container #text p { width: " . $this->text_width . "px; }#img-container #vid { float: left; width: " . ($this->vid_width + $this->vid_padding_right) . "px; }#img-container #vid p { width: " . $this->vid_width . "px; }#img-container .picture_holder { float: left; }#img-container .picture { /* padding-top: 10px; */ }#img-container .captioning .title { margin-top: 12px; font-weight: bold; }#img-container .captioning .caption { font-family:PerspectiveSansItalic; font-size:11px; color: #444; padding-top: 10px;}"; }}\[/code\]
 
Back
Top