Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URW-189 Open Graph tags #179

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open

Conversation

Kenneth-W-Chen
Copy link
Member

Adds Open Graph tags to every page. These tags are used for embeds on social media and certain messaging platforms, like Facebook and Discord.

This PR adds the required tags. The only optional tag added is site_name .

Also fixes 2 bugs in /template/top.php:

  1. MySQL connection was failing because the MySQL socket address wasn't passed to mysqli->connect().
  2. auth was set to true due to null being a falsy value.

activities.php Outdated Show resolved Hide resolved
template/header.php Outdated Show resolved Hide resolved
template/header.php Outdated Show resolved Hide resolved
template/header.php Outdated Show resolved Hide resolved
template/header.php Outdated Show resolved Hide resolved
@@ -1,6 +1,6 @@
<?php
require('../../template/top.php');
head('Merch Ordered', true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change shouldn't be needed, since it's just passing in defaults, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default description is null which puts the default description. Putting an empty string sets the OG description to be empty.

@@ -3,7 +3,7 @@
require(BASE . '/api/discord/bots/admin.php');
//require(BASE . '/api/google/count_majors.php');

head('About Us', true);
head('About Us', true, false, false, "UNT Robotics is a broad engineering student organization at the University of North Texas. We focus on developing student's skills in engineering &amp; robotics, which involves a range of beginner workshops, industry talks, robotics-based hackathons, recreational projects and competitions.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how I feel about having these as function args...

What if we create two new classes:
HeadingConfig which contains the auth, return, and the second class OpenGraphConfig

That way this ugliness of stacking params should be fixed and instead we'll have a nicer way to specify something like

$config = {
  auth: false,
  og: $og_config
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it go in template/top.php or in a separate file in template/classes/?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each would be its own new class under template/classes and head would take a single argument of $config

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you instantiate objects in PHP like that? The only way I can see to get a similar instantiation is if it's an array. As an object, it ends up moving the messy stacking of params into a constructor instead of the head function like this:

$og_config = new OpenGraphConfig('UNT Robotics is a broad engineering...', 'images/og-image-2.png');
$config = new HeadingConfig('About Us', true, true, false, $og_config);
head($config);

I don't think that's any better than extracting the params into separate variables and passing the variables instead of values.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do some platforms require a square og image? I vaguely recall from my days of setting up og at NT Daily that I had to specify a square image for facebook or twitter

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think twitter has a specific tag since the rectangle image gets cropped. https://devcommunity.x.com/t/twitter-card-for-open-graph/149336

You can specify the width and height for the image too. With Facebook it helps it load properly apparently? https://developers.facebook.com/docs/sharing/webmasters/#images

I'll try messing around with a square image

head("Buy {$product->get_name()}", true);

preg_match("@^(.+?)•@ims", $catalog_product->get_description(), $m);
//var_dump($m);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the debugging code

@@ -2,7 +2,7 @@
require('../template/top.php');
require(BASE . '/api/printful/printful.php');
require(BASE . '/template/functions/functions.php');
require(BASE . '/template/functions/payment_button.php');
//require(BASE . '/template/functions/payment_button.php');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this commented out?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was throwing an error when I pushed it to the dev site (probably because I deleted the file)

@@ -289,7 +290,7 @@ class="btn variant-btn"
'variant' => $selected_variant->get_id()
));

$payment_button = new PaymentButton(
/* $payment_button = new PaymentButton(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If any code is commented, it needs to:

  • Have a TODO or FIXME comment, with a backlog ticket number to address the issue that led to it being commented out
  • Or be considered dead code and just deleted (the nice thing about git is we can still find dead and deleted code from the past)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants