added on local at 2026-07-01 21:46:54
| 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 | #====================================================================== | |
| 8 | use strict; | |
| 9 | use warnings; | |
| 10 | ||
| 11 | use lib '/var/www/vhosts/3dshawn.com/repricer.3dshawn.com'; | |
| 12 | use CGI; | |
| 13 | use MODS::Template; | |
| 14 | use MODS::DBConnect; | |
| 15 | use MODS::Login; | |
| 16 | use MODS::RePricer::Config; | |
| 17 | use MODS::RePricer::Wrapper; | |
| 18 | use MODS::RePricer::Admin; | |
| 19 | use MODS::RePricer::SEO; | |
| 20 | ||
| 21 | my $q = CGI->new; | |
| 22 | my $form = $q->Vars; | |
| 23 | my $auth = MODS::Login->new; | |
| 24 | my $wrap = MODS::RePricer::Wrapper->new; | |
| 25 | my $tfile = MODS::Template->new; | |
| 26 | my $db = MODS::DBConnect->new; | |
| 27 | my $cfg = MODS::RePricer::Config->new; | |
| 28 | my $admin = MODS::RePricer::Admin->new; | |
| 29 | my $seo = MODS::RePricer::SEO->new; | |
| 30 | my $DB = $cfg->settings('database_name'); | |
| 31 | ||
| 32 | $|=1; | |
| 33 | my $userinfo = $auth->login_verify(); | |
| 34 | if (!$userinfo) { | |
| 35 | print "Status: 302 Found\nLocation: /login.cgi\n\n"; | |
| 36 | exit; | |
| 37 | } | |
| 38 | $admin->require_admin($userinfo); | |
| 39 | require MODS::RePricer::Permissions; | |
| 40 | MODS::RePricer::Permissions->new->require_feature($userinfo, 'admin_view_seo'); | |
| 41 | ||
| 42 | my $admin_id = $userinfo->{user_id}; | |
| 43 | $admin_id =~ s/[^0-9]//g; | |
| 44 | ||
| 45 | my $dbh = $db->db_connect(); | |
| 46 | my $schema_ready = $seo->platform_settings_ready($db, $dbh, $DB); | |
| 47 | ||
| 48 | # Save path. Each seo.* key becomes its own platform_settings row. | |
| 49 | my $flash_kind = ''; my $flash_msg = ''; | |
| 50 | if ($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 | ||
| 68 | my $settings = $schema_ready ? $seo->get_platform_settings($db, $dbh, $DB) : {}; | |
| 69 | ||
| 70 | $db->db_disconnect($dbh); | |
| 71 | ||
| 72 | sub _h { | |
| 73 | my $s = shift; $s //= ''; | |
| 74 | $s =~ s/&/&/g; $s =~ s/</</g; $s =~ s/>/>/g; $s =~ s/"/"/g; | |
| 75 | return $s; | |
| 76 | } | |
| 77 | ||
| 78 | my $robots_on = (defined $settings->{'seo.robots_index'} && $settings->{'seo.robots_index'} eq '0') ? 0 : 1; | |
| 79 | my $card = $settings->{'seo.twitter_card'} || 'summary_large_image'; | |
| 80 | ||
| 81 | my $preview_title = $settings->{'seo.title'} || 'RePricer'; | |
| 82 | my $preview_desc = $settings->{'seo.description'} || ''; | |
| 83 | my $preview_url = $settings->{'seo.canonical_base'} || 'https://repricer.3dshawn.com'; | |
| 84 | ||
| 85 | my $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 | ||
| 112 | print "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 | ||
| 114 | my $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 · SEO', | |
| 120 | body => $body, | |
| 121 | }); |