1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 3.00 out of 5)
Loading ... Loading ...

opencart seo friendly urls

opencart has built in seo friendly url but that’s for products only as far as i can tell. and you have to actually type out the terms. so i took it upon myself to make it friendlier and more automagic.

this is for opencart v1.4.8b

the format of url we are trying to achieve is:

/product/:product_id/:product_title

so it would look like something like /product/1/girls-gone-wild

change catalog/model/tool/seo_url.php


public function rewrite($link)
{

if ($this->config->get('config_seo_url'))
{
$url_data = parse_url(str_replace('&', '&', $link));
$url = '';
$data = array();
parse_str($url_data['query'], $data);

switch($data['route'])
{

case 'product/product':
$this->load->model('catalog/product');
$product = $this->model_catalog_product->getProduct($data['product_id']);
$url = $this->config->get('config_url').'product/'.$data['product_id'].'/'.$this->toSlug($product['name']);

break;

case 'product/category':
$this->load->model('catalog/category');
$categoryId = explode('_',$data['path']);
$categoryId = $categoryId[(count($categoryId)-1)];
$category = $this->model_catalog_category->getCategory($categoryId);
$url = $this->config->get('config_url').'category/'.$data['path'].'/'.$this->toSlug($category['name']);

break;

case 'information/information':
$this->load->model('catalog/information');
$info = $this->model_catalog_information->getInformation($data['information_id']);
$url = $this->config->get('config_url').'information/'.$data['information_id'].'/'.$this->toSlug($info['title']);

break;
}

if(!empty($url))
{
unset($data['route'],$data['path'],$data['product_id'],$data['information_id']);
$query = '';

if ($data)
{

foreach ($data as $key => $value)
{
$query .= '&' . $key . '=' . $value;
}

if ($query)
{
$query = '?' . trim($query, '&');
}
}

return $url.$query;
}

return $link;
} else

{

return $link;
}
}

public function toSlug($name)
{
$name = str_replace("'", "", $name);
$name = str_replace('"', "", $name);
$name = strtolower($name);
$name = preg_replace("/&#?[a-z0-9]+;/i","",$name);
$name = preg_replace('/[^a-zA-Z0-9-]/', '-', $name);
$name = preg_replace('/-+/', "-", $name);

return $name;
}


then change catalog/controller/common/seo_url.php


public function index()
{

if (isset($this->request->get['_route_']))
{
$parts = explode('/', $this->request->get['_route_']);

if($parts[0] == 'category' || $parts[0] == 'product' || $parts[0] == 'information')
{

switch($parts[0])
{

case 'category':
$this->request->get['path'] = $parts[1];

break;

case 'product':
$this->request->get['product_id'] = $parts[1];

break;

case 'information':
$this->request->get['information_id'] = $parts[1];

break;
}
}

else

{

foreach ($parts as $part)
{
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE keyword = '" . $this->db->escape($part) . "'");

if ($query->num_rows)
{
$url = explode('=', $query->row['query']);

if ($url[0] == 'product_id')
{
$this->request->get['product_id'] = $url[1];
}

if ($url[0] == 'category_id')
{

if (!isset($this->request->get['path']))
{
$this->request->get['path'] = $url[1];
} else

{
$this->request->get['path'] .= '_' . $url[1];
}
}

if ($url[0] == 'manufacturer_id')
{
$this->request->get['manufacturer_id'] = $url[1];
}

if ($url[0] == 'information_id')
{
$this->request->get['information_id'] = $url[1];
}
} else

{
$this->request->get['route'] = 'error/not_found';
}
}
}

if (isset($this->request->get['product_id']))
{
$this->request->get['route'] = 'product/product';
} elseif (isset($this->request->get['path']))
{
$this->request->get['route'] = 'product/category';
} elseif (isset($this->request->get['manufacturer_id']))
{
$this->request->get['route'] = 'product/manufacturer';
} elseif (isset($this->request->get['information_id']))
{
$this->request->get['route'] = 'information/information';
}

if (isset($this->request->get['route']))
{

return $this->forward($this->request->get['route']);
}
}
}
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 1.00 out of 5)
Loading ... Loading ...

In unrelated news: how to lose your $300,000 to HOA for a few thousand dollars

Capt. Mike Clauer was serving in Iraq last year as company commander of an Army National Guard unit assigned to escort convoys. It was exceedingly dangerous work — explosive devices buried in the road were a constant threat to the lives of Clauer and his men.

