a63d8a0d2c5e8520b953144b55ddcf35e0f475fe
[enigtomb.git] / syncfunctions.php
1 <?php
2 /**
3 * Functions used in syncing
4 *
5 * @author Christian Weiske <cweiske@cweiske.de>
6 * @license  LGPL http://www.gnu.org/copyleft/lesser.html
7 */
8
9 if (!function_exists('enigtombGetStationTitle')) {
10     /**
11     * Returns a proper title from the bouqet station data
12     * for the mediatomb entry
13     *
14     * @param array $arStation Station in a dreambox bouqet
15     *
16     * @return array Array of title and description to use in the UPnP server.
17     *               Keys title and description
18     */
19     function enigtombGetStationTitle($arStation)
20     {
21         $strName = enigtombFixName($arStation['name']);
22
23         if ($arStation['epgtitle']
24             && $arStation['epgtitle'] != 'None'
25             && $arStation['epgtitle'] != $arStation['name']
26         ) {
27             if (strtolower(substr($arStation['epgtitle'], 0, strlen($strName))) == strtolower($strName)) {
28                 $strEpgTitle = substr($arStation['epgtitle'], strlen($strName));
29             } else if (strtolower(substr($arStation['epgtitle'], 0, strlen($arStation['name']))) == strtolower($arStation['name'])) {
30                 $strEpgTitle = substr($arStation['epgtitle'], strlen($arStation['name']));
31             } else {
32                 $strEpgTitle = $arStation['epgtitle'];
33             }
34             $strEpgTitle = trim($strEpgTitle);
35             if (substr($strEpgTitle, 0, 1) == '-') {
36                 $strEpgTitle = trim(substr($strEpgTitle, 1));
37             }
38
39             if (strtoupper($strEpgTitle) == $strEpgTitle) {
40                 $strEpgTitle = ucwords(strtolower($strEpgTitle));
41             }
42
43             $strName .= ' - ' . $strEpgTitle;
44         }
45
46         if ($arStation['epgdescription'] && $arStation['epgdescription'] != 'None') {
47             $strDescription = $arStation['epgdescription'];
48         } else {
49             $strDescription = '';
50         }
51         if ($arStation['epgdescription2'] && $arStation['epgdescription2'] != 'None') {
52             $strDescription .= ' ' . $arStation['epgdescription2'];
53         }
54         if (!$strDescription) {
55             $strDescription = $strName;
56         }
57
58         return array(
59             'title'       => trim($strName),
60             'description' => trim($strDescription)
61         );
62     }//function enigtombGetStationTitle(..)
63 }
64
65
66
67 if (!function_exists('enigtombFixName')) {
68     /**
69     * Replaces the given name with a fixed one from the config.
70     * Necessary, because some stations send their names in ALL UPPERCASE
71     * which just isn't nicely readable.
72     *
73     * @param string $strName Name to fix
74     *
75     * @return string Fixed name
76     */
77     function enigtombFixName($strName)
78     {
79         $strName = trim($strName);
80         if (isset($GLOBALS['enigtombConfig']['namefixes'][$strName])) {
81             return $GLOBALS['enigtombConfig']['namefixes'][$strName];
82         } else {
83             return $strName;
84         }
85     }//function enigtombFixName(..)
86 }
87
88 ?>