Automatically display "Google Adsense for Search" results - search

I am working on a website that uses PHP/MySQL to search the website's database and display results. In addition, I now want to display results from Google Adsense for search, but without the user having to manually enter search terms into the search box.
So say the user selects the following variables for the database search:
$var1 = apples;
$var2 = pears;
$var3 = cake;
Then I want to also display search results from Google Adsense for search, as if the user had entered the following into the search box: "cake apples pears". Or something along those lines anyway.
So probably that's a bit of an indirect way of explaining what I want to do, but hopefully it's clear. How do I do this? I'm thinking along the lines of having Javascript enter the search terms automatically into the searchbox, but maybe there is a much more straightforward way without having to display/use a searchbox at all?
Thanks a lot!

Using Curl, like this :
$var1 = 'apples';
$var2 = 'pears';
$var3 = 'cake';
$query= $var1 . '+' . $var2 . '+' . $var3;
$ch=curl_init();
curl_setopt ($ch, CURLOPT_URL, "http://www.google.com/support/adsense/bin/search.py?query=$query");
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec ($ch);
curl_close($ch); // good practice to close connection, it can save a lot of time in some cases.
echo $data;

Related

Reverting a str_replace for GET in PHP

I am dynamically displaying sermons from a MYSQL database, and I want to create a dynamic page for each sermon series. Because the series titles have spaces in them, and I want to avoid that in my URLs, I have done str_replace:
(Series name)
That works great. But then of course on the dynamically-created page, I need a way to revert back to the original series name in order to fetch the actual sermon data, and I haven't figured out to how to accomplish that. I've tried this:
$series = $_GET['series'];
$str = $series;
$str = str_replace("-"," ",$str);
... ahead of my prepare & execute statements (I'm using PDO), but that doesn't really look right, and in any case doesn't work.
Is there actually a way to this?
I just needed to change one variable. The lead variable of the third line needed to be $series, not $str:
$series = $_GET['series'];
$str = $series;
$series = str_replace("-"," ",$str);

How to open URL in Microsoft Edge from the command line?

I need to open URL in Microsoft Edge (on Windows 10). When I invoke
start shell:AppsFolder\Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge http://www.google.com
then Microsoft Edge is started correctly but it doesn't open the given URL (www.google.com, in this case). It opens Bing search where the given URL is used as a search term instead.
The following method should work via Command Prompt (cmd):
start microsoft-edge:http://www.cnn.com
Windows 10: Create a shortcut with this destination:
%windir%\system32\cmd.exe /c "start microsoft-edge:https://twitter.com"
and a shortcut:
C:\Windows\System32\cmd.exe /c start shell:AppsFolder\Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge http://localhost:6516
I too was wondering why you can't just start microsoftedge.exe, like you do "old-style" applications in windows 10. Searching the web, I found the answer -- it has to do with how Microsoft implemented "Universal Apps".
Below is a brief summary taken from that answer, but I recommend reading the entire entry, because it gives a great explanation of how these "Universal Apps" are being dealt with. Microsoft Edge is not the only app like this we'll be dealing with.
Here's the link: http://www.itworld.com/article/2943955/windows/how-to-script-microsofts-edge-browser.html
Here's the summary from that page:
"Microsoft Edge is a "Modern" Universal app. This means it can't be opened from the command line in the traditional Windows manner:  Executable name followed by command switches/parameter values. But where there's a will, there's a way. In this case, the "way" is known as protocol activation."
Kudos to the author of the article, Stephen Glasskeys.
All the other solutions work for Microsoft Edge (legacy) and on Windows 10 only.
As of 2020, it will be discontinued and replaced by Microsoft Edge (Chromium based).
The solution that works with the new Edge on Windows 7, 8 and 10 is :
start msedge URL
Source :
https://en.wikipedia.org/wiki/Microsoft_Edge#Anaheim_(2019%E2%80%93present)
https://learn.microsoft.com/en-us/deployedge/microsoft-edge-sysupdate-windows-updates
While the accepted answer is correct, it has the unwanted artifact of flashing a console window when running from a non-console application.
The solution I found works best, which is only mentioned here in a comments to the question, is the following command line:
explorer.exe "microsoft-edge:<URL>"
Keep in mind that if contains the % sign you will need to type %% as Windows uses the symbol for variable expansion.
Hope someone finds this helpful.
Personally, I use this function which I created and put in my profile script ...\Documents\WindowsPowerShell\….profile, feel free to use it. As I am from the UK, I prefer to go to .co.uk where possible, if you are from another area, you can add your own country code.
# Function taking parameter add (address) and opens in edge.
Function edge {
param($add)
if (-not ($add -contains "https://www." -or $add -contains "http://www.")) {
if ($add[0] -eq "w" -and $add[1] -eq "w" -and $add[2] -eq "w") {
$add = "https://" + $add
} else {
$add = "https://www." + $add
}
}
# If no domain, tries to add .co.uk, if fails uses .com
if (-not ($add -match ".co" -or $add -match ".uk" -or $add -match ".com")) {
try {
$test = $add + ".co.uk"
$HTTP_Request = [System.Net.WebRequest]::Create($test)
$HTTP_Response = $HTTP_Request.GetResponse()
$add = $add + ".co.uk"
} catch{
$add = $add + ".com"
}
}
Write-Host "Taking you to $add"
start microsoft-edge:$add
}
Then you just have to call: edge google in powershell to go to https://www.google.co.uk
I would like to recommend:
Microsoft Edge Run Wrapper
https://github.com/mihula/RunEdge
You run it this way:
RunEdge.exe [URL]
where URL may or may not contains protocol (http://), when not provided, wrapper adds http://
if URL not provided at all, it just opens edge
Examples:
RunEdge.exe http://google.com
RunEdge.exe www.stackoverflow.com
It is not exactly new way how to do it, but it is wrapped as exe file, which could be useful in some situations. For me it is way how to start Edge from IBM Notes Basic client.
Looks like things have changed and the previous solution doesn't work anymore.
However, here is the working command to launch CNN.com on Microsoft Edge:
microsoft-edge:http://www.cnn.com
I want to complement other answers here in regards to opening a blank tab in Microsoft Edge from command-line.
I want to add an observation from my end. Windows doesn't detect the command microsoft-edge if I remove the trailing colon. I thought colon would be required only when I've to provide the target URL to open e.g. when I've to open a blank tab. But that's not the case. Color (:) is required all the time.
How to open a blank tab in Microsoft Edge?
From Run prompt (press Window logo + R):
microsoft-edge:about:blank
microsoft-edge:
msedge
From Command(cmd.exe) prompt:
start microsoft-edge:about:blank
start microsoft-edge:
start msedge
You can also initiate a search using Edge from run prompt. Let's say I've to search Barack Obama then fire below command on run prompt-
microsoft-edge:Barack Obama
It starts Microsoft's Bing search website in Edge with Barack Obama as search term.
It will do more or less the same thing in good old dos script fashion
set add=%1
if %add%$ ==$ set add="about:blank" && goto launch
rem http://
set test=%add:~0, 7%
if %test% == http:// goto launch
rem ftp://
set test=%add:~0, 6%
if %test% == ftp:// goto launch
rem https://
set test=%add:~0, 8%
if %test% == https:// goto launch
rem add http
set add=http://%add%
:launch
start microsoft-edge:%add%
microsoft-edge:http://google.com (open google as desired)
microsoft-edge: (just open)

Using getResources and a custom date TV, how can I limit my results by the year entered in my TV?

In MODx Revolution, while using getResources and a custom date TV (called: press-release-date), how can I limit my results by year (using a URL param to set the year, so I could enter any year)?
For example, my URL has page.html?year=2012
I want my results from getResources to only include ones associated with that year. I believe I want to use the &where property (if so, I am certainly botching the formatting):
&where=`{"press-release-date":[[*press-release-date:strtotime:date=`%Y`]:isequalto:`2012`]}`
I've also tried
&where=`{[[*press-release-date]]:[[*press-release-date:strtotime:date=`%Y`]:isequalto:`2012`]}`
Thanks!
UPDATE:
This is the full code I am using currently:
[[!getResources?
&parents=`780,781,782,783,784`
&tpl=`list-press-tpl`
&limit=`1000`
&sortdir=`DESC`
&includeTVs=`1`
&includeContent=`1`
&depth=`0`
&showHidden=`1`
&sortbyTV=`press-release-date`
&where=`{[[*press-release-date]]:[[*press-release-date:strtotime:date=`%Y`]:isequalto:`2012`]}`
]]
You are going to want to use the &tvFilters attribute: http://rtfm.modx.com/display/ADDON/getResources you will probably have to also &includeTVs, &includeTvsList and ~possibly~ also &processTVList. As to how to strip the post value from the url, you may have to write a quick little snippet that grabs all your url variables & sets them as placeholders. something along the lines of:
foreach($_POST as $key => $value){
$modx->setPlaceholder($key,$value);
}
Then you should be able to access them:
&where=`{[[*press-release-date]]:[[*press-release-date:strtotime:date=`%Y`]:isequalto:`[[+year]]`]}`
at a guess... not tested.:)
You can try tvFilters instead. But you will have to translate your [[+year]] into your press-release-date date format and limit search inside intertleave:
&tvFilters=`press-release-date>=[[+year:dec:strtotime]]||press-release-date<=[[+year:strtotime]]`
http://rtfm.modx.com/display/revolution20/Input+and+Output+Filters+%28Output+Modifiers%29
http://rtfm.modx.com/display/revolution20/Date+Formats
http://ru2.php.net/strtotime

Is there an Open-Source Web Search Library that does not use a Search Index File?

I'm looking for an open-source web search library that does not use a search index file.
Do you know any?
Thanks,
Kenneth
You mean:
search.cgi
#/bin/sh
arg=`echo $QUERY | sed -e 's/^s=//' -e 's/&.*$//'`
cd /var/www/httpd
find . -type f | xargs egrep -l "$arg" | awk 'BEGIN {
print "Content-type: text/html";
print "";
print "<HTML><HEAD><TITLE>Search Result</TITLE></HEAD>";
print "<BODY><P>Here are your search results, sorry it took so long.</P>";
print "<UL>";
}
{ print "<LI>" $1 "</LI>"; }
END {
print "</UL></BODY>";
}'
Untested...
The original poster clarified in a comment to this reply that what he is looking for is essentially "greplike search but through HTTP", and mentioned that he is looking for something that uses little disk as he's working with an embedded system.
I am not aware of any related projects, but you might want to look at html parsers and xquery implementations in your language of choice. You should be able to take care of "real-life" messiness of html with the former, and write a search that's almost as detailed as you might desire with the latter.
I assume that you will be working with a set of urls that will either be provided, or already stored locally, since the idea of actually crawling the whole web, discovering links, etc, in an embedded device is thoroughly unrealistic.
Although with a good html/xquery implementation, you do have the tools to extract all the links..
My original answer, which was really a request for clarification:
Not sure what you mean. How do you picture a search working without an index? Crawling the web for every query? Piping through to google? Or are you referring to a specific kind of search index file that you are trying to avoid?
I guess there is none (at least that is popular enough for users here to be aware of).
We've went ahead to code our own Search system.

