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.9'); $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 = ''; $flashhtml .= ''; $flashhtml .= ''; $flashhtml .= '' . ''; $flashhtml .= ''; $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."); } 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 "
"; echo '

' . PLUGIN_EVENT_PHONEBLOGZ_USERS_HEADING . '

'; echo "
"; echo ""; $users = serendipity_fetchUsers(); $vals = array(); $vals['empty'] = MF_MYSELF; for ($i = 0; $i < count($arr); ++$i) { echo ""; echo ""; echo ""; } echo "
PhoneBlogz NamePIN codeWordPress User
" . $arr[$i]["name"] . "" . $arr[$i]["pin"] . "
"; echo "
"; echo ""; echo "
"; echo "
"; } } function showInterface() { global $serendipity; if (isset($_POST['submitdopost'])) { $postid = $_POST['id']; $pbuserno = $_POST[pbuserid]; $postinfo = $this->phoneblogz_post($postid, $pbuserno); if ($postinfo['error'] != false) { echo "ERROR: " . $postinfo['error']; } } $arr = getPostsForAccount($this->get_config("phoneblogz_accesscode"), $this->get_config("phoneblogz_password")); if ( !empty($arr["error"]) ) { echo "ERROR: " . $arr["error"]; } else { echo '

' . PLUGIN_EVENT_PHONEBLOGZ_SEEBELOW . '

'; echo ""; // TODO: i18n echo "\n"; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; for ($i = 0; $i < count($arr); ++$i) { $msg = $arr[$i]; $status = "available"; $action = ""; $postid = $this->get_config("phoneblogz_status_" . $msg["messageid"]); if (!isset($postid)) { $status = "not posted"; $action = "" . "" . ""; } else { $status = "posted"; if ($postid > 0) { $status .= " - " . PREVIEW . ""; } $action = "" . "" . ""; } $posturl = "Click here"; $flashhtml = ''; $flashhtml .= ''; $flashhtml .= ''; $flashhtml .= '' . ''; $flashhtml .= ''; $flashhtml .= ''; echo ""; } echo "
Date PostedCaller IDLeft byListenDownload linkStatusAction
" . $msg["timeleft"] . "" . $msg["callerid"] . "" . $msg["username"] . "$flashhtml$posturl$status$action
"; } } function cleanup() { if ($this->get_config('phoneblogz_accesscode') != "" && $this->get_config('phoneblogz_password') != "" && $this->get_config('phoneblogz_notifyurl') != "") { $arrRes = updateSerendipityOptions($this->get_config('phoneblogz_accesscode'), $this->get_config('phoneblogz_password'), $this->get_config('phoneblogz_notifyurl')); if ($arrRes != "SUCCESS") echo "Failed to save changes: " . $arrRes["error"]; } } function publicInterface() { $arr = getPostsForAccount($this->get_config("phoneblogz_accesscode"), $this->get_config("phoneblogz_password")); if ( !empty($arr["error"]) ) { echo "Error: " . $arr["empty"]; return false; } else { for ($i = 0; $i < count($arr); ++$i) { $status = $this->get_config("phoneblogz_status_" . $arr[$i]["messageid"]); if ($status == "" || (intval($status) == 0 && status != "posted")) { // Found one to post $res = $this->phoneblogz_post($arr[$i]["messageid"], $arr[$i]["userno"]); if ($res["error"] != false) { echo "Error for message " . $arr[$i]["messageid"] . ": " . $res["error"] . "\r"; } else { echo "Result for message " . $arr[$i]["messageid"] . ": " . $res["postid"] . "\r"; } } } } echo "\r\n\r\n"; return true; } function event_hook($event, &$bag, &$eventData, $addData = null) { global $serendipity; $hooks = &$bag->get('event_hooks'); if (!isset($hooks[$event])) { return false; } switch($event) { case 'backend_sidebar_entries': if ($serendipity['serendipityUserlevel'] >= USERLEVEL_CHIEF) { ?> = USERLEVEL_CHIEF) { ?> showUsersInterface(); break; case 'backend_sidebar_entries_event_display_phoneblogz': $this->showInterface(); break; case 'external_plugin': if ($eventData == 'phoneblogz') { $this->publicInterface(); } break; default: return false; } } } /* vim: set sts=4 ts=4 expandtab : */