update to current services_mediatomb api
[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 (isset($arStation['epgtitle'])
24             && $arStation['epgtitle']
25             && $arStation['epgtitle'] != 'None'
26             && $arStation['epgtitle'] != $arStation['name']
27         ) {
28             if (strtolower(substr($arStation['epgtitle'], 0, strlen($strName))) == strtolower($strName)) {
29                 $strEpgTitle = substr($arStation['epgtitle'], strlen($strName));
30             } else if (strtolower(substr($arStation['epgtitle'], 0, strlen($arStation['name']))) == strtolower($arStation['name'])) {
31                 $strEpgTitle = substr($arStation['epgtitle'], strlen($arStation['name']));
32             } else {
33                 $strEpgTitle = $arStation['epgtitle'];
34             }
35             $strEpgTitle = trim($strEpgTitle);
36             if (substr($strEpgTitle, 0, 1) == '-') {
37                 $strEpgTitle = trim(substr($strEpgTitle, 1));
38             }
39
40             if (strtoupper($strEpgTitle) == $strEpgTitle) {
41                 $strEpgTitle = ucwords(strtolower($strEpgTitle));
42             }
43
44             $strName .= ' - ' . $strEpgTitle;
45         }
46
47         if (isset($arStation['epgdescription'])
48             && $arStation['epgdescription'] && $arStation['epgdescription'] != 'None'
49         ) {
50             $strDescription = $arStation['epgdescription'];
51         } else {
52             $strDescription = '';
53         }
54         if (isset($arStation['epgdescription2'])
55             && $arStation['epgdescription2'] && $arStation['epgdescription2'] != 'None'
56         ) {
57             $strDescription .= ' ' . $arStation['epgdescription2'];
58         }
59         if (!$strDescription) {
60             $strDescription = $strName;
61         }
62
63         return array(
64             'title'       => trim($strName),
65             'description' => trim($strDescription)
66         );
67     }//function enigtombGetStationTitle(..)
68 }
69
70
71
72 if (!function_exists('enigtombFixName')) {
73     /**
74     * Replaces the given name with a fixed one from the config.
75     * Necessary, because some stations send their names in ALL UPPERCASE
76     * which just isn't nicely readable.
77     *
78     * @param string $strName Name to fix
79     *
80     * @return string Fixed name
81     */
82     function enigtombFixName($strName)
83     {
84         $strName = trim($strName);
85         if (isset($GLOBALS['enigtombConfig']['namefixes'][$strName])) {
86             return $GLOBALS['enigtombConfig']['namefixes'][$strName];
87         } else {
88             return $strName;
89         }
90     }//function enigtombFixName(..)
91 }
92
93 ?>