What is kpsexpand?

gnuplot is giving the error: "sh: kpsexpand: not found."
I feel like the guy in Office Space when he saw "PC LOAD LETTER". What the heck is kpsexpand?
I searched Google, and there were a lot of pages that make reference to kpsexpand, and say not to worry about it, but I can't find anything, anywhere that actually explains what it is.
Even the man page stinks:
$ man kpsexpand
kpsetool - script to make teTeX-style kpsetool, kpsexpand, and kpsepath available
Edit: Again, I'm not asking what to do -- I know what to do, thanks to Google. What I'm wondering is what the darn thing is.
kpsexpand, kpsetool and kpsepath are all wrappers for kpsewhich that deals with finding tex-related files
kpsexpand is used to expand environment varibles.
Say $VAR1 is "Hello World" and $VAR2 is "/home/where/I/belong" then
$ kpsexpand $VAR1
will return
Hello World
and $ kpsexpand $VAR2 will return
/home/where/I/belong
kpsewhich is reminiscent to which just like which progname will search the directories in the $PATH environment variable and return the path of the first found progname, kpsewhich filename will search the directories in the various tex-paths, fonts, packages, etc. for filename.
to find out more lookup kpsewhich either in man or on google, and check out the source of kpsexpand
less `which kpsexpand`
Cheers
/B2S
This is on the first page of google search results for "kpexpand gnuplot":
http://dschneller.blogspot.com/2007/06/visualize-hard-disk-temperature-with.html
It says that you do not need to care about the error-messages.
Here is the manual page for kpsexpand:
http://linux.die.net/man/1/kpsexpand

Resources