Advertisement

This is about Me?

Do not read this

Thanks To

Related sites

Community

Syndication

You can grab our news as an Atom feed.


Wordpress Iteration in Your Own PHP Application

[27-Feb-2010]

Wordpress has its own way to loop the posts, that is different than what other CMS does. I think it’s great because of flexibility and usability reason. It would seem easy later, when you want to manipulate the result before it is displayed to the browser.
So you want to implement the Wordpress-style loop in your own PHP application? You have to say yes. :D

The following PHP code contains some basic functions to make your own Wordpress Loop.

Code

Wordpress-style Loop

<?php
$posts 
mysql_query('YOUR SQL QUERY HERE');
$post null;
$post_count 0;
$post_index 0;

function 
have_post() {
    global 
$posts$post_count$post_index;

    if (
$posts && ($post_index < = $post_count)){
        
$post_count count($posts);
        return 
true;
    }
    else {
        
$post_count 0;
        return 
false;
    }
}

function 
the_post() {
    global 
$posts$post$post_count$post_index;

    
// make sure all the posts haven't already been looped through
    
if ($post_index $post_count) {
        return 
false;
    }

    
// retrieve the post data for the current index
    
$post $posts[$post_index+1];

    
// increment the index for the next time this method is called
    
$post_index++;
    return 
$post;

}

function 
the_title() {
    global 
$post;
    return 
$post->Title;
}

function 
the_content() {
    global 
$post;
    return 
$post->Content;
}

//and the output... tada....

if(have_post()) : while(have_post()) : the_post();
echo 
"
<h2>"
.the_title()."</h2>

"
;
echo 
the_content();
endwhile; endif;

<
p>?>

The advantage of using this iteration is:
1. Easy to implement with templating system.
2. Easy to filter output through PHP function, no need edit the template file.
3. Every output element is a function rather than a variable. It accepts parameter, you can do more things.
4. Want to display next post or previous post? that’s no a pain.

Disadvantage:
Of course, that code confusing me at the first time :D

Information


Thanks to Matt Huggins post at Stackoverflow and xrvel post at kaskus


Junk Is Poetry (?)

[17-Feb-2010]
junk is poetry, idiotnesia,kaskus, pertamax

Junk Is Poetry

Barangkali ada yang aneh dengan judul posting ini. Ya, saya  sendiri nggak ngerti apa artinya kalimat tersebut, “junk is poetry”. Kalau secara harfiah, junk artinya sampah dan poetry artinya puisi. Berarti junk is poetry adalah sampah yang sok puitis :D

Okelah kalau begitu, bagi rekan-rekan yang suka gabung di forum pasti tau kalau istilah junk itu adalah aktifitas nyampah di forum. Ya, memang nyampah kok. Memposting sesuatu yang tidak berguna (kadang cuma ngakak doang, posting smilies doang, sundul up-up doang, dan banyak lagi lainnya) yang tujuannya tidak lain adalah untuk menambah jumlah postingan dengan sedikit usaha. hahaha. Gak tau deh, mungkin pikir mereka jumlah postingan bisa ditukar beras kale ya.

Sudah barang tentu para pengurus forum tidak sepihak dengan para junker-junker tersebut yang kerjanya mengotori forum yang mereka kelola. Tapi secara informal (hah?) pengelola forum juga diam-diam mengakui bahwa aktifitas junker bermanfaat bagi mereka. Kenapa? Jadi ibarat memberantas perjudian. Setengah-setengah. Otherwise, setoran menurun. wkwkwkw

Aktifitas junker ini ada dimana-mana, tak terkecuali di forum terbesar di Indonesia yaitu kaskus.us khususnya di sub forum Website, Webmaster, Webdeveloper (W3). Tersebutlah sesosok userid (gak bilang oknum) bernama idiotnesia yang sebenernya sih enggak idiot. Idiotnesia pantas dijuluki kaskuser (pengguna kaskus) paling ngejunk sedunia (W3).  Bagaimana tidak, dalam sehari dia mampu memposting 16 post selama 5 tahun berturut-turut. ck ck ck.

Data ini memang tidak akurat, tapi perhitungan saya adalah selama 5 tahun (17 Feb 2005 – 17 Feb 2010) idiotnesia mampu membuat postingan sebanyak 30.889 (lihat gambar). Kalau kita kalikan jumlah hari dalam 5 tahun adalah 565 x 5 = 1825, jumlah postingan 30.889 / 1825 = 16.925479452054794520547945205479 (enam belas koma sembilan sekian sekian….). Sebuah angka yang fantastis bukan? Tentu saja angka sebenarnya bisa lebih besar dari itu. Karena pasti banyak postingan yang dihapus momod (perkiraan lebay saya mengatakan hampir 5 ribuan), dan idiotnesia juga tidak mungkin ngaskus (baca: ngejunk) setiap hari kan?

