コード例 #1
0
    public function create_traffic_module($input_parameters)
    {
        $keyCache1 = Utils::hashKey(array(__CLASS__ . __METHOD__, $input_parameters));
        $resultData = TempDataAndCacheFile::get_cache($keyCache1);
        if (null !== $resultData) {
            return $resultData;
        }
        $wpExtend = $this->di->getShared('wpExtend');
        global $wpdb;
        $resultData = array('module' => '', 'module_id' => '');
        if (isset($input_parameters['option']['module_id']) && $input_parameters['option']['module_id']) {
            $nsModule = 'wppepvn_module_traffic';
            $resultData['module_id'] = $input_parameters['option']['module_id'];
            $isModuleNoText = true;
            if (isset($input_parameters['option']['enable_items_title']) && $input_parameters['option']['enable_items_title']) {
                $isModuleNoText = false;
            }
            if (isset($input_parameters['option']['enable_items_excerpt']) && $input_parameters['option']['enable_items_excerpt']) {
                $isModuleNoText = false;
            }
            if ($isModuleNoText) {
                $input_parameters['option']['module_style'] = 'style_2';
            }
            if (!isset($input_parameters['option']['title_of_module'])) {
                $input_parameters['option']['title_of_module'] = '';
                //Related article
            }
            if (!isset($input_parameters['option']['custom_class_css_of_module'])) {
                $input_parameters['option']['custom_class_css_of_module'] = '';
            }
            if (!isset($input_parameters['option']['custom_id_css_of_module'])) {
                $input_parameters['option']['custom_id_css_of_module'] = '';
            }
            if (!isset($input_parameters['option']['module_type'])) {
                $input_parameters['option']['module_type'] = 'fixed';
            }
            if (!isset($input_parameters['option']['module_mumber_of_items'])) {
                $input_parameters['option']['module_mumber_of_items'] = 1;
            }
            $input_parameters['option']['module_mumber_of_items'] = abs((int) $input_parameters['option']['module_mumber_of_items']);
            if ($input_parameters['option']['module_mumber_of_items'] > 10) {
                $input_parameters['option']['module_mumber_of_items'] = 10;
            } else {
                if ($input_parameters['option']['module_mumber_of_items'] < 1) {
                    $input_parameters['option']['module_mumber_of_items'] = 1;
                }
            }
            if (!isset($input_parameters['option']['thumbnail_width'])) {
                $input_parameters['option']['thumbnail_width'] = 0;
            }
            $input_parameters['option']['thumbnail_width'] = abs((int) $input_parameters['option']['thumbnail_width']);
            if (!isset($input_parameters['option']['thumbnail_height'])) {
                $input_parameters['option']['thumbnail_height'] = 0;
            }
            $input_parameters['option']['thumbnail_height'] = abs((int) $input_parameters['option']['thumbnail_height']);
            if (!isset($input_parameters['option']['maximum_width_each_item'])) {
                $input_parameters['option']['maximum_width_each_item'] = 0;
            }
            $input_parameters['option']['maximum_width_each_item'] = abs((int) $input_parameters['option']['maximum_width_each_item']);
            if (isset($input_parameters['option']['maximum_number_characters_items_title']) && $input_parameters['option']['maximum_number_characters_items_title']) {
            } else {
                $input_parameters['option']['maximum_number_characters_items_title'] = 60;
            }
            $input_parameters['option']['maximum_number_characters_items_title'] = abs((int) $input_parameters['option']['maximum_number_characters_items_title']);
            if (isset($input_parameters['option']['maximum_number_characters_items_excerpt']) && $input_parameters['option']['maximum_number_characters_items_excerpt']) {
            } else {
                $input_parameters['option']['maximum_number_characters_items_excerpt'] = 120;
            }
            $input_parameters['option']['maximum_number_characters_items_excerpt'] = abs((int) $input_parameters['option']['maximum_number_characters_items_excerpt']);
            if (isset($input_parameters['option']['module_appear_when_user_scroll_length']) && $input_parameters['option']['module_appear_when_user_scroll_length']) {
            } else {
                $input_parameters['option']['module_appear_when_user_scroll_length'] = '80%';
            }
            if (isset($input_parameters['option']['module_appear_when_user_read_for_seconds']) && $input_parameters['option']['module_appear_when_user_read_for_seconds']) {
            } else {
                $input_parameters['option']['module_appear_when_user_read_for_seconds'] = 0;
            }
            $input_parameters['option']['module_appear_when_user_read_for_seconds'] = abs((int) $input_parameters['option']['module_appear_when_user_read_for_seconds']);
            if (isset($input_parameters['option']['module_margin_bottom']) && $input_parameters['option']['module_margin_bottom']) {
            } else {
                $input_parameters['option']['module_margin_bottom'] = 0;
            }
            $input_parameters['option']['module_margin_bottom'] = (int) $input_parameters['option']['module_margin_bottom'];
            if (isset($input_parameters['option']['module_margin_left']) && $input_parameters['option']['module_margin_left']) {
            } else {
                $input_parameters['option']['module_margin_left'] = 0;
            }
            $input_parameters['option']['module_margin_left'] = (int) $input_parameters['option']['module_margin_left'];
            if (isset($input_parameters['data']['posts_ids']) && !PepVN_Data::isEmptyArray($input_parameters['data']['posts_ids'])) {
            } else {
                $input_parameters['data']['posts_ids'] = array();
                $queryString1 = '
SELECT ID
FROM `' . $wpdb->posts . '`
WHERE ( ( post_status = "publish") AND ( post_type = "post" ) )
ORDER BY RAND()
LIMIT 0,' . $input_parameters['option']['module_mumber_of_items'];
                $rsOne = $wpdb->get_results($queryString1);
                if ($rsOne && !empty($rsOne)) {
                    foreach ($rsOne as $keyOne => $valueOne) {
                        if ($valueOne) {
                            if (isset($valueOne->ID) && $valueOne->ID) {
                                $input_parameters['data']['posts_ids'][] = $valueOne->ID;
                            }
                        }
                    }
                }
            }
            $input_parameters['data']['posts_ids'] = (array) $input_parameters['data']['posts_ids'];
            $input_parameters['data']['posts_ids'] = array_unique($input_parameters['data']['posts_ids']);
            $moduleDataPlus = array();
            $moduleClassPlus = array();
            $moduleClassPlus[] = $nsModule . '_' . $input_parameters['option']['module_type'];
            $moduleClassPlus[] = $nsModule . '_' . $input_parameters['option']['module_style'];
            $moduleClassPlus[] = $input_parameters['option']['custom_class_css_of_module'];
            if (isset($input_parameters['option']['enable_thumbnails']) && $input_parameters['option']['enable_thumbnails']) {
                $moduleClassPlus[] = $nsModule . '_enable_thumbnails';
            }
            if ('flyout' === $input_parameters['option']['module_type']) {
                if (isset($input_parameters['option']['module_position']) && $input_parameters['option']['module_position']) {
                    $moduleClassPlus[] = $nsModule . '_side_' . $input_parameters['option']['module_position'];
                }
                $moduleClassPlus[] = 'wpoptxtr_shawy';
            }
            $moduleStylePlus = array();
            if ('flyout' === $input_parameters['option']['module_type']) {
                if ('style_1' === $input_parameters['option']['module_style']) {
                    if ($input_parameters['option']['maximum_width_each_item'] > 0) {
                        $valueTemp = $input_parameters['option']['maximum_width_each_item'];
                        $valueTemp = $valueTemp * 1.1;
                        $valueTemp = (int) $valueTemp;
                        $moduleStylePlus[] = 'width:' . $valueTemp . 'px;max-width:' . $valueTemp . 'px;';
                    }
                }
            }
            if (0 != $input_parameters['option']['module_margin_bottom']) {
                $valueTemp = (int) $input_parameters['option']['module_margin_bottom'];
                $moduleStylePlus[] = 'margin-bottom:' . $valueTemp . 'px;';
            }
            if (0 != $input_parameters['option']['module_margin_left']) {
                $valueTemp = (int) $input_parameters['option']['module_margin_left'];
                $moduleStylePlus[] = 'margin-left:' . $valueTemp . 'px;';
            }
            $moduleDataPlus[] = 'pepvn_data_module_appear_when_user_read_for_seconds="' . $input_parameters['option']['module_appear_when_user_read_for_seconds'] . '"';
            $moduleDataPlus[] = 'pepvn_data_module_appear_when_user_scroll_length="' . $input_parameters['option']['module_appear_when_user_scroll_length'] . '"';
            $moduleDataPlus[] = 'pepvn_data_module_position="' . $input_parameters['option']['module_position'] . '"';
            $moduleDataPlus[] = 'pepvn_data_module_id="' . $input_parameters['option']['module_id'] . '"';
            $resultData['module'] .= '
	
			<div class="wppepvn_module_traffic ' . implode(' ', $moduleClassPlus) . '" id="' . $input_parameters['option']['module_id'] . '" pepvn_data_options="' . Utils::encodeVar($input_parameters['option']) . '" style="' . implode(';', $moduleStylePlus) . '" ' . implode(' ', $moduleDataPlus) . ' >';
            if ('flyout' === $input_parameters['option']['module_type']) {
                $resultData['module'] .= '
				<span class="wppepvn_module_traffic_button_show_wrapper"></span>
				
				<span class="wppepvn_module_traffic_button_close"></span>
				';
            }
            $resultData['module'] .= '
				
				<span class="wppepvn_module_traffic_title"><strong>' . $input_parameters['option']['title_of_module'] . '</strong></span>
				
				<ul>';
            foreach ($input_parameters['data']['posts_ids'] as $keyOne => $valueOne) {
                if ($valueOne) {
                    $valueOne = (int) $valueOne;
                    if ($valueOne > 0) {
                        $rsGetPost1 = $wpExtend->getAndParsePostByPostId($valueOne);
                        if ($rsGetPost1) {
                            $rsGetPost1 = (object) $rsGetPost1;
                            if (isset($rsGetPost1->postPermalink) && $rsGetPost1->postPermalink) {
                                $thumbnailUrl1 = '';
                                if (isset($input_parameters['option']['enable_thumbnails']) && $input_parameters['option']['enable_thumbnails']) {
                                    if (isset($input_parameters['option']['default_thumbnail_url']) && $input_parameters['option']['default_thumbnail_url']) {
                                        $thumbnailUrl1 = $input_parameters['option']['default_thumbnail_url'];
                                    }
                                    if (isset($rsGetPost1->postThumbnailUrl) && $rsGetPost1->postThumbnailUrl) {
                                        $thumbnailUrl1 = $rsGetPost1->postThumbnailUrl;
                                    } else {
                                        if (isset($rsGetPost1->postImages) && $rsGetPost1->postImages && !PepVN_Data::isEmptyArray($rsGetPost1->postImages)) {
                                            $postImages1 = $rsGetPost1->postImages;
                                            shuffle($postImages1);
                                            $thumbnailUrl1 = $postImages1[0]['src'];
                                        }
                                    }
                                }
                                $thumbnailUrl1 = trim($thumbnailUrl1);
                                $itemClassPlus = array();
                                if ($thumbnailUrl1) {
                                    $itemClassPlus[] = $nsModule . '_item_has_thumbnail';
                                }
                                $resultData['module'] .= '
					<li class="wppepvn_module_traffic_item ' . implode(' ', $itemClassPlus) . '" style="';
                                if ($input_parameters['option']['maximum_width_each_item'] > 0) {
                                    $resultData['module'] .= 'width:' . $input_parameters['option']['maximum_width_each_item'] . 'px;max-width:' . $input_parameters['option']['maximum_width_each_item'] . 'px;';
                                }
                                $resultData['module'] .= '" >
					
						<a href="' . $rsGetPost1->postPermalink . '" class="wppepvn_module_traffic_item_anchor" ' . (isset($input_parameters['option']['enable_open_links_in_new_windows']) ? ' target="_blank" ' : '') . ' title="' . $rsGetPost1->post_title . '" >';
                                if ($thumbnailUrl1) {
                                    $styleImg1 = '';
                                    if ($input_parameters['option']['thumbnail_width'] > 0) {
                                        $styleImg1 .= 'width:' . $input_parameters['option']['thumbnail_width'] . 'px;max-width:' . $input_parameters['option']['thumbnail_width'] . 'px;';
                                    }
                                    if ($input_parameters['option']['thumbnail_height'] > 0) {
                                        $styleImg1 .= 'height:' . $input_parameters['option']['thumbnail_height'] . 'px;max-height:' . $input_parameters['option']['thumbnail_height'] . 'px;';
                                    }
                                    if ('style_1' === $input_parameters['option']['module_style']) {
                                        $resultData['module'] .= '
							<img class="wppepvn_module_traffic_item_img" src="' . $thumbnailUrl1 . '" style="' . $styleImg1 . '" /> ';
                                    } else {
                                        $resultData['module'] .= '
						<span class="wppepvn_module_traffic_item_img" style="' . $styleImg1 . '" >
							<img src="' . $thumbnailUrl1 . '" style="' . $styleImg1 . '" />
						</span>';
                                    }
                                }
                                $postTitle1 = $rsGetPost1->post_title;
                                $postTitle1 = Text::removeShortcode($postTitle1);
                                if ($input_parameters['option']['maximum_number_characters_items_title'] > 0) {
                                    if (PepVN_Data::mb_strlen($postTitle1) > $input_parameters['option']['maximum_number_characters_items_title']) {
                                        $postTitle1 = PepVN_Data::mb_substr($postTitle1, 0, $input_parameters['option']['maximum_number_characters_items_title']) . '...';
                                    }
                                }
                                $postExcerpt1 = $rsGetPost1->post_excerpt;
                                if (!$postExcerpt1) {
                                    $postExcerpt1 = $rsGetPost1->postContentRawText;
                                    $postExcerpt1 = PepVN_Data::mb_substr($postExcerpt1, 0, 350) . '...';
                                }
                                $postExcerpt1 = Text::removeShortcode($postExcerpt1);
                                if ($input_parameters['option']['maximum_number_characters_items_excerpt'] > 0) {
                                    if (PepVN_Data::mb_strlen($postExcerpt1) > $input_parameters['option']['maximum_number_characters_items_excerpt']) {
                                        $postExcerpt1 = PepVN_Data::mb_substr($postExcerpt1, 0, $input_parameters['option']['maximum_number_characters_items_excerpt']) . '...';
                                    }
                                }
                                if ('style_1' === $input_parameters['option']['module_style']) {
                                    if (isset($input_parameters['option']['enable_items_title']) && $input_parameters['option']['enable_items_title']) {
                                        $resultData['module'] .= '<strong class="wppepvn_module_traffic_item_title">' . $postTitle1 . '</strong>';
                                    }
                                    if (isset($input_parameters['option']['enable_items_excerpt']) && $input_parameters['option']['enable_items_excerpt']) {
                                        if ($postExcerpt1) {
                                            $resultData['module'] .= '<br /><span class="wppepvn_module_traffic_item_excerpt">' . $postExcerpt1 . '</span>';
                                        }
                                    }
                                } else {
                                    $resultData['module'] .= '
						<span class="wppepvn_module_traffic_item_text">';
                                    if (isset($input_parameters['option']['enable_items_title']) && $input_parameters['option']['enable_items_title']) {
                                        $resultData['module'] .= '
							<span class="wppepvn_module_traffic_item_title"><strong>' . $postTitle1 . '</strong></span>';
                                    }
                                    if (isset($input_parameters['option']['enable_items_excerpt']) && $input_parameters['option']['enable_items_excerpt']) {
                                        if ($postExcerpt1) {
                                            $resultData['module'] .= '
							<span class="wppepvn_module_traffic_item_excerpt">' . $postExcerpt1 . '</span>';
                                        }
                                    }
                                    $resultData['module'] .= '
						</span>';
                                }
                                $resultData['module'] .= '
						</a>
					</li>';
                            }
                        }
                    }
                }
            }
            $resultData['module'] .= '
				</ul>
			</div>';
        }
        TempDataAndCacheFile::set_cache($keyCache1, $resultData);
        return $resultData;
    }
