Sunday, October 31, 2010

Facebook fb-req-form howto?

Ive found many misleading website which teach some of the old facebook way of doing things.
There fore, the new example in the facebook php library is the latest concept, where the parameter are passed in via array of keys.

First, setup the namespace into html tag:
<html xmlns:fb="http://www.facebook.com/2008/fbml">


Init the page via code in body, somewhere before /body


<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '[your_app_id',
session : [php code], // please refer to php example which comes with facebook official library
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});

// whenever the user logs in, we refresh the page
FB.Event.subscribe('auth.login', function() {
window.location.reload();
});
};

(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());

You do not need to include the FeatureLoader.js.php. I belief this include is meant for old Facebook api.
Hope this works for you :)
p/s: facebook always change their api, therefore, if it doesnt work, try to google around :)
cheers~

Tuesday, October 26, 2010

Modx 2 syntax

[ [...] ] - Calling snippet

[ [$...] ] - Calling chunk

[ [*...] ] - output / return modx setting or page variable, example [ [*pagetitle] ], [ [*content ] ]

[ [+...] ] - output / return variable from snippet call into chunk

[ [!... ] ] - Calling snippet without cache

[ [%...] ] - output Lexicon value (language)

Monday, October 25, 2010

Quip missing chunks

Anyone having the same problem as me, here are the missing chunks in quip 1.2.0-rc2
Updates Oct27: This chunks are not needed as its the default chunk in files, packaged with quip.

To install:
Upload the zip file to core/packages/
then go to package manager > add new package
select "Search Locally for Packages"
click "yes" when prompted.

When done, you will notice the Quipchunks component in the list

Sunday, October 24, 2010

extJS on Chrome vs Firefox

The new modx 2 seems to be using extJS as their manager panel javascript ui.
Its a heavy framework, but proof to be quite handy.
But running on firefox is quite a problem.
As the longer you are using it, you will realise the memory slowly hike up, and you might be ending up having the entire browser slower and slower.
While in chrome, it works pretty smooth the entire time. So far havent notice any significant memory hiking. And performance changes have never been felt.
And comparing both chrome and firefox performance, chrome works faster in rendering the ui.

Version compared:
Firefox 3.6
Chrome 6.0

Saturday, October 23, 2010

Modx 2 Category access

By default, everyone have access to any category.
Any resources fall within those category will be editable and save by anyone who have the policy to save/edit_template/snippet/chunk.

To restrict permission, you will need to add the category into the user group with:
category: [youcategory]
min role: [member/super user]
access policy: administrator
context: mgr

Once save, you will realise, nobody will be even see the category anymore.
Solution, Running: Security > Flush permissions.
And now, only those who meet min role within mgr may see the category and the element/resources inside.

Updates Oct25: There is a bug in modx2 which doesnt allow new element to be created under the category we have provided administrator policy as set above. The work around is to create a new element without any category, and then edit the element and set category to it. It will work properly if we set the element to it.
http://bugs.modx.com/issues/2610


Okay, now if you want other user to see only those resources/element inside the category but do not want to let them edit:
Add this in the user group category:
category: [youcategory]
min role: [member/super user]
access policy: Load, List and View
context: mgr
Running: Security > Flush permissions.

If the above doesnt work, try logout and login again :)
Hope it helps :)

Friday, October 22, 2010

PHP mkdir permission

PHP Bummer when comes to mkdir permission.

mkdir($yourfolder, 0777); //somehow set the folder permission to 0755
chmod($yourfolder, 0777); //this works after mkdir :)

Modx 2 Getting Action ID

I've found a way which is easier to get the action id of the components.
Simply assigning a variable to $_GET["a"] in the controller file within core/yourcomponentname/controllername shall do.

As all action which requires the component to work will require the action id to pass in, therefore, the initial file to run will be the controller file.

Wednesday, October 20, 2010

Modx 2 get document by alias

