how can I change this Relative Paths to Absolute Paths? - php

for following code, I would like to know how can I change to absolutely link?
<a class="inline" href="<?php echo $profile->avater->full;?>" id="avater_profile_img">
<img src="<?php echo $profile->avater->avater;?>" alt="<?php echo $profile->full_name;?>" class="responsive-img" />
<?php
if((int)abs(((strtotime(date('Y-m-d H:i:s')) - $profile->lastseen))) < 60 && (int)$profile->online == 1) {
echo '<div class="useronline" style="top: 10px;left: 10px;"></div>';
}
?>
</a>

You can use $_SERVER['SERVER_NAME'] to makes the URL Absolute. I have added :// as well before the $_SERVER['SERVER_NAME'] so it may work as per currently viewing scheme either in http or https.
<a class="inline" href="<?php echo $profile->avater->full;?>" id="avater_profile_img">
<img src="<?php echo '://' . $_SERVER['SERVER_NAME'] . $profile->avater->avater;?>" alt="<?php echo $profile->full_name;?>" class="responsive-img" />
<?php
if((int)abs(((strtotime(date('Y-m-d H:i:s')) - $profile->lastseen))) < 60 && (int)$profile->online == 1) {
echo '<div class="useronline" style="top: 10px;left: 10px;"></div>';
}
?>
</a>
EDIT:
Use str_replace to change a.com with b.com in the image.
<a class="inline" href="<?php echo $profile->avater->full;?>" id="avater_profile_img">
<img src="<?php echo str_replace("a.com", "b.com", $profile->avater->avater); ?>" alt="<?php echo $profile->full_name;?>" class="responsive-img" />
<?php
if((int)abs(((strtotime(date('Y-m-d H:i:s')) - $profile->lastseen))) < 60 && (int)$profile->online == 1) {
echo '<div class="useronline" style="top: 10px;left: 10px;"></div>';
}
?>
</a>

Related

How to add if else into PHP code?

