Showing posts with the label PHP

Drupal 8 Media Library with SVG upload

Uploading the media content and maintaining together with reusability was one of the challenges in earlier versions of drupal. Media Library has been included in the Drupal core. It has a better user experience including multiple media types that can be customized based on development requirements. Media Library is a media management tool that enables you to find media that exists in your site and to add new media items. It allows you to search, sort, and create media items with a customizable interface. It can be used to add media items to an entity reference field or embed media into your content via a text editor. To use the media library luxury, Throughout the site we should use the media field. It will help us to collect the media elements as a single point and will be provisioned for us to reuse using the media library. Media type management will be maintaining the list of media types being supported by the media field. We can add the new media type thro

Drupal Content Workflow

In CMS world maintaining the content workflow is very important. When the content editor is updating the content to the page, it always requires review and approval by the content manager. This workflow will define the way, how the content will be published to the end-user on the site. Drupal 8 has a core module to support content authorization workflow. But it doesn’t have the ability to provide the interface to customize the own workflow depending on different organizations. That will be achieved by contribution module called Workflow This will help you establish the transition state between different content types and roles. But the known disadvantage on this module, will not able to edit the published content (Current published state content)

Creating content type tpl file in drupal 7

In Drupal 7, Page.tpl.php will be the default template file for whole site. In top of this, we can customize our template for different content type, individual nodes and front pages. Even we can customize the block template and views templates. In this blog post, i am going to give you small snippet of code for creating template file depends on content type. To create a template file for content type, First step we need to define in template.php file on hook_preprocess_page method. After included in template.php we need to copy the page.tpl.php. Paste in same folder, rename it according to you content type. For example:- My content type name is reviews. My file name should be page--reviews.tpl.php In this file, you can customize your design.

Get node content using node_view and node_load in drupal 7

Drupal 7 has vast functions to manipulate node and its content. Here i have gave you the piece of code to get node content using node id.

How to use DOMDocument in PHP?

DOMDocument is PHP library, which will be used to read, write and manipulate XML and HTML Documents. DOM (Document Object Model) is kind of API to validate the content of XML/ HTML. DOM support different namespaces as well. The above code is demonstrating about DOMDocument usage with sample example. The example will fetch all H2 tags from the content and will form as separate list view. To Discard White Spaces in content

CURL error code 7 in php

Curl is one of most powerful functionality in PHP. It will allow us to communicate with external URL. To use the curl functionality in your code. We must enable PHP curl module in PHP installation. In this post, i could like to explain about curl error code "7". There are some of the criteria to get this error. Due to wrong URL. URL might have some port on postfix. For Example: Solution : To solve this issue, we must remove the port on URL.Your URL must be like

How to setup virtual host in apache2 on ubuntu OS

Virtual host is one of the beautiful option, which is provided by web servers. I have already shared the snacks about XAMPP virtual host creating process. I believe that snacks was tasty and delightful for your coding life. Here, i am sharing another tasty snacks about Apache2 server virtual host, which is default server of most of linux OS. In order to create virtual host in your linux machine with apache2 server. First you have to place your project folder under root directory (/var/www/). Create virtual host file in below location with tags Step 1 : Go to cd /etc/apache2/sites-available/ Step 2 : cp default Step 3 : Open your file with following command sudo gedit Paste the below code into file. <VirtualHost *:80>     ServerAdmin     DocumentRoot /var/www/project-directory/     ServerName         ServerAlias         ErrorLog /var/log/apache2/

Call content type form in custom module with Drupal 7

Here we have realtime syntax to call content type form in drupal 7. It will allow you to call add form of particular content type. To use this code, please add some custom module with menu hook. For menu hook, Have the callback function with below code. You will get the form to submit your values.

Enable default token values in drupal 7

To enable the default token to be display in the drupal site. We have to install separate module to do the same. This module will allow the content type field to enable and replace with particular token. You download the module here . Steps to install Download the module from this location and extract it. Extract folder should be placed in /sites/all/modules folder. Then, Login as administrator in site. In admin menu, Please click on module menu. In the list modules, You will able to see the "Field default token" . Please check the checkbox, which is row of same module. Then, scroll down and click "Save Configurations" . Now, you module will start to work on the same. Please give some default token in text field of content type and check.

Data Encapsulation in PHP

Data Encapsulation is "Encapsulation is a way of storing an object or data as a property within another object, so that the outer object has full control over what how the internal data or object can be accessed." data_encapsulation.php

QR Code generation in php

