当前位置: 首页>>代码示例>>PHP>>正文


PHP Comment::insert方法代码示例

本文整理汇总了PHP中Comment::insert方法的典型用法代码示例。如果您正苦于以下问题:PHP Comment::insert方法的具体用法?PHP Comment::insert怎么用?PHP Comment::insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Comment的用法示例。


在下文中一共展示了Comment::insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: addComment

 /**
  * An easy way to save a comment against an object
  * @param <DbObject> $object
  * @param <String> $message
  */
 public function addComment($object, $message)
 {
     $comment = new Comment($this->w);
     $comment->obj_table = $object->getDbTableName();
     $comment->obj_id = $object->id;
     $comment->comment = strip_tags($message);
     $comment->insert();
 }
开发者ID:itillawarra,项目名称:cmfive,代码行数:13,代码来源:CommentService.php

示例2: insert

 function insert($force_validation = false)
 {
     parent::insert();
     $this->w->ctx('comment_id', $this->id);
     if (!$this->is_system) {
         //$notifier = new TaskNotifier($this->w);
         //$notifier->notify(null,'comment');
     }
 }
开发者ID:itillawarra,项目名称:cmfive,代码行数:9,代码来源:TaskComment.php

示例3: testGetPasteDeleteComment

 /**
  * Tests the getPaste's 'delete-comment' action
  */
 public function testGetPasteDeleteComment()
 {
     $this->initTestStep();
     $paste = Paste::createNew('web', array('title' => 'UnitTest::Title', 'data' => 'UnitTest::Data', 'language' => 'text'));
     Comment::insert(array('paste_id' => $paste->id, 'data' => 'UnitTest::Comment', 'timestamp' => time()));
     $comment = Comment::where('paste_id', $paste->id)->first();
     $this->call('GET', "{$paste->urlkey}/{$paste->hash}/delete/{$comment->id}");
     $this->assertRedirectedTo('/');
     $this->assertEquals(Comment::where('id', $comment->id)->count(), 0);
 }
开发者ID:carriercomm,项目名称:sticky-notes,代码行数:13,代码来源:ShowTest.php

示例4: ajaxSaveComment_POST

function ajaxSaveComment_POST(Web $w)
{
    $p = $w->pathMatch('parent_id');
    $comment = new Comment($w);
    $comment->obj_table = "comment";
    $comment->obj_id = $p['parent_id'];
    $comment->comment = strip_tags($w->request('comment'));
    $comment->insert();
    $w->setLayout(null);
    echo $w->partial("displaycomment", array("object" => $comment, 'redirect' => $w->request('redirect')), "admin");
}
开发者ID:itillawarra,项目名称:cmfive,代码行数:11,代码来源:ajaxSaveComment.php

示例5: run

 public function run()
 {
     // Initialize empty array
     $comments = array();
     // Blog Post 1 comments
     $date = new DateTime();
     $comments[] = array('user_id' => 1, 'post_id' => 1, 'content' => file_get_contents(__DIR__ . '/comment1-content.txt'), 'created_at' => $date->modify('-9 day +1 hour'), 'updated_at' => $date->modify('-9 day +1 hour'));
     $date = new DateTime();
     $comments[] = array('user_id' => 2, 'post_id' => 1, 'content' => file_get_contents(__DIR__ . '/comment2-content.txt'), 'created_at' => $date->modify('-7 day +2 hour'), 'updated_at' => $date->modify('-7 day +2 hour'));
     $date = new DateTime();
     $comments[] = array('user_id' => 1, 'post_id' => 1, 'content' => file_get_contents(__DIR__ . '/comment3-content.txt'), 'created_at' => $date->modify('-2 day +3 hour'), 'updated_at' => $date->modify('-2 day +3 hour'));
     // Blog Post 2 comments
     $date = new DateTime();
     $comments[] = array('user_id' => 1, 'post_id' => 2, 'content' => file_get_contents(__DIR__ . '/comment1-content.txt'), 'created_at' => $date->modify('-2 day +1 hour'), 'updated_at' => $date->modify('-2 day +1 hour'));
     $date = new DateTime();
     $comments[] = array('user_id' => 2, 'post_id' => 2, 'content' => file_get_contents(__DIR__ . '/comment2-content.txt'), 'created_at' => $date->modify('-1 day +2 hour'), 'updated_at' => $date->modify('-1 day +2 hour'));
     // Blog Post 3 comments
     $date = new DateTime();
     $comments[] = array('user_id' => 1, 'post_id' => 3, 'content' => file_get_contents(__DIR__ . '/comment1-content.txt'), 'created_at' => $date->modify('-1 day +1 hour'), 'updated_at' => $date->modify('-1 day +1 hour'));
     // Delete all the posts comments
     DB::table('comments')->truncate();
     // Insert the posts comments
     Comment::insert($comments);
 }
开发者ID:forestallers,项目名称:laravel-starter-kit,代码行数:24,代码来源:CommentsSeeder.php