I have 4 social icons and if all of them weren't available then I want to show default.jpg , currently in the column, it's showing 5 icons including default.jpg too.
I added $icons_available, but not working, here is my complete code:
<?php
$icons_available = (
!empty($rec->telegram) &&
!empty($rec->google_plus) &&
!empty($rec->instagram) &&
!empty($rec->facebook)
);
?>
<td>
<?php if(!$icons_available) {?><img class="social" src="<?php echo base_url(); ?>social/default.jpg" /><?php }?>
<?php if($rec->telegram){ ?><img class="social" src="<?php echo base_url(); ?>social/telegram.jpg" /><?php } ?>
<?php if($rec->google_pluse){ ?><img class="social" src="<?php echo base_url(); ?>social/g.jpg" /><?php } ?>
<?php if($rec->instagram){ ?><img class="social" src="<?php echo base_url(); ?>social/insta.jpg" /><?php } ?>
<?php if($rec->facebook){ ?><img class="social" src="<?php echo base_url(); ?>social/f.jpg" /><?php } ?>
</td>
Here is my question:
**
If all of 4 icons weren't available together, then it will show
default.jpg otherwise it won't show default.jpg, How to make it?
**
try below code: (replace you above mention code and try with this)
<td>
<?php
if((!empty($rec->telegram) && !empty($rec->google_plus) && !empty($rec->instagram) && !empty($rec->facebook))) { ?>
<img class="social" src="<?php echo base_url()."social/telegram.jpg"; ?>" />
<img class="social" src="<?php echo base_url()."social/g.jpg"; ?>" />
<img class="social" src="<?php echo base_url()."social/insta.jpg"; ?>" />
<img class="social" src="<?php echo base_url()."social/f.jpg"; ?>" /><?php
}else{
$defaultSrc = base_url()."social/default.jpg";
for($i=0; $i < 4;$i++){
echo '<img class="social" src="'.$defaultSrc.'"/>';
}
}
?>
</td>
try this
<? php
$icons_available = (!empty($rec - > telegram) &&
!empty($rec - > google_plus) &&
!empty($rec - > instagram) &&
!empty($rec - > facebook)
); ?>
< td >
<? php
if (!$icons_available) { ?> < img class = "social"
src = "<?php echo base_url(); ?>social/default.jpg" / >
<? php
} else if ($rec - > telegram) { ?> < a href = "<?php echo $rec->telegram; ?>" > < img class = "social"
src = "<?php echo base_url(); ?>social/telegram.jpg" / > < /a>
<?php }else if($rec->google_pluse){ ?><img class="social" src="<?php echo base_url(); ?>social/g.jpg " />
<?php }else if($rec->instagram){ ?><a href=" <? php echo $rec - > instagram; ?> "><img class="
social " src=" <? php echo base_url(); ?> social / insta.jpg " /></a>
<?php }else if($rec->facebook){ ?><a href=" <? php echo $rec - > facebook; ?> "><img class="
social " src=" <? php echo base_url(); ?> social / f.jpg " /><?php } ?></a>
</td>
Rather use a PHP switch http://php.net/manual/en/control-structures.switch.php You will then put default.jpg in the default section of the switch.

How to add else into PHP Code line?

I have this following code
<td>
<?php if($rec->telegram){ ?><img class="social" src="<?php echo base_url(); ?>social/telegram.jpg" /><?php } ?>
<?php if($rec->google_pluse){ ?><img class="social" src="<?php echo base_url(); ?>social/g.jpg" /><?php } ?>
<?php if($rec->instagram){ ?><img class="social" src="<?php echo base_url(); ?>social/insta.jpg" /><?php } ?>
<?php if($rec->facebook){ ?><img class="social" src="<?php echo base_url(); ?>social/f.jpg" /><?php } ?>
</td>
I would like to add "else" into this code that if ALL those icons facebook, instagram, google plus and facebook weren't available then it will show another image file like "nophoto.jpg"
Note: If all those icons (4 icons) weren't available then it will show nophoto.jpg
I highly appreciate if someone guide me how to add else into above code.
Regards
It'll be easier to just add an extra if:
if (!($rec->telegram || $rec->instagram || $rec->facebook || $rec->google_plus)) { //etc
But really you want to attach that kind of logic to the $rec object, so that it's neatly separated and it's easier to add new types of social media in the future. Hopefully your $rec object is indeed backed by a class and not just a stdClass from a database result or cast.
public function hasNoSocialIcon() {
return !($rec->telegram || $rec->instagram || $rec->facebook || $rec->google_plus);
}
And then use that in your template:
<?php if ($rec->hasNoSocialIcon()) { ?>
<img class="social" src="<?php echo base_url(); ?>social/nophoto.jpg" />
<?php } ?>
You should take the use of PHP's conditional operators like this:
<?php
$icons_available = (
!empty($rec->telegram) &&
!empty($rec->google_plus) &&
!empty($rec->instagram) &&
!empty($rec->facebook)
);
?>
<td>
<?php if(!$icons_available) { ?>
<a href="default-pic.jpg">
<img class="social" src="default-pic.jpg" />
</a>
<?php } else { ?>
<?php $url = echo base_url() . 'social/telegram.jpg'; ?>
<a href="<?php echo $url; ?>">
<img class="social" src="<?php echo $url ?>" />
</a>
<?php $url = echo base_url() . 'social/google_plus.jpg'; ?>
<a href="<?php echo $url ?>">
<img class="social" src="<?php echo $url ?>" />
</a>
<?php $url = echo base_url() . 'social/instagram.jpg'; ?>
<a href="<?php echo $url ?>">
<img class="social" src="<?php echo $url ?>" />
</a>
<?php $url = echo base_url() . 'social/facebook.jpg'; ?>
<a href="<?php echo $url ?>">
<img class="social" src="<?php echo $url ?>" />
</a>
<?php } ?>
</td>
Hope this helps!

How to change header logo in specific page?

I'm using wordpress "Newspaper theme" and I want to change the header logo on some pages without changing the default that's used for the rest.
What I've done is I changed the logo.php from the hostmonster filemanager to:
<?php
/**
* Created by PhpStorm.
* User: ra
* Date: 4/22/14
* Time: 10:08 AM
*/
//read the logo + retina logo
$td_customLogo = td_util::get_option('tds_logo_upload');
$td_customLogoR = td_util::get_option('tds_logo_upload_r');
$td_logo_alt = td_util::get_option('tds_logo_alt');
$td_logo_title = td_util::get_option('tds_logo_title');
if (!empty($td_logo_title)) {
$td_logo_title = ' title="' . $td_logo_title . '"';
}
if (!empty($td_customLogoR)) { //if retina
if ($_GET['page_id'] == 110){
$td_customLogoR = 'http://www.arabi-group.com/wp-content/uploads/2016/05/araib-radio.jpg';
}elseif ($_GET['page_id'] == 179){
$td_customLogoR = 'http://www.arabi-group.com/wp-content/uploads/2016/05/13840505_10209929205285223_1180352314_o-1-e1469358582277.jpg';
}elseif ($_GET['page_id'] == 577){
$td_customLogoR = 'http://www.arabi-group.com/wp-content/uploads/2016/05/arabi-App.jpg';
}
?>
<a class="td-main-logo" href="<?php echo esc_url(home_url( '/' )); ?>">
<img class="td-retina-data" data-retina="<?php echo esc_attr($td_customLogoR) ?>" src="<?php echo $td_customLogo?>" alt="<?php echo $td_logo_alt ?>"<?php echo $td_logo_title ?>/>
</a>
<?php
} else { //not retina
if (!empty($td_customLogo)) {
if ($_GET['page_id'] == 110){
$td_customLogo = 'http://www.arabi-group.com/wp-content/uploads/2016/05/araib-radio.jpg';
}elseif ($_GET['page_id'] == 179){
$td_customLogo = 'http://www.arabi-group.com/wp-content/uploads/2016/05/13840505_10209929205285223_1180352314_o-1-e1469358582277.jpg';
}elseif ($_GET['page_id'] == 577){
$td_customLogo = 'http://www.arabi-group.com/wp-content/uploads/2016/05/arabi-App.jpg';
}
?>
<a class="td-main-logo" href="<?php echo esc_url(home_url( '/' )); ?>">
<img src="<?php echo $td_customLogo?>" alt="<?php echo $td_logo_alt ?>"<?php echo $td_logo_title ?>/>
</a>
<?php
}
}
The pages that should have different logo in the header are:
http://www.arabi-group.com/?page_id=110
http://www.arabi-group.com/?page_id=179
http://www.arabi-group.com/?page_id=577
What's keeping the logos from changing?
You just edit following my source
if (is_page( 110 )){
$td_customLogoR = 'http://www.arabi-group.com/wp-content/uploads/2016/05/araib-radio.jpg';
}
Everything will be work.
Updated: And you wrong at show img at src attribute
It should be
<a class="td-main-logo" href="<?php echo esc_url(home_url( '/' )); ?>">
<img class="td-retina-data" data-retina="<?php echo esc_attr($td_customLogoR); ?>" src="<?php echo $td_customLogoR; ?>" alt="<?php echo $td_logo_alt ?>"<?php echo $td_logo_title ?>/>
</a>

Change image without reloading page

I am trying to figure out how to change the photo without the page refreshing. I have seen some of the example but just cannot figure out how to implement it in to my working page.
This is what I have right now:
<div id="propertyDetailsImage">
<img class="image photo" src="<?php echo $property->photos->photo[$mainPhoto - 1]->url; ?>" width="<?php echo $property->mainPhotoWidth * 0.77 ?>" height="<?php echo $property->mainPhotoHeight * 0.77 ?>" alt="<?php echo $property->address->full; ?>"/>
</div>
<div class="photoPosition">
<?php
$previousPhoto = $mainPhoto - 1;
if($previousPhoto == 0) {
$previousPhoto = $property->totalPhotos;
}
$nextPhoto = $mainPhoto + 1;
if ($nextPhoto > $property->totalPhotos) {
$nextPhoto = intval(1);
}
?>
<img src="images/previous.png" alt="Previous photo" height="12" width="13" border="none"/>
<span id="photoPosition"><?php echo $mainPhoto; ?></span> of <?php echo $property>totalPhotos; ?>
<img src="images/next.png" alt="Next photo" height="12" width="13" border="none" />
</div>
</div>
<div class="col-md-6">
<div id="thumbnails">
<h3 class="additional">Photos</h3>
<?php
// Iterate throught the list of photos
foreach($property->photos->photo as $photo) {
?>
<script type="text/javascript">
addPhoto(
<?php echo $photo->id; ?>,
<?php echo $photo->width; ?>,
<?php echo $photo->height; ?>,
"<?php echo $photo->caption; ?>");
</script>
<img src="<?php echo $photo->url; ?>" width="<?php echo $photo->widthSmall; ?>" height="<?php echo $photo->heightSmall; ?>" class="image photo" id="photo<?php echo $photo->position; ?>" alt="Additional Photo of <?php echo $photo->address->advertising; ?>" onclick="return showPhoto(<?php echo $photo->position; ?>)" />
<?php }
?>
Any help is appreciated. Cheers
Dima
You should use ajax to get like this results.
you should go here,
The image slider shown in this demo is for free.
For detailed instructions, please visit online
http://www.menucool.com/slider/javascript-image-slider-demo1

Show specific logo for user group in Joomla 3

I can't seem to see a logical way to do this, I've tried many different functions, some of which i get blank page errors, other which it seems to work but just skips and goes to the else function everytime.
In a nutshell, I'm trying to have it so that certain logos will be displayed depending on the User Group ID.
At the moment the code below is producing a blank error page, and I can't see why.
Could anyone help me with this? Joomla 3.1 by the way.
<?php $user = JFactory::getUser();
$usergroup=$user->getAuthorisedGroups();
if ($usergroup == '10') : ?>
<a href="<?php echo JURI::root(); ?>" id="gkLogo">
<img src="/images/fordlogo.png" alt="<?php echo $this->API->getPageName(); ?>" />
</a>
<?php elseif ($usergroup == '7') : ?>
<a href="<?php echo JURI::root(); ?>" id="gkLogo">
<img src="/images/tescologo.png" alt="<?php echo $this->API->getPageName(); ?>" />
</a>
<?php else; ?>
<a href="<?php echo JURI::root(); ?>" id="gkLogo">
<img src="<?php echo $logo_image; ?>" alt="<?php echo $this->API->getPageName(); ?>" />
</a>
<?php endif; ?>
Try something like this,
$user = JFactory::getUser();
$usergroup = $user->getAuthorisedGroups();
if(in_array('10',$usergroup)){
echo '<a href="'.JURI::root().'" id="gkLogo">
<img src="/images/fordlogo.png" alt="'.$this->API->getPageName().'" />
</a>';
}elseif(in_array('7',$usergroup)){
echo '<a href="'.JURI::root().'" id="gkLogo">
<img src="/images/fordlogo.png" alt="'.$this->API->getPageName().'" />
</a>';
}else{
echo '<a href="'.JURI::root().'" id="gkLogo">
<img src="/images/fordlogo.png" alt="'.$this->API->getPageName().'" />
</a>';
}
Hope this will help you.

Categories