Wednesday, November 10, 2010

Image upload and resizeing

class SimpleImage {

var $image;
var $image_type;

function load($filename) {
$image_info = getimagesize($filename);
$this->image_type = $image_info[2];
if( $this->image_type == IMAGETYPE_JPEG ) {
$this->image = imagecreatefromjpeg($filename);
} elseif( $this->image_type == IMAGETYPE_GIF ) {
$this->image = imagecreatefromgif($filename);
} elseif( $this->image_type == IMAGETYPE_PNG ) {
$this->image = imagecreatefrompng($filename);
}
}
function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) {
if( $image_type == IMAGETYPE_JPEG ) {
imagejpeg($this->image,$filename,$compression);
} elseif( $image_type == IMAGETYPE_GIF ) {
imagegif($this->image,$filename);
} elseif( $image_type == IMAGETYPE_PNG ) {
imagepng($this->image,$filename);
}
if( $permissions != null) {
chmod($filename,$permissions);
}
}
function output($image_type=IMAGETYPE_JPEG) {
if( $image_type == IMAGETYPE_JPEG ) {
imagejpeg($this->image);
} elseif( $image_type == IMAGETYPE_GIF ) {
imagegif($this->image);
} elseif( $image_type == IMAGETYPE_PNG ) {
imagepng($this->image);
}
}
function getWidth() {
return imagesx($this->image);
}
function getHeight() {
return imagesy($this->image);
}
function resizeToHeight($height) {
$ratio = $height / $this->getHeight();
$width = $this->getWidth() * $ratio;
$this->resize($width,$height);
}
function resizeToWidth($width) {
$ratio = $width / $this->getWidth();
$height = $this->getheight() * $ratio;
$this->resize($width,$height);
}
function scale($scale) {
$width = $this->getWidth() * $scale/100;
$height = $this->getheight() * $scale/100;
$this->resize($width,$height);
}
function resize($width,$height) {
$new_image = imagecreatetruecolor($width, $height);
imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
$this->image = $new_image;
}
}

if(!empty($_FILES)){
if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 20000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "
";
}
else
{

move_uploaded_file($_FILES["file"]["tmp_name"], '../wp-content/themes/jhun_theme/images/logo.gif');

}
}
else
{
echo "Invalid file";
}
}

$image = new SimpleImage();
$image->load('../wp-content/themes/jhun_theme/images/logo.gif');
$image->resize(300,70);
$image->save('../wp-content/themes/jhun_theme/images/logo.gif');
?>

Image upload and resizeing

class SimpleImage {

var $image;
var $image_type;

function load($filename) {
$image_info = getimagesize($filename);
$this->image_type = $image_info[2];
if( $this->image_type == IMAGETYPE_JPEG ) {
$this->image = imagecreatefromjpeg($filename);
} elseif( $this->image_type == IMAGETYPE_GIF ) {
$this->image = imagecreatefromgif($filename);
} elseif( $this->image_type == IMAGETYPE_PNG ) {
$this->image = imagecreatefrompng($filename);
}
}
function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) {
if( $image_type == IMAGETYPE_JPEG ) {
imagejpeg($this->image,$filename,$compression);
} elseif( $image_type == IMAGETYPE_GIF ) {
imagegif($this->image,$filename);
} elseif( $image_type == IMAGETYPE_PNG ) {
imagepng($this->image,$filename);
}
if( $permissions != null) {
chmod($filename,$permissions);
}
}
function output($image_type=IMAGETYPE_JPEG) {
if( $image_type == IMAGETYPE_JPEG ) {
imagejpeg($this->image);
} elseif( $image_type == IMAGETYPE_GIF ) {
imagegif($this->image);
} elseif( $image_type == IMAGETYPE_PNG ) {
imagepng($this->image);
}
}
function getWidth() {
return imagesx($this->image);
}
function getHeight() {
return imagesy($this->image);
}
function resizeToHeight($height) {
$ratio = $height / $this->getHeight();
$width = $this->getWidth() * $ratio;
$this->resize($width,$height);
}
function resizeToWidth($width) {
$ratio = $width / $this->getWidth();
$height = $this->getheight() * $ratio;
$this->resize($width,$height);
}
function scale($scale) {
$width = $this->getWidth() * $scale/100;
$height = $this->getheight() * $scale/100;
$this->resize($width,$height);
}
function resize($width,$height) {
$new_image = imagecreatetruecolor($width, $height);
imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
$this->image = $new_image;
}
}

