OSClass First Plugin Tutorial

OSCLASS PLUGIN TUTORIAL
1. Create a new directory in any directory. name it ‘my_firstplugin’.
2. Create a new file in the directory. name it ‘index.php’.
3. open the file and add these lines in it :
/*
Plugin Name: My First Plugin
Short Name: my_firstplugin
Plugin URI: –
Description: A first osclass plugin for tutorial purpopse.
Version: 1.00
Author: Satria
Author URI: –
*/
above is ‘plugin info’
4. to make the plugin installable, add this function : osc_register_plugin. so

/**
* (hook: install) Make installation operations
*         It creates the database schema and sets some preferences.
* @returns void.
*/
function my_firstplugin_install() {

}
osc_register_plugin(osc_plugin_path(__FILE__), ‘my_firstplugin_install’);

then add two hooks to initialize (load/init) the plugin and to uninstall the plugin, respectively :

/**
* (hook: init) Registers scripts and styles.
* @returns void.
*/
function my_firstplugin_load() {

}
osc_add_hook(‘init’, ‘my_firstplugin_load’);

/**
* (hook: uninstall) Make un-installation operations
*         It destroys the database schema and unsets some preferences.
* @returns void.
*/
function my_firstplugin_uninstall() {

}
osc_add_hook(osc_plugin_path(__FILE__) . ‘_uninstall’, ‘my_firstplugin_uninstall’);

5. those are the minimum requirement (install, uninstall and load) to create an osclass plugin. Zip the directory (so it’ll be my_firstplugin.zip) then open the oc-admin page and add the plugin from the zip file.
if there is an error “There was a problem adding the plugin” when installing the plugin then just copy and paste the plugin directory in oc-content/plugins/ directory

6. From admin page, we can install/uninstall and enable/disable our plugin but this plugin dont have any functionality yet. we will add some scripts so we can display the links/menu in admin page to configure the plugin. In the index.php file, add this hook ‘admin_menu’ so it’ll be :
/**
* (hook: admin_menu) Display the admin menu
* @returns html.
*/
function my_firstplugin_admin_menu() {
echo ‘<h3><a href=”#”>My First Plugin</a></h3>
<ul>
<li><a href=”‘ . osc_admin_render_plugin_url(osc_plugin_folder(__FILE__) . ‘/admin/link1.php’) . ‘”>&raquo; ‘ . __(‘Link 1’, ‘my_firstplugin’) . ‘</a><li>
<li><a href=”‘ . osc_admin_render_plugin_url(osc_plugin_folder(__FILE__) . ‘/admin/link2.php’) . ‘”>&raquo; ‘ . __(‘Link 2’, ‘my_firstplugin’) . ‘</a></li>
</ul>’;
}
osc_add_hook(‘admin_menu’, ‘my_firstplugin_admin_menu’);

EDIT : if we have osclass version higher than 320 then we better to edit the above function like this :
/**
* (hook: admin_menu) Display the admin menu
* @returns html.
*/
function my_firstplugin_admin_menu() {
if(osc_version()<320) {
echo ‘<h3><a href=”#”>My First Plugin</a></h3>
<ul>
<li><a href=”‘ . osc_admin_render_plugin_url(osc_plugin_folder(__FILE__) . ‘/admin/link1.php’) . ‘”>&raquo; ‘ . __(‘Link 1’, ‘my_firstplugin’) . ‘</a><li>
<li><a href=”‘ . osc_admin_render_plugin_url(osc_plugin_folder(__FILE__) . ‘/admin/link2.php’) . ‘”>&raquo; ‘ . __(‘Link 2’, ‘my_firstplugin’) . ‘</a></li>
</ul>’;
}else{
osc_add_admin_submenu_divider(‘plugins’, __(‘My First Plugin’, ‘my_firstplugin’), ‘my_firstplugin_divider’, ‘administrator’);
osc_add_admin_submenu_page(‘plugins’, ‘&raquo; ‘.__(‘Link 1’, ‘my_firstplugin’), osc_admin_render_plugin_url(osc_plugin_folder(__FILE__) . ‘/admin/link1.php’), ‘my_firstplugin_link1’, ‘administrator’);
osc_add_admin_submenu_page(‘plugins’, ‘&raquo; ‘.__(‘Link 2’, ‘my_firstplugin’), osc_admin_render_plugin_url(osc_plugin_folder(__FILE__) . ‘/admin/link2.php’), ‘my_firstplugin_link2’, ‘administrator’);
}
}
//osc_add_hook(‘admin_menu’, ‘my_firstplugin_admin_menu’);
if(osc_version()<320) {
osc_add_hook(‘admin_menu’, ‘my_firstplugin_admin_menu’);
} else {
osc_add_hook(‘admin_menu_init’, ‘my_firstplugin_admin_menu’);
}