Lalu apa untungnya punya postingan berlimpah dengan cara korupsi ngejunk tersebut? Jawabnnya tentu saja hanya idiotnesia yang tahu. Barangkali dia lagi menuntut suatu ilmu hitam yang mensyaratkan untuk ngejunk setiap hari. hahahha.  Lalu, apa pula ruginya? Kata orang Jawa, sing rugi yo kucing (cuma kucing yang berak diurugi, red).  Sampai berita ini diturunkan si idiotnesia masih sering curhat soal laptopnya yang jebol. Loh, kenapa jebol? Karena ngejunk atau karena ngising gak diurugi? Hanya Tuhan lah yang tahu.


WP Editarea Wordpress Plugin

[11-Feb-2010]

Wordpress used to embed Codepress syntax highlighting at Version 2.8 and immediately disabled it at Version 2.8.1 due to browser incompatibilities. However I found another free Javascript code editor called Editarea which has more features than Codepress . Now you can simply integrate Editarea functionality to your Wordpress by using WP Editarea Plugins.

WP Editarea
Contributors: takien
Requires at least: 2.9
Tested up to: 2.9.1
Stable tag: 0.1

Description

WP Editarea turns your Oldschool textarea code editor in Wordpress Dashboard (plugin/theme editor) into a fancy realtime highlighted code editor using Editarea.

Plugin Feature

* Automatically detect syntax language
* Live preview in plugin option page
* Better than codepress (for me)
* Easy integration, no file to edit
* Easy to use configuration page

Editarea Feature
* Multi language interface
* Bracket matching highlight
* Support many syntax
* Line numbers
* Search/replace with regex
* More at Editarea homepage.

Browser Compatibility
* IE 6 & 7 & 8, Firefox 1.5 & 2 & 3, Safari 3.x & 4, Opera 9, 9.5, 9.6 and Chrome 1 & 2[2]

Installation

The installation process.

1. Upload `wp-editarea` folder to the `/wp-content/plugins/` directory. Make sure directory structures are not changed. Or Directly upload from your Plugin management page.
2. Activate the plugin through the ‘Plugins’ menu in WordPress
3. Go to Settings menu and set options you need.

Screenshots

1. Setting page and live preview.

wordpress editarea, wordpress syntax highlight

WP Editarea setting page.


2. Your new theme editor :D
 editarea, wordpress code editor, wordpress syntax highlight

Wordpress Editarea


Wordpress 3.0 with Twenty Ten Default Theme

[9-Feb-2010]
Wordpress 3.0, twenty ten, wordpress screnshoot

Twenty Ten 0.7 comes with Wordpress 3.0

I just download and install alpha version of WordPress Version 3.0. At a glance, there are no major changes that I can see. After installation process that run as simple as usual, I walk through menus in the Dashboard and found a new sub-menu named “Network” under the Tools menu. As I have heard before that in version 3.0 Wordpress would be integrated with Wordpress MU with Multi-Site feature. It’s mean that you can multiply your site easily without Installing Wordpress MU.

Navigate other menus, there is nothing striking until my mouse clicked on the “Appearance”. There seems to be a new stuff. The new default theme entitled “Twenty Ten 0.7 by the WordPress team“, cool.  There’s a new atmosphere in my Wordpress instead of seeing Kubrick theme for several years.

My curiosity led to Theme Editor that may also have some changes there. A little difference with previous version in the lists of the theme file name. The file title and file name are separated into two lines. Look quite neater.

At the bottom of file lists, there is a new stylesheet file named “editor-style.css“. I hope my guess’ right, it is the css style file to be used in editor page when I write or edit a post. I think it will be useful for those who create a new post from the dashboard, but not for me who prefer to write using Windows Live Writer.

That’s my story when testing Wordpress 3.0 alpha — development version (3.0-alpha)– which may a lot of changes will be added  until the final version released.


Google Apps Tidak Lagi Mendukung Internet Explorer 6

[3-Feb-2010]

google apps, google aps logo, google

Google Apps


Baru saja dapat email dari Pak Google bahwa Layanan mereka Google Apps tidak lagi mendukung pengaksesan melalui browser Internet Explorer. Tidak ada yang aneh sih, karena Anda para pengguna Google Apps pasti sudah dapat emailnya juga.

