<?php
/*
 * Created on 11.02.2012
 * Oliver Soop(osoop1@ut.ee)
 */
 
 include_once("XMLBaseTagger.php");
 include_once("../utils/StoryEnum.php");
 class YahooMediaTagger extends XMLBaseTagger {
 	protected static $nameSpace = "http://search.yahoo.com/mrss/";
 	protected static $prefix = "media";
 	protected static $mediaGroupTag = "group";
 	protected static $mediaContentTag = "content";
 	protected static $mediaRatingTag = "rating";
 	protected static $mediaTitleTag = "title";
 	protected static $mediaDescriptionTag = "description";
 	protected static $mediaKeywordsTag = "keywords";
 	protected static $mediaThumbnailTag = "thumbnail";
 	protected static $mediaCategoryTag = "category";
 	protected static $mediaHashTag = "hash";
 	protected static $mediaPlayerTag = "player";
 	protected static $mediaCreditTag = "credit";
 	protected static $mediaCreditTagRoleAttribute = "role";
 	protected static $mediaCopyrightTag = "copyright";
 	protected static $mediaTextTag = "text";
 	protected static $mediaRestrictionTag = "restriction";
 	protected static $mediaCommunityTag = "community";
 	protected static $mediaCommentsTag = "comments";
 	protected static $mediaCommentTag = "comment";
 	protected static $mediaEmbedTag = "embed";
 	protected static $mediaResponsesTag = "responses";
 	protected static $mediaResponseTag = "response";
 	protected static $mediaBackLinksTag = "backLinks";
 	protected static $mediaBackLinkTag = "backLink";
 	protected static $mediaStatusTag = "status";
 	protected static $mediaPriceTag = "price";
 	protected static $mediaLicenseTag = "license";
 	protected static $mediaSubtitleTag = "subTitle";
 	protected static $mediaPeerlinkTag = "peerLink";
 	protected static $mediaLocationTag = "location";
 	protected static $mediaRightsTag = "rights";
 	protected static $mediaScenesTag = "scenes";
 	
 	public function __construct() {
 		$this->name = "Yahoo Media";
 	}
 	
 	/**
	 * Funktsioon, millega etteantud Story objekti täiendatakse vastavalt algoritmile
	 */
	public function updateNewsStory($story, $domElement) {
 		$list = $domElement->getElementsByTagNameNS(YahooMediaTagger::$nameSpace, "*");
 		if($list->length == 0) {
 			return $story;
 		}
 		
 		foreach($list as $element) {
			if(strcasecmp($element->prefix, YahooMediaTagger::$prefix) != 0) {
 				continue;
 			}
 			
 			//Kuna need tag-id on osa ainult meedia elementidest ja mitte sisust, siis neid ei käsitle
 			switch ($element->localName) {
	 			case YahooMediaTagger::$mediaContentTag:
	 				continue;
	 			case YahooMediaTagger::$mediaTitleTag:
	 				continue;
	 			case YahooMediaTagger::$mediaDescriptionTag:
	 				continue;
	 			case YahooMediaTagger::$mediaCategoryTag:
	 				continue;
	 			case YahooMediaTagger::$mediaCreditTag:
	 				continue;
	 			default:
	 				continue;
	 		}
 			
		}
 		return $story;
 	}
 	
 	/**
 	 * Funktsioon, mis tagastab Yahoo Media märgenditele vastava Story objekti väärtuse
 	 */
 	public static function getStoryEnum($tag) {
 		if(strcasecmp($tag->prefix, YahooMediaTagger::$prefix) != 0) {
 			return null;
 		}
 		switch ($tag->localName) {
 			case YahooMediaTagger::$mediaContentTag:
 				return null;
 			case YahooMediaTagger::$mediaTitleTag:
 				return StoryEnum::TITLE;
 			case YahooMediaTagger::$mediaDescriptionTag:
 				return StoryEnum::DESCRIPTION;
 			case YahooMediaTagger::$mediaCategoryTag:
 				return StoryEnum::CATEGORY;
 			case YahooMediaTagger::$mediaCreditTag:
 				if(strcasecmp($tag->getAttribute($this->mediaCreditTagRoleAttribute), "author")){
 					return StoryEnum::AUTHOR;
 				}
 				return null;
 			
 			default:
 				return null;
 		}
 	}
 }
?>
