Site Builder
Editing:
_core.php
writable 0666
<?php // /amazon/_core.php // Minimal helpers: paths, sanitization, list rendering. function e($s){ return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); } function slugify($s){ return strtolower(trim(preg_replace('~[^a-z0-9]+~i','-', $s), '-')); } function asin_clean($s){ return strtoupper(preg_replace('~[^A-Z0-9]~','', $s)); } function product_dir_from_context(){ // for stubs that set $CATEGORY/$ASIN return __DIR__ . '/' . $GLOBALS['CATEGORY'] . '/' . $GLOBALS['ASIN']; } function product_json_path($category, $asin){ return __DIR__ . '/' . $category . '/' . $asin . '/product.json'; } function product_dir($category, $asin){ return __DIR__ . '/' . $category . '/' . $asin; } // Load product.json as array (manual mode) function load_product($category, $asin){ $path = product_json_path($category, $asin); if (!is_file($path)) return null; $raw = file_get_contents($path); $data = json_decode($raw, true); if (!is_array($data)) return null; // Normalize images to absolute web paths relative to the ASIN folder: $webBase = "/amazon/$category/$asin/"; if (!empty($data['images']) && is_array($data['images'])) { $fixed = []; foreach ($data['images'] as $img) { $fixed[] = (strpos($img, 'http')===0) ? $img : $webBase.ltrim($img,'/'); } $data['_image_srcs'] = $fixed; } else { $data['_image_srcs'] = []; } return $data; } function render_list($arr){ if (!$arr || !is_array($arr)) return ''; $out = "<ul>\n"; foreach ($arr as $li) $out .= '<li>'.e($li)."</li>\n"; return $out."</ul>\n"; } // Create a 1-line stub file for category or product (keeps portability) function write_category_stub($categoryDir){ if (!is_file("$categoryDir/index.php")) { $code = "<?php \$CATEGORY=basename(__DIR__); require __DIR__.'/../_core.php'; require __DIR__.'/../_templates/category.php';"; file_put_contents("$categoryDir/index.php", $code); } } function write_product_stub($productDir){ if (!is_file("$productDir/index.php")) { $code = "<?php \$ASIN=basename(__DIR__); \$CATEGORY=basename(dirname(__DIR__)); require __DIR__.'/../../_core.php'; require __DIR__.'/../../_templates/product.php';"; file_put_contents("$productDir/index.php", $code); } }
Save changes
Create folder
writable 0777
Create
Cancel