Hours of Operation

RSS

Posts tagged with "mozajik"

May 9

Introducing the Mozajik Loader plugin for Wordpress

Some sites have complex data needs (where a framework like Mozajik does a great job) while also requiring a simple CMS for publishing news and updating site content (which is what Wordpress does best).

Introducing, the Mozajik Loader plugin for Wordpress 3.x+. It allows you to load up the Mozajik framework and display any framework-based data or content inline.

See the docs and download it from Github.

Install Mozajik on nginx

nginx is a lightweight alternative to Apache. It supports rewrites but not via the .htaccess file like Apache. To install Mozajik under nginx, you will need to add these rules to your site conf file:

location /site/{

        }

location /system/site/{

        }

location / {

                rewrite ^/(js|css|ext|img)/(.+) /site/$1/$2 last;

                rewrite /(system)/(js|css|ext|img)/(.+) /system/site/$2/$3 last;

                rewrite ^/(system)/(site)/(js|css|ext|img)/(.+) /system/site/$3/$4 last;

                rewrite ^/(plugins)[/]+([A-z0-9]+)[/]+(.+) /plugins/$2/site/$3 last;

                rewrite ^/(robots.txt|favicon.ico) /site/$1 last;

                rewrite ^/(data/private)(/)?(.+) /site/index.php?error=private last;

                rewrite ^/(data)/(.+) /data/$2 last;

                rewrite ^/([^/.]+)/(.+) /site/index.php?zajhtver=303&zajapp=$1&zajmode=$2&$args last;

                rewrite ^/([^/.]*)(/)?(.*) /site/index.php?zajhtver=303&zajapp=$1&zajmode=&$args last;

                rewrite /(.+)? /site/index.php?zajhtver=303&zajapp= last;

        }

Mozajik pushState support

The Mozajik Framework now supports pushState ajax requests out of the box. Here is how to create a link:

<a href=”{{baseurl}}some/content/” data-container=”#divid” data-block=”blockname” data-title=”New Page Title”>Load some content</a>

In your controller file (some.ctl.php  / function content()) you will have the following:

// do something then load template

$this->zajlib->template->show(‘some/content.html’);

Mozajik will recognize that the current request is a pushState ajax request and will not generate the full content.html. Instead it will load up only the ‘blockname’ block within the template and place that content into divid. So:

This is my template and it includes:

{% block blockname %}some content{% endblock %}

…the end result will be that the page will NOT be reloaded, the URL will be set to some/content and the element with id ‘divid’ will be set to the returned content:

<div id=”divid”>some content</div>

Works much like pjax, but it’s Mootools and Mozajik-friendly.

Ajax requests and returning JSON data in Mozajik

Handling complex AJAX requests is simple in Mozajik.

1. First send an ajax request via the Mozajik js framework

zaj.ajax.post(‘/relative/url/to/controller/?variable=something’, function(result){ });

2. Process the request in the controller (relative.ctl.php / function url_to_controller in this example)

function url_to_controller(){

// Do something with $_POST[‘variable’];

// Return ajax json

$this->zajlib->json(array(‘status’=>’ok’, ‘message’=>’You successfully did something’));

}

3. Process the result in the inline function (this uses Mootools)

zaj.ajax.post(‘/relative/url/to/controller/?variable=something’, function(result){

var rdata = JSON.decode(result);

if(rdata.status == ‘ok’) alert(rdata.message);

});

Feb 9

Forcing debug_mode for Mozajik in apache configuration

In the latest SVN version of Mozajik you can force a site to use debug_mode (in which errors and log messages are displayed) from the Apache configuration file or the .htaccess file. Simply add the following line to your vserver or the .htaccess file:

SetEnv DEBUG_MODE “true”

Check for plugins in Mozajik beta 8

Mozajik beta 8 now has much better plugin support. If you want to check whether a plugin is loaded, you can use one of the two methods below:

  1. Check in a controller (returns true if enabled)
    $this->zajlib->plugin->is_enabled(‘plugin_name’);
  2. Check in a template (displays text if enabled)
    {% if zaj.plugin.plugin_name %}Display this if plugin enabled{% endif %} 
Dec 8

New value substitution feature for easier localization in Mozajik

Mozajik now supports a useful new feature for localizations in your lang files.

Lang file will be as follows:

see_all_users = See all %1 users

Template file will contain:

{{#see_all_users#|printf:users.total}}

This will output (assuming there are 32 users in the db):

See all 32 users

You can also do multiple replacements as follows:

see_all_users = See all %1 users in %2 groups

{{#see_all_users#|printf:users.total|printf:groups.total}}

Oct 3

Custom database query in Mozajik

Though the database API (via the zajFetcher class) is often enough, you may need to run custom queries on occasion. If you need to run several queries at once, you should create a new connection or create a new session.

You can execute custom queries via the existing connection through the Mozajik db object. Be careful to note that unlike PHP’s built-in functions, Mozajik returns OBJECTS and not associative arrays!

$result = $this->zajlib->db->query(“SELECT fieldname FROM table LIMIT 100”);

foreach($result as $row){

print $row->fieldname; // columns are accessible as object properties

}

Extending plugins, overriding plugins in Mozajik

Note to self: see NwUser model.

Manually fire the default controllers __load magic method in Mozajik

In some cases, you may want to load the default controller’s __load method from other controller files. Here is how:

// load file

$this->zajlib->load->file('controller/default.ctl.php');

// do a static load

zajapp_default::__load();