dont forget to add a new directory ‘admin’ in the plugin. then add two new files in it : link1.php and link2.php. the files will display the html content. you can add any html file in its.

7. Ok. great. then how to add any content on the front page by our plugin? Without any plugin we can add any content in oc-content/themes/your-theme/main.php. ‘your-theme’ is curent activated theme, it could be ‘bender’ (default theme). we can insert any html/php code in main.php file like <p>TEST</p> or <?php echo “Great”; ?>. If we want to make it better, we can include any php/html file and add this code <?php osc_current_web_theme_path(‘your_file.php’) ; ?> dont forget to add the new file your_file.php and fill it with any html/php code.

8. Ok. now we want to connect to database and pull some data to be displayed in the admin page.
in index.php file below the plugin info, add a line :
require_once ‘model/myfirstplugin_model.php’;
then add a new directory ‘model’ and a file ‘myfirstplugin_model.php’ in it.
we want to display all city in a table t_city on link1.php file. so add these lines in myfirstplugin_model.php file :
<?php

/**
* Data Access Object (DAO) for messages.
*    Performs operations on database.
* @author Satria
* @package my_firstplugin
* @subpackage Model
* @since 1.00
*/
class MyFirstPluginModel extends DAO {

function __construct() {
parent::__construct();
}

/**
* Singleton.
*/
private static $instance;

/**
* Singleton constructor.
* @return an MadhouseMessengerDAO object.
*/
public static function newInstance() {
if(!self::$instance instanceof self) {
self::$instance = new self;
}
return self::$instance;
}

/**
* Return table name city
* @return string
*/
public function getTable_City()
{
return DB_TABLE_PREFIX.’t_city’;
}

/**
* Get all city
*
* @return array
*/
public function getAllCity()
{
$this->dao->select();
$this->dao->from( $this->getTable_City() ) ;
$this->dao->orderBy(‘s_name’, ‘ASC’) ;

$results = $this->dao->get();
if( !$results ) {
return array() ;
}

return $results->result();
}
}

then edit link1.php file so it’ll be :

<div id=”settings_form” style=”border: 1px solid #ccc; background: #eee; “>
<div style=”padding: 20px;”>
<div>
<fieldset>
<legend><?php _e(‘My First Plugin Link 1 : All City Name’); ?></legend>
<!–p>
<?php _e(‘Congratulation. This is a link 1 content’, ‘my_firstplugin’); ?>
</p–>
<?php
$city = MyFirstPluginModel::newInstance()->getAllCity();
foreach($city as $c){
echo $c[‘s_name’].'<br>’;
}
?>
<p>
<?php _e(‘Created by Satria Faestha. Osclass version : ‘.osc_version(), ‘my_firstplugin ‘); ?>
</p>
</fieldset>
</div>
</div>
</div>

then open link1.php on admin page. All city name will be displayed on the page.
You can play with the query like just show 5 top city, etc.

9. Now we want to add our own table so when we install the plugin, our table will be created and ready to be used. otherwise if we want to uninstall the plugin, the tables will be deleted.
Add these two sql file in sql directory (create a new directory ‘sql’). they are myfirstplugin.sql and add_data.sql
in myfirstplugin.sql :
CREATE TABLE /*TABLE_PREFIX*/t_my_firstplugin (
pk_i_id INT(2) UNSIGNED NOT NULL AUTO_INCREMENT,
s_name VARCHAR(255),

PRIMARY KEY (pk_i_id)
) ENGINE=InnoDB DEFAULT CHARACTER SET ‘UTF8’ COLLATE ‘UTF8_GENERAL_CI’;

in add_data.sql :
INSERT INTO /*TABLE_PREFIX*/t_my_firstplugin (pk_i_id, s_name) VALUES (1,’Satria Faestha’);
INSERT INTO /*TABLE_PREFIX*/t_my_firstplugin (pk_i_id, s_name) VALUES (2,’Ermillya Roza’);
INSERT INTO /*TABLE_PREFIX*/t_my_firstplugin (pk_i_id, s_name) VALUES (3,’Sarah Almahyrah’);
INSERT INTO /*TABLE_PREFIX*/t_my_firstplugin (pk_i_id, s_name) VALUES (4,’Alim Alhikmah’);

in myfirstplugin_model.php add these lines :
/**
* Import sql file
* @param type $file
*/
public function import($file)
{
$path = osc_plugin_resource($file) ;
$sql = file_get_contents($path);

if(! $this->dao->importSQL($sql) ){
throw new Exception( “Error importSQL::MyFirstPluginModel<br>”.$file ) ;
}
}
/**
* Remove data and tables related to the plugin.
*/
public function uninstall()
{
$this->dao->query(sprintf(‘DROP TABLE ‘.DB_TABLE_PREFIX.’t_my_firstplugin’) ) ;
}

