Showing posts with label cms. Show all posts
Showing posts with label cms. Show all posts

Saturday, December 31, 2011

MODx page not found on manager

This was a real trouble for me in the first place.
How am i suppose to fix this...
First, i did the throw exception as stated in my last post.

then next thing i know, i realize the $modx->config["modRequest.class"] wasn't declared...
so it uses modRequest instead of modManagerRequest class.

after digging for hours, ive finally noticed that the $modx->context->prepare() doesnt seems to return
proper config in $modx->context->config;

to fix it, add in true  into the parameter:
$modx->context->prepare(true);
then, load the manager page. you should be able to see the manager page now.
next, remove the true (restore the code to its previous state).
then login into the manager.
and Site > Clear cache.
Now all your site should have the proper config loaded based on the respective context.


MODx page not found...

Stumble upon modx page not found?
MODx by default, will send an error page if any error found during the loading of the page.
its in modx/core/model/modx.class.php

want to see the actual error?
go to the line declaration of
public function sendError($type = '', $options = array()) {
throw new Exception($errorMessage); //after $errorMessage is defined

Saturday, August 20, 2011

MODx Revolution and UTF8

If you ever need to insert in latin symbol or unicode into modx title or content...
Modify modx_site_content fields:
+ pagetitle, longtitle, description, introtext, content
to unicode_general_ci encoding.
(Note: This is a fulltext index, so you will have to execute 1 statement to alter all 5 fields)
And also modify template variable content:
ALTER TABLE  `modx_site_tmplvar_contentvalues` CHANGE  `value`  `value` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL

Next, modify core/config/config.inc.php and change the line:
+ $database_connection_charset = 'utf8';
+ $database_dsn = 'mysql:host=...;dbname=...;charset=utf8';

And you may start testing it it works :)
In my setup, its somehow in njis charset... (im not sure why)

Tuesday, August 9, 2011

MODx Revolution Root resource alias / path?

I tried google around on this, and find it difficult to find the result.
I've found a solution to based my resource alias to the root of the site.
By going to system > settings
use_alias_path : no

This will change all your resource alias to be based from root.
Example:
Container1 > My page (resourcealias: mypage)
now become:
http://www.example.com/mypage

If you need the container path, just put the full folder path:
Example:
Resource alias: container1/mypage

Wednesday, January 26, 2011

MODx 2 Context setup

When setting up a site to a context, be sure to set these setting in the context:
  • site_url - site url to the domain
  • filemanager_path - the file manager path for this context to upload images / media
  • site_start - the starting resource id as home / landing page
  • site_name - the Site name to be displayed in email and page title

Sunday, January 16, 2011

MODx 2 Adding ... to intro text summary

If you plan to add "..." to a intro text or content which is more than some # of characters,
you may use if condition within the chunk.

Example below will add ... to intro text:
[[+introtext:if=`[[+introtext:len]]`:gt=`200`:then=`[[+introtext:limit=`200`]] ...`:else=`[[+introtext]]`]]

Monday, January 3, 2011

MODx loading other components lexicon

If you need some lexicon from another components from your snippet,
you may do so by running this in snippet:
$modx->lexicon->load("namespacename:filename");

Example:
$modx->lexicon->load("login:register");
//resolve to: core/components/login/lexicon/register.inc.php

Thursday, December 23, 2010

MODx 2.0.6 update

MODx team have finally made it right :)
Every logged in session now have to be in
$_SESSION["modx.user.contextTokens"]

Example:
$_SESSION["modx.user.contextTokens"]["web"]=UserId#


And $modx->executeProcessor($options) now get $scriptProperties from $options, no longer $_POST.



Wednesday, December 22, 2010

MODx 2 Plugin OnBeforeDocFormSave

Here is an example to make a tv to be a required field:
----------------------
<?php
/*
* $mode: "new/upd"
* $resource: modResource object
* $id: resource id
* Calling $modx->event->output("..."); will output error and cancel save
*/


