<?php

/*
  PHP version 5
  Copyright (c) 2002-2019ECISP.CN、EarcLink.COM
  警告：这不是一个免费的软件，请在许可范围内使用，请尊重知识产权，侵权必究，举报有奖
  作者：黄祥云 E-mail:6326420@qq.com  QQ:6326420 TEL:18665655030 / 13797552220
*/



namespace modul_application;

use inc_application\link\ArticleLink;

class KeywordsOptimizationDB {

	public static function get_keywords_optimization_view($kid = false, $keywordname = false, $return_key = false) {
		if ((empty($kid) || !espcms_ismatches($kid)) && !$keywordname) {
			return false;
		}
		$db_where = $kid && espcms_ismatches($kid) ? "WHERE kid=$kid" : "WHERE keywordname='$keywordname'";
		$db_table = ESPCMS_DB_PREFIX . 'keylink';
		$talbe_field_array = espcms_field_out($db_table, false);
		$read_info = espcms_db_read($db_table, $db_where, $talbe_field_array);
		if (!$read_info) {
			return false;
		}
		return !$return_key ? $read_info : $read_info[$return_key];
	}

	public static function get_key_link($key_array = false) {
		if (!$key_array) {
			return array();
		}
		if (is_array($key_array) && count($key_array) > 0) {
			$key_array = array_unique($key_array);
			if (count($key_array) <= 0) {
				return array();
			}
			foreach ($key_array as $key => $value) {
				$TagArray[$key]['title'] = $value;
				$TagArray[$key]['keywordname'] = $value;
				$TagArray[$key]['link'] = ArticleLink::tags_link($TagArray[$key]);
			}
		} else {
			$key_array = array_unique(explode(',', $key_array));
			if (count($key_array) <= 0) {
				return array();
			}
			foreach ($key_array as $key => $value) {
				$TagArray[$key]['title'] = $value;
				$TagArray[$key]['keywordname'] = $value;
				$TagArray[$key]['link'] = ArticleLink::tags_link($TagArray[$key]);
			}
		}
		return $TagArray;
	}

}
