From ProgClub
Jump to: navigation, search

Pcphpjs is the ProgClub content management system for the JsPHP project. That's the software that allows you to manage and develop JavaScript functions that emulate PHP functions. It's a new version of phpjs with some planned bug fixes and improvements. For other projects see Projects.



Released, but there's stuff TODO.



Members who have contributed to this project. Newest on top.

All contributors have agreed to the terms of the Contributor License Agreement. This excludes any upstream contributors who tend to have different administrative frameworks.

Upstream contributors:


Copyright 2011-2012, Contributors.


The pcphpjs software is licensed under the New BSD license.

The pcphpjs project is the software than manages the jsphp.com web site. It's a free software content management system for a JavaScript library. The JavaScript library itself is licensed separately under the MIT and GPL licenses. These are the same terms as used by the upstream developers as explained on their license page. For more information about the JavaScript library check out the JsPHP project.

Pcphpjs uses the Doctrine ORM toolkit which is licensed under the LGPL.

Pcphpjs uses the CodeIgniter web-framework which is licensed under the CodeIgniter license.


Source code

The repository can be browsed online:


The latest stable code is publicly available from svn:


Or the latest development version is available for member access:



Development links

phpjs related information

Doctrine related information

CodeIgniter related information

Doctrine with CodeIgniter information

JavaScript testing frameworks

Release notes

Hey everyone. You haven't heard from me for a while, because I've been very busy implementing a web-site in PHP and MySQL. This is the most substantial PHP/MySQL (AKA: LAMP) project that I've ever done, and I did it to research the technology and hone my skills, as this is the technology the Blackbrick will use.

You can see the newly released web-site here:


Basically the site is a Content Management System (CMS) for a JavaScript library that provides the PHP API. This means code written for PHP can be more easily migrated to JavaScript, something I did when I created a JavaScript and PHP implementation of the Blowfish encryption cypher, pccipher:


The jsphp.com web-site has a number of features where I got to try out different technology. I used a number of free software frameworks and toolkits, being:

We're using the following technologies:

The jsphp.com web-site has implemented the following features:

So I've learned how to do all that in PHP, and I'm pretty pleased with my effort. Of course the actual JavaScript library the system has been instituted to manage is itself useful too, and hopefully this tool will end up being the platform for a free software community.

All told the web-site took me about two weeks to create, from nothing at all to version one.


Functional specification

Pcphpjs provides a CMS tool for the management of a free software JavaScript library.

User registration functionality

When a new member wants to register for an account (so that they have access to edit functions and comment on the website etc.) they need to fill in an account request. The account request is recorded in the database and an email is sent to the registering member asking them to confirm their registration. The user receives the email and clicks on a link which provides them with a 'Confirm' button that they can press to confirm that they want to register their account. After the user has confirmed their registration a user account is enabled for them and they are able to login using their account details.


These are the pagination functional requirements. See pagination technicalities for implementation details.