if(!empty($_FILES)){
if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 20000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "
";
}
else
{

move_uploaded_file($_FILES["file"]["tmp_name"], '../wp-content/themes/jhun_theme/images/logo.gif');

}
}
else
{
echo "Invalid file";
}
}

$image = new SimpleImage();
$image->load('../wp-content/themes/jhun_theme/images/logo.gif');
$image->resize(300,70);
$image->save('../wp-content/themes/jhun_theme/images/logo.gif');
?>

Control wordpress menu

If you want to control wordpress upper menu just go wp-includes/post-template.php function wp_page_menu change it and enjoy

Thursday, August 26, 2010

Manage Not found post

If you click any post title in your blog then it will redirect you in a page where you can see this particular post in that case your browser address bar show you "/?p=50" suppose your post id 50. But if you directly put the id of the post in your address bar and if it's not available then it can show you an error
-------------------------------------------------------------------------------

Not Found

Apologies, but the page you requested could not be found. Perhaps searching will help
--------------------------------------------------------------------------------------
Now if you want to change the design of this page go in your theme folder and edit "404.php" file

Monday, August 23, 2010

Admin New post add_meta_box() function

When you are going to add a new post then you can see many widget like publish, discussion, author etc. those function are calling from "wp-admin\edit-form-advanced.php" and the 'add_meta_box()' this function body has define under the "wp-admin\includes\template.php" line number 2782. But the widget html is coming from "wp-admin\includes\meta-boxes.php". If you change this html in here then the change will reflect in the page.

Remove permalink from your Post



If you want to remove this parmalink and post category from your post page. Just go to the 'single.php' of your theme folder and comment 'div class="entry-utility"' this div

Thursday, August 19, 2010

Change your admin View post table








This image is the tabulate form of your admin view post. if you want to change any column content or other then you can easily found your browser show you the address "wp-admin/edit.php". In this file
<?php include( './edit-post-rows.php' ); ?> this block of code include edit-post-rows.php
where "page_rows($posts, $pagenum, $per_page);" this function is calling from "wp-admin\includes\template.php" line number 1238. and again it call
"_post_row($post, $comment_pending_count[$post->ID], $mode);"
which have line number 1271. you can get your all need in this part..........
And if you want to change the table header and footer which call from "edit.php" then you can find a function "print_column_headers( $current_screen );" edit-post-rows.php line 16 and 22. this function body have define "wp-admin\includes\template.php" line number 773

Change post utility in your blog




You can see this part in every post footer, if you want to change it then you can find a function in the index.php in your theme folder. the function is "get_template_part( 'loop', 'index' ); "

this function body is located in "wp-includes/general-template.php" line 119

this function get the html architecture from "wp-content\themes\twentyten\loop.php"

if you change there the change will reflect in your blog.....

Wednesday, August 18, 2010

Create your customize sidebar in the blog frontend

This code will customize your sidebar in your blog theme you can get it in the sidebar.php


<div id="primary" class="widget-area" role="complementary">

<ul class="xoxo">

<?php/* When we call the dynamic_sidebar() function, it'll spit out
* the widgets for that widget area. If it instead returns false,
* then the sidebar simply doesn't exist, so we'll hard-code in
* some default sidebar stuff just in case.*/
//if ( ! dynamic_sidebar( 'primary-widget-area' ) ) : ?>

<!--<li id="search" class="widget-container widget_search">

<?php //get_search_form(); ?>


</li>
-->


<li id="archives" class="widget-container">


<h3 class="widget-title">
<?php _e( 'Recent Posts', 'twentyten' ); ?>
</h3>


