Saturday, December 12, 2015

Cross Origin support specially for AJAX request-response.

htaccess file should be configured correctly to tell Apache to receive-send response for cross origin site.
For e.g. we've site www.mysite.com and www.subdomain1.mysite.com. Now we want to send-receive data from subdomain1. In this case we should configure htaccess  properly otherwise response will always be sent to mysite domain even when request is from subdomain1.

Just add these following line of code inside the htaccess and you're done :)

----------------------------
<IfModule mod_headers.c>
    Header add Access-Control-Allow-Origin "*"
    Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type"
    Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"
</IfModule>

----------------------------

htaccess protection for file - directory or website.

Sometimes we need to protect our development/ staging site from indexing of search engines or anonymous visits. Also we should protect from directory browsing i.e. we don't want to list down all files we've stored. In this case we should take help of Apache by configuring httaccess file.

To configure this we do these two simple steps.
1. Creating and placing the credentials data in a file. 
Here i've created a file named "htaccess-password-file"
Content inside "htaccess-password-file" is
-----------------------
nirmalya:$apr1$4vPpAb1l$jSHCl/KEuZCgeiHPoWxyz.
-----------------------
File "htaccess-password-file"is containing username along with encrypted password by seperated with ":".

2. Configuring htaccess for htaccess-password-file
 At the top of the .htaccess file we'll place these following lines below -
-----------------------
AuthType Basic
AuthName "Restricted Access"
AuthUserFile /srv/typo3/htdocs/htaccess-password-file
Require user nirmalya

-----------------------
We need to change value for "AuthUserFile" as required. This is the absolute path to file "htaccess-password-file" and  "Require user" to username.

* This site http://www.htaccesstools.com/htpasswd-generator/ is useful to generate encrypted password.

To stop directory browsing we need to use these following code inside htaccess.
------------------------------
# Apache < 2.3
<IfModule !mod_authz_core.c>
    Order allow,deny
    Deny from all
    Satisfy All
</IfModule>

# Apache รข‰¥ 2.3
<IfModule mod_authz_core.c>
    Require all denied
</IfModule>

 ----------------------------



Monday, November 30, 2015

Fetch content from multiple higher level of parent page when content in current page is empty.

temp.rightContent is fetching content of current page. Now check if this is empty we'll fetch from the parent page. This way we'll check again parent-parent i.e. grand parent page as so on. To achieve this i've take leveluid into count. We can apply different way as well. As per example below Typoscript object `lib.column_right_parent` is containing our required content.

temp.rightContent.current = CONTENT
temp.rightContent.current  {
  table = tt_content
  select.pidInList.data = leveluid : -1
  #select.pidInList.data = 1
  select.orderBy = sorting
  select.where = colPos= 2
  select.languageField = sys_language_uid
}

lib.column_right_parent < temp.rightContent.current
lib.column_right_parent.stdWrap.ifEmpty.cObject < temp.rightContent.current
lib.column_right_parent.stdWrap.ifEmpty.cObject {
  select.pidInList.data = leveluid : -2
  stdWrap.ifEmpty.cObject  < temp.rightContent.current
  stdWrap.ifEmpty.cObject {
    select.pidInList.data = leveluid : -3
    stdWrap.ifEmpty.cObject  < temp.rightContent.current
    stdWrap.ifEmpty.cObject {
      select.pidInList.data = leveluid : -4
        stdWrap.ifEmpty.cObject  < temp.rightContent.current
        stdWrap.ifEmpty.cObject {
          select.pidInList.data = leveluid : -5
      }
    }
  }
}

Typoscript to generate SELECT box (option-select) for page tree.

This typoscript below will generate a option select box for page tree or dropdown box for a page tree.
One simple javascript code has been added to make this select box active.
This example below is just an idea. We can easily customize this according to our need.

