Friday, December 30, 2011

My answer to "Little bug, with open editor"

This is my answer to a Question on Support site for LampCMS project


I don't really consider it a bug. It is actually a very valuable feature. The editor uses browser local storage feature to save text from your editor to local storage. So if you type something in the editor and don't post it right away and your session expires, the editor will still remember your text.

There is even a "save" icon in the editor so you can save whatever you typed in the editor, so you can continue writing your post later, can be even in a few days.

If you don't push the Save button, the text is auto-saved every few seconds so if your computer crashes your text will still not be lost.

The contents of cache are cleared after you post a question or the answer and the "success" message is returned from the server. This way if the sever is down for any reason at the time you trying to post, your text in the editor is still not lost, so you can try to post later.

As for second window "bug", it's just how browsers work - it shares local storage between windows for the same domain.

Finally if this bothers you, there is an icon next to "Save" icon in the editor "New". Clicking on it clears the cache of editor and your start with a blank page.

Enjoy.

Tuesday, December 27, 2011

New feature - categories

My Question on Support site for LampCMS project

Just want to let you all know that I've been working on adding support for categories, in addition to tags.

The first, most important part of this was to write an admin interface to add/edit categories and to sort categories by the order and by sub-categories.

I have just finished this feature. Basically we going to have support for categories with unlimited nested categories.

Next step will be to add drop-down menu to select the category when posting a question, then add a breadcrumb navigation links to question view pages to point to category.

Then add a new page that will show the list of all categories and sub-categories. That page will probably look similar to the look of most online forums like phpbb and vbulletin, where you see categories, subcategories and latest posts in each category.

More feature will be added, for example we will probably have a way to subscribe to category, similar to subscribing to a tag.

Should I upload the new category editor files now or wait until support for selecting a category when asking a question is done?

Click here to post your reply


Saturday, December 24, 2011

My answer to "Updates to Facebook API"

This is my answer to a Question on Support site for LampCMS project


I have just pushed the new files to github. It includes the new API for Facebook, both for login with Facebook and for posting to Facebook Wall.

This updates also includes a rewrite of how User (Viewer) object is stored in session. The User object is no longer stored in session, only the userid and classname of user is stored in session and the actual object is recreated on page load.

Is this less efficient? I don't thinks so. The select of user array on primary key from Mongo collection takes about 1 millisecond. Creating a new object is not any slower that unserializing it.

The benefit of this change is that session becomes alot more reliable now. No more sudden user logout, no more unpredictable session behaviour.

I also rewrite some parts of the script that used to have the exit() statement, we no longer using exit(), instead using a special type of exception which propagates all the way to the end of the script, so script always exists the natural way. The exit() method is not bad way to terminate the script, except that in some servers, in certain server environments it causes problems. Since this is an open source project, it must work on as many different platforms as possible. I think the latest change makes alot of progress in making it alot more reliable.

Please download, install, test it. Report any problems if you encounter any.

Thank you.

Monday, December 19, 2011

My answer to "Geo location"

This is my answer to a Question on Support site for LampCMS project


There is not special code to install. It's all automatic. If the user location can be determined from ip address, it is stored in USERS collection and then it's automatically shown on profile page.

Also when adding new question or answer the location, if it can be resolved from the ip address is stored in the collection with the QUESTION or ANSWER and than data base be shown or question/answer page. But that location (in Question or Answer) is not automatically displayed. I will update the templates to show the country flag of the locations in Question and Answer templates and will upload to github by end of the year.

Keep in mind that location is stored only if it is successfully resolved from the ip address, which means it will not work when you developing your site on localhost because your ip is local ip then.

Sunday, December 18, 2011

Updates to Facebook API

My Question on Support site for LampCMS project

As was noticed by one of the users, there is a problem with the "logout" action. I traced this problem to the Facebook Javascript API.

So I started investigating further and it turned out that Facebook has updated their APIs a couple of month ago and on December 13 the old APIs no longer working.

That's the reason for our problems with logout and with login using facebook button.

I will be rewriting our own Facebook API now. I will be using the official facebook php sdk this time.

This is not a difficult thing for me to do, normally stuff like that will take 2 days - one to write, another day to test and debug. The problem is that I'm not going to have 2 days untill Christmas, so the updates will be available after Christmas, but maybe even sooner. I have already started writing the new Client to Facebook API.

Click here to post your reply


Saturday, December 17, 2011

My answer to "Logout problem in original lampcms"

This is my answer to a Question on Support site for LampCMS project


I am having the same problem now. This is something new and it has to do with javascript from Facebook.

I searched for this error, looks like other people are having this problem with Facebook Javascript, but I just can't find any answer on how to fix this. There is a bug report filed on facebook API forum but apparantly that bug is closed.

Honestly I don't know how to fix this other than just not use Facebook login feature for now until these clowns at facebook fix their script.

Friday, December 16, 2011

My answer to "Problem with Geo_location"

This is my answer to a Question on Support site for LampCMS project


I have made a small change to Geo/Import class. It now creates indexes first and then imports, instead of creating data and then indexing it.

I tested on my local Windows 7 and on this site, both worked fine, but I never had the problem with the import in the first place. All I know that the script works after the update.

You can download the latest version from github and try it.
I also made some minor changes, so the never version is probably a little bit better anyway.

For example, the session_start is called earlier in the process, possibly fixing problem some people were having with sessions on local installations.

Also error handler will not email admin of non-critical errors.

My answer to "Problem with Geo_location"

This is my answer to a Question on Support site for LampCMS project


So it sounds like your script imported the 3.5 million records into GEO_BLOCKS which is good, then connection to MongoDB was lost. I know the GEO_BLOCKS import takes long, can take 3-5 minutes to complete as records are imported one by one.

I have not faced this problem before.

I'll investigate. Maybe there is some extra setting or param to MongoDB connection that can be used, I'll look into that. If I can't find the answer then maybe I can split the import into 2 scripts - one to import GEO_BLOCKS and then run another script to import LOCATIONS.

Thursday, December 15, 2011

My answer to "Is it possible for moderators to filter or control the posts before they are published?"

This is my answer to a Question on Support site for LampCMS project


RIght now there is no such feature. Moderator can only delete or edit post but there is no feature to "approve" a post.

This feature can be added pretty easily, probably with very little programming, just have to set the status of new posts to "deleted" - deleted posts dont show up on the site but moderator/admin can still see deleted posts and can 'undelete' them, so this will be exactly the feature you looking for.

Tuesday, December 13, 2011

My answer to "how GEO location is working flow of the geo location"

This is my answer to a Question on Support site for LampCMS project


First read and follow instructions in geo_import.php file in the www directory.

The location of user is resolved during the post of new question or answer and stored with the answer or question, in the same collection, in the same record.

Also location of user is stored during the registration process in the USERS collection, and during the normal operation of a site, if the "whos online" module is enabled in !config.ini, then it is also stored in the ONLINE collection.

You can then use this data in your custom module to display the locations of users. For example you can create a page with Google maps showing currently logged in users on the map or you can show a map on the View Question page showing locations of where the answers came from.

Or you can just edit template to display country name and city.

The extra fields added to collections to represent locations are:

'cc' = country code like US
'cn' = country name like "India"
'city' = city
'lat' = latitude
'lon' = longitude

Not all fields will have data, some locations may have only cc and cn and no city. Most of the time all the fields will be present.


Saturday, December 10, 2011

My answer to "EXPLAIN THE FLOW..."

This is my answer to a Question on Support site for LampCMS project


