<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Dollar Dev</title>
    <description>The latest articles on Forem by Dollar Dev (@ta_phpwebdev).</description>
    <link>https://forem.com/ta_phpwebdev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1242058%2Fc1230557-d5ad-4afb-b07a-6075b56954b8.jpg</url>
      <title>Forem: Dollar Dev</title>
      <link>https://forem.com/ta_phpwebdev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/ta_phpwebdev"/>
    <language>en</language>
    <item>
      <title>My First Steps to learning Wordpress (connection Accerdible Credential API)</title>
      <dc:creator>Dollar Dev</dc:creator>
      <pubDate>Sun, 28 Jan 2024 23:09:10 +0000</pubDate>
      <link>https://forem.com/ta_phpwebdev/my-first-steps-to-learning-wordpress-connection-accerdible-credential-api-13ki</link>
      <guid>https://forem.com/ta_phpwebdev/my-first-steps-to-learning-wordpress-connection-accerdible-credential-api-13ki</guid>
      <description>&lt;p&gt;I decided to fixate on this historical moment. I finally started learning WordPress from the developer side.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;At the first I did some looking into:&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;1️⃣ Explored &lt;strong&gt;&lt;em&gt;versioning&lt;/em&gt;&lt;/strong&gt;. When I learnt that each version release is themed around one of the jazz musicians, I understand what the popularity of WordPress is all about.&lt;br&gt;
2️⃣ &lt;strong&gt;&lt;em&gt;Download&lt;/em&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;em&gt;install&lt;/em&gt;&lt;/strong&gt; WordPress.&lt;br&gt;
3️⃣ Analyse the &lt;strong&gt;&lt;em&gt;file structure&lt;/em&gt;&lt;/strong&gt;. The most interesting thing to notice is the existence of files with the prefix wp-.&lt;br&gt;
4️⃣ Introduced to the &lt;strong&gt;&lt;em&gt;database&lt;/em&gt;&lt;/strong&gt;. There were not very many tables in WordPress, it took a few minutes to study their contents.&lt;br&gt;
5️⃣ Then I looked at the &lt;strong&gt;&lt;em&gt;documentation&lt;/em&gt;&lt;/strong&gt; a little bit 🧐 &lt;/p&gt;

&lt;p&gt;Next, I decided I was ready for development.&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;To do:&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;1️⃣ Create a template with a registration form (bootstrap).&lt;br&gt;
2️⃣ Enable multi-language on the site and add a second language translation for the form.&lt;br&gt;
3️⃣ Create a plugin to work with Accredible Credential API and with functionality:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;display the &lt;strong&gt;list of badges&lt;/strong&gt; in admin panel;&lt;/li&gt;
&lt;li&gt;after user registration &lt;strong&gt;create a certificate&lt;/strong&gt; in Accredible&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I uploaded the code for my experiments to the &lt;a href="https://github.com/DollarDevTa/wp-accredible" rel="noopener noreferrer"&gt;repository&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Theme with registration form:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F95kie45u7qbxm47nga27.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F95kie45u7qbxm47nga27.png" alt=" " width="753" height="650"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I also added a little bit of validation:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpnnw3unuztvs25jscq5q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpnnw3unuztvs25jscq5q.png" alt=" " width="746" height="796"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Theme code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php
require_once(ABSPATH . WPINC . '/registration.php');
global $wpdb, $user_ID;

$success = false;
$errors = [];

if( $_POST ) {

    $username = $wpdb-&amp;gt;escape($_POST['username']);
    if( username_exists( $username ) ) {
        $errors[] = esc_html__('Username already exists, try another one.');
    }

    $email = $wpdb-&amp;gt;escape($_POST['email']);
    if( email_exists( $email ) ) {
        $errors['email'] = esc_html__('This email is already registered.');
    }

    if(0 !== strcmp($_POST['password'], $_POST['password_confirmation'])){
        $errors['password_confirmation'] = esc_html__('Password mismatch');
    }

    if( empty($errors) ) {
        $password = $_POST['password'];
        $new_user_id = wp_create_user( $username, $password, $email );
        $success = true;
    } else {
        $message = esc_html__('There are errors in completing the form:');
    }
}
?&amp;gt;

&amp;lt;?php get_header(); ?&amp;gt;

&amp;lt;?php if($success){ ?&amp;gt;
&amp;lt;div class="row mt-5"&amp;gt;
    &amp;lt;div class="col"&amp;gt;
        &amp;lt;div class="alert alert-success" role="alert"&amp;gt;
            &amp;lt;?=esc_html__('User registered successfully')?&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;?php } else { ?&amp;gt;
&amp;lt;div class="row mt-5"&amp;gt;
    &amp;lt;div class="col"&amp;gt;
        &amp;lt;?php if(isset( $message )):?&amp;gt;
        &amp;lt;div class="alert alert-danger" role="alert" id="message"&amp;gt;
            &amp;lt;?=$message?&amp;gt;
            &amp;lt;?php foreach( $errors as $error_message ){ ?&amp;gt;
                &amp;lt;br /&amp;gt;&amp;lt;?=$error_message?&amp;gt;
            &amp;lt;?php } ?&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;?php endif;?&amp;gt;
        &amp;lt;form id="wp_signup_form" action="&amp;lt;?php echo $_SERVER['REQUEST_URI']; ?&amp;gt;" method="post" class="needs-validation" novalidate&amp;gt;
            &amp;lt;div class="col-md-4 control-group form-floating mb-4"&amp;gt;
                &amp;lt;input id="username" type="text" name="username" class="form-control" placeholder="User Name" pattern="[0-9a-zA-Z!@#$%^&amp;amp;*\S]*" value="&amp;lt;?= isset( $_POST['username'] ) ? $_POST['username']  : '' ?&amp;gt;" required&amp;gt;
                &amp;lt;label for="username"&amp;gt;&amp;lt;?php echo esc_html__( 'User Name', 'testpage' )?&amp;gt;&amp;lt;/label&amp;gt;
                &amp;lt;span class="error invalid-feedback"&amp;gt;&amp;lt;?=esc_html__('Sorry, you can\'t use spaces in usernames')?&amp;gt;&amp;lt;/span&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;div class="col-md-4 control-group form-floating mb-4"&amp;gt;
                &amp;lt;input id="email" type="text" name="email" class="form-control" pattern="[A-Za-z0-9._+\-']+@[A-Za-z0-9.\-]+\.[A-Za-z]{2,}$" value="&amp;lt;?= isset( $_POST['email'] ) ? $_POST['email']  : '' ?&amp;gt;" placeholder="Email" required&amp;gt;
                &amp;lt;label for="email"&amp;gt;&amp;lt;?php echo esc_html__( 'Email', 'testpage' )?&amp;gt;&amp;lt;/label&amp;gt;
                &amp;lt;span class="error invalid-feedback"&amp;gt;&amp;lt;?=esc_html__('Please enter a valid email.')?&amp;gt;&amp;lt;/span&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;div class="col-md-4 control-group form-floating mb-4"&amp;gt;
                &amp;lt;input id="password" type="password" name="password" pattern="[0-9a-zA-Z!@#$%^&amp;amp;*]{6,}" class="form-control" value="&amp;lt;?= isset( $_POST['password'] ) ? $_POST['password']  : '' ?&amp;gt;" placeholder="Password" required&amp;gt;
                &amp;lt;label for="password"&amp;gt;&amp;lt;?php echo esc_html__( 'Password', 'testpage' )?&amp;gt;&amp;lt;/label&amp;gt;
                &amp;lt;span class="error invalid-feedback"&amp;gt;&amp;lt;?=esc_html__('The password must consist of at least six characters.')?&amp;gt;&amp;lt;/span&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;div class="col-md-4 control-group form-floating mb-4"&amp;gt;
                &amp;lt;input id="password_confirmation" type="password" name="password_confirmation" pattern="[0-9a-zA-Z!@#$%^&amp;amp;*]{6,}" class="form-control" value="&amp;lt;?= isset( $_POST['password_confirmation'] ) ? $_POST['password_confirmation']  : '' ?&amp;gt;" placeholder="Confirm Password" required&amp;gt;
                &amp;lt;label for="password_confirmation"&amp;gt;&amp;lt;?php echo esc_html__( 'Confirm password', 'testpage' )?&amp;gt;&amp;lt;/label&amp;gt;
                &amp;lt;span class="error invalid-feedback"&amp;gt;&amp;lt;?=esc_html__('The password must consist of at least six characters.')?&amp;gt;&amp;lt;/span&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;div class="col-md-4 form-check mt-3 mb-3"&amp;gt;
                &amp;lt;input id="terms" name="terms" class="form-check-input" type="checkbox" required&amp;gt;
                &amp;lt;label class="form-check-label" for="terms"&amp;gt;&amp;lt;?php echo esc_html__( 'Agree to terms and conditions', 'testpage' )?&amp;gt;&amp;lt;/label&amp;gt;
                &amp;lt;span class="error invalid-feedback"&amp;gt;&amp;lt;?=esc_html__('You must agree to the Terms of Use')?&amp;gt;&amp;lt;/span&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;div class="col-12"&amp;gt;
                &amp;lt;button class="btn btn-primary py-2" id="submitbtn" type="button"&amp;gt;&amp;lt;?php echo esc_html__( 'Registration', 'testpage' )?&amp;gt;&amp;lt;/button&amp;gt;
            &amp;lt;/div&amp;gt;
        &amp;lt;/form&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;?php } 
