Pages

Wednesday, December 21, 2011

Uploading docx file in Code Igniter

1. Go to system->config directory.
2. Open the mimes.php file.
3. Add

'docx'    =>  'application/vnd.openxmlformats-officedocument.wordprocessingml.document'

at the end of the array.

4. Also add the `docx` in the allowed_types list where the upload library is called as configuration parameter.

Thursday, December 1, 2011

Publishing text in a Facebook page

Below is the core code using the facebook graph API in PHP, cURL is required:

It is assumed the PHP variables containing proper data.the $attachment array keys can be added or removed necessarily.

<?php
$ch = curl_init();
$url="https://graph.facebook.com/<PAGE ID>/feed?access_token=<APP API KEY>|<APP Secret>";
$attachment = array(
'access_token' => "$access_token",
'message' =>"$message",
'name' => "New Session!",
'link' => "$purl",
'description' => ' ',
'picture'=>"<PICTURE URL>",
);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_exec($ch);
curl_close ($ch);
?>

Wednesday, October 26, 2011

Wordpress: Getting posts by Category Name

The below code retrieves all posts under a certain Category Name in Wordpress:

<?php
    // retrieve posts under the category banners
    query_posts( 'category_name=banners' );

    // the Loop
    while (have_posts()) : the_post();
        the_content( 'Read the full post »' );
    endwhile;
 ?>

Monday, October 17, 2011

Resizing images in a folder and putting into another folder

I visited Cox's Bazar on 30-07 to 02-08, 2011 with my colleagues. They snapped our happy memory in more than 500 pics of digital/mobile camera.

I found the sizes are quit large around 2M, more or less. So I decided to write some code to reduces the size and quality so the file size got reduced.


With the combination of 2 type of code, I wrote the code:
1. Directory content reading. and
2. Image resizing and saving.

Configurations:
set_time_limit: The function parameter - larger need to be the value if more pics are there.
source directory: the $dir variable
destination directory:  the $dest dir inside the `imageresize` function

Preparation:
A destination folder is to be created before, I do not write code to create destination directory.

Condition:
* I wrote the code only to resize JPEG type of image.
* I tested it on a Windows 7 box and in Wamp.

The code:


<?php

set_time_limit(300);

function imageresize($v, $i, $dir ) {

    $dest='D:/Cox\'s Bazzar/100SSCAM-small/';

    if( stripos( $v, '.jpg') ) {

        $filename = $dir.$v;

        $percent = 0.5;




        // Content type

        header('Content-Type: image/jpeg');




        // Get new sizes

        list($width, $height) = getimagesize($filename);

        $newwidth = $width * $percent;

        $newheight = $height * $percent;




        // Load

        $thumb = imagecreatetruecolor($newwidth, $newheight);

        $source = imagecreatefromjpeg($filename);




        // Resize

        imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);




        // Output

        imagejpeg($thumb, $dest.$v, 40);

        

    } //else echo $v, '=>',$i;

}//end function imageresize




$dir    = "D:/Cox's Bazzar/100SSCAM/";

$files1 = scandir($dir);

//$files2 = scandir($dir, 1);




array_walk($files1, 'imageresize' , $dir);

//print_r($files1);

//print_r($files2);

?>

Removing the Facebook iframe scrollbars for App Canvas/Page Tab

My colleague Behestee gave me the link:

http://facebook.stackoverflow.com/questions/6345363/facebook-fb-canvas-setsize-not-working

A guy named waqar alamgir posted the solution that worked perfectly.





<head>
<script type="text/javascript">
window.fbAsyncInit = function()
{
    FB.Canvas.setSize();
}
</script>
</head>

.
.
.
.

    <div id="fb-root"></div>
    <script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script> 
    <script type="text/javascript">

    FB.init({
        appId: 'xxxxxxxx', 
        status: true, 
        cookie: true, 
        xfbml: true
    });

    /* Init fb Resize window */
    FB.Canvas.setAutoResize(7);

    </script>
</body>
</html>

Friday, September 16, 2011

jQuery version of document.scrollIntoView with animation

$('html,body').animate({scrollTop: $([selector]).offset().top-[offsettop]},500);


Where [selector] is the css-patterned name or object (e.g. this ) of the target and [offsettop] is an integer to keep the browser a bit uplifted.

e.g.


$('html,body').animate({scrollTop: $("#description-section").offset().top-20 },500);


Tuesday, September 13, 2011

Movable Type: Getting the Loop Counter

<mt:if name="__counter__" op="mod" value="3" eq="0">Something HTML Output</mt:if>

So, the "__counter__"  is the way to find out the Loop count. It can be a loop, inside <mt:Entries> or what ever is.

In the Above code, if the counter%3 == 0, Some HTML Output will be t
he parsing output.

Saturday, September 10, 2011

Joomla! 1.5: Accessing a Model of a Component from a Module/Plugin or anywhere

JLoader::import('joomla.application.component.model');

JLoader::import( 'investment', JPATH_SITE . DS . 'components' . DS . 'com_<COMPONENT-NAME>' . DS . 'models' );

$model =& JModel::getInstance('<MODEL-CLASS-NAME>');

A blog commenter told the 2 line is not required but I can not make this working without the 2nd line.

It is also notable, that blog was using JPATH_ADMINISTRATOR, and mine was JPATH_SITE.

Wednesday, September 7, 2011

Executing JS code in Mootools Ajax Response

evalScripts: true

By default, Mootools 1.11, (that is default Joomla 1.5 JS library if not upgraded) keeps the Javascript evaluation OFF in the Ajax calling, that means evalScritps : false.

On a Joomla Project I fall into trouble with it. Later found, if this ajax setup parameter is set to true, the arrived JS codes are executed.