« Newer Snippets
Older Snippets »
11 total  XML / RSS feed 

Adding "post to" links for del.icio.us, digg, and ma.gnolia in Textpattern

Here's how to add "post to" links for del.icio.us, digg, and ma.gnolia to individual articles in Textpattern

del.icio.us


              
post to <a href="http://del.icio.us/post?url=&title=">del.icio.usa> 



digg


              
post to <a href="http://www.digg.com/submit?phase=2&url=">digga>



ma.gnolia


              
post to <a href="http://ma.gnolia.com/bookmarklet/add?url=&title=">ma.gnoliaa>



Clicking one of the those links will automatically post a permanent link for an article and, in the case of del.icio.us and ma.gnolia, the title to one of the above services.

Photoblogging with Textpattern: atom feeds

To textpattern/publish/atom.php somewhere around line 131 (in 4.0.2), or after
else {
$Body = '';
// If there's no excerpt, use body as content instead of body as summary
if (!trim($Excerpt))
$Body = fixup_for_feed($thisarticle['body'], permlinkurl($a));
}

add this:
// hack to get pictures to syndicate
if ($a['Section'] == "photo")
{
$img_url = hu."images/".$a['Image'].'.jpg';
$Body = doSpecial(''.permlinkurl($a).'">'.$img_url.'" alt="the latest and greatest" />');
}
// /hack

Photoblogging with Textpattern: rss feeds

Add this to textpattern/publish/rss.php somewhere around line 62 (in 4.0.2), or after "$Body = (!trim($Body)) ? $thisarticle['body'] : $Body;":
// hack to get pictures to syndicate
if ($a['Section'] == "photo")
{
$img_url = hu."images/".$a['Image'].'.jpg';
$Body = doSpecial(''.permlinkurl($a).'">'.$img_url.'" alt="the latest and greatest" />');
}
// /hack

Testing if this is NOT a category listing

The new releases of textpattern tend to use the new "yoursite.com/category/ZZZ" url format for category listing links. Which means that those category-filtered archives use the "default" template for formatting & so forth.

To handle this on the front page, you need to be able to test if the current view IS a category search, and you also need to test if this ISN't a category search (to display normal front-page content). To do this I had to modify the glx_if plugin - very easy really.

In Textpattern, go to admin > plugins, and click the "edit" link for glx_if. Add the following function anywhere it would seem to fit:

function glx_if_not_category_list($atts, $thing)
{
        global $pretext, $is_article_list;
        return (empty($pretext["c"]) && $is_article_list == true) ? parse($thing) : "";
}


A use for this is shown in this snippet.

Low-Overhead Archives By Month

You used to have to use rss_suparchive to get an archive of articles broken out by month, but this plugin produces an ungodly number of db queries when dealing with large archives (e.g., hundreds or thousands of articles).

Textpattern 4.0.2 allows you to get the same effect using the good ol' tag, which uses a LOT FEWER database queries.

You can see this in action at Not Far North.

First, you need the glx_if plugin installed.

put this in your "article" page template:

<txp:glx_if_section_frontpage>
   <h2>Archivesh2>
   
/> dl> </txp:glx_if_section_frontpage> <txp:if_individual_article> <txp:article /> txp:if_individual_article>


If you were attentive, you see that we also need an article_archive form. Create that form and put this in it:

<txp:if_different>
  <dt><txp:posted format="%B %Y" />dt>
</txp:if_different>

<dd><txp:permlink><txp:title />txp:permlink>

/><txp:excerpt />dd>


Now, "yoursite.com/article" will display a list of articles broken out by month, and "yoursite.com/article/2/helloworld" will display only that article using the "default" form.

To handle category listings, install the upm_category_title plugin and add this to your front page ("default") template:

<txp:glx_if_category_list>
   <h2>Articles in <txp:upm_category_title />h2>
   

/article/">View all articles

"archivelist"> "article" form="article_archive" />
"2" form="article_newest" />


