<?php

/* CLASS FILE
----------------------------------*/

class social extends db {

  public $json;
  public $settings;

  public function structured($data = []) {
    $html = '';
    $prs = social::params('struct');
    $ar = array(
      'fb' => array(
        '{name}' => (isset($data['fb']['site']) ? $data['fb']['site'] : ''),
        '{url}' => (isset($data['fb']['url']) ? $data['fb']['url'] : ''),
        '{title}' => (isset($data['fb']['title']) ? $data['fb']['title'] : ''),
        '{desc}' => (isset($data['fb']['desc']) ? $data['fb']['desc'] : ''),
        '{image}' => (isset($data['fb']['image']) ? $data['fb']['image'] : '')
      )
    );
    if (isset($prs['struct']['fb']) && $prs['struct']['fb'] == 'yes') {
      if (isset($data['fb']['img-path']) && file_exists($data['fb']['img-path'])) {
        $dims = getimagesize($data['fb']['img-path']);
      }
      $ar['fb']['{height}'] = (isset($dims[1]) ? $dims[1] : '0');
      $ar['fb']['{width}'] = (isset($dims[0]) ? $dims[0] : '0');
      $html = strtr(mswTmp(PATH . THEME_FOLDER . '/html/social/social-meta-facebook' . (mswSSL() == 'yes' ? '-ssl' : '') . '.htm'), $ar['fb']) . mswNL();
    }
    return ltrim($html);
  }

  public function params($flag = 'all') {
    $arr = [];
    switch($flag) {
      case 'all':
        $Q   = db::db_query("SELECT `desc`, `param`, `value` FROM `" . DB_PREFIX . "social`");
        break;
      default:
        $Q   = db::db_query("SELECT `desc`, `param`, `value` FROM `" . DB_PREFIX . "social` WHERE `desc` = '{$flag}'");
        break;
    }
    while ($PAR = db::db_object($Q)) {
      $arr[$PAR->desc][$PAR->param] = $PAR->value;
    }
    return $arr;
  }
}

?>