PHP Classes

File: aksara/Common.php

Recommend this page to a friend!
  Classes of Aby Dahana  >  Aksara  >  aksara/Common.php  >  Download  
File: aksara/Common.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Aksara
A CodeIgniter based API and CRUD generator
Author: By
Last change: Initial commit for update 4.2.8

This commit updates the following changes:
1. String helper: changes in string replacement to display the restricted syntax as special chars;
2. Core: adds the cover on mobile view when the first column of grid data is an image. Rewrite the statement for form validation;
3. Validation: add the missing parameter value that throws error when no parameter given;
4. Refine the mobile view template to add the cover image when the type of first column on the datagrid is an image.
Initial commit for update 4.2.8

This commit changes the following updates:
1. Replace the default session path to file;
2. Add the query builder compatibility for each database driver;
3. Refine the statement of session cleaner module;
4. Rewrite the migration file to use the database forge when creating the foreign key constraint;
5. Remove the default auto increment value for database seeder;
6. Change the default installation to use dummy data;
Initial commit for update 4.2.8

1. Core improvements;
2. Menu generator improvements;
3. Validation for file upload improvements;
4. Adds the failed login attempts blocking with customizable attempt count and blocking time;
5. Login page improvements, removing the login component due to the easy customization;
6. Removing unused JS plugins;
7. Routing machine preparation for maps rendering;
8. Preparing the market addons to be able to auto update the installed modules and themes;
9. Changes for uploader plugin with Aksara custom uploader since the previous version used to be paid version (fileuploader by innostudio);
10. Improve the carousel slideshow CMS that previously missing the order when uploaded file is skipping the first slide;
Initial commit for update 4.2.8

1. Refine addons views;
2. Refine grid view;
3. Refine require.js;
4. Add the capability to reload the page after CRUD action from outside the data table
Initial commit for update 4.2.8

Add the json pretty print for the generated phrases
Initial commit for update 4.2.8

This commit includes many update such like:
1. Capability to install the modules and auto generate the menus and permission (sets from module properties) from module package;
2. Capability to remove junk menus and permission when the related module is uninstalled;
3. Verification during uninstall the active theme, that will throw a notification;
4. Refine the blog module;
5. Restructure the coding style;
6. Correcting the PostgreSQL syntax support.
Initial commit for update 4.2.8

Add the capability to install in SQLSRV, PostgreSQL and SQLite3 engine
Initial commit for update 4.2.8
Redo the phrase format to prevent break the json
Initial commit for update 4.2.8

Files changed:
1. \aksara\Common.php (remove the single quote string replacement);
2. \aksara\laboratory\Core.php (correcting the response for API request);
3. \aksara\laboratory\Template.php (adds the API documentation for administration menu);
4. Adds the required validation for some modules;
5. Adds the API Documentation under the API module;
6. Adds the parameter from the data atribut when using swiperJS;
7. Change the structure of session table.
8. Minor changes for installation page;
9. Minor changes for core modules.
Date: 11 hours ago
Size: 5,689 bytes
 

Contents

Class file image Download
<?php
/**
 * The goal of this file is to allow developers a location
 * where they can overwrite core procedural functions and
 * replace them with their own. This file is loaded during
 * the bootstrap process and is called during the frameworks
 * execution.
 *
 * This can be looked at as a `master helper` file that is
 * loaded early on, and may also contain additional functions
 * that you'd like to use throughout your entire application
 *
 * @link: https://codeigniter4.github.io/CodeIgniter4/
 */

