Exemplo n.º 1
0
    public function GetChunk()
    {
        global $post;
        $post_id = $post->ID;
        $post_title = $post->post_title;
        $keywords = explode(' ', $post_title);
        $word_count = count($keywords);
        $overusedwords = array('', 'a', 'an', 'the', 'and', 'of', 'i', 'to', 'is', 'in', 'with', 'for', 'as', 'that', 'on', 'at', 'this', 'my', 'was', 'our', 'it', 'you', 'we', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '10', 'about', 'after', 'all', 'almost', 'along', 'also', 'amp', 'another', 'any', 'are', 'area', 'around', 'available', 'back', 'be', 'because', 'been', 'being', 'best', 'better', 'big', 'bit', 'both', 'but', 'by', 'c', 'came', 'can', 'capable', 'control', 'could', 'course', 'd', 'dan', 'day', 'decided', 'did', 'didn', 'different', 'div', 'do', 'doesn', 'don', 'down', 'drive', 'e', 'each', 'easily', 'easy', 'edition', 'end', 'enough', 'even', 'every', 'example', 'few', 'find', 'first', 'found', 'from', 'get', 'go', 'going', 'good', 'got', 'gt', 'had', 'hard', 'has', 'have', 'he', 'her', 'here', 'how', 'if', 'into', 'isn', 'just', 'know', 'last', 'left', 'li', 'like', 'little', 'll', 'long', 'look', 'lot', 'lt', 'm', 'made', 'make', 'many', 'mb', 'me', 'menu', 'might', 'mm', 'more', 'most', 'much', 'name', 'nbsp', 'need', 'new', 'no', 'not', 'now', 'number', 'off', 'old', 'one', 'only', 'or', 'original', 'other', 'out', 'over', 'part', 'place', 'point', 'pretty', 'probably', 'problem', 'put', 'quite', 'quot', 'r', 're', 'really', 'results', 'right', 's', 'same', 'saw', 'see', 'set', 'several', 'she', 'sherree', 'should', 'since', 'size', 'small', 'so', 'some', 'something', 'special', 'still', 'stuff', 'such', 'sure', 'system', 't', 'take', 'than', 'their', 'them', 'then', 'there', 'these', 'they', 'thing', 'things', 'think', 'those', 'though', 'through', 'time', 'today', 'together', 'too', 'took', 'two', 'up', 'us', 'use', 'used', 'using', 've', 'very', 'want', 'way', 'well', 'went', 'were', 'what', 'when', 'where', 'which', 'while', 'white', 'who', 'will', 'would', 'your');
        if ($word_count == 0) {
            return false;
        }
        global $wpdb;
        $sql = "SELECT ID AS id, post_title AS post_title, post_content AS post_content FROM " . DB_NAME . ".{$wpdb->prefix}posts WHERE ";
        for ($i = 0; $i < $word_count; $i++) {
            $keyword = mysql_real_escape_string($keywords[$i]);
            if (!in_array($keyword, $overusedwords)) {
                $sql .= "post_title LIKE '%{$keyword}%' AND ID != {$post_id} AND post_type='post' AND post_status='publish' ";
                if ($i + 1 != $word_count) {
                    $sql .= "OR ";
                }
            }
        }
        $sql .= 'LIMIT 3';
        $result = mysql_query($sql);
        $error = '<div id="related-articles">    
						<div class="error">There are no related articles.</div>
					</div>';
        $return = '';
        if (!$result) {
            return $error;
        } else {
            $num_rows = mysql_numrows($result);
            $return .= '<div id="related-articles"><div class="title">' . OnePanelLanguage::GetText('related') . '</div>';
            if ($num_rows > 0) {
                for ($i = 0; $i < $num_rows; $i++) {
                    $id = mysql_result($result, $i, 'ID');
                    $title = mysql_result($result, $i, 'post_title');
                    $content = mysql_result($result, $i, 'post_content');
                    $return .= '<div class="related-article">';
                    $return .= OnePanelTheme::GetThumbnail($id);
                    $return .= '<div class="title"><a href="' . get_permalink($id) . '">' . substr($title, 0, 39) . '...</a></div>';
                    $return .= substr(strip_tags($content), 0, 135) . '...';
                    $return .= '</div>';
                }
                $return .= '</div>';
                return $return;
            } else {
                return $error;
            }
        }
    }