It means if question has any answers or if currently logged in user of the site is a moderator (admin also moderator, so it's true for admins too), then instantiate the Answers object and get the answers for this question.

The reason for isModerator check is that in theory the question may contain deleted answers, which would mean that count of answers is 0, but there still may be deleted answers. Since moderator may be allowed to "undelete" answers, the Answers object will still pull all the answers, even deleted ones.

My answer to "Language translation problem"

This is my answer to a Question on Support site for LampCMS project


The translation files are cached. You need to clear your cache. When logged in as admin, click on Settings, you will see an option to clear cache. Click on it and it should remove everything from cache collection.

After doing that try and see if your translations work on your site

Friday, December 9, 2011

My answer to "Follow Mecahnism"

This is my answer to a Question on Support site for LampCMS project


To explain it very simple - the user ID of your user account is added to array of followers. So a single question may has a property a_flwrs which is an array of user ids.

Very simple. When you unfollow question., your user id is removed from that array.

My answer to "How many collections are there in mongodb for lampcms"

This is my answer to a Question on Support site for LampCMS project


Looks about right. Once you start creating questions, answers and comments, the new collections will be added automatically as needed.

My answer to "Why social buttons are not displaying on local lampcms"

This is my answer to a Question on Support site for LampCMS project


You need to configure each one of the services, for example, to enable login with Twitter you need to register with Twitter developer account. Same for Facebook.

The buttons are only going to appear for services that you enabled - you must have special user accounts for each one. For example, to enable LinkedIn button, find the section [LINKEDIN] in your !config.ini and setup your own OAUTH_KEY and OAUTH_SECRET
Once set, the button will appear.

Also you will need to logout and log back in because I think the block with the buttons are cached in session for performance reasons.

Instructions are in the !config.ini file.

My answer to "How Geo Location is identifying in lampcms?"

This is my answer to a Question on Support site for LampCMS project


Geo IP database files are not included. You need to download the .csv files from Maxmind.com and run an import script.

Instructions are in the geo_import.php file in the www folder. Follow instructions and start this file from your browser. Once imported, the GeoIP will work on your site to map ip to location.

Thursday, December 8, 2011

My answer to "What actually contains question_title table?"

This is my answer to a Question on Support site for LampCMS project


It stores titles of questions.
Simple as that. The interesting thing about it as that this table has a full text index of titles.
Using full test search of mysql it is then easy to find "Similar" questions for a new question.
It is also used for the search feature of the site - the "Search" form uses it.
In the future the search feature may be powered by a more sophisticated search engine, but for now it's powered by mysql full text search. It's very easy to setup and it does the job.

Monday, December 5, 2011

My answer to "does lampcms support chinese well?is there some example website in china based on lampcms?"

This is my answer to a Question on Support site for LampCMS project


If you write your language translations string file, the ".xlf" file in the utf-8 charset that it can be in chinese or in any other language as long as it uses utf-8 encoding.

You just need to write your own translation file and same in 'translations' folder, name it "messages.cn.xml" ( I think "cn" is correct abbreviation for chinese locale, but I'm not sure)

You can see how it's done in translations/messages.ru.xlf for the Russian translation.

You then have to add a line in the !config.ini in the [LOCALES] section. For example, add this:
cn = "Chinese"

That will add the extra option to the drop-down language selection menu at the bottom of your site.

Saturday, December 3, 2011

My answer to "Few doubts in Lampcms ???"

This is my answer to a Question on Support site for LampCMS project


The factory in Urhere is not in User class. Urhere class extends LampcmsObject, so it uses factory in LampcmsObject. That class in the \Lampcms\Object.php file.

factory method even though is static, is inherited by sub-class - it's part of php 5.3 late static binding feature, where a new keyword "static" refers to the calling class. factory method then call constructor of the calling class.

Trust me, everything just works, and works pretty well.

My answer to "[want try lampcms]how to safely upgrade php 5.1.6 to php 5.3.3 , what should be backup before"

This is my answer to a Question on Support site for LampCMS project


I would say just install php 5.3.3 and try it.

Some existing php programs may have a few errors (most likely just warnings) pop up here and there after the upgrade, those can be easily fixed.

The 5.1.6 is really an outdated version, 5.3.3 (or newer) is much more effecient and just a faster version.

You will almost certainly will want to also use the APC extension instead of eAccelerator or if you really like eAccelerator then at least upgrade it to version compatable with php 5.3. I personally would just go with APC since it's not standard part of php and is maintained by php, unlike eAccelerator.

You don't have to do anything with nginx, just upgrade php, make sure you install php-fpm and use run php as fastcgi under php-fpm management.

Wednesday, November 30, 2011

My answer to "How the Request will be passed to index page"

This is my answer to a Question on Support site for LampCMS project


the value of 'a' resolved to name of controller - a class in the Lampcms/Controllers directory.
For example the a=unanswered resolved to Lampcms/Controllers/Unanswered.php

If controller does not exist for the action (this should never happen) then there will be an error.
Every controller class extends Lampcms/WebPage.php

The job of controller is to implement own main() method and setup the values in the this->aPageVars array. This array is then passed to tplMain template and the page is rendered. WebPage class sets up some vars then calls the main().
Controllers all have their own version of main() - that's where controller does their main processing and controller usually sets up the values of ['body'] which is the main area of page and often the value of side navigation blocks, the page title.

After the main() is run, the controller adds some extra values to aPageVars and the in index.php there is this line:
echo new $class($Registry);

This calls the __toString() method in WebPage which basically passes the aPageVars array to the tplMail::parse() and that gets back the html of the web page. The page is echoed to the browser.

There is also an Event Dispatcher involved. The Controller and WebPage class (which is base for every controller) does post some events to event dispatcher, for example 'onPageView', 'onBeforeNewQuestion', 'onNewQuestion', etc.

This allows to write and add custom modules that extends Lampcms/Event/Observer and then these modules are registered as observers and receive all events. Any one of the observers usually ignores most of the events and acts only when specific event occurs. There are several modules that exist, so you can see how they are written. For example Email notifications is a module. Just look in Modules and Modules/Observers directory for some examples. Every Observer since it extends Lampcms\Event\Observer has access to Registry object, meaing it can access the Mongo, Request, and some other important objects from it. A custom observer module just has to implement own main() method and inside that main() method do it's logic. Usually an observer module will first examing the name of the $this->eventName and see if it's the event it's interested in.

Last thing is fastcgi_finish_request() is run and it often runs some extra functions that have been setup usually in custom modules. These functions all run after the page has been served to used, so user experience does not suffer by running some functions that can be run after the page is returned. Such functions may include adding the new question to search index. finding similar questions, posting the new question/answer to twitter, facebook, tumblr, linkedin, emailing users who may be subscribed to that particular tag, updating the 'whos online' collection, which resolved ip to geo location. All these extra steps run after the page is returned and connection to browser is closed. The end-result is similar to offloading the extra work to another thread in Java. Of cause in Java you can create more than one thread and run each task separately, but that's a different story. The user experience is still the same - page is served as fast as possible and extra processing is done afterwards if possible.

Tuesday, November 29, 2011

My answer to "Is it possible to separate the mongodb from Lampcms."

This is my answer to a Question on Support site for LampCMS project


It is not possible. This project is written specifically for mongodb. To put is simply - it takes advantage of the features that Mongodb has and mysql does not have. There are many Q&A projects that are powered by MySQL, but this one runs on MongoDB and that's why it will always be faster and will be able to easier handle heavy traffic and easier to scale when your site grows to millions of questions and answers than MySQL based programs.

Saturday, November 26, 2011

My answer to "How to set local email server details in Lampcms???"

This is my answer to a Question on Support site for LampCMS project


It's sometimes not easy to setup php to send email from local server. Usually you need to add smtp server in your php.ini file and restart your web server.

If you are on Linux then it different and may be due to some unconfigured hosts file or something like a missing PTR record that points back to your domain name.

It really have nothing to do with Lampcms. If you want to show page loading time there is a config option called
SHOW_TIMER in your !config.ini file. You need to change the value to true and it will start showing page rendering time just like on this site.

My answer to "Which design pattern Lampcms following??"

This is my answer to a Question on Support site for LampCMS project


A complex program like this one usually implements more than one design pattern. One pattern that is well-known and is used here is Subject/Observer. Many interesting points in the program post events to event dispatcher.

Various observers are registered with the Dispatcher and listen to events and take some actions on various events. Custom modules are all observer objects and receive events and can then do stuff to the objects passed in Event, including modifying data in the object.

Other patterns I like is adapter pattern.

Also the whole program pretty much designed with MVC pattern. All web pages are actually controllers, all database related stuff is taken care by very lightweight class on top of php's Mongo classes.

There is no dedicated routing class, all requests are routed based on name of the 'a' param in URL. 'a' stand for "action''. For example a request to index.php?a=unanswered is automatically routed to 'Unanswered' class in Lampcms\Controllers\ namespace, etc.

Most classes are autoloaded based on the namespace. Base classes are always pre-loaded for extra efficiency.

The custom templating engine I wrote is very simple and fast, a template is a php class, so templates are cached by APC cache really well. There is no pre-parsing of any kind in the template, you simply pass the array of key=>value pairs to a template's parse() function and it returnes a parsed html block

There is also a REST api with read/write functions. I hope one day to start writing an Android app for this program. I know Java, I played with Android SDK before, it should be pretty easy for me to at least start an Android app. I'll make it open source also, so hopefully others will join and contribute.

Friday, November 25, 2011

My answer to "Getting error when clicking on signup button"

This is my answer to a Question on Support site for LampCMS project


You need to make sure you have the tmp directory and that it has writable permissions.
Baiscally the errors points to a directory that is probably does not exist on your server or is not writable:
/var/www/lamp/www/w/img/tmp/

Check on your server to make sure that this directory exists, and then check the permissions.

Thursday, November 24, 2011

My answer to "Which server is best for LampCMS???"

This is my answer to a Question on Support site for LampCMS project


This site runs on Lighttpd server. It's easy to install, easy to configure. Rewrite rules for it are documented in the program distribution. Using lighttpd with php-fpm (fastcgi process manager for php) is close to 10 times more efficient than traditional Apache with mod_php and most importantly running php under php-fpm adds an extra function to the php 'fastcgi_finish_request' which this program uses to implement a 'runLater' functionality.
It allows the web server to close connection to the browser but continue to execute some extra functions after. For example posting your new question to Twitter, Facebook, etc is done after the page is served to uses, so even if it takes an extra second or two, the user will not see that extra delay in page load. It's also used for indexing new post, finding similar topics, updating tags, updating the geo-location of the request for the 'whos online' plugin.

So no matter which server you choose (even Apache can do that), you should always try to set up the php-fpm and run your php as fastcgi under the php-fpm control. The result will be very similar to using an extra thread in Java to do heavy processing without affecting the load time of the page.

Monday, November 21, 2011

My answer to "Popup "Step 2: provide email address""

This is my answer to a Question on Support site for LampCMS project


I looked at your account. It looks like you have not provided an email address for this account. I think you have also created a different account and provided an email address for that other account.

That's why when you try to enter email address for this account it rejects it because the email address is already used by your other account.

So basically this is not a bug, it's just asking you to provide an email address because you joined the site using external authentication like Google Friend connect and have not provided an email address. This is a feature of the site - to let people quickly join with external login systems like Twitter, LinkedIn, but then also ask for an email address.

My answer to "Translation tools"

This is my answer to a Question on Support site for LampCMS project


This maybe useful, especially if you use Eclipse
http://www.slideshare.net/guesta950cdd8d/lets-localize-your-plugins

My answer to "Error in profile page"

This is my answer to a Question on Support site for LampCMS project


It's fixed now. What happened is that I redesigned a templating engine, basically improved it alot. Now the templating engine has 2 base classes "Fast" and "Simple", Simple extending Fast.

The "Fast" template has ordered placeholders - in the format that works with sprintf() function, which basically has placeholders like %1$s, %2$s, etc - in order, and each placeholder can appear more than once in the template if necessary. This template uses vsprintf() function of php to render the template, which is very fast.

The "Simple" template has named placeholders like {some_name}, {something_else}, etc. This type of template is alot easier to create and edit but it's 20% slower to render. Basically any template that being used inside the loop - like to render a list of comments or a list of answers, etc should extend "Fast" template, but templates that used only once on page like to render some block on the page can extend "Simple" template.

Anyway, now I uploaded new templates to go with the new templating engine and everything works again.

Also in debug mode the templating engine automatically adds html comment blocks to <!-- begin sometemplate --> and <!-- // end sometemplate --> and also comments before and after the template loop. This makes it very easy to debug your template design by just viewing the source html of the page.

These comments are not added in production (non-debug mode), so you don't worry about extra overhead for your production site.

I also plan to release this templating engine as a stand-alone project, calling it "Fast and Simple" php templates.

Sunday, November 20, 2011

My answer to "mongodb collections choice question"

This is my answer to a Question on Support site for LampCMS project


There is no such thing as one thread here. Both Questions and Answers can contain comments. Comments are stored as nested arrays. So QUESTIONS and ANSWERS collections are very similar in structure but they are not exactly the same. For example the QUESTION has a concept of being "unanswered" and also can have the "best answer", while ANSWER does not have these properties.

Also if a question contains so many answers that it requires a pagination, it is then easier to select paginated results from dedicated ANSWERS collection rather than using extra condition to only select answers from a single collection and also paginate results on top of that.

Also sorting questions by recent, popular, unanswered, active is easier when dealing with a dedicated collection - QUESTIONS rather than adding extra condition + sorting condition. It just makes some sorting and pagination operations more efficient.

Same thing when paginating the main page (home page, for example), it's a lot easier and also more efficient when you work with just one collection - QUESTIONS, you just pass the pagination conditions to one collections and get the results.

Also in the long run when you have millions and maybe tens of millions of questions and answers it may be more easier to scale, for example you can store questions and answers on separate servers at some point.

I am sure it is possible to store all in one collection, even questions, answers and comments. But I am glad I chose the separate collections approach, I think it makes the program faster, also easier to work with and also be ready to better handle situation where a site grows to tens of millions of questions/answers.

Thursday, November 17, 2011

My answer to "Fatal error: Method Lampcms\Controllers\Viewquestions::__toString() must not throw an exception"

This is my answer to a Question on Support site for LampCMS project


Thank you for reporting this bug. Yes, it was error that I overlooked after I refactored - remaned and moved many classes to organize them better but I forgot to update couple of files with new namespaces.

I just uploaded the corrected version to github. Please download the newest version and try it.

Let me know if there are still some errors.

Tuesday, November 15, 2011

My answer to "Mongo extension is not installed"

This is my answer to a Question on Support site for LampCMS project


It's possible that extension is installed but not loaded. You need to add it to list of extensions in php.ini
like this:
extension="mongo.so"
and restart the apache (or whatever web server you using)

You may also try to load that extension dynamically, try to add this to your !inc.php - on top of file.

if(!extension_loaded('mongo'){
    dl('mongo.so');
}

Saturday, October 29, 2011

My answer to "German Umlaute transformed to chinese signs :-)"

This is my answer to a Question on Support site for LampCMS project


OK, since you mentioned the error from iconv, I suspected that you may not have mbstring extension on your php. The way it is setup now is that the program uses mbstring to handle utf-8 related functions but then if the server does not have mbstring, it uses iconv as a fallback option.

So basically on this server iconv is never used because we have mbstring, which usually handles multibyte string parsing better.

This is just one the the possible reasons for your errors. Just look in your phpinfo() output as see if you have mbstring enabled.

Wednesday, October 26, 2011

Latest updates to Lampcms now on Github

My Question on Support site for LampCMS project

I recently commited the recent changes to github.
The main changes are: IP to Location module has been completely rewritten to use MongoDB instead of compiled DB file to store IP to Location database.
This means that relying on shared memory extension is no longer required - one less thing to worry about. Since this project requires MongoDB that means that you will be able to use IP to Location lookup guaranteed.

All you have to do is download the GeoIP database from Mixmind.com and make sure it's a .csv version.
I wrote the importer script for it, it's in the root www directory, called geo_import.php

That file has instructions on how to import geo file into your MongoDB.

Once imported the program will use the new classes to lookup location info for your visitors. Lookups are very fast - about 3 milliseconds per lookup and they are done in the shutdown function, after the page has been served to the user, so even these extra 3ms are not added to end-user browsing experience.

Another change is the addition of the "Whos online" module. This module is activated by default. To turn it off comment out the online module in the [OBSERVERS] section of !config.ini

What this module does is stores the data about the visitors browsing your site - it records user info, the url on your website that they are on currently, the ip, the resolved Geo Location based on IP, which usually includes longitude and latitude, country name, and sometimes city (also states are for US and Canada only)

This module only records the data, it also deletes records older than 24 hours so that the ONLINE collection does not grow too big and lookups will always be very fast.

There are 2 separate collections actually - ONLINE keeps track of logged in users and GUESTS keeps track of non-logged in users just browsing your site. For non-logged in users ip address is used as unique id

This module only records the user data, there is currently no functionality to display the "who's online" details on the site.

I'm working on this next, there will be an option to add a block with stats on number of guests and users currently online, also whole page will be available to show details on who is doing what on the site currentlly and later I want to add option to put all visitors on google map.

Also it will be possible to add small blocks of info of who is currently reading "this" question or "this" tag.

And also it will be easy to add small icons next to user to indicate if they are currently online or not.

All these is coming next. I also want to add API calls to get the "Whos online" data.

Finally I added a debugging comments to templating engine, so when your site is in debug mode, the html comments are added to beginning and end of each template so you can view the html source code and see the name of each template used for generating a page. This is very useful for when you write your own templates.

These html comments are only added in debug mode, so there is no overhead in production environment at all.

That's all for now. Download the latest version, try it out, let me know if you have any questions.

Click here to post your reply


Thursday, October 20, 2011

My answer to "What's the best way to enhance LampCMS?"

This is my answer to a Question on Support site for LampCMS project


Yes, you can write plugins for pretty much any new feature.
I call them modules. Your custom module is a class that extends the \Lampcms\Observer object
As such it has access to the all important oRegistry object from which you can get your Mongo object, Ini object, and most other important object.

You write your own methods and write your own main() method. main() is called by the Dispatcher and notifies of important events. You can perform actions based on specific event.

Some of the core features of Lampcms are already written as modules, for example FloodCheck, IpFilter as well as Search indexer and EmailNotifier.

Take a look how there are written and you can then write your own plugin the same way. Then add your plugin to the !config.ini file either to [OBSERVERS] section - plugins in that section listen to all events or to [INPUT_FILTERS] section - plugins defined there listen to events like new questions, new answers, comments - all type of user input. If you write plugin like a spam filter then you would put it in the [INPUT_FILTERS] section. It's more efficient since input filters are not notified on all events like observers, only on input events.

I am now working on the new module "Who's online" and I'm writing it as a module.

Wednesday, October 19, 2011

My answer to "cc-wiki or LGPL license?"

This is my answer to a Question on Support site for LampCMS project


Content of this website is licenced under cc-wiki. You don't have to add this cc-wiki licence to your own site if you don't want to. This is just something I chose for this support forum, which basically allows the contents of posts on this forum to be re-published as long as they follow cc-wiki license.


The program itself is licensed under LGPL.

Saturday, October 8, 2011

Delays in new updates

My Question on Support site for LampCMS project

Just want to let you all know that I have several new features in the pipeline. The new MongoDB-only GeoIP class - no more use of shmop extension since it has been causing problems for some users. Also A lookup of a single IP address to map to a location takes about 3 milliseconds on my Windows PC running MongoDB. I think on a decent Linux server it will be even faster. All IP to Location lookups are done in post process mode. This means the lookup and storing the location data is done after the page has been served to the user and browser connection closed. I also wrote an import script to import the CSV file from MaxMind.com into MongoDB. Import takes 5-10 minutes to complete - there are over 4 million records inserted one by one and also 4 indexes are created.

Second feature - "who's online" module - it depends on GeoIP module because the GeoLocation of users online is extracted from IP and stored. That's why I could not release "Who's online" before the new Mongo based GeoIP module is done, and it is only 95% done - needs some finishing refactoring.

Also working on a nice debug toolbar - the Log data from the script will be viewable in the floating div in the debug mode. I've heard that this is how it's done in codeignitor.

Lastly, I am going to add several changes to templating engine making it also use namespaces and to also use directories for templates for better organization. For example, the templates that have to do with answers will be in template/answers, template to view users will be in template/users, etc...
I also added a nice feature to templating engine that in debug mode it adds the html comment section to indicate the start/end of each template and also start/end of each loop inside the template along with the full path to template file. So debugging templates and debugging in general will become alot easier.

Unfortunately I am not going to have any time for probably the next month. We are very busy at work with the launch of a new web portal for a major company and we are all asked to come to work 7 days a week now.

So realistically I will only have time to actually release all there new features in about 6 weeks.

But I'm still reading and replying to your questions every day.

Click here to post your reply


Sunday, September 25, 2011

Who's online module

My Question on Support site for LampCMS project

I am working on the "who's online" module. Finished writing the plugin
that updates the ONLINE records with the user data (user id, username, avatar, what url they are on, title of page and geo ip location)
This update is made after every page request. When you run the php in fastcgi mode controlled by php-fpm (you should, all the cool kids are doing it) this data is written after the page is served to the browser, so there is no noticeable performance hit.

The module is written as a plugin, it can be easily disabled from !config.ini by commenting out just one line.

Next step or steps would be to write a code to actually display a small block with 'who's online' and then we can include that block anywhere on the site.

I will also write the controller to show the list of all users online with links to pages that they are on right now.

It will be a while before all is ready but at least the logic to update the "ONLINE" collection is almost done. I just have to add additional config block to !config.ini to allow admin to also enable tracking "Guests" activity so non-logged in users will also be tracked with geo location and what pages they viewing currently. For performance reasons admin may want to disable guests online tracking.

I hope to have this finished by next weekend.

I am also working on exporting geo ip data into Mongo collections, so no more use of shmop extension will be required - it will be pure Mongo DB based ip to location lookup. I think I got it working even on 32 bit php now, using float as opposed to integer to store larger numbers. The whole GeoIP class will also become much cleaner and probably even more efficient.

I just have to test it more.

Click here to post your reply


Wednesday, September 21, 2011

My answer to "Customize look & feel"

This is my answer to a Question on Support site for LampCMS project


Sure you can. Everything on the site is rendered from templates.
You can edit any of the html template in case you want to add css class to any element. You can then edit the css file.

Thursday, September 15, 2011

My answer to "Registering a user crashes LampCMS: shmop_open(): unable to attach or create shared memory segment"

This is my answer to a Question on Support site for LampCMS project


It looks like this may be a problem for some users. This may very well be caused by Suhosin or by SELinux. I can't be sure, but just a quick search for this issue revealed that it's a common problem with many other projects.

I am now thinking of a couple of possible solutions:

Add config option to !config.inc ENABLE_SHARED_MEMORY and set it to true by default but if you notice problems with this function then setting to false will cause this GEOIP module to not use shared memory and use a slower file-based reads.

A Second possibility is to download the comma-separated GEOIP file from Maxmind.com and then write a script that imports it to MongoDB then just use MongoDB to lookup location by ip address. This will work for everyone. It's very easy to write that import script, but I have to think of how to do this most effeciently, not sure if I want to keep all data in one Mongo collection or use 2 or 3.
What I mean is that maybe store country/state in one location, city in another and ip to locationID in another one. OR can just follow the Mongo NO-Joins way and just store the data in one collection, keep its size fairly large but never have any joins during select. Basically it will require a little more RAM like 300MB but since the old way of storing binary DB in shared memory required at least 50MB, we can just say that the new way will require just 250MB more but will eliminate the need for shared memory and will eliminate the need to cache already resolved ip - to - location records in cache, which is currently stored in Mongo anyway.


I'm working on the solution. It will be done probably over the weekend.

Tuesday, August 30, 2011

My answer to "Is there any way to include images in my post?"

This is my answer to a Question on Support site for LampCMS project


There are some posts with images on this site. I am not sure how they did it. There is no support to actually save an image to the server but there is a way to just include an img tag that points to image hosted somewhere else. 

Monday, August 22, 2011

My answer to "Sitemap Generation."

This is my answer to a Question on Support site for LampCMS project


OK, I figured out the problem. The SiteMap class needs this constructor.
Add it to the SiteMap class and it will work. Keep using the factory method that I posted before.


public function __construct(Registry $o){
                $this->oRegistry = $o;
        }

Sunday, August 21, 2011

My answer to "Lampcms Write API"

This is my answer to a Question on Support site for LampCMS project


TO use WRITE API you need to make POST request to API and also pass basic authentication in headers.

This is how to do this from php using curl: (replace with your own existing question id, replace with your own url, use your own username and password)

$aInputs = array(
'a' => 'addanswer',
'qbody' => 'bbb body of answer here again!', 
'qid' => '631');


try{
        $oCurl = new \Lampcms\Curl();
        $oCurl->setBasicAuth('user2', 'test123');

        $oCurl->getDocument('http://127.0.0.5:88/api/api.php', null, null, array('formVars' => $aInputs, 'redirect' => 4));

        $body = $oCurl->getResponseBody();

        echo ' body: '.$body;

} catch (\Exception $e){

        $info = $oCurl->getCurlInfo();
        echo 'INFO: '.print_r($info, 1);

        if($e instanceof \Lampcms\HttpRedirectException){
                $newUrl = $e->getNewURI();
                get_page($newUrl, $info['url']);
        }
        $s = 'E: '.$e->getMessage().' in '.$e->getFile().' on '.$e->getLine();
        exit($s);
}


My answer to "Sitemap Generation."

This is my answer to a Question on Support site for LampCMS project


Try this:
In sitemap.php change line 49 to this:

$o = \Lampcms\SiteMap::factory($oRegistry);

My answer to "Lampcms Write API"

This is my answer to a Question on Support site for LampCMS project


Sounds like you need import script, not a write API. I agree that it would be very useful to have import scripts to import from other forums like from existing phpbb or vbulletin or any other type of forum.

If anyone is interested in import scripts then let's start a separate discussion. I will need sample database dumps so I can at least start working on those scripts.

As for Write API - I agree that there is not much documentation at this time but you can ask specific question and I will answer it.

Read and write APIs are actually fully functional and support basic authentication (username and password in http headers).

Sunday, August 14, 2011

My answer to "Do you recommend any specific host?"

This is my answer to a Question on Support site for LampCMS project


I don't recommend any hosts. That's because I don't know any hosts other then my current host.

Basically it does not matter what host it is. The program does not care about it. It just needs php 5.3+ and MongoDB and optionally MySQL.

I always recommend to get a dedicated server where you have full control of it and can install MongoDB, php and php mongodb extension yourself. It's does not matter what host. I am looking for a new host myself. I am looking for an inexpensive server with 2 hard drives and 8 Gigs of ram and CentOS as operating system. That's because I have experience with CentOS. CPU speed is not very important to me.Any Linux flavor is fine, it runs on Windows too. I actually developing this program on Windows 7 at home.

One thing is important - the operating system must be 64 bit so that you can use 64-bit MongoDB version. 32-bit MongoDB has severe limitations as far as maximum size of repository.

You don't need 8Gigs normally, I just expect to host several instances of this program on it, different Q&A sites.



Wednesday, August 10, 2011

Another update, more translations in XLIFF file

My Question on Support site for LampCMS project

Just pushed another update to github

Fixed a bug that prevented new registrations. It had to do with the new translation module. It works now.

Also added more translation strings to the russian translations file. It's in /translations/messages.ru.xlf
It now contains 92 translated strings.
This file should be used as template for translating this site into any other language or other locale.

All you have to do is copy that file to messages.fr.xlf (if you translating into French for example), then just replace all russian strings with French translations - keep the original English strings unchanged.

I think there are about 70 more strings left to translate, including all messages that are sent by email like after the registration, after the password changed, etc.

By the way, translation objects are cached for best performance. So if you add or update the translation .xlf file you need to clear cache. I just added the new controller for that.

If you logged in as administrator you will see a new link "Clear Cache" in "Settings" Just click on it and it will remove all data from cache. This is safe to do and not a big deal, new files will be re-generated and cached as needed.

One extra bonus is that now the ACL object (access control) is also cached and it usually saves about 5-10 milliseconds because it's no longer required to read acl.ini file to generate the ACL object. If you added new permissions or edit acl.ini file you will also need to clear cache.

My goal is of cause to have all strings on the site to be accessed via Translator object, no hard-coded strings should be left on the site.

Anyways, you can get to latest from github as usual.

I'm not planning any more major features, maybe only one more - "whose online" feature, you know, to show whos' currently online and possibly what they are doing - like reading this question, viewing tags, asking question and stuff like that.

Click here to post your reply


Sunday, August 7, 2011

My answer to "Is there any way to include images in my post?"

This is my answer to a Question on Support site for LampCMS project


There are some posts with images on this site. I am not sure how they did it. There is no support to actually save an image to the server but there is a way to just include an img tag that points to image hosted somewhere else. 

Wednesday, August 3, 2011

Translation/Locale Xliff based module is done

My Question on Support site for LampCMS project

Hello!
I know it has been a long time since the last post. I am very busy these days and only have several hours a week to work on this project.

I finally finished the Translation module for this site. Translation module is done using Xliff standard. I'm sure you can Google it if you don't know what it is.

The code is in the latest commit on github

So far I have translated 52 strings (there has gotto be at least as many left to translate) into Russian language.
I don't know any other languages and even my Russian is rusty.

You can test it by selecting Russian from the drop-down menu at the bottom of this site.

Anyway, the Russian translations file is a good example of how you can translate this site into any other language.

You need to just copy the file from /translations/messages.ru.xlf into your own language and save the new file as /translations/messages.fr.xlf (if you going to be using French)

You can also use Locale-specific translations, for example messages.en_GB.xlf

Remember that .xlf files are xml files and must be a valid xml.

If you want to contribute your own translations just send me a copy of your own .xlf translation file.

To add more language options to your site add more locale choices to your config.ini file
There is now a [LOCALES] section in it.

Add something like this:

[LOCALES]
en_US = "English (United States)"
en_GB = "English (United Kingdom)"
fr_FR = "French"
fr_CA = "French (Canadian)"
de = "German"
es = "Spanish (Spain)"
ru_RU = "Russian"

These will become the choices in the drop-down menu at the bottom of the pages.

Click here to post your reply


Friday, July 29, 2011

My answer to "Is there any way to include images in my post?"

This is my answer to a Question on Support site for LampCMS project


There are some posts with images on this site. I am not sure how they did it. There is no support to actually save an image to the server but there is a way to just include an img tag that points to image hosted somewhere else. 

Thursday, July 7, 2011

My answer to "Is there any way to include images in my post?"

This is my answer to a Question on Support site for LampCMS project


There are some posts with images on this site. I am not sure how they did it. There is no support to actually save an image to the server but there is a way to just include an img tag that points to image hosted somewhere else. 

Thursday, June 30, 2011

Internationalization for LampCMS using XLIFF

My Question on Support site for LampCMS project

I was researching the topic of Internationalization and was considering different solutions.
I was more inclined to store translation strings right in the Mongo Database.

But then after looking at what other projects are using I came across something interesting. Symfony2 uses XLIFF as preferred method to store translated strings. So I looked at that XLIFF format, and I really like it. At first it looked like it would be complicated for users to create their xml files. But then I found that there are several GUI editors for XLIFF files. One of them is a plugin for Eclipse. I use Eclipse all the time anyway, that's my preferred IDE.

There is also a web-based program that allows you to setup a translation project, define desired languages and let volunteers to contribute translations and at the end it creates valid XLIFF flies.

I think it's really cool. So am thinking now if to use Symfony's existing Translator class or to write my own which will be more lightweight (Symfony is great but as always it can do alot more that I need for this project and most importantly it does not have one feature I really like to see). I will try to get in touch with Symfony developers and see if that can add that extra small feature I want. If it does not work out then I'll write my own Translator class.

Click here to post your reply


Tuesday, June 28, 2011

My answer to "Is there any way to include images in my post?"

This is my answer to a Question on Support site for LampCMS project


There are some posts with images on this site. I am not sure how they did it. There is no support to actually save an image to the server but there is a way to just include an img tag that points to image hosted somewhere else. 

Sunday, June 26, 2011

Added LinkedIn API Integration

My Question on Support site for LampCMS project

I am finished with the LinkedINAPI module.
It's done and pushed to github.

It's now possible to add "Login with LinkedIn" button to the list of existing buttons.
Also when posting Question or Answer there is an option to also post to LinkedIn. The link to your Question or Answer will then be sent to LinkedIn and will be visible by people on your network on LinkedIn.

This is similar to "Sharing" on Twitter.

As with other social sites it's also possible to add LinkedIn to your existing account from the Viewing your profile page while logged in to site.

Also if you check the "Post to LInkedIn" checkbox on the "Ask" or "Answer" form and your account is not connected to LinkedIn, the small window will popup starting the "Connect to LinkedIn" process.

The new section [LINKEDIN] is added to the !config.ini.dist (which you rename to !config.ini)
Instructions on how to get your LinkedInAPI key are in that section.

Click here to post your reply


Sunday, June 19, 2011

My answer to "Removing Copyright Message"

This is my answer to a Question on Support site for LampCMS project


The free version of Lampcms will always have this attribution requirement. The commercial license will be available when the program is ready for stable release version 1.0. Commercial license will not have any such attribution requirements.

At least one more important feature has to be added before version 1.0 can be released - I18N module. It will take probably one more month before everything is ready, probably more like 2-3 months.

Friday, June 17, 2011

Working on LinkedIn integration

My Question on Support site for LampCMS project

Just a heads up. I am working on "Login with LinkedIN" and also a way to connect "LinkedIn" account to your existing Lampcms account.

It will be very similar to Signin with Twitter. You will be able to also post links to your questions/Answers to your LinkedIn as an "Update"

It will be ready in a few days. The "Signin with LInkedIn" is almost done.

Click here to post your reply


Thursday, June 16, 2011

My answer to "Application details don't register"

This is my answer to a Question on Support site for LampCMS project


I found the bug and fixed it. Please try again on this site.

Lampcms Write API

My Question on Support site for LampCMS project

I said before that OAuth2 (or Oauth1) based API will not be free. This is still true.
But I also decided to still write a write API, based on Basic Auth. Basic Auth is a simple authentication where username and password are sent in request headers. This is the old standard. When Twitter API first came out it was based on Basic Auth, then for some time it was still available even after they released OAuth api, then finally they discontinued it.

Basic Auth in not secure but can still be OK if used with https urls.

Some (maybe even many) APIs out there still support Basic Auth, for example github API has such support.

Anyway, I added the support for Basic Auth and wrote 2 write API controllers: addquestion and addanswer

I am still testing the addanswer but addquestion already works.

This all means that you can start writing apps for Lampcms, for example maybe an Android app or web app.
More write API controllers will be added soon, like retag, edit, addcomment, vote, acceptanswer, delete, flag, close

You should ask questions here if you need more details on how to write apps for Lampcms and how to use API in general.

Click here to post your reply


My answer to "MySQL, why not Sqlite3?"

This is my answer to a Question on Support site for LampCMS project


It will be easy to add other types of databases. MySQL is used only for the search feature. Ideally no database will be needed at all when we start using real search engine like Lucene or Sphinx.

If you want to write sqlite plugin then you need to implement 2 interfaces: Search and Indexer
Then edit SearchFactory class to return your own objects that implement these 2.

The class for creating tables if tables don't exists is just a helper class specifically for mysql. You are not required to implement it but then you will be required to pre-create all your SQLite tables in advance. I prefer when there is that helper class that detects that table does not exist and creates it.

Later I should probably refactory this a little so that every search provider is in its own namespace, for example
\Lampcms\Modules\Search\Mysql\Indexer.php and \Lampcms\Modules\Search\Mysql\Search.php

Then it will be easy to define your prefered search provider in !config.ini by just defining the name of search provider.

My answer to "Application details don't register"

This is my answer to a Question on Support site for LampCMS project


It will be easy to add other types of databases. MySQL is used only for the search feature. Ideally no database will be needed at all when we start using real search engine like Lucene or Sphinx.

If you want to write sqlite plugin then you need to implement 2 interfaces: Search and Indexer
Then edit SearchFactory class to return your own objects that implement these 2.

The class for creating tables if tables don't exists is just a helper class specifically for mysql. You are not required to implement it but then you will be required to pre-create all your SQLite tables in advance. I prefer when there is that helper class that detects that table does not exist and creates it.

Later I should probably refactory this a little so that every search provider is in its own namespace, for example
\Lampcms\Modules\Search\Mysql\Indexer.php and \Lampcms\Modules\Search\Mysql\Search.php

Then it will be easy to define your prefered search provider in !config.ini by just defining the name of search provider.

Monday, June 13, 2011

My answer to "Big improvement to comments system - now comments can have replies!"

This is my answer to a Question on Support site for LampCMS project


Everything looked good, I also updated the Email Notifier script to notify original commentor when someone replies to their comment.
I pushed all the updates to github today, you can try it now.

Sunday, June 12, 2011

Big improvement to comments system - now comments can have replies!

My Question on Support site for LampCMS project

This is a pretty big update to the comments system.
Here is the deal: Often a comment is a reply to another comment. It's not easy to keep track of these replies.
On most other site like StackOverflow for example, the best one can do is to include the @user in the beginning
of a comment to indicate that this is a reply.

But this only tells that it's a reply to a comment by @userA. It is not very helpful when userA made more than one comment. How do you know which one of these comments this reply is referring to?

I thought I can do better. Here is goes: Now every comment has a "reply" link. Want to reply to a comment - just use that magic link. No need to manually type @userA - the system will figure out that this is a reply to @userA and more importantly which one of @userA comments

Then when looking at comments all the replies will automatically include @user - and these are underscored with a dashed line.

Now the best part - when you mouse over these @user labels - the comment for which this is a reply will become highlighted - you in case instantly see the message for this this is a reply. You can even click on that @user label in which case BOTH - the original and this reply are highlighted. Clicking it again will toggle the highlighing on/off

And now I'm going to post a simple comment and a reply, and you are welcome to also post replies to comments and just test it out. If this works well, I'll push it to github soon.

I don't think you'll find this feature anywhere else because I thought of it myself. I think it's pretty useful addition.

Click here to post your reply


Friday, June 10, 2011

My answer to "Dmitri: is this agile development? do you have your idea / plan documents?"

This is my answer to a Question on Support site for LampCMS project


One more programming tip I can share, but this is a top secret trick, dont tell anyone.

Sometimes I just create an new blank php file, give it the name of class it's going to be, then just write some comments in the comments block describing what it's going to do, including as much details as possible and then just save it and it will just sit there for awhile.
I may even include a few methods with no body, just comment blocks.

For example

protected function main(){
        $this->getInput()
        ->parseData()
        ->validate()
        ->saveData()
        ->updateUser()
        ->sendEmails();
}


This could be all I need to later take it from there. This is actually the important part, the actual methods can be written later but the main() methods I have to write as I think about the steps involved in this one feature. This is called a top-down design. This may be a true secret to being a good programmer. This is certainly what separates a good programmer from a beginner. Beginners don't do a top-down design, they tend to do the opposite - sometimes refereed to as bottom-up design, which is the wrong way of doing things

A little blank php file, not doing anything but waiting for me to implement it when I get to it.

My answer to "Dmitri: is this agile development? do you have your idea / plan documents?"

This is my answer to a Question on Support site for LampCMS project


Once I wrote the base classes and basically wrote the framework, adding new features is not that hard, actually quite fast. It probably took me about 6 months or so before I even released the first commit to github, but it goes much faster now that all the base classes are solid and "bulllet-proof", I mean bug-free and have test cases.

Also abandoning MySQL and going with Mongo resulted in much faster development, and also alot of unpleasant parts of defining new tables and modifying existing tables and thinking of complex table joins are gone.

Yes, I did have all written down in a simple text file, like a todo list.

Also when I have another idea I now adding it to github issue tracker as a "todo" item, sometimes even including some implementation details. Often when I think of some new feature I also think of how this feature is going to be done, what classes, what database model has to be added. I now if I don't write it down I will forget all the details.

So right now there are a few things on the "todo" list and I don't really want to even adding new ideas before at least some of the "todo" items are completed.

Important items now are "Internationalization" class. I am thinking of the best way to implement it right now.

Also want to add option the "reply" to comment so that it will be clear that a comment is a reply to @user
On StackOverflow you have to explicitely type @user when you replying. I want to simple add a "reply" link and then it will automatically add the @user and maybe even visually indicate that comment B is a reply to comment A

At the same time I am not in the process of writing the API. Most of read API is already done. Next I want to start writing OAuth2 based write API. I've never done this before, so it may not be as fast.

It's perfectly fine for me to switch tasks and just write the comments reply feature for now and then come back to OAuth API thing. I find this task switching is easier on my brain sometimes.


I know there are many more features I want to add, but I also see that the "todo" features list is not infinite. I pretty much know what else has to be done before I can call this a finished program.

These other things are "messaging system" that would include sending system and private user-to-user messages and also a custom SESSION storage class so that a large site that has multiple front-end servers can store session data somewhere on a dedicated server. Also SESSION class will make it easy to show "who's online" and "what they are doing now"

Agile is slightly different. TDD is also different. I mean, I do write test cases but usually not before the classes. In TDD you write test case first, then write code untill it passes your test. I don't do this yet, maybe in the future I will. I don't have any plans to use UnitTests for the documentation. This is a whole other pattern and I don't really like it. I like to just add descriptive comments to all my classes and methods. This is then easy for new developers and also for me to go back and read my own documentation in case I forget what I was thinking at the time I wrote something.

Lampcms REST API update

My Question on Support site for LampCMS project

Hello!
Just want to share some progress of the LampCMS API work:

Any good API must have a way for developers to quickly register their APP and get a unique API KEY.

I have added this feature. This is how it works: most api calls can be made without the API KEY but the daily rate limit will be low without the key. With the valid API KEY the daily limit is much higher. All these limits are configures from !config.ini

So this is how it works: If you want to add API to your Lampcms powered site you need to tell developers how to register their app. All you do is point them to /viewapps/ url
If use does not have any apps yet, then user is redirected to the form to create new app, otherwise user sees the list of all registered apps and can view and edit any app.

You are welcome to try it here http://support.lampcms.com/viewapps/

Once you have the api key you just add &apikey=somekey to all the API requests

For example: http://support.lampcms.com/api/api.php?a=questions&tags=feature&starttime=1306360958&apikey=yourkey

Replace "youkey" with your new valid key or you will get an error, just as you should in case of invalid api key

Several api controllers are ready. Controllers are identiried by the value of the 'a' param which stands for "action"

So in previous example url the "a" is "Questions"

Other controllers are "users" - get info on any user(s) by passing comma-separated values of "uids" param
You can also just call /api/api.php?a=users with no params to get all users and can user pageID and limit params to paginate results. Results can also be sorted using sort= and dir=
for example sort=i_rep&dir=desc to sort by reputation in descending order

Another controllers:


"tags" to get tags data,

"relatedtags" to get related tags - pass tag=sometag to get related data of "sometag"

"usertags" to get tags user's active tags. Pass userID in uid param

"isfollowing" to check if user identified by uid is following another user (or tag or question) identified by "val"
For example: /api/api.php?a=isfollowing&uid=3&t=q&val=125
Will return is_following = true if user with id 3
is following question with id 125

For example /api/api.php?a=isfollowing&uid=3&t=u&val=23
Will return is_following = true IF user with id 3 IS FOLLOWING
user with id 23 (false if not following)

I will push all the latest stuff to github soon so you can examine the API controllers for yourself.





Click here to post your reply


Thursday, June 9, 2011

My answer to "This is a multi-browser test for tag auto-compete"

This is my answer to a Question on Support site for LampCMS project


This is strange. What you describing is a buggy behaviour of the orifinal widget.
You can see it on the original widget demo page

http://rgrove.github.com/node-tokeninput/examples/example-autocomplete.html

(try apple, banana, cherry)

But since I applied a fix the bug is gone, you can select the autosuggested tag with a mouse (or with keyboard) now. I mean it works for me on this site using Chrome on Windows.

I am not sure about other browsers. Maybe it's different on Mac?

Have you reloaded the "Ask" page while holding down the shift key to update browser cache? I mean, is it possible that you were still using the old version of javascript file?

Wednesday, June 8, 2011

Autocomplete for tags added

My Question on Support site for LampCMS project

OK, as per some requests I added the autocomplete for tags
After applying a quick fix to YUI tag widget it works well now.

You can try it here for yourself here, post some question with some existing tags.

If everything works well and there are not more bugs discovered here then I'll push this to github.

Click here to post your reply


Tuesday, June 7, 2011

My answer to "xml markup in editor and (maybe) preview"

This is my answer to a Question on Support site for LampCMS project


There are no limitations. Your users can even use Code highleghter to treat your code snippets as XML, for examle like this: (just highlight code and select "Code style" in the editor


<xsl:template match="/">
        <xsl:element name="plaintext">
                <xsl:apply-templates />
        </xsl:element>
</xsl:template>

My answer to "What attachments beyond images and YouTube are supported?"

This is my answer to a Question on Support site for LampCMS project


Text file? Why don't you just post it as text?
Right now there is no option to attach any files. Even image and youtube options are not really an attachments but simply point to external images or video.

I plan on adding uploader option to the RTE editor but was only going to allow image uploads, have not thought about attachments really.


Monday, June 6, 2011

My answer to "Is there any way to include images in my post?"

This is my answer to a Question on Support site for LampCMS project


There are some posts with images on this site. I am not sure how they did it. There is no support to actually save an image to the server but there is a way to just include an img tag that points to image hosted somewhere else. 

Sunday, June 5, 2011

Lampcms REST API preview

My Question on Support site for LampCMS project

Hello!

Just want to let you know the status of the API work. Here is what I wrote so far:

Wrote base class for the API, wrote a new type of class called Output. This represents the content that is ready to be sent out to the client and it specific to the output format. Concrete classes representing the output format like Json or XML or Jsonp extend this class.

Wrote the Response class - it represents the body and headers ready to be sent to the client (usually browser but any API client really)

Added a new section to !config.ini called [API]

It has these params:
; Maximum results an API can return per page
MAX_RESULTS = 100
; Dalily access limit for not logged in users
DAILY_LIMIT_ANON = 150
; Daily access limit for logged in users
DAILY_LIMIT_APP = 3000
; Daily limit for authenticated user
DAILY_LIMIT_USER = 10000


Using these settings you can completely restring the access to API to only your partner sites by settings DAILY_LIMIT_ANON = 0
It will prevent any access by anonymous clients


API already supports these basic features: makes use of Http response headers and specific HTTP status codes. For example 404 when content not fount or 406 when the value of request parameter is invalid or 500 in case of error in API

Support for custom headers to indicate client's daily rate limit:
X-RateLimit-Limit
X-RateLimit-Remaining
X-RateLimit-Reset
The X-RateLimit-Reset is the timestamp of the next time limit is reset which is usually the beginning of the next day since rate limit is per day.

API currently supports 2 output formats: JSON and JSONP
support for XML can easily be added by just writing the custom OutputXML class. No changes to other classes will be necessary.

API has support for versioning. This is how most good APIs work - when new version of API is released the old ones still work, so your client programs are not broken. You can just pass the v (version id) in request and start using the new version of API. Current version is 1

Currently I wrote 2 API controllers: questions and question

This is how you use it:
Example URL for api is: domain/api/api.php?v=1&a=questions&start_id=5&limit=1&sort=i_votes&dir=desc&alt=json

Here is the explanation of params:

v = version of API, optional, defaults to 1, so for now you can omit it as 1 is the only version

a = "action" Currently completed controllers for "questions" and "question" actions

limit = number of results to return per API call. Think of it as a per-page number on the website.
sort = sort results by this param. For "questions" allowed values are i_votes to sort by votes,
i_lm_ts to sort by "last modified timestamp",
_id to sort by question id,
i_ans to sort by number of answers

dir = direction of sorting. Allowed values are asc for ascending or desc for descending (default)

start_id = show questions with id greated than this (but not including this) id.

max_id = show questions with id less than but not including this id

starttime = unix timestamp in GMT. Show questions posted after this time

tags = space separated tags. Request must be urlencoded so space char should be replaced with %20
show only questions with these tags

match = when tags value is set you can use this param to set to "all" or "any" to match questions with any of the tags or to return questions that must contain all of the tags

uid = userID. Return only questions posted by this user.

type = Return only questions of this type. Allowed values are: "unans" to return only questions with no answers,
"answrd" to return questions with answers by not with "Accepted" answer, "accptd" to return only questions that have an "Accepted" answer.

Extra params: comments=yes to also include comments (by default comments not included)
body=yes to also include full body of question. By default only the "intro", a short text-only version of the first 150 chars of question is included

You can mix these params. For example you can easily get only unanswered questions that have certain tags and posted after certain time.


Question controller.

This controller returns data for one question specified by the qid param.
Example : domain/api/api.php?a=question&qid=5&sort=i_votes&limit=4

Here the limit applies to number of Answers included in response.
For Question controller you can also sort by "accepted", for example: sort=accepted&limit=1
will return only 1 answer that is an "Accepted" answer.


For both questions and question controllers the returned data includes number of total results and the pageID.
Default pageid = 1, you can pass the pageID in request in order to get questions that did not fit in the per-page limit and you know that are more results. In such cases you use the pagination by passing pageID value


You can review the source files for more info. API classes are in /lib/Lampcms/Api/ folder

More API controllers will be released soon: tags, tag, users, user, answers
As well as web controller to register the client and to get clientID.







Click here to post your reply


Saturday, June 4, 2011

My answer to "autocomplete search not including tags"

This is my answer to a Question on Support site for LampCMS project


Yes, definetely I want to add autocomplete for the tags field too. In fact if you dig through my Javascript code you will find that it was actually added but then commented out.
The reason for that is that autocomplete for tags has a bug. I use the YUI tag widget written by one of the YUI team member and when I discovered that bug in autocomplete I contacted him and he basically promised to fix it. So as soon as it's fixed I will add auto complete for tags back.

My answer to "two word tags"

This is my answer to a Question on Support site for LampCMS project


I personally think 2-word tags is not a good idea. I thought about it but I don't remember exact reason why I decided the 2-words tags are bad idea, but at that time there was a good reason for that. One reason is it makes it easier for end-user to enter tags and now worry about forgetting to include comma.

As far as comma separated - yes, currently comma could be used as well as space.
For 2-word tags you would have to use underscore or dashed between words.

The Good thing about tags on this site is that any char is allowed in tags, including UTF-8 char, so even non-English alphabet could be used in tags. This support for Unicode chars in tags is a big deal, this feature is not supported on many other Q&A sites. Also even non-letters like % are allowed in tags, so a 100% would be a valid tag.


Tuesday, May 31, 2011

Beginning work on the Lampcms API

My Question on Support site for LampCMS project

Yes, the Lampcms will have an API. It will be one of the few Open Source Q&A programs that has own API.

Before I beging working on the API, here are some basic outlines of what it will do:

1) Output will be in JSON or XML, but first I'll work on JSON version since it's much simpler. But right from the start the output will be handled by the formatter class. That class will accept raw data (php array or object) and convert it into JSON or XML. So first I'll just write JSON formatter)

2) It will be read/write API. First I'll work on read functions, then on write.

3) Good news and bad news about write API. Good news - it will be OAuth2, which is harder to write for me but easier to use for clients. Bad news - this will be one module which that will not be free. Yes, it will be the first premium module. After all, if you need the write API you are probably building a very interesting project with the purpose of making a profit. So it will not be a big deal to pay for this module. It will not be expensive anyway.

So, here you have it - a free read API with support to get latest questions, unanswered, by tag(s), support for "startwith" and "limit" and "sort by" options

Support to get all answers for a question with "startwith", "limit" and "sort" options and support for include/exclude comments from data

Support for questions for specific user, answers by specific user.

Maybe other options like get following/followers per user, but that will come later.

Any suggestions? Post them here.

Click here to post your reply


Saturday, May 28, 2011

My answer to "Is there any way to include images in my post?"

This is my answer to a Question on Support site for LampCMS project


There are some posts with images on this site. I am not sure how they did it. There is no support to actually save an image to the server but there is a way to just include an img tag that points to image hosted somewhere else. 

Friday, May 27, 2011

My answer to "Is there any way to include images in my post?"

This is my answer to a Question on Support site for LampCMS project


There are some posts with images on this site. I am not sure how they did it. There is no support to actually save an image to the server but there is a way to just include an img tag that points to image hosted somewhere else. 

Thursday, May 26, 2011

My answer to "Working on "Add YouTube" video"

This is my answer to a Question on Support site for LampCMS project


Start testing!
You can use this "Youtube" button now.
Just add some videos to your question or answer and see if it worked.
It still not the 100% polished, but it works with both inserting video and then playing in by replacing thumbnail with actual player.


Confused? More about NextUp: http://youtube-global.blogspot.com/2011/05/introducing-stars-of-future-on-youtube.html Keep up to date on Twitter: http://twitter.com/#!/search/%23YTnextup The YouTube NextUp winners arrive in New York City for Day 1 of the YouTube NextUp Creator Camp!Confused? More about NextUp: http://youtube-global.blogspot.com/2011/05/introducing-stars-of-future-on-youtube.html Keep up to date on Twitter: http://twitter.com/#!/search/%23YTnextup The YouTube NextUp winners arrive in New York City for Day 1 of the YouTube NextUp Creator Camp!

My answer to "A test of Adding YouTube video"

This is my answer to a Question on Support site for LampCMS project



Part of the Google Apps for Education Professional Development Webinar Series. Learn about three LMSs available on the marketplace that integrate with Google Apps. Representatives from Haiku, Class.io, and CourseDirector will demo their products and answers your questions.Part of the Google Apps for Education Professional Development Webinar Series. Learn about three LMSs available on the marketplace that integrate with Google Apps. Representatives from Haiku, Class.io, and CourseDirector will demo their products and answers your questions.







This is a reply with YouTube video in it.

Sunday, May 15, 2011

My answer to "Some questions regarding lampcms"

This is my answer to a Question on Support site for LampCMS project


Lampcms Can handle such load if you do few things right:
1) Do NOT run php as mod_php under apache. Instead run it as fastcgi, and not only that, but also run it under control of php-fpm. php-fpm comes with php 5.3.3 now, so you should just set it up. Make sure you have anough ram on the server and allocate about 250 php processors to run. This will be more than enough because 1000 requests are not really at the same time - php will not take more than 1/4 second per page on Lampcms, some pages are rendered in under 50 millisends here! This is true, even though my server is just plain dual core, 2 hard drives....

