(PHP) Trying to controll the include function - php

I am now done making my website dynamic (control multiple pages througe 1 page)
I have template where I have 2 side bars left and right, right for categories, left for the the many pages of each category.
Now using the include function to dynamicly generate the side bars is great,
but i am also using class:current on these side bars so the user can easily detect where he is.
now with the right sidebar there is no problem because if the user is in HTML category it will be highlighted with class:current but will not need to change, because user is still in HTML category.
but if the user switch page the left side bar will stay with the last class:current (for example html intro ), even tho user switched to next page (html basics).
i can only have 1 class:current when using the include function.
how can i controll that?
the code below is the file that im including to each page dynamicly it is .php file.
<div class="sidenav">
<h3> HTML Collection</h3>
<hr class="hr1">
<a class="current" style="cursor: pointer;" onclick="window.location.href = 'html_default.php';"> HTML Intro</a>
<a style="cursor: pointer;" onclick="window.location.href = 'html_editors.php';"> HTML Editors</a>
<a style="cursor: pointer;" onclick="window.location.href = 'html_basics.php';"> HTML Basics</a>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
</div>
<div class="sidenavright">
<h3> Categories</h3>
<hr class="hr1">
<a style="cursor: pointer;" onclick="window.location.href = '../javascript/js_intro.php';"> Javascript</a>
<hr class="hr1" />
<a class="current" style="cursor: pointer;" onclick="window.location.href = '../html/html_default.php';"> HTML</a>
<hr class="hr1" />
<a style="cursor: pointer;" onclick="window.location.href = '../howtomain/howto_default.php';"> HowTo</a>
<hr class="hr1" />
<a style="cursor: pointer;" onclick="window.location.href = '../python/python_intro.php';"> Python</a>
<hr class="hr1" />
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
</div>

You should be doing this all though JavaScript really, something like AngularJS, or maybe even use Laravel and it would be very easy to control it in your blade views.
Here’s something you can do however.
From the file where you are including it, define a variable before the include that will allow the include to know what page you’re on.
Like so:
$currPage = “page1”;
Then in your include, on each tag, you can programmatically put your current class on using one line if/elses, like so:
<a <?php ($currPage == “page1”) ? echo ‘class=“current”’ : echo ‘’?>>Page 1</a>
And repeat for all pages you want.
One line if/elses in PHP go like this:
Condition ? //true : //false
Good luck

Related

How to link to a specific part of a page HTML PHP

I am trying to link to a specific part in my php page. I have tried all the other answers on here but none of them have helped my special problem. This is how I am trying to go to the link
<a href="<?php echo $userLoggedIn; ?>#posts_tab">
So when the user clicks the dropdown they see a list of things. One of those things being the word Profile and when the user clicks on their profile they go to their own personal profile. When they are there they have a list of items at the top that look like this:
So what I want to do is when they click the profile they are automatically on the Profile Posts tab. Like a default option. For some reason it's not working for me and I can't figure out why. Any help please ?
header.php:
<a href="<?php echo $userLoggedIn; ?>#posts_tab">
</a>
profile.php:
<a style="color: #000;" id="posts_tab" href="javascript:void(0)" onclick="openCity(event, 'Posts');">
<div class="w3-third tablink w3-bottombar w3-hover-light-grey w3-padding">
<center>Profile Posts</center>
</div>
</a>
I believe this is what you want, you need to let your profile page know that you want to load that part of profile.php, you can do it different ways I have used php and GET as example, I've sent a parameter on the URL and received it on profile.php
header.php
<a href="<?php echo $userLoggedIn; ?>?tab=posts_tab">
profile.php
<?php
$tab = $_GET["tab"];
if ($tab == "posts_tab"){
?><script>openCity(event, 'Posts');</script><?php
}
?>
<a style="color: #000;" id="posts_tab" href="javascript:void(0)" onclick="openCity(event, 'Posts');">
<div class="w3-third tablink w3-bottombar w3-hover-light-grey w3-padding">
<center>Profile Posts</center>
</div>
</a>

How to redirect to a particular block of html page?

