Posts

Showing posts from January, 2022

Simple JavaScript clock

Although this code can easily be found on the Internet, we still write a simple JavaScript clock Clock: < div id = " clock " > </ div > < script > function clock ( ) { let date = new Date ( ) , hours = date . getHours ( ) , minutes = date . getMinutes ( ) , seconds = date . getSeconds ( ) ; if ( hours < 10 ) hours = '0' + hours ; if ( minutes < 10 ) minutes = '0' + minutes ; if ( seconds < 10 ) seconds = '0' + seconds ; let time = hours + ':' + minutes + ':' + seconds ; document . getElementById ( 'clock' ) . innerText = time ; setTimeout ( ( ) => { clock ( ) ; } , 1000 ) ; } clock ( ) ; </ script >

Joomla DB Queries

Consider two types of queries into the Joomla database by its own means. The code was written for CMS version 3. Perhaps in the versions below it will also work, but it was not checked. For clarity, the examples will be wrapped in a function. The first is when we need to get multiple values. function getAllCategoryesId ( ) { $db = JFactory : : getDBO ( ) ; $query = "SELECT `category_id` FROM `#__jshopping_categories` WHERE `category_publish` = 1" ; $db - > setQuery ( $query ) ; $categoriesId = $db - > loadObjectList ( ) ; $ids = array ( ) ; foreach ( $categoriesId as $catId ) { array_push ( $ids , $catId - > category_id ) ; } return $ids ; } In this case, we received a list of identifiers of published categories as an array. But there is a situation when we need to get one specific value. For this fit a slightly different design. Also we will wrap everything in a function. function getDescriptionCategory ( ) { ...

Adding fields to the ZOO category

This article is about the ZOO component for Joomla CMS . First of all consider adding a simple text field to the right side of the admin panel category ZOO . 1. Open media/zoo/applications/blog/aplication.xml and after the line < param name = " image " type = " zooimage " label = " Image " description = " Choose a category image. " /> add: < param name = " ourname " type = " text " label = " Our field name " description = " Our tip " /> 2. Output in category template media/zoo/applications/blog/templates/default/category.php <?php echo $this - > category - > getParams ( ) - > get ( 'content.ourname' ) ; ?> ourname is our unique name. You can add a picture field ZOO instead of a text field. Сhange type="text" to type="zooimage". We get src of the picture in the output. Adding fields to the main area of the ZOO category admin panel Wh...

Sending form data to email (PHP)

Let's write a simple form for sending data to email using the PHPmail() function. Our form will also write data to a file on the server. The code is not related to any CMS and can be used anywhere. Code: <?php if ( isset ( $_POST [ 'spam' ] ) && isset ( $_POST [ 'submit' ] ) && ! $_POST [ 'spam' ] ) { //departure date $date = date ( 'd-m-Y H:i' ) ; //the value from the name field is limited to 100 characters $field_name = substr ( htmlspecialchars ( trim ( $_POST [ 'name' ] ) ) , 0 , 100 ) ; //the value of the message field is limited to 1000 characters $field_message = substr ( htmlspecialchars ( trim ( $_POST [ 'message' ] ) ) , 0 , 1000 ) ; $to = "user@example.com" ; //to $subject = "Data from the feedback form" ; //text of the letter $msg = "Name: $field_name \nMessage: $field_message " ; $he...

How to create a custom jQuery plugin

The convenience of the jQuery plugin is that you can use the same code several times for different objects. In this case, copy-paste code is not needed. In addition, you can change the behavior of the plugin with different parameters. To write your jQuery plugin, you need to expand the $.fn object In general, it looks like this: $ . fn . MyPlugin = function ( ) { //plugin code } We write a plugin that will add a paragraph with the class "paragraph" after the selected object by clicking on it. By default we will set the red color of the text of our paragraph. ( $ => { $ . fn . myPlugin = function ( options ) { let settings = $ . extend ( { //set default parameters color : 'red' } , options ) ; //write the logic of our plugin $ ( this ) . on ( 'click' , function ( ) { let par = '<p class="paragraph">An added paragraph</p>' ; ...