<ul>


<?php wp_get_archives('title_li=&type=postbypost&limit=100'); ?>


</ul>


</li>



<li id="archives" class="widget-container">


<h3 class="widget-title">
<?php _e( 'Recent Comments', 'twentyten' ); ?>
</h3>


<ul>


<?php

foreach((get_comments(array('number' =>
30, 'status' =>
'approve'))) as $recent_comments){ ?>


<li>


<a href="<?php echo $recent_comments->
comment_author_url; ?>
">
<?php echo $recent_comments->
comment_author . ' '; ?>
</a>
On <?php $id = $recent_comments->
comment_post_ID; ?>
<a href="<?php echo get_post( $id, $output )->
guid; ?>
">
<?php echo get_post( $id, $output )->
post_title; ?>
</a>


</li>


<?php } ?>


</ul>


</li>



<li id="archives" class="widget-container">


<h3 class="widget-title">
<?php _e( 'Archives', 'twentyten' ); ?>
</h3>


<ul>


<?php wp_get_archives( 'type=monthly' ); ?>


</ul>


</li>



<!--<li id="archives" class="widget-container">


<h3 class="widget-title">
<?php _e( 'Categories', 'twentyten' ); ?>
</h3>


<ul>


<?php

foreach((get_the_category()) as $category) { ?>


<li>


<a href="<?php echo get_category_link( $category->
cat_ID ); ?>
">
<?php echo $category->
cat_name . ' '; ?>
</a>


</li>


<?php } ?>


</ul>


</li>
-->

<li id="meta" class="widget-container">


<h3 class="widget-title">
<?php _e( 'Meta', 'twentyten' ); ?>
</h3>


<ul>


<?php wp_register(); ?>


<li>
<?php wp_loginout(); ?>
</li>


<?php wp_meta(); ?>


</ul>


</li>


<?php //endif; // end primary widget area ?>


</ul>


</div>
<!-- #primary .widget-area -->


<?php

// A second sidebar for widgets, just because.

//if ( is_active_sidebar( 'secondary-widget-area' ) ) : ?>


<!--<div id="secondary" class="widget-area" role="complementary">


<ul class="xoxo">


<?php// dynamic_sidebar( 'secondary-widget-area' ); ?>


</ul>


</div>
-->

<!-- #secondary .widget-area -->
<?php //endif; ?>


Saturday, August 14, 2010

Change your Edit Comment page

Go to the "wp-admin\edit-form-comment.php" you can find all the div related to the design.
and the css are using "wp-admin\css\wp-admin.css", "wp-admin\css\global.css", "wp-admin\css\colors-fresh.css"





in the above picture you can see both are same but in the Approved there have a number in the second picture. It is a very small trick. if you want to do it go to the "wp-admin\edit-comments.php" line number 240. You can see this code
"'approved' => _n_noop('Approved', 'Approved')," now you replace this code with this
"'approved' => _n_noop('Approved (%s)', 'Approved (%s)'),"
you can see the change

Friday, August 13, 2010

Change your wordpress email sending, receiving address and content

If you want to change wordpress default sending address then go to the "wp-includes\pluggable.php" just change on line number 375 and 391 "$from_name" and "$from_email"

Thursday, August 12, 2010

Customize admin Add new post page

This page structure is very complex. if you want to change editor style and function then go to "wp-admin\edit-form-advanced.php" line no 271 "the_editor($post->post_content);" function which point "wp-includes/general-template.php" line 1777. if you want to edit media button then look on this function "do_action( 'media_buttons' );" line 1808 in 'general-template.php'

Wednesday, August 11, 2010

Change on Admin Dashboard

If you want to remove "Configure" from Recent Comments widgets then go to "wp-admin\includes\dashboard.php" line 133

Tuesday, August 10, 2010

Edit Comment Form

if you want to change the comment form then go to your "wp-content\themes\twentyten\comments.php"

you can find a part of code
this is point at "wp-includes\comment-template.php" line 1484