if (empty($_REQUEST["tv4"])) {
$modx->event->output("Field 'XXX' is required");
}


Tuesday, December 21, 2010

MODx 2 Resource Create/Update Cancel redirect

If you need to create your own resource grid,
you may find it difficult to control the resource create / update redirect on after save or when cancel button is clicked.
One way to do this is to add your own startupclientscript like this:
----------------------
setCancelButton();

function setCancelButton() {
if (!Ext.getCmp("modx-action-buttons")) {
setTimeout("setCancelButton()", 1000);
return;
}
Ext.getCmp("modx-action-buttons").actions.cancel = 90;//your action number
for(var c=0; c Ext.getCmp("modx-action-buttons").items.items.length; c++) {
if (Ext.getCmp("modx-action-buttons").items.items[c].process == "cancel") {
Ext.getCmp("modx-action-buttons").items.items[c].handler = cancelHandler;
}
}
}

var cancelHandler = function (btn,e) {
var fp = Ext.getCmp(this.config.formpanel);
if (fp && fp.isDirty()) {
Ext.Msg.confirm(_('warning'),_('resource_cancel_dirty_confirm'),function(e) {
if (e == 'yes') {
MODx.releaseLock(MODx.request.id);
MODx.sleep(400);
location.href = '?a=90'; //your url or action here
}
},this);
} else {
MODx.releaseLock(MODx.request.id);
location.href = '?a=90'; //your url or action here
}
}


Wednesday, December 15, 2010

MODx 2.0.5 form customization for profile

The new form customisation for MODx 2.0.5-pl seems to only cater for resource create/update.

If you need a form customization for user profile, you may do it by adding a plugin on initialized manager with event "OnManagerPageInit":
-----------
define("IS_PROFILE_MODULE", $_GET["a"] == 71? true: false);
if (IS_PROFILE_MODULE) {
$modx->regClientStartupScript("url to your file.js",true);
}
-----------

URL to your file.js:
-----------
Ext.onReady(function() {
doHideProfileTabs();
});

function doHideProfileTabs() {
if (!Ext.getCmp("modx-panel-profile-tabs")) {
setTimeout("doHideProfileTabs()", 1000);
return;
}

MODx.hideTab("modx-panel-profile-tabs","modx-panel-profile-update");
MODx.hideTab("modx-panel-profile-tabs","modx-profile-recent-docs");
//MODx.hideTab("modx-panel-profile-tabs","ext-comp-1020"); //change password
Ext.getCmp("modx-panel-profile-tabs").setActiveTab(2);
}
-----------
Please take note: The hidden tab is still in the tabs container, therefore setactivetab have to reflect the index of the original position.

MODx Updating to new version

files needed to copy:
core/* , except core/cache, core/config
manager/*
connectors/*
setup/*
index.php

Remember to avoid copying:
core/cache
core/config

Friday, December 10, 2010

Modx 2 getResources enhanced tvFilters

I've done some modification to getResources to accomodate more condition operators such as :
!=
EXISTS
NOTEXISTS
| : for OR operator

And changed that the condition will only effect after the main condition is meet, etc. published='1' and deleted='0'

Examples:
tvFilters=`mytv!=%xxx%|mytv==NOTEXISTS`
#setting condition to TV mytv does not contain tag "xxx" or no mytv variable exists

getResources2.php

Hope it helps you guys :)
Cheers~

Tuesday, December 7, 2010

Modx 2 file manager + upload image on 2.0.4-pl2 or lower

File manager works well when you plan to use only "web" context for your manager users.
But when it comes to using other context, you will realise that there are some permission issue related to context.

To fix it temporary, until modx 2.0.5 is release, here is a fix.
path:
model/modx/processors/browser:

*/directory/getlist.php , */directory/getfiles.php , */file/upload.php , */file/remove.php:
Adding this somewhere at the top:
$context = !isset($scriptProperties['ctx']) ? "web": $scriptProperties['ctx'];

