Sunday, April 7, 2013

Enable OpenSSL Support for PHP on Windows

Enable OpenSSL Support for PHP on Windows 

As a prerequisite, two libraries must be existing in your Windows system: libeay32.dll and ssleay32.dll. Two ways to achieve this:
  • Install OpenSSL for Windows
  • Or, copy these two files to C:\WINDOWS\system32 folder. They’re shipped with PHP package, you can find them in PHP root folder.
OK, it’s time to open php.ini by using any text editor, and remove the semicolon before the following line:
extension=php_openssl.dll
Done!
http://huang.yunsong.net/2009/windows-php-openssl.html 

Saturday, April 6, 2013

Yii customizing the display of url parameters

Add the following rule to your main.php rules array:
'product/<id:[A-Z0-9]+>'=>'site/product',
 
 
You can then get the value by:
$id = Yii::app()->getRequest()->getQuery('id');

$this->createUrl('product',array('id'=>100));
 
 

<?php $this->widget('zii.widgets.CMenu',array(
	'items'=>array(
		array('label'=>'Product 10', 'url'=>array('/product', 'id' => 20 )),
		array('label'=>'About', 'url'=>array('/site/page', 'view'=>'about')),
		array('label'=>'Contact', 'url'=>array('/site/contact')),
		array('label'=>'Login', 'url'=>array('/site/login'), 'visible'=>Yii::app()->user->isGuest),
		array('label'=>'Logout ('.Yii::app()->user->name.')', 'url'=>array('/site/logout'), 'visible'=>!Yii::app()->user->isGuest)
	),
)); ?> 
 
 
echo $this->createUrl('post/read',array('id'=>$id))."<BR>";
echo $this->createUrl('post/read',array('id'=>$id, 'title' => "New post title")); 

'post/<id:\d+>/<title>'=>'post/read',
'post/<id:\d+>'=>'post/read' 

Remove index.php from url yii

There is one more thing that we can do to further clean our URLs, i.e., hiding the entry script index.php in the URL. This requires us to configure the Web server as well as the urlManager application component.

We first need to configure the Web server so that a URL without the entry script can still be handled by the entry script. For Apache HTTP server, this can be done by turning on the URL rewriting engine and specifying some rewriting rules. We can create the file /wwwroot/blog/.htaccess with the following content. Note that the same content can also be put in the Apache configuration file within the Directory element for /wwwroot/blog.
RewriteEngine on

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php
RewriteRule . index.php
We then configure the showScriptName property of the urlManager component to be false.
Now if we call $this->createUrl('post/read',array('id'=>100)), we would obtain the URL /post/100. More importantly, this URL can be properly recognized by our Web application.

7. Faking URL Suffix

We may also add some suffix to our URLs. For example, we can have /post/100.html instead of /post/100. This makes it look more like a URL to a static Web page. To do so, simply configure the urlManager component by setting its urlSuffix property to the suffix you like.

Thanks for guidance.

One more thing.
How can change static pages urls. E.g; following is url for About page.

http://localhost/main/yii/wf/site/page?view=about

How can I change it to more friendly url by removing '?' sign from url.

ANS:
Add the following line at first of components->urlManager->rules
'site/page/<view:\w+>'=>'site/page'




Thanks in advance

<?php
// uncomment the following to define a path alias
// Yii::setPathOfAlias('local','path/to/local-folder');
// This is the main Web application configuration. Any writable
// CWebApplication properties can be configured here.
return array(
        'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
        'name'=>'My Web Application',

        // preloading 'log' component
        'preload'=>array('log'),

        // autoloading model and component classes
        'import'=>array(
                'application.models.*',
                'application.components.*',
        ),

        // application components
        'components'=>array(
                'user'=>array(
                        // enable cookie-based authentication
                        'allowAutoLogin'=>true,
                ),
                // uncomment the following to enable URLs in path-format
                
                'urlManager'=>array(
                        'urlFormat'=>'path',
                        'showScriptName' => false,
                        'rules'=>array( 
                                'site/page/<view:\w+>'=>'site/page',
                                '<controller:\w+>/<id:\d+>'=>'<controller>/view',
                                '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
                                '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
                        ),
                ),
                
                'db'=>array(
                        'connectionString' => 'sqlite:protected/data/testdrive.db',
                ),
                // uncomment the following to use a MySQL database
                /*
                'db'=>array(
                        'connectionString' => 'mysql:host=localhost;dbname=testdrive',
                        'emulatePrepare' => true,
                        'username' => 'root',
                        'password' => '',
                        'charset' => 'utf8',
                ),
                */
                'errorHandler'=>array(
                        // use 'site/error' action to display errors
            'errorAction'=>'site/error',
        ),
                'log'=>array(
                        'class'=>'CLogRouter',
                        'routes'=>array(
                                array(
                                        'class'=>'CFileLogRoute',
                                        'levels'=>'error, warning',
                                ),
                                // uncomment the following to show log messages on web pages
                                /*
                                array(
                                        'class'=>'CWebLogRoute',
                                ),
                                */
                        ),
                ),
        ),

        // application-level parameters that can be accessed
        // using Yii::app()->params['paramName']
        'params'=>array(
                // this is used in contact page
                'adminEmail'=>'webmaster@example.com',
        ),
);

How to enable rewrite module in XAMPP, WAMP and Apache

