I have a database with roughly 500 cards.
They have qualities 0,1,2,3,4,5.
Each quality has different colors, in CSS I have:
.quality0 { color: grey }, .quality1 { color: green } and so on...
I want if there's an URL on the page, like mywebsite.com/card/card_id_comes_here, then add a class called quality + print $card['quality']
$card['quality'] is the number (0,1,2,3,4,5) from database.
I use this code on pages where I just list the cards and their names, there's no problem with this, because everything is already there:
<a class="quality<?php print $card['quality'] ?>"
href="/card/<?php print $card['id']; ?>">
<?php print $card['name']; ?></a>
But if I create a new article and link to these card pages, It won't type manually to all URLs that class="quality3" or so...
I want if I have an URL with mywebsite.com/card/id to add the class quality + print the id from database as I mentioned above.
How is this possible?
You will have to retrieve the id from the url. The best way probably is to use the mod-rewrite module and retrieve the id-variable from the url via $_GET.
It is a bit tricky if you have never done it before, you better look at some examples and read a guide like this one: Guide to mod_rewrite
edit: If you have the ID, I guess you know how to do the rest, right?
Related
We're trying to create a trackback system where an outside web publisher can put some html on a page on their website that links back to a specific product page on our site. Let's call it a 'badge' for purposes of this question.
Once they've inserted the badge, we want to identify this, then grab the < h1 > and first < p > as a teaser to comprise a link from our site back to theirs and write all this stuff to our database. Then, our users can see the title and first bit of their page, then decide if they want to see more.
Here's what we've done (not much I'm afraid):
<a href="http://www.mysite.com/abc.html">
<img alt="abc" src="http://www.mysite.com/logo.gif" style="width:200px;height:100px" />
</a>
We're planning to build an admin page to do the last part of grabbing the < h1> and < p> and posting it to the live database, etc. and we'll figure this out later.
However, the middle step (identifying that this piece of html has been used) we're at a loss.
Is this something we should be doing through a log file....I have no clue even how to begin thinking about it.
A little direction of where to begin working on this problem would be very helpful.
Thanks in advance!!
This is one approach.
You give them HTML which looks something like:
<a href="http://www.mysite.com/abc.html">
<img alt="abc" src="http://www.mysite.com/logo.php" style="width:200px;height:100px" />
</a>
Notice that says logo.php, not logo.gif.
logo.php will live on your server. Its purpose is twofold:
Gather information about the page holding the <img> tag
Load and output logo.gif so the users see the image as expected.
If you embed that html on a webpage somewhere, logo.php will have information about where the request for the image originated. Specifically, $_SERVER['HTTP_REFERER'] will give you the complete URL to the page where the img tag resides. It is then up to you to decide how to process and store that information.
I don't know exactly what you want to do, but a very simplified logo.php would look something like this:
<?php
$url = $_SERVER['HTTP_REFERER'];
// do something with $url...
// it will be something like "http://theirsite.com/wherever/they/pasted/the.html"
// now output the logo image...
header("Content-Type: image/gif");
echo file_get_contents("/path/to/logo.gif");
Keep in mind that every time anyone hits their page with the image tag, logo.php will be run. So don't accidentally create 10000 links back to their site on your site :)
Apologies, novice Drupal question warning:
Aim: to split my outputted list of custom field images up so I can use them differently.
ie. In my node.tpl.php use the first 3 (most recent node) images in a slider. Then list the rest (offsetting the first three) just as plain images.
But I can't find how to limit my results. In my node template I can style all my images up using something like this:
<a href="<?php $nodeurl = url('node/'. $node->nid); echo $nodeurl; ?>"
<img src="<?php print render (file_create_url($node->field_featured_image['und'][0]['uri'])); ?>" alt="<?php echo $title; ?>" />
</a>
But how do I limit the result? I guess this would work to ignore the first 3 results:
<?php foreach($node->field_featured_image as $k=>$v){
if ($k < 3) continue;
print render (file_create_url($node->field_featured_image['und'][0]['uri']));
}
?>
But not in node.tpl as node.tpl appears to be a loop so the above code gets looped and the array key never gets past 0.
I think :/
Am I way off here with a basic misunderstanding of the templates?
Any pointers appreciated. Desperately trying to stick with drupal but finding it tough.
I might be mislead by what you're trying to accomplish, but you probably don't need to be hacking into node.tpl.php just yet.
If you aren't using Views, start with that.
If you're trying to build a slider, use Views Rotator.
If you want something that's ready to be dropped in, use Enterprise Rotator. (basically Views Rotator and a Banner Slide content type built out already).
You can offset the images by using the pager options to either show a certain number, and offset the number of images queued up.
Or if you want to just use specific images, use Nodequeue. Make a simple queue, add the nodes that contain the images you want, then in your View create a relationship (marked as required) to the nodequeue.
I have a need for getting preview a url over mouse hover, my application is built on php , js and jquery. Although I have an idea of to get to my requirements but am a little confused with the right approach, i checked all the posted question on here but most of them refer to some third party tools or installables. Frnakly i do not want to use them and think i should try one on my own. Please can you guide me through on the best possible step as per you?
Thanks!
11-Jun-2012
Finally I managed to use Curl and get a preview of the site on a Div placed next to the Link on my site, well now the problem is of fitting the content in the Div ..is there a way that I can adjust the css of the extracted html page in such a way that all the content fits in the fixed height and width of the Div.scaledown option or something? that would scale everything down to the required proportion?
You can do this, in plain ol' CSS and HTML:
.mouseover {
position:absolute;
width:200px;
height:200px;
top:5px;
left:5px;
display:none;
}
.link {
position:relative;
}
.link:hover .mouseover {
display:block;
}
Then, in HTML:
<a href="#" class="link">Link
<div style="background:url('<URL HERE>')" class="mouseover"></div>
</a>
Ok, so you want to get a thumbnail of a webpage and show it on mouse over. To do that, you'll need to either use tools that generate thumbnails or write a PHP script yourself. Here are some tools:
websnapr
Website Thumbnail Generator - This one you can install on your own server
If you want to write your own, check out imagegrabwindow. Note that it requires a Windows server. I don't know if PHP has any other methods to do this. If you're not on a Windows server, you could write a bash script to open a browser and use a screenshot utility to take a screenshot and save it to a file for your website to pick up.
You'll also have to make sure to have some sort of cache so you're not doing this every time every user moves their mouse over a link.
You can use urlbox.io for this, here's an example preview thumbnail of this very URL:
https://api.urlbox.io/v1/ca482d7e-9417-4569-90fe-80f7c5e1c781/32040df25d7c57da28ef4da7ce461af00d852653/png?url=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F10970647%2Fthumbnail-preview-of-a-url-using-php-and-javascript&thumb_width=400
You can see that the options passed into the Urlbox API are simply url, and thumb_width to set the desired width of the thumbnail in pixels, in this case I chose 400 pixels wide.
Now all you got to do is embed it in an <img> tag like so:
<img src="https://api.urlbox.io/v1/ca482d7e-9417-4569-90fe-80f7c5e1c781/32040df25d7c57da28ef4da7ce461af00d852653/png?url=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F10970647%2Fthumbnail-preview-of-a-url-using-php-and-javascript&thumb_width=400"/>
You can use API to do this. For example ApiFlash has a free plan that you can use up to 100 screenshots per month.
Here is how it would look like with PHP:
<?php
$params = http_build_query(array(
"access_key" => "YOUR_ACCESS_KEY"
"url" => "https://example.com",
));
$image_data = file_get_contents("https://api.apiflash.com/v1/urltoimage?" . $params);
file_put_contents("screenshot_api_example.jpeg", $image_data);
?>
The API has a very good uptime because it's based on AWS Lambda.
We have several pages generated using PHP on our website with the following titles (for example):
http://www.mysite.com/project/category/1
http://www.mysite.com/project/category/2
http://www.mysite.com/project/category/3
Each one is created dynamically with the same page layout with each showing a different database result depending on the predefined conditions.
I would like an image to be displayed at the top of the page for just one of the results, let's say for http://www.mysite.com/project/category/2 - how can I go about this?
The relevant code on our page is this:
$category=mysql_fetch_array(mysql_query("select * from project_category where project_category_id='".$project_category_id."'"));?>
If we go down the if statement route can you show an example of how to display an example image by modifying the above code to get me started?
I would probably make it a property (can be a as simple yes/no) in the database, and use the existing db-result to determine if the category has to display a page. Although this might seem overkill - I'd definitely pick this dynamic solution over a if ($categoryId == 2) { } solution any day. Keeps it dynamic and your code clean and generic.
In the end I opted for an if statement (as found here http://www.tizag.com/phpT/if.php).
The original code above was modified in the following way:
$category=mysql_fetch_array(mysql_query("select * from project_category where project_category_id='".$project_category_id."'"));
if ( $project_category_id == "2" ) {
echo '<img src="http://www.mywebsite.com/image.jpg" width="675" height="75" border="0" />';
}?>
I have some thumbnail images with its larger version.I placed the thumbnail images in a page.Now for link I just gave a link
<img src="thumbnail1.jpg>
but for this I have to make different pages for showing larger one.I want to give a link to show them in a single page.means whenever I will click the thumbnail it will open the larger one in a page with the same url but with its name like
imagegallery.php?news=images/largerimage1/13.jpg
imagegallery.php?news=images/largerimage1/14.jpg
so how to do that?
Pretty basic stuff, I suggest you get to read some PHP tutorials on the internet to get some knowledge on one thing and another.
The ?news= part in your URL is a parameter that can be read by PHP. This type is known as $_GET. To get this part you would need $_GET['news'] so if we'd use your first link and place this inside a script: echo $_GET['news']; the page would say images/largerimages1/13.jpg.
In order to get the image loaded on your website we need some simple steps, I'm changing the news parameter into image, that suits better for your script since it ain't news items:
<?php
// Define the path (used to see if an image exists)
$path = 'your/absolute/path/to/public_html/'; # or wwwroot or www folder
// First check if the parameter is not empty
if($_GET['image'] != "") {
// Then check if the file is valid
if(file_exists($path . $_GET['image'])) {
// If an image exists then display image
echo '<img src="'. $_GET['image'] . '" />;
}
}
?>
Below this script you can put all your thumbnails the way you want. Ofcourse, also for these thumbnails there are some automated options. But I strongly suggest you get a good look at the script above and some beginner PHP tutorials so you completely understand the example given. This still isn't the best method, but it's kicking you in the right direction.
if your imagegallery.php is in root of your domain, you can just add slash as a first char to links like this:
<img src="thumbnail1.jpg>
else you will have to write some php function which it returns BaseUrl of your web. Then it should looks like this:
<img src="thumbnail1.jpg>
maybe you can something like this,
Techincally, there is no thumbnail image, just a stretch version of the regular image
I don't understand which part you don't know how to do:
- the link part?
it should look like
<img src="thumbnail1.jpg>
- or the PHP part (the file called imagegallery.php)?