Note that using the above bit of code requires you to modify the glx_if plugin a bit - more about that in another snippet (it's really easy).

Plugin development workflow improvements

By Sencer on the TXP forums
-> http://forum.textpattern.com/viewtopic.php?id=1043&p=2

Make your life developing plugins significantly easier:

1. Use zem�s tamplate.
2. insert row into txp_prefs table with

name = �plugin_cache_dir� and val = �/full/path/www/textpattern/tmp�
(you can let the other ones default to their respective default value)
3. create a directory /full/path/www/textpattern/tmp
4. drop your plugins (uncompiled) in that directory (make sure plugin name and plugin-filename correspond, e.g. zem_test should be in zem_test.php)
(Note: do not put zem_tpl.php in the same directory)

Textpattern clean urls with Lighttpd, the elegant way

I love this shit:

server.error-handler-404 = "/index.php"

Switching a working copy with subversion

If you find that the location to a subversion repository has changed, do this:

svn switch --relocate http://textpattern.com/svn/repos/current/textpattern http://svn.textpattern.com/current/textpattern


Where the old url is http://textpattern.com/svn/repos/current/textpattern

And the new one is http://svn.textpattern.com/current/textpattern

To see if it worked, do this:

svn info | grep URL


And you should see something like this:

URL: http://svn.textpattern.com/current/textpattern


(source: Switching a Working Copy)

Textpattern form for Paypal shopping-cart integration

A site I've been working on has a retail area which uses Paypal's shopping cart; since the whole site is Textpattern powered, the necessary HTML for each item is generated by a form. This code is based on 1.0rc1 and using the rei_show_custom plugin. I know that in rc3 there's probably something built in to pull out arbitrary custom fields, so just substitute that.

To use, add each product as an article; in the first custom field put the name you want passed to the cart, and in the second custom field put the price of the item. Then make sure this is called by the article form:

<fieldset>
<legend>Buy this product:legend>

Our fine /> is available for the low, low price of $<txp:rei_show_custom customid="2" />.p>

/> <input type="hidden" name="business" value="yourbiz@yourdomain" /> <input type="hidden" name="item_name" value="" /> <input type="hidden" name="amount" value=""2" />" /> <input type="image" id="add_to_cart" src="/path/to/your_cart_image" name="submit" alt="Add this item to your cart" /> <input type="hidden" name="add" value="1" /> p> </form> <form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <p> <input type="hidden" name="cmd" value="_cart" /> <input type="hidden" name="business" value="yourbiz@yourdomain" /> <input type="image" id="view_cart" src="/path/to/your_view_cart_image.png" name="submit" alt="View all items currently in your cart" /> <input type="hidden" name="display" value="1" /> p> </form> fieldset>



That'll display both an "add to cart" and a "view cart" button.

You'll want to fill in your own Paypal account address and product options, of course.

Upload all .gif and .jpg files in a directory to textpattern

This will upload all files in the current directory ending in jpg jpeg or gif through your textpattern-admin panel to your site.

Save this as a shell script, adjust the first 3 variables and excute. (Note: LOGIN and PASS should be ascii only, or else manually url-encoded)

URL='http://www.mysite.com/textpattern/'
LOGIN='simplename'
PASS='yourpassword'

COOKIE=$(curl -s -D - -d "p_userid=$LOGIN&p_password=$PASS" \
    $URL | head -n10 | sed -n 's/^Set\-Cookie\: //p')

if [ -z $COOKIE ] 
then 
  echo "Can't log in."
  exit 1
else 
  echo "Cookie: "$COOKIE
fi


for file in $(ls -1|egrep '(gif)|(jpe?g)$') ; 
do
 echo "Sending "$file
 curl -s -H "Cookie: $COOKIE" -F "thefile=@$file" \
   -F "event=image" -F "step=image_insert" $URL > /dev/null
done


This will not output anything. But after it returns to the prompt, log in to textpattern and take a look into the image section.

Update: Added rudimentary check wether login is successful and basic progress meter.

Clean Textpattern install from the current repository

In a shell, cd to the directory from which you'd like to serve the site, and rename or delete any '.htaccess' or 'index.php' files, and any directories called 'images' or 'files', that may be there.

Checkout the current code:

svn co http://svn.textpattern.com/current/ .


(Note the dot at the end). To complete the installation, just load http://thesiteurl/textpattern/ in a browser, fill in your database info, and when presented with the config.php block, copy it, go back to the shell client and:

nano textpattern/config.php


Paste in the code block, save and exit (ctrl-x, then y, then return).

Back to the browser, click through, add personal details, and that, as they say, is it.

Whenever you want to update to the latest code, cd to the same directory and:

svn update


...and the latest code will be seamlessly integrated with your installation.
« Newer Snippets
Older Snippets »
11 total  XML / RSS feed