Saturday, April 6, 2013

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.

ckeditor jquery javascript php

https://docs.google.com/file/d/0B5nZNPW48dpFSE5LMk05V2VWSzA/edit?usp=sharing
 
<?php
$ck_id = "ck_editor".time();
if(!isset($ck_className)) {
    $ck_className = time();
}
if(!isset($ck_content)) {
    $ck_content = "";
}
if(!isset($ck_name)) {
    $ck_name = "ck_name";
}

?>
<textarea name="<?php echo $ck_name; ?>
class="<?php echo $ck_className; ?>
id="<?php echo $ck_id; ?>"><?php echo $ck_content; ?></textarea>
 
<script type="text/javascript">
    for (var i in CKEDITOR.instances) {
        if(CKEDITOR.instances[i]) {
            <?php if(isset($replaceAll) && $replaceAll == true) { ?>CKEDITOR.remove(CKEDITOR.instances[i]); <?php } ?>
        }
    }
    CKEDITOR.replace( '<?php echo $ck_id; ?>',
        {
            pasteFromWordRemoveFontStyles : false,
   fullPage : false,
            removePlugins : 'elementspath',
            height : 300,
            toolbar :
                [
                    {
                        name: 'styles',
                        items : [ 'Format','Font','FontSize' ]
                    },
                    {
                        name: 'basicstyles',
                        items : [ 'Bold','Italic','Underline','Strike']
                    },
                    {
                        name: 'paragraph',
                        items : [ 'NumberedList','BulletedList','JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock' ]
                    },
                    {
                        name: 'clipboard',
                        items : [ 'Undo','Redo', 'imageUploader' ]
                    },
                    {
                        name: 'tableoperations',
                        items : [ '-', 'Table', 'TableInsertRowBefore', 'TableInsertRowAfter', 'TableRowDelete', '-',
                            'TableInsertColumnBefore', 'TableInsertColumnAfter', 'TableColumnDelete', '-', 'TableCellMerge',
                            'TableCellSplitVertical', 'TableCellSplitHorizontal', 'TableDeleteTable' ]
                    },
                    {
                        name: 'spellcheck',
                        items: [ 'jQuerySpellChecker' ]
                    }
                ]
        });
</script>
 
 
 
 
 
 
 
Extra plugins made by me "imageUploader" includes in config.js file 
CKEDITOR.editorConfig = function( config )
{
 // Define changes to default configuration here. For example:
 //config.language = 'fr';
 config.uiColor = '#FCFFEB';
 config.enterMode = CKEDITOR.ENTER_BR;
 config.extraPlugins = "imageUploader,tableoperations";
 config.pasteFromWordRemoveFontStyles = false;
 config.disableNativeSpellChecker = false; /* default spell checking */ 
};
Make a folder "imageUploader" in plugins folder, 
create a file icon.gif and plugin.js
 
PLUGIN.JS 
(function(){
    //Section 1 : Code to execute when the toolbar button is pressed
    var editorCustom;
    var a = {
        exec:function(editor){
            editorCustom = editor;
            var theSelectedText = "";
            var mySelection = editor.getSelection();

            if (CKEDITOR.env.ie) {
                mySelection.unlock(true);
                theSelectedText = mySelection.getNative().createRange().text;
            } else {
                theSelectedText = mySelection.getNative();
            }

            var backgroundHtmlStyle = " style='background-color: white; ";
            backgroundHtmlStyle += " height: " + $(window).height() + "px; ";
            backgroundHtmlStyle += " width: " + $(document).width() + "px; ";
            backgroundHtmlStyle += " left: 0; opacity: 0.5; position: fixed; top: 0; z-index: 500; ' ";
            var backgroundHtml = "<div class='ck-editor-image-upload-background' "+backgroundHtmlStyle+"></div>";
            $("body").append(backgroundHtml);

            var uploadFormHtml = "<div class='ck-editor-image-upload'><form id='ck-editor-image-upload-form' accept='utf-8' method=\"post\" enctype=\"multipart/form-data\" accept-charset=\"utf-8\" > ";
            uploadFormHtml += "<div><span class='1'>Upload Image File</span><span class='2'></span><input type=\"file\" name=\"file\" class=\"file\"/></div>";
            uploadFormHtml += "</form></div>";

            jQuery.dialogFromHTML("Insert Image", uploadFormHtml, {width: 400});

            $(".ck-editor-image-upload").find(".file").bind("change", function() {
                $("#ck-editor-image-upload-form").attr("action", BASE_URL + "custom_image/upload_ck_editor_image");
                $("#ck-editor-image-upload-form").ajaxForm({
                    beforeSubmit: function() {
                        jQuery.showBackgroundWorkingState();
                    },
                    success: function(data) {
                        if(data != "error" && data != "unsupported") {
                            var imageLocation = CK_EDITOR_IMAGE_DIR + data;
                            var imageHtml = "<img src='"+imageLocation+"' alt='"+data+"'/>";

                            try {
                                editorCustom.insertHtml(imageHtml);
                            } catch (ex) {
                                var content = editorCustom.getData() + "<p>" + imageHtml + "</p>";
                                editorCustom.setData(content);
                            }
                        } else {
                            jQuery.showWarning("File uploading error, please try again");
                        }
                        jQuery.closeAllDialog();
                        jQuery.hideBackgroundWorkingState();
                        jQuery(".ck-editor-image-upload-background").remove();
                    },
                    error: function() {
                        jQuery.showWarning("File uploading error, please try again");
                        jQuery.closeAllDialog();
                        jQuery.hideBackgroundWorkingState();
                        jQuery(".ck-editor-image-upload-background").remove();
                    }
                }).submit();
            });
        }
    },
    //Section 2 : Create the button and add the functionality to it
    b='imageUploader';
    CKEDITOR.plugins.add(b,{
        init:function(editor){
            editor.addCommand(b,a);
            editor.ui.addButton('imageUploader',{
                label:'Insert Image',
                icon: this.path + 'icon.gif',
                command:b
            });
        }
    });
})();

Monday, April 1, 2013

Configure apache virtual host


Make a entry to: C:\Windows\System32\drivers\etc\hosts
-----------------------------------------------------------
127.0.0.1    test.com
127.0.0.1    www.test.com

File Location:
-----------------------------------------------------------
C:\xampp\apache\conf\extra\httpd-vhosts

File Contents:

<VirtualHost 127.0.0.1:80>
    DocumentRoot "C:/xampp/htdocs"
    ServerName localhost
</VirtualHost>

<VirtualHost 127.0.0.1:80>
    ServerAdmin pritomkucse@gmail.com
    DocumentRoot "D:/src/test"
    ServerName test.com
    ServerAlias www.test.com
    ErrorLog "logs/test.error.log"   
    CustomLog "logs/test.custom.log"
    <Directory "D:/src/test">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Order allow,deny
        Allow from all
        Require all granted
    </Directory>
</VirtualHost>