コード例 #1
0
 function addComment()
 {
     global $wpdb;
     $Validation = new ThemeValidation();
     $response = array('error' => 0, 'info' => null, 'changeURL' => '');
     $data = array('author' => null, 'email' => null, 'url' => null, 'comment' => null, 'comment_post_ID' => 0, 'comment_parent' => 0);
     foreach ($data as $index => $value) {
         if (array_key_exists($index, $_POST)) {
             $data[$index] = $_POST[$index];
         }
     }
     if (!is_user_logged_in()) {
         if ($Validation->isEmpty($data['author']) && get_option('require_name_email') == 1) {
             $response['error'] = 1;
             $response['info'][] = array('fieldId' => 'author', 'message' => esc_html__('Please enter your name.', THEME_DOMAIN));
         }
         if (!$Validation->isEmailAddress($data['email']) && get_option('require_name_email') == 1) {
             $response['error'] = 1;
             $response['info'][] = array('fieldId' => 'email', 'message' => esc_html__('Please enter valid e-mail address.', THEME_DOMAIN));
         }
         if (!$Validation->isURL($data['url'], true)) {
             $response['error'] = 1;
             $response['info'][] = array('fieldId' => 'url', 'message' => esc_html__('Please enter valid URL address.', THEME_DOMAIN));
         }
     }
     if ($Validation->isEmpty($data['comment'])) {
         $response['error'] = 1;
         $response['info'][] = array('fieldId' => 'comment', 'message' => esc_html__('Please enter your message.', THEME_DOMAIN));
     }
     if ($response['error'] == 1) {
         $this->createResponse($response);
     }
     $data = ThemeHelper::stripslashesPOST($data);
     $insertData = array('comment_post_ID' => (int) $data['comment_post_ID'], 'comment_content' => $data['comment'], 'comment_parent' => (int) $data['comment_parent'], 'comment_date' => current_time('mysql'), 'comment_approved' => $this->comment_moderation);
     if (!is_user_logged_in()) {
         $insertData['comment_author'] = $data['author'];
         $insertData['comment_author_url'] = ThemeHelper::addProtocolName($data['url']);
         $insertData['comment_author_email'] = $data['email'];
     } else {
         $user = wp_get_current_user();
         $insertData['comment_author'] = $user->display_name;
         $insertData['comment_author_email'] = $user->user_email;
     }
     $commentId = wp_insert_comment($insertData);
     if ($commentId) {
         query_posts('p=' . (int) $data['comment_post_ID'] . '&post_type=post');
         if (have_posts()) {
             the_post();
             if ((int) $data['comment_parent'] == 0 || $this->thread_comments == 0) {
                 $query = 'select count(*) as count from ' . $wpdb->comments . ' where comment_approved=1 and comment_post_ID=' . (int) get_the_ID() . ($this->thread_comments == 1 ? ' and comment_parent=0' : null);
                 $parent = $wpdb->get_row($query);
                 if ($this->comments_per_page > 0) {
                     $_GET['cpage'] = ceil($parent->count / $this->comments_per_page);
                 } else {
                     $_GET['cpage'] = 1;
                 }
                 $response['changeURL'] = '#cpage-' . $_GET['cpage'];
             } else {
                 $_GET['cpage'] = (int) $_POST['cpage'];
             }
             $response['cpage'] = (int) $_GET['cpage'];
             $response['commentId'] = (int) $commentId;
             ob_start();
             comments_template();
             $response['html'] = ob_get_contents();
             ob_end_clean();
         }
         $response['comment_id'] = $commentId;
         $response['error'] = 0;
         $response['info'][] = array('fieldId' => 'submit', 'message' => esc_html__('Your comment has been added.', THEME_DOMAIN));
     } else {
         $response['error'] = 1;
         $response['info'][] = array('fieldId' => 'submit', 'message' => esc_html__('Your comment could not be added.', THEME_DOMAIN));
     }
     $this->createResponse($response);
 }
コード例 #2
0
 function displayTitle($title)
 {
     $Validation = new ThemeValidation();
     global $fable_parentPost;
     $title = get_bloginfo('name');
     if (!$Validation->isEmpty($title)) {
         $title .= ' | ';
     }
     $title .= $fable_parentPost->post->post_title;
     return $title;
 }
コード例 #3
0
    function createCategoryList()
    {
        $html = null;
        $Validation = new ThemeValidation();
        $category = get_the_category(get_the_ID());
        $count = count($category);
        if (!$count) {
            return $html;
        }
        foreach ($category as $index => $value) {
            $title = $Validation->isEmpty($value->description) ? sprintf(__('View all posts filed under "%s"', THEME_DOMAIN), $value->name) : strip_tags(apply_filters('category_description', $value->description, $value));
            $html .= '
				<li><a href="' . get_category_link($value->term_id) . '" title="' . esc_attr($title) . '">' . esc_html($value->name) . '</a>' . ($index == $count - 1 ? '' : ',&nbsp;') . '</li>
			';
        }
        $html = '
			<div class="theme-post-meta-category">
				<ul class="theme-reset-list">
					' . $html . '
				</ul>
			</div>
		';
        return $html;
    }
コード例 #4
0
 static function createStyleAttribute($style)
 {
     $ret = null;
     $Validation = new ThemeValidation();
     foreach ($style as $index => $value) {
         if ($Validation->isEmpty($value)) {
             continue;
         }
         $ret .= $index . ':' . $value . ';';
     }
     return $Validation->isEmpty($ret) ? null : ' style="' . $ret . '"';
 }