[Phpbbproject-svn] SF.net SVN: phpbbproject: [264] trunk
phpBB download manager, mainly aimed at MOD authors
Status: Planning
Brought to you by:
lord_le_brand
From: <lor...@us...> - 2008-04-23 00:26:09
|
Revision: 264 http://phpbbproject.svn.sourceforge.net/phpbbproject/?rev=264&view=rev Author: lord_le_brand Date: 2008-04-22 17:26:14 -0700 (Tue, 22 Apr 2008) Log Message: ----------- Changed column project_start_id to project_owner on table project_projects Merged tables project_actions and project_action_contents Changed column is_active to project_status on table project_projects Made project_create a class Started working on import class Changed private to protected in download class Modified Paths: -------------- trunk/develop/create_schema_files_phpbb3.php trunk/phpbb3/root/includes/project/project_main.php trunk/phpbb3/root/includes/sources_project/constants.php trunk/phpbb3/root/includes/sources_project/create_project.php trunk/phpbb3/root/includes/sources_project/download_project.php trunk/phpbb3/root/styles/prosilver/template/project_viewcat.html Added Paths: ----------- trunk/develop/autopost.temp.php trunk/develop/create_project.temp.php trunk/phpbb3/root/includes/sources_project/import_project.php Added: trunk/develop/autopost.temp.php =================================================================== --- trunk/develop/autopost.temp.php (rev 0) +++ trunk/develop/autopost.temp.php 2008-04-23 00:26:14 UTC (rev 264) @@ -0,0 +1,331 @@ +<? +/** + * Handle autoposting + * + * @param array $info_array + * @param array $authors + * @param boolean|array $history + * @param boolean|array $update + * @return integer|boolean Either post_id or topic_id, depending on $update, or false on failure + */ +function project_autopost($info_array, $authors, $history = false, $update = false) +{ + global $db, $config, $user, $auth; + global $phpbb_root_path, $phpEx; + + include_once("{$phpbb_root_path}includes/functions_posting.$phpEx"); + include_once("{$phpbb_root_path}includes/message_parser.$phpEx"); + + $forum_root_path = generate_board_url(); + + $stages_ary = array( + PROJECT_STAGE_ALPHA => $user->lang['PROJECT_STAGE_ALPHA'], + PROJECT_STAGE_BETA => $user->lang['PROJECT_STAGE_BETA'], + PROJECT_STAGE_DEV => $user->lang['PROJECT_STAGE_DEV'], + PROJECT_STAGE_RC => $user->lang['PROJECT_STAGE_RC'], + PROJECT_STAGE_STABLE => $user->lang['PROJECT_STAGE_STABLE'], + ); + + $post_tpl = new template(); + $post_tpl->set_custom_template("{$phpbb_root_path}store/phpbbproject/autopost", 'project_autopost'); + + if ($update) + { + // Reply to topic $info_array['topic_id'] + $topic_id = $info_array['topic_id']; + + if (!$topic_id) + { + return false; + } + + $post_tpl->set_filenames(array( + 'first_post_body' => 'topic_layout.html', + 'first_post_title' => 'topic_title.html', + 'update_post_body' => 'update_post_layout.html', + 'update_post_title' => 'update_post_title.html', + )); + + if ($history) + { + for ($i = 0, $size = sizeof($history); $i < $size; $i++) + { + $post_tpl->assign_block_vars('history', array( + 'DATE' => date('Y-m-d', $history[$i]['version_time']), + 'VERSION' => "{$history[$i]['version_major']}.{$history[$i]['version_minor']}.{$history[$i]['version_revision']}{$history[$i]['version_release']}", + 'CHANGELOG' => $history[$i]['version_changelog'], + + 'U_UPDATE_POST' => ($history[$i]['version_post_id']) ? "{$forum_root_path}viewtopic.$phpEx?t=$topic_id&p={$history[$i]['version_post_id']}#{$history[$i]['version_post_id']}" : '', + 'U_DIFF' => ($history[$i]['version_id'] && $history[$i]['previous_version_id']) ? "{$forum_root_path}project.$phpEx?i=project&mode=diff&pr={$info_array['project_id']}&dm=normal&nv={$history[$i]['version_id']}&ov={$history[$i]['previous_version_id']}" : '', + )); + } + } + + for ($i = 0, $size = sizeof($authors); $i < $size; $i++) + { + $post_tpl->assign_block_vars('author', array( + 'USERNAME' => $authors[$i]['author_username'], + 'REAL_NAME' => $authors[$i]['author_realname'], + 'EMAIL' => $authors[$i]['author_email'], + 'WEBSITE' => $authors[$i]['author_website'], + 'ROLE' => $authors[$i]['author_role_title'], + + 'S_STARTER' => ($authors[$i]['author_id'] == $info_array['project_start_id']) ? true : false, + + 'U_AUTHOR' => "{$forum_root_path}project.$phpEx?i=author&mode=view&u={$authors[$i]['author_id']}", + )); + } + + $post_tpl->assign_vars(array( + 'PROJECT_TITLE' => $info_array['project_title'], + 'PROJECT_TITLE_CLEAN' => $info_array['project_title_clean'], + 'PROJECT_DESCRIPTION' => $info_array['project_description'], + 'AUTHOR_NOTES' => $info_array['project_notes'], + + 'DATE' => $info_array['project_last_update'], + 'VERSION' => $info_array['project_version'], + 'TARGET_VERSION' => $info_array['project_target_version'], + + 'DEV_STAGE_ID' => $info_array['project_stage'], + 'DEV_STAGE_UC' => strtoupper($stages_ary[$info_array['project_stage']]), + 'DEV_STAGE_LC' => strtolower($stages_ary[$info_array['project_stage']]), + 'DEV_STAGE_NC' => $stages_ary[$info_array['project_stage']], + + 'U_DOWNLOAD' => "{$forum_root_path}project.$phpEx?i=project&mode=download&pr={$info_array['project_id']}", + 'U_PROJECT_INFO' => "{$forum_root_path}project.$phpEx?i=project&mode=view&pr={$info_array['project_id']}", + + // Update post extra vars + 'CHANGELOG' => $update['changelog'], + + 'U_DIFF' => "{$forum_root_path}project.$phpEx?i=project&mode=diff&pr={$info_array['project_id']}&dm=normal&nv={$update['version_id']}&ov={$update['previous_version_id']}", + 'U_TOPIC' => "{$forum_root_path}viewtopic.$phpEx?t=$topic_id", + + 'OLD_TARGET_VERSION' => $update['previous_target_version'], + 'OLD_VERSION' => $update['previous_version'], + 'OLD_DEV_STAGE_ID' => $update['previous_dev_stage'], + )); + + ob_start(); + $post_tpl->display('first_post_body'); + $first_post_contents = ob_get_contents(); + ob_clean(); + $post_tpl->display('first_post_title'); + $first_post_title = ob_get_contents(); + ob_clean(); + $post_tpl->display('update_post_body'); + $update_post_contents = ob_get_contents(); + ob_clean(); + $post_tpl->display('update_post_title'); + $update_post_title = ob_get_clean(); + } + else + { + $post_tpl->set_filenames(array( + 'post_body' => 'topic_layout.html', + 'post_title' => 'topic_title.html', + )); + + if ($history) + { + for ($i = 0, $size = sizeof($history); $i < $size; $i++) + { + $post_tpl->assign_block_vars('history', array( + 'DATE' => date('Y-m-d', $history[$i]['version_time']), + 'VERSION' => "{$history[$i]['version_major']}.{$history[$i]['version_minor']}.{$history[$i]['version_revision']}{$history[$i]['version_release']}", + 'CHANGELOG' => $history[$i]['version_changelog'], + + 'U_UPDATE_POST' => '', + 'U_DIFF' => '', + )); + } + } + + for ($i = 0, $size = sizeof($authors); $i < $size; $i++) + { + $post_tpl->assign_block_vars('author', array( + 'USERNAME' => $authors[$i]['author_username'], + 'REAL_NAME' => $authors[$i]['author_realname'], + 'EMAIL' => $authors[$i]['author_email'], + 'WEBSITE' => $authors[$i]['author_website'], + 'ROLE' => $authors[$i]['author_role_title'], + + 'S_STARTER' => ($authors[$i]['author_id'] == $info_array['project_start_id']) ? true : false, + 'U_AUTHOR' => "{$forum_root_path}project.$phpEx?i=author&mode=view&u={$authors[$i]['author_id']}", + )); + } + + $post_tpl->assign_vars(array( + 'PROJECT_TITLE' => $info_array['project_title'], + 'PROJECT_TITLE_CLEAN' => $info_array['project_title_clean'], + 'PROJECT_DESCRIPTION' => $info_array['project_description'], + 'AUTHOR_NOTES' => $info_array['project_notes'], + + 'DATE' => $info_array['project_last_update'], + 'VERSION' => $info_array['project_version'], + 'TARGET_VERSION' => $info_array['project_target_version'], + + 'DEV_STAGE_ID' => $info_array['project_stage'], + 'DEV_STAGE_UC' => strtoupper($stages_ary[$info_array['project_stage']]), + 'DEV_STAGE_LC' => strtolower($stages_ary[$info_array['project_stage']]), + 'DEV_STAGE_NC' => $stages_ary[$info_array['project_stage']], + + 'U_DOWNLOAD' => "{$forum_root_path}project.$phpEx?i=project&mode=download&pr={$info_array['project_id']}", + 'U_PROJECT_INFO' => "{$forum_root_path}project.$phpEx?i=project&mode=view&pr={$info_array['project_id']}", + )); + + ob_start(); + $post_tpl->display('post_body'); + $first_post_contents = ob_get_contents(); + ob_clean(); + $post_tpl->display('post_title'); + $first_post_title = ob_get_clean(); + } + + // Get forum ID + if ($config['project_autopost_forum_per_category']) + { + $sql = 'SELECT c.forum_id, f.forum_name + FROM ' . PROJECT_CATEGORIES_TABLE . ' c, ' . FORUMS_TABLE . ' f + WHERE c.category_id = ' . (int) $info_array['category_id'] . ' + AND f.forum_id = c.forum_id'; + + $db->sql_query($sql, 604800); + $forum_data = $db->sql_fetchrow(); + $db->sql_freeresult(); + } + else + { + $sql = 'SELECT forum_id, forum_name + FROM ' . FORUMS_TABLE . ' + WHERE forum_id = ' . (int) $config['project_autopost_forum_id']; + + $db->sql_query($sql, 604800); + $forum_data = $db->sql_fetchrow(); + $db->sql_freeresult(); + } + + $forum_id = $forum_data['forum_id']; + $forum_name = $forum_data['forum_name']; + + // submit_post() needs $user to be the info of the posting user, this is not the case here, so make a workaround + $this_user = $user; + + $user->data['is_registered'] = false; + $user->data['user_id'] = $config['project_autopost_user_id']; + + $sql = 'SELECT username, user_colour + FROM ' . USERS_TABLE . ' + WHERE user_id = ' . (int) $user->data['user_id']; + + $db->sql_query($sql, 604800); + $userdata = $db->sql_fetchrow(); + $db->sql_freeresult(); + + $user->data['username'] = $userdata['username']; + $user->data['user_colour'] = $userdata['user_colour']; + $user->data['user_permissions'] = ''; + $user->ip = '127.0.0.1'; + $auth->acl($user->data); + + $message_parser = new parse_message($first_post_contents); + + if ($update) + { + $update_message_parser = new parse_message($update_post_contents); + $update_message_parser->parse(1, 1, 1); + + $sql = 'SELECT t.topic_replies_real, p.post_id, p.bbcode_uid, p.post_time + FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p + WHERE t.topic_id = $topic_id + AND p.post_id = t.topic_first_post_id"; + + $db->sql_query($sql); + $post_data = $db->sql_fetchrow(); + $db->sql_freeresult(); + + $message_parser->bbcode_uid = $post_data['bbcode_uid']; + } + + $message_parser->parse(1, 1, 1); + + + // Build data array + $data = array( + 'topic_title' => $first_post_title, + 'post_subject' => $first_post_title, + 'forum_id' => $forum_id, + 'forum_name' => $forum_name, + 'icon_id' => 0, + + 'enable_bbcode' => 1, + 'enable_smilies' => 1, + 'enable_urls' => 1, + 'enable_sig' => 0, + 'enable_indexing' => 1, + + 'message' => $message_parser->message, + 'message_md5' => md5($message_parser->message), + + 'bbcode_bitfield' => $message_parser->bbcode_bitfield, + 'bbcode_uid' => $message_parser->bbcode_uid, + + 'attachment_data' => array(), + + 'post_edit_locked' => false, + 'post_time' => (isset($post_data['post_time'])) ? (int) $post_data['post_time'] : time(), + + ); + + $poll = array(); + + if ($update) + { + $data = array_merge($data, array('topic_id' => $topic_id, 'topic_first_post_id' => $post_data['post_id'], 'post_id' => $post_data['post_id'], 'topic_replies_real' => $post_data['topic_replies_real'], 'poster_id' => $user->data['user_id'], 'topic_approved' => true, 'post_approved' => true)); + submit_post('edit', $first_post_title, '', POST_NORMAL, $poll, $data); + + $update_data = array( + 'topic_id' => $topic_id, + 'post_subject' => $update_post_title, + 'forum_id' => $forum_id, + 'forum_name' => $forum_name, + 'icon_id' => 0, + + 'enable_bbcode' => 1, + 'enable_smilies' => 1, + 'enable_urls' => 1, + 'enable_sig' => 0, + 'enable_indexing' => 1, + + 'message' => $update_message_parser->message, + 'message_md5' => md5($update_message_parser->message), + + 'bbcode_bitfield' => $update_message_parser->bbcode_bitfield, + 'bbcode_uid' => $update_message_parser->bbcode_uid, + + 'attachment_data' => array(), + + 'post_edit_locked' => false, + 'post_time' => time(), + ); + + submit_post('reply', $update_post_title, '', POST_NORMAL, $poll, $update_data); + } + else + { + submit_post('post', $first_post_title, '', POST_NORMAL, $poll, $data); + } + + $user = $this_user; + $auth->acl($user->data); + + if (!$update) + { + $sql = 'UPDATE ' . PROJECT_PROJECTS_TABLE . ' + SET topic_id = ' . (int) $data['topic_id'] . ' + WHERE project_id = ' . $info_array['project_id']; + $db->sql_query($sql); + } + + return ($update) ? $update_data['post_id'] : $data['topic_id']; +} +?> \ No newline at end of file Added: trunk/develop/create_project.temp.php =================================================================== --- trunk/develop/create_project.temp.php (rev 0) +++ trunk/develop/create_project.temp.php 2008-04-23 00:26:14 UTC (rev 264) @@ -0,0 +1,169 @@ +<? + +/** + * Create a new project + * + * @param string $mode + * @param array $info_array + * @param array $authors + * @param array|boolean $history + * @param array|boolean $actions + * @param array|boolean $old_actions + * @return boolean|string Either false if succesful of the error message + */ +function project_create($mode, $info_array, $authors, $history = false, $actions = false, $old_actions = false) +{ + global $db, $config, $auth, $user; + + // Check permissions + if (!$auth->acl_get('p_add_project')) + { + return $user->lang['PROJECT_NOT_AUTH_CREATE']; + } + if (!$auth->acl_get('p_view_category', $info_array['category_id'])) + { + return $user->lang['PROJECT_NOT_AUTH_CAT']; + } + + // Time & date of project creation + $current_time = time(); + + // History and action information are only needed for importing + if ($mode != 'import') + { + $history = $actions = $old_actions = false; + } + + // Variable types for database protection + $info_vars = array('category_id' => 'int' + , 'project_title' => 'string', + 'project_description' => 'string', + 'project_notes' => 'string', + 'project_license' => 'int', + 'project_target_version' => 'string', + 'project_version' => 'string', + 'project_stage' => 'int', + 'project_logo' => 'string', + 'project_logo_type' => 'int', + 'project_logo_width' => 'int', + 'project_logo_height' => 'int', + 'is_active' => 'int', + 'file_only' => 'int'); + + $error_message = ''; + foreach ($info_vars AS $var => $type) + { + if (!isset($info_array[$var])) + { + $error_message .= (($error_message) ? '<br />' : '') . sprintf($user->lang['FIELD_REQUIRED'], $var); + } + + $$var = ($type == 'string') ? $db->sql_escape($info_array[$var]) : intval($info_array[$var]); + } + if (!empty($error_message)) + { + return $error_message; + } + + // Clean title for uniqueness + $info_array['project_title_clean'] = utf8_clean_string($info_array['project_title']); + $project_title_clean = $db->sql_escape($info_array['project_title_clean']); + + $info_array['project_install_time'] = ($actions) ? project_generate_install_time($actions) : 0; + $info_array['project_level'] = ($actions) ? project_generate_level('actions', $actions) : PROJECT_LEVEL_EASY; + + $info_array['project_start_time'] = (empty($info_array['project_start_time'])) ? $current_time : intval($info_array['project_start_time']); + $info_array['project_start_id'] = (empty($info_array['project_start_id'])) ? $user->data['user_id'] : intval($info_array['project_start_id']); + $info_array['project_start_author'] = (empty($info_array['project_start_author'])) ? project_get_author_name($user->data['user_id']) : $info_array['project_start_author']; + + $project_start_author = $db->sql_escape($info_array['project_start_author']); + + $info_array['project_last_update'] = $current_time; + + /** + * @todo $authors, $history, $actions, $old_actions... Also, add some setting for permissions + */ + + // All set to go into the database :-) + $db->sql_transaction('begin'); + + $sql = 'INSERT INTO ' . PROJECT_PROJECTS_TABLE . " (category_id, project_title, project_title_clean, project_description, project_level, project_install_time, project_notes, project_license, project_target_version, project_version, project_stage, project_logo, project_logo_type, project_logo_width, project_logo_height, project_start_time, project_start_id, project_start_author, project_last_update, is_active, file_only, project_downloads) + VALUES ($category_id, '$project_title', '$project_title_clean', '$project_description', {$info_array['project_level']}, {$info_array['project_install_time']}, '$project_notes', $project_license, '$project_target_version', '$project_version', $project_stage, '$project_logo', $project_logo_type, $project_logo_width, $project_logo_height, {$info_array['project_start_time']}, {$info_array['project_start_id']}, '$project_start_author', {$info_array['project_last_update']}, $is_active, $file_only, 0)"; + $db->sql_query($sql); + + $info_array['project_id'] = $project_id = $db->sql_nextid(); + + for ($i = 0, $size = sizeof($authors); $i < $size; $i++) + { + $db->sql_query('INSERT INTO ' . PROJECT_PROJECT_AUTHORS_TABLE . " (project_id, author_id, author_role) + VALUES ($project_id, {$authors[$i]['author_id']}, {$authors[$i]['author_role_id']})"); + } + + if ($history) + { + for ($i = 0, $size = sizeof($history); $i < $size; $i++) + { + $db->sql_query('INSERT INTO ' . PROJECT_VERSIONS_TABLE . " (project_id, previous_id, version_time, version_major, version_minor, version_revision, version_release, version_stage, version_changelog) + VALUES ($project_id, {$history[$i]['previous_id']}, {$history[$i]['version_time']}, {$history[$i]['version_major']}, {$history[$i]['version_minor']}, {$history[$i]['version_revision']}, '{$history[$i]['version_release']}', {$history[$i]['version_stage']}, {$history[$i]['version_changelog']})"); + } + + $version_time = $history[$i]['version_time']; + } + else + { + $db->sql_query('INSERT INTO ' . PROJECT_VERSIONS_TABLE . " (project_id, previous_id, version_time, version_major, version_minor, version_revision, version_release, version_stage, version_changelog) + VALUES ($project_id, 0, $current_time, 0, 0, 0, '', " . PROJECT_STAGE_DEV . ", '')"); + + $version_time = $current_time; + } + + $version_id = $db->sql_nextid(); + + if ($actions) + { + for ($i = 0, $size = sizeof($actions); $i < $size; $i++) + { + /** + * @todo Something tells me this could be much more efficient... + */ + $db->sql_query('INSERT INTO ' . PROJECT_ACTIONS_TABLE . " (project_id) + VALUES ($project_id)"); + + $actions[$i]['action_id'] = $action_id = $db->sql_nextid(); + + $db->sql_query('INSERT INTO ' . PROJECT_ACTION_CONTENTS_TABLE . " (action_id, version_id, version_time, action_order, action_type, action_content) + VALUES ($action_id, $version_id, $version_time, {$actions[$i]['action_order']}, {$actions[$i]['action_type']}, '{$actions[$i]['action_content']}')"); + } + } + + // Update project count for category + $sql = 'UPDATE ' . PROJECT_CATEGORIES_TABLE . " + SET category_projects = category_projects + 1, + last_update_id = $project_id, + last_update_time = {$info_array['project_last_update']} + WHERE category_id = {$info_array['category_id']}"; + $db->sql_query($sql); + + // And roll it + $db->sql_transaction('commit'); + + // Now post it if needed + if ($config['project_autopost_enable']) + { + $topic_id = project_autopost($info_array, $authors, $history); + + if (!$topic_id) + { + return $user->lang['PROJECT_AUTOPOST_FAILURE']; + } + + $sql = 'UPDATE ' . PROJECT_PROJECTS_TABLE . ' + SET topic_id = ' . (int) $topic_id . ' + WHERE project_id = ' . $project_id; + $db->sql_query($sql); + } + + return false; +} + +?> \ No newline at end of file Modified: trunk/develop/create_schema_files_phpbb3.php =================================================================== --- trunk/develop/create_schema_files_phpbb3.php 2008-04-21 23:17:05 UTC (rev 263) +++ trunk/develop/create_schema_files_phpbb3.php 2008-04-23 00:26:14 UTC (rev 264) @@ -880,8 +880,7 @@ 'project_logo_width' => array('USINT', '0'), 'project_logo_height' => array('USINT', '0'), 'project_start_time' => array('UINT:11', '0'), - 'project_start_id' => array('UINT', '0'), - 'project_start_author' => array('STEXT_UNI', ''), + 'project_owner' => array('UINT', '0'), 'project_last_update' => array('UINT:11', '0'), 'is_active' => array('BOOL', '1'), 'file_only' => array('BOOL', '0'), @@ -899,14 +898,6 @@ // // Actions and versions // - $schema_data['phpbb_project_actions'] = array( - 'COLUMNS' => array( - 'action_id' => array('UINT:11', NULL, 'auto_increment'), - 'project_id' => array('UINT', '0'), - ), - 'PRIMARY_KEY' => 'action_id', - ); - $schema_data['phpbb_project_versions'] = array( 'COLUMNS' => array( 'version_id' => array('UINT:11', NULL, 'auto_increment'), @@ -926,9 +917,10 @@ ) ); - $schema_data['phpbb_project_action_contents'] = array( + $schema_data['phpbb_project_actions'] = array( 'COLUMNS' => array( 'action_id' => array('UINT:11', '0'), + 'project_id' => array('UINT', '0'), 'version_id' => array('UINT:11', '0'), 'version_time' => array('UINT:11', '0'), 'action_order' => array('USINT', '0'), @@ -939,6 +931,7 @@ ), 'PRIMARY_KEY' => array('action_id, version_id'), 'KEYS' => array( + 'project_id' => array('INDEX', 'project_id'), 'action_order' => array('INDEX', 'action_order'), 'version_time' => array('INDEX', 'version_time'), ) Modified: trunk/phpbb3/root/includes/project/project_main.php =================================================================== --- trunk/phpbb3/root/includes/project/project_main.php 2008-04-21 23:17:05 UTC (rev 263) +++ trunk/phpbb3/root/includes/project/project_main.php 2008-04-23 00:26:14 UTC (rev 264) @@ -213,7 +213,6 @@ $sort_by_sql = array( 'lu' => 'project_last_update', - 'sa' => 'project_start_author', 'pt' => 'project_title', 'st' => 'project_start_time', 'it' => 'project_install_time', @@ -232,7 +231,7 @@ $acl_projects = array_keys($auth->acl_getf('p_view_project', true)); $project_ids = $db->sql_in_set('project_id', $acl_projects, false, true); - $sql = "SELECT project_id, topic_id, project_title, project_description, project_level, project_install_time, project_target_version, project_version, project_stage, project_start_time, project_start_id, project_start_author, project_last_update, project_downloads + $sql = "SELECT project_id, topic_id, project_title, project_description, project_level, project_install_time, project_target_version, project_version, project_stage, project_start_time, project_owner, project_last_update, project_downloads FROM " . PROJECT_PROJECTS_TABLE . " WHERE $project_ids AND category_id = $category_id @@ -279,7 +278,7 @@ 'DOWNLOADS' => $projects[$i]['project_downloads'], 'START_DATE' => $user->format_date($projects[$i]['project_start_time']), - 'START_AUTHOR' => get_username_string('full', $projects[$i]['project_start_id'], $projects[$i]['project_start_author']), + 'OWNER' => get_username_string('full', $projects[$i]['project_owner'], project_get_author_name($projects[$i]['project_owner'])), 'LAST_UPDATE' => $user->format_date($projects[$i]['project_last_update']), 'S_ROW_COUNT' => $i, Modified: trunk/phpbb3/root/includes/sources_project/constants.php =================================================================== --- trunk/phpbb3/root/includes/sources_project/constants.php 2008-04-21 23:17:05 UTC (rev 263) +++ trunk/phpbb3/root/includes/sources_project/constants.php 2008-04-23 00:26:14 UTC (rev 264) @@ -23,22 +23,27 @@ define('PROJECT_STAGE_RC', 4); define('PROJECT_STAGE_STABLE', 5); +// Status types +define('PROJECT_STATUS_UNAPPROVED', 0); +define('PROJECT_STATUS_APPROVED', 1); +define('PROJECT_STATUS_DISCONTINUED', 2); + // Action types define('PROJECT_ACTION_DELETED', 0); define('PROJECT_ACTION_SQL', 1); define('PROJECT_ACTION_COPY', 2); define('PROJECT_ACTION_DIY', 3); -//define('PROJECT_ACTION_OPEN', 4); // Deprecated ;) -define('PROJECT_ACTION_FIND', 5); -define('PROJECT_ACTION_AFTER_ADD', 6); -define('PROJECT_ACTION_BEFORE_ADD', 7); -define('PROJECT_ACTION_REPLACE_WITH', 8); -define('PROJECT_ACTION_INCREMENT', 9); -define('PROJECT_ACTION_INLINE_FIND', 10); -define('PROJECT_ACTION_INLINE_AFTER_ADD', 11); -define('PROJECT_ACTION_INLINE_BEFORE_ADD', 12); -define('PROJECT_ACTION_INLINE_REPLACE_WITH', 13); -define('PROJECT_ACTION_INLINE_INCREMENT', 14); +define('PROJECT_ACTION_FIND', 4); +define('PROJECT_ACTION_AFTER_ADD', 5); +define('PROJECT_ACTION_BEFORE_ADD', 6); +define('PROJECT_ACTION_REPLACE_WITH', 7); +define('PROJECT_ACTION_INCREMENT', 8); +define('PROJECT_ACTION_INLINE_FIND', 9); +define('PROJECT_ACTION_INLINE_AFTER_ADD', 10); +define('PROJECT_ACTION_INLINE_BEFORE_ADD', 11); +define('PROJECT_ACTION_INLINE_REPLACE_WITH', 12); +define('PROJECT_ACTION_INLINE_INCREMENT', 13); +//define('PROJECT_ACTION_OPEN', 14); // Not used (anymore / yet?) // Search match types define('PROJECT_MATCH_TITLE', 1); @@ -66,7 +71,6 @@ // Tables define('PROJECT_ACTIONS_TABLE', $table_prefix . 'project_actions'); -define('PROJECT_ACTION_CONTENTS_TABLE', $table_prefix . 'project_action_contents'); define('PROJECT_AUTHORS_TABLE', $table_prefix . 'project_authors'); define('PROJECT_CATEGORIES_TABLE', $table_prefix . 'project_categories'); define('PROJECT_DOCUMENTATION_TABLE', $table_prefix . 'project_documentation'); Modified: trunk/phpbb3/root/includes/sources_project/create_project.php =================================================================== --- trunk/phpbb3/root/includes/sources_project/create_project.php 2008-04-21 23:17:05 UTC (rev 263) +++ trunk/phpbb3/root/includes/sources_project/create_project.php 2008-04-23 00:26:14 UTC (rev 264) @@ -9,478 +9,258 @@ */ /** - * Create a new project + * Create Project base class * - * @param string $mode - * @param array $info_array - * @param array $authors - * @param array|boolean $history - * @param array|boolean $actions - * @param array|boolean $old_actions - * @return boolean|string Either false if succesful of the error message + * @package create_project */ -function project_create($mode, $info_array, $authors, $history = false, $actions = false, $old_actions = false) +class project_create { - global $db, $config, $auth, $user; + public $current_time; + public $error; + protected $data; + protected $authors; - // Check permissions - if (!$auth->acl_get('p_add_project')) + /** + * Create project constructor + * + * @param array $data + * @param array $authors + */ + public function __construct($data, $authors) { - return $user->lang['PROJECT_NOT_AUTH_CREATE']; - } - if (!$auth->acl_get('p_view_category', $info_array['category_id'])) - { - return $user->lang['PROJECT_NOT_AUTH_CAT']; - } + global $auth, $user, $config; - // Time & date of project creation - $current_time = time(); - - // History and action information are only needed for importing - if ($mode != 'import') - { - $history = $actions = $old_actions = false; - } - - // Variable types for database protection - $info_vars = array('category_id' => 'int', 'project_title' => 'string', 'project_description' => 'string', 'project_notes' => 'string', 'project_license' => 'int', 'project_target_version' => 'string', 'project_version' => 'string', 'project_stage' => 'int', 'project_logo' => 'string', 'project_logo_type' => 'int', 'project_logo_width' => 'int', 'project_logo_height' => 'int', 'is_active' => 'int', 'file_only' => 'int'); - - $error_message = ''; - foreach ($info_vars AS $var => $type) - { - if (!isset($info_array[$var])) + // Check permissions + if (!$auth->acl_get('p_add_project')) { - $error_message .= (($error_message) ? '<br />' : '') . sprintf($user->lang['FIELD_REQUIRED'], $var); + $this->error = $user->lang['PROJECT_NOT_AUTH_CREATE']; + return; } + if (!$auth->acl_get('p_view_category', $data['category_id'])) + { + $this->error = $user->lang['PROJECT_NOT_AUTH_CAT']; + return; + } - $$var = ($type == 'string') ? $db->sql_escape($info_array[$var]) : intval($info_array[$var]); + // Time & date of project creation + $this->current_time = time(); + $this->authors = $authors; + + $this->set_data($data); } - if (!empty($error_message)) - { - return $error_message; - } - // Clean title for uniqueness - $info_array['project_title_clean'] = utf8_clean_string($info_array['project_title']); - $project_title_clean = $db->sql_escape($info_array['project_title_clean']); - - $info_array['project_install_time'] = ($actions) ? project_generate_install_time($actions) : 0; - $info_array['project_level'] = ($actions) ? project_generate_level('actions', $actions) : PROJECT_LEVEL_EASY; - - $info_array['project_start_time'] = (empty($info_array['project_start_time'])) ? $current_time : intval($info_array['project_start_time']); - $info_array['project_start_id'] = (empty($info_array['project_start_id'])) ? $user->data['user_id'] : intval($info_array['project_start_id']); - $info_array['project_start_author'] = (empty($info_array['project_start_author'])) ? project_get_author_name($user->data['user_id']) : $info_array['project_start_author']; - - $project_start_author = $db->sql_escape($info_array['project_start_author']); - - $info_array['project_last_update'] = $current_time; - /** - * @todo $authors, $history, $actions, $old_actions... Also, add some setting for permissions + * Set data array + * + * @param array $data */ - - // All set to go into the database :-) - $db->sql_transaction('begin'); - - $sql = 'INSERT INTO ' . PROJECT_PROJECTS_TABLE . " (category_id, project_title, project_title_clean, project_description, project_level, project_install_time, project_notes, project_license, project_target_version, project_version, project_stage, project_logo, project_logo_type, project_logo_width, project_logo_height, project_start_time, project_start_id, project_start_author, project_last_update, is_active, file_only, project_downloads) - VALUES ($category_id, '$project_title', '$project_title_clean', '$project_description', {$info_array['project_level']}, {$info_array['project_install_time']}, '$project_notes', $project_license, '$project_target_version', '$project_version', $project_stage, '$project_logo', $project_logo_type, $project_logo_width, $project_logo_height, {$info_array['project_start_time']}, {$info_array['project_start_id']}, '$project_start_author', {$info_array['project_last_update']}, $is_active, $file_only, 0)"; - $db->sql_query($sql); - - $info_array['project_id'] = $project_id = $db->sql_nextid(); - - for ($i = 0, $size = sizeof($authors); $i < $size; $i++) + protected function set_data($data) { - $db->sql_query('INSERT INTO ' . PROJECT_PROJECT_AUTHORS_TABLE . " (project_id, author_id, author_role) - VALUES ($project_id, {$authors[$i]['author_id']}, {$authors[$i]['author_role_id']})"); + global $config, $user; + + $this->data = array_merge($data, array( + 'project_clean_title' => utf8_clean_string($data['project_title']), + 'project_install_time' => 0, + 'project_level' => PROJECT_LEVEL_EASY, + 'project_stage' => PROJECT_STAGE_DEV, + 'project_version' => '0.0.0', + 'project_start_time' => $this->current_time, + 'project_last_update' => $this->current_time, + 'project_owner' => $user->data['user_id'], + 'project_status' => ($config['project_approve_creation']) ? PROJECT_STATUS_UNAPPROVED : PROJECT_STATUS_APPROVED, + 'project_downloads' => 0, + )); } - if ($history) + /** + * Process project creation + * + * @return integer Project ID + */ + public function process() { - for ($i = 0, $size = sizeof($history); $i < $size; $i++) - { - $db->sql_query('INSERT INTO ' . PROJECT_VERSIONS_TABLE . " (project_id, previous_id, version_time, version_major, version_minor, version_revision, version_release, version_stage, version_changelog) - VALUES ($project_id, {$history[$i]['previous_id']}, {$history[$i]['version_time']}, {$history[$i]['version_major']}, {$history[$i]['version_minor']}, {$history[$i]['version_revision']}, '{$history[$i]['version_release']}', {$history[$i]['version_stage']}, {$history[$i]['version_changelog']})"); - } + global $db, $config; - $version_time = $history[$i]['version_time']; - } - else - { - $db->sql_query('INSERT INTO ' . PROJECT_VERSIONS_TABLE . " (project_id, previous_id, version_time, version_major, version_minor, version_revision, version_release, version_stage, version_changelog) - VALUES ($project_id, 0, $current_time, 0, 0, 0, '', " . PROJECT_STAGE_DEV . ", '')"); + $db->sql_transaction('begin'); - $version_time = $current_time; - } + // Insert main project data + $db->sql_query('INSERT INTO ' . PROJECT_PROJECTS_TABLE . $db->sql_build_array('INSERT', $this->data)); - $version_id = $db->sql_nextid(); + $this->data['project_id'] = $project_id = $db->sql_nextid(); - if ($actions) - { - for ($i = 0, $size = sizeof($actions); $i < $size; $i++) + // Add all authors + for ($i = 0, $size = sizeof($authors); $i < $size; $i++) { - /** - * @todo Something tells me this could be much more efficient... - */ - $db->sql_query('INSERT INTO ' . PROJECT_ACTIONS_TABLE . " (project_id) - VALUES ($project_id)"); - - $actions[$i]['action_id'] = $action_id = $db->sql_nextid(); - - $db->sql_query('INSERT INTO ' . PROJECT_ACTION_CONTENTS_TABLE . " (action_id, version_id, version_time, action_order, action_type, action_content) - VALUES ($action_id, $version_id, $version_time, {$actions[$i]['action_order']}, {$actions[$i]['action_type']}, '{$actions[$i]['action_content']}')"); + $db->sql_query('INSERT INTO ' . PROJECT_PROJECT_AUTHORS_TABLE . $db->sql_build_array('INSERT', array( + 'project_id' => $project_id, + 'author_id' => $authors[$i]['author_id'], + 'author_role' => $authors[$i]['author_role_id'] + ))); } - } - // Update project count for category - $sql = 'UPDATE ' . PROJECT_CATEGORIES_TABLE . " - SET category_projects = category_projects + 1, - last_update_id = $project_id, - last_update_time = {$info_array['project_last_update']} - WHERE category_id = {$info_array['category_id']}"; - $db->sql_query($sql); + // Add the version entry + $db->sql_query('INSERT INTO ' . PROJECT_VERSIONS_TABLE . $db->sql_build_array('INSERT', array( + 'project_id' => $project_id, + 'previous_id' => 0, + 'version_time' => $this->current_time, + 'version_major' => 0, + 'version_minor' => 0, + 'version_revision' => 0, + 'version_release' => '', + 'version_stage' => PROJECT_STAGE_DEV, + 'version_changelog' => '', + ))); - // And roll it - $db->sql_transaction('commit'); + // Update project count for category + $sql = 'UPDATE ' . PROJECT_CATEGORIES_TABLE . " + SET category_projects = category_projects + 1, + last_update_id = $project_id, + last_update_time = $this->current_time + WHERE category_id = {$this->data['category_id']}"; + $db->sql_query($sql); - // Now post it if needed - if ($config['project_autopost_enable']) - { - $topic_id = project_autopost($info_array, $authors, $history); + // And roll it + $db->sql_transaction('commit'); - if (!$topic_id) + // Now post it if needed + if ($config['project_autopost_enable'] && !$config['project_approve_creation']) { - return $user->lang['PROJECT_AUTOPOST_FAILURE']; + project_autopost($this->data, $this->authors); } - $sql = 'UPDATE ' . PROJECT_PROJECTS_TABLE . ' - SET topic_id = ' . (int) $topic_id . ' - WHERE project_id = ' . $project_id; - $db->sql_query($sql); + return $project_id; } - - return false; } /** - * Handle autoposting + * Create project from import * - * @param array $info_array - * @param array $authors - * @param boolean|array $history - * @param boolean|array $update - * @return integer|boolean Either post_id or topic_id, depending on $update, or false on failure + * @package create_project */ -function project_autopost($info_array, $authors, $history = false, $update = false) +class project_create_import extends project_create { - global $db, $config, $user, $auth; - global $phpbb_root_path, $phpEx; + protected $history = array(); + protected $actions = array(); - include_once("{$phpbb_root_path}includes/functions_posting.$phpEx"); - include_once("{$phpbb_root_path}includes/message_parser.$phpEx"); + /** + * Class constructor + * + * @param array $data + * @param array $authors + * @param array $history + * @param array $actions + */ + public function __construct($data, $authors, $history, $actions) + { + $this->history = $history; + $this->actions = $actions; - $forum_root_path = generate_board_url(); + parent::__construct($data, $authors); + } - $stages_ary = array( - PROJECT_STAGE_ALPHA => $user->lang['PROJECT_STAGE_ALPHA'], - PROJECT_STAGE_BETA => $user->lang['PROJECT_STAGE_BETA'], - PROJECT_STAGE_DEV => $user->lang['PROJECT_STAGE_DEV'], - PROJECT_STAGE_RC => $user->lang['PROJECT_STAGE_RC'], - PROJECT_STAGE_STABLE => $user->lang['PROJECT_STAGE_STABLE'], - ); + /** + * Set data array + * + * @param array $data + */ + protected function set_data($data) + { + global $config, $user; - $post_tpl = new template(); - $post_tpl->set_custom_template("{$phpbb_root_path}store/phpbbproject/autopost", 'project_autopost'); + $this->data = array_merge($data, array( + 'project_clean_title' => utf8_clean_string($data['project_title']), + 'project_install_time' => project_generate_install_time($this->actions), + 'project_level' => project_generate_level('actions', $this->actions), + 'project_last_update' => $this->current_time, + 'project_owner' => $user->data['user_id'], + 'project_status' => ($config['project_approve_creation']) ? PROJECT_STATUS_UNAPPROVED : PROJECT_STATUS_APPROVED, + )); + } - if ($update) + /** + * Process project creation + * + * @return integer Project ID + */ + public function process() { - // Reply to topic $info_array['topic_id'] - $topic_id = $info_array['topic_id']; + global $db, $config; - if (!$topic_id) - { - return false; - } + $db->sql_transaction('begin'); - $post_tpl->set_filenames(array( - 'first_post_body' => 'topic_layout.html', - 'first_post_title' => 'topic_title.html', - 'update_post_body' => 'update_post_layout.html', - 'update_post_title' => 'update_post_title.html', - )); + // Insert main project data + $db->sql_query('INSERT INTO ' . PROJECT_PROJECTS_TABLE . $db->sql_build_array('INSERT', $this->data)); - if ($history) - { - for ($i = 0, $size = sizeof($history); $i < $size; $i++) - { - $post_tpl->assign_block_vars('history', array( - 'DATE' => date('Y-m-d', $history[$i]['version_time']), - 'VERSION' => "{$history[$i]['version_major']}.{$history[$i]['version_minor']}.{$history[$i]['version_revision']}{$history[$i]['version_release']}", - 'CHANGELOG' => $history[$i]['version_changelog'], + $this->data['project_id'] = $project_id = $db->sql_nextid(); - 'U_UPDATE_POST' => ($history[$i]['version_post_id']) ? "{$forum_root_path}viewtopic.$phpEx?t=$topic_id&p={$history[$i]['version_post_id']}#{$history[$i]['version_post_id']}" : '', - 'U_DIFF' => ($history[$i]['version_id'] && $history[$i]['previous_version_id']) ? "{$forum_root_path}project.$phpEx?i=project&mode=diff&pr={$info_array['project_id']}&dm=normal&nv={$history[$i]['version_id']}&ov={$history[$i]['previous_version_id']}" : '', - )); - } - } - + // Add all authors for ($i = 0, $size = sizeof($authors); $i < $size; $i++) { - $post_tpl->assign_block_vars('author', array( - 'USERNAME' => $authors[$i]['author_username'], - 'REAL_NAME' => $authors[$i]['author_realname'], - 'EMAIL' => $authors[$i]['author_email'], - 'WEBSITE' => $authors[$i]['author_website'], - 'ROLE' => $authors[$i]['author_role_title'], - - 'S_STARTER' => ($authors[$i]['author_id'] == $info_array['project_start_id']) ? true : false, - - 'U_AUTHOR' => "{$forum_root_path}project.$phpEx?i=author&mode=view&u={$authors[$i]['author_id']}", - )); + $db->sql_query('INSERT INTO ' . PROJECT_PROJECT_AUTHORS_TABLE . $db->sql_build_array('INSERT', array( + 'project_id' => $project_id, + 'author_id' => $authors[$i]['author_id'], + 'author_role' => $authors[$i]['author_role_id'] + ))); } - $post_tpl->assign_vars(array( - 'PROJECT_TITLE' => $info_array['project_title'], - 'PROJECT_TITLE_CLEAN' => $info_array['project_title_clean'], - 'PROJECT_DESCRIPTION' => $info_array['project_description'], - 'AUTHOR_NOTES' => $info_array['project_notes'], + $version_id = $action_id = array(); - 'DATE' => $info_array['project_last_update'], - 'VERSION' => $info_array['project_version'], - 'TARGET_VERSION' => $info_array['project_target_version'], + // Insert version history + for ($i = 0, $size = sizeof($this->history); $i < $size; $i++) + { + $old_version = $this->history[$i]['version_id']; + unset($this->history[$i]['version_id']); - 'DEV_STAGE_ID' => $info_array['project_stage'], - 'DEV_STAGE_UC' => strtoupper($stages_ary[$info_array['project_stage']]), - 'DEV_STAGE_LC' => strtolower($stages_ary[$info_array['project_stage']]), - 'DEV_STAGE_NC' => $stages_ary[$info_array['project_stage']], + $db->sql_query('INSERT INTO ' . PROJECT_VERSIONS_TABLE . + $db->sql_build_array('INSERT', array_merge($this->history[$i], array( + 'project_id' => $project_id + ))) + ); - 'U_DOWNLOAD' => "{$forum_root_path}project.$phpEx?i=project&mode=download&pr={$info_array['project_id']}", - 'U_PROJECT_INFO' => "{$forum_root_path}project.$phpEx?i=project&mode=view&pr={$info_array['project_id']}", + $version_id[$old_version] = $db->sql_nextid(); + } - // Update post extra vars - 'CHANGELOG' => $update['changelog'], + // Get highest action_id for increment + $sql = 'SELECT MAX(action_id) AS max_action_id + FROM ' . PROJECT_ACTIONS_TABLE; + $result = $db->sql_query($sql); + $max_action_id = $db->sql_fetchfield('max_action_id', false, $result); + $db->sql_freeresult($result); - 'U_DIFF' => "{$forum_root_path}project.$phpEx?i=project&mode=diff&pr={$info_array['project_id']}&dm=normal&nv={$update['version_id']}&ov={$update['previous_version_id']}", - 'U_TOPIC' => "{$forum_root_path}viewtopic.$phpEx?t=$topic_id", - - 'OLD_TARGET_VERSION' => $update['previous_target_version'], - 'OLD_VERSION' => $update['previous_version'], - 'OLD_DEV_STAGE_ID' => $update['previous_dev_stage'], - )); - - ob_start(); - $post_tpl->display('first_post_body'); - $first_post_contents = ob_get_contents(); - ob_clean(); - $post_tpl->display('first_post_title'); - $first_post_title = ob_get_contents(); - ob_clean(); - $post_tpl->display('update_post_body'); - $update_post_contents = ob_get_contents(); - ob_clean(); - $post_tpl->display('update_post_title'); - $update_post_title = ob_get_clean(); - } - else - { - $post_tpl->set_filenames(array( - 'post_body' => 'topic_layout.html', - 'post_title' => 'topic_title.html', - )); - - if ($history) + // Insert actions + for ($i = 0, $size = sizeof($this->actions); $i < $size; $i++) { - for ($i = 0, $size = sizeof($history); $i < $size; $i++) + $old_action = $this->actions[$i]['action_id']; + if (!isset($action_id[$old_action])) { - $post_tpl->assign_block_vars('history', array( - 'DATE' => date('Y-m-d', $history[$i]['version_time']), - 'VERSION' => "{$history[$i]['version_major']}.{$history[$i]['version_minor']}.{$history[$i]['version_revision']}{$history[$i]['version_release']}", - 'CHANGELOG' => $history[$i]['version_changelog'], - - 'U_UPDATE_POST' => '', - 'U_DIFF' => '', - )); + $max_action_id++; + $action_id[$old_action] = $max_action_id; } - } + $this->actions[$i]['action_id'] = $action_id[$old_action]; + $this->actions[$i]['project_id'] = $project_id; - for ($i = 0, $size = sizeof($authors); $i < $size; $i++) - { - $post_tpl->assign_block_vars('author', array( - 'USERNAME' => $authors[$i]['author_username'], - 'REAL_NAME' => $authors[$i]['author_realname'], - 'EMAIL' => $authors[$i]['author_email'], - 'WEBSITE' => $authors[$i]['author_website'], - 'ROLE' => $authors[$i]['author_role_title'], - - 'S_STARTER' => ($authors[$i]['author_id'] == $info_array['project_start_id']) ? true : false, - 'U_AUTHOR' => "{$forum_root_path}project.$phpEx?i=author&mode=view&u={$authors[$i]['author_id']}", - )); + $db->sql_query('INSERT INTO ' . PROJECT_ACTIONS_TABLE . $db->sql_build_array('INSERT', $this->actions[$i])); } - $post_tpl->assign_vars(array( - 'PROJECT_TITLE' => $info_array['project_title'], - 'PROJECT_TITLE_CLEAN' => $info_array['project_title_clean'], - 'PROJECT_DESCRIPTION' => $info_array['project_description'], - 'AUTHOR_NOTES' => $info_array['project_notes'], - - 'DATE' => $info_array['project_last_update'], - 'VERSION' => $info_array['project_version'], - 'TARGET_VERSION' => $info_array['project_target_version'], - - 'DEV_STAGE_ID' => $info_array['project_stage'], - 'DEV_STAGE_UC' => strtoupper($stages_ary[$info_array['project_stage']]), - 'DEV_STAGE_LC' => strtolower($stages_ary[$info_array['project_stage']]), - 'DEV_STAGE_NC' => $stages_ary[$info_array['project_stage']], - - 'U_DOWNLOAD' => "{$forum_root_path}project.$phpEx?i=project&mode=download&pr={$info_array['project_id']}", - 'U_PROJECT_INFO' => "{$forum_root_path}project.$phpEx?i=project&mode=view&pr={$info_array['project_id']}", - )); - - ob_start(); - $post_tpl->display('post_body'); - $first_post_contents = ob_get_contents(); - ob_clean(); - $post_tpl->display('post_title'); - $first_post_title = ob_get_clean(); - } - - // Get forum ID - if ($config['project_autopost_forum_per_category']) - { - $sql = 'SELECT c.forum_id, f.forum_name - FROM ' . PROJECT_CATEGORIES_TABLE . ' c, ' . FORUMS_TABLE . ' f - WHERE c.category_id = ' . (int) $info_array['category_id'] . ' - AND f.forum_id = c.forum_id'; - - $db->sql_query($sql, 604800); - $forum_data = $db->sql_fetchrow(); - $db->sql_freeresult(); - } - else - { - $sql = 'SELECT forum_id, forum_name - FROM ' . FORUMS_TABLE . ' - WHERE forum_id = ' . (int) $config['project_autopost_forum_id']; - - $db->sql_query($sql, 604800); - $forum_data = $db->sql_fetchrow(); - $db->sql_freeresult(); - } - - $forum_id = $forum_data['forum_id']; - $forum_name = $forum_data['forum_name']; - - // submit_post() needs $user to be the info of the posting user, this is not the case here, so make a workaround - $this_user = $user; - - $user->data['is_registered'] = false; - $user->data['user_id'] = $config['project_autopost_user_id']; - - $sql = 'SELECT username, user_colour - FROM ' . USERS_TABLE . ' - WHERE user_id = ' . (int) $user->data['user_id']; - - $db->sql_query($sql, 604800); - $userdata = $db->sql_fetchrow(); - $db->sql_freeresult(); - - $user->data['username'] = $userdata['username']; - $user->data['user_colour'] = $userdata['user_colour']; - $user->data['user_permissions'] = ''; - $user->ip = '127.0.0.1'; - $auth->acl($user->data); - - $message_parser = new parse_message($first_post_contents); - - if ($update) - { - $update_message_parser = new parse_message($update_post_contents); - $update_message_parser->parse(1, 1, 1); - - $sql = 'SELECT t.topic_replies_real, p.post_id, p.bbcode_uid, p.post_time - FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p - WHERE t.topic_id = $topic_id - AND p.post_id = t.topic_first_post_id"; - + // Update project count for category + $sql = 'UPDATE ' . PROJECT_CATEGORIES_TABLE . " + SET category_projects = category_projects + 1, + last_update_id = $project_id, + last_update_time = $this->current_time + WHERE category_id = {$this->data['category_id']}"; $db->sql_query($sql); - $post_data = $db->sql_fetchrow(); - $db->sql_freeresult(); - $message_parser->bbcode_uid = $post_data['bbcode_uid']; - } + // And roll it + $db->sql_transaction('commit'); - $message_parser->parse(1, 1, 1); + // Now post it if needed + if ($config['project_autopost_enable'] && !$config['project_approve_creation']) + { + project_autopost($this->data, $this->authors, $this->history); + } - - // Build data array - $data = array( - 'topic_title' => $first_post_title, - 'post_subject' => $first_post_title, - 'forum_id' => $forum_id, - 'forum_name' => $forum_name, - 'icon_id' => 0, - - 'enable_bbcode' => 1, - 'enable_smilies' => 1, - 'enable_urls' => 1, - 'enable_sig' => 0, - 'enable_indexing' => 1, - - 'message' => $message_parser->message, - 'message_md5' => md5($message_parser->message), - - 'bbcode_bitfield' => $message_parser->bbcode_bitfield, - 'bbcode_uid' => $message_parser->bbcode_uid, - - 'attachment_data' => array(), - - 'post_edit_locked' => false, - 'post_time' => (isset($post_data['post_time'])) ? (int) $post_data['post_time'] : time(), - - ); - - $poll = array(); - - if ($update) - { - $data = array_merge($data, array('topic_id' => $topic_id, 'topic_first_post_id' => $post_data['post_id'], 'post_id' => $post_data['post_id'], 'topic_replies_real' => $post_data['topic_replies_real'], 'poster_id' => $user->data['user_id'], 'topic_approved' => true, 'post_approved' => true)); - submit_post('edit', $first_post_title, '', POST_NORMAL, $poll, $data); - - $update_data = array( - 'topic_id' => $topic_id, - 'post_subject' => $update_post_title, - 'forum_id' => $forum_id, - 'forum_name' => $forum_name, - 'icon_id' => 0, - - 'enable_bbcode' => 1, - 'enable_smilies' => 1, - 'enable_urls' => 1, - 'enable_sig' => 0, - 'enable_indexing' => 1, - - 'message' => $update_message_parser->message, - 'message_md5' => md5($update_message_parser->message), - - 'bbcode_bitfield' => $update_message_parser->bbcode_bitfield, - 'bbcode_uid' => $update_message_parser->bbcode_uid, - - 'attachment_data' => array(), - - 'post_edit_locked' => false, - 'post_time' => time(), - ); - - submit_post('reply', $update_post_title, '', POST_NORMAL, $poll, $update_data); + return $project_id; } - else - { - submit_post('post', $first_post_title, '', POST_NORMAL, $poll, $data); - } - - $user = $this_user; - $auth->acl($user->data); - - return ($update) ? $update_data['post_id'] : $data['topic_id']; } ?> \ No newline at end of file Modified: trunk/phpbb3/root/includes/sources_project/download_project.php =================================================================== --- trunk/phpbb3/root/includes/sources_project/download_project.php 2008-04-21 23:17:05 UTC (rev 263) +++ trunk/phpbb3/root/includes/sources_project/download_project.php 2008-04-23 00:26:14 UTC (rev 264) @@ -20,11 +20,11 @@ public $project_id; public $version_id; public $archive_type = 'zip'; - private $version_time; - private $download_type = PROJECT_DOWNLOAD_NORMAL; - private $version_newest = false; - private $version_oldest = false; - private $package; + protected $version_time; + protected $download_type = PROJECT_DOWNLOAD_NORMAL; + protected $version_newest = false; + protected $version_oldest = false; + protected $package; // parser properties public $open_files = array(); @@ -138,7 +138,7 @@ /** * Get information */ - private function get_info() + protected function get_info() { global $db; @@ -167,7 +167,7 @@ * * @todo Order by role + other sorting methods... */ - private function get_authors() + protected function get_authors() { global $db; @@ -204,7 +204,7 @@ /** * Get history information */ - private function get_history() + protected function get_history() { global $db; @@ -240,7 +240,7 @@ /** * Get actions from database */ - private function get_actions() + protected function get_actions() { global $db; @@ -257,6 +257,9 @@ PROJECT_ACTION_REPLACE_WITH => 'replace with', ); + /** + * @todo Change these queries to work on new SQL schema + */ $sql = 'SELECT action_id FROM ' . PROJECT_ACTIONS_TABLE . " WHERE project_id = $this->project_id @@ -348,7 +351,7 @@ * * @todo see if there is a way to get it out of the while loop... */ - private function generate_files($dirname = false, $relative_dir = 'root') + protected function generate_files($dirname = false, $relative_dir = 'root') { global $phpbb_root_path; if ($dirname === false) Added: trunk/phpbb3/root/includes/sources_project/import_project.php =================================================================== --- trunk/phpbb3/root/includes/sources_project/import_project.php (rev 0) +++ trunk/phpbb3/root/includes/sources_project/import_project.php 2008-04-23 00:26:14 UTC (rev 264) @@ -0,0 +1,25 @@ +<?php +/** + * phpBB Project + * + * @package phpbbproject + * @version $Id$ + * @copyright (c) 2008 phpBB Project Team + * @license http://opensource.org/licenses/gpl-license.php GNU Public License + */ + +/** + * Import Project from SVN Repository + * + * This class will import a project from a Subversion repository. + * It should be able to reconstruct previous versions if there are tags defined in the repository. + * By default it will look for the /trunk and assume it is set up as if it were a mod. + * + * @package create_project + */ +class project_import_svn +{ + +} + +?> \ No newline at end of file Property changes on: trunk/phpbb3/root/includes/sources_project/import_project.php ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Modified: trunk/phpbb3/root/styles/prosilver/template/project_viewcat.html =================================================================== --- trunk/phpbb3/root/styles/prosilver/template/project_viewcat.html 2008-04-21 23:17:05 UTC (rev 263) +++ trunk/phpbb3/root/styles/prosilver/template/project_viewcat.html 2008-04-23 00:26:14 UTC (rev 264) @@ -33,7 +33,7 @@ <!-- IF project_row.U_VIEW_TOPIC --><br /><a href="{project_row.U_VIEW_TOPIC}">{L_VIEW_TOPIC}</a><!-- ENDIF --> </dt> <dd class="posts">{project_row.DOWNLOADS}</dd> - <dd style="width: 17%; font-size: 1.1em;"><span style="display: block; padding-<!-- IF S_CONTENT_DIRECTION eq 'rtl' -->right<!-- ELSE -->left<!-- ENDIF -->: 5px;">{L_POST_BY_AUTHOR} {project_row.START_AUTHOR} {L_POSTED_ON_DATE} {project_row.START_DATE}</span></dd> + <dd style="width: 17%; font-size: 1.1em;"><span style="display: block; padding-<!-- IF S_CONTENT_DIRECTION eq 'rtl' -->right<!-- ELSE -->left<!-- ENDIF -->: 5px;">{L_POST_BY_AUTHOR} {project_row.OWNER} {L_POSTED_ON_DATE} {project_row.START_DATE}</span></dd> <dd style="width: 17%; font-size: 1.1em; height: 28px;"><span style="display: block; padding-<!-- IF S_CONTENT_DIRECTION eq 'rtl' -->right<!-- ELSE -->left<!-- ENDIF -->: 5px;">{project_row.LAST_UPDATE}</span></dd> </dl> </li> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |