Jump to content

Building an image tag using an image from a diffrent site


ghurty

Recommended Posts

I am trying to edit a code so that images that are placed using a wysiwyg editor (live linked) would display, as of now only images residing on your server that are are displayed.

 

What would I change so that it could assemble the tag from anywhere, not only from my site ($mosConfig_live_site)?

 

Thanks

 

// assemble the <image> tag
		$image = '<img src="'. $mosConfig_live_site .'/images/stories/'. $attrib[0] .'"';

I tried to replace it with this:

$image = '<img src="'. $attrib[0] .'"';

 

But that didnt work.

 

Here is a copy of the rest of the code from the script if that helps:

	function replaceImage( &$row, $maxchars, $showimage, $width = -1, $height = -1 ) {
	global $database, $_MAMBOTS, $current_charset;

	// expression to search for
	$regex = '/<img\s*.*?>/i';

	$image = $showimage?processImage ( $row, $width, $height ):"";
	$row->introtext = trim($row->introtext);
	$row->introtext = preg_replace( $regex, '', $row->introtext );

	$row->introtext1 = strip_tags($row->introtext);
	if ($maxchars && strlen ($row->introtext) > $maxchars) {
		$row->introtext1 = substr ($row->introtext1, 0, $maxchars) . "...";
	}
	// clean up globals
	return $image;
}

function processImage ( &$row, $width, $height ) {
	global $mosConfig_absolute_path, $mosConfig_live_site;

	// split on \n the images fields into an array
	$row->images 	= explode( "\n", $row->images );
	$img = trim( $row->images[0] );

	// split on pipe the attributes of the image
	if ( $img ) {
		$attrib = explode( '|', trim( $img ) );
		// $attrib[0] image name and path from /images/stories

		// $attrib[1] alignment
		if ( !isset($attrib[1]) || !$attrib[1] ) {
			$attrib[1] = '';
		}

		// $attrib[2] alt & title
		if ( !isset($attrib[2]) || !$attrib[2] ) {
			$attrib[2] = 'Image';
		} else {
			$attrib[2] = htmlspecialchars( $attrib[2] );
		}

		// $attrib[3] border
		if ( !isset($attrib[3]) || !$attrib[3] ) {
			$attrib[3] = 0;
		}

		$attrib[4]	= '';
		$border 	= 0;

		// $attrib[5] caption position
		if ( !isset($attrib[5]) || !$attrib[5] ) {
			$attrib[5] = '';
		}

		// $attrib[6] caption alignment
		if ( !isset($attrib[6]) || !$attrib[6] ) {
			$attrib[6] = '';
		}

		// image size attibutes

		// assemble the <image> tag
		$image = '<img src="'. $mosConfig_live_site .'/images/stories/'. $attrib[0] .'"';

		// no aligment variable - if caption detected
		if ( !$attrib[4] ) {
			$image .= $attrib[1] ? ' align="'. $attrib[1] .'"' : '';
		}
		$image .=' alt="'. $attrib[2] .'" title="'. $attrib[2] .'" border="'. $border .'" '. (($width != -1) ? 'width="'. $width . '"' : '') .(($height != -1) ? ' height="'. $height .'"' : '').' />';

		$img = $image;
	}
	return $img;
}

Here is the entire code, but I think only the first part effects the image:

 

As  of now it only displays an image that is tagged using {mosimage} (and those have to reside on my server) what I am trying to do is allow it to using a image from a different server.

 

Thanks

 

<?php
if (!defined ('JA_NEWS')){
define ('JA_NEWS', 1);
function replaceImage( &$row, $maxchars, $showimage, $width = -1, $height = -1 ) {
	global $database, $_MAMBOTS, $current_charset;

	// expression to search for
	$regex = '/{mosimage\s*.*?}/i';

	$image = $showimage?processImage ( $row, $width, $height ):"";
	$row->introtext = trim($row->introtext);
	$row->introtext = preg_replace( $regex, '', $row->introtext );

	$row->introtext1 = strip_tags($row->introtext);
	if ($maxchars && strlen ($row->introtext) > $maxchars) {
		$row->introtext1 = substr ($row->introtext1, 0, $maxchars) . "...";
	}
	// clean up globals
	return $image;
}

function processImage ( &$row, $width, $height ) {
	global $mosConfig_absolute_path, $mosConfig_live_site;

	// split on \n the images fields into an array
	$row->images 	= explode( "\n", $row->images );
	$img = trim( $row->images[0] );

	// split on pipe the attributes of the image
	if ( $img ) {
		$attrib = explode( '|', trim( $img ) );
		// $attrib[0] image name and path from /images/stories

		// $attrib[1] alignment
		if ( !isset($attrib[1]) || !$attrib[1] ) {
			$attrib[1] = '';
		}

		// $attrib[2] alt & title
		if ( !isset($attrib[2]) || !$attrib[2] ) {
			$attrib[2] = 'Image';
		} else {
			$attrib[2] = htmlspecialchars( $attrib[2] );
		}

		// $attrib[3] border
		if ( !isset($attrib[3]) || !$attrib[3] ) {
			$attrib[3] = 0;
		}

		$attrib[4]	= '';
		$border 	= 0;

		// $attrib[5] caption position
		if ( !isset($attrib[5]) || !$attrib[5] ) {
			$attrib[5] = '';
		}

		// $attrib[6] caption alignment
		if ( !isset($attrib[6]) || !$attrib[6] ) {
			$attrib[6] = '';
		}

		// image size attibutes

		// assemble the <image> tag
		$image = '<img src="'. $mosConfig_live_site .'/images/stories/'. $attrib[0] .'"';

		// no aligment variable - if caption detected
		if ( !$attrib[4] ) {
			$image .= $attrib[1] ? ' align="'. $attrib[1] .'"' : '';
		}
		$image .=' alt="'. $attrib[2] .'" title="'. $attrib[2] .'" border="'. $border .'" '. (($width != -1) ? 'width="'. $width . '"' : '') .(($height != -1) ? ' height="'. $height .'"' : '').' />';

		$img = $image;
	}
	return $img;
}

function calModStyle ($cols) {
	$modules = array();
	switch ($cols) {
		case 0: return null;
		break;
		case 1: 
			$modules[0]['class'] = "";
			$modules[0]['width'] = "100%";
			$modules[0]['subwidth'] = "100%";
			break;
		case 2: 
			$modules[0]['class'] = "-left";
			$modules[0]['width'] = "49.9%";
			$modules[0]['subwidth'] = "95%";
			$modules[1]['class'] = "-right";
			$modules[1]['width'] = "49.9%";
			$modules[1]['subwidth'] = "95%";
			break;
		default: 

			$width1 = round(99.6/($cols-0.1), 2);
			$width2 = round((99.6 - $width1*($cols-2))/2, 2);

			for ($i=1; $i<$cols - 1; $i++){
				$modules[$i]['class'] = "-center";
				$modules[$i]['width'] = $width1."%";
				$modules[$i]['subwidth'] = "90%";
			}
			$modules[0]['class'] = "-left";
			$modules[0]['width'] = $width2."%";
			$modules[0]['subwidth'] = "95%";
			$modules[$cols - 1]['class'] = "-right";
			$modules[$cols - 1]['width'] = $width2."%";
			$modules[$cols - 1]['subwidth'] = "95%";
			break;
	}
	return $modules;
}
  
  global $mosConfig_live_site;
//Insert link to head (onece)
$linktag = '<link rel="stylesheet" type="text/css" href="'.$mosConfig_live_site.'/modules/ja_news/ja-news.css" />';

$buffer = ob_get_contents();
$pos = strpos ($buffer, '</head>');
if (!strpos ($buffer, "ja-news.css") && $pos) {
$buffer = substr ($buffer, 0, $pos) . "\n$linktag\n". substr($buffer, $pos);
ob_clean();
echo $buffer;
  }
}
?>

<?php
// no direct access
defined( '_VALID_MOS' ) or die( 'Restricted access' );

global $mosConfig_offset, $mosConfig_live_site, $mainframe;

$catid = trim( $params->get( 'catid' ) );
$showheadline = intval (trim( $params->get( 'showheadline', 0 ) ));
$headlinelang = trim( $params->get( 'headlinelang' ) );
$headlineheight = intval( $params->get( 'headlineheight' ) );
$linksitem 	= intval (trim( $params->get( 'linkitems', 0 ) ));
$maxchars = intval (trim( $params->get( 'maxchars', 200 ) ));
$width = intval (trim( $params->get( 'width', 100 ) ));
$height = intval (trim( $params->get( 'height', 100 ) ));
$showintro = $params->get( 'showintro', 0 );
$showimage = $params->get( 'showimage', 0 );
$cols	= intval (trim( $params->get( 'cols', 2 ) ));

$numberofheadlinenews = intval (trim( $params->get( 'numberofheadlinenews', 10 ) ));
$autoroll = ($params->get( 'autoroll', 1 )) ? 1 : 0;
$delaytime = intval (trim( $params->get( 'delaytime', 5 ) ));

$now 		= _CURRENT_SERVER_TIME;
$access 	= !$mainframe->getCfg( 'shownoauth' );
$nullDate 	= $database->getNullDate();

$charset = array(
   "CHARSET=ISO-8859-1" => "ISO8859-1",
   "CHARSET=ISO8859-1" => "ISO8859-1",
   "CHARSET=ISO-8859-15" => "ISO8859-15",
   "CHARSET=ISO8859-15" => "ISO8859-15",
   "CHARSET=UTF-8" => "UTF-8",
   "CHARSET=CP866" => "ibm866",
   "CHARSET=866" => "ibm866",
   "CHARSET=IBM866" => "ibm866",
   "CHARSET=CP1251" => "Windows-1251",
   "CHARSET=WINDOWS-1251" => "Windows-1251",
   "CHARSET=WIN-1251" => "Windows-1251",
   "CHARSET=1251" => "Windows-1251",
   "CHARSET=CP1252" => "Windows-1252",
   "CHARSET=WINDOWS-1252" => "Windows-1252",
   "CHARSET=1252" => "Windows-1252",
   "CHARSET=KOI8-R" => "koi8-ru",
   "CHARSET=KOI8-RU" => "koi8-ru",
   "CHARSET=KOI8R" => "koi8-ru",
   "CHARSET=BIG5" => "950",
   "CHARSET=950" => "950",
   "CHARSET=GB2312" => "936",
   "CHARSET=936" => "936",
   "CHARSET=BIG5-HKSCS" => "BIG5-HKSCS",
   "CHARSET=SHIFT_JIS" => "SJIS",
   "CHARSET=SJIS" => "SJIS",
   "CHARSET=932" => "SJIS",
   "CHARSET=EUC-JP" => "EUCJP",
   "CHARSET=EUCJP" => "EUCJP"
);

$current_charset = isset($charset[strtoupper(_ISO)]) ? $charset[strtoupper(_ISO)] : "";

if ($catid) $catids = split(",", $catid);
else {
$query = "SELECT id FROM #__categories WHERE published = 1;";
$database->setQuery($query);
$c = $database->loadObjectList();
$catids = array();
foreach($c as $_c) $catids[] = $_c->id;
}

if ($showheadline) {
$query = "SELECT COUNT(*)"
		. "\n FROM #__content AS a"
		. "\n INNER JOIN #__content_frontpage AS f ON f.content_id = a.id"
		. "\n INNER JOIN #__categories AS cc ON cc.id = a.catid"
		. "\n WHERE ( a.state = 1 AND a.sectionid > 0 "
		. "\n AND ( a.publish_up = '$nullDate' OR a.publish_up <= '$now' )"
		. "\n AND ( a.publish_down = '$nullDate' OR a.publish_down >= '$now' )"
		. ( $access ? "\n AND a.access <= $my->gid AND cc.access <= $my->gid" : '' )
		. "\n AND cc.published = 1 )";
$database->setQuery($query);
$c = $database->loadResult();
$numberofheadlinenews = ($numberofheadlinenews < $c) ? $numberofheadlinenews : $c;

$query = "SELECT a.images, a.introtext, a.id, a.title, a.sectionid, a.catid, cc.title as cattitle"
		. "\n FROM #__content AS a"
		. "\n INNER JOIN #__content_frontpage AS f ON f.content_id = a.id"
		. "\n INNER JOIN #__categories AS cc ON cc.id = a.catid"
		. "\n WHERE ( a.state = 1 AND a.sectionid > 0 "
		. "\n AND ( a.publish_up = '$nullDate' OR a.publish_up <= '$now' )"
		. "\n AND ( a.publish_down = '$nullDate' OR a.publish_down >= '$now' )"
		. ( $access ? "\n AND a.access <= $my->gid AND cc.access <= $my->gid" : '' )
		. "\n AND cc.published = 1 )"
		. "\n ORDER BY f.ordering ASC limit 1";
$database->setQuery($query);
$firstnew = null;
$database->loadObject($firstnew);

if ($firstnew) {
	$headlineid = $firstnew->id;
	echo "<div class=\"ja-newshlwrap\">";
	echo "<div class=\"ja-newsblock clearfix\" style=\"width: 100%;". ($headlineheight ? " height: {$headlineheight}px; overflow: hidden;" : "") ."\">";

	$bs 	= $mainframe->getBlogSectionCount();
	$bc 	= $mainframe->getBlogCategoryCount();
	$gbs 	= $mainframe->getGlobalBlogSectionCount();

	$Itemid = $mainframe->getItemid( $firstnew->id, 0, 0, $bs, $bc, $gbs );
	if ($Itemid == NULL) {
		$Itemid = '';
	} else {
		$Itemid = '&Itemid='. $Itemid;
	}
	$link = sefRelToAbs( 'index.php?option=com_content&task=view&id='. $firstnew->id . $Itemid );

	echo "<div class=\"ja-newsitem\" style=\"width: 100%;\">\n";

	echo "<div class=\"ja-newsitem-inner\" style=\"width: 100%;\">\n";
	if ($numberofheadlinenews > 1) {
		if (isset($_COOKIE['JAHL-AUTOROLL'])) $autoroll = ($_COOKIE['JAHL-AUTOROLL']) ? 1 : 0;
		setcookie("JAHL-AUTOROLL", $autoroll, 0, "/");
		?>
		<script type="text/javascript">
			var jahl = new Object
			jahl.livesite = '<?php echo $mosConfig_live_site; ?>';
			jahl.autoroll = <?php echo ($autoroll) ? "true" : "false" ?>;
			jahl.delaytime = <?php echo $delaytime; ?>;
			jahl.total = <?php echo $numberofheadlinenews; ?>;
			jahl.current = 1;
		</script>
		<?php

		//~ echo "<script type=\"text/javascript\" src=\"$mosConfig_live_site/modules/ja_news/janews.mootools.v1.00.js\"></script>\n";
		echo "<script type=\"text/javascript\" src=\"$mosConfig_live_site/modules/ja_news/janews.js\"></script>\n";
	}

	echo "<div class=\"ja-newscat\"><span id=\"jahl-headlineanchor\">{$headlinelang}</span>";
	if ($numberofheadlinenews > 1) {
		$query = "SELECT a.title"
				. "\n FROM #__content AS a"
				. "\n INNER JOIN #__content_frontpage AS f ON f.content_id = a.id"
				. "\n INNER JOIN #__categories AS cc ON cc.id = a.catid"
				. "\n WHERE ( a.state = 1 AND a.sectionid > 0 "
				. "\n AND ( a.publish_up = '$nullDate' OR a.publish_up <= '$now' )"
				. "\n AND ( a.publish_down = '$nullDate' OR a.publish_down >= '$now' )"
				. ( $access ? "\n AND a.access <= $my->gid AND cc.access <= $my->gid" : '' )
				. "\n AND cc.published = 1 )"
				. "\n ORDER BY f.ordering ASC limit 1, 1";
		$database->setQuery($query);
		$nexttitle = $database->loadResult();

		$query = "SELECT a.title"
				. "\n FROM #__content AS a"
				. "\n INNER JOIN #__content_frontpage AS f ON f.content_id = a.id"
				. "\n INNER JOIN #__categories AS cc ON cc.id = a.catid"
				. "\n WHERE ( a.state = 1 AND a.sectionid > 0 "
				. "\n AND ( a.publish_up = '$nullDate' OR a.publish_up <= '$now' )"
				. "\n AND ( a.publish_down = '$nullDate' OR a.publish_down >= '$now' )"
				. ( $access ? "\n AND a.access <= $my->gid AND cc.access <= $my->gid" : '' )
				. "\n AND cc.published = 1 )"
				. "\n ORDER BY f.ordering ASC limit ". ($numberofheadlinenews - 1) .", 1";
		$database->setQuery($query);
		$prevtitle = $database->loadResult();

		echo "<div class=\"jahl-newscontrol\">";
		echo "<img id=\"loading-indicator\" style=\"display: none;\" src=\"{$mosConfig_live_site}/modules/ja_news/loading.gif\" alt=\"Loading\" border=\"0\" />\n";
		echo "<ul>";
		echo "<li>".($autoroll ? "<img title=\"Pause\" style=\"cursor: pointer;\" id=\"jahl-switcher\" onclick=\"jahl.switchRoll(); return false;\" src=\"$mosConfig_live_site/modules/ja_news/pause.png\" alt=\"Pause\" border=\"0\" />" : "<img title=\"Play\" style=\"cursor: pointer;\" id=\"jahl-switcher\" onclick=\"jahl.switchRoll(); return false;\" src=\"$mosConfig_live_site/modules/ja_news/play.png\" alt=\"Play\" border=\"0\" />")."</li>\n";
		echo "<li><img title=\"Previous: ".trim(htmlentities($prevtitle, ENT_QUOTES, $current_charset))."\" style=\"cursor: pointer;\" onclick=\"jahl.showNews(((jahl.current==1)?jahl.total : jahl.current - 1), jahl.total); return false;\" id=\"jahl-prev\" src=\"$mosConfig_live_site/modules/ja_news/prev.png\" alt=\"Previous\" border=\"0\" /></li>\n";
		echo "<li><img title=\"Next: ".trim(htmlentities($nexttitle, ENT_QUOTES, $current_charset))."\" style=\"cursor: pointer;\" onclick=\"jahl.showNews(((jahl.current==jahl.total)?1 : jahl.current + 1), jahl.total); return false;\" id=\"jahl-next\" src=\"$mosConfig_live_site/modules/ja_news/next.png\" alt=\"Next\" border=\"0\" /></li>\n";
		echo "</ul>";
		echo "<span id=\"jahl-indicator\">1/{$numberofheadlinenews}</span>\n";
		echo "</div>";
	}
	echo  "</div>\n";
	echo "<div id=\"jahl-newsitem\">\n";

	$image = replaceImage ($firstnew, 0, 1);
	echo "<div class=\"ja-newscontent\">\n";
	echo $image. "\n";
	echo "<a href=\"$link\" class=\"ja-newstitle\" title=\"".trim(htmlentities($firstnew->title, ENT_QUOTES, $current_charset))."\">{$firstnew->title}</a>\n";
	echo "{$firstnew->introtext}\n</div>\n";
	echo "<a href=\"$link\" class=\"readon\">"._READ_MORE."</a>";
	echo "</div>\n</div>\n</div></div></div>\n";
	echo "<span class=\"article_seperator\"> </span>";
}
}

if ($cols > 0) {
echo "<div class=\"ja-newscatwrap\">";  
$modwidth = round(100 / $cols, 2) ;
$l = 0;
$modStyle = calModStyle ($cols);
$isrowopen = false;
for ($k=0;$k<count($catids);++$k){
	$query = "SELECT a.images, a.introtext, a.id, a.title, a.sectionid, a.catid, cc.title as cattitle, cc.description as catdesc"
			. "\n FROM #__content AS a"
			. "\n LEFT JOIN #__content_frontpage AS f ON f.content_id = a.id"
			. "\n INNER JOIN #__categories AS cc ON cc.id = a.catid"
			. "\n WHERE ( a.state = 1 AND a.sectionid > 0 "
			. "\n AND ( a.publish_up = '$nullDate' OR a.publish_up <= '$now' )"
			. "\n AND ( a.publish_down = '$nullDate' OR a.publish_down >= '$now' )"
			. ( $access ? "\n AND a.access <= $my->gid AND cc.access <= $my->gid" : '' )
			. ( $catids ? "\n AND ( a.catid = {$catids[$k]} )" : "" )
			. ( isset($headlineid) ? "\n AND a.id <> $headlineid" : "" )
			. "\n AND cc.published = 1 )"
			. "\n ORDER BY a.created DESC limit " . ($linksitem+1);
	$database->setQuery( $query );
	$temp = $database->loadObjectList();

	$rows = array();
	if (count($temp)) {
		foreach ($temp as $row ) {
			$rows[] = $row;
		}
	}
	unset($temp);
	if (count($rows)) {
		$bs 	= $mainframe->getBlogSectionCount();
		$bc 	= $mainframe->getBlogCategoryCount();
		$gbs 	= $mainframe->getGlobalBlogSectionCount();

		// Output
		if ($l == 0){
			//Begin a row
			echo "<div class=\"ja-newsblock clearfix\">\n";
		$isrowopen = true;
		}

		//get Itemid of category
		$Itemid = $mainframe->getItemid( $rows[0]->id, 0, 0, $bs, $bc, $gbs );
		if ($Itemid == NULL) {
			$Itemid = '';
		} else {
			$Itemid = '&Itemid='. $Itemid;
		}
		$link = sefRelToAbs( 'index.php?option=com_content&task=category&sectionid='.$rows[0]->sectionid.'&id='. $rows[0]->catid . $Itemid );

		echo "<div class=\"ja-newsitem{$modStyle[$l]['class']}\" style=\"width: {$modStyle[$l]['width']};\"><div class=\"ja-newsitem-inner\" style=\"width:{$modStyle[$l]['subwidth']};\">\n";
		echo "<a href=\"$link\" class=\"ja-newscat\" title=\"".trim(htmlentities($rows[0]->catdesc, ENT_QUOTES, $current_charset))."\"><span>{$rows[0]->cattitle}</span></a>\n";

		$hasul = true;

		for ( $i=0; $i<count($rows); $i++ ) {
			$row = $rows[$i];
			// get Itemid
			$Itemid = $mainframe->getItemid( $row->id, 0, 0, $bs, $bc, $gbs );
			// Blank itemid checker for SEF
			if ($Itemid == NULL) {
				$Itemid = '';
			} else {
				$Itemid = '&Itemid='. $Itemid;
			}

			$link = sefRelToAbs( 'index.php?option=com_content&task=view&id='. $row->id . $Itemid );
			$image = replaceImage ($row, $maxchars, $showimage, $width, $height);

			if ($i == 0){
				//Show the latest news
					echo "<div class=\"ja-newscontent\">\n";
					echo $image. "\n";
					echo "<a href=\"$link\" class=\"ja-newstitle\" title=\"".($showintro ? $row->title : $row->introtext1)."\">{$row->title}</a>\n";
  					if ($showintro){
  						if ($maxchars)
                echo "{$row->introtext1}\n";
              else  
                echo "{$row->introtext}\n";
  					}	
            echo "</div>\n";
					if (count ($rows) > 1) echo "<ul class=\"ja-newslinks\">\n"; else $hasul = false;
			}else{
				?>
				<li>
				<a title="<?php echo $row->introtext1; ?>" href="<?php echo $link; ?>">
				<?php echo $row->title; ?></a>
				</li>
				<?php
			}
		}
		if ($hasul) echo "</ul>\n";
		echo "</div></div>\n";
		$l++;
	}
	if ($isrowopen && ($l == $cols || $k == (count ($catids)-1))){
		//End a row
		echo "</div>\n";
		echo "<span class=\"article_seperator\"> </span>";
		$l = 0;
		$isrowopen = false;
	}
}
echo "</div>";
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.