I'm currently using this code for embedding from youtube:
if($e['domain'] == "youtube.com") {
preg_match('/[\\?\\&]v=([^\\?\\&]+)/',$e['url'],$matches);
if(count($matches) > 1) {
$embed = true;
$embed_code = "<object width='480' height='344'><param name='movie' value='http://www.youtube.com/v/" . $matches[1] . "?fs=1&hl=en_US&color1=FFFFFF&color2=FFFFFF'></param><param name='allowFullScreen' value='true'></param><param name='allowscriptaccess' value='always'></param><embed src='http://www.youtube.com/v/" . $matches[1] . "?fs=1&hl=en_US&color1=FFFFFF&color2=FFFFFF' type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' width='480' height='344'></embed></object>";
}
}
And I want to use kind of the same for imgur.com which uses the prefix "i" for embedding. So the images are prefix+$e. How do I make it work?
Right now I've tried:
if($e['domain'] == "i.imgur.com") {
preg_match('/[\\?\\&]([^\\?\\&]+)/',$e['url'],$matches);
if(count($matches) > 1) {
$embed = true;
$embed_code = "<img src='http://i.imgur.com/' alt='' title='Hosted by imgur.com' />";
}
}
But I get this error message:
Notice: Undefined variable: embed in /hsphere/local/home/xx/xx/xx/xx/view.php on line 107
EDIT: Here are the lines from 105-116:
else $embed = false;
if(isset($e['description']) || $embed == true) { ?>
<tr class="listing_spacer_tr"><td colspan="6"></td></tr>
<tr><td colspan="5"></td><td>
<?php if($embed) echo $embed_code . "<br /><br />"; ?>
<?php // DESCRIPTION
if(isset($e['description'])) { ?>
<div class="view_description"><?php echo make_clickable(nl2br($e['description'])); ?></div>
<?php }
} ?>
There isn't problem in code you have posted. You've probably got some problems somewhere else. Problem is reading, not assigning value to your $embed variable.
Related
edd restrict content plugin creates this shortcodes and these are working in pages and posts :
[edd_restrict id="any"]sample restricted html or text[/edd_restrict]
but i want to use it in my theme not in the posts or pages.
i tried this :
<?php =echo do_shortcode( '[edd_restrict id="any"]' . sample text . '[/edd_restrict]' );?>
but theme shows me fatal error.
so how can i use this shortcodes in wordress theme?
sample text here will be a php code that i want to restrict.
let me tell you more... i want to put the line below between those shortcodes in my single.php in wordpress :
<li><?php if(get_post_meta($post->ID, 'download',true)!= ""){echo "<a href='".get_post_meta($post->ID, 'download',true)."' > دانلود با لینک مستقیم</a> ";} else { echo ""; } ?>
<?php if(get_post_meta($post->ID, 'download32',true)!= ""){echo "<a href='".get_post_meta($post->ID, 'download32',true)."'>لینک مستقیم نسخه 32bit / </a> ";} else { echo ""; } ?>
<?php if(get_post_meta($post->ID, 'download64',true)!= ""){echo "<a href='".get_post_meta($post->ID, 'download64',true)."'>لینک مستقیم نسخه 64bit </a> ";} else { echo ""; } ?>
<?php if(get_post_meta($post->ID, 'downloadwin',true)!= ""){echo "<a href='".get_post_meta($post->ID, 'downloadwin',true)."'>دانلود نسخه ویندوز </a> ";} else { echo ""; } ?></li>
The method do_shortcode accepts a string of a shortcode and it's attributes/content. So for example
<?php
$string = "some value or <b>html</b>";
// or (?)
$string = include TEMPLATEPATH . "/post-ads.php";
// or (!)
ob_start();
include TEMPLATEPATH . "/post-ads.php";
$string = ob_get_clean();
// for a specific use case:
if (get_post_meta($post->ID, 'download', true) != "") {
$string = "<a href='" . get_post_meta($post->ID, 'download', true) . "' >download</a> ";
} else {
$string = "";
}
if (get_post_meta($post->ID, 'download32', true) != "") {
$string2 = "<a href='" . get_post_meta($post->ID, 'download32', true) . "'>download 32bit / </a> ";
} else {
$string2 = "";
}
// after you have string:
echo do_shortcode('[edd_restrict id="any"]' . $string . '[/edd_restrict]');
My following code is based on
1.Get current URL
2.Go through array and check if in url value = to value in array
do this:
$on_this_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
foreach ($city_array as $sandwich) {
if (strpos($on_this_link, $sandwich) == true) {
$sandwich = trim($sandwich, '/');
$city = $sandwich;
if ($city == 'newyork') {
foreach ($category_array as $double_sandwich) {
if (strpos($on_this_link, $double_sandwich) == true) {
$double_sandwich = trim($double_sandwich, '/');
$category_is = $double_sandwich;
Loader::model('page_list');
$nh = Loader::helper('navigation');
$pl = new PageList();
$pl->filterByAttribute('city', '%' . $city . '%', 'like');
$pl->filterByAttribute('category','%'.$category_is.'%','like');
$pl->sortByDisplayOrder();
$pagelist = $pl->get();
foreach ($pagelist as $p) {
echo '<li> ' .htmlspecialchars($p->getCollectionName()) . ' </li>';
?>
}
}
}
}
So It will show me only pages that have the same attribute with URL
Each of this page has image attribute that I want to show.
How can I pass this Image Attribute??
Check out the comments in the page list block's view template:
https://github.com/concrete5/concrete5/blob/master/web/concrete/blocks/page_list/view.php#L33
You can get image attributes by putting some code like this inside your foreach ($pagelist as $p) loop:
$img = $p->getAttribute('example_image_attribute_handle');
if ($img) {
//you could output the original image at its full size like so:
echo '<img src="' . $img->getRelativePath() . '" width="' . $img->getAttribute('width') . '" height="' . $img->getAttribute('height') . '" alt="" />';
//or you could reduce the size of the original and output that like so:
$thumb = Loader::helper('image')->getThumbnail($img, 200, 100, false); //<--200 is width, 100 is height, and false is for cropping (change to true if you want to crop the image instead of resize proportionally)
echo '<img src="' . $thumb->src . '" width="' . $thumb->width . '" height="' . $thumb->height . '" alt="" />';
}
Thx but I did it already just another way!
I didnt used
Loader::model('page_list');
Instead I used:
$blockType = BlockType::getByHandle('page_list');
And hardcoded the block!
$th = Loader::helper('text');
$ih = Loader::helper('image');
$page_current = Page::getCurrentPage();
$page_2 = $page_current->getCollectionHandle();
$img = $page->getAttribute('product'); $thumb =
$ih->getThumbnail($img, 240,150, false);
And after I changed a little bit my Code above:
$on_this_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
foreach ($city_array as $sandwich) {
if (strpos($on_this_link, $sandwich) == true) {
$sandwich = trim($sandwich, '/');
$city = $sandwich;
if ($city == 'newyork') {
foreach ($category_array as $double_sandwich) {
if (strpos($on_this_link, $double_sandwich) == true) {
$double_sandwich = trim($double_sandwich, '/');
$category_is = $double_sandwich;
$city_att = $page->getAttribute('city', '%' . $city . '%', 'like');
$sub_cat_att = $page->getAttribute('category','%'.$category_is.'%','like'); ?>
<?php if($city == $city_att && $category_is == $sub_cat_att){ ?><li><img src="<?php echo $thumb->src ?>" width="<?php echo $thumb->width ?>" height="<?php echo $thumb->height ?>" alt="" />
<h3> <?php echo $title ?></h3>
<div class="product_description">
<?php echo $description ?>
</div>
Read More...
</li> <?php } ?> <?php
}
}
}
So everything it is working But still thx for respond! Apreciate
I have an webpage where I want to have another html page displayed. I used iframes. The page gets to know what to load is via the get procedure. But there is an fault in this coding I think...
<iframe src="
<?
$file = ($_GET['ti'])
if ($title = '')
echo "information.html";
else echo "$file";
?>
"></iframe>
The url the page would recieve looks like this:
http://www.website.com/reference.html?ti=unlimited.html
http://www.w3schools.com/php/php_if_else.asp
It's your if / else syntax and over all php code. It's not very well written.
<?php
$file = $_GET['ti'];
if ($title = '') {
echo "information.html";
} else {
echo "$file";
}
?>
Need semicolon:
$file = ($_GET['ti']);
Use empty(), like this:
<iframe src="
<?
$file = ($_GET['ti'])
if (empty($title))
echo "information.html";
else echo $file;
?>
"></iframe>
<?php
$possible = array("information.html", "home.html", "test.html");
$file = isset($_GET['ti']) &&
in_array($_GET['ti'], $possible)? $_GET['ti'] : "information.html";
?>
<iframe src="<?php echo $file;?>"></iframe>
I am working on a small project to display live streams for Dota 2, League of Legends and StarCraft 2 and was using a 3rd party hosted api that had both feeds from Twitch.tv and own3d - I couldn't of been happier, until they shut down their servers!
I tried merging them together with Yahoo pipes but didn't have much luck!
These are the two feeds I am working with:
Twitch.tv/justin.tv - http://api.justin.tv/api/stream/list.xml?category=gaming&limit=15
Own3d - http://api.own3d.tv/live?limit=15
Here is my attempt at combining the two feeds, by just listing them on top of each other. Its a temporary solution but they are not sorted by live viewers (which is something I would like to do) -
The current script I have:
<table class="table">
<thead>
<tr>
<th colspan="4" class="streamheader">Current live Sstreams</th>
</tr>
</thead>
<tbody>
<?php
$xmlFileData2 = file_get_contents("http://api.own3d.tv/live?limit=15");
$xmlData2 = new SimpleXMLElement($xmlFileData2);
foreach($xmlData2->channel->item as $item)
if ($item->misc['game'] == 'Dota 2' OR $item->misc['game'] == 'League of Legends' OR $item->misc['game'] == 'StarCraft II') {
{
$titlelimit = $item->title;
$title = substr($titlelimit,0,20);
echo "<tr><td>";
if ($item->misc['game'] == 'League of Legends')
echo"<img src='http://localhost/ae/wp-content/themes/ae/img/lol.jpg' /></td><td>";
elseif ($item->misc['game'] == 'StarCraft II')
echo"<img src='http://localhost/ae/wp-content/themes/ae/img/sc2.jpg' /></td><td>";
elseif ($item->misc['game'] == 'Dota 2')
echo"<img src='http://localhost/ae/wp-content/themes/ae/img/dota2.jpg' /></td><td>";
else
echo "none";
echo "<a href='";
$link = $item->link;
$findthis ="/www.own3d.tv/live/";
$replacement ="ae/stream/";
echo str_replace ($findthis, $replacement, $link);
echo "'>";
echo $title;
echo "</a></td><td>";
$author = $item->author;
$find ="/rss#own3d.tv/";
$replace ="";
echo preg_replace ($find, $replace, $author);
echo "<td>";
echo $item->misc['viewers'];
echo "</td> </tr>";
}
}
else
{
echo "";
}
$xmlFileData1 = file_get_contents("http://api.justin.tv/api/stream/list.xml?category=gaming&limit=15");
$xmlData1 = new SimpleXMLElement($xmlFileData1);
foreach($xmlData1->stream as $itemtwitch) {
$game = $itemtwitch->meta_game;
$sc2 = "StarCraft II: Wings of Liberty";
if ($itemtwitch->meta_game == 'Dota 2' OR $itemtwitch->meta_game == 'League of Legends' OR $itemtwitch->meta_game == 'StarCraft II: Wings of Liberty') {
{
echo "<tr><td>";
$titlelimittwitch = $itemtwitch->title;
$titlelimittwitch = substr($titlelimittwitch,0,20);
if ($itemtwitch->meta_game == 'League of Legends')
echo"<img src='http://localhost/ae/wp-content/themes/ae/img/lol.jpg' /></td><td>";
elseif ($itemtwitch->meta_game == 'StarCraft II: Wings of Liberty')
echo"<img src='http://localhost/ae/wp-content/themes/ae/img/sc2.jpg' /></td><td>";
elseif ($itemtwitch->meta_game == 'Dota 2')
echo"<img src='http://localhost/ae/wp-content/themes/ae/img/dota2.jpg' /></td><td>";
else
echo "none";
$data = $itemtwitch->name;
$find ="/live_user_/";
$replace ="";
echo "<a href='";
echo "http://localhost/ae/stream/";
echo preg_replace ($find, $replace, $data);
echo "''>";
echo "$titlelimittwitch";
//print(" - " . $itemtwitch->meta_game . "");
echo "</a></td><td>";
echo preg_replace ($find, $replace, $data);
print("</td><td>" . $itemtwitch->channel_count . "</td></tr>");
}
}
else {
echo "";
}
}
?>
<tr>
<th colspan="4" class="streamheader centered">View all streams</th>
</tr>
</tbody>
</table>
Any guidance or being pointed in the right direction would be fantastic.
Cheers!
Dan, you will need to add both sets of information(own3d/twitch) to the same array, then sort it. Say you add them to an array named $streamArray you would use the following code to then sort them by viewers.
foreach ($streamArray as $key => $row) {
$viewers[$key] = $row['viewers'];
}
array_multisort($viewers, SORT_DESC, SORT_NUMERIC, $streamArray);
I have developed a similar setup at http://halfw.com/streams.php
If you have any questions just let me know!
You can use a library like Streamtastic (disclaimer: I wrote it) to get latest and top viewed streams for both Own3d and Twitch.tv
https://github.com/sergiotapia/Streamtastic
Usage is very simple:
Own3d Examples:
StreamFinder own3dStreamtastic = new StreamFinder(new Own3dStreamRepository());
// Let's find the most viewed streamers in general.
var topStreamers = own3dStreamtastic.FindTopViewedStreams();
foreach (var stream in topStreamers)
{
Console.WriteLine(String.Format("{0} - Viewers: {1}", stream.Title, stream.ViewerCount));
}
// You can find the top viewed streamers for any game Own3d supports.
// For example, League of Legends.
var topStreamersForLeagueOfLegends = own3dStreamtastic.FindTopViewedStreamsByGame("League+of+Legends");
foreach (var stream in topStreamersForLeagueOfLegends)
{
Console.WriteLine(String.Format("{0} - Viewers: {1}", stream.Title, stream.ViewerCount));
}
// Or how about League of Legends.
var topStreamersForLol = own3dStreamtastic.FindTopViewedStreamsByGame("League+of+Legends");
foreach (var stream in topStreamersForLol)
{
Console.WriteLine(String.Format("{0} - Viewers: {1}", stream.Title, stream.ViewerCount));
}
Since you're using PHP, just run this application and save results to the database. Then have your PHP program just fetch results from the database.
On My Site users can login and add news. That works fine. I have problems when trying to display the news. First problem is if the news text doesn't fill all the space by the side of the news image, then the next news item gets displayed too soon (not below the orange breaker) as you can see on the site at the moment. I was thinking to get around this I could set the height of each news post div to the height of the image, although the image is a little shorter than the div so I'm not sure how I'd do that.
Secondly, users put links in their news posts. How do I get them to be displayed as active? on firefox they just come out as text. Could someone point me in the right direction please!
Here's the code:
$query="SELECT id, date, title, text, author, media1, media2, deleted FROM news ORDER BY id DESC LIMIT 4";
$result=mysql_query($query);
$counter = 0;
$number1 = 1;
$number2 = 2;
while($row = mysql_fetch_array($result)){
if($row['deleted'] == 0) {
if (($counter % 2) == 0) {
echo '<div id="text">';
echo '<a name="'.stripslashes($row['title']).'" id="'.stripslashes($row['title']).'"></a>';
echo '<span class="kisstitle">'.stripslashes($row['title']).'</span><br>';
echo ' (';
echo $row['date'];
echo ')';
echo '<br>';
echo '<br>';
if((preg_match ("/\bjpg\b/",$row['media1'])) || (preg_match ("/\bjpeg\b/",$row['media1'])) || (preg_match ("/\bpng\b/i",$row['media1'])) || (preg_match ("/\bgif\b/i",$row['media1']))){
echo '<img style="max-width:300px;" src="media/news/'.$row['media1'].'" class="floatRightClear" id="border">';
}
if((preg_match ("/\bjpg\b/",$row['media2'])) || (preg_match ("/\bjpeg\b/",$row['media2'])) || (preg_match ("/\bpng\b/i",$row['media2'])) || (preg_match ("/\bgif\b/i",$row['media2']))){
echo '<img style="max-width:300px;" src="media/news/'.$row['media2'].'" class="floatRightClear" id="border">';
}
if((preg_match ("/\bmp3\b/", $row['media1']))) {
echo ' <p id="audioplayer_'.$number1.'" class="floatRightClear">Media Content</p>
<script type="text/javascript">
AudioPlayer.embed("audioplayer_'.$number1.'", {soundFile: "http://kiddiessupportscheme.org/media/news/'.$row['media1'].'"});
</script>';
echo '<br>';
}
if((preg_match ("/\bmp3\b/", $row['media2']))) {
echo ' <p id="audioplayer_'.$number2.'" class="floatRightClear">Media Content</p>
<script type="text/javascript">
AudioPlayer.embed("audioplayer_'.$number2.'", {soundFile: "http://kiddiessupportscheme.org/media/news/'.$row['media2'].'"});
</script>';
echo '<br>';
}
echo stripslashes(nl2br($row['text']));
echo '<br><br>';
echo stripslashes($row['author']);
echo '</div>';
echo '<p align="right" id="seperater">Top<img src="images/seperater.jpg" width="950" height="6" style="border:none;" /></p>';
}
else {
echo '<div id="text">';
echo '<a name="'.stripslashes($row['title']).'" id="'.stripslashes($row['title']).'"></a>';
echo '<span class="kisstitle">'.stripslashes($row['title']).'</span><br>';
echo ' (';
echo $row['date'];
echo ')';
echo '<br>';
echo '<br>';
if((preg_match ("/\bjpg\b/",$row['media1'])) || (preg_match ("/\bjpeg\b/",$row['media1'])) || (preg_match ("/\bpng\b/i",$row['media1'])) || (preg_match ("/\bgif\b/i",$row['media1']))){
echo '<img style="max-width:300px;" src="media/news/'.$row['media1'].'" class="floatLeftClear" id="border">';
}
if((preg_match ("/\bjpg\b/",$row['media2'])) || (preg_match ("/\bjpeg\b/",$row['media2'])) || (preg_match ("/\bpng\b/i",$row['media2'])) || (preg_match ("/\bgif\b/i",$row['media2']))){
echo '<img style="max-width:300px;" src="media/news/'.$row['media2'].'" class="floatLeftClear" id="border">';
}
if((preg_match ("/\bmp3\b/", $row['media1']))) {
echo ' <p id="audioplayer_'.$number1.'" class="floatLeftClear">Media Content</p>
<script type="text/javascript">
AudioPlayer.embed("audioplayer_'.$number1.'", {soundFile: "http://kiddiessupportscheme.org/media/news/'.$row['media1'].'"});
</script>';
echo '<br>';
}
if((preg_match ("/\bmp3\b/", $row['media2']))) {
echo ' <p id="audioplayer_'.$number2.'" class="floatLeftClear">Media Content</p>
<script type="text/javascript">
AudioPlayer.embed("audioplayer_'.$number2.'", {soundFile: "http://kiddiessupportscheme.org/media/news/'.$row['media2'].'"});
</script>';
echo '<br>';
}
echo stripslashes(nl2br($row['text']));
echo '<br><br>';
echo stripslashes($row['author']);
echo '</div>';
echo '<p align="right" id="seperater">Top<img src="images/seperater.jpg" width="950" height="6" style="border:none;" /></p>';
}
$number1++;
$number1++;
$number1++;
$number2++;
$number2++;
$number2++;
$counter++;
}}
to your first problem:
First problem is if the news text doesn't fill all the space by the side of the news image, then the next news item gets displayed too soon (not below the orange breaker) as you can see on the site at the moment. I was thinking to get around this I could set the height of each news post div to the height of the image, although the image is a little shorter than the div so I'm not sure how I'd do that.
You only have to edit your css file:
Change:
#seperater {
float: left;
}
To:
#seperater {
clear: both;
}
For your second problem, I found this link: http://www.sitepoint.com/forums/3713338-post5.html There is exactly the solution you need.
Code from the link I posted above:
define( 'LINK_LIMIT', 30 );
define( 'LINK_FORMAT', '%s' );
function prase_links ( $m )
{
$href = $name = html_entity_decode($m[0]);
if ( strpos( $href, '://' ) === false ) {
$href = 'http://' . $href;
}
if( strlen($name) > LINK_LIMIT ) {
$k = ( LINK_LIMIT - 3 ) >> 1;
$name = substr( $name, 0, $k ) . '...' . substr( $name, -$k );
}
return sprintf( LINK_FORMAT, htmlentities($href), htmlentities($name) );
}
$s = 'Here is a text - www.ellehauge.net - it has some links with e.g. comma, www.one.com,
in it. Some links look like this: http://mail.google.com - mostly they end with a
space or carriage return www.unis.no
<br /> - but they may also end with a period: http://ellehauge.net. You may even put
the links in brackets (www.skred-svalbard.no) (http://one.com).
From time to time, links use a secure protocol like https://gmail.com |
This.one.is.a.trick. Sub-domaines: http://test.ellehauge.net |
www.test.ellehauge.net | Files: www.unis.no/photo.jpg |
Vars: www.unis.no?one=1&~two=2 | No.: www.unis2_check.no/doc_under_score.php |
www3.one.com | another tricky one:
http://ellehauge.net/cv_by_id.php?id%5B%5D=105&id%5B%5D=6&id%5B%5D=100';
$reg = '~((?:https?://|www\d*\.)\S+[-\w+&##/%=\~|])~';
print preg_replace_callback( $reg, 'prase_links', $s );