codes****@googl*****
codes****@googl*****
2008年 9月 29日 (月) 12:29:35 JST
Author: tacahi Date: Sun Sep 28 20:27:53 2008 New Revision: 843 Modified: trunk/geeklog-1-jp/system/classes/config.class.php trunk/geeklog-1-jp/system/classes/downloader.class.php trunk/geeklog-1-jp/system/classes/sanitize.class.php trunk/geeklog-1-jp/system/classes/search.class.php trunk/geeklog-1-jp/system/classes/story.class.php trunk/geeklog-1-jp/system/classes/syndication/rss.feed.class.php trunk/geeklog-1-jp/system/classes/template.class.php trunk/geeklog-1-jp/system/lib-admin.php trunk/geeklog-1-jp/system/lib-comment.php trunk/geeklog-1-jp/system/lib-custom.php trunk/geeklog-1-jp/system/lib-database.php trunk/geeklog-1-jp/system/lib-pingback.php trunk/geeklog-1-jp/system/lib-plugins.php trunk/geeklog-1-jp/system/lib-security.php trunk/geeklog-1-jp/system/lib-sessions.php trunk/geeklog-1-jp/system/lib-story.php trunk/geeklog-1-jp/system/lib-syndication.php trunk/geeklog-1-jp/system/lib-user.php trunk/geeklog-1-jp/system/lib-webservices.php trunk/geeklog-1-jp/system/pear/HTTP/Request.php trunk/geeklog-1-jp/system/pear/HTTP/Request/Listener.php trunk/geeklog-1-jp/system/pear/Net/Socket.php Log: さらに、Geeklog 1.5.1のマージに失敗していたファイルを、改めて1.5.1の内容にし ます。 この変更には、*空白の違いだけではなく*、1.5.1で変更された部分を含んでいま す。 なお、geeklog-1-jpで修正された、以下の項目は1.5.1に反映されていません。 * calendarプラグインのHTML生成の誤り: plugins/calendar/functions.inc * Issue 11: staticpagesプラグインで「お問い合わせが何も表示されない」: plugins/staticpages/functions.inc * Issue 21: siteconfig db-config.phpのインストール後の改行文字が CR + LF: public_html/admin/install/index.php * インストーラの日本語の言語ファイルの翻訳が古い: public_html/admin/install/language/japanese_utf-8.php * 1.4.0/1.4.1でutf-8を大文字で指定している、アップグレード時に文字化けが発 生: system/databases/mysql.class.php Modified: trunk/geeklog-1-jp/system/classes/config.class.php ============================================================================== --- trunk/geeklog-1-jp/system/classes/config.class.php (original) +++ trunk/geeklog-1-jp/system/classes/config.class.php Sun Sep 28 20:27:53 2008 @@ -29,7 +29,7 @@ // | | // +---------------------------------------------------------------------------+ // -// $Id: config.class.php,v 1.42 2008/06/14 15:28:01 dhaun Exp $ +// $Id: config.class.php,v 1.50 2008/08/31 19:17:39 dhaun Exp $ class config { var $dbconfig_file; @@ -102,17 +102,27 @@ * track of this reference, and the set function will mutate it. * * @return array(string => mixed) This is a reference to the - * config array + * config array */ function &initConfig() { global $_TABLES; - $sql_query = "SELECT name, value, group_name FROM {$_TABLES['conf_values']} WHERE (type <> 'subgroup') AND (type <> 'fieldset')"; - $result = DB_query($sql_query); + $false_str = serialize(false); + + $sql = "SELECT name, value, group_name FROM {$_TABLES['conf_values']} WHERE (type <> 'subgroup') AND (type <> 'fieldset')"; + $result = DB_query($sql); while ($row = DB_fetchArray($result)) { if ($row[1] !== 'unset') { - $this->config_array[$row[2]][$row[0]] = unserialize($row[1]); + if (!array_key_exists($row[2], $this->config_array) || + !array_key_exists($row[0], $this->config_array[$row[2]])) { + $value = @unserialize($row[1]); + if (($value === false) && ($row[1] != $false_str)) { + COM_errorLog("Unable to unserialize {$row[1]} for {$row[2]}:{$row[0]}"); + } else { + $this->config_array[$row[2]][$row[0]] = $value; + } + } } } $this->_post_configuration(); @@ -154,21 +164,15 @@ */ function set($name, $value, $group='Core') { - global $_TABLES, $_DB, $_DB_dbms; + global $_TABLES; $escaped_val = addslashes(serialize($value)); $escaped_name = addslashes($name); $escaped_grp = addslashes($group); - $sql_query = "UPDATE {$_TABLES['conf_values']} " . - "SET value = '{$escaped_val}' WHERE " . - "name = '{$escaped_name}' AND group_name = '{$escaped_grp}'"; - if ($_DB_dbms == 'mssql') { - $sql_query = str_replace("\\'","''",$sql_query); - $sql_query = str_replace('\\"','"',$sql_query); - $_DB->dbQuery($sql_query, 0, 1); - } else { - DB_query($sql_query); - } + $sql = "UPDATE {$_TABLES['conf_values']} " . + "SET value = '{$escaped_val}' WHERE " . + "name = '{$escaped_name}' AND group_name = '{$escaped_grp}'"; + $this->_DB_escapedQuery($sql); $this->config_array[$group][$name] = $value; $this->_post_configuration(); } @@ -184,21 +188,15 @@ */ function set_default($name, $value, $group = 'Core') { - global $_TABLES, $_DB, $_DB_dbms; + global $_TABLES; $escaped_val = addslashes(serialize($value)); $escaped_name = addslashes($name); $escaped_grp = addslashes($group); - $sql_query = "UPDATE {$_TABLES['conf_values']} " . - "SET default_value = '{$escaped_val}' WHERE " . - "name = '{$escaped_name}' AND group_name = '{$escaped_grp}'"; - if ($_DB_dbms == 'mssql') { - $sql_query = str_replace("\\'", "''", $sql_query); - $sql_query = str_replace('\\"', '"', $sql_query); - $_DB->dbQuery($sql_query, 0, 1); - } else { - DB_query($sql_query); - } + $sql = "UPDATE {$_TABLES['conf_values']} " . + "SET default_value = '{$escaped_val}' WHERE " . + "name = '{$escaped_name}' AND group_name = '{$escaped_grp}'"; + $this->_DB_escapedQuery($sql); } function restore_param($name, $group) @@ -207,9 +205,19 @@ $escaped_name = addslashes($name); $escaped_grp = addslashes($group); - $sql = "UPDATE {$_TABLES['conf_values']} SET value = default_value " . - "WHERE name = '{$escaped_name}' AND group_name = '{$escaped_grp}'"; - DB_query($sql); + + $result = DB_query("SELECT value, default_value FROM {$_TABLES['conf_values']} WHERE name = '{$escaped_name}' AND group_name = '{$escaped_grp}'"); + list($value, $default_value) = DB_fetchArray($result); + + $sql = "UPDATE {$_TABLES['conf_values']} "; + if ($value == 'unset') { + $default_value = addslashes($default_value); + $sql .= "SET value = '{$default_value}', default_value = 'unset:{$default_value}'"; + } else { + $sql .= "SET value = default_value"; + } + $sql .= " WHERE name = '{$escaped_name}' AND group_name = '{$escaped_grp}'"; + $this->_DB_escapedQuery($sql); } function unset_param($name, $group) @@ -218,9 +226,15 @@ $escaped_name = addslashes($name); $escaped_grp = addslashes($group); - $sql = "UPDATE {$_TABLES['conf_values']} SET value = 'unset' " . - "WHERE name = '{$escaped_name}' AND group_name = '{$escaped_grp}'"; - DB_query($sql); + $default_value = DB_getItem($_TABLES['conf_values'], 'default_value', + "name = '{$escaped_name}' AND group_name = '{$escaped_grp}'"); + $sql = "UPDATE {$_TABLES['conf_values']} SET value = 'unset'"; + if (substr($default_value, 0, 6) == 'unset:') { + $default_value = addslashes(substr($default_value, 6)); + $sql .= ", default_value = '{$default_value}'"; + } + $sql .= " WHERE name = '{$escaped_name}' AND group_name = '{$escaped_grp}'"; + $this->_DB_escapedQuery($sql); } /** @@ -254,18 +268,12 @@ * * @param boolean $set whether or not this parameter is set */ - function add( $param_name, $default_value, $type, $subgroup, $fieldset, + function add($param_name, $default_value, $type, $subgroup, $fieldset, $selection_array=null, $sort=0, $set=true, $group='Core') { - global $_TABLES, $_DB, $_DB_dbms; + global $_TABLES; - $format = 'INSERT INTO %1$s (name, value, type, ' . - 'subgroup, group_name, selectionArray, sort_order,'. - ' fieldset, default_value) ' . - 'VALUES ("%2$s","%3$s","%4$s",%5$s,"%6$s",%7$s,'. - '%8$s,%9$s, "%10$s")'; - $Qargs = array($_TABLES['conf_values'], - $param_name, + $Qargs = array($param_name, $set ? serialize($default_value) : 'unset', $type, $subgroup, @@ -276,15 +284,20 @@ $fieldset, serialize($default_value)); $Qargs = array_map('addslashes', $Qargs); - $sql_query = vsprintf($format, $Qargs); + $sql = "INSERT INTO {$_TABLES['conf_values']} (name, value, type, " . + "subgroup, group_name, selectionArray, sort_order,". + " fieldset, default_value) VALUES (" + ."'{$Qargs[0]}'," + ."'{$Qargs[1]}'," + ."'{$Qargs[2]}'," + ."{$Qargs[3]}," + ."'{$Qargs[4]}'," + ."{$Qargs[5]}," + ."{$Qargs[6]}," + ."{$Qargs[7]}," + ."'{$Qargs[8]}')"; - if ($_DB_dbms == 'mssql') { - $sql_query = str_replace("\\'","''",$sql_query); - $sql_query = str_replace('\\"','""',$sql_query); - $_DB->dbQuery($sql_query, 0, 1); - } else { - DB_query($sql_query); - } + $this->_DB_escapedQuery($sql); $this->config_array[$group][$param_name] = $default_value; } @@ -296,7 +309,7 @@ function del($param_name, $group) { DB_delete($GLOBALS['_TABLES']['conf_values'], - array("name","group_name"), + array('name', 'group_name'), array(addslashes($param_name), addslashes($group))); unset($this->config_array[$group][$param_name]); } @@ -312,7 +325,7 @@ global $_TABLES, $LANG_confignames, $LANG_configselects; $q_string = "SELECT name, type, selectionArray, " - . "fieldset, value FROM {$_TABLES['conf_values']}" . + . "fieldset, value, default_value FROM {$_TABLES['conf_values']}" . " WHERE group_name='{$group}' AND subgroup='{$subgroup}' " . " AND (type <> 'fieldset' AND type <> 'subgroup') " . " ORDER BY fieldset,sort_order ASC"; @@ -326,6 +339,11 @@ } while ($row = DB_fetchArray($Qresult)) { $cur = $row; + if (substr($cur[5], 0, 6) == 'unset:') { + $cur[5] = true; + } else { + $cur[5] = false; + } $res[$cur[3]][$cur[0]] = array('display_name' => (array_key_exists($cur[0], $LANG_confignames[$group]) ? @@ -340,7 +358,8 @@ $LANG_configselects[$group][$cur[2]] : null), 'value' => (($cur[4] == 'unset') ? - 'unset' : unserialize($cur[4]))); + 'unset' : unserialize($cur[4])), + 'reset' => $cur[5]); } return $res; @@ -443,7 +462,7 @@ $groups = $this->_get_groups(); $outerloopcntr = 1; if (count($groups) > 0) { - $t->set_block('menugroup','subgroup-selector','subgroups'); + $t->set_block('menugroup', 'subgroup-selector', 'subgroups'); foreach ($groups as $group) { $t->set_var("select_id", ($group === $grp ? 'id="current"' : '')); $t->set_var("group_select_value", $group); @@ -501,7 +520,8 @@ $e['display_name'], $e['type'], $e['value'], - $e['selectionArray']); + $e['selectionArray'], false, + $e['reset']); } $this->_UI_get_fs($grp, $fs_contents, $fset, $t); } @@ -568,7 +588,8 @@ } function _UI_get_conf_element($group, $name, $display_name, $type, $val, - $selectionArray = null , $deletable = 0) + $selectionArray = null , $deletable = false, + $allow_reset = false) { global $_CONF, $LANG_CONFIG; @@ -588,18 +609,22 @@ $t->set_var('xhtml', XHTML); $t->set_var('lang_restore', $LANG_CONFIG['restore']); + $t->set_var('lang_enable', $LANG_CONFIG['enable']); $t->set_var('lang_add_element', $LANG_CONFIG['add_element']); $t->set_var('name', $name); $t->set_var('display_name', $display_name); if (!is_array($val)) { - $t->set_var('value', $val); + $t->set_var('value', htmlspecialchars($val)); } if ($deletable) { $t->set_var('delete', $t->parse('output', 'delete-button')); } else { - //$t->set_var('unset_link', - // "(<a href='#' onClick='unset(\"{$name}\");'>X</a>)"); + if ($allow_reset) { + $t->set_var('unset_link', + "(<a href='#' onClick='unset(\"{$name}\");' title='" + . $LANG_CONFIG['disable'] . "'>X</a>)"); + } if (($a = strrchr($name, '[')) !== FALSE) { $on = substr($a, 1, -1); $o = str_replace(array('[', ']'), array('_', ''), $name); @@ -664,7 +689,8 @@ $result .= config::_UI_get_conf_element($group, $name . '[' . $valkey . ']', $display_name . '[' . $valkey . ']', - substr($type, 1), $valval, $selectionArray); + substr($type, 1), $valval, $selectionArray, + false); } return $result; } elseif (strpos($type, "*") === 0 || strpos($type, "%") === 0) { @@ -828,6 +854,23 @@ 'footer')); return $retval; + } + + /** + * Helper function: Fix escaped SQL requests for MS SQL, if necessary + * + */ + function _DB_escapedQuery($sql) + { + global $_DB, $_DB_dbms; + + if ($_DB_dbms == 'mssql') { + $sql = str_replace("\\'", "''", $sql); + $sql = str_replace('\\"', '"', $sql); + $_DB->dbQuery($sql, 0, 1); + } else { + DB_query($sql); + } } } Modified: trunk/geeklog-1-jp/system/classes/downloader.class.php ============================================================================== --- trunk/geeklog-1-jp/system/classes/downloader.class.php (original) +++ trunk/geeklog-1-jp/system/classes/downloader.class.php Sun Sep 28 20:27:53 2008 @@ -2,13 +2,13 @@ /* Reminder: always indent with 4 spaces (no tabs). */ // +---------------------------------------------------------------------------+ -// | Geeklog 1.3 | +// | Geeklog 1.5 | // +---------------------------------------------------------------------------+ // | downloader.class.php | // | | // | Geeklog file download class library. | // +---------------------------------------------------------------------------+ -// | Copyright (C) 2002-2005 by the following authors: | +// | Copyright (C) 2002-2008 by the following authors: | // | | // | Authors: Tony Bibbs - tony AT tonybibbs DOT com | // +---------------------------------------------------------------------------+ @@ -29,7 +29,7 @@ // | | // +---------------------------------------------------------------------------+ // -// $Id: downloader.class.php,v 1.14 2007/11/25 06:59:56 ospiess Exp $ +// $Id: downloader.class.php,v 1.15 2008/08/11 14:11:21 dhaun Exp $ /** * This class allows you to download a file from outside the web tree. Many hooks @@ -207,6 +207,7 @@ 'gif' => 'image/gif', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', + 'png' => 'image/png', 'png' => 'image/x-png', 'mp3' => 'audio/mpeg', 'wav' => 'audio/wav', Modified: trunk/geeklog-1-jp/system/classes/sanitize.class.php ============================================================================== --- trunk/geeklog-1-jp/system/classes/sanitize.class.php (original) +++ trunk/geeklog-1-jp/system/classes/sanitize.class.php Sun Sep 28 20:27:53 2008 @@ -37,7 +37,7 @@ */ if (strpos(strtolower($_SERVER['PHP_SELF']), 'sanitize.class.php') !== false) { - die ('This file can not be used on its own.'); + die('This file can not be used on its own.'); } /** Modified: trunk/geeklog-1-jp/system/classes/search.class.php ============================================================================== --- trunk/geeklog-1-jp/system/classes/search.class.php (original) +++ trunk/geeklog-1-jp/system/classes/search.class.php Sun Sep 28 20:27:53 2008 @@ -33,7 +33,7 @@ // $Id: search.class.php,v 1.68 2008/09/21 08:37:12 dhaun Exp $ if (strpos(strtolower($_SERVER['PHP_SELF']), 'search.class.php') !== false) { - die ('This file can not be used on its own.'); + die('This file can not be used on its own.'); } require_once $_CONF['path_system'] . 'classes/plugin.class.php'; @@ -303,12 +303,11 @@ // get rows $A['title'] = str_replace ('$', '$', $A['title']); $thetime = COM_getUserDateTimeFormat ($A['day']); - if (empty($this->_query)) { - $articleUrl = COM_buildUrl($_CONF['site_url'] - . '/article.php?story=' . $A['sid']); - } else { - $articleUrl = $_CONF['site_url'] . '/article.php?story=' - . $A['sid'] . '&query=' . urlencode($this->_query); + $articleUrl = COM_buildUrl($_CONF['site_url'] + . '/article.php?story=' . $A['sid']); + if (!empty($this->_query)) { + $articleUrl .= (strpos($articleUrl, '?') ? '&' : '?') + . 'query=' . urlencode($this->_query); } $author = htmlspecialchars($this->_displayName($A['username'], $A['fullname'])); Modified: trunk/geeklog-1-jp/system/classes/story.class.php ============================================================================== --- trunk/geeklog-1-jp/system/classes/story.class.php (original) +++ trunk/geeklog-1-jp/system/classes/story.class.php Sun Sep 28 20:27:53 2008 @@ -29,7 +29,7 @@ // | | // +---------------------------------------------------------------------------+ // -// $Id: story.class.php,v 1.27 2008/05/24 19:46:13 dhaun Exp $ +// $Id: story.class.php,v 1.36 2008/08/16 18:07:09 dhaun Exp $ /** * This file provides a class to represent a story, or article. It provides a @@ -495,6 +495,8 @@ return STORY_PERMISSION_DENIED; } elseif ($this->_access == 2 && $mode != 'view') { return STORY_EDIT_DENIED; + } elseif ((($this->_access == 2) && ($mode == 'view')) && (($this->_draft_flag == 1) || ($this->_date > time()))) { + return STORY_INVALID_SID; } } else { return STORY_INVALID_SID; @@ -573,6 +575,8 @@ $currentSidExists = false; /* Fix up old sid => new sid stuff */ + $checksid = addslashes($this->_originalSid); // needed below + if ($this->_sid != $this->_originalSid) { /* The sid has changed. Load from request will have * ensured that if the new sid exists an error has @@ -581,7 +585,6 @@ * sid that was then thrown away) to reduce the sheer * number of SQL queries we do. */ - $checksid = addslashes($this->_originalSid); $newsid = addslashes($this->_sid); $sql = "SELECT 1 FROM {$_TABLES['stories']} WHERE sid='{$checksid}'"; @@ -631,8 +634,8 @@ // Get the related URLs $this->_related = implode("\n", STORY_extractLinks("{$this->_introtext} {$this->_bodytext}")); $this->_in_transit = 1; - $sql = 'REPLACE INTO ' . $_TABLES['stories'] . ' ('; - $values = ' VALUES ('; + $values = ''; + $fields = ''; reset($this->_dbFields); /* This uses the database field array to generate a SQL Statement. This @@ -642,7 +645,7 @@ while (list($fieldname, $save) = each($this->_dbFields)) { if ($save === 1) { $varname = '_' . $fieldname; - $sql .= $fieldname . ', '; + $fields .= $fieldname . ', '; if (($fieldname == 'date') || ($fieldname == 'expire')) { // let the DB server do this conversion (cf. timezone hack) $values .= 'FROM_UNIXTIME(' . $this->{$varname} . '), '; @@ -652,11 +655,10 @@ } } - $sql = substr($sql, 0, strlen($sql) - 2); + // Fields and values has a trailing ', ' remove them: + $fields = substr($fields, 0, strlen($fields) - 2); $values = substr($values, 0, strlen($values) - 2); - $sql .= ') ' . $values . ')'; - - DB_query($sql); + DB_Save($_TABLES['stories'], $fields, $values); /* Clean up the old story */ if ($oldArticleExists) { @@ -792,6 +794,7 @@ // Use what we have: $this->_tid = $topic; + $this->_date = time(); } /** @@ -800,6 +803,10 @@ function loadSubmission() { $array = $_POST; + + $this->_expire = time(); + $this->_date = time(); + $this->_expiredate = 0; // Handle Magic GPC Garbage: while (list($key, $value) = each($array)) @@ -812,6 +819,10 @@ $this->_uid = COM_applyFilter($array['uid'], true); $this->_unixdate = COM_applyFilter($array['date'], true); + if (!isset($array['bodytext'])) { + $array['bodytext'] = ''; + } + /* Then load the title, intro and body */ if (($array['postmode'] == 'html') || ($array['postmode'] == 'adveditor')) { $this->_htmlLoadStory($array['title'], $array['introtext'], $array['bodytext']); @@ -905,9 +916,12 @@ $this->_oldsid = $this->_sid; $this->_date = mktime(); + $this->_featured = 0; $this->_commentcode = $_CONF['comment_code']; $this->_trackbackcode = $_CONF['trackback_code']; + $this->_statuscode = 0; $this->_show_topic_icon = $_CONF['show_topic_icon']; + $this->_owner_id = $_USER['uid']; $this->_group_id = $T['group_id']; $this->_perm_owner = $T['perm_owner']; $this->_perm_group = $T['perm_group']; @@ -1023,11 +1037,18 @@ $lFilename_large; } - // And finally, replace the [imagex_mode] tags with the image and it's - // hyperlink: - $lLink_url = $lFilename_large_URL; - $lLink_attr = array('title' => $LANG24[57]); + // And finally, replace the [imageX_mode] tags with the + // image and its hyperlink (only when the large image + // actually exists) + $lLink_url = ''; + $lLink_attr = ''; + if (file_exists($lFilename_large_complete)) { + $lLink_url = $lFilename_large_URL; + $lLink_attr = array('title' => $LANG24[57]); + } + } + if (!empty($lLink_url)) { $intro = str_replace($norm, COM_createLink($img_noalign, $lLink_url, $lLink_attr), $intro); $body = str_replace($norm, COM_createLink($img_noalign, $lLink_url, $lLink_attr), $body); $intro = str_replace($left, COM_createLink($img_leftalgn, $lLink_url, $lLink_attr), $intro); @@ -1417,6 +1438,10 @@ $return = $return[0]; break; + case 'unixdate': + $return = $this->_date; + break; + case 'hits': $return = COM_NumberFormat($this->_hits); @@ -1651,7 +1676,11 @@ // SID's are a special case: $sid = COM_sanitizeID($array['sid']); - $oldsid = COM_sanitizeID($array['old_sid']); + if (isset($array['old_sid'])) { + $oldsid = COM_sanitizeID($array['old_sid'], false); + } else { + $oldsid = ''; + } if (empty($sid)) { $sid = $oldsid; @@ -1665,10 +1694,22 @@ $this->_originalSid = $oldsid; /* Need to deal with the postdate and expiry date stuff */ - $publish_ampm = COM_applyFilter($array['publish_ampm']); - $publish_hour = COM_applyFilter($array['publish_hour'], true); - $publish_minute = COM_applyFilter($array['publish_minute'], true); - $publish_second = COM_applyFilter($array['publish_second'], true); + $publish_ampm = ''; + if (isset($array['publish_ampm'])) { + $publish_ampm = COM_applyFilter($array['publish_ampm']); + } + $publish_hour = 0; + if (isset($array['publish_hour'])) { + $publish_hour = COM_applyFilter($array['publish_hour'], true); + } + $publish_minute = 0; + if (isset($array['publish_minute'])) { + $publish_minute = COM_applyFilter($array['publish_minute'], true); + } + $publish_second = 0; + if (isset($array['publish_second'])) { + $publish_second = COM_applyFilter($array['publish_second'], true); + } if ($publish_ampm == 'pm') { if ($publish_hour < 12) { @@ -1680,9 +1721,18 @@ $publish_hour = '00'; } - $publish_year = COM_applyFilter($array['publish_year'], true); - $publish_month = COM_applyFilter($array['publish_month'], true); - $publish_day = COM_applyFilter($array['publish_day'], true); + $publish_year = 0; + if (isset($array['publish_year'])) { + $publish_year = COM_applyFilter($array['publish_year'], true); + } + $publish_month = 0; + if (isset($array['publish_month'])) { + $publish_month = COM_applyFilter($array['publish_month'], true); + } + $publish_day = 0; + if (isset($array['publish_day'])) { + $publish_day = COM_applyFilter($array['publish_day'], true); + } $this->_date = strtotime( "$publish_month/$publish_day/$publish_year $publish_hour:$publish_minute:$publish_second"); Modified: trunk/geeklog-1-jp/system/classes/syndication/rss.feed.class.php ============================================================================== --- trunk/geeklog-1-jp/system/classes/syndication/rss.feed.class.php (original) +++ trunk/geeklog-1-jp/system/classes/syndication/rss.feed.class.php Sun Sep 28 20:27:53 2008 @@ -269,12 +269,14 @@ */ function _RFC822DateFormat($timestamp='') { + // format the date if(!empty($timestamp)) { $time = date( 'r', $timestamp); } else { $time = date( 'r' ); } + // return the time return $time; } Modified: trunk/geeklog-1-jp/system/classes/template.class.php ============================================================================== --- trunk/geeklog-1-jp/system/classes/template.class.php (original) +++ trunk/geeklog-1-jp/system/classes/template.class.php Sun Sep 28 20:27:53 2008 @@ -5,7 +5,7 @@ * (C) Copyright 1999-2000 NetUSE GmbH * Kristian Koehntopp * - * $Id: template.class.php,v 1.8 2007/11/25 06:59:56 ospiess Exp $ + * $Id: template.class.php,v 1.9 2008/06/26 00:26:43 blaine Exp $ * */ @@ -823,12 +823,14 @@ if ($this->debug & 4) { echo "<p><b>filename:</b> filename = $filename</p>\n"; } - if (substr($filename, 0, 1) != "/") { - $filename = $this->root."/".$filename; - } + // Test if file exist and add physical path as 2nd test if (!file_exists($filename)) { - $this->halt("filename: file $filename does not exist."); + // Try appending file to template root + $filename = $this->root."/".$filename; + if (!file_exists($filename)) { + $this->halt("filename: file $filename does not exist."); + } } return $filename; } Modified: trunk/geeklog-1-jp/system/lib-admin.php ============================================================================== --- trunk/geeklog-1-jp/system/lib-admin.php (original) +++ trunk/geeklog-1-jp/system/lib-admin.php Sun Sep 28 20:27:53 2008 @@ -36,7 +36,7 @@ // $Id: lib-admin.php,v 1.136 2008/09/21 08:37:11 dhaun Exp $ if (strpos(strtolower($_SERVER['PHP_SELF']), 'lib-admin.php') !== false) { - die ('This file can not be used on its own!'); + die('This file can not be used on its own!'); } /** @@ -913,7 +913,11 @@ "{$_CONF['site_admin_url']}/syndication.php?mode=edit&fid={$A['fid']}"); break; case 'type': - $retval = ucwords($A['type']); + if ($A['type'] == 'article') { + $retval = $LANG33[55]; + } else { + $retval = ucwords($A['type']); + } break; case 'format': $retval = str_replace ('-' , ' ', ucwords ($A['format'])); Modified: trunk/geeklog-1-jp/system/lib-comment.php ============================================================================== --- trunk/geeklog-1-jp/system/lib-comment.php (original) +++ trunk/geeklog-1-jp/system/lib-comment.php Sun Sep 28 20:27:53 2008 @@ -36,7 +36,7 @@ // $Id: lib-comment.php,v 1.69 2008/09/21 08:37:11 dhaun Exp $ if (strpos(strtolower($_SERVER['PHP_SELF']), 'lib-comment.php') !== false) { - die ('This file can not be used on its own!'); + die('This file can not be used on its own!'); } if( $_CONF['allow_user_photo'] ) @@ -95,7 +95,7 @@ $commentbar->set_var('story_title', $cmt_title); // Article's are pre-escaped. if( $type != 'article' ) { - $cmt_title = htmlspecialchars($cmt_title); + $cmt_title = htmlspecialchars($cmt_title); } $commentbar->set_var('comment_title', $cmt_title); @@ -722,7 +722,8 @@ $newcomment = $comment; if (!empty ($sig)) { if (($postmode == 'html') || ($fakepostmode == 'html')) { - $newcomment .= '<p>---<br' . XHTML . '>' . nl2br ($sig); + $newcomment .= '<p>---<br' . XHTML . '>' . nl2br($sig) + . '</p>'; } else { $newcomment .= LB . LB . '---' . LB . $sig; } @@ -752,9 +753,9 @@ } } - if (empty ($A['username'])) { - $A['username'] = DB_getItem ($_TABLES['users'], 'username', - "uid = $uid"); + if (empty($A['username']) || empty($A['fullname']) || empty($A['email'])) { + $nresult = DB_query("SELECT username, fullname, email FROM {$_TABLES['users']} WHERE uid = $uid"); + list($A['username'], $A['fullname'], $A['email']) = DB_fetchArray($nresult); } $thecomments = CMT_getComment ($A, 'flat', $type, 'ASC', false, true); @@ -923,7 +924,7 @@ } if (!empty ($sig)) { if ($postmode == 'html') { - $comment .= '<p>---<br' . XHTML . '>' . nl2br($sig); + $comment .= '<p>---<br' . XHTML . '>' . nl2br($sig) . '</p>'; } else { $comment .= LB . LB . '---' . LB . $sig; } Modified: trunk/geeklog-1-jp/system/lib-custom.php ============================================================================== --- trunk/geeklog-1-jp/system/lib-custom.php (original) +++ trunk/geeklog-1-jp/system/lib-custom.php Sun Sep 28 20:27:53 2008 @@ -46,7 +46,7 @@ // $Id: lib-custom.php,v 1.43 2008/09/21 08:37:11 dhaun Exp $ if (strpos(strtolower($_SERVER['PHP_SELF']), 'lib-custom.php') !== false) { - die ('This file can not be used on its own!'); + die('This file can not be used on its own!'); } // You can use this global variable to print useful messages to the errorlog @@ -151,6 +151,9 @@ located under the theme_dir/custom directory. Sample is provided under /system with the distribution. + Note3: Optional parm $bulkimport added so that if your using the [Batch Add] feature, + you can execute different logic if required. + Functions have been provided that are called from the Core Geeklog user and admin functions - This works with User Moderation as well - Admin will see the new registration info when checking a member's profile only @@ -162,7 +165,7 @@ /* Create any new records in additional tables you may have added */ /* Update any fields in the core GL tables for this user as needed */ /* Called when user is first created */ -function CUSTOM_userCreate ($uid) +function CUSTOM_userCreate ($uid,$bulkimport=false) { global $_CONF, $_TABLES; @@ -403,11 +406,16 @@ } foreach($showblocks as $block) { - $sql = "SELECT bid, name,type,title,content,rdfurl,phpblockfn,help,allow_autotags FROM {$_TABLES['blocks']} WHERE name='$block'"; + $sql = "SELECT bid, name,type,title,content,rdfurl,phpblockfn,help,allow_autotags,onleft FROM {$_TABLES['blocks']} WHERE name='$block'"; $result = DB_query($sql); if (DB_numRows($result) == 1) { $A = DB_fetchArray($result); - $retval .= COM_formatBlock($A,$noboxes); + if ($A['onleft'] == 1) { + $side = 'left'; + } else { + $side = 'right'; + } + $retval .= COM_formatBlock($A,$noboxes, $side); } } Modified: trunk/geeklog-1-jp/system/lib-database.php ============================================================================== --- trunk/geeklog-1-jp/system/lib-database.php (original) +++ trunk/geeklog-1-jp/system/lib-database.php Sun Sep 28 20:27:53 2008 @@ -39,7 +39,7 @@ */ if (strpos(strtolower($_SERVER['PHP_SELF']), 'lib-database.php') !== false) { - die ('This file can not be used on its own!'); + die('This file can not be used on its own!'); } // +---------------------------------------------------------------------------+ @@ -535,6 +535,34 @@ global $_DB; $_DB->dbUnlockTable($table); +} + +/** + * Check if a table exists + * + * @param string $table Table name + * @return boolean True if table exists, false if it does not + * + */ +function DB_checkTableExists($table) +{ + global $_TABLES, $_DB_dbms; + + $exists = false; + + if ($_DB_dbms == 'mysql') { + $result = DB_query ("SHOW TABLES LIKE '{$_TABLES[$table]}'"); + if (DB_numRows ($result) > 0) { + $exists = true; + } + } elseif ($_DB_dbms == 'mssql') { + $result = DB_Query("SELECT 1 FROM sysobjects WHERE name='{$_TABLES[$table]}' AND xtype='U'"); + if (DB_numRows ($result) > 0) { + $exists = true; + } + } + + return $exists; } ?> Modified: trunk/geeklog-1-jp/system/lib-pingback.php ============================================================================== --- trunk/geeklog-1-jp/system/lib-pingback.php (original) +++ trunk/geeklog-1-jp/system/lib-pingback.php Sun Sep 28 20:27:53 2008 @@ -32,7 +32,7 @@ // $Id: lib-pingback.php,v 1.15 2008/09/21 08:37:11 dhaun Exp $ if (strpos(strtolower($_SERVER['PHP_SELF']), 'lib-pingback.php') !== false) { - die ('This file can not be used on its own!'); + die('This file can not be used on its own!'); } // PEAR class to handle XML-RPC Modified: trunk/geeklog-1-jp/system/lib-plugins.php ============================================================================== --- trunk/geeklog-1-jp/system/lib-plugins.php (original) +++ trunk/geeklog-1-jp/system/lib-plugins.php Sun Sep 28 20:27:53 2008 @@ -41,7 +41,7 @@ */ if (strpos(strtolower($_SERVER['PHP_SELF']), 'lib-plugins.php') !== false) { - die ('This file can not be used on its own!'); + die('This file can not be used on its own!'); } require_once $_CONF['path_system'] . 'classes/plugin.class.php'; @@ -205,7 +205,7 @@ // removing tables for ($i=0; $i < count($remvars['tables']); $i++) { COM_errorLog ("Dropping table {$_TABLES[$remvars['tables'][$i]]}", 1); - DB_query ("DROP TABLE {$_TABLES[$remvars['tables'][$i]]}"); + DB_query ("DROP TABLE {$_TABLES[$remvars['tables'][$i]]}", 1 ); COM_errorLog ('...success', 1); } Modified: trunk/geeklog-1-jp/system/lib-security.php ============================================================================== --- trunk/geeklog-1-jp/system/lib-security.php (original) +++ trunk/geeklog-1-jp/system/lib-security.php Sun Sep 28 20:27:53 2008 @@ -64,10 +64,10 @@ $_SEC_VERBOSE = false; if (strpos(strtolower($_SERVER['PHP_SELF']), 'lib-security.php') !== false) { - die ('This file can not be used on its own!'); + die('This file can not be used on its own!'); } -/* Constants for acount stats */ +/* Constants for account stats */ define('USER_ACCOUNT_DISABLED', 0); // Account is banned/disabled define('USER_ACCOUNT_AWAITING_ACTIVATION', 1); // Account awaiting user to login. define('USER_ACCOUNT_AWAITING_APPROVAL', 2); // Account awaiting moderator approval @@ -732,6 +732,7 @@ * * @param int $userid Valid uid value. * @return int user status, 0-3 +* @note May not return for banned/non-approved users. * */ function SEC_checkUserStatus($userid) @@ -743,36 +744,33 @@ // only do redirects if we aren't on users.php in a valid mode (logout or // default) - if (strpos ($_SERVER['PHP_SELF'], 'users.php') === false) - { + if (strpos($_SERVER['PHP_SELF'], 'users.php') === false) { $redirect = true; } else { - if (empty($_REQUEST['mode']) || ($_REQUEST['mode'] == 'logout')) - { + if (empty($_REQUEST['mode']) || ($_REQUEST['mode'] == 'logout')) { $redirect = false; } else { $redirect = true; } } - if ($status == USER_ACCOUNT_AWAITING_ACTIVATION) - { + if ($status == USER_ACCOUNT_AWAITING_ACTIVATION) { DB_change($_TABLES['users'], 'status', USER_ACCOUNT_ACTIVE, 'uid', $userid); } elseif ($status == USER_ACCOUNT_AWAITING_APPROVAL) { // If we aren't on users.php with a default action then go to it - if ($redirect) - { + if ($redirect) { COM_accessLog("SECURITY: Attempted Cookie Session login from user awaiting approval $userid."); echo COM_refresh($_CONF['site_url'] . '/users.php?msg=70'); exit; } } elseif ($status == USER_ACCOUNT_DISABLED) { - if ($redirect) - { + if ($redirect) { COM_accessLog("SECURITY: Attempted Cookie Session login from banned user $userid."); echo COM_refresh($_CONF['site_url'] . '/users.php?msg=69'); exit; } } + + return $status; } /** @@ -1078,7 +1076,13 @@ */ function SEC_createToken($ttl = 1200) { - global $_USER, $_TABLES; + global $_USER, $_TABLES, $_DB_dbms; + + static $last_token; + + if (isset($last_token)) { + return $last_token; + } /* Figure out the full url to the current page */ $pageURL = COM_getCurrentURL(); @@ -1088,9 +1092,13 @@ $pageURL = addslashes($pageURL); /* Destroy exired tokens: */ - /* Note: TTL not yet implemented! So commented out */ - $sql = "DELETE FROM {$_TABLES['tokens']} WHERE (DATE_ADD(created, INTERVAL ttl SECOND) < NOW())" + if($_DB_dbms == 'mssql') { + $sql = "DELETE FROM {$_TABLES['tokens']} WHERE (DATEADD(ss, ttl, created) < NOW())" + . " AND (ttl > 0)"; + } else { + $sql = "DELETE FROM {$_TABLES['tokens']} WHERE (DATE_ADD(created, INTERVAL ttl SECOND) < NOW())" . " AND (ttl > 0)"; + } DB_Query($sql); /* Destroy tokens for this user/url combination */ @@ -1103,6 +1111,8 @@ . "VALUES ('$token', NOW(), {$_USER['uid']}, '$pageURL', $ttl)"; DB_Query($sql); + $last_token = $token; + /* And return the token to the user */ return $token; } @@ -1117,7 +1127,7 @@ */ function SEC_checkToken() { - global $_USER, $_TABLES; + global $_USER, $_TABLES, $_DB_dbms; $token = ''; // Default to no token. $return = false; // Default to fail. @@ -1129,8 +1139,18 @@ } if(trim($token) != '') { - $sql = "SELECT ((DATE_ADD(created, INTERVAL ttl SECOND) < NOW()) AND ttl > 0) as expired, owner_id, urlfor FROM " + if($_DB_dbms != 'mssql') { + $sql = "SELECT ((DATE_ADD(created, INTERVAL ttl SECOND) < NOW()) AND ttl > 0) as expired, owner_id, urlfor FROM " . "{$_TABLES['tokens']} WHERE token='$token'"; + } else { + $sql = "SELECT owner_id, urlfor, expired = + CASE + WHEN (DATEADD(s,ttl,created) < getUTCDate()) AND (ttl>0) THEN 1 + + ELSE 0 + END + FROM {$_TABLES['tokens']} WHERE token='$token'"; + } $tokens = DB_Query($sql); $numberOfTokens = DB_numRows($tokens); if($numberOfTokens != 1) { Modified: trunk/geeklog-1-jp/system/lib-sessions.php ============================================================================== --- trunk/geeklog-1-jp/system/lib-sessions.php (original) +++ trunk/geeklog-1-jp/system/lib-sessions.php Sun Sep 28 20:27:53 2008 @@ -42,7 +42,7 @@ $_SESS_VERBOSE = false; if (strpos(strtolower($_SERVER['PHP_SELF']), 'lib-sessions.php') !== false) { - die ('This file can not be used on its own!'); + die('This file can not be used on its own!'); } if (empty ($_CONF['cookiedomain'])) { @@ -114,17 +114,20 @@ if ($userid > 1) { // Check user status - SEC_checkUserStatus($userid); - $user_logged_in = 1; - SESS_updateSessionTime($sessid, $_CONF['cookie_ip']); - $userdata = SESS_getUserDataFromId($userid); - if ($_SESS_VERBOSE) { - COM_errorLog("Got " . count($userdata) . " pieces of data from userdata",1); - COM_errorLog(COM_debug($userdata),1); - // COM_debug($userdata); + $status = SEC_checkUserStatus($userid); + if (($status == USER_ACCOUNT_ACTIVE) || + ($status == USER_ACCOUNT_AWAITING_ACTIVATION)) { + $user_logged_in = 1; + + SESS_updateSessionTime($sessid, $_CONF['cookie_ip']); + $userdata = SESS_getUserDataFromId($userid); + if ($_SESS_VERBOSE) { + COM_errorLog("Got " . count($userdata) . " pieces of data from userdata", 1); + COM_errorLog(COM_debug($userdata), 1); + } + $_USER = $userdata; + $_USER['auto_login'] = false; } - $_USER = $userdata; - $_USER['auto_login'] = false; } else { // Session probably expired, now check permanent cookie if (isset ($_COOKIE[$_CONF['cookie_name']])) { @@ -144,13 +147,17 @@ // User may have modified their UID in cookie, ignore them } else if ($userid > 1) { // Check user status - SEC_checkUserStatus ($userid); - $user_logged_in = 1; - $sessid = SESS_newSession ($userid, $_SERVER['REMOTE_ADDR'], $_CONF['session_cookie_timeout'], $_CONF['cookie_ip']); - SESS_setSessionCookie ($sessid, $_CONF['session_cookie_timeout'], $_CONF['cookie_session'], $_CONF['cookie_path'], $_CONF['cookiedomain'], $_CONF['cookiesecure']); - $userdata = SESS_getUserDataFromId ($userid); - $_USER = $userdata; - $_USER['auto_login'] = true; + $status = SEC_checkUserStatus ($userid); + if (($status == USER_ACCOUNT_ACTIVE) || + ($status == USER_ACCOUNT_AWAITING_ACTIVATION)) { + $user_logged_in = 1; + + $sessid = SESS_newSession($userid, $_SERVER['REMOTE_ADDR'], $_CONF['session_cookie_timeout'], $_CONF['cookie_ip']); + SESS_setSessionCookie($sessid, $_CONF['session_cookie_timeout'], $_CONF['cookie_session'], $_CONF['cookie_path'], $_CONF['cookiedomain'], $_CONF['cookiesecure']); + $userdata = SESS_getUserDataFromId($userid); + $_USER = $userdata; + $_USER['auto_login'] = true; + } } } } @@ -185,15 +192,18 @@ // User could have modified UID in cookie, don't do shit } else if ($userid > 1) { // Check user status - SEC_checkUserStatus ($userid); - $user_logged_in = 1; + $status = SEC_checkUserStatus($userid); + if (($status == USER_ACCOUNT_ACTIVE) || + ($status == USER_ACCOUNT_AWAITING_ACTIVATION)) { + $user_logged_in = 1; - // Create new session and write cookie - $sessid = SESS_newSession ($userid, $_SERVER['REMOTE_ADDR'], $_CONF['session_cookie_timeout'], $_CONF['cookie_ip']); - SESS_setSessionCookie ($sessid, $_CONF['session_cookie_timeout'], $_CONF['cookie_session'], $_CONF['cookie_path'], $_CONF['cookiedomain'], $_CONF['cookiesecure']); - $userdata = SESS_getUserDataFromId ($userid); - $_USER = $userdata; - $_USER['auto_login'] = true; + // Create new session and write cookie + $sessid = SESS_newSession($userid, $_SERVER['REMOTE_ADDR'], $_CONF['session_cookie_timeout'], $_CONF['cookie_ip']); + SESS_setSessionCookie($sessid, $_CONF['session_cookie_timeout'], $_CONF['cookie_session'], $_CONF['cookie_path'], $_CONF['cookiedomain'], $_CONF['cookiesecure']); + $userdata = SESS_getUserDataFromId($userid); + $_USER = $userdata; + $_USER['auto_login'] = true; + } } } } @@ -204,8 +214,7 @@ } // Ensure $_USER is set to avoid warnings (path exposure...) - if(isset($_USER)) - { + if (isset($_USER)) { return $_USER; } else { return NULL; @@ -284,16 +293,16 @@ if ($_SESS_VERBOSE) COM_errorLog("*************leaving SESS_newSession*****************",1); if ($md5_based == 1) { // Cellular phones IP address is changed frequently. So, seve it. - if( function_exists( 'CUSTOM_MOBILE_is_cellular' ) && CUSTOM_MOBILE_is_cellular()) { + if( function_exists( 'CUSTOM_MOBILE_is_cellular' ) && CUSTOM_MOBILE_is_cellular()) { CUSTOM_MOBILE_save_session($md5_sessid, $remote_ip); } return $md5_sessid; } else { // Cellular phones IP address is changed frequently. So, save it. - if( function_exists( 'CUSTOM_MOBILE_is_cellular' ) && CUSTOM_MOBILE_is_cellular()) { + if( function_exists( 'CUSTOM_MOBILE_is_cellular' ) && CUSTOM_MOBILE_is_cellular()) { CUSTOM_MOBILE_save_session($sessid, $remote_ip); } - return $sessid; + return $sessid; } } else { echo DB_error().": ".DB_error()."<br" . XHTML . ">"; @@ -359,7 +368,7 @@ // Cellular phones IP address is changed frequently. So, load saived one. if( function_exists( 'CUSTOM_MOBILE_is_cellular' ) && CUSTOM_MOBILE_is_cellular()) { CUSTOM_MOBILE_debug("remote_ip: $remote_ip"); - $remote_ip = CUSTOM_MOBILE_load_ip(); + $remote_ip = CUSTOM_MOBILE_load_ip(); CUSTOM_MOBILE_debug("remote_ip from mobile session: $remote_ip"); } @@ -372,7 +381,7 @@ } if ($_SESS_VERBOSE) { - COM_errorLog("SQL in SESS_getUserIdFromSession is:\n<br" . XHTML . "> $sql <br" . XHTML . ">\n"); + COM_errorLog("SQL in SESS_getUserIdFromSession is:\n $sql\n"); } $result = DB_query($sql); Modified: trunk/geeklog-1-jp/system/lib-story.php ============================================================================== --- trunk/geeklog-1-jp/system/lib-story.php (original) +++ trunk/geeklog-1-jp/system/lib-story.php Sun Sep 28 20:27:53 2008 @@ -36,7 +36,7 @@ // $Id: lib-story.php,v 1.133 2008/09/21 08:37:12 dhaun Exp $ if (strpos(strtolower($_SERVER['PHP_SELF']), 'lib-story.php') !== false) { - die ('This file can not be used on its own!'); + die('This file can not be used on its own!'); } require_once $_CONF['path_system'] . '/classes/story.class.php'; @@ -208,14 +208,20 @@ // n = 'Compact display' for list of stories. p = 'Preview' mode. if ((($index != 'n') && ($index != 'p')) || !empty($query)) { - $article->set_var( 'start_storylink_anchortag', '<a href="' - . $articleUrl . '" class="non-ul">' ); - $article->set_var( 'end_storylink_anchortag', '</a>' ); - $article->set_var( 'story_title_link', + $attributes = ' class="non-ul"'; + $attr_array = array('class' => 'non-ul'); + if (!empty($query)) { + $attributes .= ' rel="bookmark"'; + $attr_array['rel'] = 'bookmark'; + } + $article->set_var('start_storylink_anchortag', + '<a href="' . $articleUrl . '"' . $attributes); + $article->set_var('end_storylink_anchortag', '</a>'); + $article->set_var('story_title_link', COM_createLink( $story->DisplayElements('title'), $articleUrl, - array('class'=>'non-ul') + $attr_array ) ); } else { @@ -305,6 +311,7 @@ { $article->set_var( 'story_introtext', $introtext ); $article->set_var( 'story_text_no_br', $introtext ); + $article->set_var( 'story_introtext_only', $introtext ); if( !empty( $bodytext )) { @@ -740,8 +747,12 @@ $retval[] = trim (PLG_replaceTags ($excerpt)); break; case 'feed': - $feedfile = DB_getItem ($_TABLES['syndication'], 'filename', - "topic = '::all'"); + $feedfile = DB_getItem($_TABLES['syndication'], 'filename', + "topic = '::all'"); + if (empty($feedfile)) { + $feedfile = DB_getItem($_TABLES['syndication'], 'filename', + "topic = '::frontpage'"); + } if (empty ($feedfile)) { $feedfile = DB_getItem ($_TABLES['syndication'], 'filename', "topic = '{$A['tid']}'"); @@ -773,210 +784,6 @@ } /** -* This replaces all article image HTML in intro and body with -* GL special syntax -* -* @param string $sid ID for story to parse -* @param string $intro Intro text -* @param string $body Body text -* @return string processed text -* -*/ -function STORY_replace_images($sid, $intro, $body) -{ - global $_CONF, $_TABLES, $LANG24; - - $stdImageLoc = true; - if (!strstr($_CONF['path_images'], $_CONF['path_html'])) { - $stdImageLoc = false; - } - $result = DB_query("SELECT ai_filename FROM {$_TABLES['article_images']} WHERE ai_sid = '$sid' ORDER BY ai_img_num"); - $nrows = DB_numRows($result); - for ($i = 1; $i <= $nrows; $i++) { - $A = DB_fetchArray($result); - - $imageX = '[image' . $i . ']'; - $imageX_left = '[image' . $i . '_left]'; - $imageX_right = '[image' . $i . '_right]'; - - $sizeattributes = COM_getImgSizeAttributes ($_CONF['path_images'] . 'articles/' . $A['ai_filename']); - - $lLinkPrefix = ''; - $lLinkSuffix = ''; - if ($_CONF['keep_unscaled_image'] == 1) { - $lFilename_large = substr_replace ($A['ai_filename'], '_original.', - strrpos ($A['ai_filename'], '.'), 1); - $lFilename_large_complete = $_CONF['path_images'] . 'articles/' - . $lFilename_large; - if ($stdImageLoc) { - $imgpath = substr ($_CONF['path_images'], - strlen ($_CONF['path_html'])); - $lFilename_large_URL = $_CONF['site_url'] . '/' . $imgpath - . 'articles/' . $lFilename_large; - } else { - $lFilename_large_URL = $_CONF['site_url'] - . '/getimage.php?mode=show&image=' . $lFilename_large; - } - if (file_exists ($lFilename_large_complete)) { - $lLinkPrefix = '<a href="' . $lFilename_large_URL - . '" title="' . $LANG24[57] . '">'; - $lLinkSuffix = '</a>'; - } - } - - if ($stdImageLoc) { - $imgpath = substr ($_CONF['path_images'], - strlen ($_CONF['path_html'])); - $imgSrc = $_CONF['site_url'] . '/' . $imgpath . 'articles/' - . $A['ai_filename']; - } else { - $imgSrc = $_CONF['site_url'] - . '/getimage.php?mode=articles&image=' . $A['ai_filename']; - } - $norm = $lLinkPrefix . '<img ' . $sizeattributes . 'src="' . $imgSrc . '" alt=""' . XHTML . '>' . $lLinkSuffix; - $left = $lLinkPrefix . '<img ' . $sizeattributes . 'class="alignleft" src="' . $imgSrc . '" alt=""' . XHTML . '>' . $lLinkSuffix; - $right = $lLinkPrefix . '<img ' . $sizeattributes . 'class="alignright" src="' . $imgSrc . '" alt=""' . XHTML . '>' . $lLinkSuffix; - - $fulltext = $intro . ' ' . $body; - $intro = str_replace ($norm, $imageX, $intro); - $body = str_replace ($norm, $imageX, $body); - $intro = str_replace ($left, $imageX_left, $intro); - $body = str_replace ($left, $imageX_left, $body); - $intro = str_replace ($right, $imageX_right, $intro); - $body = str_replace ($right, $imageX_right, $body); - - if (($_CONF['allow_user_scaling'] == 1) and - ($_CONF['keep_unscaled_image'] == 1)){ - - $unscaledX = '[unscaled' . $i . ']'; - $unscaledX_left = '[unscaled' . $i . '_left]'; - $unscaledX_right = '[unscaled' . $i . '_right]'; - - if (file_exists ($lFilename_large_complete)) { - $sizeattributes = COM_getImgSizeAttributes($lFilename_large_complete); - $norm = '<img ' . $sizeattributes . 'src="' . $lFilename_large_URL . '" alt=""' . XHTML . '>'; - $left = '<img ' . $sizeattributes . 'align="left" src="' . $lFilename_large_URL . '" alt=""' . XHTML . '>'; - $right = '<img ' . $sizeattributes . 'align="right" src="' . $lFilename_large_URL . '" alt=""' . XHTML . '>'; - } - $intro = str_replace ($norm, $unscaledX, $intro); - $body = str_replace ($norm, $unscaledX, $body); - $intro = str_replace ($left, $unscaledX_left, $intro); - $body = str_replace ($left, $unscaledX_left, $body); - $intro = str_replace ($right, $unscaledX_right, $intro); - $body = str_replace ($right, $unscaledX_right, $body); - } - } - - return array($intro, $body); -} - -/** -* Replaces simple image syntax with actual HTML in the intro and body. -* If errors occur it will return all errors in $error -* -* @param string $sid ID for story to parse -* @param string $intro Intro text -* @param string $body Body text -* @param string $usage 'html' for normal use, 'email' for email use -* @return string Processed text -* -*/ -function STORY_insert_images($sid, $intro, $body, $usage='html') -{ - global $_CONF, $_TABLES, $LANG24; - - $result = DB_query("SELECT ai_filename FROM {$_TABLES['article_images']} WHERE ai_sid = '$sid' ORDER BY ai_img_num"); - $nrows = DB_numRows($result); - $errors = array(); - $stdImageLoc = true; - if (!strstr($_CONF['path_images'], $_CONF['path_html'])) { - $stdImageLoc = false; - } - for ($i = 1; $i <= $nrows; $i++) { - $A = DB_fetchArray($result); - - $lLinkPrefix = ''; - $lLinkSuffix = ''; - if ($_CONF['keep_unscaled_image'] == 1) { - $lFilename_large = substr_replace ($A['ai_filename'], '_original.', - strrpos ($A['ai_filename'], '.'), 1); - $lFilename_large_complete = $_CONF['path_images'] . 'articles/' - . $lFilename_large; - if ($stdImageLoc) { - $imgpath = substr ($_CONF['path_images'], - strlen ($_CONF['path_html'])); - $lFilename_large_URL = $_CONF['site_url'] . '/' . $imgpath - . 'articles/' . $lFilename_large; - } else { - $lFilename_large_URL = $_CONF['site_url'] - . '/getimage.php?mode=show&image=' . $lFilename_large; - } - if (file_exists ($lFilename_large_complete)) { - $lLinkPrefix = '<a href="' . $lFilename_large_URL - . '" title="' . $LANG24[57] . '">'; - $lLinkSuffix = '</a>'; - } - } - - $sizeattributes = COM_getImgSizeAttributes ($_CONF['path_images'] . 'articles/' . $A['ai_filename']); - - $norm = '[image' . $i . ']'; - $left = '[image' . $i . '_left]'; - $right = '[image' . $i . '_right]'; - - $unscalednorm = '[unscaled' . $i . ']'; - $unscaledleft = '[unscaled' . $i . '_left]'; - $unscaledright = '[unscaled' . $i . '_right]'; - - $fulltext = $intro . ' ' . $body; - $icount = substr_count($fulltext, $norm) + substr_count($fulltext, $left) + substr_count($fulltext, $right); - $icount = $icount + substr_count($fulltext, $unscalednorm) + substr_count($fulltext, $unscaledleft) + substr_count($fulltext, $unscaledright); - if ($icount == 0) { - // There is an image that wasn't used, create an error - $errors[] = $LANG24[48] . " #$i, {$A['ai_filename']}, " . $LANG24[53]; - } else { - // Only parse if we haven't encountered any error to this point - if (count($errors) == 0) { - if ($usage=='email') { // image will be attached, no path necessary - $imgSrc = $A['ai_filename']; - } elseif ($stdImageLoc) { - $imgpath = substr ($_CONF['path_images'], - strlen ($_CONF['path_html'])); - $imgSrc = $_CONF['site_url'] . '/' . $imgpath . 'articles/' - . $A['ai_filename']; - } else { - $imgSrc = $_CONF['site_url'] . '/getimage.php?mode=articles&image=' . $A['ai_filename']; - } - $intro = str_replace($norm, $lLinkPrefix . '<img ' . $sizeattributes . 'src="' . $imgSrc . '" alt=""' . XHTML . '>' . $lLinkSuffix, $intro); - $body = str_replace($norm, $lLinkPrefix . '<img ' . $sizeattributes . 'src="' . $imgSrc . '" alt=""' . XHTML . '>' . $lLinkSuffix, $body); - $intro = str_replace($left, $lLinkPrefix . '<img ' . $sizeattributes . 'align="left" src="' . $imgSrc . '" alt=""' . XHTML . '>' . $lLinkSuffix, $intro); - $body = str_replace($left, $lLinkPrefix . '<img ' . $sizeattributes . 'align="left" src="' . $imgSrc . '" alt=""' . XHTML . '>' . $lLinkSuffix, $body); - $intro = str_replace($right, $lLinkPrefix . '<img ' . $sizeattributes . 'align="right" src="' . $imgSrc . '" alt=""' . XHTML . '>' . $lLinkSuffix, $intro); - $body = str_replace($right, $lLinkPrefix . '<img ' . $sizeattributes . 'align="right" src="' . $imgSrc . '" alt=""' . XHTML . '>' . $lLinkSuffix, $body); - - if (($_CONF['allow_user_scaling'] == 1) and - ($_CONF['keep_unscaled_image'] == 1)) { - - if (file_exists ($lFilename_large_complete)) { - $imgSrc = $lFilename_large_URL; - $sizeattributes = COM_getImgSizeAttributes ($lFilename_large_complete); - } - $intro = str_replace($unscalednorm, '<img ' . $sizeattributes . 'src="' . $imgSrc . '" alt=""' . XHTML . '>', $intro); - $body = str_replace($unscalednorm, '<img ' . $sizeattributes . 'src="' . $imgSrc . '" alt=""' . XHTML . '>', $body); - $intro = str_replace($unscaledleft, '<img ' . $sizeattributes . 'align="left" src="' . $imgSrc . '" alt=""' . XHTML . '>', $intro); - $body = str_replace($unscaledleft, '<img ' . $sizeattributes . 'align="left" src="' . $imgSrc . '" alt=""' . XHTML . '>', $body); - $intro = str_replace($unscaledright, '<img ' . $sizeattributes . 'align="right" src="' . $imgSrc . '" alt=""' . XHTML . '>', $intro); - $body = str_replace($unscaledright, '<img ' . $sizeattributes . 'align="right" src="' . $imgSrc . '" alt=""' . XHTML . '>', $body); - } - - } - } - } - - return array($errors, $intro, $body); -} - -/** * Delete a story. * * This is used to delete a story from the list of stories. @@ -1083,8 +890,12 @@ /* Apply filters to the parameters passed by the webservice */ if ($args['gl_svc']) { - $args['mode'] = COM_applyBasicFilter($args['mode']); - $args['editopt'] = COM_applyBasicFilter($args['editopt']); + if (isset($args['mode'])) { + $args['mode'] = COM_applyBasicFilter($args['mode']); + } + if (isset($args['editopt'])) { + $args['editopt'] = COM_applyBasicFilter($args['editopt']); + } } /* - START: Set all the defaults - */ @@ -1109,7 +920,7 @@ } if(empty($args['owner_id'])) { - $args['owner_id'] = $_USER['uid']; + $args['owner_id'] = $_USER['uid']; } if (empty($args['group_id'])) { @@ -1181,6 +992,9 @@ // exit (); // END TEST CODE + if (!isset($args['sid'])) { + $args['sid'] = ''; + } $args['sid'] = COM_sanitizeID($args['sid']); if (!$gl_edit) { if (strlen($args['sid']) > STORY_MAX_ID_LENGTH) { @@ -1559,6 +1373,7 @@ } $output['id'] = $output['sid']; $output['category'] = array($output['tid']); + $output['published'] = date('c', $output['date']); $output['updated'] = date('c', $output['date']); if (empty($output['bodytext'])) { $output['content'] = $output['introtext']; @@ -1644,6 +1459,7 @@ } $output_item['id'] = $output_item['sid']; $output_item['category'] = array($output_item['tid']); + $output_item['published'] = date('c', $output_item['date']); $output_item['updated'] = date('c', $output_item['date']); if (empty($output_item['bodytext'])) { $output_item['content'] = $output_item['introtext']; Modified: trunk/geeklog-1-jp/system/lib-syndication.php ============================================================================== --- trunk/geeklog-1-jp/system/lib-syndication.php (original) +++ trunk/geeklog-1-jp/system/lib-syndication.php Sun Sep 28 20:27:53 2008 @@ -36,16 +36,17 @@ $_SYND_DEBUG = false; if (strpos(strtolower($_SERVER['PHP_SELF']), 'lib-syndication.php') !== false) { - die ('This file can not be used on its own!'); + die('This file can not be used on its own!'); } if ($_CONF['trackback_enabled']) { - require_once ($_CONF['path_system'] . 'lib-trackback.php'); + require_once $_CONF['path_system'] . 'lib-trackback.php'; } /** * Check if a feed for all stories needs to be updated. * +* @param bool $frontpage_only true: only articles shown on the frontpage * @param string $update_info list of story ids * @param string $limit number of entries or number of hours * @param string $updated_topic (optional) topic to be updated @@ -53,7 +54,7 @@ * @return bool false = feed needs to be updated * */ -function SYND_feedUpdateCheckAll( $update_info, $limit, $updated_topic = '', $updated_id = '' ) +function SYND_feedUpdateCheckAll( $frontpage_only, $update_info, $limit, $updated_topic = '', $updated_id = '' ) { global $_CONF, $_TABLES, $_SYND_DEBUG; @@ -91,6 +92,9 @@ $tlist = "'" . implode( "','", $topiclist ) . "'"; $where .= " AND (tid IN ($tlist))"; } + if ($frontpage_only) { + $where .= ' AND frontpage = 1'; + } $result = DB_query( "SELECT sid FROM {$_TABLES['stories']} WHERE draft_flag = 0 AND date <= NOW() $where AND perm_anon > 0 ORDER BY date DESC $limitsql" ); $nrows = DB_numRows( $result ); @@ -186,23 +190,24 @@ * @return bool false = feed has to be updated, true = ok * */ -function SYND_feedUpdateCheck( $topic, $update_data, $limit, $updated_topic = '', $updated_id = '' ) +function SYND_feedUpdateCheck($topic, $update_data, $limit, $updated_topic = '', $updated_id = '') { $is_current = true; - switch( $topic ) - { - case '::all': - { - $is_current = SYND_feedUpdateCheckAll( $update_data, $limit, - $updated_topic, $updated_id ); - } + switch($topic) { + case '::all': + $is_current = SYND_feedUpdateCheckAll(false, $update_data, $limit, + $updated_topic, $updated_id); break; - default: - { - $is_current = SYND_feedUpdateCheckTopic( $topic, $update_data, - $limit, $updated_topic, $updated_id ); - } + + case '::frontpage': + $is_current = SYND_feedUpdateCheckAll(true, $update_data, $limit, + $updated_topic, $updated_id); + break; + + default: + $is_current = SYND_feedUpdateCheckTopic($topic, $update_data, + $limit, $updated_topic, $updated_id); break; } @@ -266,6 +271,18 @@ $fulltext = trim( $fulltext ); $fulltext = preg_replace( "/(\015)/", "", $fulltext ); + + if( $row['postmode'] == 'plaintext' ) + { + if( !empty($storytext) ) + { + $storytext = nl2br($storytext); + } + if( !empty($fulltext) ) + { + $fulltext = nl2br($fulltext); + } + } $storylink = COM_buildUrl( $_CONF['site_url'] . '/article.php?story=' . $row['sid'] ); @@ -303,6 +320,7 @@ /** * Get content for a feed that holds all stories. * +* @param bool $frontpage_only true: only articles shown on the frontpage * @param string $limit number of entries or number of stories * @param string $link link to homepage * @param string $update list of story ids @@ -311,7 +329,7 @@ * @return array content of the feed * */ -function SYND_getFeedContentAll( $limit, &$link, &$update, $contentLength, $feedType, $feedVersion, $fid) +function SYND_getFeedContentAll($frontpage_only, $limit, &$link, &$update, $contentLength, $feedType, $feedVersion, $fid) { global $_TABLES, $_CONF, $LANG01; @@ -354,6 +372,9 @@ { $where .= " AND (tid IN ($tlist))"; } + if ($frontpage_only) { + $where .= ' AND frontpage = 1'; + } $result = DB_query( "SELECT sid,tid,uid,title,introtext,bodytext,postmode,UNIX_TIMESTAMP(date) AS modified,commentcode,trackbackcode FROM {$_TABLES['stories']} WHERE draft_flag = 0 AND date <= NOW() $where AND perm_anon > 0 ORDER BY date DESC $limitsql" ); @@ -373,33 +394,43 @@ $storytext = SYND_truncateSummary( $fulltext, $contentLength ); $fulltext = trim( $fulltext ); $fulltext = preg_replace( "/(\015)/", "", $fulltext ); - + + if( $row['postmode'] == 'plaintext' ) + { + if( !empty($storytext) ) + { + $storytext = nl2br($storytext); + } + if( !empty($fulltext) ) + { + $fulltext = nl2br($fulltext); + } + } + $storylink = COM_buildUrl( $_CONF['site_url'] . '/article.php?story=' . $row['sid'] ); - $extensionTags = PLG_getFeedElementExtensions('article', $row['sid'], $feedType, $feedVersion, $fid, '::all'); + $extensionTags = PLG_getFeedElementExtensions('article', $row['sid'], $feedType, $feedVersion, $fid, ($frontpage_only ? '::frontpage' : '::all')); if( $_CONF['trackback_enabled'] && ($feedType == 'RSS') && ($row['trackbackcode'] >= 0)) { $trbUrl = TRB_makeTrackbackUrl( $row['sid'] ); $extensionTags['trackbacktag'] = '<trackback:ping>'.htmlspecialchars($trbUrl).'</trackback:ping>'; } $article = array( 'title' => $storytitle, - 'summary' => $storytext, - 'text' => $fulltext, - 'link' => $storylink, - 'uid' => $row['uid'], - 'author' => COM_getDisplayName( $row['uid'] ), - 'date' => $row['modified'], - 'format' => $row['postmode'], - 'topic' => $topics[$row['tid']], - 'extensions' => $extensionTags - ); + 'summary' => $storytext, + 'text' => $fulltext, + 'link' => $storylink, + 'uid' => $row['uid'], + 'author' => COM_getDisplayName( $row['uid'] ), + 'date' => $row['modified'], + 'format' => $row['postmode'], + 'topic' => $topics[$row['tid']], + 'extensions' => $extensionTags + ); if($row['commentcode'] >= 0) { $article['commenturl'] = $storylink . '#comments'; } $content[] = $article; - - } $link = $_CONF['site_url']; @@ -425,10 +456,10 @@ if( $A['is_enabled'] == 1 ) { // Import the feed handling classes: - require_once( $_CONF['path_system'] - . '/classes/syndication/parserfactory.class.php' ); - require_once( $_CONF['path_system'] - . '/classes/syndication/feedparserbase.class.php' ); + require_once $_CONF['path_system'] + . '/classes/syndication/parserfactory.class.php'; + require_once $_CONF['path_system'] + . '/classes/syndication/feedparserbase.class.php'; // Load the actual feed handlers: $factory = new FeedParserFactory( $_CONF['path_system'] @@ -441,38 +472,35 @@ $feed->encoding = $A['charset']; $feed->lang = $A['language']; - if( $A['type'] == 'geeklog' ) - { - if( $A['topic'] == '::all') - { - $content = SYND_getFeedContentAll( $A['limits'], $link, - $data, $A['content_length'], - $format[0], $format[1], $fid ); + if ($A['type'] == 'article') { + if ($A['topic'] == '::all') { + $content = SYND_getFeedContentAll(false, $A['limits'], + $link, $data, $A['content_length'], + $format[0], $format[1], $fid); + } elseif ($A['topic'] == '::frontpage') { + $content = SYND_getFeedContentAll(true, $A['limits'], + $link, $data, $A['content_length'], + $format[0], $format[1], $fid); + } else { // feed for a single topic only + $content = SYND_getFeedContentPerTopic($A['topic'], + $A['limits'], $link, $data, + $A['content_length'], $format[0], + $format[1], $fid); } - else // feed for a single topic only - { - $content = SYND_getFeedContentPerTopic( $A['topic'], - $A['limits'], $link, $data, $A['content_length'], - $format[0], $format[1], $fid ); - } - } - else - { - $content = PLG_getFeedContent( $A['type'], $fid, $link, $data, $format[0], $format[1] ); + } else { + $content = PLG_getFeedContent($A['type'], $fid, $link, $data, $format[0], $format[1]); + // can't randomly change the api to send a max length, so // fix it here: - if ($A['content_length'] != 1) - { - $count = count( $content ); - for( $i = 0; $i < $count; $i++ ) - { + if ($A['content_length'] != 1) { + $count = count($content); + for ($i = 0; $i < $count; $i++ ) { $content[$i]['summary'] = SYND_truncateSummary( - $content[$i]['text'], $A['content_length'] ); + $content[$i]['text'], $A['content_length']); } } } - if( empty( $link )) - { + if (empty($link)) { $link = $_CONF['site_url']; } @@ -649,6 +677,21 @@ $url .= $feedfile; return $url; +} + +/** +* Helper function: Return MIME type for a feed format +* +* @param string $format internal name of the feed format, e.g. Atom-1.0 +* @return string MIME type, e.g. application/atom+xml +* +*/ +function SYND_getMimeType($format) +{ + $fmt = explode('-', $format); + $type = strtolower($fmt[0]); + + return 'application/' . $type . '+xml'; } ?> Modified: trunk/geeklog-1-jp/system/lib-user.php ============================================================================== --- trunk/geeklog-1-jp/system/lib-user.php (original) +++ trunk/geeklog-1-jp/system/lib-user.php Sun Sep 28 20:27:53 2008 @@ -8,7 +8,7 @@ // | | // | User-related functions needed in more than one place. | // +---------------------------------------------------------------------------+ -// | Copyright (C) 2000-2007 by the following authors: | +// | Copyright (C) 2000-2008 by the following authors: | // | | // | Authors: Tony Bibbs - tony AT tonybibbs DOT com | // | Mark Limburg - mlimburg AT users DOT sourceforge DOT net | @@ -35,7 +35,7 @@ // $Id: lib-user.php,v 1.49 2008/09/21 08:37:12 dhaun Exp $ if (strpos(strtolower($_SERVER['PHP_SELF']), 'lib-user.php') !== false) { - die ('This file can not be used on its own!'); + die('This file can not be used on its own!'); } /** @@ -237,15 +237,16 @@ * * NOTE: Does NOT send out password emails. * -* @param string $username user name (mandatory) -* @param string $email user's email address (mandatory) -* @param string $passwd password (optional, see above) -* @param string $fullname user's full name (optional) -* @param string $homepage user's home page (optional) -* @return int new user's ID +* @param string $username user name (mandatory) +* @param string $email user's email address (mandatory) +* @param string $passwd password (optional, see above) +* @param string $fullname user's full name (optional) +* @param string $homepage user's home page (optional) +* @param boolean $batchimport set to true when called from importuser() in admin/users.php (optional) +* @return int new user's ID * */ -function USER_createAccount ($username, $email, $passwd = '', $fullname = '', $homepage = '', $remoteusername = '', $service = '') +function USER_createAccount ($username, $email, $passwd = '', $fullname = '', $homepage = '', $remoteusername = '', $service = '',$batchimport=false) { global $_CONF, $_TABLES; @@ -323,7 +324,7 @@ // call custom registration function and plugins if ($_CONF['custom_registration'] && (function_exists ('CUSTOM_userCreate'))) { - CUSTOM_userCreate ($uid); + CUSTOM_userCreate ($uid,$batchimport); } PLG_createUser ($uid); @@ -671,6 +672,159 @@ } return $groups; +} + +/** +* Subscribe user to a topic (for the Daily Digest) +* +* @param string $tid Topic ID +* +*/ +function USER_subscribeToTopic($tid) +{ + global $_CONF, $_TABLES, $_USER; + + if ($_CONF['emailstories'] == 0) { + return; + } + + if (COM_isAnonUser()) { + return; + } + + if (!SEC_hasTopicAccess($tid)) { + return; + } + + $user_etids = DB_getItem($_TABLES['userindex'], 'etids', + "uid = {$_USER['uid']}"); + if (empty($user_etids)) { + return; // already subscribed to all topics + } + + if ($user_etids == '-') { + $user_etids = $tid; // first topic user subscribed to + } else { + $etids = explode(' ', $user_etids); + if (in_array($tid, $etids)) { + return; // already subscribed + } + $etids[] = $tid; + $user_etids = implode(' ', $etids); + } + $user_etids = addslashes($user_etids); + + DB_query("UPDATE {$_TABLES['userindex']} SET etids = '$user_etids' WHERE uid = {$_USER['uid']}"); +} + +/** +* Unsubscribe user from a topic (for the Daily Digest) +* +* @param string $tid Topic ID +* +*/ +function USER_unsubscribeFromTopic($tid) +{ + global $_CONF, $_TABLES, $_USER; + + if ($_CONF['emailstories'] == 0) { + return; + } + + if (COM_isAnonUser()) { + return; + } + + // no check for SEC_hasTopicAccess here to unsubscribe user "just in case" + + $user_etids = DB_getItem($_TABLES['userindex'], 'etids', + "uid = {$_USER['uid']}"); + if ($user_etids == '-') { + return; // not subscribed to any topics + } + + if (empty($user_etids)) { + // subscribed to all topics - get list + $etids = USER_getAllowedTopics(); + } else { + $etids = explode(' ', $user_etids); + } + + $key = array_search($tid, $etids); + if ($key === false) { + return; // not subscribed to this topic + } + + unset($etids[$key]); + + if (count($etids) == 0) { + $user_etids = '-'; + } else { + $user_etids = implode(' ', $etids); + } + $user_etids = addslashes($user_etids); + + DB_query("UPDATE {$_TABLES['userindex']} SET etids = '$user_etids' WHERE uid = {$_USER['uid']}"); +} + +/** +* Check if user is subscribed to a topic +* +* @param string $tid Topic ID +* @return boolean true: subscribed, false: not subscribed +* +*/ +function USER_isSubscribedToTopic($tid) +{ + global $_CONF, $_TABLES, $_USER; + + if ($_CONF['emailstories'] == 0) { + return false; + } + + if (COM_isAnonUser()) { + return false; + } + + if (!SEC_hasTopicAccess($tid)) { + return false; + } + + $user_etids = DB_getItem($_TABLES['userindex'], 'etids', + "uid = {$_USER['uid']}"); + if (empty($user_etids)) { + return true; // subscribed to all topics + } elseif ($user_etids == '-') { + return false; // not subscribed to any topics + } + + $etids = explode(' ', $user_etids); + + return in_array($tid, $etids); +} + +/** +* Get topics the current user has access to +* +* @return array Array of topic IDs +* +*/ +function USER_getAllowedTopics() +{ + global $_TABLES; + + $topics = array(); + + $result = DB_query("SELECT tid FROM {$_TABLES['topics']}"); + $numrows = DB_numRows($result); + for ($i = 0; $i < $numrows; $i++) { + $A = DB_fetchArray($result); + if (SEC_hasTopicAccess($A['tid'])) { + $topics[] = $A['tid']; + } + } + + return $topics; } ?> Modified: trunk/geeklog-1-jp/system/lib-webservices.php ============================================================================== --- trunk/geeklog-1-jp/system/lib-webservices.php (original) +++ trunk/geeklog-1-jp/system/lib-webservices.php Sun Sep 28 20:27:53 2008 @@ -11,6 +11,7 @@ // | Copyright (C) 2007-2008 by the following authors: | // | | // | Authors: Ramnath R Iyer - rri AT silentyak DOT com | +// | Dirk Haun - dirk AT haun-online DOT de | // +---------------------------------------------------------------------------+ // | | // | This program is free software; you can redistribute it and/or | @@ -32,15 +33,17 @@ // $Id: lib-webservices.php,v 1.44 2008/09/21 08:37:12 dhaun Exp $ if (strpos(strtolower($_SERVER['PHP_SELF']), 'lib-webservices.php') !== false) { - die ('This file can not be used on its own!'); + die('This file can not be used on its own!'); } +define('WS_ATOM_NS', 'http://www.w3.org/2005/Atom'); +define('WS_APP_NS', 'http://www.w3.org/2007/app'); +define('WS_APP_NS2', 'http://purl.org/atom/app#'); +define('WS_EXTN_NS', 'http://www.geeklog.net/xmlns/app/gl'); + $WS_PLUGIN = ''; $WS_INTROSPECTION = false; $WS_TEXT = ''; -$WS_ATOM_NS = 'http://www.w3.org/2005/Atom'; -$WS_APP_NS = 'http://www.w3.org/2007/app'; -$WS_EXTN_NS = 'http://www.geeklog.net/xmlns/app/gl'; // Set = true to enable verbose logging (in error.log) $WS_VERBOSE = false; @@ -149,8 +152,7 @@ */ function WS_post() { - global $WS_PLUGIN, $WS_ATOM_NS, $WS_APP_NS, $WS_EXTN_NS, $WS_VERBOSE, - $_CONF; + global $_CONF, $WS_PLUGIN, $WS_VERBOSE; if ($WS_VERBOSE) { COM_errorLog("WS: POST request received"); @@ -199,10 +201,10 @@ if ($ret == PLG_RET_OK) { $atom_doc = new DOMDocument('1.0', 'utf-8'); - $entry_elem = $atom_doc->createElementNS($WS_ATOM_NS, 'atom:entry'); + $entry_elem = $atom_doc->createElementNS(WS_ATOM_NS, 'atom:entry'); $atom_doc->appendChild($entry_elem); - $atom_doc->createAttributeNS($WS_APP_NS, 'app:entry'); - $atom_doc->createAttributeNS($WS_EXTN_NS, 'gl:entry'); + $atom_doc->createAttributeNS(WS_APP_NS, 'app:entry'); + $atom_doc->createAttributeNS(WS_EXTN_NS, 'gl:entry'); WS_arrayToEntryXML($out, $svc_msg['output_fields'], $entry_elem, $atom_doc); WS_write($atom_doc->saveXML()); @@ -219,8 +221,7 @@ */ function WS_put() { - global $WS_PLUGIN, $WS_ATOM_NS, $WS_APP_NS, $WS_EXTN_NS, $WS_VERBOSE, - $_CONF; + global $_CONF, $WS_PLUGIN, $WS_VERBOSE; if ($WS_VERBOSE) { COM_errorLog("WS: PUT request received"); @@ -235,7 +236,10 @@ /* Indicates that the method are being called by the webservice */ $args['gl_svc'] = true; $args['gl_edit'] = true; - $args['gl_etag'] = trim($_SERVER['HTTP_IF_MATCH'], '"'); + $args['gl_etag'] = ''; + if (isset($_SERVER['HTTP_IF_MATCH'])) { + $args['gl_etag'] = trim($_SERVER['HTTP_IF_MATCH'], '"'); + } // Call PLG_invokeService here $ret = PLG_invokeService($WS_PLUGIN, 'submit', $args, $out, $svc_msg); @@ -245,6 +249,10 @@ return; } + if (!isset($svc_msg['error_desc'])) { + $svc_msg['error_desc'] = ''; + } + WS_error($ret, $svc_msg['error_desc']); } @@ -253,8 +261,7 @@ */ function WS_get() { - global $WS_PLUGIN, $WS_INTROSPECTION, $WS_ATOM_NS, $WS_APP_NS, $WS_EXTN_NS, - $WS_VERBOSE, $_CONF, $_PLUGINS; + global $_CONF, $WS_PLUGIN, $WS_INTROSPECTION, $WS_VERBOSE, $_PLUGINS; if ($WS_VERBOSE) { COM_errorLog("WS: GET request received"); @@ -287,10 +294,10 @@ /* It might be simpler to do this part directly :-/ */ $atom_doc = new DOMDocument('1.0', 'utf-8'); - $root_elem = $atom_doc->createElementNS($WS_APP_NS, 'app:service'); + $root_elem = $atom_doc->createElementNS(WS_APP_NS, 'app:service'); $atom_doc->appendChild($root_elem); - $atom_doc->createAttributeNS($WS_ATOM_NS, 'atom:service'); - $atom_doc->createAttributeNS($WS_EXTN_NS, 'gl:service'); + $atom_doc->createAttributeNS(WS_ATOM_NS, 'atom:service'); + $atom_doc->createAttributeNS(WS_EXTN_NS, 'gl:service'); $workspace = $atom_doc->createElement('app:workspace'); $root_elem->appendChild($workspace); @@ -346,7 +353,10 @@ if (!$svc_msg['gl_feed']) { /* This is an entry, not a feed */ - $etag = trim($_SERVER['HTTP_IF_NONE_MATCH'], '"'); + $etag = ''; + if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) { + $etag = trim($_SERVER['HTTP_IF_NONE_MATCH'], '"'); + } if (!empty($etag) && ($out['updated'] == $etag)) { header($_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified'); exit(); @@ -355,10 +365,10 @@ } $atom_doc = new DOMDocument('1.0', 'utf-8'); - $entry_elem = $atom_doc->createElementNS($WS_ATOM_NS, 'atom:entry'); + $entry_elem = $atom_doc->createElementNS(WS_ATOM_NS, 'atom:entry'); $atom_doc->appendChild($entry_elem); - $atom_doc->createAttributeNS($WS_APP_NS, 'app:entry'); - $atom_doc->createAttributeNS($WS_EXTN_NS, 'gl:entry'); + $atom_doc->createAttributeNS(WS_APP_NS, 'app:entry'); + $atom_doc->createAttributeNS(WS_EXTN_NS, 'gl:entry'); WS_arrayToEntryXML($out, $svc_msg['output_fields'], $entry_elem, $atom_doc); WS_write($atom_doc->saveXML()); @@ -366,10 +376,10 @@ /* Output the feed here */ $atom_doc = new DOMDocument('1.0', 'utf-8'); - $feed_elem = $atom_doc->createElementNS($WS_ATOM_NS, 'atom:feed'); + $feed_elem = $atom_doc->createElementNS(WS_ATOM_NS, 'atom:feed'); $atom_doc->appendChild($feed_elem); - $atom_doc->createAttributeNS($WS_APP_NS, 'app:feed'); - $atom_doc->createAttributeNS($WS_EXTN_NS, 'gl:feed'); + $atom_doc->createAttributeNS(WS_APP_NS, 'app:feed'); + $atom_doc->createAttributeNS(WS_EXTN_NS, 'gl:feed'); $feed_id = $atom_doc->createElement('atom:id', $_CONF['site_name']); $feed_elem->appendChild($feed_id); @@ -414,8 +424,7 @@ */ function WS_delete() { - global $WS_PLUGIN, $WS_ATOM_NS, $WS_APP_NS, $WS_EXTN_NS, $WS_VERBOSE, - $_CONF; + global $_CONF, $WS_PLUGIN, $WS_VERBOSE; if ($WS_VERBOSE) { COM_errorLog("WS: DELETE request received"); @@ -456,11 +465,13 @@ switch ($type) { case 'text': + case 'text/plain': $args['content'] = (string) $node->nodeValue; $args['content_type'] = 'text'; break; case 'html': + case 'text/html': $args['content'] = (string) $node->nodeValue; $args['content_type'] = 'html'; break; @@ -496,7 +507,7 @@ */ function WS_xmlToArgs(&$args) { - global $_USER, $WS_EXTN_NS, $WS_ATOM_NS, $WS_APP_NS; + global $_USER; /* Previous data in args is NOT deleted */ @@ -512,7 +523,7 @@ } /* Get the action, if it exists */ - $action_element = $entry_element->getElementsByTagNameNS($WS_EXTN_NS, 'action')->item(0); + $action_element = $entry_element->getElementsByTagNameNS(WS_EXTN_NS, 'action')->item(0); $action = ''; if ($action_element != null) { $args['action'] = strtolower((string)($action_element->firstChild->data)); @@ -524,9 +535,10 @@ for ($index = 0; $index < $nodes->length; $index++) { $node = $nodes->item($index); - if (($node->namespaceURI != $WS_ATOM_NS) && - ($node->namespaceURI != $WS_APP_NS ) && - ($node->namespaceURI != $WS_EXTN_NS)) { + if (($node->namespaceURI != WS_ATOM_NS) && + ($node->namespaceURI != WS_APP_NS) && + ($node->namespaceURI != WS_APP_NS2) && + ($node->namespaceURI != WS_EXTN_NS)) { continue; } @@ -536,7 +548,7 @@ if ($author_name_element != null) { $args['author_name'] = (string)($author_name_element->firstChild->nodeValue); } - $author_uid_element = $node->getElementsByTagNameNS($WS_EXTN_NS, 'uid')->item(0); + $author_uid_element = $node->getElementsByTagNameNS(WS_EXTN_NS, 'uid')->item(0); if ($author_uid_element != null) { $args['uid'] = (string)($author_uid_element->firstChild->nodeValue); } @@ -547,9 +559,34 @@ case 'updated': $args['updated'] = (string)$node->firstChild->nodeValue; break; + case 'edited': + $args['edited'] = (string)$node->firstChild->nodeValue; + break; + case 'published': + $args['published'] = (string)$node->firstChild->nodeValue; + break; case 'content': WS_getContent($args, $atom_doc, $node); break; + case 'control': + if ($node->nodeType == XML_ELEMENT_NODE) { + $child_nodes = $node->childNodes; + if ($child_nodes == null) { + continue; + } + $args[$node->localName] = array(); + for ($i = 0; $i < $child_nodes->length; $i++) { + $child_node = $child_nodes->item($i); + if ($child_node->nodeType == XML_ELEMENT_NODE) { + if ($child_node->firstChild->nodeType == XML_TEXT_NODE) { + $args[$node->localName][$child_node->localName] + = $child_node->firstChild->nodeValue; + break; + } + } + } + } + break; default: if ($node->nodeType == XML_ELEMENT_NODE) { $is_array = 1; @@ -567,23 +604,30 @@ if ($child_node->firstChild->nodeType == XML_TEXT_NODE) { $args[$node->localName][$node->firstChild->localName] = $child_node->firstChild->nodeValue; } + } elseif ($child_node->nodeType == XML_CDATA_SECTION_NODE) { + $args[$node->localName] = $child_node->nodeValue; } } } } } - if (empty($args['updated'])) { - $args['updated'] = date('c'); - } - $args['publish_month'] = date('m', strtotime($args['updated'])); - $args['publish_year'] = date('Y', strtotime($args['updated'])); - $args['publish_day'] = date('d', strtotime($args['updated'])); - $args['publish_hour'] = date('H', strtotime($args['updated'])); - $args['publish_minute'] = date('i', strtotime($args['updated'])); - $args['publish_second'] = date('s', strtotime($args['updated'])); + $timestamp = date('c'); + if (!empty($args['published'])) { + $timestamp = $args['published']; + } elseif (!empty($args['updated'])) { + $timestamp = $args['updated']; + } elseif (!empty($args['edited'])) { + $timestamp = $args['edited']; + } + $args['publish_month'] = date('m', strtotime($timestamp)); + $args['publish_year'] = date('Y', strtotime($timestamp)); + $args['publish_day'] = date('d', strtotime($timestamp)); + $args['publish_hour'] = date('H', strtotime($timestamp)); + $args['publish_minute'] = date('i', strtotime($timestamp)); + $args['publish_second'] = date('s', strtotime($timestamp)); - if (isset($args['control'])) { + if (isset($args['control']) && is_array($args['control'])) { foreach ($args['control'] as $key => $value) { if ($key == 'draft') { $args['draft_flag'] = ($value == 'yes' ? 1 : 0); @@ -606,13 +650,18 @@ */ function WS_arrayToEntryXML($arr, $extn_elements, &$entry_elem, &$atom_doc) { - global $WS_PLUGIN, $WS_ATOM_NS, $WS_APP_NS, $WS_EXTN_NS, $_CONF; + global $_CONF, $WS_PLUGIN; /* Standard Atom elements */ $id = $atom_doc->createElement('atom:id', $arr['id']); $entry_elem->appendChild($id); + if (!empty($arr['published'])) { + $published = $atom_doc->createElement('atom:published', $arr['published']); + $entry_elem->appendChild($published); + } + $updated = $atom_doc->createElement('atom:updated', $arr['updated']); $entry_elem->appendChild($updated); @@ -672,26 +721,29 @@ // Geeklog-specific elements foreach ($extn_elements as $elem) { - if (is_array($arr[$elem])) { - $count = 0; - $extn_elem = $atom_doc->createElement('gl:' . $elem); - foreach ($arr[$elem] as $param) { - if (empty($param)) { - continue; - } - $count += 1; + if (isset($arr[$elem])) { + if (is_array($arr[$elem])) { + $count = 0; + $extn_elem = $atom_doc->createElement('gl:' . $elem); + foreach ($arr[$elem] as $param) { + if (empty($param)) { + continue; + } - $param_elem = $atom_doc->createElement('gl:param', $param); - $extn_elem->appendChild($param_elem); - } - if ($count > 0) { - $entry_elem->appendChild($extn_elem); - } - } else { - $extn_elem = $atom_doc->createElement('gl:' . $elem, $arr[$elem]); - if (!empty($arr[$elem])) { - $entry_elem->appendChild($extn_elem); + $count += 1; + + $param_elem = $atom_doc->createElement('gl:param', $param); + $extn_elem->appendChild($param_elem); + } + if ($count > 0) { + $entry_elem->appendChild($extn_elem); + } + } else { + $extn_elem = $atom_doc->createElement('gl:' . $elem, $arr[$elem]); + if (!empty($arr[$elem])) { + $entry_elem->appendChild($extn_elem); + } } } } @@ -824,7 +876,26 @@ } if (!empty($username) && !empty($password)) { - if ($_CONF['user_login_method']['standard']) { + if ($_CONF['user_login_method']['3rdparty']) { + // remote users will have to use username @ servicename + $u = explode('@', $username); + if (count($u) > 1) { + $sv = $u[count($u) - 1]; + if (!empty($sv)) { + $modules = SEC_collectRemoteAuthenticationModules(); + foreach ($modules as $smod) { + if (strcasecmp($sv, $smod) == 0) { + array_pop($u); // drop the service name + $uname = implode('@', $u); + $status = SEC_remoteAuthentication($uname, + $password, $smod, $uid); + break; + } + } + } + } + } + if (($status == -1) && $_CONF['user_login_method']['standard']) { $status = SEC_authenticate($username, $password, $uid); } } @@ -893,7 +964,6 @@ global $WS_TEXT; $WS_TEXT .= $text; - } /** @@ -904,7 +974,6 @@ global $WS_TEXT; echo $WS_TEXT; - } /* Modified: trunk/geeklog-1-jp/system/pear/HTTP/Request.php ============================================================================== --- trunk/geeklog-1-jp/system/pear/HTTP/Request.php (original) +++ trunk/geeklog-1-jp/system/pear/HTTP/Request.php Sun Sep 28 20:27:53 2008 @@ -40,7 +40,7 @@ * @author Alexey Borzov <avb****@php*****> * @copyright 2002-2007 Richard Heyes * @license http://opensource.org/licenses/bsd-license.php New BSD License - * @version CVS: $Id: Request.php,v 1.58 2007/10/26 13:45:56 avb Exp $ + * @version CVS: $Id: Request.php,v 1.60 2008/07/21 17:41:56 avb Exp $ * @link http://pear.php.net/package/HTTP_Request/ */ @@ -116,7 +116,7 @@ * @package HTTP_Request * @author Richard Heyes <richa****@phpgu*****> * @author Alexey Borzov <avb****@php*****> - * @version Release: 1.4.2 + * @version Release: 1.4.3 */ class HTTP_Request { @@ -682,10 +682,12 @@ $host = isset($this->_proxy_host) ? $this->_proxy_host : $this->_url->host; $port = isset($this->_proxy_port) ? $this->_proxy_port : $this->_url->port; - // 4.3.0 supports SSL connections using OpenSSL. The function test determines - // we running on at least 4.3.0 - if (strcasecmp($this->_url->protocol, 'https') == 0 AND function_exists('file_get_contents') AND extension_loaded('openssl')) { - if (isset($this->_proxy_host)) { + if (strcasecmp($this->_url->protocol, 'https') == 0) { + // Bug #14127, don't try connecting to HTTPS sites without OpenSSL + if (version_compare(PHP_VERSION, '4.3.0', '<') | | !extension_loaded('openssl')) { + return PEAR::raiseError('Need PHP 4.3.0 or later with OpenSSL support for https:// requests', + HTTP_REQUEST_ERROR_URL); + } elseif (isset($this->_proxy_host)) { return PEAR::raiseError('HTTPS proxies are not supported', HTTP_REQUEST_ERROR_PROXY); } $host = 'ssl://' . $host; @@ -837,6 +839,17 @@ } /** + * Returns the response reason phrase + * + * @access public + * @return mixed Response reason phrase, false if not set + */ + function getResponseReason() + { + return isset($this->_response->_reason) ? $this->_response->_reason : false; + } + + /** * Returns either the named header or all if no name given * * @access public @@ -923,9 +936,8 @@ } } - // No post data or wrong method, so simply add a final CRLF - if (in_array($this->_method, $this->_bodyDisallowed) || - (HTTP_REQUEST_METHOD_POST != $this->_method && 0 == strlen($this->_body))) { + // Method does not allow a body, simply add a final CRLF + if (in_array($this->_method, $this->_bodyDisallowed)) { $request .= "\r\n"; @@ -986,10 +998,10 @@ "\r\n\r\n"; $request .= $this->_body; - // Terminate headers with CRLF on POST request with no body, too + // No body: send a Content-Length header nonetheless (request #12900) } else { - $request .= "\r\n"; + $request .= "Content-Length: 0\r\n\r\n"; } return $request; @@ -1096,7 +1108,7 @@ * @package HTTP_Request * @author Richard Heyes <richa****@phpgu*****> * @author Alexey Borzov <avb****@php*****> - * @version Release: 1.4.2 + * @version Release: 1.4.3 */ class HTTP_Response { @@ -1119,6 +1131,12 @@ var $_code; /** + * Response reason phrase + * @var string + */ + var $_reason; + + /** * Response headers * @var array */ @@ -1186,11 +1204,12 @@ { do { $line = $this->_sock->readLine(); - if (sscanf($line, 'HTTP/%s %s', $http_version, $returncode) != 2) { + if (!preg_match('!^(HTTP/\d\.\d) (\d{3})(?: (.+))?!', $line, $s)) { return PEAR::raiseError('Malformed response', HTTP_REQUEST_ERROR_RESPONSE); } else { - $this->_protocol = 'HTTP/' . $http_version; - $this->_code = intval($returncode); + $this->_protocol = $s[1]; + $this->_code = intval($s[2]); + $this->_reason = empty($s[3])? null: $s[3]; } while ('' !== ($header = $this->_sock->readLine())) { $this->_processHeader($header); @@ -1229,7 +1248,7 @@ $data = $this->_sock->read(min(4096, $this->_toRead)); $this->_toRead -= HTTP_REQUEST_MBSTRING? mb_strlen($data, 'iso-8859-1'): strlen($data); } - if ('' == $data) { + if ('' == $data && (!$this->_chunkLength || $this->_sock->eof())) { break; } else { $hasBody = true; @@ -1467,7 +1486,8 @@ $dataSize = $tmp[2]; // finally, call the gzinflate() function - $unpacked = @gzinflate(substr($data, $headerLength, -8), $dataSize); + // don't pass $dataSize to gzinflate, see bugs #13135, #14370 + $unpacked = gzinflate(substr($data, $headerLength, -8)); if (false === $unpacked) { return PEAR::raiseError('_decodeGzip(): gzinflate() call failed', HTTP_REQUEST_ERROR_GZIP_READ); } elseif ($dataSize != strlen($unpacked)) { Modified: trunk/geeklog-1-jp/system/pear/HTTP/Request/Listener.php ============================================================================== --- trunk/geeklog-1-jp/system/pear/HTTP/Request/Listener.php (original) +++ trunk/geeklog-1-jp/system/pear/HTTP/Request/Listener.php Sun Sep 28 20:27:53 2008 @@ -52,7 +52,7 @@ * @category HTTP * @package HTTP_Request * @author Alexey Borzov <avb****@php*****> - * @version Release: 1.4.2 + * @version Release: 1.4.3 */ class HTTP_Request_Listener { Modified: trunk/geeklog-1-jp/system/pear/Net/Socket.php ============================================================================== --- trunk/geeklog-1-jp/system/pear/Net/Socket.php (original) +++ trunk/geeklog-1-jp/system/pear/Net/Socket.php Sun Sep 28 20:27:53 2008 @@ -17,7 +17,7 @@ // | Chuck Hagenbuch <chuck****@horde*****> | // +----------------------------------------------------------------------+ // -// $Id: Socket.php,v 1.31 2007/05/04 04:30:29 chagenbu Exp $ +// $Id: Socket.php,v 1.38 2008/02/15 18:24:17 chagenbu Exp $ require_once 'PEAR.php'; @@ -123,6 +123,7 @@ $openfunc = $this->persistent ? 'pfsockopen' : 'fsockopen'; $errno = 0; $errstr = ''; + $old_track_errors = @ini_set('track_errors', 1); if ($options && function_exists('stream_context_create')) { if ($this->timeout) { $timeout = $this->timeout; @@ -130,7 +131,15 @@ $timeout = 0; } $context = stream_context_create($options); - $fp = @$openfunc($this->addr, $this->port, $errno, $errstr, $timeout, $context); + + // Since PHP 5 fsockopen doesn't allow context specification + if (function_exists('stream_socket_client')) { + $flags = $this->persistent ? STREAM_CLIENT_PERSISTENT : STREAM_CLIENT_CONNECT; + $addr = $this->addr . ':' . $this->port; + $fp = stream_socket_client($addr, $errno, $errstr, $timeout, $flags, $context); + } else { + $fp = @$openfunc($this->addr, $this->port, $errno, $errstr, $timeout, $context); + } } else { if ($this->timeout) { $fp = @$openfunc($this->addr, $this->port, $errno, $errstr, $this->timeout); @@ -140,9 +149,14 @@ } if (!$fp) { + if ($errno == 0 && isset($php_errormsg)) { + $errstr = $php_errormsg; + } + @ini_set('track_errors', $old_track_errors); return $this->raiseError($errstr, $errno); } + @ini_set('track_errors', $old_track_errors); $this->fp = $fp; return $this->setBlocking($this->blocking); @@ -152,7 +166,7 @@ * Disconnects from the peer, closes the socket. * * @access public - * @return mixed true on success or an error object otherwise + * @return mixed true on success or a PEAR_Error instance otherwise */ function disconnect() { @@ -184,7 +198,7 @@ * * @param boolean $mode True for blocking sockets, false for nonblocking. * @access public - * @return mixed true on success or an error object otherwise + * @return mixed true on success or a PEAR_Error instance otherwise */ function setBlocking($mode) { @@ -204,7 +218,7 @@ * @param integer $seconds Seconds. * @param integer $microseconds Microseconds. * @access public - * @return mixed true on success or an error object otherwise + * @return mixed true on success or a PEAR_Error instance otherwise */ function setTimeout($seconds, $microseconds) { @@ -229,7 +243,7 @@ return $this->raiseError('not connected'); } - $returned = stream_set_write_buffer($this->fp, $code); + $returned = stream_set_write_buffer($this->fp, $size); if ($returned == 0) { return true; } @@ -248,7 +262,7 @@ * </p> * * @access public - * @return mixed Array containing information about existing socket resource or an error object otherwise + * @return mixed Array containing information about existing socket resource or a PEAR_Error instance otherwise */ function getStatus() { @@ -303,7 +317,9 @@ * NULL means all at once. * * @access public - * @return mixed true on success or an error object otherwise + * @return mixed If the socket is not connected, returns an instance of PEAR_Error + * If the write succeeds, returns the number of bytes written + * If the write fails, returns false. */ function write($data, $blocksize = null) { @@ -312,7 +328,7 @@ } if (is_null($blocksize) && !OS_WINDOWS) { - return fwrite($this->fp, $data); + return @fwrite($this->fp, $data); } else { if (is_null($blocksize)) { $blocksize = 1024; @@ -432,10 +448,10 @@ } /** - * Reads an IP Address and returns it in a dot formated string + * Reads an IP Address and returns it in a dot formatted string * * @access public - * @return Dot formated string, or a PEAR_Error if + * @return Dot formatted string, or a PEAR_Error if * not connected. */ function readIPAddress() @@ -445,7 +461,7 @@ } $buf = @fread($this->fp, 4); - return sprintf("%s.%s.%s.%s", ord($buf[0]), ord($buf[1]), + return sprintf('%d.%d.%d.%d', ord($buf[0]), ord($buf[1]), ord($buf[2]), ord($buf[3])); }