hesabixWpTheme/inc/brand.php

299 lines
10 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* دستورالعمل برند حسابیکس — URL، ایجاد برگه، دارایی‌ها
*
* حسابیکس محصول شرکت توسعه فناوری سرکش است.
*
* @package Hesabix2
*/
if (!defined('ABSPATH')) {
exit;
}
/**
* آدرس صفحهٔ برند.
*
* @return string
*/
function hesabix2_brand_page_url() {
static $cached = null;
if ($cached !== null) {
return $cached;
}
$pages = get_pages(
array(
'meta_key' => '_wp_page_template',
'meta_value' => 'page-brand.php',
'number' => 1,
)
);
$cached = !empty($pages)
? get_permalink($pages[0]->ID)
: home_url('/brand/');
return apply_filters('hesabix2_brand_page_url', $cached);
}
/**
* نام شرکت مالک برند.
*
* @return string
*/
function hesabix2_brand_company_name() {
return apply_filters('hesabix2_brand_company_name', __('شرکت توسعه فناوری سرکش', 'hesabix2'));
}
/**
* URL فایل دارایی برند داخل قالب.
*
* @param string $file نام فایل داخل assets/brand
* @return string
*/
function hesabix2_brand_asset_url($file) {
$file = ltrim((string) $file, '/');
return get_template_directory_uri() . '/assets/brand/' . $file;
}
/**
* عنوان و توضیح سئو.
*
* @return array{title: string, description: string}
*/
function hesabix2_brand_seo_meta() {
return array(
'title' => __('دستورالعمل برند حسابیکس', 'hesabix2'),
'description' => __('راهنمای استفاده از نام، نشان و هویت بصری حسابیکس — محصول شرکت توسعه فناوری سرکش — برای شرکا، رسانه‌ها و توسعه‌دهندگان.', 'hesabix2'),
);
}
/**
* پالت رنگ رسمی.
*
* @return array<int, array<string, string>>
*/
function hesabix2_brand_colors() {
$colors = array(
array(
'name' => __('سرکش نیوی', 'hesabix2'),
'role' => __('رنگ نشان', 'hesabix2'),
'hex' => '#001870',
'rgb' => '0, 24, 112',
'usage' => __('پس‌زمینهٔ نشان دایره‌ای؛ قوی‌ترین رنگ هویت.', 'hesabix2'),
'class' => 'navy',
),
array(
'name' => __('آسمان حسابیکس', 'hesabix2'),
'role' => __('رنگ محصول', 'hesabix2'),
'hex' => '#0EA5E9',
'rgb' => '14, 165, 233',
'usage' => __('دکمه‌ها، لینک‌ها و تاکید رابط کاربری آرک.', 'hesabix2'),
'class' => 'sky',
),
array(
'name' => __('آسمان عمیق', 'hesabix2'),
'role' => __('رنگ محصول تیره', 'hesabix2'),
'hex' => '#0284C7',
'rgb' => '2, 132, 199',
'usage' => __('حالت hover و گرادیان محصول.', 'hesabix2'),
'class' => 'sky-deep',
),
array(
'name' => __('نارنجی تاکید', 'hesabix2'),
'role' => __('رنگ کنش', 'hesabix2'),
'hex' => '#F97316',
'rgb' => '249, 115, 22',
'usage' => __('فراخوان عمل؛ هرگز جایگزین نشان نیوی نشود.', 'hesabix2'),
'class' => 'accent',
),
array(
'name' => __('مرکب', 'hesabix2'),
'role' => __('متن', 'hesabix2'),
'hex' => '#0F172A',
'rgb' => '15, 23, 42',
'usage' => __('متن اصلی روی زمینهٔ روشن.', 'hesabix2'),
'class' => 'ink',
),
array(
'name' => __('کاغذ', 'hesabix2'),
'role' => __('زمینه', 'hesabix2'),
'hex' => '#F8FAFC',
'rgb' => '248, 250, 252',
'usage' => __('پس‌زمینهٔ صفحات و نمونه‌های روشن نشان.', 'hesabix2'),
'class' => 'paper',
),
array(
'name' => __('سفید نشان', 'hesabix2'),
'role' => __('نماد روی نیوی', 'hesabix2'),
'hex' => '#F8F8F8',
'rgb' => '248, 248, 248',
'usage' => __('حرف داخل نشان؛ نزدیک به سفید خالص.', 'hesabix2'),
'class' => 'mark-white',
),
);
return apply_filters('hesabix2_brand_colors', $colors);
}
/**
* وزن‌های حروف‌نگاری یکان‌بخ.
*
* @return array<int, array{label: string, weight: int, sample: string}>
*/
function hesabix2_brand_type_weights() {
$weights = array(
array('label' => 'Thin', 'weight' => 100, 'sample' => __('حسابیکس', 'hesabix2')),
array('label' => 'Light', 'weight' => 300, 'sample' => __('حسابیکس', 'hesabix2')),
array('label' => 'Regular', 'weight' => 400, 'sample' => __('حسابیکس', 'hesabix2')),
array('label' => 'Semibold', 'weight' => 500, 'sample' => __('حسابیکس', 'hesabix2')),
array('label' => 'Bold', 'weight' => 700, 'sample' => __('حسابیکس', 'hesabix2')),
array('label' => 'Extrabold', 'weight' => 800, 'sample' => __('حسابیکس', 'hesabix2')),
array('label' => 'Black', 'weight' => 900, 'sample' => __('حسابیکس', 'hesabix2')),
);
return apply_filters('hesabix2_brand_type_weights', $weights);
}
/**
* فایل‌های قابل دانلود.
*
* @return array<int, array<string, string>>
*/
function hesabix2_brand_downloads() {
$items = array(
array(
'file' => 'hesabix-mark.svg',
'label' => __('نشان رنگی SVG', 'hesabix2'),
'meta' => __('نیوی + نماد روشن', 'hesabix2'),
),
array(
'file' => 'hesabix-mark.png',
'label' => __('نشان رنگی PNG', 'hesabix2'),
'meta' => '330×330',
),
array(
'file' => 'hesabix-mark-white.svg',
'label' => __('نماد سفید SVG', 'hesabix2'),
'meta' => __('برای زمینهٔ تیره', 'hesabix2'),
),
array(
'file' => 'hesabix-mark-navy.svg',
'label' => __('نماد نیوی SVG', 'hesabix2'),
'meta' => __('برای زمینهٔ روشن', 'hesabix2'),
),
array(
'file' => 'hesabix-mark-inverse.svg',
'label' => __('نشان معکوس SVG', 'hesabix2'),
'meta' => __('دایره روشن + نماد نیوی', 'hesabix2'),
),
array(
'file' => 'hesabix-mark-on-dark.svg',
'label' => __('نشان روی تیره SVG', 'hesabix2'),
'meta' => __('دایره مرکب', 'hesabix2'),
),
);
return apply_filters('hesabix2_brand_downloads', $items);
}
/**
* ایجاد یک‌بارهٔ برگهٔ برند.
*/
function hesabix2_maybe_create_brand_page() {
if (get_option('hesabix2_brand_page_created')) {
return;
}
$existing = get_pages(
array(
'meta_key' => '_wp_page_template',
'meta_value' => 'page-brand.php',
'number' => 1,
)
);
if (!empty($existing)) {
update_option('hesabix2_brand_page_created', 1);
return;
}
$by_path = get_page_by_path('brand');
if ($by_path) {
update_post_meta($by_path->ID, '_wp_page_template', 'page-brand.php');
update_option('hesabix2_brand_page_created', 1);
return;
}
$page_id = wp_insert_post(
array(
'post_title' => __('دستورالعمل برند', 'hesabix2'),
'post_name' => 'brand',
'post_status' => 'publish',
'post_type' => 'page',
'post_content' => '',
'post_excerpt' => __('نام، نشان و قوانین استفاده از هویت حسابیکس — محصول شرکت توسعه فناوری سرکش.', 'hesabix2'),
),
true
);
if (!is_wp_error($page_id) && $page_id) {
update_post_meta($page_id, '_wp_page_template', 'page-brand.php');
update_option('hesabix2_brand_page_created', 1);
}
}
add_action('after_setup_theme', 'hesabix2_maybe_create_brand_page', 36);
/**
* @param string $title
* @return string
*/
function hesabix2_brand_yoast_title($title) {
if (!is_page_template('page-brand.php')) {
return $title;
}
$meta = hesabix2_brand_seo_meta();
return $meta['title'] . ' | ' . get_bloginfo('name');
}
add_filter('wpseo_title', 'hesabix2_brand_yoast_title');
add_filter('wpseo_opengraph_title', 'hesabix2_brand_yoast_title');
/**
* @param string $desc
* @return string
*/
function hesabix2_brand_yoast_desc($desc) {
if (!is_page_template('page-brand.php')) {
return $desc;
}
return hesabix2_brand_seo_meta()['description'];
}
add_filter('wpseo_metadesc', 'hesabix2_brand_yoast_desc');
add_filter('wpseo_opengraph_desc', 'hesabix2_brand_yoast_desc');
/**
* @param array<string, string> $parts
* @return array<string, string>
*/
function hesabix2_brand_document_title($parts) {
if (is_page_template('page-brand.php')) {
$parts['title'] = hesabix2_brand_seo_meta()['title'];
}
return $parts;
}
add_filter('document_title_parts', 'hesabix2_brand_document_title', 20);
/**
* meta وقتی Yoast نیست.
*/
function hesabix2_brand_seo_head() {
if (!is_page_template('page-brand.php')) {
return;
}
if (function_exists('hesabix2_seo_yoast_active') && hesabix2_seo_yoast_active()) {
return;
}
$meta = hesabix2_brand_seo_meta();
$title = $meta['title'] . ' | ' . get_bloginfo('name');
$desc = $meta['description'];
$url = hesabix2_brand_page_url();
$image = hesabix2_brand_asset_url('hesabix-mark.png');
echo '<meta name="description" content="' . esc_attr($desc) . '" />' . "\n";
echo '<meta property="og:title" content="' . esc_attr($title) . '" />' . "\n";
echo '<meta property="og:description" content="' . esc_attr($desc) . '" />' . "\n";
echo '<meta property="og:type" content="article" />' . "\n";
echo '<meta property="og:url" content="' . esc_url($url) . '" />' . "\n";
echo '<meta property="og:image" content="' . esc_url($image) . '" />' . "\n";
}
add_action('wp_head', 'hesabix2_brand_seo_head', 5);