示例6: taskEditSubmit

/**
* Submit changes to a task
*
* @ingroup pages
*/
function taskEditSubmit()
{
    global $PH;
    global $auth;
    require_once confGet('DIR_STREBER') . 'db/class_taskperson.inc.php';
    /**
     * keep a list of items linking to this task, task is new
     * we have to change the linking id after(!) inserting the task
     */
    $link_items = array();
    ### temporary object or from database? ###
    $tsk_id = getOnePassedId('tsk', '', true, 'invalid id');
    if ($tsk_id == 0) {
        $task = new Task(array('id' => 0, 'project' => get('task_project')));
        $was_category = 0;
        # undefined category for new tasks
        $was_resolved_version = 0;
    } else {
        if (!($task = Task::getVisiblebyId($tsk_id))) {
            $PH->abortWarning("invalid task-id");
        }
        $was_category = $task->category;
        $was_resolved_version = $task->resolved_version;
        $task->validateEditRequestTime();
    }
    ### cancel? ###
    if (get('form_do_cancel')) {
        if (!$PH->showFromPage()) {
            $PH->show('taskView', array('tsk' => $task->id));
        }
        exit;
    }
    ### Validate integrety ###
    if (!validateFormCrc()) {
        $PH->abortWarning(__('Invalid checksum for hidden form elements'));
    }
    validateFormCaptcha(true);
    $was_a_folder = $task->category == TCATEGORY_FOLDER ? true : false;
    $was_released_as = $task->is_released;
    ### get project ###
    if (!($project = Project::getVisiblebyId($task->project))) {
        $PH->abortWarning("task without project?");
    }
    /**
     * adding comment (from quick edit) does only require view right...
     */
    $added_comment = false;
    ### check for request feedback
    if ($request_feedback = get('request_feedback')) {
        $team_members_by_nickname = array();
        foreach ($project->getProjectPeople() as $pp) {
            $team_members_by_nickname[$pp->getPerson()->nickname] = $pp->getPerson();
        }
        $requested_people = array();
        foreach (explode('\\s*,\\s*', $request_feedback) as $nickname) {
            ### now check if this nickname is a team member
            if ($nickname = trim($nickname)) {
                if (isset($team_members_by_nickname[$nickname])) {
                    $person = $team_members_by_nickname[$nickname];
                    ### update to itemperson table...
                    if ($view = ItemPerson::getAll(array('person' => $person->id, 'item' => $task->id))) {
                        $view[0]->feedback_requested_by = $auth->cur_user->id;
                        $view[0]->update();
                    } else {
                        $new_view = new ItemPerson(array('item' => $task->id, 'person' => $person->id, 'feedback_requested_by' => $auth->cur_user->id));
                        $new_view->insert();
                    }
                    $requested_people[] = "<b>" . asHtml($nickname) . "</b>";
                } else {
                    new FeedbackWarning(sprintf(__("Nickname not known in this project: %s"), "<b>" . asHtml($nickname) . "</b>"));
                }
            }
        }
        if ($requested_people) {
            new FeedbackMessage(sprintf(__('Requested feedback from: %s.'), join($requested_people, ", ")));
        }
    }
    ### only insert the comment, when comment name or description are valid
    if (get('comment_name') || get('comment_description')) {
        require_once confGet('DIR_STREBER') . 'pages/comment.inc.php';
        $valid_comment = true;
        ### new object? ###
        $comment = new Comment(array('name' => get('comment_name'), 'description' => get('comment_description'), 'project' => $task->project, 'task' => $task->id));
        validateNotSpam($comment->name . $comment->description);
        ### write to db ###
        if ($valid_comment) {
            if (!$comment->insert()) {
                new FeedbackWarning(__("Failed to add comment"));
            } else {
                ### change task update modification date ###
                if (isset($task)) {
                    ### Check if now longer new ###
                    if ($task->status == STATUS_NEW) {
                        global $auth;
                        if ($task->created < $auth->cur_user->last_login) {
//.........这里部分代码省略.........
开发者ID:Bremaweb,项目名称:streber-1,代码行数:101,代码来源:task_edit.inc.php

示例7: xmlrpc_pingback__ping


//.........这里部分代码省略.........
			if ( isset( $headers['Content-Type'] ) && strpos( $headers['Content-Type'], 'charset' ) !== false ) {
				// This regex should be changed to meet the HTTP spec at some point
				if ( preg_match("/charset[\x09\x0A\x0C\x0D\x20]*=[\x09\x0A\x0C\x0D\x20]*('?)([A-Za-z0-9\-\_]+)\1/i", $headers['Content-Type'], $matches ) ) {
					$source_encoding = strtoupper( $matches[2] );
				}
			}
			// Can we tell the charset from the stream itself?
			else if ( ( $enc = MultiByte::detect_bom_encoding( $source_contents ) ) !== false ) {
				$source_encoding = $enc;
			}
			// Is the charset in a meta tag?
			else if ( preg_match( "/<meta[^>]+charset[\x09\x0A\x0C\x0D\x20]*=[\x09\x0A\x0C\x0D\x20]*([\"']?)([A-Za-z0-9\-\_]+)\1/i", $source_contents, $matches ) ) {
				$source_encoding = strtoupper( $matches[2] );
				if (in_array($source_encoding, array("UTF-16", "UTF-16BE", "UTF-16LE"))) {
					$source_encoding = "UTF-8";
				}
			}
			// Then, convert the string
			$ret = MultiByte::convert_encoding( $source_contents, $habari_encoding, $source_encoding );
			if ( $ret !== false ) {
				$source_contents = $ret;
			}

			// Find the page's title
			preg_match( '/<title>(.*)<\/title>/is', $source_contents, $matches );
			$source_title = $matches[1];

			// Find the reciprocal links and their context
			preg_match( '/<body[^>]*>(.+)<\/body>/is', $source_contents, $matches );
			$source_contents_filtered = preg_replace( '/\s{2,}/is', ' ', strip_tags( $matches[1], '<a>' ) );

			// Get rid of all the non-recriprocal links
			$ht = new HTMLTokenizer( trim( $source_contents_filtered ) );
			$set = $ht->parse();
			$all_links = $set->slice( 'a', array() );
			$keep_links = $set->slice( 'a', array( 'href' => $target_uri ) );
			$bad_links = array_diff( $all_links, $keep_links );
			foreach( $bad_links as $link ) {
				$link->tokenize_replace( '' );
				$set->replace_slice( $link );
			}
			$source_contents_filtered = (string)$set;

			// Get the excerpt
			if ( !preg_match( '%.{0,100}?<a[^>]*?href\\s*=\\s*("|\'|)' . $target_uri . '\\1[^>]*?'.'>(.+?)</a>.{0,100}%s', $source_contents_filtered, $source_excerpt ) ) {
				throw new XMLRPCException( 17 );
			}

			/** Sanitize Data */
			$source_excerpt = '&hellip;' . InputFilter::filter( $source_excerpt[0] ) . '&hellip;';
			$source_title = InputFilter::filter($source_title);
			$source_uri = InputFilter::filter($source_uri);

			/* Sanitize the URL */
			if (!empty($source_uri)) {
				$parsed = InputFilter::parse_url( $source_uri );
				if ( $parsed['is_relative'] ) {
					// guess if they meant to use an absolute link
					$parsed = InputFilter::parse_url( 'http://' . $source_uri );
					if ( ! $parsed['is_error'] ) {
						$source_uri = InputFilter::glue_url( $parsed );
					}
					else {
						// disallow relative URLs
						$source_uri = '';
					}
				}
				if ( $parsed['is_pseudo'] || ( $parsed['scheme'] !== 'http' && $parsed['scheme'] !== 'https' ) ) {
					// allow only http(s) URLs
					$source_uri = '';
				}
				else {
					// reconstruct the URL from the error-tolerant parsing
					// http:moeffju.net/blog/ -> http://moeffju.net/blog/
					$source_uri = InputFilter::glue_url( $parsed );
				}
			}

			// Add a new pingback comment
			$pingback = new Comment( array(
				'post_id'	=>	$target_post->id,
				'name'		=>	$source_title,
				'email'		=>	'',
				'url'		=>	$source_uri,
				'ip'		=>	Utils::get_ip(),
				'content'	=>	$source_excerpt,
				'status'	=>	Comment::STATUS_UNAPPROVED,
				'date'		=>	HabariDateTime::date_create(),
				'type' 		=> 	Comment::PINGBACK,
				) );

			$pingback->insert();

			// Respond to the Pingback
			return 'The pingback has been registered';
		}
		catch ( XMLRPCException $e ) {
			$e->output_fault_xml();
		}
	}
开发者ID:rynodivino,项目名称:system,代码行数:101,代码来源:pingback.plugin.php

示例8: action_auth_ajax_wp_import_comments

    /**
     * The plugin sink for the auth_ajax_wp_import_comments hook.
     * Responds via authenticated ajax to requests for comment importing.
     *
     * @param AjaxHandler $handler The handler that handled the request, contains $_POST info
     */
    public function action_auth_ajax_wp_import_comments($handler)
    {
        $valid_fields = array('db_name', 'db_host', 'db_user', 'db_pass', 'db_prefix', 'commentindex', 'category_import', 'utw_import');
        $inputs = array_intersect_key($_POST->getArrayCopy(), array_flip($valid_fields));
        extract($inputs);
        $wpdb = $this->wp_connect($db_host, $db_name, $db_user, $db_pass, $db_prefix);
        if ($wpdb) {
            if (!DB::in_transaction()) {
                DB::begin_transaction();
            }
            $commentcount = $wpdb->get_value("SELECT count( comment_ID ) FROM {$db_prefix}comments;");
            $min = $commentindex * IMPORT_BATCH + 1;
            $max = min(($commentindex + 1) * IMPORT_BATCH, $commentcount);
            echo "<p>Importing comments {$min}-{$max} of {$commentcount}.</p>";
            $postinfo = DB::table('postinfo');
            $post_info = DB::get_results("SELECT post_id, value FROM {$postinfo} WHERE name= 'wp_id';");
            foreach ($post_info as $info) {
                $post_map[$info->value] = $info->post_id;
            }
            $comments = $wpdb->get_results("\n\t\t\t\tSELECT\n\t\t\t\tcomment_content as content,\n\t\t\t\tcomment_author as name,\n\t\t\t\tcomment_author_email as email,\n\t\t\t\tcomment_author_url as url,\n\t\t\t\tINET_ATON( comment_author_IP ) as ip,\n\t\t\t \tcomment_approved as status,\n\t\t\t\tcomment_date as date,\n\t\t\t\tcomment_type as type,\n\t\t\t\tID as wp_post_id\n\t\t\t\tFROM {$db_prefix}comments\n\t\t\t\tINNER JOIN\n\t\t\t\t{$db_prefix}posts on ( {$db_prefix}posts.ID= {$db_prefix}comments.comment_post_ID )\n\t\t\t\tLIMIT {$min}, " . IMPORT_BATCH, array(), 'Comment');
            foreach ($comments as $comment) {
                switch ($comment->type) {
                    case 'pingback':
                        $comment->type = Comment::PINGBACK;
                        break;
                    case 'trackback':
                        $comment->type = Comment::TRACKBACK;
                        break;
                    default:
                        $comment->type = Comment::COMMENT;
                }
                $comment->content = MultiByte::convert_encoding($comment->content);
                $comment->name = MultiByte::convert_encoding($comment->name);
                $carray = $comment->to_array();
                if ($carray['ip'] == '') {
                    $carray['ip'] = 0;
                }
                switch ($carray['status']) {
                    case '0':
                        $carray['status'] = Comment::STATUS_UNAPPROVED;
                        break;
                    case '1':
                        $carray['status'] = Comment::STATUS_APPROVED;
                        break;
                    case 'spam':
                        $carray['status'] = Comment::STATUS_SPAM;
                        break;
                }
                if (isset($post_map[$carray['wp_post_id']])) {
                    $carray['post_id'] = $post_map[$carray['wp_post_id']];
                    unset($carray['wp_post_id']);
                    $c = new Comment($carray);
                    //Utils::debug( $c );
                    try {
                        $c->insert();
                    } catch (Exception $e) {
                        EventLog::log($e->getMessage(), 'err', null, null, print_r(array($c, $e), 1));
                        Session::error($e->getMessage());
                        $errors = Options::get('import_errors');
                        $errors[] = $e->getMessage();
                        Options::set('import_errors', $errors);
                    }
                }
            }
            if (DB::in_transaction()) {
                DB::commit();
            }
            if ($max < $commentcount) {
                $ajax_url = URL::get('auth_ajax', array('context' => 'wp_import_comments'));
                $commentindex++;
                $vars = Utils::addslashes(array('host' => $db_host, 'name' => $db_name, 'user' => $db_user, 'pass' => $db_pass, 'prefix' => $db_prefix));
                echo <<<WP_IMPORT_AJAX1
\t\t\t\t\t<script type="text/javascript">
\t\t\t\t\t\$( '#import_progress' ).load(
\t\t\t\t\t\t"{$ajax_url}",
\t\t\t\t\t\t{
\t\t\t\t\t\t\tdb_host: "{$vars['host']}",
\t\t\t\t\t\t\tdb_name: "{$vars['name']}",
\t\t\t\t\t\t\tdb_user: "{$vars['user']}",
\t\t\t\t\t\t\tdb_pass: "{$vars['pass']}",
\t\t\t\t\t\t\tdb_prefix: "{$vars['prefix']}",
\t\t\t\t\t\t\tcategory_import: "{$category_import}",
\t\t\t\t\t\t\tutw_import: "{$utw_import}",
\t\t\t\t\t\t\tcommentindex: {$commentindex}
\t\t\t\t\t\t}
\t\t\t\t\t );

\t\t\t\t</script>
WP_IMPORT_AJAX1;
            } else {
                EventLog::log('Import complete from "' . $db_name . '"');
                echo '<p>' . _t('Import is complete.') . '</p>';
                $errors = Options::get('import_errors');
                if (count($errors) > 0) {
//.........这里部分代码省略.........
开发者ID:anupom,项目名称:my-blog,代码行数:101,代码来源:wpimport.plugin.php

示例9: action_auth_ajax_wp_import_comments


//.........这里部分代码省略.........
     $posts = DB::get_results('select post_id, value from {postinfo} where name = :name', array(':name' => 'wp_id'));
     // create an easy post map of old ID -> new ID
     $post_map = array();
     foreach ($posts as $info) {
         $post_map[$info->value] = $info->post_id;
     }
     // get all the comment IDs we've imported so far to make sure we don't duplicate any
     $comment_map = DB::get_column('select value from {commentinfo} where name = :name', array(':name' => 'wp_id'));
     // now we're ready to start importing comments
     $comments = $wpdb->get_results('select comment_id, comment_post_id, comment_author, comment_author_email, comment_author_url, comment_author_ip, comment_date, comment_content, comment_karma, comment_approved, comment_agent, comment_type, comment_parent, user_id from ' . $inputs['db_prefix'] . 'comments order by comment_id asc limit ' . $min . ', ' . IMPORT_BATCH);
     foreach ($comments as $comment) {
         // if this post is already in the list we've imported, skip it
         if (in_array($comment->id, $comment_map)) {
             continue;
         }
         // if the post this comment belongs to is not in the list of imported posts, skip it
         if (!isset($post_map[$comment->comment_post_id])) {
             continue;
         }
         // create the new comment
         $c = new Comment(array('content' => MultiByte::convert_encoding($comment->comment_content), 'name' => MultiByte::convert_encoding($comment->comment_author), 'email' => MultiByte::convert_encoding($comment->comment_author_email), 'url' => MultiByte::convert_encoding($comment->comment_author_url), 'date' => HabariDateTime::date_create($comment->comment_date), 'post_id' => $post_map[$comment->comment_post_id]));
         // figure out the comment type
         switch ($comment->comment_type) {
             case 'pingback':
                 $c->type = Comment::type('pingback');
                 break;
             case 'trackback':
                 $c->type = Comment::type('trackback');
                 break;
             default:
             case 'comment':
                 $c->type = Comment::type('comment');
                 break;
         }
         // figure out the comment status
         switch ($comment->comment_approved) {
             case '1':
                 $c->status = Comment::status('approved');
                 break;
             case '':
             case '0':
                 $c->status = Comment::status('unapproved');
                 break;
             case 'spam':
                 $c->status = Comment::status('spam');
                 break;
             default:
                 // Comment::status() returns false if it doesn't recognize the status type
                 $status = Comment::status($comment->comment_status);
                 // store in a temp value because if you try and set ->status to an invalid value the Comment class freaks
                 if ($status == false) {
                     // we're not importing statuses we don't recognize - continue 2 to break out of the switch and the loop and continue to the next comment
                     continue 2;
                 } else {
                     $c->status = $status;
                 }
                 break;
         }
         // save the old comment ID in info
         $c->info->wp_id = $comment->comment_id;
         // save the old post ID in info
         $c->info->wp_post_id = $comment->comment_post_id;
         // save the old comment karma - but only if it is something
         if ($comment->comment_karma != '0') {
             $c->info->wp_karma = $comment->comment_karma;
         }
         // save the old comment user agent - but only if it is something
         if ($comment->comment_agent != '') {
             $c->info->wp_agent = $comment->comment_agent;
         }
         // now that we've got all the pieces in place, save the comment
         try {
             $c->insert();
         } catch (Exception $e) {
             EventLog::log($e->getMessage(), 'err');
             echo '<p class="error">' . _t('There was an error importing comment ID %d. See the EventLog for the error message.', array($comment->comment_id));
             echo '<p>' . _t('Rolling back changes&hellip;') . '</p>';
             // rollback all changes before we return so the import hasn't changed anything yet
             DB::rollback();
             // and return so they don't get AJAX to send them on to the next step
             return false;
         }
     }
     // if we've finished without an error, commit the import
     DB::commit();
     if ($max < $num_comments) {
         // if there are more posts to import
         // get the next ajax url
         $ajax_url = URL::get('auth_ajax', array('context' => 'wp_import_comments'));
         // bump the import index by one so we get a new batch next time
         $inputs['import_index']++;
     } else {
         // display the completed message!
         EventLog::log(_t('Import completed from "%s"', array($inputs['db_name'])));
         echo '<p>' . _t('Import is complete.') . '</p>';
         return;
     }
     // and spit out ajax to send them to the next step - posts!
     echo $this->get_ajax($ajax_url, $inputs);
 }
开发者ID:ringmaster,项目名称:system,代码行数:101,代码来源:wpimport.plugin.php

示例10: action_mollom_fallback

 public function action_mollom_fallback(SuperGlobal $handler_vars, Comment $comment)
 {
     if (!empty($handler_vars['mollom_captcha']) && !empty($comment)) {
         if (Mollom::checkCaptcha($comment->info->mollom_session_id, $handler_vars['mollom_captcha'])) {
             $comment->status = 'unapproved';
             $comment->insert();
             $anchor = '#comment-' . $comment->id;
             Utils::redirect($comment->post->permalink . $anchor);
             exit;
         } else {
             Session::error(_t('Sorry, that answer was incorrect. Please try again.', 'mollom'));
             $this->send_captcha($comment);
             exit;
         }
     } elseif (empty($comment)) {
         die(_t('Sorry, the gremlins ate your comment...', 'mollom'));
     } else {
         $this->send_captcha($comment);
         exit;
     }
 }
开发者ID:habari-extras,项目名称:mollom,代码行数:21,代码来源:mollom.plugin.php

示例11: action_auth_ajax_hab_import_comments

 /**
  * The plugin sink for the auth_ajax_hab_import_comments hook.
  * Responds via authenticated ajax to requests for comment importing.
  *
  * @param AjaxHandler $handler The handler that handled the request, contains $_POST info
  */
 public function action_auth_ajax_hab_import_comments($handler)
 {
     $inputs = $_POST->filter_keys('db_type', 'db_name', 'db_host', 'db_user', 'db_pass', 'db_prefix', 'commentindex', 'tag_import');
     $inputs = $inputs->getArrayCopy($inputs);
     $inputs = array_merge($this->default_values, $inputs);
     $connect_string = $this->get_connect_string($inputs['db_type'], $inputs['db_host'], $inputs['db_name']);
     $db = $this->hab_connect($connect_string, $inputs['db_user'], $inputs['db_pass']);
     if (!$db) {
         EventLog::log(sprintf(_t('Failed to import from "%s"'), $inputs['db_name']), 'crit');
         Session::error($e->getMessage());
         echo '<p>' . _t('Failed to connect using the given database connection details.') . '</p>';
     }
     DB::begin_transaction();
     $commentcount = $db->get_value("SELECT count( id ) FROM {$inputs['db_prefix']}comments;");
     $min = $inputs['import_index'] * IMPORT_BATCH + ($inputs['import_index'] == 0 ? 0 : 1);
     $max = min(($inputs['import_index'] + 1) * IMPORT_BATCH, $commentcount);
     echo "<p>Importing comments {$min}-{$max} of {$commentcount}.</p>";
     $post_info = DB::get_results("SELECT post_id, value FROM {$inputs['db_prefix']}postinfo WHERE name= 'old_id';");
     foreach ($post_info as $info) {
         $post_map[$info->value] = $info->post_id;
     }
     $comments = $db->get_results("\r\n\t\t\tSELECT\r\n\t\t\tc.id,\r\n\t\t\tc.content,\r\n\t\t\tc.name,\r\n\t\t\tc.email,\r\n\t\t\tc.url,\r\n\t\t\tc.ip,\r\n\t\t\tc.status,\r\n\t\t\tc.date,\r\n\t\t\tc.type,\r\n\t\t\tc.post_id as old_post_id\r\n\t\t\tFROM {$inputs['db_prefix']}comments c\r\n\t\t\tINNER JOIN\r\n\t\t\t{$inputs['db_prefix']}posts on {$inputs['db_prefix']}posts.id = c.post_id\r\n\t\t\tLIMIT {$min}, " . IMPORT_BATCH, array(), 'Comment');
     foreach ($comments as $comment) {
         $carray = $comment->to_array();
         if (isset($post_map[$carray['old_post_id']])) {
             $carray['post_id'] = $post_map[$carray['old_post_id']];
             unset($carray['old_post_id']);
             $c = new Comment($carray);
             $infos = $db->get_results("SELECT name, value, type FROM {$inputs['db_prefix']}commentinfo WHERE comment_id = ?", array($carray['id']));
             foreach ($infos as $info) {
                 $fields = $info->get_url_args();
                 if ($fields['type'] == 1) {
                     $fields['value'] = unserialize($fields['value']);
                 }
                 $c->info->{$fields}['name'] = $fields['value'];
             }
             try {
                 $c->insert();
             } catch (Exception $e) {
                 EventLog::log($e->getMessage(), 'err', null, null, print_r(array($c, $e), 1));
                 Session::error($e->getMessage());
                 $errors = Options::get('import_errors');
                 $errors[] = $e->getMessage();
                 Options::set('import_errors', $errors);
             }
         }
     }
     if (DB::in_transaction()) {
         DB::commit();
     }
     if ($max < $commentcount) {
         $ajax_url = URL::get('auth_ajax', array('context' => 'hab_import_comments'));
         $inputs['import_index']++;
         echo $this->get_ajax($ajax_url, $inputs);
     } else {
         EventLog::log('Import complete from "' . $inputs['db_name'] . '"');
         echo '<p>' . _t('Import is complete.') . '</p>';
         $errors = Options::get('import_errors');
         if (count($errors) > 0) {
             echo '<p>' . _t('There were errors during import:') . '</p>';
             echo '<ul>';
             foreach ($errors as $error) {
                 echo '<li>' . $error . '</li>';
             }
             echo '</ul>';
         }
     }
 }
开发者ID:habari-extras,项目名称:habari_import,代码行数:74,代码来源:habari_import.plugin.php

示例12: newComment

 function newComment()
 {
     foreach ($_POST as $k => $v) {
         $_POST[$k] = trim($v);
     }
     if ($_POST['url'] == 'http://' || empty($_POST['url'])) {
         unset($_POST['url']);
     }
     //strip html tags in comment
     if (!empty($_POST['content'])) {
         $_POST['content'] = strip_tags($_POST['content']);
     }
     Doo::loadModel('Comment');
     $c = new Comment($_POST);
     $this->prepareSidebar();
     // 'skip' is same as DooValidator::CHECK_SKIP
     if ($error = $c->validate('skip')) {
         $this->data['rootUrl'] = Doo::conf()->APP_URL;
         $this->data['title'] = 'Oops! Error Occured!';
         $this->data['content'] = '<p style="color:#ff0000;">' . $error . '</p>';
         $this->data['content'] .= '<p>Go <a href="javascript:history.back();">back</a> to post.</p>';
         $this->render('error', $this->data);
     } else {
         Doo::autoload('DooDbExpression');
         $c->createtime = new DooDbExpression('NOW()');
         $c->insert();
         $this->data['rootUrl'] = Doo::conf()->APP_URL;
         $this->render('comment', $this->data);
     }
 }
开发者ID:mindaugas-valinskis,项目名称:doophp,代码行数:30,代码来源:BlogController.php

示例13: commentAction

 public function commentAction()
 {
     $label = $this->_getParam('label');
     if ($label === null) {
         throw new Zend_Exception('No label specified in PostsController::commentAction()');
     }
     $postManager = new Post();
     $post = $postManager->fetchRow(array('label = ?' => $label, 'is_active = ?' => 1));
     if ($post === null) {
         throw new Zend_Exception('No post found with that label in PostsController::commentAction()');
     }
     $this->view->post = $post;
     // form
     $form = new Zend_Form($this->_commentForm);
     $form->setAction('/posts/' . $post->label . '/comment');
     $this->view->form = $form;
     if ($this->getRequest()->isPost()) {
         if ($form->isValid($_POST)) {
             $config = Zend_Registry::get('config');
             $akismet = new Zend_Service_Akismet($config->akismet->key, 'http://codecaine.co.za');
             $akismetData = array('user_ip' => $_SERVER['REMOTE_ADDR'], 'user_agent' => $_SERVER['HTTP_USER_AGENT'], 'referrer' => $_SERVER['HTTP_REFERER'], 'permalink' => 'http://codecaine.co.za/posts/' . $post->label, 'comment_type' => 'comment', 'comment_author' => $_POST['name'], 'comment_author_email' => $_POST['email'], 'comment_author_url' => $_POST['website'], 'comment_content' => $_POST['text']);
             if ($akismet->isSpam($akismetData)) {
                 $this->_redirect('/spam');
             }
             $commentManager = new Comment();
             $data = $_POST;
             unset($data['submit']);
             $data['post_id'] = $post->id;
             $data['posted_at'] = new Zend_Db_Expr('NOW()');
             $id = $commentManager->insert($data);
             $this->_redirect('/posts/' . $post->label . '#comment-' . $id);
         }
     }
     // description
     $this->view->metaDescription = 'Post your comments on ' . $post->title;
     // set title
     $this->_title($post->title);
 }
开发者ID:neilgarb,项目名称:codecaine,代码行数:38,代码来源:PostsController.php

示例14: import_comment

 /**
  * Imports a single comment from the s9y database into the
  * habari database
  *
  * @param		comment_info		 	QueryRecord of comment information to import
  * @param		habari_post_id		ID of the post to attach the comment to
  * @return	TRUE or FALSE if import of comment succeeded
  */
 private function import_comment($comment_info = array(), $habari_post_id)
 {
     /* A mapping for s9y comment status to habari comment status codes */
     $status_map = array('APPROVED' => Comment::STATUS_APPROVED, 'PENDING' => Comment::STATUS_UNAPPROVED);
     /* A mapping for s9y comment type to habari comment type codes */
     $type_map = array('TRACKBACK' => Comment::TRACKBACK, 'NORMAL' => Comment::COMMENT);
     $comment = new Comment();
     $comment->post_id = $habari_post_id;
     $comment->info->s9y_id = $comment_info->id;
     if (!empty($comment_info->parent_id) && $comment_info->parent_id != "0") {
         $comment->info->s9y_parent_id = $comment_info->parent_id;
     }
     $comment->ip = sprintf("%u", ip2long($comment_info->ip));
     $comment->status = $status_map[strtoupper($comment_info->status)];
     $comment->type = $type_map[strtoupper($comment_info->type)];
     $comment->name = $this->transcode($comment_info->author);
     $comment->url = $comment_info->url;
     $comment->date = date('Y-m-d H:i:s', $comment_info->timestamp);
     $comment->email = $this->transcode($comment_info->email);
     $comment->content = $this->transcode($comment_info->body);
     if ($comment->insert()) {
         return TRUE;
     } else {
         EventLog::log($e->getMessage(), 'err', null, null, print_r(array($comment, $e), 1));
         Session::error($e->getMessage());
         return FALSE;
     }
 }
开发者ID:habari-extras,项目名称:s9yimport,代码行数:36,代码来源:s9yimport.plugin.php

示例15: action_auth_ajax_mt_file_import_all

 /**
  * action: auth_ajax_mt_file_import_all
  *
  * @access public
  * @param array $handler
  */
 public function action_auth_ajax_mt_file_import_all($handler)
 {
     $text = file_get_contents($_SESSION['mtimport_mt_file']);
     try {
         $parser = new MTFileParser($text);
     } catch (Exception $e) {
         echo '<p>' . _t('Failed parsing File: ') . $e->getMessage() . '</p>';
         return;
     }
     $posts = $parser->getResult();
     @reset($posts);
     while (list(, $mt_post) = @each($posts)) {
         // Post
         $t_post = array();
         $tags = array();
         if (isset($mt_post['_META']['BASENAME'])) {
             $t_post['slug'] = $mt_post['_META']['BASENAME'];
         }
         $t_post['content_type'] = Post::type('entry');
         $t_post['title'] = strip_tags(htmlspecialchars_decode(MultiByte::convert_encoding($mt_post['_META']['TITLE'])));
         if (isset($mt_post['EXTENDED BODY']['_BODY'])) {
             $t_post['content'] = MultiByte::convert_encoding($mt_post['BODY']['_BODY'] . $mt_post['EXTENDED BODY']['_BODY']);
         } else {
             $t_post['content'] = MultiByte::convert_encoding($mt_post['BODY']['_BODY']);
         }
         if (!isset($mt_post['_META']['STATUS']) || $mt_post['_META']['STATUS'] == 'Publish') {
             $t_post['status'] = Post::status('published');
         } else {
             $t_post['status'] = Post::status('draft');
         }
         $t_post['pubdate'] = $t_post['updated'] = HabariDateTime::date_create($mt_post['_META']['DATE']);
         if (isset($mt_post['_META']['CATEGORY'])) {
             $tags = array_merge($tags, $mt_post['_META']['CATEGORY']);
         }
         if (isset($mt_post['_META']['TAGS'])) {
             $t_tags = explode(',', $mt_post['_META']['TAGS']);
             $t_tags = array_map('trim', $t_tags, array('"'));
             $tags = array_merge($tags, $t_tags);
         }
         $post = new Post($t_post);
         if (isset($mt_post['_META']['ALLOW COMMENTS']) && $mt_post['_META']['ALLOW COMMENTS'] != 1) {
             $post->info->comments_disabled = 1;
         }
         $post->tags = array_unique($tags);
         $post->user_id = User::identify()->id;
         // TODO: import MT author
         try {
             $post->insert();
         } catch (Exception $e) {
             EventLog::log($e->getMessage(), 'err', null, null, print_r(array($p, $e), 1));
             Session::error($e->getMessage());
             $errors = Options::get('import_errors');
             $errors[] = $p->title . ' : ' . $e->getMessage();
             Options::set('import_errors', $errors);
         }
         // Comments
         if (isset($mt_post['COMMENT'])) {
             @reset($mt_post['COMMENT']);
             while (list(, $mt_comment) = @each($mt_post['COMMENT'])) {
                 $t_comment = array();
                 $t_comment['post_id'] = $post->id;
                 $t_comment['name'] = MultiByte::convert_encoding($mt_comment['AUTHOR']);
                 if (isset($mt_comment['EMAIL'])) {
                     $t_comment['email'] = $mt_comment['EMAIL'];
                 }
                 if (isset($mt_comment['URL'])) {
                     $t_comment['url'] = strip_tags($mt_comment['URL']);
                 }
                 if (isset($mt_comment['IP'])) {
                     $t_comment['ip'] = $mt_comment['IP'];
                 }
                 $t_comment['content'] = MultiByte::convert_encoding($mt_comment['_BODY']);
                 $t_comment['status'] = Comment::STATUS_APPROVED;
                 $t_comment['date'] = HabariDateTime::date_create($mt_comment['DATE']);
                 $t_comment['type'] = Comment::COMMENT;
                 $comment = new Comment($t_comment);
                 try {
                     $comment->insert();
                 } catch (Exception $e) {
                     EventLog::log($e->getMessage(), 'err', null, null, print_r(array($c, $e), 1));
                     Session::error($e->getMessage());
                     $errors = Options::get('import_errors');
                     $errors[] = $e->getMessage();
                     Options::set('import_errors', $errors);
                 }
             }
         }
         // Trackbacks
         if (isset($mt_post['PING'])) {
             @reset($mt_post['PING']);
             while (list(, $mt_comment) = @each($mt_post['PING'])) {
                 $t_comment = array();
                 $t_comment['post_id'] = $post->id;
                 $t_comment['name'] = MultiByte::convert_encoding($mt_comment['BLOG NAME'] . ' - ' . $mt_comment['TITLE']);
//.........这里部分代码省略.........
开发者ID:habari-extras,项目名称:mtimport,代码行数:101,代码来源:mtimport.plugin.php


注:本文中的Comment::insert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。