Jump to content

UserProfiles addon Prevent regular listing submissions until profile is submitted


DanielH

Recommended Posts

Hello,

Jreviews 3.5.3.2 and UserProfiles Add-on 2.5.0.3

Haven't tested thoroughly yet to see if listings will submit properly or any hiccups but it does prevent listing submission and redirects to profile submission just fine. If there are any issues will update.

The original code came from Alejandro on earlier versions and can be found here. This code stopped working in recent versions, figured to update for others if needed and post it here.

You don't need a custom theme or custom theme settings in jreviews configuration for this to work but do need to create your "jreviews_overrides" directory structure as per the documentation for theme customization to edit plugins. If you already have a custom theme in overrides you only need to add the plugins directory.

The UserProfiles "userprofiles_listings_create.thtml" file needed can be found in:

/components/com_jreviews_addons/userprofiles/plugins

If you haven't created an overrides directory yet do so with the following structure and copy the userprofiles_listings_create.thtml to the new plugins directory:

/template/jreviews_overrides/plugins

Your overrides structure should look like this:

/templates/jreviews_overrides/plugins/userprofiles_listings_create.thtml

Edit the userprofiles_listings_create.thtml.

Find:

    function plgAfterFilter()
    {
        if (defined('MVC_FRAMEWORK_ADMIN')) return;

        $output = & $this->c->output;

        // If already submitted a profile then the profile preview is shown

        $createPage = $this->c->name == 'listings' && $this->c->action == 'create';

        $loadForm = $this->c->name == 'listings' && $this->c->action == '_loadForm';

        $profilePreviewRender = null;

        if($createPage || $loadForm)
        {
            $passedCatId = Sanitize::getInt($this->c->params, 'cat');

            $passedDataCatId = Sanitize::getInt($this->c->data, 'catid');

            if($passedCatId && !$this->isProfileCategory($passedCatId)) return;

            if($passedDataCatId && !$this->isProfileCategory($passedDataCatId)) return;

            if($profilePreview = $this->c->UserprofilesProfile->renderProfilePreview($this->c->auth->id))
            {
                $this->c->set('profilePreview', $profilePreview);

                $profilePreviewRender = $this->c->partialRender('profiles', 'create_profile_exists');
            }

            if($createPage && $passedCatId && $profilePreviewRender)
            {
                $output = $profilePreviewRender;
            }
            elseif($loadForm && $passedDataCatId && $profilePreviewRender) {

                $output = json_encode(['action' => 'show_form', 'html' => $profilePreviewRender]);
            }
        }
    }

Replace with:

    function plgAfterFilter()
    {
        if (defined('MVC_FRAMEWORK_ADMIN')) return;

        $output = & $this->c->output;

        // If already submitted a profile then the profile preview is shown

        $createPage = $this->c->name == 'listings' && $this->c->action == 'create';

        $loadForm = $this->c->name == 'listings' && $this->c->action == '_loadForm';

        $profilePreviewRender = null;

        if($createPage || $loadForm)
        {
            $passedCatId = Sanitize::getInt($this->c->params, 'cat');

            $passedDataCatId = Sanitize::getInt($this->c->data, 'catid');

            if(
                ($passedCatId && !$this->isProfileCategory($passedCatId))
                ||
                ($passedDataCatId && !$this->isProfileCategory($passedDataCatId))
            ) {
                $profilePreview = $this->c->UserprofilesProfile->renderProfilePreview($this->c->auth->id);

                if (!$profilePreview)
                {
                    $message = 'Message why profiles are required before submitting a listing';

                    if ($createPage)
                    {
                        $output = $message;
                    }
                    else {
                        $output = json_encode(array(['action' => 'show_form', 'html' => $profilePreviewRender]));
                    }
                }
                return;
            }

            if($profilePreview = $this->c->UserprofilesProfile->renderProfilePreview($this->c->auth->id))
            {
                $this->c->set('profilePreview', $profilePreview);


                $profilePreviewRender = $this->c->partialRender('profiles', 'create_profile_exists');
            }

            if($createPage && $passedCatId && $profilePreviewRender)
            {
                $output = $profilePreviewRender;
            }
            elseif($loadForm && $passedDataCatId && $profilePreviewRender) {

                $output = json_encode(array(['action' => 'show_form', 'html' => $profilePreviewRender]));
            }
        }
    }

Below is a simple, example, html message with two buttons added to the $message. One button for a popup stating why the profile is required and the other as a hyperlink to the profile listing submission page by replacing:

                    $message = 'Your html message goes here';

with:

                    $message = '<div class="jr-page jrPage jrUserAccountManage">
                                    <h1 class="contentheading">My Account</h1>	
                                    <div class="jrGrid jrAccountSection">
                                        <div class="jrCol3">
                                            <h3>Profile</h3>
                                            <p>Public profile</p>
                                        </div>
                                        <div class="jrCol9">
                                            <div class="jrGrid">
                                                <div class="jrCol6">
                                                    <p></p>
                                                    <p>You have not created your public profile yet.</p>
                                                    <p>
                                                         <button type="button" class="jrButton i-popover" title="Required profiles"
                                                         data-content="Message why profiles are required before submitting a listing." data-placement="bottom"
                                                         data-trigger="focus">Why are profiles required?</button>
                                                    </p>
                                                    <p><a class="jrButton" href="https://path to submit page" >Create profile now</a></p>
													<p></p>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>';

Be sure to edit the

'Message why profiles are required before submitting a listing.'

and the

"https://path to submit page"

with your information. The quotes ' ' and " " need to be included. Like I said this is a simple message example but any html attributes and styles can be added here to suit your template styling.

 

Cheers!

Edited by DanielH
Code correction
Link to comment
  • 1 year later...
  • 2 weeks later...
×
×
  • Create New...