QR code generating in PHP, that can be used to generate QR Code images using Google Chart API. It was build using Google Chart API Web server to request the generation of a PNG image that represents the QR code graphic for a given information snippet. Currently the class can request the generation of QR codes for information snippets of the following types: bookmark, text, SMS message, phone number, contact information, e-mail message, geo-location, WIFI access, i-appli metadata, or abitrary content-type. The generated QR code image can be returned as a string, served for download, or returned as a URL string. QRCodeClass.php Test.php

Soap using PHP CURL

SOAP Stands SIMPLE OBJECT ACCESS PROTOCOL . Soap is most powerful and secure web service architecture. Soap will have two way communication between different request and responses. It is more secure compare with REST. It has own set of properties to implement the structure of protocol. The below code is for SOAP connection using PHP CURL. soap_client.php soap_request.php

Image resizing in PHP

The post is about image resize using php methods. This will help us to make the image as thumb size on run time. For this method, we need to pass six parameters file, photo_dir (Image directory), thumbs_dir (New image directory), square_size (Optional, by default we mentioned 140px), img_height (Optional, by default we mentioned 140px), img_width (Optional, by default we mentioned 128px).

Create a block using custom module in drupal 7

In this post, we will discuss about creating block using custom module in drupal 7. The main benefit of build a block using custom module is connectable module. This code will act as separate connectable component. In Drupal 6, there is only one hook used for all block operations but now in Drupal 7 there are different functions for different operations of the blocks. This are the hook method provided by drupal 7 for build a block. hook_block_info() hook_block_configure() hook_block_save() hook_block_view() hook_block_list_alter() hook_block_view_alter() hook_block_info_alter() hook_block_view_MODULE_DELTA_alter() Here we will discuss through different steps. Step : 1 We need to create a directory in this path "sites/all/modules". i.e you need to create a new module folder inside drupal directory. Directory name must under-stable and meaningful related to your module purpose. I will named as "customblockmodule" for module directory. We should have thi

Android Push notification using php

Android push notification using php script. This code will act as web service for the android developers make the app to send push notifications. Before using this code, You have to create a project in google console and get the API key for authentication. Also you have send the Device Token of each mobile. You can also get device token in with your mobile client side function. So, we you trying to execute the push notification through web service. Should be pass two parameters API Key and Device Token.

Image editing and saving using canvas in HTML5 with PHP

This document will demonstrate use of canvas for editing image and also we can get as download. Index.html Script.js Save.php Download.php

Export HTML to .CSV in PHP

This script will help you to export HTML content to *.CSV. PHP is one of most powerfull scripting language in Open source. This script was build through PHP script. We split across three files to achieve this functionality. CSS file [To make desgin of HTML table]. PHP file which will list out the DB data from Mysql to PHP. Another PHP file. Which will help you generate *.CSV file. style.css table.php export.php

Import .CSV file in PHP

This code will help you to import the .CSV file data into Database. This code was build in PHP. It is generic class which can use into different purpose. Db.php $con = mysql_connect("hostname","username","password"); mysql_select_db("dbname",$con); Import.php include('db.php'); class ImportComponent { function array_remove_empty($arr){ $narr = array(); while(list($key, $val) = each($arr)){ if (is_array($val)){ $val = array_remove_empty($val); // does the result array contain anything? if (count($val)!=0){ // yes :-) $narr[$key] = $val; } } else { if (trim($val) != ""){ $narr[$key] = $val; } } } unset($arr); return $narr; } function import($file,$uid,$table){ $row = 1; $status = ""; if (($handle = fopen($file, "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { if($row == 1){ foreach

Load different image on page refresh in PHP

In PHP, We can have multiple image can be show on page refresh. ALL the images should have same format.

Creating Dynamic PDF files using HTML and PHP

There always arise a need for converting content from one file format to another one. Some may need to convert some text into HTML and some may need to convert some HTML content to an image format. The main reason for the need to convert from one file format to another is because the target file format is best suited for targeted medium where the content need to be displayed. The targeted medium may be an email, a printed hard copy or a web browser. The text format is best suited for sending emails, as the possibility of the email contents getting corrupted in the transition is much lesser, when compared to the HTML formatted emails. PDF document or a word document would be the best choice for taking a printed hard copy and obviously HTML is best for showing contents in web browsers. Here, we are going to study on converting HTML 2 PDF using PHP. This article is not going to explain on the main logic of how to convert a HTML file to PDF file. That would be a separa