get_footer();
?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I used the same &lt;strong&gt;library&lt;/strong&gt; for connecting to the API that I used for &lt;a href="https://dev.to/ta_phpwebdev/component-accredible-credential-for-joomla-5-part-2-2g54"&gt;Joomla&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I have separated the list in the Admin Panel into a New Menu Item:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj9un8bpjnlor10z3hy7d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj9un8bpjnlor10z3hy7d.png" alt=" " width="800" height="466"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Code for displaying the list:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php
/**
 * Accredible Certificate administration panel
 *
 * @package WordPress
 * @subpackage Administration
 * @since 1.0.0
 */

$title = __( 'Accredible Credentials' );
global $wpdb;
$items = $wpdb-&amp;gt;get_results("SELECT * FROM `wp_accrediblecertificate` order by id desc");

?&amp;gt;
&amp;lt;div class="wrap"&amp;gt;
    &amp;lt;h1 class="wp-heading-inline"&amp;gt;
        &amp;lt;?php echo esc_html( $title ); ?&amp;gt;
    &amp;lt;/h1&amp;gt;

    &amp;lt;div class="row"&amp;gt;
        &amp;lt;div class="col-md-12"&amp;gt;
            &amp;lt;div id="j-main-container" class="j-main-container"&amp;gt;
                &amp;lt;?php if (empty($items)) : ?&amp;gt;
                    &amp;lt;div class="alert alert-info"&amp;gt;
                        &amp;lt;span class="icon-info-circle" aria-hidden="true"&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;span class="visually-hidden"&amp;gt;&amp;lt;?php echo __('INFO'); ?&amp;gt;&amp;lt;/span&amp;gt;
                        &amp;lt;?php echo __('No data'); ?&amp;gt;
                    &amp;lt;/div&amp;gt;
                &amp;lt;?php else : ?&amp;gt;
                    &amp;lt;table class="table wp-list-table widefat fixed striped table-view-list" id="bannerList"&amp;gt;
                        &amp;lt;thead&amp;gt;
                            &amp;lt;tr&amp;gt;
                                &amp;lt;th scope="col" class="column-language_"&amp;gt;
                                    &amp;lt;?= __( 'Id', 'testpage' ); ?&amp;gt;
                                &amp;lt;/th&amp;gt;
                                &amp;lt;th scope="col" class="w-10"&amp;gt;
                                    &amp;lt;?= __( 'User ID', 'testpage' ); ?&amp;gt;
                                &amp;lt;/th&amp;gt;
                                &amp;lt;th scope="col" class="w-10"&amp;gt;
                                    &amp;lt;?= __( 'Group ID', 'testpage' ); ?&amp;gt;
                                &amp;lt;/th&amp;gt;
                                &amp;lt;th scope="col" class="column-response"&amp;gt;
                                    &amp;lt;?= __( 'Url image', 'testpage' ); ?&amp;gt;
                                &amp;lt;/th&amp;gt;
                                &amp;lt;th scope="col" class="column-response"&amp;gt;
                                    &amp;lt;?= __( 'Url badge', 'testpage' ); ?&amp;gt;
                                &amp;lt;/th&amp;gt;
                                &amp;lt;th scope="col" class="column-response"&amp;gt;
                                    &amp;lt;?= __( 'Date created', 'testpage' ); ?&amp;gt;
                                &amp;lt;/th&amp;gt;
                                &amp;lt;th scope="col" class="w-5 d-none d-md-table-cell"&amp;gt;
                                    &amp;lt;?= __( 'Published', 'testpage' ); ?&amp;gt;
                                &amp;lt;/th&amp;gt;
                            &amp;lt;/tr&amp;gt;
                        &amp;lt;/thead&amp;gt;
                        &amp;lt;tbody&amp;gt;
                            &amp;lt;?php foreach ($items as $i =&amp;gt; $item) : ?&amp;gt;
                                &amp;lt;tr class="row&amp;lt;?php echo $i % 2; ?&amp;gt;" data-draggable-group="&amp;lt;?php echo $item-&amp;gt;id; ?&amp;gt;"&amp;gt;
                                    &amp;lt;td class="text-center"&amp;gt;
                                        &amp;lt;?php echo $item-&amp;gt;id; ?&amp;gt;

                                    &amp;lt;/td&amp;gt;
                                    &amp;lt;th scope="row" class="has-context"&amp;gt;
                                        &amp;lt;?php echo $item-&amp;gt;user_id; ?&amp;gt;
                                    &amp;lt;/th&amp;gt;
                                    &amp;lt;td class=""&amp;gt;
                                        &amp;lt;?php echo $item-&amp;gt;group_id; ?&amp;gt;
                                    &amp;lt;/td&amp;gt;
                                    &amp;lt;td class=""&amp;gt;
                                        &amp;lt;?php echo $item-&amp;gt;url_image; ?&amp;gt;
                                    &amp;lt;/td&amp;gt;
                                    &amp;lt;td class=""&amp;gt;
                                        &amp;lt;?php echo $item-&amp;gt;url_badge; ?&amp;gt;
                                    &amp;lt;/td&amp;gt;
                                    &amp;lt;td class=""&amp;gt;
                                        &amp;lt;?php echo $item-&amp;gt;created; ?&amp;gt;
                                    &amp;lt;/td&amp;gt;
                                    &amp;lt;td class="d-none d-md-table-cell"&amp;gt;
                                        &amp;lt;?= $item-&amp;gt;published; ?&amp;gt;
                                    &amp;lt;/td&amp;gt;
                                &amp;lt;/tr&amp;gt;
                            &amp;lt;?php endforeach; ?&amp;gt;
                        &amp;lt;/tbody&amp;gt;
                    &amp;lt;/table&amp;gt;
                &amp;lt;?php endif; ?&amp;gt;
            &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;

    &amp;lt;div class="clear"&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;&amp;lt;!-- .wrap --&amp;gt;
