Improve Your AikiFu
From Aikiframework wiki
With Aiki, there is no right way to accomplish your goal from the web. Below are some common needs and how to accomplish them to level up your AikiFu!
Make a User an Administrator
The default Aiki installation lists systemGOD at usergroup ID 1. Thus, if you want to change a user to have full systemGOD (Administrator) privileges), then run this sql:
update aiki_users set usergroup=1 where username = 'USERNAME';
Create a Site with Multiple Languages
Please see Language Support.
Turn on Revision Control
Please see Revision Control
Develop a Separate CSS for a Site
in Aiki you can link to external .css file, or create a new style-sheet file from a widget. this method is used if you don't want to use the in widget CSS System, or in companion with it.
to link to a .css file (either stored on the file system or a virtual file) you can have <link rel="stylesheet" type="text/css" href="PATH_TO_CSS_FIILE" /> html inside your widget,
but in widget options you have to change the Target to header in order to add the content in the html <header> instead of body, also you need to set Remove Container in the widget editing form to yes, to remove thethe PATH_TO_CSS_FILE can be either an actual file on the filesystem or a virtual file created inside a widget
to create a virtual CSS file you can create a new widget, add the CSS inside the Content part, then set Remove Container to Yes, and Custom Output to Yes, then in Send Custom http header add:
Content-type: text/css
to change the apache headers to be css for the browser to understand that it's an actual CSS file and not normal html with some CSS like content.
the Address (URL) of this widget can be something like: PATH/FILE.css then you can link to this virtual file in a header widget
Move Your Site to a New Domain
See Moving Aiki Sites for multiple ways to move your aiki site around.
Create Widget with Feed
This is documented here http://www.aikiframework.org/wiki/Aikimarkup#RSS_and_XML_markup
It should work for both an RSS and ATOM feed.
Howto Extend Aiki
Please see Extending Aiki.
Howto Develop on Aiki Core
See HOWTO Develop Aiki Framework
HOWTO Set a Page Title
Aiki auto-generates a page title of the site name. you can set the page title field to set a page title. If you set it on the homepage > content widget, that should set it for all pages that use the content widget. If a page doesn't have a page-title, it cascades from higher order downward.
To change the auto-generated page title from the site name: go to Database & forms, click on aiki_sites, click on Browse, click the edit button near the site you want to change, then edit the (site name) field.
Script Method
By default, title is:
Output.php line 124.
$title = '<title>' . ( $this->title ? "$this->title - " : "" ) .
$aiki->site->site_name() . '</title>';
To override, in a widget put:
(script( $aiki->output->set_title("new title of site"); )script)
HOWTO Make Pretty URLS
by default aiki uses rewrite rules to write urls, most urls look like www.yoursite.com/somepage, but if you are making an application that output results from database such as blog or photo gallery, you will probably end up with urls that looks like www.yoursite.com/blog/1 where 1 is the primary key of the record in database. such approach is good because the IDs are usually indexes and this make retrieving results really fast from the database, but it's not SEO friendly.
because of that many people prefer to use urls such as www.yoursite.com/blog/title-of-your-post or www.yoursite.com/blog/1/title-of-your-post where 1 again is the primary key of the record if you have both the id and the pretty url in the full url it will make it easier to read the find the post sense you will be using the primary key and the rest is only for search engines and not actually used to retrieve the post.
aiki provides a way to convert normal titles to urls, to make such urls you can use the fix url method: <php $aiki->url->fix_url( post title here ); php>
for example:
<a href="[root]/blog/((id))/<php $aiki->url->fix_url( ((title)) ); php>">((title))</a>
but if you want to only to only have the pretty url without the primary key like in: www.yoursite.com/blog/title-of-your-post you have to create a new field in your table for links, and to make it index, then store the links of each page either manually by entering the desired link or by having some javascript that auto reads the title from the title field while inserting (like wordpress) and then convert it to link, or by using the <php $aiki->url->fix_url( ((title)) ); php> markup to convert your title into links
HOWTO Edit 404 Error Pages
To edit 404 Error page you need to edit widget error_404, Aiki will display widgets that have url error_404 so you can create page for it, based on your site layout.
For more advanced usage, there is a fallback to db, if you enable the option ($config["register_errors"]) in config.php it will register those errors in aiki_redirects and allow th user to add a redirect for each one of those 404.
Working with Widgets
- If you use the name of the widget as an ID in CSS, etc, then if you rename the widget you will have to rename in multiple places.
- One way cxadams works is to use CSS classes to avoid this.
Help! No Results Error cannot process aiki markup
- The No Results Error widget field is useful because it displays output such as "No record found" if the SQL query does not return any results.
- Sometimes, however, you want more complicated behavior like a URL redirect or complex output.
- Unfortunately, No Results Error does not currently accept Aiki markup!
Oftentimes in an Aiki site we have a URL scheme such as [root]/folder/((record_field))
An example is http://example.com/user/1001
For the widget that exists on the URL 'user', we know that we can find the value of 1001 by calling it with (!(1)!)
We also know that if instead of 1001, (!(1)!) either has no value or is equal to a value that is not found in the database, we can use the No Results Error field to output the message "No User Found"
But if instead of displaying a simple error message, we want some more complicated output, then here is one solution
- Create a new widget also on URL user
- For the SQL Query enter the following:
- SELECT userid from aiki_users WHERE NOT EXISTS (SELECT userid from aiki_users WHERE userid = '(!(1)!)') LIMIT 1
- for the content enter in whatever should be processed if (!(1)!) is either NULL or not a valid userid
Create Wiki-like Functionality
- So you create a pages table like this: Create Table pages
CREATE TABLE `page` ( `id` int(11) NOT NULL auto_increment, `title` varchar(255) NOT NULL, `text` text NOT NULL, `url` varchar(2083) default NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=38 DEFAULT CHARSET=utf8;
- Then, create form for that, by clicking on the table name inside of the aiki framework instance under Database & Forms" tab.
- Now, create a widget to display those pages with a widget with the following sql:
select * from pages where url = '(!(0)!)'
- Now, change the standard 404 error to match the style of the site.
- Change the 404 error to have a create new page link in it.
- It could be simple like:
<a href="[root]/addpage">Create page</a>
- OR
- Make it so it can be any page:
<a href="[root]/addpage?url=(!(0)!)">Create page</a>
Create a robots.txt
- Create a widget
- Name it robots.txt
- Set
Custom Outputto Yes - Input:
Content-Type: text/plain; - Put your directives in the content textarea something like this (which disables all bots from crawling your site):
User-agent: * Disallow: /
Create a captcha
Captcha is used to prevent spam bot registrantions. Aiki Framework has a default implementation of captcha.
To use the default Aiki captcha to prevent spam bots from inserting into public forms (like comments forms) do the following:
- From the admin interface, click on Database & Forms and select the form you want to protect.
- At the end of the form, add new field of type: captcha
- In the text input for that field enter the word: default
In the widget, use the regular Aiki markup to insert your form: (#(form:add:_form_number_)#)
The captcha will show up automatically on that form when it is an 'add' form used to insert a new record (like a new user or comment). The captcha will not show up on the form when it is an 'edit' form to edit a record.
For captcha to work properly it seems you have to edit config.php and set the following value to true:
$config["allow_guest_sessions"] = true;
Create a Password Reset feature
Aiki has built in functions to help your site users recover lost passwords. This guide will walk you through the steps to implement this feature on your site.
Step 1: Create a form for lost users
A user visits the sign-in page and realize he has forgotten his password.
- Create a link on your sign-in page: <a href="[root]/forgotten_password">Forgotten your password?</a>
- Create a new widget
- Set the Address (url) to: forgotten_password
- Set the Content of the widget to:
<form action="[root]/reset_password" method="post" enctype="multipart/form-data" class="questionnaire">
<fieldset class="fields">
<div class="field">
<label for="username">Username</label>
<input type="text" id="username" name="username" />
</div>
<div class="field">
<label for="email">Email</label>
<input type="text" id="email" name="email" />
</div>
</fieldset>
<fieldset class="button">
<input class="button" type="submit" value="Submit" name="submit" />
</fieldset>
</form>
Step 2: Create a widget to send an email to the user
- Create a new widget
- Set the Address (url) to: reset_password
- Set the Content of the widget to:
<php $aiki->membership->ResetPassword(POST[username],POST[email],noreply@example.org,Reset Aiki Framework site password password,Reset your password:); php>
This function will send an email to the specified email address with a link to reset the password.
Step 3: Create a callback widget to help reset the password
- Create a new widget
- Set the Address (url) to: secure
- Set the Content of the widget to:
<php $aiki->membership->NewPassword(GET[key]); php>
This function will output a form that let's the user reset his password
Done!
Redirect a url
HTML
This is a bad way to do it, but is one of a few I'm sure:
- Create a widget
- Give it a path like
some path
- Then, put this into the content, wher eyou can change the url=TO_SOMETHING_ELSE
<meta http-equiv="refresh" content="0;url=[root]/wiki/">
Aiki Way
(#(header:Location: [root]/admin|false|301)#)
With New Script
In latest aiki you can edit widgets that have header. If you have version of Aiki that don't allow for header in Admin Panel you can use
(script( $aiki->utils->header("HTTP/1.1 301 Moved Permanently",); )script)
(script( $aiki->utils->header("Location: [root]/admin",); )script)
and utils->header is just wrapper of header php function.