then in index.php file edit these functions :
function my_firstplugin_install() {
MyFirstPluginModel::newInstance()->import(‘my_firstplugin/sql/myfirstplugin.sql’);
MyFirstPluginModel::newInstance()->import(‘my_firstplugin/sql/add_data.sql’);
}
osc_register_plugin(osc_plugin_path(__FILE__), ‘my_firstplugin_install’);

and

function my_firstplugin_uninstall() {
MyFirstPluginModel::newInstance()->uninstall();
}
osc_add_hook(osc_plugin_path(__FILE__) . ‘_uninstall’, ‘my_firstplugin_uninstall’);

then do uninstall (if our plugin still installed) and install the plugin. you can see the new table t_my_firstplugin in our database. you can add new function in the model file to pull the content :
public function getMyFirstPluginData()
{
$this->dao->select();
$this->dao->from( $this->getTable_MyFirstPlugin() ) ;
//$this->dao->orderBy(‘s_name’, ‘ASC’) ;
$this->dao->orderBy(‘pk_i_id’, ‘ASC’) ;

$results = $this->dao->get();
if( !$results ) {
return array() ;
}

return $results->result();
}

then in link2.php file, edit the content so it’ll be :
<div id=”settings_form” style=”border: 1px solid #ccc; background: #eee; “>
<div style=”padding: 20px;”>
<div>
<fieldset>
<legend><?php _e(‘My First Plugin Link 2’); ?></legend>
<p>
<?php
$data = MyFirstPluginModel::newInstance()->getMyFirstPluginData();
foreach($data as $d){
echo $d[‘s_name’].'<br>’;
}
?>
</p>
</fieldset>
</div>
</div>
</div>

10. We also want the data in our table can be added, edited and/or deleted.

Docker Installation

For linux, download from http://docs.docker.com/engine/installation/linux/. For Ubuntu, read and follow the step here.

  1. Check the kernel machine. The kernel should be newer than 3.1. Also docker requires 64-bit Ubuntu.

    My kernel version is 4.4.0-38 (PASS)
  2. Update APT source
    Update system

    Update package information, ensure that APT works with the https method, and that CA certificates are installed.

    Add the new GPG key

    Then Open the /etc/apt/sources.list.d/docker.list file in your favorite editor. If the file doesn’t exist, create it.

    Make sure the file is empty or remove any existing entries. Add this on file for Ubuntu Trusty 14.04 (LTS)

    Save and close the file.
    Update the system

    Purge the old repo if it exists.

    Verify that APT is pulling from the right repository.

    CONT….

Another My Ubuntu 14.04 Installation, Problem and Solutions

When I want to update my system,

I got this error on my terminal

Solution:
For

from “GPG error:The following signatures were invalid: KEYEXPIRED”, It’s safe to IGNORE the GPG error. From this How can I fix a 404 Error when using a PPA or updating my package lists?, I CAN LEARN ABOUT THE PPA, HOW TO HANDLE THE ERROR AND DELETE/REMOVE PPA.
For

from “GPG error: Release: The following signatures were invalid: BADSIG” and How can i rebuild my ubuntu package lists??, It said to backup my current ppa list then do clean update??? BUT I HAVEN’T DONE IT YET!!! BUSY WITH ANOTHER THING

PHP/Apache error??
I got this message when I’m trying to repair the software update (I got my linux package broken in order to make upwork time tracker software working)

I got this error

when trying to access another disk (sdb3).
Solution: Start to windows 10 then restart/shutdown it. It took a few minutes to completely restart/shutdown windows 10. If I didn’t patient enough, the above error would be displayed again when I use ubuntu and try to access another partition. If I dont want to do the above (restart to windows again), I can use a trick from this http://askubuntu.com/questions/462381/cant-mount-ntfs-drive-the-disk-contains-an-unclean-file-system. but i never try it!

Installation of Cinnamon 2.8 Linux Desktop Environment (DE)
I need to install this DE because I see my screen pixel has black horizontal line and it’s growing everyday. I suspected it’s caused by the bottom panel bar of my Gnome classic DE can’t be hidden (auto hide) so the panel always appear and the black  line precisely at the border between the panel and the rest of screen.–> I DECIDED TO NOT INSTALL THIS DE RIGHT NOW, MAY BE SOMEDAY LATER. I FOUND A WAY TO AUTO HIDE THE BOTTOM (AND THE TOP) PANEL OF GNOME BY SELECTING ‘GNOME FLASHBACK (METACITY)’ INSTEAD OF ‘GNOME FLASHBACK (COMPIZ)’ I OFTEN TO USE WHEN I LOG IN MY UBUNTU MACHINE. BASED ON THIS LINK auto-hide bottom panel using classic gnome ?, I CAN USE ‘Alt + right click or Super Key + Alt + right click in an open panel area.’ THEN CLICK ‘Properties’ THEN CHECK ‘Autohide’. DONE!

