private function encodingToUtf8(&$text, $key, $encoding) { static $tr = array(); if (!is_string($text)) { return; } $text = Lms_Translate::translate($encoding, 'UTF-8', $text); }
public static function getFilm($params) { try { $filmId = (int) $params['film_id']; $user = Lms_User::getUser(); $db = Lms_Db::get('main'); if ($user->getId()) { $db->query('UPDATE users SET ViewActivity=ViewActivity+1 WHERE ID=?d', $user->getId()); } $avgHit = $db->selectCell('SELECT sum(Hit)/count(*) FROM films WHERE Hide=0'); $hitThreshold = round($avgHit * Lms_Application::getConfig('hit_factor')); $wheres = array(); if (!$user->isAllowed("film", "moderate")) { $wheres[] = " films.Hide=0 "; } $sql = "SELECT films.ID as film_id, " . "films.Name as name, " . "films.OriginalName as international_name, " . "films.Year as year, " . "films.RunTime as runtime, " . "films.Description as description, " . "films.MPAA as mpaa, " . "films.Resolution as resolution, " . "films.VideoInfo as video_info, " . "films.AudioInfo as audio_info, " . "films.Translation as translation, " . "films.Quality as quality, " . "films.CreateDate as create_date, " . "films.UpdateDate as update_date, " . "ROUND(films.ImdbRating/10, 1) as rating_imdb_value, " . "IF(LENGTH(films.imdbID)>0, CONCAT('http://www.imdb.com/title/', films.imdbID), '') as imdb_url, " . "films.Poster as poster, " . "films.BigPosters as big_posters, " . "films.Trailer as trailer, " . "films.TypeOfMovie as type_of_movie, " . "films.Hide as hide, " . "films.Hit as hit, " . "films.SoundTrack as soundtrack, " . "films.Links as links, " . "films.Present as present, " . "films.Group as `group`, " . "films.Frames as frames, " . "films.SmallFrames as small_frames, " . "ufr.Rating as rating_personal_value, " . "ROUND(films.LocalRating/10, 1) as rating_local_value, " . "films.LocalRatingDetail as rating_local_detail, " . "films.CountLocalRating as rating_local_count, " . "users.Login as moderator " . "FROM films " . " LEFT JOIN userfilmratings ufr ON (films.ID = ufr.FilmID AND ufr.UserID=?d) " . " LEFT JOIN users ON (films.Moderator=users.ID) WHERE films.ID=?d" . (count($wheres) ? " AND " . implode(' AND ', $wheres) . " " : ""); $film = $db->selectRow($sql, $user->getId(), $filmId); $result = array(); if ($film) { $film["popular"] = $film['hit'] > $hitThreshold ? true : false; $film["hide"] = $film['hide'] ? true : false; $film["international_name"] = htmlentities($film["international_name"], ENT_NOQUOTES, 'cp1252'); $film["genres"] = $db->selectCol('SELECT Name FROM filmgenres LEFT JOIN genres ON (genres.ID = filmgenres.GenreID) WHERE filmgenres.FilmID=?d', $filmId); $film["countries"] = $db->selectCol('SELECT Name FROM filmcountries LEFT JOIN countries ON (countries.ID = filmcountries.CountryID) WHERE filmcountries.FilmID=?d', $filmId); $rows = $db->select("SELECT persones.ID as person_id, persones.RusName as name, persones.OriginalName as international_name, persones.Images as old_photos, persones.Photos as photos, roles.Role as role, filmpersones.RoleExt as `character` FROM filmpersones LEFT JOIN roles ON (roles.ID = filmpersones.RoleID) LEFT JOIN persones ON (persones.ID = filmpersones.PersonID) WHERE filmpersones.FilmID=?d ORDER BY SortOrder, LENGTH(Images) DESC", $filmId); $persones = array(); foreach ($rows as $row) { $personId = $row['person_id']; if ($row["role"] == "режиссер") { $film['directors'][] = trim($row["name"]) ? $row["name"] : $row["international_name"]; } $persones[$personId]['person_id'] = $personId; $persones[$personId]['name'] = $row["name"]; $persones[$personId]['international_name'] = $row["international_name"]; $persones[$personId]['names'] = array_values(array_filter(array(trim($row["name"]), trim($row["international_name"])))); $photos = array_values(array_filter(array_merge(preg_split("/(\r\n|\r|\n)/", $row["photos"]), preg_split("/(\r\n|\r|\n)/", $row["old_photos"])))); $photo = array_shift($photos); if ($photo) { $photo = Lms_Application::thumbnail($photo, $width = 90, $height = 0, $defer = true); } $persones[$personId]['photo'] = $photo; $persones[$personId]['roles'][] = array("role" => $row["role"], "character" => $row["character"]); } $film['persones'] = array_values($persones); $covers = array_values(array_filter(array_merge(preg_split("/(\r\n|\r|\n)/", $film["big_posters"]), preg_split("/(\r\n|\r|\n)/", $film["poster"])))); $film["cover"] = array_shift($covers); if ($film["cover"]) { $film["cover"] = Lms_Application::thumbnail($film["cover"], $width = 200, $height = 0); } $film["frames"] = preg_split("/(\r\n|\r|\n)/", $film["frames"]); if ($film["frames"]) { //TODO: delete frame_width, frame_height list($width, $height) = getimagesize(dirname(APP_ROOT) . '/' . $film["frames"][0]); $film["frame_width"] = $width; $film["frame_height"] = $height; $film["small_frames"] = array(); foreach ($film["frames"] as $frame) { $film["small_frames"][] = Lms_Application::thumbnail($frame, $width = 225, $height); $film["small_frame_width"] = $width; $film["small_frame_height"] = $height; } } $film["comments_count"] = $db->selectCell("SELECT count(*) as count FROM comments WHERE FilmID=?d AND (ISNULL(ToUserID) OR ToUserID=0 {OR ToUserID=?d OR UserID=?d})", $filmId, $user->getId() ? $user->getId() : DBSIMPLE_SKIP, $user->getId() ? $user->getId() : DBSIMPLE_SKIP); $rows = $db->select("SELECT ID as file_id, Name as name, Path as path, Size as `size`, ed2kLink as ed2k_link, dcppLink as dcpp_link FROM files WHERE FilmID=?d ORDER BY Path", $filmId); $files = array(); foreach ($rows as $row) { $links = array(); if (Lms_Application::getConfig('download', 'license')) { $v = Lms_Application::getLeechProtectionCode(array($filmId, $row["file_id"], $user->getId())); $links['license'] = "pl.php?player=ftp&uid=" . $user->getId() . "&filmid={$filmId}&fileid=" . $row["file_id"] . "&v={$v}"; } else { $links['download'] = str_replace(Lms_Application::getConfig('source'), Lms_Application::getConfig('ftp'), $row['path']); if ($encoding = Lms_Application::getConfig('download', 'escape', 'encoding')) { $links['download'] = Lms_Translate::translate('CP1251', $encoding, $links['download']); } if (Lms_Application::getConfig('download', 'escape', 'enabled')) { $t = explode("/", $links['download']); for ($i = 3; $i < count($t); $i++) { $t[$i] = rawurlencode($t[$i]); } $links['download'] = implode("/", $t); } } if ($row['ed2k_link']) { $links['ed2k'] = $row['ed2k_link']; } if ($row['dcpp_link']) { $links['dcpp'] = $row['dcpp_link']; } $files[] = array('file_id' => $row['file_id'], 'name' => $row['name'], 'size' => $row['size'], 'links' => $links); } $film['files'] = $files; if (Lms_Application::getConfig('smb')) { $mode = $user->getMode(); if (Lms_Application::getConfig('modes', $mode, 'smb')) { $film['smb'] = 1; } } if ($film["group"]) { $films = $db->select("SELECT ID as film_id, Name as name, " . " OriginalName as international_name, " . " Year as year, " . " CONCAT(BigPosters, '\n', Poster) as `covers` " . "FROM films " . "WHERE `Group`=? AND ID!=?d {AND films.Hide=?d} " . "ORDER BY Year", $film["group"], $filmId, $user->isAllowed("film", "moderate") ? DBSIMPLE_SKIP : 0); Lms_Item_Film::postProcess($films, 90); $film['other_films'] = $films; } } else { $film = null; } $result['film'] = $film; return new Lms_Api_Response(200, null, $result); } catch (Exception $e) { return new Lms_Api_Response(500, $e->getMessage()); } }
/** * Encode string to $internalEncoding * * @param string $fileUrl * @return srting */ public static function encodeUrl($fileUrl) { return Lms_Translate::translate(self::$internalEncoding, self::getEncoding($fileUrl), $fileUrl); }
<?php /** * @copyright 2006-2011 LanMediaService, Ltd. * @license http://www.lanmediaservice.com/license/1_0.txt * @author Ilya Spesivtsev <*****@*****.**> * @version $Id: api.php 700 2011-06-10 08:40:53Z macondos $ */ if (!isset($_GET['q'])) { exit; } require_once dirname(__FILE__) . "/app/config.php"; $query = Lms_Translate::translate('UTF-8', 'CP1251', $_GET['q']); $_POST['action'][0] = 'Video.getSuggestion'; $_POST['query'][0] = $query; $_GET['format'] = 'json'; Lms_Application::runApi(); header("Pragma: private"); header("Cache-Control: private"); header("Expires: " . date("r", time() + 600));