You can still use Apache but do not use mod_php, configure it to run php as fastcgi.
Ideally you should use NGINX or Lighttpd server for php - they are capable of handling much higher load.

2) Always use APC. This is one of the easiest thing is the world to do. APC is not even a server - you don't need to start it up, all you have to do is make sure apc extension is enabled in php.ini (and of cause you must have apc extension installed)

3) For best results run MongoDB on separate server, but make sure it's really close to the web server, I mean on the same subnet. This is not necessary, you can perfectly run the MongoDB and web server together on one box, just make sure you have enough RAM. I recommend minimum of 16Gig if you run Mongo and Web server together.

4) Scaling will be done mostly by MongoDB - it supports "horizontal scaling", which basically means "Just add another server" and with minimal or even no downtime. MongoDB will take care of it, you need to know how to do this of cause. You can learn more on MongoDB site and on their discussion list.

You can also scale by adding extra web server. One of the easiest things to do is to have dedicated server for images, JavaScript and css files. LampCMS supports this and even has config options in !config.ini to define urls of Image and CSS servers.

For serving static files Apache is preferred choice is it has excellent in-memory cache module, which you should always use for static files.

If you need to add more web servers then there are ways to do that too. There are some common time-tested ways to do this like round robin DNS. Just install copies on Lampcms scripts on several servers, point them to the same MongoDB database or cluster of databases and you should be able to handle millions of visitors a day.


I recommend you start with just 2 servers: one web server and one database server. Put as much ram on your DB server and more importantly make sure you can add more RAM later. Start with 16Gigs of ram and have room to expand it like 4 times just in case you will even need it. 16Gigs should be enough for start.

Make sure hard disks are fast. RAID 10 is the best choice.

Web server does not need to be super fast, 2 hard drives - one for system files, one where the program is. If you like logging then it's best to log to dedicated disk, so 3rd disk for that.

If you sending out lots of emails then you may need another server as email server. You may also use some type of messaging system like ActiveMQ to send mail jobs to mail server. LampCMS has EventDispatcher, so you can just write simple php class that listens to events that need to send out mass emails then use messaging like ActiveMQ (php has libraries for it) and then just post messages to ActiveMQ server. All these will be done after the page renders, so these things do not add to page load at all. You need to use fastcgi under control on php-fpm for that. I already said this like 100 times on this forum - use php-fpm and you'll have Java-like performance on php.





My answer to "Thanks and some feature requests"

This is my answer to a Question on Support site for LampCMS project


Thanks.
This site already has the "Reputation" system just like on StackOverflow. You do earn points for votes and for w hen someone selects your answer.

You also earn points for posting your Q and A to Twitter, Facebook. Tubmlr, Blogger.