&amp;lt;?php

require_once ABSPATH . 'wp-admin/admin-footer.php';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I hope this Post will be useful to those wishing to know about WordPress development.&lt;/p&gt;

&lt;p&gt;Thanks in advance for the 💖 🦄 🤯 🙌 🔥 if you enjoyed it!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>wordpress</category>
      <category>php</category>
      <category>programming</category>
    </item>
    <item>
      <title>Component Accredible Credential for Joomla 5 (Part 2)</title>
      <dc:creator>Dollar Dev</dc:creator>
      <pubDate>Fri, 26 Jan 2024 08:37:27 +0000</pubDate>
      <link>https://forem.com/ta_phpwebdev/component-accredible-credential-for-joomla-5-part-2-2g54</link>
      <guid>https://forem.com/ta_phpwebdev/component-accredible-credential-for-joomla-5-part-2-2g54</guid>
      <description>&lt;p&gt;Hello! 👋&lt;br&gt;
And finally, a continuation to the &lt;a href="https://dev.to/ta_phpwebdev/component-accredible-credential-for-joomla-5-part-1-5bh4"&gt;part 1&lt;/a&gt; &lt;br&gt;
The component code can be downloaded from the &lt;a href="https://github.com/DollarDevTa/Joomla-Accredible" rel="noopener noreferrer"&gt;repository&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flxcqex5n58a2nbhhbsfg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flxcqex5n58a2nbhhbsfg.png" alt=" " width="414" height="860"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It probably looks a little horrible, but there's nothing difficult here. &lt;/p&gt;

&lt;p&gt;On the administration side it looks like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc0mglf6r2r5pybjwpdsq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc0mglf6r2r5pybjwpdsq.png" alt=" " width="800" height="428"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And settings for Accredible Credential API:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvugo0q1xzk5avh8xq1j3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvugo0q1xzk5avh8xq1j3.png" alt=" " width="800" height="290"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Group settings are necessary because the certificate or badge design is implemented in the group. You can create a group through the API, but then you will need to additionally draw a design on the Accredible side.&lt;/p&gt;

&lt;p&gt;I will describe the implementation of the component for Joomla in the following posts. Here I will only describe the points for working with the API.&lt;/p&gt;

&lt;p&gt;The main file for working with the API Accredible Credential is found at:&lt;br&gt;
&lt;strong&gt;src\Helper\AccrediblecertificateHelper.php&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;namespace Joomla\Component\Accrediblecertificate\Administrator\Helper;

use Joomla\CMS\Helper\ContentHelper;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
 * Accredible Certificate component helper.
 *
 * @since  1.6
 */
class AccrediblecertificateHelper extends ContentHelper
{
    private $api_key;

    private $api_endpoint = "https://api.accredible.com/v1/";

    /**
     * Set API Key
     * @param String $key
     * @return null
     */
    public function setAPIKey($key) {
        $this-&amp;gt;api_key = $key;
    }

    /**
     * Get API Key
     * @return String
     */
    public function getAPIKey() {
        return $this-&amp;gt;api_key;
    }

    /**
     * Contruct API instance
     * @param String $api_key
     * @param boolean|null $test
     * @return null
     */
    public function __construct($api_key, $test = null){
        $this-&amp;gt;setAPIKey($api_key);

        if (null !== $test) {
            //$this-&amp;gt;api_endpoint = "https://staging.accredible.com/v1/";
        }
    }

    /**
     * Creates a Credential given an existing Group
     * @param String $recipient_name
     * @param String $recipient_email
     * @param String $course_id
     * @param Date|null $issued_on
     * @param Date|null $expired_on
     * @param stdObject|null $custom_attributes
     * @return stdObject
     */
    public function create_credential($recipient_name, $recipient_email, $course_id, $issued_on = null, $expired_on = null, $custom_attributes = null){

        $data = array(
            "credential" =&amp;gt; array(
                "group_id" =&amp;gt; $course_id,
                "recipient" =&amp;gt; array(
                    "name" =&amp;gt; $recipient_name,
                    "email" =&amp;gt; $recipient_email
                ),
                "issued_on" =&amp;gt; $issued_on,
                "expired_on" =&amp;gt; $expired_on,
                "custom_attributes" =&amp;gt; $custom_attributes
            )
        );

        return json_decode($this-&amp;gt;execAccredible($this-&amp;gt;getAPIKey(), 'credentials', json_encode($data)), true);
    }

    public function execAccredible($key, $url, $params=array()){

        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, $this-&amp;gt;api_endpoint.$url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch, CURLOPT_HEADER, FALSE);

        if(!empty($params)){
            curl_setopt($ch, CURLOPT_POST, TRUE);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
        }

        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
          "Content-Type: application/json",
          "Authorization: Token token=".$key
        ));
        $response = curl_exec($ch);
        curl_close($ch);

        return $response;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To connect, I use a regular &lt;strong&gt;curl&lt;/strong&gt;, so that there is no need to connect additional libraries.&lt;br&gt;
The API Accredible feature set is very large, but the &lt;strong&gt;certificate creation&lt;/strong&gt; function is enough for me at the moment.&lt;/p&gt;

&lt;p&gt;I use this file (AccrediblecertificateHelper.php) in the plugin to create the Certificate:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php

namespace Joomla\Plugin\User\Accregistration\Extension;

use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Date\Date;
use Joomla\Database\DatabaseAwareTrait;
use Joomla\Component\Accrediblecertificate\Administrator\Helper\AccrediblecertificateHelper;
use Joomla\CMS\Component\ComponentHelper;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects


final class Accregistration extends CMSPlugin
{
    use DatabaseAwareTrait;