コード例 #2
0
ファイル: WpExtend.php プロジェクト: Bushzhao/rvbwebsite
 public function parsePostData($post)
 {
     if (is_object($post)) {
         $post = (array) $post;
     }
     $post['ID'] = (int) $post['ID'];
     $keyCache1 = Utils::hashKey(array(__CLASS__, __METHOD__, $post['ID']));
     $tmp = PepVN_Data::$cacheObject->get_cache($keyCache1);
     if (null !== $tmp) {
         return $tmp;
     }
     if (!isset($post['post_excerpt']) || !$post['post_excerpt']) {
         $post['post_excerpt'] = $post['post_content'];
     }
     $post['post_excerpt'] = Text::removeShortcode($post['post_excerpt'], ' ');
     $post['post_excerpt'] = strip_tags($post['post_excerpt']);
     $post['post_excerpt'] = Text::removeLine($post['post_excerpt'], ' ');
     $post['post_excerpt'] = Text::reduceLine($post['post_excerpt'], ' ');
     $post['post_excerpt'] = explode(' ', $post['post_excerpt'], 250);
     if (isset($post['post_excerpt'][251])) {
         $post['post_excerpt'][251] = '...';
     }
     $post['post_excerpt'] = implode(' ', $post['post_excerpt']);
     $post['postPermalink'] = $this->get_permalink($post['ID']);
     $post['postImages'] = array();
     preg_match_all('#<img[^>]+src=(\'|\\")([^\'\\"]+)\\1[^>]+\\/?>#is', $post['post_content'], $matched1);
     if (isset($matched1[2]) && $matched1[2]) {
         foreach ($matched1[2] as $key1 => $value1) {
             $post['postImages'][] = array('src' => $value1);
         }
     }
     $post['postThumbnailId'] = 0;
     $post['postThumbnailUrl'] = '';
     $post_thumbnail_id = $this->get_post_thumbnail_id($post['ID']);
     if ($post_thumbnail_id) {
         $post['postThumbnailId'] = $post_thumbnail_id;
         $post_thumbnail_url = $this->wp_get_attachment_url($post_thumbnail_id);
         if ($post_thumbnail_url) {
             $post['postThumbnailUrl'] = $post_thumbnail_url;
             $post['postImages'][] = array('src' => $post_thumbnail_url);
         }
     }
     $post['postThumbnailId'] = (int) $post['postThumbnailId'];
     $post['postThumbnailUrl'] = trim($post['postThumbnailUrl']);
     $post['postAttachments'] = array();
     $attachments = get_posts(array('post_type' => 'attachment', 'posts_per_page' => -1, 'post_parent' => $post['ID']));
     if ($attachments) {
         foreach ($attachments as $key1 => $attachment) {
             unset($attachments[$key1]);
             $tmp = array('ID' => $attachment->ID, 'post_mime_type' => $attachment->post_mime_type, 'post_title' => $attachment->post_title);
             $tmp['attachment_url'] = $this->wp_get_attachment_url($attachment->ID);
             $tmp['metadata'] = wp_get_attachment_metadata($attachment->ID, true);
             $post['postAttachments'][$attachment->ID] = $tmp;
             unset($attachment, $tmp);
         }
     }
     $post['postContentRawText'] = $post['post_content'];
     $post['postContentRawText'] = strip_tags($post['postContentRawText']);
     $post['postContentRawText'] = Text::reduceLine($post['postContentRawText']);
     $post['postContentRawText'] = Text::reduceSpace($post['postContentRawText']);
     //unset($post['post_content']);
     PepVN_Data::$cacheObject->set_cache($keyCache1, $post);
     return $post;
 }