You also gain certain extra permissions for reaching certain score. This is all configurable. So the Points system is already fully implemeted.

As for badges - no. I am not sure I want this. I mean, what are we a boyscout club? I mean badges are great for when you in boyscout, but seriusly, I have never, ever paid any attention to anyone's badges (including my own) on StackOverflow. What this means to me is that there is a considerable work required to add a feature that I personally totally ignore on other sites.

Badges is just one of those features that I will do if someone sponsors it. I mean, I am open for coding sponsored features - you pay, I code. New code becomes available as feature - for everyone, not just you. Your name and link goes into "sponsors" category. A Win-Win.

As Far as "not as feature rich" as So and So... Take a look at what we already have. I think it has more features than "so and so". Does "so and so" have "Dot folders"? Does "so and so" have indicators of "Questions you follow"?

Does "so and so" have ability to follow tags, follow users and follow questions?

Does "so and so" have feature when words that match your tags are wrapped in <em> tag which can boost SEO for these words?

Does "so and so" have "Sticky thread" feature to keep certain posts on top of list all the time, like an announcement?

Does "so and so" have ability to post question or answer to Twitter, Facebook wall, Tumbl blog and Blogger blog - all at the same time?


Does "so and so" have excellent programming code editor/highter which is much better than one used on StackOverflow?


I am not sure about all other sites but at least one of the sites you mentioned does not have support for UTF-8 Tags - they only allow tags to be in English. On this site tags can be any word in any language - arabic, chinese, even html tags or percent sign can be in tag.

Does "so and so" have ajax based sort in tags and users pages?

Not as feature rich as StackOverflow? Think about it - SO does not even have their own user signup system - you MUST use open ID, there is no way to just create own account on SO. How lame is that?


Yes, this site does not have all the features that all other sites have. We don't have "Favorite" feature where you mark question as favorite - and it's saved to your favorites. But this is going to be added because I like it and I use it on stackoverflow, so it's going to be here too.

Yes, we don't have badges but I explained my position.

We don't have Internationalization yet but it's on a todo list and when I write it it's going to be better than "so and so" sites because I'm am planning to write complete locatization library not just translation. What I mean is not just language selection but locale like en_US, en_UK, etc... The locale also results in formatting date/time differently, formatting decimal points. currency etc.