He was halfway through his deployment when he got a bolt from the blue — a frantic phone call from his wife, May, back in Texas.

“She was bawling on the phone and was telling me that the HOA [homeowners association] had foreclosed on our house, and it was sold,” he says. “And I couldn’t believe that could even happen.”

Read More/Source

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

get cakephp build-in css compression to work

Since cakephp 1.3, build-in css compression has stopped working. at least for me. however, it’s very easy to get it working again.

Step 1:

grab csspp from here and put it in your vendor directory so it looks something like this (app/vendors/csspp/csspp.php)

Step 2:

in your core.php file in app/config, uncomment Configure::write(‘Asset.filter.css’, ‘css.php’);

Step 3:

in your css.php under app/webroot,  modify make_clean_css function so that it looks something like this

function make_clean_css($path, $name)
{
App::import('Vendor', 'csspp' . DS . 'csspp');
$data = file_get_contents($path);
$csspp = new csspp($name,'');
$output = $csspp->process();
$ratio = 100 - (round(strlen($output) / strlen($data), 3) * 100);
$output = " /* file: $name, ratio: $ratio% */ " . $output;

return $output;
}

and that should be it. if it doesnt work for some reason,

change  line 82 in your app/webroot/css.php to

if (file_exists($cachepath) && 0)

so you won’t be looking at cached file when u debug.

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

jquery validate plugin, show only one error at a time

$('#form').validate({
errorLabelContainer:'#errorContainer',
showErrors: function(errorMap, errorList) {

if(errorList.length)
{
$('#errorContainer').html(errorList[0]['message']);
}
},
highlight:function(element,errorClass){
$(element).parent('td').addClass('error');
},
unhighlight:function(element,errorClass){
$(element).parent('td').removeClass('error');
}
})
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

jquery validate plugin with ajax duplicate check

jQuery validate plugin is pretty awsome. However it doesn’t do everything. That’s why the plugin have the addMethod function. And I need to add an ajax duplicate check for an email input. Here’s the method i wrote. There might be a better way. I would love to know.

jQuery.validator.addMethod("checkForDupeEmail", function(value, element, param){

var ajaxFunc = $.ajax({
async:false,   //we have to set it to false, it does not return a value before we even complete the request.
data:'email='+($.trim(value)),
type:'POST',
url:'/employees/ajax_checkDupe',
dataType:'text',
});
//here we check the response


if(ajaxFunc.responseText == 1)

return >true;

else

return >false;
});
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Dynamic subdomain in cakephp

I am doing this under windows 7+Apache on my local machine. So it’s a local environment. Production setup might change slightly.

In apache httpd-vhosts.conf, which can be found in Apache2.2\conf\extra\

<VirtualHost *:80>
ServerName company.lc
DocumentRoot D:/htdocs/web/public/company/app/webroot
ServerAlias *.company.lc
</VirtualHost>

And in windows hosts file which can be found windows\system32\drivers\etc\ in windows 7

127.0.0.1       test.company.lc
127.0.0.1       company.lc

since windows hosts doesnt allow dynamic subdomain. You have to type out each subdomain you want accessible through your browser locally. Not a big deal.

Restart apache. If it doesn’t work. Flush your local dns by typing ipconfig /flushdns in cmd.exe.

Now you should be able to access test.company.lc correctly.

I have a function in my app_controller.php for grabbing the subdomain and do some comparison and checking. It’s very simple though flawed in some way.

function getSubdomain() {
$domain = parse_url($_SERVER['HTTP_HOST']);
$domain = explode('.',$domain['path']);

if(count($domain)==3 and !empty($domain[0])) {

return $domain[0];
}

return '';
}

And there you have it.

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Shadow Menu

Shadow Menu is a simple dropdown menu with a little animation.

1

see demo

ShadowMenu -- Download (180)
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading ... Loading ...

relative time in cakephp

function plural($num) {
 if ($num != 1)
 return "s";
}
function getRelativeTime($date) {
 $diff = time() - strtotime($date);
 if ($diff<60)
 return $diff . " second" . plural($diff) . " ago";
 $diff = round($diff/60);
 if ($diff<60)
 return $diff . " minute" . plural($diff) . " ago";
 $diff = round($diff/60);
 if ($diff<24)
 return $diff . " hour" . plural($diff) . " ago";
 $diff = round($diff/24);
 if ($diff<7)
 return $diff . " day" . plural($diff) . " ago";
 $diff = round($diff/7);
 if ($diff<4)
 return $diff . " week" . plural($diff) . " ago";
 return "on " . date("F j, Y", strtotime($date));
}<span>