Change from:
$root = $modx->fileHandler->getBasePath();
To:
$root = $modx->fileHandler->getBasePath(false, $context);
---------------
Change from:
$fileManagerUrl = $modx->fileHandler->getBaseUrl();
To:
$fileManagerUrl = $modx->fileHandler->getBaseUrl($context);
----------------

Wednesday, November 24, 2010

ExtJS Datagrid column sortable

I've just realized that if you dont set id for the columns of the datagrid,
the sorting option for the column will be disabled by default, even with sortable set to true.

,columns: [
{id:'id', header: _("id"), width: 80, sortable: true, dataIndex: 'id'},
{id:'pagetitle', header: _("pagetitle"), width: 400, sortable: true, dataIndex: 'pagetitle'}
]

Hope this help you save hours of debugging :)
cheers~

MODx 2 Manager Alert and Prompts examples

Success example:
MODx.msg.alert(_('success'), ("Saved"));

Error example:
MODx.msg.alert(_('error'), ("Some problem occur!"));

Prompt Example:
Note: code highlighted in italic are just sample code, will not work without full code.
---------------------------------------
MODx.msg.confirm({
title: "Delete Article?"
,text: "Confirm delete this article?"
,url: MODx.config.connectors_url + "resource/index.php"
,params: {
action: "delete",
id: selectedIndex
}
,listeners: {
'success': {
fn: function (A) {
if(A.success) {
MODx.msg.alert(_('success'), ("Removed"));
mygrid.refresh();
} else {
MODx.msg.alert(_('error'),A.message);
}
},
scope: this
}
}
});
---------------------------------------

_('...') is a function to output lexicon text (translation text)


Sunday, November 21, 2010

useful modx 2 variables

PHP Constants:
MODX_BASE_PATH - dir path to index.php (root)

MODX_ASSETS_PATH - dir path to assets
MODX_ASSETS_URL - url to assets

MODX_CONNECTORS_PATH - dir path to connector
MODX_CONNECTORS_URL - url path to connector

MODX_PROCESSORS_PATH - dir path to processor: example: core/model/modx/processors/

MODX_CORE_PATH - dir path to core

MODX_SITE_URL - domainurl
MODX_HTTP_HOST - hostname / domain

MODX_URL_SCHEME - http:// / https://

MODX_MANAGER_PATH - dir path to manager
MODX_MANAGER_URL - url to manager

$modx->context->get("key"); // get context name
$modx->context->getConfig("upload_maxsize"); // example of getting upload max size


JAVASCRIPT Constants:
MODx.config.http_host, example www.example.com
MODx.config.http_host_remote, example http://www.example.com
MODx.config.site_url , example: http://www.example.com/
MODx.config.assets_path, example "/assets/"
MODx.config.connectors_url, example "/connectors/"
MODx.config.manager_url, example "/manager/"
MODx.config.template_url, example "/manager/templates/default/"


Wednesday, November 17, 2010

New Modx 2.0.5 Profile Set

Damn cool :D
[Link here: http://bit.ly/aXTvxB]

Modx 2 getUser

Instead of calling $modx->getUser to get currently logged in user,
use getAuthenticatedUser.

Example:
$oUser = $modx->getAuthenticatedUser($modx->context->get("key"));
echo $oUser->username;
echo $oUser->getOne("Profile")->fullname;

If you use "getUser", it might return the first user in the database if the person is not logged in, which might not be what you are looking for.

hope it helps :)
Cheers~

Sunday, November 14, 2010

Modx 2 How does getService works?

modx->getService($name, $class= '', $path= '', $params= array ())

name = name to be assigned to modx->$name and modx->services[$name]
class = classname (resolving to "classname".class.php)
path = path to look for class
params = array of value pass to class.

Example:

getService("login", "Login", corepath."/components/login", ...);
Resolve to:
core/components/login/Login.class.php
initiate class __construct(modxobject, $params);