Tapi menurut saya, keputusan Google ini sebenarnya sedikit telat (tepatnya telat 3 bulan telat 2 tahun, wow). Ya, karena saya sendiri sudah melakukan hal ini sejak 2 tahun lalu. Kalau nggak percaya lihat saja postingan saya yang ini:Internet Explorer, Sepertinya Kita Harus Berpisah :D

Walaupun Google telat, tapi sebagai manusia biasa selayaknya kita bersyukur atas keputusan tersebut guna mengurangi pengguna Internet Explorer 6 yang berarti akan meningkatkan taraf hidup para Webdeveloper

Berikut kutipan email tersebut:

Dear Google Apps admin,​

In order to continue to improve our products and deliver more sophisticated features and performance, we are harnessing some of the latest improvements in web browser technology. This includes faster JavaScript processing and new standards like HTML5. As a result, over the course of 2010, we will be phasing out support for Microsoft Internet Explorer 6.0 as well as other older browsers that are not supported by their own manufacturers.

We plan to begin phasing out support of these older browsers on the Google Docs suite and the Google Sites editor on March 1, 2010. After that point, certain functionality within these applications may have higher latency and may not work correctly in these older browsers. Later in 2010, we will start to phase out support for these browsers for Google Mail and Google Calendar.

Google Apps will continue to support Internet Explorer 7.0 and above, Firefox 3.0 and above, Google Chrome 4.0 and above, and Safari 3.0 and above.

Starting this week, users on these older browsers will see a message in Google Docs and the Google Sites editor explaining this change and asking them to upgrade their browser. We will also alert you again closer to March 1 to remind you of this change.

In 2009, the Google Apps team delivered more than 100 improvements to enhance your product experience. We are aiming to beat that in 2010 and continue to deliver the best and most innovative collaboration products for businesses.

Thank you for your continued support!

Sincerely,

The Google Apps team


Word Replacer Wordpress Plugin

[1-Feb-2010]

Word Replacer is a Wordpress plugin will enable you to replace a specific word in your content then replace it with replacement given. Contents that can be replaced are posts, pages, or comments. It’s identical with the Word Censors in SMF Forum Software.

Readme:

=== Word Replacer ===
Contributors: takien
Donate link: Donate
Tags: replacer, post, comment, page, replace, censor, bbcode, filter
Requires at least: 2.9
Tested up to: 2.9.1
Stable tag: 0.1

Replace word in post, page, or comment.

== Description ==

Word Replacer is a Wordpress plugins to replace any desired text/word with your choice. You can filter which content to be replaced, eg. only in page, comment, or post. With very userfriendly administration page you can manage list of word eaasily. It’s also can be used to censor any bad/vulgar words in your comment your your guest posting. It’s simple but useful.

Feature:

* Userfriendly administration page.
* Define yourself what word to replace in where. (e.g. a word shoud be replaced in comment but not in post etc)
* Uses it’s own database table, if you wish you can directly update/add/delete/import through your MySQL admin.

== Installation ==

The installation process.

1. Upload zipped plugin file to the `/wp-content/plugins/` directory. Or Directly upload from your Plugin management page.
2. Activate the plugin through the ‘Plugins’ menu in WordPress
3. Go to Settings menu and you will see Word Replacer sub menu. Yeah, there are your playground.

== Frequently Asked Questions ==

== Support RegeX ==

No, at this time.

== Screenshots ==

Word replacer

Administration page where you can add/remove your word.


Administration page where you can add/remove your word.

== Changelog ==

= 0.1 =
* First release

The code:

Word Replacer Source Code

<?php
/*
Plugin Name: Word Replacer
Plugin URI: http://wordpress.org/#
Description: Replace word in post, page, or comment
Author: Takien
Version: 0.1
Author URI: http://takien.com/
*/