How to enable rewrite module in XAMPP, WAMP and Apache
  1. Open apache’s configuration file using your favorite text editor. The configuration file generally locates at:{apache_dir}/conf/httpd.conf
    If you are using XAMPP or WAMP package then you will find the file at:{xampp_dir}/apache/conf/httpd.conf
    {wamp_dir}/apache/conf/httpd.conf
  2. Search for the following string:#LoadModule rewrite_module modules/mod_rewrite.so and uncomment it (remove the ‘#’ sign).
  3. Now search for another string AllowOverride None and replace it by AllowOverride All
  4. Finally save the changes, close your text editor and restart your apache server.

Thursday, April 4, 2013

ckeditor spellchecker plugin.js

CKEDITOR.plugins.add('jqueryspellchecker', {

    config: {
        lang: 'en',
        parser: 'html',
        webservice: {
            path: "../SpellChecker.php",
            driver: 'google'
        },
        suggestBox: {
            position: 'below',
            appendTo: 'body'
        }
    },

    init: function( editor ) {

        var t = this;
        var pluginName = 'jqueryspellchecker';

        this.config.suggestBox.position = this.positionSuggestBox();

        editor.addCommand(pluginName, {
            canUndo: false,
            readOnly: 1,
            exec: function() {
                t.toggle(editor);
            }
        });

        editor.ui.addButton('jqueryspellchecker', {
            label: 'SpellCheck',
            command: pluginName,
            toolbar: 'spellchecker,10',
            icon: this.path + 'icon.gif'
        });

        editor.on('saveSnapshot', function() {
            t.destroy();
        });
    },

    create: function() {
        this.editor.setReadOnly(true);
        this.editorWindow = this.editor.document.getWindow().$;

        this.createSpellchecker();
        this.spellchecker.check();

        $(this.editorWindow)
            .on('scroll.spellchecker', $.proxy(function scroll(){
                if (this.spellchecker.suggestBox) {
                    this.spellchecker.suggestBox.close();
                }
            }, this));
    },

    destroy: function() {
        if (!this.spellchecker)
            return;
        this.spellchecker.destroy();
        this.spellchecker = null;
        this.editor.setReadOnly(false);
        $(this.editorWindow).off('.spellchecker');
    },

    toggle: function(editor) {
        this.editor = editor;
        if (!this.spellchecker) {
            this.create();
        } else {
            this.destroy();
        }
    },

    createSpellchecker: function() {
        var t = this;

        t.config.getText = function() {
            return $('<div />').append(t.editor.getData()).text();
        };

        t.spellchecker = new $.SpellChecker(t.editor.document.$.body, this.config);

        t.spellchecker.on('check.success', function() {
            alert('There are no incorrectly spelt words.');
            t.destroy();
        });
        t.spellchecker.on('replace.word', function() {
            if (t.spellchecker.parser.incorrectWords.length === 0) {
                t.destroy();
            }
        });
    },

    positionSuggestBox: function() {

        var t = this;

        return function() {

            var ed = t.editor;
            var word = (this.wordElement.data('firstElement') || this.wordElement)[0];

            var p1 = $(ed.container.$).find('iframe').offset();
            var p2 = $(ed.container.$).offset();
            var p3 = $(word).offset();

            var left = p3.left + p2.left;
            var top = p3.top + p2.top + (p1.top - p2.top) + word.offsetHeight;

            top -= $(t.editorWindow).scrollTop();

            this.container.css({
                top: top,
                left: left
            });
        };
    }
});

ckeditor spell checking plugin

1. Download plugin
2. View Plugin.js
3. Include the jQuery and the Spellchecker files in the <head> section of your page:
<link href="css/jquery.spellchecker.css" rel="stylesheet" />
<script src="js/jquery-1.8.2.min.js"></script>
<script src="js/jquery.spellchecker.min.js"></script>
 
// Create a new spellchecker instance
var spellchecker = new $.SpellChecker('textarea', {
  lang: 'en',
  parser: 'text',
  webservice: {
    path: '../../webservices/php/SpellChecker.php',
    driver: 'pspell'
  },
  suggestBox: {
    position: 'above'
  },
  incorrectWords: {
    container: '#incorrect-word-list'
  }
});

// Bind spellchecker handler functions
spellchecker.on('check.success', function() {
  alert('There are no incorrectly spelt words.');
});

// Check the spelling
$("button#check").click(function(e){
  spellchecker.check();
}); 

Enabling Pspell for PHP in XAMPP on Windows

PHP provides spell checking functionality through the Pspell extension. Despite its name, the extension uses the Aspell library, as development of the Pspell library ceased in 2001. Being part of the GNU Project, Aspell is part of most Linux distributions but is not supplied with Windows. This page explains how to install Aspell and enable the Pspell extension in XAMPP on Windows.

Downloading and installing Aspell

A Windows port of Aspell is available on the Aspell website. The Windows port has not been updated in several years, but still functions on recent version of Windows.
First, download and run the ‘full installer’, which installs the library itself. Then download and install at least one language’s dictionary from the same page.

Copying the library DLL

While the PHP manual states that the Aspell DLL must be available within the Windows system path, under XAMPP it must be available in Apache’s ‘bin’ directory. Find the file aspell-15.dll, which by default is installed at C:\Program Files\Aspell\bin\aspell-15.dll, and copy it to the Apache ‘bin’ directory, which by default resides at C:\xampp\apache\bin.

Enabling the Pspell extension

To enable the Pspell extension, first find the php.ini file, which, depending on the XAMPP version, is by default located at either C:\xampp\apache\bin\php.ini or C:\xampp\php\php.ini. Open it in a text editor, find the following line (which should be in a block relating to extensions about halfway down the file), and remove the semicolon:
;extension=php_pspell.dll
If the line above wasn’t present in the file, add the following line:
extension=php_pspell.dll
Finally, enable the extension by restarting Apache using the XAMPP control panel.