if(! function_exists('aksara'))
{
   
/**
     * Get Aksara variable
     */
   
function aksara($parameter = null)
    {
       
$version = '4.2.8';
       
$modified = filemtime(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Laboratory' . DIRECTORY_SEPARATOR . 'Core.php');
       
        if(
'version' == $parameter)
        {
            return
$version;
        }
        else if(
'built_version' == $parameter)
        {
            return
$version . \CodeIgniter\CodeIgniter::CI_VERSION;
        }
        else if(
'date_modified' == $parameter)
        {
            return
date('F d Y H:i:s', $modified);
        }
       
        return
false;
    }
}

if(!
function_exists('get_setting'))
{
   
/**
     * Get setting variable
     */
   
function get_setting($parameter = null)
    {
       
$model = new \Aksara\Laboratory\Model;
       
        if(
$model->field_exists($parameter, 'app__settings'))
        {
            return
$model->select($parameter)->get_where
           
(
               
'app__settings',
                array
                (
                   
'id' => 1
               
),
               
1
           
)
            ->
row($parameter);
        }
       
        return
false;
    }
}

if(!
function_exists('get_userdata'))
{
   
/**
     * Get user session
     */
   
function get_userdata($key = '')
    {
        if(!
service('session')->get($key) && service('session')->get('user_id'))
        {
           
$model = new \Aksara\Laboratory\Model;
           
$user_id = service('session')->get('user_id');
           
            if(
$model->field_exists($key, 'app__users'))
            {
                return
$model->select
               
(
                   
$key
               
)
                ->
get_where
               
(
                   
'app__users',
                    array
                    (
                       
'user_id' => $user_id
                   
),
                   
1
               
)
                ->
row($key);
            }
           
            return
false;
        }
       
        return
service('session')->get($key);
    }
}

if(!
function_exists('set_userdata'))
{
   
/**
     * Set user session
     */
   
function set_userdata($key = array(), $value = null)
    {
        if(!
is_array($key))
        {
           
$key = array
            (
               
$key => $value
           
);
        }
       
        return
service('session')->set($key);
    }
}

if(!
function_exists('unset_userdata'))
{
    function
unset_userdata($key = array())
    {
        return
service('session')->remove($key);
    }
}

if(!
function_exists('get_languages'))
{
   
/**
     * Get active languages
     */
   
function get_languages()
    {
       
$model = new \Aksara\Laboratory\Model;
       
        return
$model->get_where
       
(
           
'app__languages',
            array
            (
               
'status' => 1
           
)
        )
        ->
result();
    }
}

if(!
function_exists('phrase'))
{
   
/**
     * Get phrase of translation
     */
   
function phrase($phrase = null, $keep_word = false, $check = false)
    {
       
/* make sure the phrase and language is valid */
       
if(!$phrase)
        {
           
/* otherwise, throwback the null result */
           
return false;
        }
       
       
$model = new \Aksara\Laboratory\Model;
       
       
/* keep original phrase as given */
       
$original_phrase = $phrase;
       
       
/* restrict non alphabet phrase */
       
if(!preg_match('/[A-Za-z]/', $phrase))
        {
            return
$phrase;
        }
       
       
/* transform the phrase into safe-string */
       
$phrase = strtolower(preg_replace('!\s+!', '_', trim(preg_replace('/([^0-9a-z])/i', ' ', $phrase))));
       
       
/* get locale by session */
       
$language = get_userdata('language');
       
       
/* check if language session isn't available */
       
if(!$language)
        {
           
$language_id = (get_userdata('language_id') ? get_userdata('language_id') : (get_setting('app_language') > 0 ? get_setting('app_language') : 1));
           
           
$language = $model->select
           
('
                code
            '
)
            ->
get_where
           
(
               
'app__languages',
                array
                (
                   
'id' => $language_id
               
)
            )
            ->
row('code');
        }
       
       
$translation_file = WRITEPATH . 'translations' . DIRECTORY_SEPARATOR . $language . '.json';
       
        if(!
$check && !file_exists($translation_file))
        {
            if(!
is_dir(WRITEPATH . 'translations') && @mkdir(WRITEPATH . 'translations', 0755, true))
            {
               
/* put content into file */
               
file_put_contents($translation_file, json_encode(array()));
            }
            else if(
is_writable(WRITEPATH . 'translations'))
            {
               
/* put content into file */
               
file_put_contents($translation_file, json_encode(array()));
            }
        }
       
       
/* get existing translation */
       
$language = file_get_contents($translation_file);
       
       
/* decode json from translation */
       
$language = json_decode($language, true);
       
       
/* check if language property is valid */
       
if(isset($language[$phrase]))
        {
           
/* throwback the translated phrase */
           
return preg_replace('/"([^<>]*?)"(?=[^>]*?<)/', '&raquo;\1&laquo', str_replace('\'', '&apos;', $language[$phrase]));
        }
        else
        {
           
/* skip put new phrase if check is applied */
           
if($check)
            {
               
/* return formatted phrase */
               
return ucwords(str_replace('_', ' ', $phrase));
            }
           
           
/* set new phrase and push into existing */
           
$language[$phrase] = (!$keep_word ? ucwords(str_replace('_', ' ', $phrase)) : $original_phrase);
           
           
/* sort and humanize the order of phrase */
           
ksort($language);
           
           
/* put new phrase into existing language */
           
if(file_exists($translation_file) && is_writable($translation_file))
            {
               
file_put_contents($translation_file, json_encode($language, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES));
            }
           
           
/* throwback the result */
           
return preg_replace('/"([^<>]*?)"(?=[^>]*?<)/', '&raquo;\1&laquo', str_replace('\'', '&apos;', $language[$phrase]));
        }
    }
}

For more information send a message to info at phpclasses dot org.