/*  Copyright 2010 takien.com

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    For a copy of the GNU General Public License, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

global $wpdb;
global 
$word_replacer;

$word_replacer = Array(
                
'name'             => 'Word Replacer',
                
'version'         => '0.1',
                
'table_name'    => $wpdb->prefix "word_replacer",
                
'base_name'        => 'wordreplacer'
);

function 
_specialchar($string) {
    return 
htmlspecialchars(stripcslashes($string));
}

if(isset(
$_POST['submit'])) {

    
$id                $_POST['id'];
    
$original         $_POST['original'];
    
$replacement     $_POST['replacer'];
    
$in_posts         $_POST['in_posts'];
    
$in_comments    $_POST['in_comments'];
    
$in_pages        $_POST['in_pages'];

$numfield count($original);

    for (
$i 1$i < = $numfield$i++) {
    if(!empty(
$original[$i]) && empty($id[$i])) {
    
$wpdb->query$wpdb->prepare"
        INSERT INTO "
.$word_replacer['table_name']."
        (original, replacement, in_posts, in_comments, in_pages)
        VALUES (%s, %s, %s, %s, %s)"
,
        array(
$wpdb->escape($original[$i]), $wpdb->escape($replacement[$i]),$wpdb->escape($in_posts[$i]),$wpdb->escape($in_comments[$i]),$wpdb->escape($in_pages[$i]))));
        
$message =  '
<div id="message" class="updated fade">

<strong>Word Inserted.</strong>
</div>

'
;
    }
    elseif(empty(
$original[$i]) && !empty($id[$i])) {
        
$wpdb->query("
        DELETE FROM "
.$word_replacer['table_name']." WHERE id = '".$id[$i]."'");
        
$message =  '
<div id="message" class="updated fade">

<strong>Word Deleted.</strong>
</div>

'
;
    }
    elseif(!empty(
$original[$i]) && !empty($id[$i])) {
        
$wpdb->update($word_replacer['table_name'],
        array(
'original'     => $wpdb->escape($original[$i]),
        
'replacement'         => $wpdb->escape($replacement[$i]),
        
'in_posts'            => $wpdb->escape($in_posts[$i]),
        
'in_comments'        => $wpdb->escape($in_comments[$i]),
        
'in_pages'            => $wpdb->escape($in_pages[$i])
        ),
        array( 
'id' => $id[$i] ), array( '%s''%s''%s''%s''%s'), array( '%d' ) );
        
$message =  '
<div id="message" class="updated fade">

<strong>Word Updated.</strong>
</div>

'
;
    }
    }
}

function 
word_replacer_install () {
    global 
$wpdb;
    global 
$word_replacer;

   if(
$wpdb->get_var('show tables like "'.$word_replacer['table_name'].'"') != $word_replacer['table_name']) {

      
$sql "CREATE TABLE " $word_replacer['table_name'] . " (
      id mediumint(9) NOT NULL AUTO_INCREMENT,
      original VARCHAR(200) NOT NULL,
      replacement VARCHAR(200) NOT NULL,
      in_posts VARCHAR(5) NOT NULL,
      in_comments VARCHAR(5) NOT NULL,
      in_pages VARCHAR(5) NOT NULL,
      UNIQUE KEY id (id)
    );"
;

      require_once(
ABSPATH 'wp-admin/includes/upgrade.php');
      
dbDelta($sql);

      
$badword         "badword";
      
$properword     "goodword";

      
$insert "INSERT INTO " $word_replacer['table_name'] .
            
" (original, replacement, in_posts, in_comments, in_pages) " .
            
"VALUES ('" $wpdb->escape($badword) . "','" $wpdb->escape($properword) . "','yes','yes','yes')";

      
$results $wpdb->query$insert );

      
add_option("word_replacer_ver"$word_replacer['version']);
   }
}

register_activation_hook(__FILE__,'word_replacer_install');

function 
word_replacer_db() {
    global 
$wpdb;
    global 
$word_replacer;
    return 
$wpdb->get_results("SELECT * FROM ".$word_replacer['table_name']." ORDER BY id"ARRAY_A);
}

// for content 

function word_replacer_postpage($content) {
$i 1;
foreach(
word_replacer_db() as $wrdb) {
$i++;
    
$original[$i]         = stripslashes($wrdb['original']);
    
$replacement[$i]     = stripslashes($wrdb['replacement']);
    
$in_posts[$i]         = stripslashes($wrdb['in_posts']);
    
$in_comments[$i]     = stripslashes($wrdb['in_comments']);
    
$in_pages[$i]         = stripslashes($wrdb['in_pages']);

    if(
is_page() && ($in_pages[$i] == 'yes')) {
        
$content str_replace($original[$i],$replacement[$i],$content);
    }
    elseif(!
is_page() && ($in_posts[$i] == 'yes')) {
        
$content str_replace($original[$i],$replacement[$i],$content);
    }

}
return 
$content;
}

// for comment
function word_replacer_comment($content) {
$i 1;
foreach(
word_replacer_db() as $wrdb) {
$i++;
    
$original[$i]         = stripslashes($wrdb['original']);
    
$replacement[$i]     = stripslashes($wrdb['replacement']);
    
$in_posts[$i]         = stripslashes($wrdb['in_posts']);
    
$in_comments[$i]     = stripslashes($wrdb['in_comments']);
    
$in_pages[$i]         = stripslashes($wrdb['in_pages']);

    if(
$in_comments[$i]    == 'yes') {
    
$content str_replace($original[$i],$replacement[$i],$content);
    }
    }
return 
$content;
}

add_filter('comment_text','word_replacer_comment');
add_filter('the_content','word_replacer_postpage');
add_action('admin_menu''word_replacer_add_page');

function 
word_replacer_add_page() {
    global 
$word_replacer;
    
add_options_page($word_replacer ['name'], $word_replacer ['name'], 'administrator''wordreplacer''word_replacer_page');
}

function 
word_replacer_page() {
    global 
$wpdb$word_replacer$message;

    echo 
'
<div class="wrap">
<h2>'
.$word_replacer ['name'].'</h2>

'
;
    echo 
$message;
?>

<script language="Javascript" type="text/javascript">
<!--
function addField(area,field,limit) {
    if(!document.getElementById) return;
    var field_area = document.getElementById(area);
    var all_inputs = field_area.getElementsByTagName("input");
    var last_item = all_inputs.length - 1;
    var last = all_inputs[last_item].id;
    var count = Number(last.split("_")[1]) + 1;

    if(count > limit && limit > 0) return;

    field_area.innerHTML += "
<tr>
<td>
<input type='hidden' name='id[]' value='' />
<input style='width:100%' name='original[]' type='text' /></td>
<td> => </td>
<td>
<input style='width:100%' name='replacer[]' type='text' /></td>
<td>
<input value='yes' name='in_posts[]' type='checkbox' /></td>
<td>
<input value='yes' name='in_comments[]' type='checkbox' /></td>
<td>
<input value='yes' name='in_pages[]' type='checkbox' /></td>
</tr>

";

}
//-->
</script>

<?php
$action_url 
$_SERVER[PHP_SELF] . '?page=' $word_replacer['base_name'];

?>

Put the word to be replaced on the left, and what to change it to on the right.
<form method="post" action="<?php echo $action_url;?>">
<table class="widefat fixed" width="650" align="center" id="word-replacer-list" width="100%">
<thead>
<?php wp_nonce_field('update-options'); ?>
<tr>
<th>Original</th>
<th width="20"> </th>
<th>Replacement</th>
<th width="80">Posts</th>
<th width="80">Comments</th>
<th width="80">Pages</th>
</tr>
</thead>

<?php
$i 
= -1;

foreach(
word_replacer_db() as $wrdb) { $i++ ?>
<?php $alternate 
= (empty($alternate) ? 'class="alternate"' '');?>
<tr <?php echo $alternate;?>>
<td>
<input type="hidden" name="id[]" value="<?php echo $wrdb['id']; ?/>" />
<input style="
width:100%" type="text" name="original[<?php echo $i;?/>]" id="original_<?php echo $i;?>" value="<?php echo _specialchar($wrdb['original']) ?>" /></td>
<td> => </td>
<td>
<input style="width:100%" type="text" name="replacer[<?php echo $i;?/>]" value="<?php echo _specialchar($wrdb['replacement']) ?>" /></td>
<td>
<input value="yes" name="in_posts[<?php echo $i;?/>]" <?php echo (($wrdb['in_posts'] == 'yes') ? 'checked="checked"' : ''); ?> type="checkbox" /></td>
<td>
<input value="
yes" name="in_comments[<?php echo $i;?/>]" <?php echo (($wrdb['in_comments'] == 'yes') ? 'checked="checked"' : ''); ?> type="checkbox" /></td>
<td>
<input value="
yes" name="in_pages[<?php echo $i;?/>]" <?php echo (($wrdb['in_pages'] == 'yes') ? 'checked="checked"' : ''); ?> type="checkbox" /></td>
</tr>

<?php } ?>
</table>
<input type="
button" value="Add More Fields" style="cursor:pointer" onclick="addField('word-replacer-list','original_',0);" />
<input type="
hidden" name="action" value="update" />
<input name="
submit" class="button-primary" type="submit" value="<?php _e('Add/Update Words') ?/>" />
</form>

Instruction:


1. To <b>Add New Word</b> click Add More Fields  add your word, replacement and filter, then hit Add/Update Words.
2. To <b>Update</b> a word, just replace/retype in it's place an hit Add/Update Words.
3. To <b>Delete</b> a word, leave blank/clear word in "
original" field and hit Add/Update Words.
</div>

<?php
}
?>

<p>?>


Feature Wishlist

Here are  some feature wish lists for Word Replacer Plugin based on user comments:

  • Replace the title
  • Replace Case-insensitive

Uploaded to Wordpress.org

This Word Replacer Plugin just approved and uploaded to Wordpress Plugins Directory
Please see it in action, here.. http://wordpress.org/extend/plugins/word-replacer/ :D

Note: This post was posted by WP Sub Post Plugin


News Archive