When showing a list of things generally you need to paginate them. I.e. show them one page at a time with the ability to scroll through pages and adjust the page size. To provide pagination:

  1. Provide 'first page', 'previous page', 'next page' and 'last page' controls for the pagination controls.
  2. Show the controls even if they don't do anything. I.e. if the user is on the first page still show the first page control even though it will just reload the current page.
  3. Tell the user what page they're on and how many pages there are.
  4. Show a list of page numbers surrounding the current page. The previous three pages, or as many as there are, the current page, then the next three pages, or as many as there are. In the example below the user is on the first page, so the previous three pages are irrelevant and the next three pages are 2, 3, 4.
  5. When showing pagination status make the controls bold if they are active, except for the first/prev/next/last controls which are never bold.
  6. Allow the user to adjust the page size. Minimum page size is 10, maximum page size is 100. In the example below the user can -10 items per page; +10 items per page; show 10, 20, 50 or 100 items per page; or reload the default number of items per page. (In the example the user has the option to show 'all' items on a single page, but we won't support that, the maximum is 100 items per page.)
  7. Provide the pagination controls before the list and again after the list.
  8. Only load the necessary data (the data for the current page) from the database.
  9. Control the page position/size using URL query string parameters. E.g. for comments pagination /page?comments_page=2&comments_size=20, for widgets pagination /page?widgets_page=2&widgets_size=20.
  10. When the user modifies the page size reset the current page back to page 1.

For example:


At the moment pagination needs to be supported for:

  1. Comments on the comments list.
  2. Comments on 'pages', i.e.: home, demo, download, links, FAQ, contacts, admin reference, license, and terms.
  3. Comments on other facilities: contributors, function view, function edit, function edit code, function edit tests, function edit benchmark, function view version, function edit version, function comments,
  4. Function versions and tests versions on revisions view, function versions, and tests versions.
  5. JsPHP contributors and PHPjs contributors on function contributors.

Note pagination on: categories, functions, dependencies, function links, and function administration will not be supported.

Technical specification

Pcphpjs is implemented in PHP and MySQL using the CodeIgniter and Doctrine frameworks as well as a number of other PHP and JavaScript library components.

User registration technicalities

The user table needs to be modified to handle user 'status' and a 'confirmation_key'. The user status can be one of the following:

0: registered 1: confirmed, active 2: disabled

Only users with status 1 can login (the backend for the login system will need to be updated). Users with status 0 can confirm their registration by providing their 'confirmation_key' in which case their status can be changed to 1. Users with status 2 cannot login or operate on their account. So basically a login requires status=1 and a confirmation requires status=0.

A user registration has a confirmation_key associated with it (see PHP uniqid) that will be used in the registration confirmation link. The following data is collected for a registration request:

The data is accepted and inserted into the database provided that there is no existing user with that username and that values for all fields have been provided. The confirmation_key is set to a new uniqid and the status is set to 0.

An email is then generated and sent to the user's email address asking them to confirm their account creation request. The generated email is from "support@jsphp.com <support@jsphp.com>" and contains the text:

Hi there. Someone, probably you, has requested a user account at jsphp.com.

The requested username is 'jj5' and we have reserved this name for you for two weeks.

To confirm and enable your jsphp.com account please visit the following URL and click 'Confirm'.


John Elliot.

The subject of the email is: "Please confirm 'jj5' account at jsphp.com."

Note: in the above example substitute 'jj5' with the user's username, e.g. 'joe'.

When the user clicks on the account confirmation link they are shown a page that says:

If you would like to confirm the account 'jj5' click the confirm button.
Otherwise no action is required.

When the user clicks confirm the backend checks the user record for the username has a status of '0' and that the correct confirmation_key has been provided, updates the status field to 1, logs the user in (only if their status was 0 and they had the correct confirmation_key, i.e. this only works the first time), and then redirects them to the /user/welcome page (which needs to be created).

The /user/welcome page describes the jsphp.com system to the user and gives them a run down of the features and how to use them.

Pagination technicalities

These are the pagination technical details. See the pagination functional spec for required functionality.

Note: page size is user configurable (within bounds). There are three constants which control the supported page size:

  1. PAGE_SIZE_MIN: the minimum number of items per page. Defaults to 10 for production and 3 for development/testing.
  2. PAGE_SIZE_MAX: the maximum number of items per page. Defaults to 100.
  3. PAGE_SIZE_DEFAULT: the default number of items per page. Defaults to 10 for production and 3 for development/testing.

These constants can be set in the config.php file, however they might not be set. The developer should default them (to production values) if they are unspecified when they are required. E.g.:

if ( ! defined( 'PAGE_SIZE_MIN' ) ) { define( 'PAGE_SIZE_MIN', 10 ); }
if ( ! defined( 'PAGE_SIZE_MAX' ) ) { define( 'PAGE_SIZE_MAX', 100 ); }
if ( ! defined( 'PAGE_SIZE_DEFAULT' ) ) { define( 'PAGE_SIZE_DEFAULT', 10 ); }

Pagination is something that will be applied to many different types of data in many different contexts, so the code should be factored into components that can be reused in various contexts.


Notes for implementers

If you are interested in incorporating this software into your project, here's what you need to know:

TODO: explain how to create and initialize the database; and how to install and configure the application.

Notes for developers

Download the source code

Download the latest source code from svn:

svn co https://www.progclub.org/svn/pcrepo/pcphpjs/trunk/ pcphpjs.web

MySQL configuration

Creating the MySQL user and database

CREATE USER 'jsphp'@'local' IDENTIFIED BY  '***';
GRANT ALL PRIVILEGES ON  `jsphp` . * TO  'jsphp'@'local';

Storing the user credentials

  1. Create a file in your home directory called "login_mysql" containing -
  1. You can also store the root login here
  2. Then run:
chmod 600 login_mysql

Loading the MySQL schema from database export

  1. Login to PHPMyAdmin on your local server
  2. Create a new database and user with privileges according to the instructions under Creating the MySQL user and database
  3. Click the database you created in the list of databases on the top left of the page so that you are 'inside' that database.
  4. When you are 'inside' the database click the 'import' tab at the top of the page
  5. Browse to the database file you would like to import and click "Go" (the default settings should be fine).

 Updating the database

If you know that the database you have imported is an older version, or just as a matter of precaution you may want to run the database update script from the terminal as follows-

sudo apt-get install php5-cli
svn update
cd etc
chmod +x apply-update.sh

Loading the MySQL schema from scratch

(John will document this later)

How to reset the password of a MySQL user account

Using SQL
use mysql;
update user set password=PASSWORD('<new password>') where User='USERNAME';
flush privileges;
Using the phpMyAdmin GUI
  1. Navigate to the privileges tab
  2. Click 'Edit privileges' for the user of choice
  3. Scroll down in the popup window to the reset password section and enter a new password
  4. Click OK

Samba configuration

Sharing your home directory with Samba

Setting the password for a Samba account

Pcphpjs configuration

Checking out pcphpjs trunk from svn into home directory

Proxies directory permissions

After you have configured your database you will have to CHMOD the following directory to allow read/write access for the www-data group-


You can either use the terminal or the linux GUI.

Using the terminal
cd /PROJECT_FOLDER/src/lib/ci2/application/models/Proxies
chmod o+w .
Using the GUI
A final note on the Proxies folder

Not setting these permissions correctly or not setting them at all will most likely cause a server error when trying to navigate to index.php. If you are encountering such an error, checking the permissions of the proxies folder may help.

Navigating to index.php

To navigate to index.php and actually view the working website, navigate to-


Creating config.php and database.php

Creating config.php

TODO: For John to do I think, as I only copy/pasted the file from e-mail.

Editing database.php

Watching the web logs

The servers have bee configured so that when you commit changes to /trunk they are automatically deployed to the test/development system on honesty.progclub.net. This means you can use /trunk and the test system to do development work. If you're doing development work in this way then you might want to watch the web logs, especially the error log, while you're working. Some errors that aren't shown in the browser will be shown in the error log. So to watch the web logs:

ssh you@honesty.progclub.net
cd /var/log/apache2
tail -f www.jsphp.com*.log

Note: in order for this to work for you, you need to be in the adm group on honesty. Ask your friendly administrator to add you by emailing admin@progclub.org and asking them to:

sudo adduser you adm



Things to do, in rough order of priority:


Stuff that's done. Latest stuff on top.

Personal tools
Mailing lists