I'm working on a simple project which has a requirement to show a particular block of html by passing an div id to that url.
I have tried so many solutions, but none of them worked for me.
Here is my code.
<div class="row">
<a onclick="redirect_tooltip();">
<i class="fa fa-question-circle" aria-hidden="true"></i>
</a>
</div>
Whenever I click the icon it calls a Javascript function, through that function I tried to pass a url with another page division id
function redirect_tooltip()
{
var source_type = $("#_src_type").val();
if(source_type == "source")
{
window.location.replace(base_url+'/help/tooltip#rtmp_4');
//I have already difined the base url
}
}
My html code:
<div id="rtmp_4">
<h4>Some Title</h4>
<h5> <?php echo trim($tooltip_rtmp_server[1]);?></h5>
<p> <?php echo trim($tooltip_rtmp_server[3]);?> </p>
<h5> <?php echo trim($tooltip_rtmp_stream_name[1]);?></h5>
<p> <?php echo trim($tooltip_rtmp_stream_name[3]);?> </p>
</div>
I need to display only the rtmp block whenever the url executes. Please give me a suggestions like where I am doing the mistake.

using simple html dom to find facebook username - php

I'm using php and the simple html dom
http://simplehtmldom.sourceforge.net/manual.htm
I'm trying to extract the facebook, twitter, google, youtube and pinterest usernames from the addthis code below..
<!-- AddThis Follow BEGIN -->
<div class="addthis_toolbox addthis_default_style" style="margin-top:-3px;">
<a tabindex="2" class="addthis_button_facebook_follow" style="padding:3px 6px;" addthis:userid="namehere"></a>
<a tabindex="3" class="addthis_button_twitter_follow" style="padding:3px 6px;" addthis:userid="namehere"></a>
<a tabindex="4" class="addthis_button_google_follow" style="padding:3px 6px;" addthis:userid="namehere"></a>
<a tabindex="5" class="addthis_button_youtube_follow" style="padding:3px 6px;" addthis:userid="namehere"></a>
<a tabindex="6" class="addthis_button_pinterest_follow" style="padding:3px 6px;" addthis:userid="namehere"></a>
</div>
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-51e6691575bd9b10"></script>
<!-- AddThis Follow END -->
How can I get the usernames using the simple html dom?
I tried running this...
$html = file_get_html('http://www.domain.com/');
foreach($html->find('a[class=addthis_button_facebook_follow]') as $element)
echo $element->class;
which outputs the class name:
addthis_button_facebook_follow
but how do I return the addthis:userid value?
addthis:userid
Actually, you're not calling the attribute right. Consider this example:
// target the first link, since you only need one, and target the proper attribute
$id = $html->find('a[class="addthis_button_facebook_follow"]', 0)->{'addthis:userid'}; // first link facebook
echo $id; // namehere
Try:
echo $element->{'addthis:userid'};

What would be the best way to make a widget that will link to 4 different websites?

