Help adding unique text to each page displayed


#22

I was unable to test the script because I have missing functions, etc

In order to prevent the blank page from showing add error_reporting:

<?php
declare( strict_types=1);
error_reporting(-1);
ini_set( 'display_errors', 'true');
// 

Or add more descriptive detail to the $test variables, preferbly with PHP LINE numbers.


#23

Thank you.
I am already running that error reporting thanks to your earlier suggestion.

Any additional help with displaying unique text, when each unique page is loaded will be welcomed.


#24

The issue here is that you’re creating multiple variables, because you are giving them different names. Inside the if.. else structure at the start where you assign the text to the variables, just give them the same name all the time, then you only have one variable to pass through.


#25

Thanks again for your reply.

I’ve tried this:

$text = '';
$category_id = '';
$videos = array();

if ($page == 'trending') {
    $title  = $lang->trending;
    $db->where('privacy', 0);
    $videos = $db->where('time', time() - 172800, '>')->orderBy('views', 'DESC')->get(T_VIDEOS, $limit);
	$text = 'trending text here';
}

else if ($page == 'latest') {
    $title  = $lang->latest_videos;
    $db->where('privacy', 0);
    $videos = $db->orderBy('id', 'DESC')->get(T_VIDEOS, $limit);
   $text = 'Latest text here';
}

else if ($page == 'top') {
    $title  = $lang->top_videos;
    $db->where('privacy', 0);
    $videos = $db->orderBy('views', 'DESC')->get(T_VIDEOS, $limit);
    $text = 'Top text here';
}


along with this:


$pt->content     = PT_LoadPage('videos/content', array(
    'TITLE' => $title,
    'VIDEOS' => $html_videos,
    'TYPE' => $page,
    'CATEGORY_ID' => $category_id,
    'TEXT' => $text

and the html file page has this:

<div class="test">HELLO{{TEXT}}</div>

Yet, all that is displayed is: HELLO

Any additional guidance is appreciated.


#26

What value of $page are you testing with?

What about changing this line:

$text = '';

to give it a value, something like “default” or “should not see this”. If it shows that text, you can see that something is not replacing it. What about the fourth possible value for $page in your original code, do you have the same line in there to assign a value?


#27

Much thanks again.

when I change to $text=‘default’;

the html page displays:

HELLOdefault

Can you please clarify/expand on what you mean by " What about the fourth possible value for $page in your original code, do you have the same line in there to assign a value?"

I look forward to hearing back from you


#28

In your first post, you have four different possible values for $page, and in the latest code where you create $text, you only showed that you had created it for three of them. I wondered whether you had missed it out of the post, or whether you have only added $text into three of them, but are testing with the fourth. Hence me asking what value of $page you were testing with.


#29

Thanks again for your reply. The fourth is still there. Haven’t changed anything with it. Any suggestions?
Here’s the full code:

<?php

if (empty($_GET['page'])) {
    header("Location: " . PT_Link('404'));
    exit();
}
$page         = PT_Secure($_GET['page']);
$limit        = 20;
$pt->rss_feed = false;
$pt->exp_feed = true;
$pages        = array(
    'trending',
    'category',
    'latest',
    'top'
);

if (!in_array($page, $pages)) {
    header("Location: " . PT_Link('404'));
    exit();
}

if (!empty($_GET['feed']) && $_GET['feed'] == 'rss') {
    $limit        = 50;
    $pt->rss_feed = true;

}

$text = 'default';
$category_id = '';
$videos = array();
if ($page == 'trending') {
    $title  = $lang->trending;
    $db->where('privacy', 0);
    $videos = $db->where('time', time() - 172800, '>')->orderBy('views', 'DESC')->get(T_VIDEOS, $limit);
$text = 'trending text here';
}

else if ($page == 'latest') {
    $title  = $lang->latest_videos;
    $db->where('privacy', 0);
    $videos = $db->orderBy('id', 'DESC')->get(T_VIDEOS, $limit);
$text = 'latest text here';
}

else if ($page == 'top') {
    $title  = $lang->top_videos;
    $db->where('privacy', 0);
    $videos = $db->orderBy('views', 'DESC')->get(T_VIDEOS, $limit);
$text = 'top text here';
}

else if ($page == 'category') {
    if (!empty($_GET['id'])) {
        if (in_array($_GET['id'], array_keys($categories))) {
            $category = PT_Secure($_GET['id']);
            $title    = $categories[$category];
            $category_id = "data-category='$category'";
            $db->where('privacy', 0);
            $videos   = $db->where('category_id', $category)->orderBy('id', 'DESC')->get(T_VIDEOS, $limit);
        } else {
            header("Location: " . PT_Link('404'));
            exit();
        }
    }
}

use Bhaktaraz\RSSGenerator\Item;
use Bhaktaraz\RSSGenerator\Feed;
use Bhaktaraz\RSSGenerator\Channel;


//Export rss feed
if ($pt->rss_feed) {
    $rss_feed_xml   = "";
    $fl_rss_feed    = new Feed();
    $fl_rss_channel = new Channel();


    $fl_rss_channel
        ->title($pt->config->title)
        ->description($pt->config->description)
        ->url($pt->config->site_url)
        ->appendTo($fl_rss_feed);

    if (is_array($videos)) {
        foreach ($videos as $feed_item_data) {
            $feed_item_data = PT_GetVideoByID($feed_item_data, 0, 0, 0);
            $fl_rss_item    = new Item();
            $fl_rss_item
             ->title($feed_item_data->title)
             ->description($feed_item_data->markup_description)
             ->url($feed_item_data->url)
             ->pubDate($feed_item_data->time)
             ->guid($feed_item_data->url,true)
             ->media(array(
                'attr'  => 'url',
                'ns'    => 'thumbnail',
                'link'  => PT_GetMedia($feed_item_data->org_thumbnail)))
             ->appendTo($fl_rss_channel);
        }
    }

    header('Content-type: text/rss+xml');
    echo($fl_rss_feed);
    exit();
}


$html_videos = '';
if (!empty($videos)) {
    foreach ($videos as $key => $video) {
    	$video = PT_GetVideoByID($video, 0, 0, 0);
        $html_videos .= PT_LoadPage('videos/list', array(
            'ID' => $video->id,
            'VID_ID' => $video->id,
	        'TITLE' => $video->title,
	        'VIEWS' => $video->views,
            'VIEWS_NUM' => number_format($video->views),
	        'USER_DATA' => $video->owner,
	        'THUMBNAIL' => $video->thumbnail,
	        'URL' => $video->url,
	        'TIME' => $video->time_ago,
            'DURATION' => $video->duration
        ));
    }
}

if (empty($videos)) {
	$html_videos = '<div class="text-center no-content-found empty_state"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-video-off"><path d="M16 16v1a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2h2m5.66 0H14a2 2 0 0 1 2 2v3.34l1 1L23 7v10"></path><line x1="1" y1="1" x2="23" y2="23"></line></svg>' . $lang->no_videos_found_for_now . '</div>';
}
$pt->videos_count= count($videos);
$pt->page        = $page;
$pt->title       = $title . ' | ' . $pt->config->title;
$pt->description = $pt->config->description;
$pt->keyword     = @$pt->config->keyword;
$pt->content     = PT_LoadPage('videos/content', array(
    'TITLE' => $title,
    'VIDEOS' => $html_videos,
    'TYPE' => $page,
    'CATEGORY_ID' => $category_id,
    'TEXT' => $text
));

#30

As mentioned in Post: #22 - use error reporting, etc and clear all errors and warnings before submitting the script or post the errors/warnings and ask for help.

A couple of other useful debugging features to try:

<?php 
var_dump( $valueToDisplay ); // displays contents of $valueToDisplay, can also be objects, arrays, etc

echo '<br> line ==> ' .__LINE__; // displays script line

die; // halts browser execution and display progress up to that point


#31

You don’t set a value for $text in the fourth one, though.

If you’re only testing the page for the one you haven’t added the code to, then you won’t see anything in the text string.


#32

Thanks for your replies.

When I add ‘category text here’ (to the fourth one) and var_dump($valueToDisplay); at the top of the page after <?php

I see NULL at the top right of blank page quickly, then I see the page (any of the three tested) with HELLOcategory text here:

$text = 'default';
$cateogry_id = '';
$videos = array();
if ($page == 'trending') {
    $title  = $lang->trending;
    $db->where('privacy', 0);
    $videos = $db->where('time', time() - 172800, '>')->orderBy('views', 'DESC')->get(T_VIDEOS, $limit);
    $text = 'trending text here';
}

else if ($page == 'latest') {
    $title  = $lang->latest_videos;
    $db->where('privacy', 0);
    $videos = $db->orderBy('id', 'DESC')->get(T_VIDEOS, $limit);
    $text = 'latest text here';
}

else if ($page == 'top') {
    $title  = $lang->top_videos;
    $db->where('privacy', 0);
    $videos = $db->orderBy('views', 'DESC')->get(T_VIDEOS, $limit);
    $text = 'top text here';
}

else if ($page == 'category') {
    if (!empty($_GET['id'])) {
        if (in_array($_GET['id'], array_keys($categories))) {
            $pt->page_url_ = $pt->config->site_url.'/videos/'.$page.'/'.$_GET['id'];
            $category = PT_Secure($_GET['id']);
            $title    = $categories[$category];
            $category_id = "data-category='$category'";

            if (!empty($_GET['sub_id'])) {
                 $is_found = $db->where('type',PT_Secure($_GET['id']))->where('lang_key',PT_Secure($_GET['sub_id']))->getValue(T_LANGS,'COUNT(*)');
                if ($is_found > 0) {
                    $pt->page_url_ = $pt->config->site_url.'/videos/'.$page.'/'.$_GET['id'].'/'.$_GET['sub_id'];
                    $db->where('sub_category', PT_Secure($_GET['sub_id']));
                }
            }
            $db->where('privacy', 0);
            $category_old = str_replace('category__', '', $category);
            $videos   = $db->where('category_id = "' . $category . '" OR category_id = "' . $category_old . '"')->orderBy('id', 'DESC')->get(T_VIDEOS, $limit);
			$text = 'category text here';

        } else {
            header("Location: " . PT_Link('404'));
            exit();
        }
    }
}

any additional help is appreciated


#33

As mentioned in post" #30

<?php 
// ...

echo '<br> line ==>  ' .__LINE__; die;

Adding the above will halt script execution and render prior output.


#34

Thanks for your reply.

I don’t know where to add your suggestion.

When I add it like so:

<?php

var_dump( $valueToDisplay ); // displays contents of $valueToDisplay, can also be objects, arrays, etc

echo '<br> line ==> ' .__LINE__; // displays script line

die; // halts browser execution and display progress up to that point

I see this:

NULL
line ==> 5


#35

Try moving the script further down to immediately after $text is declared and change value $valueToDisplay to $text.

Afterwards experiment by moving the lines further down… until you pinpoint the problem.

Goodnight


#36

Much thanks again for your guidance.

I tried this:

$text = 'default';
var_dump($text);

echo '<br> line ==> ' .__LINE__;

die;





$category_id = '';
$videos = array();
if ($page == 'trending') {
    $title  = $lang->trending;
    $db->where('privacy', 0);
    $videos = $db->where('time', time() - 172800, '>')->orderBy('views', 'DESC')->get(T_VIDEOS, $limit);
    $text = 'trending text here';
}

else if ($page == 'latest') {
    $title  = $lang->latest_videos;
    $db->where('privacy', 0);
    $videos = $db->orderBy('id', 'DESC')->get(T_VIDEOS, $limit);
    $text = 'latest text here';
}

else if ($page == 'top') {
    $title  = $lang->top_videos;
    $db->where('privacy', 0);
    $videos = $db->orderBy('views', 'DESC')->get(T_VIDEOS, $limit);
    $text = 'top text here';
}

else if ($page == 'category') {
    if (!empty($_GET['id'])) {
        if (in_array($_GET['id'], array_keys($categories))) {
            $pt->page_url_ = $pt->config->site_url.'/videos/'.$page.'/'.$_GET['id'];
            $category = PT_Secure($_GET['id']);
            $title    = $categories[$category];
            $category_id = "data-category='$category'";

            if (!empty($_GET['sub_id'])) {
                 $is_found = $db->where('type',PT_Secure($_GET['id']))->where('lang_key',PT_Secure($_GET['sub_id']))->getValue(T_LANGS,'COUNT(*)');
                if ($is_found > 0) {
                    $pt->page_url_ = $pt->config->site_url.'/videos/'.$page.'/'.$_GET['id'].'/'.$_GET['sub_id'];
                    $db->where('sub_category', PT_Secure($_GET['sub_id']));
                }
            }
            $db->where('privacy', 0);
            $category_old = str_replace('category__', '', $category);
            $videos   = $db->where('category_id = "' . $category . '" OR category_id = "' . $category_old . '"')->orderBy('id', 'DESC')->get(T_VIDEOS, $limit);
			$text = 'category text here';

        } else {
            header("Location: " . PT_Link('404'));
            exit();
        }
    }
}

and see this:

string(7) “default”
line ==> 37

I added:

var_dump($text);
echo ’
line ==> ’ .LINE;
die;

after each if and else if block of code and saw a blank html page. And when I added it after:

else if ($page == 'category') {
    if (!empty($_GET['id'])) {
        if (in_array($_GET['id'], array_keys($categories))) {
            $pt->page_url_ = $pt->config->site_url.'/videos/'.$page.'/'.$_GET['id'];
            $category = PT_Secure($_GET['id']);
            $title    = $categories[$category];
            $category_id = "data-category='$category'";

            if (!empty($_GET['sub_id'])) {
                 $is_found = $db->where('type',PT_Secure($_GET['id']))->where('lang_key',PT_Secure($_GET['sub_id']))->getValue(T_LANGS,'COUNT(*)');
                if ($is_found > 0) {
                    $pt->page_url_ = $pt->config->site_url.'/videos/'.$page.'/'.$_GET['id'].'/'.$_GET['sub_id'];
                    $db->where('sub_category', PT_Secure($_GET['sub_id']));
                }
            }
            $db->where('privacy', 0);
            $category_old = str_replace('category__', '', $category);
            $videos   = $db->where('category_id = "' . $category . '" OR category_id = "' . $category_old . '"')->orderBy('id', 'DESC')->get(T_VIDEOS, $limit);
			$text = 'category text here';

        } else {
            header("Location: " . PT_Link('404'));
            exit();
        }
    }
}

var_dump($text);

echo '<br> line ==> ' .__LINE__;

die;

I see this:

string(18) “category text here”
line ==> 91

I look forward to your comments


#37

[quote=“ChrisjChrisj, post:32, topic:320601”]
When I add ‘category text here’ (to the fourth one) and var_dump($valueToDisplay); at the top of the page after <?php

I see NULL at the top right of blank page quickly, [/quote]

Where does $valueToDisplay come from? I don’t see anywhere that you define that variable in your code, so why would you try to display it? @John_Betong uses that as an example, meaning that you’d put your variable name in that spot.

Any of the three categories, or one category, one trending, one top?

If that’s for any of three categories, then surely that is correct and is now doing what you want?


#38

Thanks for your reply.

I believe I defined it here:

$text = 'default'; 
var_dump($text); 
echo '<br> line ==> ' .__LINE__; 
die;

next to var_dump

the three categories, are ‘trending’, ‘top’, ‘latest’?

They all show “HELLO category test here”.
Ultimately I’d like
trending page to show the text ‘trending text here’
and
top page to show the text ‘top text here’
and
latest page to show ‘latest text here’

so, as far as I can see it’s not doing what I want, it’s showing the same text ‘category text here’ on all three pages.

I look forward to any additional replies/assistance


#39

What is/are the values of $page that you are testing with here?

I am a little confused by some of the terminology. You say

but are they categories in the sense that $page == "category" and “trending”, “top” or “latest” is denoted by $_GET['id'], or are the values of $page set to each of the above? By using “category” to describe them, it’s getting confusing.


#40

Thanks for your reply.
Sorry for any confusion.
there are just 3 categories.
category 1 is titled ‘latest’
category 2 is titled ‘trending’
category 3 is titled ‘top’

is that helpful?

I look forward to your comments/suggestions/remedy


#41

No. What is the value of $page for your testing? Is it always “category”, or is it one of the other values?