    public function onUserAfterSave($data, $isNew, $result, $error): void
    {
        if ($isNew &amp;amp;&amp;amp; $result ) {
        $config   = ComponentHelper::getParams('com_accrediblecertificate');
        $default_group_id = $config-&amp;gt;get('default_group_id', '546130');

        $api = new AccrediblecertificateHelper($config-&amp;gt;get('api_key', 'ade377f959a7f522c67a948772f02bc6'), true);
        $new_credential = $api-&amp;gt;create_credential($data['username'], $data['email1'], $default_group_id);

        $db = $this-&amp;gt;getDatabase();
        $query = $db-&amp;gt;getQuery(true)-&amp;gt;insert($db-&amp;gt;quoteName('#__accrediblecertificate'));

        $query-&amp;gt;columns([
                $db-&amp;gt;quoteName('user_id'), 
                $db-&amp;gt;quoteName('group_id'), 
                $db-&amp;gt;quoteName('url_image'),
                $db-&amp;gt;quoteName('url_badge'),
                $db-&amp;gt;quoteName('created'),
                $db-&amp;gt;quoteName('published')
            ])
        -&amp;gt;values(
                $db-&amp;gt;quote($data['id']) . ', ' . 
                $db-&amp;gt;quote($default_group_id) . ', ' .                  $db-&amp;gt;quote($new_credential['credential']['seo_image']) . ', ' . 
                $db-&amp;gt;quote($new_credential['credential']['badge']['image']['preview']) . ', "' .                    date('Y-m-d H:i:s'). '", ' . 
                ( !empty($new_credential['credential']['seo_image']) ? 1 : 0 )
            );

            $db-&amp;gt;setQuery($query);
            $db-&amp;gt;execute();
        }
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code is very simple, in order to review it in detail.&lt;br&gt;
This is just one example for adding a Certificate and this is not the final version of the plugin yet, I will be finalizing situations when the service is not available.&lt;br&gt;
Also, I would like to create a script (for cron) that will automatically create badges for users for specified accomplishments on the site, similar to how it is implemented on this portal. 😉&lt;/p&gt;

&lt;p&gt;I hope this material was useful...&lt;/p&gt;

&lt;p&gt;Thanks in advance for the "💖 🦄 🤯 🙌 🔥" if you enjoyed it!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>php</category>
      <category>programming</category>
      <category>joomla</category>
    </item>
    <item>
      <title>Component Accredible Credential for Joomla 5 (Part 1)</title>
      <dc:creator>Dollar Dev</dc:creator>
      <pubDate>Mon, 22 Jan 2024 11:59:40 +0000</pubDate>
      <link>https://forem.com/ta_phpwebdev/component-accredible-credential-for-joomla-5-part-1-5bh4</link>
      <guid>https://forem.com/ta_phpwebdev/component-accredible-credential-for-joomla-5-part-1-5bh4</guid>
      <description>&lt;p&gt;This component 🛠️ (set of extensions) for Joomla 5 and Accreditation integration I developed for use on my portal, but I'm willing to share it.&lt;br&gt;
In this post I will transcribe the &lt;strong&gt;design scheme&lt;/strong&gt; and make &lt;strong&gt;a development plan&lt;/strong&gt;, which usually helps to estimate more accurately the time to be used for development.&lt;br&gt;
But first a few words about what Accreditable is and why I need it.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="https://www.accredible.com/" rel="noopener noreferrer"&gt;Accredible&lt;/a&gt;&lt;/strong&gt; is a platform that provides digital credentialing and certificate services. It allows organizations, educational institutions, and businesses to create, manage, and issue digital certificates, badges, and credentials to individuals. These digital credentials can represent achievements, skills, or certifications earned by individuals in various fields.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;✨I plan to use these certificates for my users who will successfully complete the training and tasks on the site. But in the starter pack I will demonstrate only the creation of badges for users who have registered on the site. These badges will be displayed using a module on the User Profile page.&lt;/p&gt;

&lt;p&gt;📝In general, the scheme of interaction between extensions looks as follows:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzfbrps8w8o4p5ljbu47e.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzfbrps8w8o4p5ljbu47e.jpg" alt=" " width="800" height="1130"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With the diagram, I made a development plan:&lt;br&gt;
1️⃣ &lt;strong&gt;Create a component:&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;1.1 Administer the customization of the&lt;/strong&gt;&lt;br&gt;
➡️ API KEY&lt;br&gt;
➡️ default group ID (since it is not possible to create a badge or certificate in Accreditable without a group).&lt;br&gt;
&lt;strong&gt;1.2 Administer the component:&lt;/strong&gt; &lt;br&gt;
➡️ DB table for keeping data and certificates&lt;br&gt;
➡️ page with displaying data from the table&lt;br&gt;
➡️ main backend class for interaction with Accredible Credential API&lt;/p&gt;

&lt;p&gt;2️⃣ &lt;strong&gt;Create a plugin&lt;/strong&gt; with a trigger onUserAfterSave(). In the plugin settings, it should be possible to edit the Group from Accredible.&lt;/p&gt;

&lt;p&gt;3️⃣ &lt;strong&gt;Create a module&lt;/strong&gt; that will be located on the User Profile page and display the user's current badges.&lt;/p&gt;

&lt;p&gt;But before you start realization, you need to register at &lt;a href="https://www.accredible.com" rel="noopener noreferrer"&gt;https://www.accredible.com&lt;/a&gt;. Create Api Key, for this there is a very good instruction in the help center &lt;a href="https://help.accredible.com/how-do-i-find-my-integration-api-key" rel="noopener noreferrer"&gt;https://help.accredible.com/how-do-i-find-my-integration-api-key&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Thanks in advance for the "💖 🦄 🤯 🙌 🔥" if you enjoyed it!&lt;/p&gt;

&lt;p&gt;Part 2 coming soon ...&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>php</category>
      <category>joomla</category>
    </item>
    <item>
      <title>Readme to the Module Contact me for Joomla 5</title>
      <dc:creator>Dollar Dev</dc:creator>
      <pubDate>Wed, 17 Jan 2024 13:59:05 +0000</pubDate>
      <link>https://forem.com/ta_phpwebdev/readme-to-the-module-contact-me-for-joomla-5-41km</link>
      <guid>https://forem.com/ta_phpwebdev/readme-to-the-module-contact-me-for-joomla-5-41km</guid>
      <description>&lt;p&gt;Even though there are already a lot of modules written for Joomla, I have not been able to find a Contact module that is suitable for me.&lt;br&gt;
Most probably - this is only the first version of the module. I plan to improve it to perfection.&lt;br&gt;
You can see the current version of the working module on &lt;a href="https://tatsiana-dev.eu/en/#contact" rel="noopener noreferrer"&gt;my CV site&lt;/a&gt;, the module code in the &lt;a href="https://github.com/DollarDevTa/sta_contact_module" rel="noopener noreferrer"&gt;repository&lt;/a&gt;.&lt;br&gt;
File structure + Language files:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqv7x8sej1bwqaesg9ptn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqv7x8sej1bwqaesg9ptn.png" alt=" " width="288" height="226"&gt;&lt;/a&gt;&lt;br&gt;
A short description of the file assignments:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;mod_sta_contact.xml - 
File for installation and configuration of the module in joomla
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;extension type="module" client="site" method="upgrade"&amp;gt;
    &amp;lt;name&amp;gt;mod_sta_contact&amp;lt;/name&amp;gt;
    &amp;lt;author&amp;gt;Joomla! Project&amp;lt;/author&amp;gt;
    &amp;lt;creationDate&amp;gt;2024-01&amp;lt;/creationDate&amp;gt;
    &amp;lt;copyright&amp;gt;(C) 2024 Open Source Tatsiana, Inc.&amp;lt;/copyright&amp;gt;
    &amp;lt;license&amp;gt;GNU General Public License version 2 or later; see LICENSE.txt&amp;lt;/license&amp;gt;
    &amp;lt;authorEmail&amp;gt;dollar2901@gmail.com&amp;lt;/authorEmail&amp;gt;
    &amp;lt;authorUrl&amp;gt;www.joomla.org&amp;lt;/authorUrl&amp;gt;
    &amp;lt;version&amp;gt;1.0.0&amp;lt;/version&amp;gt;
    &amp;lt;description&amp;gt;MOD_STA_CONTACT_XML_DESCRIPTION&amp;lt;/description&amp;gt;
    &amp;lt;namespace path="src"&amp;gt;Joomla\Module\StaContact&amp;lt;/namespace&amp;gt;
    &amp;lt;files&amp;gt;
        &amp;lt;filename module="mod_sta_contact"&amp;gt;mod_sta_contact.php&amp;lt;/filename&amp;gt;
        &amp;lt;folder&amp;gt;forms&amp;lt;/folder&amp;gt;
        &amp;lt;folder&amp;gt;src&amp;lt;/folder&amp;gt;
        &amp;lt;folder&amp;gt;tmpl&amp;lt;/folder&amp;gt;
    &amp;lt;/files&amp;gt;
    &amp;lt;languages&amp;gt;
        &amp;lt;language tag="en-GB"&amp;gt;language/en-GB/mod_sta_contact.ini&amp;lt;/language&amp;gt;
        &amp;lt;language tag="en-GB"&amp;gt;language/en-GB/mod_sta_contact.sys.ini&amp;lt;/language&amp;gt;
        &amp;lt;language tag="pl-PL"&amp;gt;language/pl-PL/mod_sta_contact.ini&amp;lt;/language&amp;gt;
        &amp;lt;language tag="pl-PL"&amp;gt;language/pl-PL/mod_sta_contact.sys.ini&amp;lt;/language&amp;gt;
    &amp;lt;/languages&amp;gt;

&amp;lt;/extension&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;mod_sta_contact.php - Module controller
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php

\defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Helper\AuthenticationHelper;
use Joomla\CMS\Helper\ModuleHelper;
use Joomla\Module\StaContact\Site\Helper\StaContactHelper;

$data = Factory::getApplication()-&amp;gt;input-&amp;gt;post-&amp;gt;get('jform', [], 'array');

Form::addFormPath(JPATH_SITE . '/modules/mod_sta_contact/forms');

$form = Form::getInstance('mod_sta_contact.sendmessage', 'sendmessage',['control' =&amp;gt; 'jform']);

if(isset($data['contact_sta_send_mail'])){
    $staContact = new StaContactHelper();
    $staContact-&amp;gt;submit();
}

require ModuleHelper::getLayoutPath('mod_sta_contact');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;forms\sendmessage.xml - 
Xml file for configuring form fields
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;form&amp;gt;
    &amp;lt;fieldset name="stacontact" label="MOD_STA_CONTACT_DEFAULT_LABEL"&amp;gt;
        &amp;lt;field
            name="contact_name"
            type="text"
            label="MOD_STA_CONTACT_EMAIL_NAME_LABEL"
            id="contact-name"
            size="30"
            filter="string"
            required="true"
            hint="MOD_STA_CONTACT_EMAIL_NAME_LABEL"
        /&amp;gt;

        &amp;lt;field
            name="contact_email"
            type="email"
            label="MOD_STA_CONTACT_EMAIL_LABEL"
            id="contact-email"
            size="30"
            filter="string"
            autocomplete="email"
            required="true"
            hint="MOD_STA_CONTACT_EMAIL_LABEL"
        /&amp;gt;

        &amp;lt;field
            name="contact_subject"
            type="text"
            label="MOD_STA_CONTACT_MESSAGE_SUBJECT_LABEL"
            id="contact-emailmsg"
            size="60"
            filter="string"
            required="true"
            hint="MOD_STA_CONTACT_MESSAGE_SUBJECT_LABEL"
        /&amp;gt;

        &amp;lt;field
            name="contact_message"
            type="textarea"
            label="MOD_STA_CONTACT_ENTER_MESSAGE_LABEL"
            cols="20"
            rows="5"
            id="contact-message"
            filter="safehtml"
            hint="MOD_STA_CONTACT_ENTER_MESSAGE_LABEL"
        /&amp;gt;

        &amp;lt;field
            name="contact_sta_send_mail"
            type="hidden"
            default="1"
        /&amp;gt;
    &amp;lt;/fieldset&amp;gt;

    &amp;lt;fieldset name="captcha"&amp;gt;
        &amp;lt;field
            name="captcha"
            type="captcha"
            label="MOD_STA_CONTACT_CAPTCHA_LABEL"
            validate="captcha"
            required="true"
            namespace="contact"
        /&amp;gt;
    &amp;lt;/fieldset&amp;gt;

&amp;lt;/form&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;tmpl\default.php - 
Main module template. Here for now you need to manually change the *&lt;em&gt;action *&lt;/em&gt; to the one you need. It will be improved in the next versions - *&lt;em&gt;action *&lt;/em&gt; can be customized in the module administration.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php
defined('_JEXEC') or die;

use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Factory;

$document  = Factory::getDocument();
$app-&amp;gt;getDocument()-&amp;gt;getWebAssetManager()
    -&amp;gt;useScript('core')
    -&amp;gt;useScript('keepalive')
    -&amp;gt;useScript('form.validate');

// Get the message queue
$messages = Factory::getApplication()-&amp;gt;getMessageQueue();
$list_messages = [];
// Build the sorted message list
if (\is_array($messages) &amp;amp;&amp;amp; !empty($messages)) {
    foreach ($messages as $msg) {
        if (isset($msg['type']) &amp;amp;&amp;amp; isset($msg['message'])) {
            $list_messages[$msg['type']][] = $msg['message'];
        }
    }
}
?&amp;gt;
&amp;lt;form id="sta-contact-form" class="mod-sta-contact needs-validation" novalidate action="&amp;lt;?php echo Route::_('index.php#contact'); ?&amp;gt;" method="post"&amp;gt;
    &amp;lt;h1 style="color:#013F4E" class="h3 mb-3 fw-normal"&amp;gt;Contact me&amp;lt;/h1&amp;gt;
    &amp;lt;?php if (is_array($list_messages) &amp;amp;&amp;amp; !empty($list_messages)) {
        echo $list_messages["info"][0];
    }else{ ?&amp;gt;
    &amp;lt;p&amp;gt;&amp;lt;?=Text::_('MOD_STA_CONTACT_ADD_MESSAGE_TEXT')?&amp;gt;&amp;lt;/p&amp;gt;

    &amp;lt;?php foreach ($form-&amp;gt;getFieldsets() as $fieldset) : ?&amp;gt;
            &amp;lt;?php if ($fieldset-&amp;gt;name === 'captcha') : ?&amp;gt;
                &amp;lt;?php continue; ?&amp;gt;
            &amp;lt;?php endif; ?&amp;gt;
            &amp;lt;?php $fields = $form-&amp;gt;getFieldset($fieldset-&amp;gt;name); ?&amp;gt;
            &amp;lt;?php if (count($fields)) : ?&amp;gt;
                &amp;lt;fieldset class="m-0 text-start"&amp;gt;
                    &amp;lt;?php foreach ($fields as $field) : ?&amp;gt;
                        &amp;lt;div class="control-group form-floating"&amp;gt;
                        &amp;lt;?php echo $field-&amp;gt;input; ?&amp;gt;
                        &amp;lt;?php echo $field-&amp;gt;label; ?&amp;gt;
                        &amp;lt;/div&amp;gt;
                    &amp;lt;?php endforeach; ?&amp;gt;
                &amp;lt;/fieldset&amp;gt;
            &amp;lt;?php endif; ?&amp;gt;
        &amp;lt;?php endforeach; ?&amp;gt;

    &amp;lt;?php echo $form-&amp;gt;renderFieldset('captcha'); ?&amp;gt;
    &amp;lt;?php echo HTMLHelper::_('form.token'); ?&amp;gt;
    &amp;lt;button class="btn btn-primary w-100 py-2" id="contact-send" type="button"&amp;gt;&amp;lt;?= Text::_('MOD_STA_CONTACT_SEND'); ?&amp;gt;&amp;lt;/button&amp;gt;
&amp;lt;/form&amp;gt;
&amp;lt;?php 
Factory::getDocument()-&amp;gt;addScriptDeclaration('
    window.onload = function(){

  document.getElementById("contact-send").addEventListener("click",function (){
    var form = document.getElementById("sta-contact-form");
    if (!form.checkValidity()) {
          event.preventDefault();
          event.stopPropagation();
          form.classList.add("was-validated");
        }else{
            document.getElementById("sta-contact-form").submit();
        }
   });
};');
}?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;src\Helper\StaContactHelper.php - 
Helper file with module functions
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php
/**
 * @package     Joomla.Site
 * @subpackage  mod_sta_contact
 *
 */
namespace Joomla\Module\StaContact\Site\Helper;

use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Language\Multilanguage;
use Joomla\CMS\String\PunycodeHelper;
use Joomla\CMS\Mail\MailTemplate;
use Joomla\CMS\Uri\Uri;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
 * Helper for mod_sta_contact
 *
 * @since  1.5
 */
class StaContactHelper
{
    public function submit()
    {
        // Check for request forgeries.
        Factory::getApplication()-&amp;gt;checkToken();
        $app    = Factory::getApplication();

        // Get the data from POST
        $data = $app-&amp;gt;input-&amp;gt;post-&amp;gt;get('jform', [], 'array');
        $msg = '';
        $sent = false;

        $sent = $this-&amp;gt;_sendEmail($data);

        // Set the success message if it was a success
        if ($sent) {
            $msg = Text::_('MOD_STA_CONTACT_EMAIL_THANKS');
        }
        $app-&amp;gt;enqueueMessage($msg);

        return true;
    }

    private function _sendEmail($data)
    {
        $app = Factory::getApplication();

        $templateData = [
            'sitename'     =&amp;gt; $app-&amp;gt;get('sitename'),
            'name'         =&amp;gt; $data['contact_name'],
            'contactname'  =&amp;gt; 'Contact me form',
            'email'        =&amp;gt; PunycodeHelper::emailToPunycode($data['contact_email']),
            'subject'      =&amp;gt; $data['contact_subject'],
            'body'         =&amp;gt; stripslashes($data['contact_message']),
            'url'          =&amp;gt; Uri::base(),
            'customfields' =&amp;gt; '',
        ];

        try {
            $mailer = new MailTemplate('com_contact.mail', $app-&amp;gt;getLanguage()-&amp;gt;getTag());
            $mailer-&amp;gt;addRecipient($app-&amp;gt;get('mailfrom'));
            $mailer-&amp;gt;setReplyTo($templateData['email'], $templateData['name']);
            $mailer-&amp;gt;addTemplateData($templateData);
            $sent = $mailer-&amp;gt;send();

        } catch (MailDisabledException | phpMailerException $exception) {
            try {
                Log::add(Text::_($exception-&amp;gt;getMessage()), Log::WARNING, 'jerror');

                $sent = false;
            } catch (\RuntimeException $exception) {
                $app-&amp;gt;enqueueMessage(Text::_($exception-&amp;gt;errorMessage()), 'warning');

                $sent = false;
            }
        }
        return $sent;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can &lt;strong&gt;install&lt;/strong&gt; the module in the standard method:&lt;br&gt;
System -&amp;gt; Install Extensions -&amp;gt; Upload Package File.&lt;br&gt;
In the module settings add a &lt;strong&gt;position&lt;/strong&gt; for module output and &lt;strong&gt;published&lt;/strong&gt; it:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffrq9gaejtlrqx2jn12h3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffrq9gaejtlrqx2jn12h3.png" alt=" " width="689" height="754"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As a result, a form should appear on the selected position:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7uqr08e3d6o3w7hk1xnq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7uqr08e3d6o3w7hk1xnq.png" alt=" " width="791" height="682"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I planned to add the ability to customize in the Joomla admin: the choice of fields, which to display in the module, adding styles for fields, email to which to send emails, perhaps a few more settings.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>joomla</category>
      <category>php</category>
      <category>module</category>
    </item>
    <item>
      <title>Connecting the collapse to the menu - Joomla 4+</title>
      <dc:creator>Dollar Dev</dc:creator>
      <pubDate>Mon, 08 Jan 2024 17:57:27 +0000</pubDate>
      <link>https://forem.com/ta_phpwebdev/connecting-the-collapse-to-the-menu-joomla-4-37jg</link>
      <guid>https://forem.com/ta_phpwebdev/connecting-the-collapse-to-the-menu-joomla-4-37jg</guid>
      <description>&lt;p&gt;Maybe it will be useful to someone how to connect collapse menu in Cassiopea template.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Log in to the Joomla Administrator&lt;/li&gt;
&lt;li&gt;Go to the System -&amp;gt; Manage Site Modules&lt;/li&gt;
&lt;li&gt;Edit a module with the Menu type. In my case it Main Menu:
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9emsw8avtkcewcifd7jp.png" alt=" " width="800" height="174"&gt;
&lt;/li&gt;
&lt;li&gt;On the advanced options tab, you need to change the Layout value
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F07onyjkdieyg5pgfk685.png" alt=" " width="782" height="649"&gt;
Select Collapsible Dropdown in Cassiopea template and save changes to the module
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frw2tmcer5w9f7dnpyhwa.png" alt=" " width="587" height="307"&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The module template is located in the folder&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;templates\cassiopeia\html\mod_menu\collapse-metismenu.php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Maybe I haven't reviewed something, please ask in comments.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>First steps to secure your site (Part 1)</title>
      <dc:creator>Dollar Dev</dc:creator>
      <pubDate>Fri, 05 Jan 2024 19:19:01 +0000</pubDate>
      <link>https://forem.com/ta_phpwebdev/first-steps-to-secure-your-site-part-1-2km</link>
      <guid>https://forem.com/ta_phpwebdev/first-steps-to-secure-your-site-part-1-2km</guid>
      <description>&lt;p&gt;Securing your website is crucial to protect it from potential threats and ensure the safety of your users and data. Here are some essential first steps to secure your site:&lt;/p&gt;

&lt;p&gt;🧐&lt;strong&gt;1. Keep Software Updated and Remove Unused Plugins and Themes:&lt;/strong&gt;&lt;br&gt;
Regularly update your website's CMS (Content Management System), plugins, themes, and any other software you use. Updates often include security patches.&lt;br&gt;
Delete or disable any plugins or themes that are not actively in use. Unused extensions can be a security risk if not regularly updated.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Use Strong Passwords and Limit Login Attempts:&lt;/strong&gt;&lt;br&gt;
Use complex and unique passwords for all accounts associated with your website, including hosting, CMS, and database accounts. Consider using a password manager.&lt;br&gt;
Implement measures to limit the number of login attempts to prevent brute force attacks. This can include account lockouts after a certain number of failed attempts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Monitor User Permissions:&lt;/strong&gt;&lt;br&gt;
Regularly review and audit user roles and permissions. Ensure that users have the minimum necessary access required for their roles.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Secure File Uploads:&lt;/strong&gt;&lt;br&gt;
If your website allows file uploads, ensure that only authorized file types are accepted. Set strict permissions on uploaded files and validate file types and sizes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Secure Database Access:&lt;/strong&gt;&lt;br&gt;
Use strong passwords for database accounts. Restrict database access to specific IP addresses and avoid using default database prefixes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Protect Against SQL Injection:&lt;/strong&gt;&lt;br&gt;
Sanitize and validate user inputs to prevent SQL injection attacks. Use prepared statements and parameterized queries when interacting with databases.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7. Enable HTTPS:&lt;/strong&gt;&lt;br&gt;
Use HTTPS to encrypt data transmitted between your website and users. Obtain an SSL/TLS certificate for your domain. Many hosting providers offer free certificates through Let's Encrypt.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;8. Backup Regularly:&lt;/strong&gt;&lt;br&gt;
Set up regular backups of your website, including databases and files. Store backups in a secure location, separate from your hosting server. Test your backups to ensure they can be restored.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;9. Implement Web Application Firewall (WAF):&lt;/strong&gt;&lt;br&gt;
Use a WAF to filter and monitor HTTP traffic between a web application and the Internet. WAFs can help protect against common web application attacks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;10. Cross-Site Scripting (XSS) Protection:&lt;/strong&gt;&lt;br&gt;
Validate and sanitize user inputs to prevent cross-site scripting attacks. Avoid echoing user-input directly into HTML or JavaScript.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;11. Security Headers:&lt;/strong&gt;&lt;br&gt;
Implement security headers in your website's HTTP responses. Common headers include Content Security Policy (CSP), Strict Transport Security (HSTS), and X-Content-Type-Options.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;12. Monitor and Audit Logs:&lt;/strong&gt;&lt;br&gt;
Regularly review server logs, CMS logs, and security logs for suspicious activities. Set up alerts for unusual or suspicious events.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;13. Educate Users and Team:&lt;/strong&gt;&lt;br&gt;
Educate your team and users about security best practices. This includes avoiding common pitfalls like clicking on suspicious links and using strong passwords.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;14. Security Audits:&lt;/strong&gt;&lt;br&gt;
Conduct regular security audits or hire a professional to assess your website's security. Identify and address vulnerabilities before they can be exploited.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;15. Stay Informed:&lt;/strong&gt;&lt;br&gt;
Keep yourself informed about the latest security threats and best practices. Subscribe to security newsletters, follow security blogs, and stay connected with your CMS community.&lt;/p&gt;

&lt;p&gt;By implementing these first steps, you establish a foundation for a more secure website. Security is an ongoing process, so regularly review and update your security measures to stay ahead of potential threats.&lt;/p&gt;

</description>
      <category>security</category>
      <category>website</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Top 10 PHP coding standards</title>
      <dc:creator>Dollar Dev</dc:creator>
      <pubDate>Thu, 04 Jan 2024 11:48:44 +0000</pubDate>
      <link>https://forem.com/ta_phpwebdev/top-10-php-coding-standards-35an</link>
      <guid>https://forem.com/ta_phpwebdev/top-10-php-coding-standards-35an</guid>
      <description>&lt;p&gt;PHP coding standards are a set of guidelines and best practices that developers follow to ensure consistency, readability, and maintainability of code. Adhering to coding standards is essential for collaborative development, as it promotes a uniform coding style across a project or organization. Here are common PHP coding standards:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.PSR Standards&lt;/strong&gt;&lt;br&gt;
Many PHP projects and frameworks follow the standards defined by the PHP-FIG (PHP Framework Interop Group). Notable PSRs include PSR-1, PSR-2, PSR-4, and PSR-12.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.Indentation&lt;/strong&gt;&lt;br&gt;
Use spaces for indentation instead of tabs. PSR-2 recommends using four spaces for each level of indentation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3.Line Length&lt;/strong&gt;&lt;br&gt;
Limit lines to a maximum length, commonly 80 or 120 characters per line. This enhances code readability, especially in side-by-side comparisons.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4.Opening and Closing PHP Tags&lt;/strong&gt;&lt;br&gt;
Use &lt;strong&gt;&amp;lt;?php&lt;/strong&gt; for opening PHP tags, and avoid using the short tags (&lt;strong&gt;&amp;lt;?&lt;/strong&gt;). For files that contain only PHP code, omit the closing tag &lt;strong&gt;?&amp;gt;&lt;/strong&gt; to prevent unintended whitespace.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5.Namespace and Class Naming&lt;/strong&gt;&lt;br&gt;
Use a namespace, and follow an autoloader-friendly directory structure. Class names should be declared in StudlyCaps (PascalCase).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;namespace Vendor\Package;

class ClassName
{
    // Class implementation
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6.Class Constants, Properties, and Methods&lt;/strong&gt;&lt;br&gt;
Constants should be declared in uppercase with underscores as separators. Properties and methods should use camelCase.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const MAX_ATTEMPTS = 3;

class MyClass
{
    private $myProperty;

    public function myMethod()
    {
        // Method implementation
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;7.Control Structures&lt;/strong&gt;&lt;br&gt;
Place control structure keywords (if, else, for, while, etc.) on a new line with an indentation. Use braces even for single-line statements.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if ($condition) {
    // Code block
} else {
    // Code block
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;8.Function and Method Calls&lt;/strong&gt;&lt;br&gt;
Do not use spaces between the function or method name and the opening parenthesis. Add a space after commas in argument lists.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myFunction($arg1, $arg2);

$object-&amp;gt;myMethod($arg1, $arg2);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;9.Array Declaration&lt;/strong&gt;&lt;br&gt;
Use the array() syntax for array declaration rather than the short [] syntax. Add a space after the comma.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$myArray = array('apple', 'banana', 'orange');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;10.Doc Comments&lt;/strong&gt;&lt;br&gt;
Use doc comments to document classes, methods, and properties. Follow the PHPDoc format for consistency and clarity.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/**
 * Short description.
 *
 * @param  string $param1 Description of param1
 * @param  int    $param2 Description of param2
 * @return bool   Description of the return value
 */
public function myMethod($param1, $param2)
{
    // Method implementation
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And one more additional recommendation:&lt;br&gt;
Integrate tools like PHP_CodeSniffer and follow the predefined coding standards (e.g., PSR-2) by creating configuration files. Automate the process of code checking within your development workflow.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Example usage of PHP_CodeSniffer
phpcs --standard=PSR2 path/to/your/code
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These coding standards help create a unified coding style across PHP projects and facilitate collaboration among developers. It's essential to choose and consistently follow a set of coding standards that align with the project's requirements and the wider PHP community.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>The main components of a good website</title>
      <dc:creator>Dollar Dev</dc:creator>
      <pubDate>Thu, 04 Jan 2024 08:50:49 +0000</pubDate>
      <link>https://forem.com/ta_phpwebdev/the-main-components-of-a-good-website-549i</link>
      <guid>https://forem.com/ta_phpwebdev/the-main-components-of-a-good-website-549i</guid>
      <description>&lt;p&gt;A good website is a combination of various elements that work together to provide a positive user experience, convey information effectively, and achieve its intended goals. Here are the main components of a good website:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Clear Purpose and Goals:&lt;/strong&gt;&lt;br&gt;
Clearly define the purpose and goals of the website. Understand the target audience and what actions you want visitors to take.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;User-Friendly Design:&lt;/strong&gt;&lt;br&gt;
Intuitive and easy-to-navigate design with a clear hierarchy of information. Use consistent navigation menus, readable fonts, and an uncluttered layout.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Responsive Design:&lt;/strong&gt;&lt;br&gt;
Ensure the website is responsive and adapts to different devices and screen sizes. Mobile-friendly design is essential for a positive user experience.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Compelling Visuals:&lt;/strong&gt;&lt;br&gt;
High-quality and relevant images, graphics, and multimedia elements that enhance the visual appeal and engage users.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Clear Call-to-Action (CTA):&lt;/strong&gt;&lt;br&gt;
Strategically place clear and compelling CTAs to guide users toward desired actions, whether it's making a purchase, signing up, or contacting the business.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Effective Copywriting:&lt;/strong&gt;&lt;br&gt;
Well-written and concise content that communicates the brand message, value proposition, and key information. Use headings, subheadings, and bullet points for easy readability.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Optimized Loading Speed:&lt;/strong&gt;&lt;br&gt;
Optimize the website for fast loading times. Users expect pages to load quickly, and a slow website can lead to high bounce rates.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Search Engine Optimization (SEO):&lt;/strong&gt;&lt;br&gt;
Implement SEO best practices to improve the website's visibility in search engine results. This includes using relevant keywords, meta tags, and creating a sitemap.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Security Measures:&lt;/strong&gt;&lt;br&gt;
Implement security protocols, especially if the website handles sensitive information. Use HTTPS, keep software updated, and regularly perform security audits.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Contact Information:&lt;/strong&gt;&lt;br&gt;
Provide clear and accessible contact information, including a contact form, email address, phone number, and physical address if applicable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Social Media Integration:&lt;/strong&gt;&lt;br&gt;
Incorporate social media buttons and links to encourage social sharing and connect with users on other platforms.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Analytics and Tracking:&lt;/strong&gt;&lt;br&gt;
Implement analytics tools, such as Google Analytics, to track website performance, user behavior, and traffic sources. Use data to make informed decisions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Consistent Branding:&lt;/strong&gt;&lt;br&gt;
Maintain consistent branding elements, including logos, colors, and typography, to reinforce brand identity across the website.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Accessibility Features:&lt;/strong&gt;&lt;br&gt;
Ensure the website is accessible to users with disabilities by following web accessibility standards. This includes providing alternative text for images and ensuring keyboard navigation is smooth.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Content Management System (CMS):&lt;/strong&gt;&lt;br&gt;
Use a reliable and user-friendly CMS to manage and update website content efficiently. Popular CMS options include WordPress, Joomla, and Drupal.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Feedback Mechanism:&lt;/strong&gt;&lt;br&gt;
Incorporate feedback forms, surveys, or contact options to gather user opinions and address concerns. This helps improve the website based on user input.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Legal Compliance:&lt;/strong&gt;&lt;br&gt;
Include necessary legal components, such as privacy policies, terms of service, and disclaimers, to comply with regulations and build trust with users.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Regular Updates and Maintenance:&lt;/strong&gt;&lt;br&gt;
Regularly update content, check for broken links, and perform routine maintenance to keep the website current and functioning optimally.&lt;/p&gt;

&lt;p&gt;By focusing on these components, you can create a website that not only looks appealing but also effectively serves its purpose and meets the needs of both users and the business or organization it represents.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>product</category>
      <category>website</category>
    </item>
    <item>
      <title>Review of new string functions in PHP 8.1</title>
      <dc:creator>Dollar Dev</dc:creator>
      <pubDate>Wed, 03 Jan 2024 08:28:19 +0000</pubDate>
      <link>https://forem.com/ta_phpwebdev/review-of-new-string-functions-in-php-81-4i3b</link>
      <guid>https://forem.com/ta_phpwebdev/review-of-new-string-functions-in-php-81-4i3b</guid>
      <description>&lt;p&gt;Hi, &lt;br&gt;
I decided to start my first post specifically with the new PHP string functions. I work with many lines of code every day and thanks to these functions the code will be more pleasant.&lt;br&gt;
Please support this post with reactions and I will continue to please the DEV community with new posts about the PHP backend.&lt;br&gt;
I'll start, perhaps, with how it was in previous versions of PHP and what were the options for checking for the content of a substring in a string - &lt;strong&gt;str_contains()&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using strstr():&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$fullstr = "It is a nice day today.";
$needle = "nice";

if (strstr($fullstr , $needle) !== false) {
    echo "The fullstr contains the needle.";
} else {
    echo "The fullstr does not contain the needle.";
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;strong&gt;strstr()&lt;/strong&gt; function returns the portion of the string starting from the first occurrence of the needle to the end of the string. If the needle is not found, it returns false.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using preg_match():&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$fullstr = "It is a nice day today.";
$needle = "/nice/";

if (preg_match($needle, $fullstr)) {
    echo "The fullstr contains the needle.";
} else {
    echo "The fullstr does not contain the needle.";
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, &lt;strong&gt;preg_match()&lt;/strong&gt; is using a regular expression to match the needle in the fullstr. The &lt;strong&gt;preg_match()&lt;/strong&gt; function returns 1 if the pattern is found, 0 if no match is found, and false on error.&lt;br&gt;
While these alternatives are available, the choice between them depends on the specific requirements and patterns you are working with. It's essential to consider factors like performance, flexibility, and the nature of the data you're handling.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using strpos():&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$fullstr = "It is a nice day today.";
$needle = "nice";

if (strpos($fullstr , $needle) !== false) {
    echo "The fullstr contains the needle.";
} else {
    echo "The fullstr does not contain the needle.";
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In PHP 7.4, you may also use the null coalescing assignment operator (??=) to provide a default value in case the substring is not found. Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$fullstr = "It is a nice day today.";
$needle = "nice";

$result = strpos($fullstr , $needle) ?? -1;

if ($result !== -1) {
    echo "The fullstr contains the needle.";
} else {
    echo "The fullstr does not contain the needle.";
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, if &lt;strong&gt;strpos()&lt;/strong&gt; returns false (needle not found), the null coalescing operator sets the value of $result to -1. You can then check against this value to determine if the needle is present.&lt;br&gt;
Remember that PHP 7.4 and later versions offer a range of improvements and new features, so it's generally recommended to use the latest stable version for security and performance reasons.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;And finally using str_contains():&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$fullstr = "It is a nice day today.";
$needle= "nice";

if (str_contains($fullstr , $needle)) {
    echo "The fullstr contains the needle.";
} else {
    echo "The fullstr does not contain the needle.";
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;strong&gt;str_contains()&lt;/strong&gt; function in PHP is used to check if a string contains another substring. It returns true if the substring is found, and false otherwise.&lt;/p&gt;

&lt;p&gt;Personally, I like the last string search option the most :)&lt;br&gt;
Thank you for your attention and I hope this material will be useful.&lt;/p&gt;

</description>
      <category>backend</category>
      <category>php</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