If you want to use this in your view files, You need a create a file call app.php in view folder.
In your app_controller.php declare a variable


var $view = "App";

your app.php looks something like this

class AppView extends View{
 function convertMysqlDate($dateString)
 {
 return date('M d Y h:s A',strtotime($dateString));
 }
 function plural($num) {
 if ($num != 1)
 return "s";
 }
 function getRelativeTime($date) {
 $diff = time() - strtotime($date);
 if ($diff<60)
 return $diff . " second" . $this->plural($diff) . " ago";
 $diff = round($diff/60);
 if ($diff<60)
 return $diff . " minute" . $this->plural($diff) . " ago";
 $diff = round($diff/60);
 if ($diff<24)
 return $diff . " hour" . $this->plural($diff) . " ago";
 $diff = round($diff/24);
 if ($diff<7)
 return $diff . " day" . $this->plural($diff) . " ago";
 $diff = round($diff/7);
 if ($diff<4)
 return $diff . " week" . $this->plural($diff) . " ago";
 return "on " . date("F j, Y", strtotime($date));
 }
}


source

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading ... Loading ...

load jquery for firebug console

javascript:void((function(){j=document.createElement("SCRIPT");j.src="http://code.jquery.com/jquery-latest.pack.js";document.getElementsByTagName("HEAD")[0].appendChild(j);})())

you put this in your address bar and hit enter. Bookmarking it would help a lot also.

of course, i didnt write it. I also forgot where i found it too.

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading ... Loading ...

mysql get first letter of a column from a table

Let’s say you have a store table in your database and you want to get the first letter of each store’s name. So you can create a menu by first letter of each store name and not having a letter that contains no stores.

$stores = $this->Store->find('all',array(    'order'=>'name ASC',
'fields'=>'DISTINCT(UPPER(LEFT(name,1))) AS letter',
'conditions'=>array("UPPER(LEFT(name,1)) REGEXP '[A-Z]'")));
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading ... Loading ...

Cakephp model–sum, avg and etc on same model

If you need to sum up or average a column on a table via bindModel. this is what you are looking for.
The table looks like this

