Samstag, 20. Februar 2016

Handling vowel mutation with php and databases

If you try to handle vowel mutation in combination with latin an cyrillic letters you it is very annoying to do this with functions like htmlentities or mb_convert_encoding.

For cyrillic letters those functions convert them into the corresponding ACSII-Code. So in databases you will see only plain latin letters and ACSII-Codes. But the result of converting vowel mutation looks strange.

The following exmaple shows how you convert every non latin letter or symbol into the corresponding ASCII-Code, so you can save it to the database and read it out by using html_entity_decode.

 
function convert_for_db($string){
    $for_db = "";
    for ($i = 0; $i < strlen($string); $i++){ 
 if(is_latin_char($string[$i])){
         $for_db .=  $string[$i];
 }
 else{
  $for_db .= to_ascii($string[$i]);
 }
    }
    return $for_db;
}
 
function to_ascii($char){
    $ascii = ord($char);
 return "&#".($ascii).";";
    }
 
function is_latin_char($char){
    $latin_chars = array("a","b","c","d","e","f","g","h","i",
                        "j","k","l","m","n","o","p", "q","r",
                        "s","t","u","v","w","x","y","z");
    return in_array(strtolower($char), $latin_chars);
}

Dienstag, 29. Dezember 2015

Javascript - Hovermenu

Hovermenu is a javascript which provides menubuttons. These buttons typically show an icon. When you move the mouse over a button it will became larger and shows a text.

Have a look at the example on: http://gundermann.bplaced.com/playground/hovermenu/
The examle is implemented with ZURB Foundation.

Usage

Of cause you have to import the javascript into the html file. Also you have to add a div to the body with an specific id. Inside of a script tag you have to add any button with the function addMenu(imagepath, text, additionalClass, link). After this you have to call the menu by showMenu(menuIndex). In the end you have to activate the hover by enableHover(additionalWidth).

Meaning of the parameter

  • imagepath: Path to the image that is shown on the button.
  • text: The text shown when button has hover.
  • additionalClass: An class-attribute of the html-element. You might use it to use different colors.
  • link: The page which is referenced by the menu button.
  • menuIndex: The number of the active menu for the current page. (First number is 0)
  • additionalWidth: The difference in px between the width of the button without hover an with hover.

Download

Hovermenu

Little CMS - phpReports

phpReports is a little Content-Management-System which doesn't need the whole installation and setup-overload like Joomla or Wordpress. So it is perfect if you want to write you webpage by your own code and want to display an handle small reports or notifications to the user.

How does it work?

Think about a container of all of your reports. The framework provides access into this container. It is possible to select a specific report out of the container, or to select all reports by year, or to select all reports you worte. If you successfully include the framework into your website you only have to add new reports to this container, while the container is only a folder on the server. Reports are written in html. There are two files for every report. The first one has the suffix "s". This means "short" and those files describe the short-version of the report you might want to show in an overview. The other file has no suffix an includes the whole report. So in the end you have to create html-files for your reports and paste it into your report-folder.

Nothing works without configuration

But the configuration is straitforward. If you have a look to the files which comes with phpReports you will find a file called Configurator.php. If you open this file you found the things you can configurate:
  • report_dir: The directory/container for your reports
  • image_dir: The directory for the images you use within the reports.
  • report_parameter: The URL-parameter for the report.
  • headline_for_latest_events: The headline for the overview of short-version of reports.
  • event_page: The file which contains the whole content of reports.
  • template_dir: The directory for templates for notifications and other stuff that has not primary to do with reports.
  • report_not_found_temp: The template for the page which is shown if no report was found. Usually you put this template in the template-directory.
That's all.  To use the core of phpReports you don't have to configurate all of these things, but the blue ones.

Embedding of phpReports

To embedd the framework you should read the readme within the github. With this information and the example you should be able to use it.

So have a look at: https://github.com/gundermann/phpReports