lib.field_menu_os = HMENU
lib.field_menu_os.entryLevel = 1
lib.field_menu_os {  
     wrap = <select id="menu_option_select" name="menu_option_select" size="1" onChange="javascript:_go_to_page(this.value);" >|</select>
     1 = TMENU
     1 {
       expAll = 1
       noBlur = 1
       NO {      
         stdWrap.dataWrap = <option value="{field:uid}">
         allWrap = |</option>
         doNotLinkIt = 1
       }
       # Inherit the 'allWrap' and 'doNotLinkIt' settings from the NO part
       CUR < .NO
       CUR = 1
       CUR {
         stdWrap.dataWrap = <option value="{field:uid}" selected="selected">
       }
     }
     2 = TMENU
     2 {
       expAll = 1
       noBlur = 1
       NO {
         stdWrap.dataWrap = <option value="{field:uid}">&nbsp;-&nbsp;
         allWrap = |</option>
         doNotLinkIt = 1
       }
       # Inherit the 'allWrap' and 'doNotLinkIt' settings from the NO part
       CUR < .NO
       CUR = 1
       CUR {
         stdWrap.dataWrap = <option value="{field:uid}" selected="selected">&nbsp;-&nbsp;
       }
     }
     3 = TMENU
     3 {
       expAll = 1
       noBlur = 1
       NO {
         stdWrap.dataWrap = <option value="{field:uid}">&nbsp;&nbsp;-&nbsp;&nbsp;
         allWrap = |</option>
         doNotLinkIt = 1
       }
       # Inherit the 'allWrap' and 'doNotLinkIt' settings from the NO part
       CUR < .NO
       CUR = 1
       CUR {
         stdWrap.dataWrap = <option value="{field:uid}" selected="selected">&nbsp;&nbsp;-&nbsp;&nbsp;
       }
     }    
  }

Simple one line of javascript will do the job easily. We can take help of jQuery too.
      function _go_to_page(selected_page_id){
  document.location.href='index.php?id='+selected_page_id;
 } 

Various TMENU wrap functions.

Availability of various wrap functions for TMENU and show them level-wise.
Here its a good example with some wrap functions and places to use them while we write typoscript for texual menu.

<wrapItemAndSub>
 <allWrap>
 <allStdWrap>
 <before>
 <beforeImg beforeImgTagParams>
 <linkWrap>
  <A href=… ATagParams TITLE=ATagTitle>
   <stdWrap.dataWrap> TMENUITEM </stdWrap>
  </A>
 </linkWrap>
 <after>
 </allStdWrap>
 </allWrap>
  UNTERMENU 1
  UNTERMENU 2
</wrapItemAndSub>

For more detail description please visit
https://docs.typo3.org/typo3cms/TyposcriptReference/MenuObjects/Tmenu/Index.html

Typoscript code to display content of this page - if empty fetch from specific page of TYPO3.

We'll fetch content from current page and check if this is empty we'll fetch content from page id = 38.
In the example below  `myContent` is fetching our default content. If this is empty we'll show content by `myContentBackup`  and this way we can go on ...

lib.myContent = CONTENT
 lib.myContent < styles.content.getLeft
 lib.myContent.stdWrap.ifEmpty.cObject < lib.myContentBackup
 lib.myContentBackup = CONTENT
 lib.myContentBackup {
    table = tt_content
        select {
            # specify the page id
            pidInList = 38
            # specify the column to fetch
            where = colPos = 3
            #for latest version language field is not required
            languageField = sys_language_uid
        }
}

Wednesday, October 14, 2015

Permission Settings for Files and Folders

index.php : ftp
644

typo3: ftp
dir   755
file: 644

(t3lib: ftp
dir   755
file: 644)

typo3conf: ftp+apache
dir   775
file: 664

fileadmin: ftp+apache
dir   775
file: 664

uploads: ftp+apache
dir   775
file: 664

typo3temp: ftp+apache
dir   775
file: 664

TYPO3 BE Editor Permissions Settings

options.hideModules.web := addToList(info,txtemplavoilaM1)
options.shortcutFrame=1
#options.defaultUploadFolder = 6:/user_upload/
options.defaultUploadFolder = 0:fileadmin/your_folder/user_upload/
#mod.web_txtemplavoilaM1.sideBarEnable = 1
options.hideModules.web := addToList(func,info,txtemplavoilaM1,web_txtemplavoilaM1)
TCEMAIN {
    # Besitzergruppe festlegen (ID der Gruppe „Seitenbaumrechte“):
    permissions.groupid = 10

    # Rechte Besitzer:
    permissions.user = show, editcontent, edit, delete, new

    # Rechte Besitzergruppe:
    permissions.group = show, editcontent, edit, delete, new

    # Rechte "everybody" (kann ungesetzt bleiben):
    permissions.everybody =
}
admPanel.enable.all = 1
setup.default.deleteCmdInClipboard = 1
setup.defaults.recursiveDelete = 10
setup.override.recursiveDelete = 1