/** static, this places the icon into the www/tmp, so that you can refer to it with <img src=, returns true if there is an icon for this object */ function cacheIcon($id) { global $cachedir; $cacheTimeout = 2 * 60; // 2 minutes if (!$id) { raiseError("missing id"); } $fname = "{$cachedir}/" . $id . '.png'; if (is_readable($fname)) { $stat = stat($fname); if (time() - $stat['mtime'] <= $cacheTimeout) { return true; } } $icon = sotf_Blob::findBlob($id, 'icon'); if (!$icon) { return false; } // TODO: cache cleanup! ////debug("cache: ". filesize($fname) ."==" . strlen($icon)); if (is_readable($fname) && filesize($fname) == strlen($icon)) { return true; } debug("cached icon for", $id); sotf_Utils::save($fname, $icon); return true; }
/** static: create contact record from metadata */ function importContact($contactData, $contactRole, $prgId, $stationId, $admins) { global $db, $permissions, $repository, $vocabularies, $config; $db->begin(); // find out what should go into the 'name' field if ($contactData['type'] == 'organisation') { $name = $contactData['organizationname']; } elseif ($contactData['type'] == 'individual') { $name = $contactData['firstname'] . ' ' . $contactData['lastname']; } else { logError("unknown type of contact: " . $contactData['type']); return null; } // if not exists, create new contact $id = sotf_Contact::findByNameLocal($name); if (!$id) { $contact = new sotf_Contact(); $status = $contact->create($name, $stationId); if (!$status) { //$page->addStatusMsg('contact_create_failed'); return null; } // add permissions for all station admins (??) while (list(, $adminId) = each($admins)) { $permissions->addPermission($contact->id, $adminId, 'admin'); } } else { $contact = $repository->getObject($id); } //debug("contactData", $contactData); // set/update contact data $contact->set('acronym', $contactData['organizationacronym']); $contact->set('alias', $contactData['alias']); $contact->set('url', $contactData['uri']); $contact->set('email', $contactData['email']); $contact->set('address', $contactData['address']); $contact->update(); // determine role if ($contactData['role']) { $language = 'eng'; // for now $rid = $vocabularies->getRoleId($contactData['role'], $language); if ($rid) { $contactRole = $rid; } } // create role if (!sotf_ComplexNodeObject::findRole($prgId, $contact->id, $contactRole)) { $role = new sotf_NodeObject("sotf_object_roles"); $role->set('object_id', $prgId); $role->set('contact_id', $contact->id); $role->set('role_id', $contactRole); $role->create(); } $db->commit(); // fetch logo from url and store if (!empty($contactData['logo'])) { $url = $contactData['logo']; if ($handle = @fopen($url, 'rb')) { $contents = ""; while (!feof($handle)) { $contents .= fread($handle, 8192); } /* do { $data = fread ($handle, 100000); if (strlen($data) == 0) { break; } //debug("received", strlen($data)); $contents .= $data; } while(0); */ fclose($handle); $tmpFile = tempnam($config['tmpDir'], 'logo_u'); debug("received logo from", $url); sotf_Utils::save($tmpFile, $contents); chmod($tmpFile, 0660); $contact->setIcon($tmpFile); unlink($tmpFile); } else { logError("Could not fetch icon from {$url}"); } } return $contact->id; }
/** * Sets icon for object. * * @internal change person icons to 50x50 done by wofli_fhsp and buddafly * @param object $file pathname of file * @return boolean True if the function succeeded, else false */ function setIcon($file, $ispersonicon = false) { // change from wolfi_fhstp and buddhafly (change person icons to 50x50) global $config; $tmpfile = $config['tmpDir'] . '/' . time() . ".png"; if ($ispersonicon) { $succ = $this->prepareIcon($file, $tmpfile, 50, 50); } else { $succ = $this->prepareIcon($file, $tmpfile, $config['iconWidth'], $config['iconHeight']); } //----------------------------------------------------------------------------------------- if (!$succ) { addError("Could not resize image"); //return false; } else { if ($fp = fopen($tmpfile, 'rb')) { $data = fread($fp, filesize($tmpfile)); fclose($fp); // save into DB sotf_Blob::saveBlob($this->id, "icon", $data); // save into file system $iconFile = $this->getMetaDir() . '/icon.png'; sotf_Utils::save($iconFile, $data); } else { addError("could not open icon file!"); } } if (is_file($tmpfile)) { debug("remove tmpfile", $tmpfile); unlink($tmpfile); } sotf_Blob::uncacheIcon($this->id); return true; }
/** static, this places the icon into the www/tmp, so that you can refer to it with <img src=, returns true if there is an icon for this object */ function cacheIcon($id) { global $config; $cacheTimeout = 10 * 60; // 10 minutes if (!$id) { raiseError("missing id"); } $fname = $config['cacheDir'] . "/" . $id . '.png'; if (is_readable($fname)) { $stat = stat($fname); if (time() - $stat['mtime'] <= $cacheTimeout) { return true; } else { debug("cached icon of {$id} expired"); if (!unlink($fname)) { clearstatcache(); if (file_exists($fname)) { logError("Could not delete {$fname}"); } } } } $icon = sotf_Blob::findBlob($id, 'icon'); if (!$icon) { return false; } debug("cached icon of {$id} for ", $forId); sotf_Utils::save($fname, $icon); return true; }
/** * Sets logo of the station * * @param object $file sotf_File object represents the logo * @return boolean True if the function succeeded, else false * @use $db * @use $config['iconWidth'] * @use $config['iconHeight'] */ function setIcon($file) { if (parent::setIcon($file)) { $iconFile = $this->getStationDir() . '/icon.png'; sotf_Utils::save($iconFile, $this->getIcon()); return true; } else { return false; } }
</head> <body> <?php require "init.inc.php"; $url = "http://www.resonancefm.com/images/banner.gif"; if ($handle = fopen($url, 'rb')) { $contents = ""; while (!feof($handle)) { $contents .= fread($handle, 8192); //debug("received", strlen($data)); } fclose($handle); $tmpFile = tempnam($config['tmpDir'], 'logo_u'); debug("received logo from", $url); debug("tmpfile", $tmpFile); sotf_Utils::save($tmpFile, $contents); chmod($tmpFile, 0660); exec("/usr/bin/convert {$tmpFile} -resize 100x36 " . $config['tmpDir'] . "/test.png 2>&1", $output, $retval); debug("retval", $retval); debug("output", $output); } exit; require_once $config['classdir'] . "/rpc_Utils.class.php"; $rpc = new rpc_Utils(); $rpc->debug = true; //$response = $rpc->callTamburine('version', ''); //$response = $rpc->callTamburine('setpls', array('/home/micsik/ok.mp3', '/home/micsik/china.mp3')); $response = $rpc->callTamburine('getpls', 1); //$response = $rpc->callTamburine('quit', 1); dump($response, "RESPONSE"); exit;