//each report is connected to same session report via session_id
CREATE TABLE IF NOT EXISTS `gather_reports` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `session_id` varchar(64) NOT NULL DEFAULT '',
  `type` enum('Category','Store') NOT NULL DEFAULT 'Category',
  `name` varchar(128) NOT NULL DEFAULT '',
  `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `importedId` text NOT NULL,
  `total` int(11) NOT NULL DEFAULT '0',
  `imported` int(11) NOT NULL DEFAULT '0',
  `duration` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
)

in your controller

$this->GatherReport->bindModel(
    array('hasOne'=>array(
	'GatherTotal'=>array(
        	'className'=>'GatherReport',
		'foreignKey'=>'id',
		'fields'=>'SUM(GatherTotal.total) as total'
	),
	'GatherImported'=>array(
		'className'=>'GatherReport',
		'foreignKey'=>'id',
		'fields'=>'SUM(GatherImported.imported) as imported'
	),
	'GatherTime'=>array(
		'className'=>'GatherReport',
		'foreignKey'=>'id',
		'fields'=>'SUM(GatherTime.duration) as duration'
	)
)),false);
$this->paginate['GatherReport']['group'] = 'GatherReport.session_id';
$data = $this->paginate('GatherReport');
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading ... Loading ...

Jquery select text on focus or click

$('input').focus(function(){
    this.select();
});
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading ... Loading ...

excel to mysql import script

Sometimes a client requires you to import some data from an excel sheet to mysql. You can do it by hand if there are only a few records. However, if there are a few hundred records, you need some kind of script to do this. I had this same problem. So i wrote something in autoit and thought i might share it. The script itself it very simple and very easy to modify.
You need to download and install autoit before you can run this. I could just give you the executable, but no one would download it and no one should. Besides the script is very specific and is meant to be modified to suit your need.

here the file in case wordpress butchers my script.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <Excel.au3>
#include <Array.au3>
#Include <Date.au3>
;file picker
$excelFile = FileOpenDialog("Select an excel file",@DesktopDir,"Excel (*.xls)" ,1+2)
If Not @error Then
;create main window
$mainGui = GUICreate("Importing",350,150)
GUISetState(@SW_SHOW)
$status = GUICtrlCreateEdit("Begin importing",10,10,330,130,$ES_AUTOVSCROLL+$ES_AUTOHSCROLL+$ES_MULTILINE+$ES_READONLY)
addStatus("File selected:"&amp;$excelFile)
doExport($excelFile)
Else
MsgBox(0,"Error","Error opening file")
Exit
EndIf
While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
GUIDelete()
Func doExport($file)
$fpExcel = _ExcelBookOpen($file,0,1)
If @error = 1 Then
addStatus("Unable to Create the Excel Object")
Exit
ElseIf @error = 2 Then
addStatus("File does not exist - Shame on you!")
Exit
Else
addStatus("File open successfully")
EndIf
$done = False
$i = 2
While Not $done
;read a row from excel file
$excelArray = _ExcelReadArray($fpExcel,$i,1,9,0,0)
If $excelArray[0] <> "" Then
addStatus("reading Row " & $i)
;insert into sql file
arrayToSql($excelArray)
Else
addStatus("Finsihed reading excel file")
addStatus($i-2 & " rows converted into sql statement")
$done = True
EndIf
$i += 1
WEnd
_ExcelBookClose($fpExcel)
EndFunc
Func arrayToSql($array)
;save sql file to desktop
$sqlFile = FileOpen(@DesktopDir&"/ExcelToSql-"&@MDAY&"-"&@MON&"-"&@YEAR&".sql",1+8)
$sqlStatement = "INSERT INTO `_products` (`int_id`, `product_type`, `title`, `description`, `synopsis`, `publication_date`, `price`, `categories`, `list`, `type_id`, `processed`, `write_err`) VALUES ("
$sqlStatement &= "'"& escapeString($array[0]) & "'," ;int_id
$sqlStatement &amp;= "'"& escapeString($array[1]) & "'," ;product_type
$sqlStatement &amp;= "'"& escapeString($array[2]) & "'," ;title
$sqlStatement &amp;= "'"& escapeString($array[3]) & "'," ;description
$sqlStatement &amp;= "'"& escapeString($array[4]) & "'," ;synopsis
$sqlStatement &amp;= "'"& toExcelDate($array[5]) & "',"  ;date
$sqlStatement &amp;= "'"& escapeString($array[6]) & "'," ;price
$sqlStatement &amp;= "'"& escapeString($array[7]) & "'," ;category
$sqlStatement &amp;= "'"& escapeString($array[8]) & "'," ;list
$sqlStatement &amp;= "'','N','N'"
$sqlStatement &amp;= ");"
FileWriteLine($sqlFile,$sqlStatement)
FileClose($sqlFile)
EndFunc
Func escapeString($string)
;replace anything that is not a number, letter or common punctuation
$string = StringRegExpReplace($string,"[^0-9a-zA-Z.,\\/\!@#$%\^\&amp;\*\(\)\-_\+=\h<>]","")
;escape single quote
$string = StringRegExpReplace($string,"[']","\'")
Return $string
EndFunc
Func toExcelDate($dateString)
$yearString = StringMid($dateString,1,4)
$monthString = StringMid($dateString,5,2)
$dayString = StringMid($dateString,7,2)

return $dayString&amp;"-"&amp;StringMid(_DateToMonth($monthString,1),1,3)&amp;"-"&amp;$yearString
EndFunc
Func addStatus($text)
GUICtrlSetData($status,@CRLF&amp;$text,1)
EndFunc
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading ... Loading ...

Cakephp custom dropdown menu/select element

[UPDATED to allow multiple instances]
[UPDATED bug fix]

Hello everyone. The select tag that comes with html is pretty useful, but once in a while, one of your clients complains that it’s fugly. So you need to make  a custom one. And that’s what i just did. Damned clients!

Requirements:

  • jquery

To do this you need to create a file called customSelect.ctp in your app/views/elements folder(Of course you don’t NEED cakephp to use this.).

And the content said file would be(This example is for a category select menu.):
Read the rest of this entry »

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading ... Loading ...

Firefox plugins that you need as a developer

Like the title says, if you are a web developer and a firefox user, you NEED these plugins to effectively and efficiently build a website.

1. firebug

I dont think i need to explain the importance of this plugin. It’s the best thing since the invention of sliced bread.

2. firecookie

This one works in conjunction with firebug. It allows you to edit cookie values. Especially useful when you need to reset a cookie based login logic. Just find the session cookie name and delete it. You can have a brand new session. Also good for poking around and seeing the inner workings of websites.

Read the rest of this entry »

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading ... Loading ...

Useful sites for web development

There comes a time where you just want to build a site really quick and not have to worry too much about the design aspect of your project. But you still want your site to look good with wonderful graphics. These sites might come in handy someday.

1. http://www.stripegenerator.com/

You can use this site to generate a background image.

2. http://www.ajaxload.info/

Need a loading gif for the ajax component of your site. Look no further. http://www.ajaxload.info/ has everything you need.

3. http://cooltext.com/

Need a quick image button, but don’t wanna open photoshop. Check this site out.

4. http://www.freewebsitetemplates.com/

This site is for those programmers out there that have absolutely no design talent at all like myself.

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading ... Loading ...

Game of life, jquery implementation

Game of life in javascript/jquery flavor.
Rules:
  • For a space that is ‘populated’:
    • Each cell with one or no neighbors dies, as if by loneliness.
    • Each cell with four or more neighbors dies, as if by overpopulation.
    • Each cell with two or three neighbors survives.
  • For a space that is ‘empty’ or ‘unpopulated’
    • Each cell with three neighbors becomes populated.

Notes:

  • runs much faster in Chrome.
  • broken and runs like crap in all versions of ie
place holder
Round:



1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading ... Loading ...

internationalization and localization in cakephp

I18n and l11n in cakephp is extremely easy. However before we start, you need to download and install a po file editor. The one I use is called poedit.

The main thing you need to change in your application is the way you handle your string constants. Normally, you just type out phrases in your application like:

$site_title = "My site title";

To internationalize it, you change it to

$site_title = __("My site title",true);

The __ function takes a string and returns or echoes the localized version of it by checking the language files. The second parameter tells it if the localized string should be returned.
Obviously, if you are outputting string in your view file. You don’t need the second parameter because it defaults to false.

Now that your files are ready to be localized, you can start creating the language files you desire.
1. create a folder in app/locale with an appropriate name like rus for russian and eng for english
2. create a folder called LC_MESSAGES. This folder will contain the actual language file.

Now we need to configure the po editor you downloaded earlier.
1. download and install it, of course.
2. now close the catalog manager. go File->Preference
3. go to translation memory tab, set max.# of missing words to 0 and max. difference in sentence length to 0
4. go to parsers tab, add a new source code parser called php if one doesn’t already exist.
5. in php parser’s setting window, change the list of extentions to *.ctp;*.php, add whatever suits your needs.
6. change parse command to xgettext –force-po -o %o %C %K %F –language=php
7. change an item in keywords list to -k%k
8. change an item in input files list to %f
9. source code charset to –from-code=%c and now hit ok to save everything
10. open poedit, go to File->Catalogs Manager
11. click on the create a new translation project.
12. give it a name and set the directory to you projects app folder. in my case it looks something like this D:\htdocs\web\public\mysite\app\
13. Now go to File->New Catalog…
14. give it a name, set charset to UTF-8
15. go to paths tab, here you add folders that you want poedit to scan through to look for files. With cakephp the folders you want to include are the controller folder and view folders. you need to enter each of them separetly as poedit don’t go through the folders recursively.
in my case i added

views\layouts
views\home
views\pages
controllers
.

The last dot tells it to look in app folder for files like app_controller.php
16. go to keywords tab, add __ as a keywords. This tells poedit to look for __ when search through the files in path tab. hit ok to save.
17. with a little luck and all the stuff set correctly. you can hit the update catalog button and you should see your string constants in poedit and click on one to write the translation for it.

With all these you still need to tell cakephp which language to use. you can do that like

Configure::write('Config.language','rus');

You can send this file to your client and he can use poedit to update the file and send it back to you. All you have to do is to put the file in the appropriate folder in locale, open it with poedit and hit the update button. Then you are set. Pretty frigging awsome if you ask me.

1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 4.00 out of 5)
Loading ... Loading ...

integrating wordpress with cakephp

So how do you combine your favorite blogging app with your favorite framework so that user can signin from your cakephp app and maintain his/her session in wordpress, assuming user can only sign up and log in from your cakephp site.

The idea is to create a wordpress user when a user signs up on your cakephp site.

1. We need wordpress password hash function to do this properly. You need to create a new component that would contain wp password hashing functions. The file that contains everything you need is at wp-include/class-phpass.php. Just turn this class into a cakephp component, so you can include it in your user controller.

2. In your user controller, include your recently created wp hash function component. And after the user is saved into your cakephp user table. You want to add it to your wp user table as well. And it would look something like this.


if($this->User->save($this->data))
{
//create blog user for this user
$wp_hash = new $this->Wphash;
$wp_hash->PasswordHash(8,1);
$blog_user['ID'] = $this->User->id;
$blog_user['user_login'] = $this->sanitize_user($email);
$blog_user['user_pass'] = $wp_hash->HashPassword($this->data['User']['password']);
$blog_user['user_email'] = trim($email);
$blog_user['user_url'] = 'http://';
$blog_user['user_nicename'] = $this->data['User']['firstname'].' '.substr($this->data['User']['lastname'],0,1);
$blog_user['display_name'] = $this->data['User']['firstname'].' '.substr($this->data['User']['lastname'],0,1);
$blog_user['user_registered'] = date(configure::read('dateformat'));
$blogdata['Blog_user'] = $blog_user;
$this->Blog_user->save($blogdata);
//create user meta
$bid = $this->Blog_user->id;
$user_meta['user_id'] = $bid;
$user_meta['meta_key'] = 'first_name';
$user_meta['meta_value'] = $this->data['User']['firstname'];
$blogdata['BlogUserMeta']= $user_meta;
$this->BlogUserMeta->save($blogdata);
$user_meta['user_id'] = $bid;
$user_meta['meta_key'] = 'last_name';
$user_meta['meta_value'] = $this->data['User']['lastname'];
$blogdata['BlogUserMeta']= $user_meta;
$this->BlogUserMeta->save($blogdata);
$user_meta['user_id'] = $bid;
$user_meta['meta_key'] = 'nickname';
$user_meta['meta_value'] = $email;
$blogdata['BlogUserMeta']= $user_meta;
$this->BlogUserMeta->save($blogdata);
$user_meta['user_id'] = $bid;
$user_meta['meta_key'] = 'rich_editing';
$user_meta['meta_value'] = 'true';
$blogdata['BlogUserMeta']= $user_meta;
$this->BlogUserMeta->save($blogdata);
$user_meta['user_id'] = $bid;
$user_meta['meta_key'] = 'comment_shortcuts';
$user_meta['meta_value'] = 'false';
$blogdata['BlogUserMeta']= $user_meta;
$this->BlogUserMeta->save($blogdata);
$user_meta['user_id'] = $bid;
$user_meta['meta_key'] = 'admin_color';
$user_meta['meta_value'] = 'fresh';
$blogdata['BlogUserMeta']= $user_meta;
$this->BlogUserMeta->save($blogdata);
$user_meta['user_id'] = $bid;
$user_meta['meta_key'] = 'blog_capabilities';
$user_meta['meta_value'] = 'a:1:{s:10:"subscriber";b:1;}';
$blogdata['BlogUserMeta']= $user_meta;
$this->BlogUserMeta->save($blogdata);

3. In your wordpress index.php file

//change the session name of your wordpress site to match that of your cakephp site.
//so session data can be shared.
session_name("mysite");

4. in your theme header.php(might not be the best place if you change your theme a lot)

//you read the user id
$user = $_SESSION['Auth']['User'];

if(!empty($user))
{
//you change the current user manually
wp_set_current_user($user['id']);
}

And there you have it.

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading ... Loading ...

maintain session data across subdomains in cakephp

One of my bigger project requires me to setup personal sites on the main site’s subdomains. So i did what everyone would do and googled that.

It turned out to be quite simple. You just have to set session.cookie_domain to the domain of your site without www.

Like this session.cookie_domain = .mysite.com

Of course, you can set it with php using

ini_set("session.cookie_domain", ".localhost/mysite");

AND
You probably need to set cakephp security setting to medium or low. You can do that in core.php
Some people say medium is enough, but i needed to change minie to low in order for it to work.