PageRenderTime 49ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/services/services.php

https://github.com/jinzora/jinzora3
PHP | 334 lines | 212 code | 30 blank | 92 comment | 42 complexity | bdc64fdb20ff277f190efbc96c0abd00 MD5 | raw file
  1. <?php if (!defined(JZ_SECURE_ACCESS)) die ('Security breach detected.');
  2. /**
  3. * - JINZORA | Web-based Media Streamer -
  4. *
  5. * Jinzora is a Web-based media streamer, primarily desgined to stream MP3s
  6. * (but can be used for any media file that can stream from HTTP).
  7. * Jinzora can be integrated into a CMS site, run as a standalone application,
  8. * or integrated into any PHP website. It is released under the GNU GPL.
  9. *
  10. * - Resources -
  11. * - Jinzora Author: Ross Carlson <ross@jasbone.com>
  12. * - Web: http://www.jinzora.org
  13. * - Documentation: http://www.jinzora.org/docs
  14. * - Support: http://www.jinzora.org/forum
  15. * - Downloads: http://www.jinzora.org/downloads
  16. * - License: GNU GPL <http://www.gnu.org/copyleft/gpl.html>
  17. *
  18. * - Contributors -
  19. * Please see http://www.jinzora.org/team.html
  20. *
  21. * - Code Purpose -
  22. * - These are auxilary functions for the services.
  23. *
  24. * @since 01.14.05
  25. * @author Ross Carlson <ross@jinzora.org>
  26. * @author Ben Dodson <ben@jinzora.org>
  27. */
  28. /*
  29. * Gets all available CMS's as an array of:
  30. * cms_type => CMS Display Name.
  31. * The order should be sensible- please leave Standalone at the top.
  32. *
  33. * @author Ben Dodson
  34. * @since 6/26/06
  35. */
  36. function getAllCMS() {
  37. $cms = array();
  38. $cms['standalone'] = 'Standalone';
  39. $cms['cpgnuke'] = 'CPGNuke';
  40. $cms['e107'] = 'e107';
  41. $cms['geeklog'] = 'Geeklog';
  42. $cms['mambo'] = 'Joomla-Mambo';
  43. $cms['mdpro'] = 'MDPro';
  44. $cms['phpnuke'] = 'PHPNuke';
  45. $cms['postnuke'] = 'POSTNuke';
  46. $cms['xoops'] = 'XooPS';
  47. return $cms;
  48. }
  49. /* Seperates matches from nonmatches.
  50. * The array returned is of the form:
  51. * $array['matches']
  52. * $array['nonmatches']
  53. * Where $array['matches'] is an array of jzMediaNodes
  54. * and $array['nonmatches'] is an array of strings.
  55. *
  56. * @author Ben Dodson
  57. * @since 1/14/05
  58. * @version 1/16/05
  59. **/
  60. function seperateSimilar($array) {
  61. if (!is_array($array) || sizeof($array) == 0) {
  62. $ret = array();
  63. $ret['nonmatches'] = array();
  64. $ret['matches'] = array();
  65. return $ret;
  66. }
  67. // We don't want more artists in the array than we came with.
  68. // The searching is what actually needs to be improved (with operator = "exact-or")
  69. $ret = array();
  70. $root = new jzMediaNode();
  71. $found = $root->search($array,"nodes",distanceTo('artist'),sizeof($array),"or");
  72. $ret['matches'] = $found;
  73. // Now let's remove the matches:
  74. $matches = array();
  75. foreach ($found as $e) {
  76. $matches[] = $e->getName();
  77. }
  78. $nonmatches = array();
  79. foreach ($array as $entry) {
  80. $foundit = false;
  81. foreach ($matches as $match) {
  82. if (0 == strcmp(strtolower($match),strtolower($entry))) {
  83. // Found it
  84. $foundit = true;
  85. break;
  86. }
  87. }
  88. if (!$foundit) {
  89. $nonmatches[] = $entry;
  90. }
  91. }
  92. $ret['nonmatches'] = $nonmatches;
  93. return $ret;
  94. }
  95. /**
  96. * Writes out the meta data of an album
  97. *
  98. * @author Ross Carlson
  99. * @version 08/10/04
  100. * @param $node The node we are looking at
  101. * @param $year The year of the album
  102. * @param $image The URL of the image for the album
  103. * @param $tracks The list of tracks for the album (an array)
  104. * @param $review The review or discription of the album
  105. * @param $rating The rating of the album in number of stars (1-5)
  106. * @param $price The price of the album
  107. * @param $genre The genre of the album
  108. * @param $displayOutput Should we display output while writing?
  109. */
  110. function writeAlbumMetaData($node, $year=false, $image=false, $tracks=false, $review=false, $rating=false, $price=false, $genre=false, $displayOutput=false, $write_now = false){
  111. global $web_root, $root_dir, $media_dir, $audio_types, $allow_id3_modify, $allow_filesystem_modify, $include_path, $backend;
  112. // Ok, now let's write out the description
  113. if ($review){
  114. if ($displayOutput){
  115. ?>
  116. <SCRIPT LANGUAGE=JAVASCRIPT><!--\
  117. ars.innerHTML = 'Status: Writing Review';
  118. -->
  119. </SCRIPT>
  120. <?php
  121. flushdisplay();
  122. }
  123. // Now let's write this data to the node
  124. $node->addDescription($review);
  125. // Now let's write it to a file if we should
  126. if ($allow_filesystem_modify == "true" and !stristr($backend,"id3")){
  127. $bioFile = $node->getFilePath(). "/album-desc.txt";
  128. $handle = @fopen($bioFile, "w");
  129. @fwrite($handle,$review);
  130. @fclose($handle);
  131. }
  132. }
  133. // Now let's write out the image
  134. if (stristr($image,".jpg")){
  135. include_once($include_path. "lib/snoopy.class.php");
  136. $snoopy = new Snoopy;
  137. $snoopy->fetch($image);
  138. $imageData = $snoopy->results;
  139. unset($snoopy);
  140. // Now let's make sure that was valid
  141. if (strlen($imageData) < 1000){
  142. $imageData = "";
  143. }
  144. } else {
  145. $imageData = "";
  146. }
  147. // Now let's write it out
  148. if ($imageData <> ""){
  149. if ($displayOutput){
  150. ?>
  151. <SCRIPT LANGUAGE=JAVASCRIPT><!--\
  152. ars.innerHTML = 'Status: Writing Album Image';
  153. -->
  154. </SCRIPT>
  155. <?php
  156. flushdisplay();
  157. }
  158. // Ok, now can we write to the filesystem?
  159. if ($allow_filesystem_modify == "false" or stristr($backend,"id3")){
  160. $imgFile = $include_path. "data/images/". pathize(str_replace("/","--",$node->getPath("String")),''). "--". pathize($node->getName(),''). ".jpg";
  161. } else {
  162. $imgFile = $node->getFilePath(). "/". $node->getName(). ".jpg";
  163. }
  164. // Now let's write it out
  165. if (writeImage($imgFile, $imageData)){
  166. $node->addMainArt($imgFile);
  167. }
  168. if ($displayOutput){
  169. ?>
  170. <SCRIPT LANGUAGE=JAVASCRIPT><!--\
  171. ars.innerHTML = 'Status: Writing Album Image - Success';
  172. -->
  173. </SCRIPT>
  174. <?php
  175. flushdisplay();
  176. }
  177. $retVal=1;
  178. }
  179. // Now let's write the rating
  180. if ($rating <> "" and is_numeric($rating)){
  181. $node->addRating($rating);
  182. if ($displayOutput){
  183. ?>
  184. <SCRIPT LANGUAGE=JAVASCRIPT><!--\
  185. ars.innerHTML = 'Status: Rating Album';
  186. -->
  187. </SCRIPT>
  188. <?php
  189. flushdisplay();
  190. }
  191. }
  192. if ($displayOutput){
  193. ?>
  194. <SCRIPT LANGUAGE=JAVASCRIPT><!--\
  195. ars.innerHTML = 'Status: Writing data to files...';
  196. -->
  197. </SCRIPT>
  198. <?php
  199. flushdisplay();
  200. }
  201. // Did they want to write this to the id3 tags?
  202. if ($allow_id3_modify == "true" and $write_now == true){
  203. // Now let's set the meta fields so they get updated for all the tracks
  204. $meta['albumYear'] = $year;
  205. $meta['image-data'] = $imageData;
  206. $meta['image-file'] = $imgFile;
  207. $meta['image-ext'] = ".jpg";
  208. $meta['image-name'] = $imgShortName;
  209. $node->bulkMetaUpdate($meta,false,$displayOutput);
  210. if ($displayOutput){
  211. ?>
  212. <SCRIPT LANGUAGE=JAVASCRIPT><!--\
  213. ars.innerHTML = 'Status: Complete!';
  214. -->
  215. </SCRIPT>
  216. <?php
  217. flushdisplay();
  218. }
  219. }
  220. }
  221. /**
  222. * Writes out the meta data of an artist
  223. *
  224. * @author Ross Carlson
  225. * @version 08/10/04
  226. * @param string $link the link of where the data is
  227. */
  228. function writeArtistMetaData($node, $image=false, $bio=false, $displayOutput){
  229. global $web_root, $root_dir, $media_dir, $allow_filesystem_modify, $allow_id3_modify, $include_path, $backend, $include_path;
  230. // Let's write the bio
  231. if ($bio){
  232. if ($displayOutput){
  233. ?>
  234. <SCRIPT LANGUAGE=JAVASCRIPT><!--\
  235. ars.innerHTML = 'Status: Writing Description';
  236. -->
  237. </SCRIPT>
  238. <?php
  239. flushdisplay();
  240. usleep(250000);
  241. }
  242. // Now let's write this data to the node
  243. $node->addDescription($bio);
  244. // Now let's write it to a file if we should
  245. if ($allow_filesystem_modify == "true" and !stristr($backend,"id3")){
  246. $bioFile = $node->getFilePath(). "/". $node->getName(). ".txt";
  247. $handle = @fopen($bioFile, "w");
  248. @fwrite($handle,$bio);
  249. @fclose($handle);
  250. }
  251. }
  252. // Now let's write out the image
  253. $imgFile="";
  254. if (stristr($image,".jpg")){
  255. include_once($include_path. "lib/snoopy.class.php");
  256. $snoopy = new Snoopy;
  257. $snoopy->fetch($image);
  258. $imageData = $snoopy->results;
  259. unset($snoopy);
  260. // Now let's make sure that was valid
  261. if (strlen($imageData) < 2000){
  262. //$imageData = "";
  263. }
  264. } else {
  265. $imageData = "";
  266. }
  267. //echo strlen($imageData);
  268. // Now let's write it out
  269. if ($imageData <> ""){
  270. if ($displayOutput){
  271. ?>
  272. <SCRIPT LANGUAGE=JAVASCRIPT><!--\
  273. ars.innerHTML = 'Status: Writing Image';
  274. -->
  275. </SCRIPT>
  276. <?php
  277. flushdisplay();
  278. usleep(250000);
  279. }
  280. // Ok, now can we write to the filesystem?
  281. if ($allow_filesystem_modify == "false" or stristr($backend,"id3")){
  282. $imgFile = $include_path. "data/images/". str_replace("/","--",$node->getPath("String")). "--". $node->getName(). ".jpg";
  283. } else {
  284. $imgFile = $node->getFilePath(). "/". $node->getName(). ".jpg";
  285. }
  286. // Now let's write it out
  287. if (writeImage($imgFile, $imageData)){
  288. $node->addMainArt($imgFile);
  289. }
  290. if ($displayOutput){
  291. ?>
  292. <SCRIPT LANGUAGE=JAVASCRIPT><!--\
  293. ars.innerHTML = 'Status: Writing Image - Success';
  294. -->
  295. </SCRIPT>
  296. <?php
  297. flushdisplay();
  298. usleep(250000);
  299. }
  300. $retVal=1;
  301. }
  302. return true;
  303. }
  304. ?>