I'm trying to limit maintnance headaches by avoiding having to copy and paste code and having to update it on several different sites. Should I use an iframe? So far I just used inline CSS to style it and plan on copying a pasting to 3 or 4 other sites. Kind of like:
<div style="width:165px; height:40px; background: url('http://site1.com/images/DH-sharebar.gif') repeat-x top #333;float:right;margin-top:15px;margin-right:20px;border-radius:5px;border:1px #565656 solid;">
<a href="http://site1.com/" target="_blank" title="site 1">
<img src="http://davidhairabedian.com/davidhairabedian/images/DH-sharebar-icon.png" style="border-radius:0;margin-top:5px;margin-left:10px;">
</a>
<a href="http://site2.org/" target="_blank" title="site 2">
<img src="http://site1.com/images/DH-sharebar-HPM-icon.png" style="border-radius:0;margin-top:5px;margin-left:10px;">
</a>
<a href="http://site3.org/" target="_blank" title="site 3">
<img src="http://site1.com/images/DH-sharbar-EHF.png" style="border-radius:0;margin-top:5px;margin-left:3px;">
</a>
<a href="http://site4.org/" target="_blank" title="site 4">
<img src="http://site1.com/images/DH-sharebar-EHC.png" style="border-radius:0;margin-top:5px;margin-left:10px;">
</a>
</div>
If you don't mind having a slight delay, you could write a light JavaScript that loaded the content into the page via AJAX, much like facebook / many other widgets do.
The benefit that offsets the fact that your links are not part of the page's initial HTML is the fact that you can update the content of all widgets from one place, with no chance that you'll forget one int he future.
Have a look into how Facebook / Google + / Twitter / Everyone else does this.
Edit
Your question got me thinking about how one might do this, so I did it. I've made a working JSFiddle example.
Basically, you paste an empty div and a script tag into your target pages. The script references a file stored on your central server. It creates another script tag in the document, which itself contains a call to a function defined in the first script, which inserts your widget into the specified div on the page.
Pasted into your pages
<div id="placeholder-div"></div>
<script type="text/javascript" src="http://pagesofinterest.net/stack-examples/what-would-be-the-best-way-to-make-a-widget-that-will-link-to-4-different-websit/script.js"></script>
First script content
(function loadContent() {
(function xss_ajax(url) {
var script_id = null;
var script = document.createElement('script');
script.setAttribute('type', 'text/javascript');
script.setAttribute('src', 'http://pagesofinterest.net/stack-examples/what-would-be-the-best-way-to-make-a-widget-that-will-link-to-4-different-websit/content.php');
script.setAttribute('id', 'script_id');
script_id = document.getElementById('script_id');
if(script_id){
document.getElementsByTagName('head')[0].removeChild(script_id);
}
// Insert <script> into DOM
document.getElementsByTagName('head')[0].appendChild(script);
})();
})();
function callback(data) {
document.getElementById('placeholder-div').innerHTML = data;
}
Inserted script content:
<?php ob_start(); ?>
<div style="width:165px; height:40px; background: url('http://site1.com/images/DH-sharebar.gif') repeat-x top #333;float:right;margin-top:15px;margin-right:20px;border-radius:5px;border:1px #565656 solid;">
<a href="http://site1.com/" target="_blank" title="site 1">
<img src="http://davidhairabedian.com/davidhairabedian/images/DH-sharebar-icon.png" style="border-radius:0;margin-top:5px;margin-left:10px;"/>
</a>
<a href="http://site2.org/" target="_blank" title="site 2">
<img src="http://site1.com/images/DH-sharebar-HPM-icon.png" style="border-radius:0;margin-top:5px;margin-left:10px;"/>
</a>
<a href="http://site3.org/" target="_blank" title="site 3">
<img src="http://site1.com/images/DH-sharbar-EHF.png" style="border-radius:0;margin-top:5px;margin-left:3px;"/>
</a>
<a href="http://site4.org/" target="_blank" title="site 4">
<img src="http://site1.com/images/DH-sharebar-EHC.png" style="border-radius:0;margin-top:5px;margin-left:10px;"/>
</a>
</div>
<?php $content = json_encode(ob_get_clean());
echo "callback($content);";
And after all this, it occurred to me that you could just use an iframe:
<iframe src="http://pagesofinterest.net/stack-examples/what-would-be-the-best-way-to-make-a-widget-that-will-link-to-4-different-websit/iframe.html"></iframe>
Personally, I would use the JavaScript method, as this would allow me to modify the style of the widget whenever I wanted, without requiring my users to update their pages.

How can I grep YouTube video ID from the web?

I was wondering if it was possible to get all the video IDs from a YouTube playlist pages and display them in a list.
<li class="playlist-video-item odd">
<a href="/watch?v=oHg5SJYRHA0&list=FLk8PLezsTU6MuuBxE5utNQw&index=3" class="tile-link-block video-tile">
<span class="video-index">3</span>
<span class="playlist-video-item-base-content">
<span class="thumb-container">
<span class="ux-thumb-wrap">
<span class="video-thumb ux-thumb-114 "><span class="clip"><img src="//i2.ytimg.com/vi/eVMWgmQA4Ig/default.jpg" alt="Thumbnail" ></span></span>
<span class="video-time">3:37</span>
<button type="button" class="addto-container addto-button short video-actions yt-uix-button yt-uix-button-short" onclick=";return false;" data-button-menu-id="shared-addto-menu" data-video-ids="oHg5SJYRHA0" data-button-action="yt.www.addtomenu.load" data-feature="thumbnail" role="button"><img class="yt-uix-button-icon yt-uix-button-icon-addto" src="//s.ytimg.com/yt/img/pixel-vfl3z5WfW.gif" alt=""><span class="yt-uix-button-content"><span class="addto-label hid">Add to</span></span><img class="yt-uix-button-arrow" src="//s.ytimg.com/yt/img/pixel-vfl3z5WfW.gif" alt=""></button>
</span>
As you can see the ID is here data-video-ids="oHg5SJYRHA0"
Rather than scraping the IDs from markup like that, you should probably take a look at the YouTube API
I guess you want this to be done with jQuery, according to your tags.
$('span.ux-thumb-wrap button').data('video-ids')
Your example code only have one ID, so I wouldn't know how to create a list. Or what type of list for that matter. Please add a comment with further instrux as needed.

Categories