| View previous topic :: View next topic |
| Author |
Message |
personman SuperGuru

 Joined: 09 Feb 2005 Posts: 2178
  votes: 15
|
Posted: Tue Mar 15, 2005 21:23 Post subject: [HACK]b2media, adding links and images from AWS |
|
|
Update 2: This is now a plugin for b2evolution 1.8, called evoAmazon. You can disregard the rest of this thread.
Update: I've upgraded this hack to be a full-fledged plugin for b2evolution 1.7. It's all in one file now and you can change the Amazon Associate ID in the backoffice. I made some changes to make it match the look of b2evolution and I did some work on internationalization (a first for me). Most of the important strings match up with strings that are already translated. The rest are in the T_() function, ready to be translated. Grab the file here, replace the .txt with a .php on the end of the name and put it in the plugins folder of b2evolution 1.7 (won't work with anything earlier, including 1.6-alpha). Once 1.7 is released I'll make a better page for this plugin, but for now you can post problems and feedback in this thread.
------------------------------
And now, the hack instructions for 0.9.x:
I put together a little hack to make it easier for me and my friends to add links and pictures from Amazon Web Services to posts in b2evolution. I use it for the Recent Media section on my sidebar. I wanted it to function like BookQueToo, a plugin for Movable Type. My hack is based on Jaap's Free Amazon PHP Script (amazonh3.php). I used some code from b2upload.php to get the popup window and pass html back to the textarea. There's very little of my own code in here. I mostly just put these peices together to make it do what I want. I'll give a description of how I use it, then I'll show how to apply the hack in case anyone wants to try it.
When I log into the backoffice and go to 'Write,' I have an extra button below the textarea labeled 'Add media.'
If I click on that button a window pops up with some options and a search window.
Choose a product category, type a search term and hit 'Search.' Then you'll see this:
The search script builds a table from the results that most closely match your search. Find the one that you want to add to your post and click 'Add the code to your post.' Then you'll have this in your post:
At this point you can edit the code if you want to add or remove any text or change image attributes. When you post, it looks something like this:
And here's how it looks in the mediablog that I've included in my sidebar:
If you would like to give this a try, then here's how I did it. The usual disclaimers apply. Back your files up. If this breaks your blog, then don't blame me. I use b2evolution version 0.9.0.11. If you get this to work with other versions, please let me know. Download this zip file, unzip it and upload the four php files to your admin directory. If you have modified your _edit_form.php, then you won't want to upload this file and erase your modifications. If you're used to messing with that file, then it won't be too hard for you to see the two sections where I added the code for the new button. Just search my file for 'b2media.' If you're not using 0.9.0.11, then I'm not sure what would happen if you overwrite your _edit_form.php file with mine. Back yours up first in case something gets broken. The other three files won't overwrite anything.
If you want to try and make money from Amazon referrals, then you can go to amazon.com, get an associate ID and replace Jaap's id with yours in b2media.php. That part is optional.
If you want to include another blog in your sidebar like I have, then look in the zip file for a file called sideblog.txt. Paste that into your _main.php and set the blog id number to match your sideblog that you create in the backoffice.
This has been my first major attempt at hacking b2evolution. Basically, I was amazed that I could get it to work. If you have ideas for improving this hack or turning it into an actual plugin, then I'm all ears.
Edit (9-20-05): Some web hosts turn off allow_url_fopen, which this hack uses to connect to Amazon. I rewrote the connection to use cURL by default, but to check to make sure the cURL module is loaded. If that fails, it will use fopen.
Last edited by personman on Thu Oct 12, 2006 13:44; edited 7 times in total |
|
| Back to top |
|
 |
StayPuft New Poster

 Joined: 21 Jul 2004 Posts: 26
      
|
Posted: Fri Sep 09, 2005 5:02 Post subject: |
|
|
| Great hack... works as advertised. |
|
| Back to top |
|
 |
personman SuperGuru

 Joined: 09 Feb 2005 Posts: 2178
  votes: 15
|
Posted: Tue Sep 20, 2005 10:49 Post subject: |
|
|
I rewrote part of this hack to use cURL to connect to Amazon rather than fopen. My new webhost doesn't allow fopen with urls, so the hack was broken until I changed it. If your webhost doesn't have cURL loaded, it will fall back on fopen. _________________ RTFM |
|
| Back to top |
|
 |
mrshiney New Poster

 Joined: 30 Mar 2005 Posts: 18
  
|
Posted: Wed Sep 21, 2005 10:55 Post subject: |
|
|
| personman wrote: |
| I rewrote part of this hack to use cURL to connect to Amazon rather than fopen. My new webhost doesn't allow fopen with urls, so the hack was broken until I changed it. If your webhost doesn't have cURL loaded, it will fall back on fopen. |
This is such an awesome hack. Would it be possible to make a version that could be called as a standalone php page? _________________ Shiney Blog! |
|
| Back to top |
|
 |
personman SuperGuru

 Joined: 09 Feb 2005 Posts: 2178
  votes: 15
|
Posted: Wed Sep 21, 2005 11:00 Post subject: |
|
|
Thanks! I'm not sure I understand your question. Do you mean can the backend (where you search for an Amazon item) be called as a standalone page? You can go directly to /admin/b2media.php rather than using the button in the edit area. Or do you mean stand-alone as in separate from b2evolution? _________________ RTFM |
|
| Back to top |
|
 |
mrshiney New Poster

 Joined: 30 Mar 2005 Posts: 18
  
|
Posted: Wed Sep 21, 2005 12:03 Post subject: |
|
|
| personman wrote: |
| Thanks! I'm not sure I understand your question. Do you mean can the backend (where you search for an Amazon item) be called as a standalone page? You can go directly to /admin/b2media.php rather than using the button in the edit area. Or do you mean stand-alone as in separate from b2evolution? |
I'm looking for a standalone, that would not require a b2evo. ADD CODE TO POST would just copy to clipboard. _________________ Shiney Blog! |
|
| Back to top |
|
 |
personman SuperGuru

 Joined: 09 Feb 2005 Posts: 2178
  votes: 15
|
Posted: Wed Sep 21, 2005 13:40 Post subject: |
|
|
You can download the script that this hack is based on here: Jaap's Amazon Scripts.
Or you could make this modification to change the add code to post button to a textarea with the code ready to be copied.
Open b2media.php and find
| Code: |
<form>
<input type="button" name="close" value="<?php echo T_('Add the code to your post !') ?>" class="search" onclick="targetopener('<?php echo "<img src="$imgurl" border="0" alt="" /><br /><a href="$url">".addslashes($pname)."</a> by ".addslashes($d); ?>');self.close()" />
</form> |
and change it to:
| Code: |
Copy this code to your post:<br />
<textarea rows="6" cols="80"><?php echo "<img src="$imgurl" border="0" alt="$pname" /><br /><a href="$url">$pname</a> by ".addslashes($d); ?></textarea> |
Then just point your browser directly at b2media.php (or rename it if you want.) _________________ RTFM |
|
| Back to top |
|
 |
mrshiney New Poster

 Joined: 30 Mar 2005 Posts: 18
  
|
Posted: Wed Sep 21, 2005 14:15 Post subject: standalone b2media |
|
|
Ok I've been working on making a standalone version of the b2media script. If you want to see the end result, see here. I'm not 100% happy with it yet (I'm new at this PHP stuff) but it seems to work. ;-)
The script is pretty long to post here. If anyone wants a copy, PM me here and I'll send it. _________________ Shiney Blog! |
|
| Back to top |
|
 |
lkahney New Poster

Joined: 30 Aug 2005 Posts: 12
        
|
Posted: Fri Nov 11, 2005 12:12 Post subject: |
|
|
danny,
what happened to the sideblog.txt file in the zip download? why is it no longer included?
btw, the 'Add Media' button works like a charm. very easy to install, works as advertised and will save a ton of time. great plugin. many thanks. |
|
| Back to top |
|
 |
personman SuperGuru

 Joined: 09 Feb 2005 Posts: 2178
  votes: 15
|
Posted: Fri Nov 11, 2005 12:33 Post subject: |
|
|
I don't know why I didn't put that in the zip when I was upgrading the script. I pulled the relevant code back out of my skin. This should do the trick, more or less.
http://www.brendoman.com/b2e/s...deblog.txt _________________ RTFM |
|
| Back to top |
|
 |
personman SuperGuru

 Joined: 09 Feb 2005 Posts: 2178
  votes: 15
|
Posted: Thu Jan 12, 2006 15:56 Post subject: |
|
|
I've updated this to be a real plugin for b2evolution 1.7. I editing the first post with more info and a link if you want to try it out. _________________ RTFM |
|
| Back to top |
|
 |
Lexagon Seasoned Poster

 Joined: 19 May 2006 Posts: 75
        
|
Posted: Sun Jun 04, 2006 11:51 Post subject: attempt to dowload from your link gives 403 |
|
|
Hello Danny,
trying to dl your file from http://brendoman.com/dev/blogs...in.php.txt gives me a no-no-page stating "Please, do not access this page directly."
Trying to be smart and just selecting 'download target as...' on the links context menu also gives me only a text file containg the line "Please, do not access this page directly."
What am I missing? Thank you for your help!
'lex |
|
| Back to top |
|
 |
personman SuperGuru

 Joined: 09 Feb 2005 Posts: 2178
  votes: 15
|
|
| Back to top |
|
 |
Lexagon Seasoned Poster

 Joined: 19 May 2006 Posts: 75
        
|
Posted: Sun Jun 04, 2006 15:35 Post subject: |
|
|
Hello Danny, thx, could download it without any pains now
Can't seem to get it to work tho.
2 reasons I can think of:
a) Is it because the /plugins folder (not a subdirectoryof that?) wasn't the correct place to put it?
b) I was under the impression that 0.9.1 (which I run) was "younger" / newer than 1.7 (I've read somewhere here that the numbering isn't consistent) and therefore tried it despite your mentioning that it's no go below ver 1.7.
No chance with 0.9.1? (Please bear with me, since I am rather a freshman to b2evo).
Thanks for your patience and your help.
Best regards,
'lex |
|
| Back to top |
|
 |
Lexagon Seasoned Poster

 Joined: 19 May 2006 Posts: 75
        
|
Posted: Sun Jun 04, 2006 15:39 Post subject: |
|
|
uh, where IS that 1.7 anyways? - Highest version I can find at the Downloads page is 1.6 alpha, and on SF there's 0.9.2 on display ..  |
|
| Back to top |
|
 |
|