When I update my system via ‘sudo apt-get update’ or via Software Updater, I got this error:

Solution: (ref: https://chrisjean.com/fix-apt-get-update-the-following-signatures-couldnt-be-verified-because-the-public-key-is-not-available/)
So add the key ’37BBEE3F7AD95B3F’ like this:

 

OSClass Sub Domain Setting

First try to install the newest osclass version. Here I use 3.6.1 version. Install it locally. It works! here is the url : http://localhost/works/osclass361. user and password for the admin page (/oc-admin/) is ‘admin’ and ‘admin’.

Setup the virtualhost

Here is the content

Then enable the website and reload Apache service using below command

Then register the above local site. open

Then type

Then restart apache

Then set the permalink for SEF url in the admin page on Show more -> Settings -> permalinks (http://localhost/works/osclass361/oc-admin/index.php?page=settings&action=permalinks) then Check ‘Enable friendly urls’ then Save Changes! It’ll create .htaccess file

Then modify config.php file. Edit these two lines

to

Test the site on your browser: http://www.osclass361.dev/ or just osclass361.dev/ Here is how it looks osclass361 Because I still have a little listing available, I need to post some of them. NOW it is time to setup the subdomain. I want to use ‘City’ as the subdomain based and use wildcard * to make it simpler. From this article Use categories, countries, regions or cities as subdomains, I’ll follow the guidelines:
1. go to admin Show More -> Settings -> Advanced (http://www.osclass361.dev/oc-admin/index.php?page=settings&action=advanced) then set:

2. Use DNS wildcard

modify from

to

3. Modify virtualhost. use *.osclass361.dev instead of www.osclass361.dev on ServerAlias

4. Restart apache

5. changes on config.php. Modify from

to

6. Add cookies configuration on config.php

7. Modify .htaccess to be like this

8. Test!

9. Open the site with the subdomain (city) like: http://abbeville.osclass361.dev/
AND IT WORKS!!! IT CAN OPEN THE OTHERS PAGES WITH THE SUBDOMAIN BUT I THINK IT NEED TO BE LIMITED WHICH PAGE CAN BE OPENED BY THE SUBDOMAIN FOR EXAMPLE ONLY FOR ITEMS PAGE AND SHOW THE ITEMS FROM THE CITY!
A FEW ERRORS ENCOUNTER:

WHEN TRYING TO ACCESS ANOTHER LINK LIKE http://www.osclass361.dev/user/login. SO IT ONLY CAN OPEN THE HOMEPAGE!
SOLUTION: It happened because I didn’t modify .htaccess file, Modify it like #7 above!
IT’S WORKS NOW BUT SLOW TO OPEN ANYPAGE (WHEN COOKIES IS ALREADY DELETED)!!!

 

Update PPA For PHP, Change PHP CLI Version

BEWARE! THIS WOULD MAKE YOUR LOCALHOST NOT WORKING LIKE WEB APP, PHPMYADMIN, ETC. NEED TO BACKUP YOUR DATA FIRST!

I need to update the PPA for php from ppa:ondrej/php5-5.6 to ppa:ondrej/php because the earlier ppa already deprecated. Here is the step for PPA migration to ppa:ondrej php. Continue reading “Update PPA For PHP, Change PHP CLI Version”

Respect

We hear it a lot – either demanding we get it from others or wanting to believe that we are people whom respect others.

So I decided to look into this

A feeling of deep admiration for someone or something elicited by their abilities, qualities, or achievements.

“the director had a lot of respect for Douglas as an actor”

synonyms: esteem, regard, high regard, high opinion, acclaim, admiration, approbation, approval, appreciation, estimation, favour, popularity, recognition, veneration, awe, reverence, deference, honour, praise, homage

“the respect due to a great artist”

Imagine if when we dealt with each other as employers and leaders, husbands and wives, parents and children, friends and neighbours, if we held people in high regard for their abilities and qualities. If we focused on ‘hey thanks for speaking to me with such grace or helping me out here, your wonderful keeping the babies whilst I go see my friends or your an amazing sister whom always listens to me’

We find it so easy to focus on people’s lack, mistakes and shortcomings.

As Muslims it’s even more important for us to really digest m this and try our best to apply this to our own lives and always look towards people with respect – respect is a doing word: you have to act to show it’

This principle is something I learnt in my psychology and counselling journey – and you will be surprised to see how many lives can become empowered and uplifted just with the application of creating a respectful environment for them when they attend counselling.

Reminder for myself that respect I apply to my clients is something that should be there always

Beautiful reminder Alhamdulilah

Source: startupmuslim