I would like to include a video into a website. I need no help with that. But for improving the loading time, I would like to check the internet speed of the user with pure php and then decided to load the video immediately if the internet speed is fast enough and it takes maximum 2 seconds to download that video. else I would like to show an image and give the user to load the video after the rest of the page is already shown.
For giving you an idea what it should look like hava look at this page: https://rocketlabusa.com/
I do already have some code and need just some help with getting the internet speed. I'm able to develop the rest on my own.
Thanks!
That's my code:
<?php
define ( "urlToVideo", "someVideo.mp4" );
define ( "sizeOfMovieInBytes", filesize ( urlToVideo ) );
define ( "speedOfInternetConnectionInBytesPerSecond", 1 ); /* this is what I need */
if (sizeOfMovieInBytes / speedOfInternetConnectionInBytesPerSecond > 2) { // if it takes more than 2 Seconds to load the movie
/*
* a image should be shown and a play button for enabling the user to load the video after the rest of the website has loaded
*/
} else { // if it takes 2 seconds or less
/*
* the video should be loaded immediately and the image and played immediately
*/
}
?>
Related
I am working on a MemberMouse subscription Wordpress website. On a specific user page I want to display content for a finite period of time. The same should go into a widget.
[MM_Member_Decision membershipId='1' daysAsMember='1' daysAsMember='-3']
**HERE SHOULD BE CONTENT OR A PICTURE**
[/MM_Member_Decision]
Basically, I want to be able to display content for my members for a finite period of time (e.g. 24 hours only).
And I want to be able to do this at any time in a member's life cycle (e.g. 7 days after they joined, 30 days after they joined, etc.)
Usually the SmartTags are looking like above, documentation below:
[MM_Member_Decision membershipId='1' daysAsMember='7']
This content will be displayed if the viewing member has been a member of membership level with ID #1 for at least 7 days.
[/MM_Member_Decision]
[MM_Member_Decision membershipId='1' daysAsMember='-10']
This content will be displayed if the viewing member has been a member of membership level with ID #1 for no more than 10 days.
[/MM_Member_Decision]
Even though this is useful, MemberMouse does not allow us to simultaneously define a positive and negative value for the daysAsMember parameter (or the daysWithBundle parameter for that matter).
In other words, if we want to show John our "Super Awesome Content" on day 7 of his membership, and make it invisible again on day 8 (thus making it a 24 hour-only window of availability), we can't do that out of the box with MemberMouse.
I found this on the web as solution:
<?php if(mm_member_decision(array("daysAsMember"=>"1")) && mm_member_decision(array("daysAsMember"=>"-3")) && (mm_member_decision(array("hasBundle"=>"2")) == false)) { echo '"13")) . '">**HERE SHOULD BE CONTENT OR A PICTURE** ; } ?>
You'll notice that the first PHP tag checks to make sure the member has been a member for 1 days.
The second tag checks to make sure that he has not been a member for more than 3 days.
Then we check to make sure he does not have access to bundle with the ID number 2.
And if all of these conditions are met, we display the Text "HERE SHOULD BE CONTENT OR A PICTURE".
Then closing out the PHP statement.
So far so good. However, I am trying since a couple of days how to implement this matter into a widget or in a page. Since it is a PHP code it is a little more difficult. Addiontally, I am not sure if the PHP code is even correct. This was just a assumption I found on the web.
Any solution to this problem would be appreciated.
Thanks,
Aron
The first thing you would do is create a widget. You can do that using the Widgets API. Then you can put whatever php code you want inside an instance of the widget.
Something like this should get you started (in functions.php or another theme file)
class MemberMouseFiniteContent extends WP_Widget {
function __construct(){
parent::__construct('mm-finite-content',
'MemberMouse Finite Content',
array('description' => 'A widget for displaying content in a time window')
);
}
// front-end
public function widget($args,$instance){
if( mm_member_decision(array("daysAsMember"=>"1"))
&& mm_member_decision(array("daysAsMember"=>"-3"))
&& (mm_member_decision(array("hasBundle"=>"2")) == false)
) {
echo 'HERE SHOULD BE CONTENT OR A PICTURE';
}
}
public function form($instance){
// if you want to configure the widget put the form here.
// #see https://codex.wordpress.org/Widgets_API
}
public function update($new,$old){
return $new;
}
}
// register the widget
add_action( 'widgets_init', function(){
register_widget( 'MemberMouseFiniteContent' );
});
I'm building a feature into a Laravel 5 app that will allow you to set the content of a status banner that will display across the top of the page. We will be using this banner both to display page-specific things (status messages, etc) and site-wide announcements (every user sees the same thing, banner stays the same for awhile).
Right now, I've implemented this by using Laravel sessions to allow banners to be added by calling a helper method from any controller or middleware:
// Call set_banner from in a controller or middleware (for persistent banners)
function set_banner($banner_text, $banner_class, $banner_persistant=false, $replace=false)
{
$banners = session()->get('banners', []);
// Create new banner
$banner = [
'text' => $banner_text,
'type' => $banner_class,
'persistent' => $banner_persistant
];
// Only put banner in array if it's not already there
if( !in_array($banner, $banners) ) {
// Either override existing banners, or add to queue
if( !$replace ) session()->push('banners', $banner);
else session()->put('banners', [$banner]);
}
}
// Called by default in the master.blade.php template
function get_banners()
{
$banners = session()->pull('banners', Array());
foreach( $banners as $banner ) {
// Print out each banner
print '<div class="col-md-12"><div class="text-center alert alert-block alert-'.$banner['type'].'">';
print $banner['text'];
print '</div></div>';
// Push back into the session if banner is marked as persistent
if ( $banner['persistent'] ) session()->push( 'banners', $banner );
}
}
Banners are created in controllers or middleware like this:
set_banner("<b>Note:</b> This is a sample persistant-scope banner set in a controller", "success", true);
Is there a better way to accomplish storing both page-level and site-wide banners? My concerns is that hitting the session on every pageload may be inefficient, especially for banners that won't be changing for long periods of time. Will this approach mess with Laravel's cache, etc?
As you said the banners do not change that often. Hence for me i would implement it using Cache. This improves performance since we need only one use to have the banners cached. And for the rest its retrieved faster from the Cache rather Session.
Do you want to have to change code to change the banner of a given page?
I would suggest instead creating a "pages" package, where each page route name is entered into a database.
From there, from your page service provider you get Page::getModel()->banner_text or something similar.
The method would look for a db result matching the current route name with a result within db.
when a controller method is triggered you simply call
Page::getBannerText()
That method will pull the current route name, pull the page result related to that page if it exists or create it if it does not exist (easy way to get everything). You cache the db query result for X hours, days or whatever so whenever someone else makes a call, you don't even need to deal with any storage on client side.
This allows you to modify the value from a db fascet. Its the more "proper" way to do it.
I am basically creating an iphone app that get's it's data from wordpress. Wordpress will serve audio and video links via a RSS feed to the iphone app. I have the feed and audio player working great but can't seem to find anything related to how to create a custom feed where I can specify pagination like start=0&items=10. A plugin would be great but I can code something up in PHP if anyone has any ideas.
I'm going to answer this question by changing the standard RSS feed of a WordPress installation to respond to limits passed by query parameters. As you say you've already got a working feed, this should hopefully give you everything else you need.
By default, the standard feeds in WordPress are limited by the setting "Syndication feeds show the most recent X items" on the Settings→Reading page, and are unpaginated, as that wouldn't generally make sense for an RSS feed. This is controlled by WordPress's WP_Query::get_posts() method, in query.php, if you're interested in taking a look at how things work internally.
However, although the feed query's limit is set to LIMIT 0, X (where X is the above setting, 10 by default) , you can override the limit by filtering the query in the right place.
For example, the filter post_limits will filter the LIMIT clause of the query between the point it's set up by the default code for feeds and the time it's run. So, the following code in a plugin -- or even in your theme's functions.php -- will completely unlimit the items returned in your RSS feeds:
function custom_rss_limits($limits) {
if (is_feed()) {
// If this is a feed, drop the LIMIT clause completely
return "";
} else {
// It's not a feed; leave the normal LIMIT in place.
return $limits;
}
}
add_filter('post_limits', 'custom_rss_limits');
(At this point I should mention the obvious security implications -- if you've got 20,000 posts on your blog, you'll cause yourself a lot of server load and bandwidth if if lots of people start grabbing your feed, and you send out all 20,000 items to everyone. Therefore, bear in mind that whatever you end up doing, you may still want to enforce some hard limits, in case someone figures out your feed endpoint can be asked for everything, say by analysing traffic from your iPhone app.)
Now all we've got to do is to respond to query parameters. First of all, we register your two query parameters with WordPress:
function rss_limit_queryvars( $qv ) {
$qv[] = 'start';
$qv[] = 'items';
return $qv;
}
add_filter('query_vars', 'rss_limit_queryvars' );
That allows us to pass in the start and items variables you're suggesting for your URL parameters.
All we have to do then is to adjust our original LIMIT changing function to respond to them:
function custom_rss_limits($limits) {
if (is_feed()) {
global $wp_query;
if (isset($wp_query->query_vars['start']) &&
isset($wp_query->query_vars['items'])) {
// We're a feed, and we got pagination parameters. Override our
// standard limit.
// First convert to ints in case anyone's put something hinky
// in the query string.
$start = intval($wp_query->query_vars['start']);
$items = intval($wp_query->query_vars['items']);
$limits = "LIMIT $start, $items";
} else {
// We weren't passed pagination parameters, so just
// leave the default limits alone.
}
}
return $limits;
}
add_filter('post_limits', 'custom_rss_limits');
And there you go. Throw those last two blocks of code at WordPress, and you can now use a URL like this on any of your existing feeds:
http://example.com/feed/?start=30&items=25
For this example, you'll get the normal RSS feed, but with 25 items starting from item number 30.
...and if you don't pass the query parameters, everything will work like normal.
I am using the Google Analytics PHP class to get data from Google Analytics.
http://code.google.com/p/gapi-google-analytics-php-interface/wiki/GAPIDocumentation
I would like to get a report of "Bounce Rate" For "Top Contnet".
The thing is I am not familiar with the terminology.
When I am trying to get a "content" report or "topcontent" or "top_content" it says that there in no such metric. I simply don't know the right expressions.
Does anyone know where can I find a list of all expressions? metrics & dimensions?
Thanks.
Top content isn't a metric, it's just a list of the pages on your site with the highest number of page views.
The metric you're looking for is 'entranceBounceRate' and the dimension is 'pagePath'. You want to get the bounce rate for the top X most visited pages on your site, so you'll want to limit your results and sort the results by '-pageviews' (pageviews descending).
If you want to get the bounce rate for the top 10 most viewed pages on your site, your query should look like this:
$ga = new gapi('email#yourdomain.com','password');
$ga->requestReportData(145141242,array('pagePath'),array('entranceBounceRate','pageviews'),array('-visits'),null,null,null,10);
The Google Analytics Export API has a data feed query explorer that should help you out considerably when using GAPI:
http://code.google.com/apis/analytics/docs/gdata/gdataExplorer.html
Also, here's a list of all available dimensions and metrics you can pull from the API:
http://code.google.com/apis/analytics/docs/gdata/gdataReferenceDimensionsMetrics.html
Definitely read over the GAPI documentation:
http://code.google.com/p/gapi-google-analytics-php-interface/wiki/GAPIDocumentation
If you would like to get the global Bounce Rate for the last 30days (by default), here is how. Very simple once you know it.
//Check Bounce Rate for the last 30 days
$ga = new gapi(ga_email, ga_password);
$ga->requestReportData(145141242, NULL ,array('bounces', 'visits'));
$data = round(($ga->getBounces() / $ga->getVisits()) * 100) . "%";
Note that the GAPI has a bug, they mention the dimension parameter is optional (2nd parameter) but it's not. You have to open the gapi.class.php file and patch line 128 with this:
//Patch bug to make 2nd parameter optional
if( !empty($dimensions) ) {
$parameters['dimensions'] = 'ga:'.$dimensions;
} else {
$parameters['dimensions'] = '';
}
So in the project ive been working on i use the youtube API to add a video to a chromeless player (got custom buttons, everything works no problems).
It loads the youtube id which it gets from the database (Codeigniter, PHP).
But what i would like to see is: instead of loading 1 video, id like to add all the videos i get from the database in the cue of that one player.
So only one screen, first video retrieved from dbase gets played first, when its done second get loaded preferably also looped. Is there any way i can achieve this?
My first guess would be to save the array with youtube id's somewhere and on state change (when the 'video stop'-event gets fired) load the next id from the array. Havent tried this yet because id prefer if the cue gets just gets filled on the init, so it doesnt have to load after a video has been ended. Is This possible?
First, you must use Youtube API version 2 to activate newly statechange function.
This is the code for you:
var video_list = [
'21OH0wlkfbc',
'InZNBcJTmWs',
'iIzqYiRo01E',
'ZYmADPVEqU4'
];
var video_current = 0;
function onYouTubePlayerReady( ) {
var o = document.getElementById( 'ytplayer2_object' );
if( o ) {
o.addEventListener( "onStateChange", "ytplayer_statechange" );
}
}
function ytplayer_statechange( state ) {
// 0 => video ended
if ( state == 0 ) {
video_current++;
video_current %= video_list.length;
ytplayer_loadvideo(video_list[ video_current ]);
}
}