add('name', PLUGIN_EVENT_PHONEBLOGZ_NAME); $propbag->add('description', PLUGIN_EVENT_PHONEBLOGZ_DESC); $propbag->add('stackable', false); $propbag->add('author', 'Garvin Hicking, phoneblogz.com'); $propbag->add('version', '0.10'); $propbag->add('requirements', array( 'serendipity' => '0.8', 'smarty' => '2.6.7', 'php' => '4.1.0' )); $propbag->add('event_hooks', array( 'external_plugin' => true, 'backend_sidebar_entries' => true, 'backend_sidebar_entries_event_display_phoneblogz' => true, 'backend_sidebar_admin' => true, 'backend_sidebar_entries_event_display_users' => true )); $propbag->add('groups', array('BACKEND_FEATURES')); $propbag->add('configuration', array('phoneblogz_accesscode', 'phoneblogz_password', 'categoryid', 'phoneblogz_subject', 'phoneblogz_text', 'phoneblogz_notifyurl')); } function introspect_config_item($name, &$propbag) { switch($name) { case 'phoneblogz_notifyurl': $propbag->add('type', 'string'); $propbag->add('name', PLUGIN_EVENT_PHONEBLOGZ_NOTIFYURL); $propbag->add('description', ''); $propbag->add('default', PLUGIN_EVENT_PHONEBLOGZ_NOTIFYURL_DEFAULT); break; case 'phoneblogz_accesscode': $propbag->add('type', 'string'); $propbag->add('name', PLUGIN_EVENT_PHONEBLOGZ_ACCESSCODE); $propbag->add('description', ''); $propbag->add('default', ''); break; case 'phoneblogz_password': $propbag->add('type', 'string'); $propbag->add('name', PLUGIN_EVENT_PHONEBLOGZ_PASSWORD); $propbag->add('description', ''); $propbag->add('default', ''); break; case 'phoneblogz_subject': $propbag->add('type', 'string'); $propbag->add('name', PLUGIN_EVENT_PHONEBLOGZ_SUBJECT); $propbag->add('description', ''); $propbag->add('default', PLUGIN_EVENT_PHONEBLOGZ_SUBJECT_DEFAULT); break; case 'phoneblogz_text': $propbag->add('type', 'html'); $propbag->add('name', PLUGIN_EVENT_PHONEBLOGZ_TEXT); $propbag->add('description', ''); $propbag->add('default', PLUGIN_EVENT_PHONEBLOGZ_TEXT_DEFAULT); break; case 'categoryid': $base_cats = serendipity_fetchCategories(); $base_cats = serendipity_walkRecursive($base_cats, 'categoryid', 'parentid', VIEWMODE_THREADED); $select['none'] = NONE; foreach ( $base_cats as $cat ) { $select[$cat['categoryid']] = str_repeat('-', $cat['depth']) . ' '. $cat['category_name']; } $propbag->add('type', 'select'); $propbag->add('name', CATEGORY); $propbag->add('description', ''); $propbag->add('select_values', $select); break; default: return false; } return true; } function generate_content(&$title) { $title = $this->title; } function phoneblogz_flash($url) { $flashhtml = ''; return $flashhtml; } function phoneblogz_post($postid, $pbuserno) { // Firstly try and download the file $url = "http://www.phoneblogz.com/listen.php?user=" . $this->get_config("phoneblogz_accesscode") . "&id=$postid"; $upload = $this->phoneblogz_upload_fromurl("pbpost.mp3", "", $url); if (!isset($upload["error"])) { // Deal with the local username $localuserid = $this->get_config("phoneblogz_usermap_$pbuserno"); if ($localuserid === FALSE || $localuserid < 1) $localuserid = 1; // Default to the admin user // Get the local username for this user $localuser = serendipity_fetchUsers($localuserid); $localusername = $localuser[0]["realname"]; // Attempt to create a new post $post_content = $this->get_config("phoneblogz_text"); $post_content = str_replace("[FLASH]", $this->phoneblogz_flash($upload["url"]), $post_content); $post_content = str_replace("[USER]", $localusername, $post_content); $first = strpos($post_content, "["); $second = strpos($post_content, "]"); if ($first !== FALSE && $second !== FALSE && $second > $first) { $link = ""; $link .= substr($post_content, $first+1, ($second-$first-1)); $link .= ""; $post_content = substr($post_content, 0, $first). $link . substr($post_content, $second+1); } $oldsess = $_SESSION['serendipityRightPublish']; $_SESSION['serendipityRightPublish'] = true; $entry = array( 'body' => $post_content, //serendipity_db_escape_string($post_content), 'title' => str_replace("[USER]", $localusername, $this->get_config('phoneblogz_subject')), 'timestamp' => time(), 'isdraft' => 'false', 'allow_comments' => true, 'authorid' => $localuserid, 'categories' => array($this->get_config('categoryid')) ); $GLOBALS['serendipity']['POST']['properties'] = array('fake' => 'fake'); $post_ID = serendipity_updertEntry($entry); $_SESSION['serendipityRightPublish'] = $oldsess; $this->set_config("phoneblogz_status_$postid", $post_ID); return array("postid" => $post_ID); } else { return array("error" => "Failed to upload the file. Exact error: " . $upload["error"]); } } function phoneblogz_upload_fromurl($name, $type, $url) { global $serendipity; if (empty($name)) { return array('error' => "Empty filename"); } $upload = array( 'path' => $serendipity['uploadPath'], 'url' => $serendipity['uploadHTTPPath'], 'error' => false ); if (!is_writable($upload['path'])) { $upload['error'] = "Don't have write permission to " . $upload['path']; return $upload; } $number = ''; $filename = $name; while (file_exists($upload['path'] . "/$filename")) { $filename = str_replace("$number.$ext", ++$number . ".$ext", $filename); } $new_file = $upload['path'] . "/$filename"; $ifp = @fopen($new_file, 'wb'); if (!$ifp) { return array('error' => "Could not write file $new_file."); } if (function_exists('serendipity_request_url')) { $fc = serendipity_request_url($url); if ($serendipity['last_http_request']['responseCode'] != '200') { return array('error' => "Could not download file " . htmlspecialchars($url)); } return false; } else { require_once S9Y_PEAR_PATH . 'HTTP/Request.php'; $req = new HTTP_Request($url); if (PEAR::isError($req->sendRequest()) || $req->getResponseCode() != '200') { return array('error' => "Could not download file " . htmlspecialchars($url)); } $fc = $req->getResponseBody(); } $success = @fwrite($ifp, $fc); fclose($ifp); // Set correct file permissions $stat = @ stat(dirname($new_file)); $perms = $stat['mode'] & 0000777; @chmod($new_file, $perms); // Compute the URL $url = $upload['url'] . "/$filename"; return array('file' => $new_file, 'url' => $url); } function showUsersInterface() { global $serendipity; if (isset($_POST[submitusersedit])) { foreach ($_POST as $key => $val) { // Pick out the "userchoose-" values if (strpos($key, "userchoose-") !== FALSE) { $pbuserid = substr($key, 11); $this->set_config("phoneblogz_usermap_$pbuserid", $val); } } } $arr = getUsersForAccount($this->get_config('phoneblogz_accesscode'), $this->get_config('phoneblogz_password')); if ( !empty($arr["error"]) ) { echo "ERROR: " . $arr["error"]; } else { echo "
Date Posted | "; echo "Caller ID | "; echo "Left by | "; echo "Listen | "; echo "Download link | "; echo "Status | "; echo "Action | "; echo "
---|---|---|---|---|---|---|
" . $msg["timeleft"] . " | " . $msg["callerid"] . " | " . $msg["username"] . " | $flashhtml | $posturl | $status | $action |