$columns = array_keys($modx->getFields('modResource'));
$criteria = $modx->newQuery('modResource');
$criteria->setClassAlias('sc');
$criteria->select($columns);
$criteria->andCondition("sc.published=1 and sc.deleted=0 and sc.alias='" . mysql_escape_string($alias) . "'");
$criteria->limit(1);
//$criteria->prepare();
//return $criteria->toSQL();
$objCollection = $modx->getCollection('modResource', $criteria);
$collection = array();
foreach ($objCollection as $obj) {
array_push($collection, $obj->get($columns));
}
if (count($collection) <>
return $collection[0]["content"];

Modx 2 snippet bummer

If you code [[*value]] in snippet php coding, you will realise the value gets populated when you return it.
But, if you are using the value in [[*value]] to check some condition, then you are out of luck.
The real value isnt populated during the script process.
Its only populated after its been processed.

Alternative way is to pass in value to snippet:
[[!mysnippet? &myvalue=`[[*value]]`]


Modx 2 processed tv to display

Previously ive talked about using "input options value" to output list of keys and values for dropdown list or options.
example: "@select listlabel, listvalue from modx_listvalues where listkey='postcategory' order by weight asc, listlabel asc, id asc"

But to output the value, its not the same.

if you installed getResourceField,
adding processTV=`1` and useTV=`1` field=`your_tvfieldname`

processedTV is obtained from the value in the TV variable.
So instead of the value directly "test", you have to put in your binding syntax as value.
Example: "@select listlabel from modx_listvalues where listkey='postcategory' and listvalue='test';

If you dont like the way of putting syntax into the value box, you may try to use snippet to pass in the value to get the value to display. I think this is the better way.

Thursday, October 14, 2010

Modx 2 Login Snippet

The login snippet installable from package management have several flaw in certain usage.
We have a client who has login form @ the very top.

When user login into the site, the user will be redirected to to site_url (start) page if the last page is his/her first visit or landing page.
@solution: Edit Login snippet, and comment off line #155
//$modx->sendRedirect($modx->getOption('site_url'));

2nd problem, since we have disabled redirect, user will be known as "not yet authenticated" in the current page, unless he/she click to another page.
@solution: Edit Login snippet, and append this line #148
$authenticated = true;

Modx 2 query for template variables

This example shows how to query for template variable from a article:

SELECT cv.*, v.`name` FROM `modx_site_tmplvar_contentvalues` cv left join `modx_site_tmplvars` v on cv.tmplvarid=v.id
WHERE `contentid` = #

Wednesday, October 13, 2010

Modx 2 showing error page instead of unauthorize page

In modx 1, its a direct method to setup article / post permission.
1st, setting up resource group. Then setup user group, and add in resource group to user group.
Next, assign user to user group.
Finally, when someone not logged in, the user will be shown a unauthorized page.

But in modx2, there are extra steps to setup this.
Notice that modx2 now have "minimum role", "access policy", "context".
1st. setting up resource group. Then setup user group. Right click on user group, and click "Update user group".
Click on "Resource Group Access" tab, "add resource group"
Select the resource group you created.
Minimum Role: Member (9999)
Access policy: "Load, list and view"
Context: Web

This allow user of type member to load the document, or list it out in rss and also view the document.

Now that you have protected this page, you will notice the unauthorised user will see a error page when trying to view this page. By right, the guest should see the unauthorized page instead...

Okay, to fix this, Go to "Access Control",
Right click on "(Anonymous)", and click "Update user group".
Click on "Resource Group Access" tab, "add resource group".
Select the resource group you created.
Minimum Role: Member (9999)
Access policy: "Load"
Context: Web

This will allow guest to load the document, but will not allow guest to list or view the document. This is how modx2 policy works.

Hope it helps ;)

Tuesday, October 12, 2010

Modx 2 Bummer in XPDO Log

It seems that modx developer have did a mistake by setting debug true/false to xpdo debug with php ERROR LEVEL constant

having : int(30711) for E_ALL & ~E_NOTICE in core/model/modx/modx.class.php line 453:
parent :: setDebug(intval($debug)); // isn't going to make any sense to xpdo debug

to fix it, ive manually
set it to true.

output path:
core/cache/logs/error.log

Friday, October 8, 2010

modx2 unable to right click Action

If you ever encounter problem right clicking on action box to create action for a namespace,
you may still do it manually by inserting a record in table "modx_actions"
  • create namespace in manager
  • insert record into modx_actions
    namespace=[namespace_name], parent: 0, controller: index, haslayout: 1
  • clear cache in manager
Tada, it will be there.

Modx2 accidental removed core Action

If you ever accidently removed the core Action ,
you may restore the file @
core/cache/mgr/actions.cache.php

Modx2 deployment

To transfer testing site to live site:

  • restore database to server
  • upload files to serveredit core/config/config.inc.php (many path setting)
  • server edit config.inc.php
  • server edit manager/config.inc.php
  • server edit connectors/config.inc.php
  • edit table modx_workspaces and set path field to core ,
    example: '/var/www/modx/core/'
  • for provisioner package: setting modx_system_settings.value of key "cookiefile" to temporary folder (if its not /tmp)
  • set chmod -R 777 to core
  • set chmod -R 777 to assets (create if not exists)
  • login manager, and clear cache (ignore the error of unable to locate action file)
If you have problem with packages, and accidently deleted the zip file, you may either download the package file manually, or delete the record in table "modx_transport_packages"

Newer version (2.1.3) doesnt need to edit manager, connectors config.inc.php.

First thing after done all above, login to manager, and clear cache.
But if you encounter unable to locate file ...manager/controllers/default/welcome.php
Try rerun setup

Useful links:

Thursday, October 7, 2010

Modx 2 how to output TV (template variable)

[[+tv.namehere]]

Make sure to have set:
&includeTVs=`1` in getResources snippet call

Example:
[[+tv.post_eventdate:strtotime:date=`%b %d, %Y`]]