Diff -- /var/www/vhosts/3dshawn.com/repricer.3dshawn.com/admin_seo.cgi
Diff

/var/www/vhosts/3dshawn.com/repricer.3dshawn.com/admin_seo.cgi

added on local at 2026-07-01 21:46:54

Added
+121
lines
Removed
-0
lines
Context
0
unchanged
Blobs
from
to c993c3c88548
Restore this content →
Unified diff
Naive LCS-based line diff. Additions in emerald, deletions in rose. Both sides decompressed live from BLOB_STORE.
1#!/usr/bin/perl
2#======================================================================
3# RePricer - Admin SEO editor
4#
5# Platform-wide SEO settings (admin-only). Drives the meta tags on the
6# RePricer marketing pages + dashboard chrome via MODS::RePricer::SEO.
7#======================================================================
8use strict;
9use warnings;
10
11use lib '/var/www/vhosts/3dshawn.com/repricer.3dshawn.com';
12use CGI;
13use MODS::Template;
14use MODS::DBConnect;
15use MODS::Login;
16use MODS::RePricer::Config;
17use MODS::RePricer::Wrapper;
18use MODS::RePricer::Admin;
19use MODS::RePricer::SEO;
20
21my $q = CGI->new;
22my $form = $q->Vars;
23my $auth = MODS::Login->new;
24my $wrap = MODS::RePricer::Wrapper->new;
25my $tfile = MODS::Template->new;
26my $db = MODS::DBConnect->new;
27my $cfg = MODS::RePricer::Config->new;
28my $admin = MODS::RePricer::Admin->new;
29my $seo = MODS::RePricer::SEO->new;
30my $DB = $cfg->settings('database_name');
31
32$|=1;
33my $userinfo = $auth->login_verify();
34if (!$userinfo) {
35 print "Status: 302 Found\nLocation: /login.cgi\n\n";
36 exit;
37}
38$admin->require_admin($userinfo);
39require MODS::RePricer::Permissions;
40MODS::RePricer::Permissions->new->require_feature($userinfo, 'admin_view_seo');
41
42my $admin_id = $userinfo->{user_id};
43$admin_id =~ s/[^0-9]//g;
44
45my $dbh = $db->db_connect();
46my $schema_ready = $seo->platform_settings_ready($db, $dbh, $DB);
47
48# Save path. Each seo.* key becomes its own platform_settings row.
49my $flash_kind = ''; my $flash_msg = '';
50if ($schema_ready && $form->{act} && $form->{act} eq 'save') {
51 my @keys = qw(
52 seo.title seo.description seo.keywords seo.og_image
53 seo.og_site_name seo.twitter_card seo.twitter_site
54 seo.canonical_base
55 );
56 foreach my $k (@keys) {
57 my $form_key = $k; $form_key =~ s/\./_/g;
58 $seo->set_platform_setting($db, $dbh, $DB, $k, $form->{$form_key}, $admin_id);
59 }
60 # Boolean robots toggle: checkbox absent = 0, present = 1.
61 my $robots_val = ($form->{seo_robots_index} ? '1' : '0');
62 $seo->set_platform_setting($db, $dbh, $DB, 'seo.robots_index', $robots_val, $admin_id);
63
64 $flash_kind = 'ok';
65 $flash_msg = 'Platform SEO settings saved.';
66}
67
68my $settings = $schema_ready ? $seo->get_platform_settings($db, $dbh, $DB) : {};
69
70$db->db_disconnect($dbh);
71
72sub _h {
73 my $s = shift; $s //= '';
74 $s =~ s/&/&amp;/g; $s =~ s/</&lt;/g; $s =~ s/>/&gt;/g; $s =~ s/"/&quot;/g;
75 return $s;
76}
77
78my $robots_on = (defined $settings->{'seo.robots_index'} && $settings->{'seo.robots_index'} eq '0') ? 0 : 1;
79my $card = $settings->{'seo.twitter_card'} || 'summary_large_image';
80
81my $preview_title = $settings->{'seo.title'} || 'RePricer';
82my $preview_desc = $settings->{'seo.description'} || '';
83my $preview_url = $settings->{'seo.canonical_base'} || 'https://repricer.3dshawn.com';
84
85my $tvars = {
86 user_id => $admin_id,
87 schema_ready => $schema_ready ? 1 : 0,
88 schema_missing => $schema_ready ? 0 : 1,
89
90 seo_title => _h($settings->{'seo.title'} // ''),
91 seo_description => _h($settings->{'seo.description'} // ''),
92 seo_keywords => _h($settings->{'seo.keywords'} // ''),
93 seo_og_image => _h($settings->{'seo.og_image'} // ''),
94 seo_og_site_name => _h($settings->{'seo.og_site_name'} // 'RePricer'),
95 seo_twitter_card => $card,
96 seo_twitter_site => _h($settings->{'seo.twitter_site'} // ''),
97 seo_canonical_base => _h($settings->{'seo.canonical_base'} // 'https://repricer.3dshawn.com'),
98
99 is_robots_on => $robots_on,
100 is_card_summary => ($card eq 'summary') ? 1 : 0,
101 is_card_large => ($card eq 'summary_large_image') ? 1 : 0,
102
103 preview_title => _h(substr($preview_title, 0, 60)),
104 preview_desc => _h(substr($preview_desc, 0, 160)),
105 preview_url => _h($preview_url),
106
107 flash_kind => $flash_kind,
108 flash_msg => _h($flash_msg),
109 has_flash => $flash_msg ne '' ? 1 : 0,
110};
111
112print "Content-Type: text/html; charset=utf-8\nCache-Control: no-store, no-cache, must-revalidate, max-age=0\nPragma: no-cache\nExpires: 0\n\n";
113
114my $body = join('', $tfile->template('repricer_admin_seo.html', $tvars, $userinfo));
115
116$wrap->render({
117 userinfo => $userinfo,
118 page_key => 'admin_seo',
119 title => 'Admin &middot; SEO',
120 body => $body,
121});
Keyboard: j next diff k previous diff g top G bottom r restore c compile-check ? help