(.*?)<\/div>/', $itemTxt, $matches);
//if not empty, set item link description to the extracted link description
if(! empty($matches[1][0]))
$item['item_link_description'] = $matches[1][0];
//if item link description is not empty, wrap it in
tags and append it to the item description
if ( ! empty($item['item_link_description']) ) {
$item['item_description'] .= '
' . $item['item_link_description'] . '
';
}
//match the link image using REGEX
preg_match_all('/
Link:' . $item_link;
// No image skip
if (wp_automatic_trim($item['item_img']) == '' && in_array('OPT_TE_IMG', $camp_opt)) {
echo '<- No image skip';
continue;
}
// Filter type
if (in_array('OPT_TE_POST_FILTER', $camp_opt)) {
$item_type = $item['item_type'];
//uppercase item_type and append OPT_TE_POST_ then set this as search for opt
$opt = 'OPT_TE_POST_' . strtoupper($item_type);
//if opt is not in camp_opt skip
if (!in_array($opt, $camp_opt)) {
//echo skipped and show current item type which is not selected
echo '<- Skipped (' . $item_type . ')';
continue;
}
}
if ($this->is_execluded($camp->camp_id, $item_link)) {
echo '<-- Execluded';
continue;
}
if (!$this->is_duplicate($item_link)) {
$query = "INSERT INTO {$this->wp_prefix}automatic_general ( item_id , item_status , item_data ,item_type) values ( '$id', '0', '$data' ,'te_{$camp->camp_id}_$keyword') ";
$this->db->query($query);
} else {
echo ' <- duplicated
#' . $this->duplicate_id . '';
}
}
echo '';
}
/*
* ---* telegram fetch post ---
*/
public function telegram_get_post($camp)
{
// Campaign options and general fields from db
$camp_opt = $this->camp_opt;
$camp_general = $this->camp_general;
//mocking a keyword
$keywords = array(
'*',
);
foreach ($keywords as $keyword) {
$keyword = wp_automatic_trim($keyword);
// update last keyword
update_post_meta($camp->camp_id, 'last_keyword', wp_automatic_trim($keyword));
if (wp_automatic_trim($keyword) != '') {
// report posting for cg_te_page
$cg_te_page = wp_automatic_trim($camp_general['cg_te_page']);
echo '
Posting from Telegram page:' . $cg_te_page;
// getting links from the db for that keyword
$query = "select * from {$this->wp_prefix}automatic_general where item_type= 'te_{$camp->camp_id}_$keyword' ";
$this->used_keyword = $keyword;
$res = $this->db->get_results($query);
// when no links lets get new links
if (count($res) == 0) {
// clean any old cache for this keyword
$query_delete = "delete from {$this->wp_prefix}automatic_general where item_type='te_{$camp->camp_id}_$keyword' ";
$this->db->query($query_delete);
// get new fresh items
$this->telegram_fetch_items($keyword, $camp);
// getting links from the db for that keyword
$res = $this->db->get_results($query);
}
// check if already duplicated
// deleting duplicated items
$res_count = count($res);
for ($i = 0; $i < $res_count; $i++) {
$t_row = $res[$i];
$t_data = unserialize(base64_decode($t_row->item_data));
$t_link_url = $t_data['item_url'];
if ($this->is_duplicate($t_link_url)) {
// duplicated item let's delete
unset($res[$i]);
echo '
Telegram item (' . $t_data['item_title'] . ') found cached but duplicated
#' . $this->duplicate_id . '';
// delete the item
$query = "delete from {$this->wp_prefix}automatic_general where id='{$t_row->id}' ";
$this->db->query($query);
} else {
break;
}
}
// check again if valid links found for that keyword otherwise skip it
if (count($res) > 0) {
// lets process that link
$ret = $res[$i];
$data = unserialize(base64_decode($ret->item_data));
$temp = $data;
echo '
Found Link:' . $temp['item_link'];
// Item img html
if (isset($temp['item_gallery_imgs']) && in_array('OPT_RD_SLIDER', $camp_opt)) {
echo '
Slider images exist...';
// template for img html
$cg_rd_full_img_t = $camp_general['cg_rd_full_img_t'];
if (wp_automatic_trim($cg_rd_full_img_t) == '') {
$cg_rd_full_img_t = '

';
}
// build the html
$item_gallery_imgs = explode(',', $temp['item_gallery_imgs']);
$gallery_html = '';
foreach ($item_gallery_imgs as $single_img_src) {
$gallery_html .= wp_automatic_str_replace('[img_src]', $single_img_src, $cg_rd_full_img_t);
}
$temp['item_img_html'] = $gallery_html;
} elseif (wp_automatic_trim($temp['item_img']) != '') {
$temp['item_img_html'] = '

';
} else {
$temp['item_img_html'] = '';
}
//item_title auto generation
if (in_array('OPT_IT_AUTO_TITLE', $camp_opt)) {
echo '
No title generating...';
$cg_it_title_count = $camp_general['cg_it_title_count'];
if (!is_numeric($cg_it_title_count)) {
$cg_it_title_count = 80;
}
// Clean content from tags , emoji and more
$contentClean = $this->removeEmoji(strip_tags(strip_shortcodes(($temp['item_description']))));
// remove hashtags
if (in_array('OPT_TT_NO_TTL_TAG', $camp_opt)) {
$contentClean = preg_replace('{#\S*}', '', $contentClean);
}
// remove mentions
if (in_array('OPT_TT_NO_TTL_MEN', $camp_opt)) {
$contentClean = preg_replace('{@\S*}', '', $contentClean);
}
if (function_exists('mb_substr')) {
$newTitle = (mb_substr($contentClean, 0, $cg_it_title_count));
} else {
$newTitle = (substr($contentClean, 0, $cg_it_title_count));
}
$temp['item_title'] = in_array('OPT_GENERATE_TW_DOT', $camp_opt) ? ($newTitle) : ($newTitle) . '...';
} else {
$temp['item_title'] = '(notitle)';
}
// Yt embed
if (!isset($temp['item_embed'])) {
$temp['item_embed'] = '';
}
if (stristr($temp['item_url'], 'youtu.be') || stristr($temp['item_url'], 'youtube.com')) {
$temp['item_embed'] = '[embed]' . $temp['item_url'] . '[/embed]';
}
// Gif embed
/*
$temp ['item_gif_embed'] = '';
if (wp_automatic_trim( $temp ['item_gif'] ) != '') {
$temp ['item_embed'] = $temp ['item_gif_embed'] = '

';
}
*/
//if item type is video or the item_embed_url is set and
if (wp_automatic_trim($temp['item_type']) == 'video' || isset($temp['item_embed_url'])) {
//if item_embed_url is set, set the target video url to item_embed_url, otherwise set it to item_link
$target_video_url = isset($temp['item_embed_url']) ? $temp['item_embed_url'] : $temp['item_link'];
//remove https://t.me/ from the beginning of the item_link as a short_link
$short_link = wp_automatic_str_replace('https://t.me/', '', $target_video_url);
$temp['item_embed'] = '';
//if item_video_link contains youtube or youtu.be, set item_embed to youtube embed
if (stristr($temp['item_video_link'], 'youtube') || stristr($temp['item_video_link'], 'youtu.be')) {
$temp['item_embed'] = '[embed]' . $temp['item_video_link'] . '[/embed]';
}
// official embed
/*
if (in_array ( 'OPT_RD_OFFICIAL_EMBED', $camp_opt )) {
$temp ['item_embed'] = '[embed]https://reddit.com' . $temp ['item_link'] . '[/embed]';
}
*/
}
// update the link status to 1
$query = "delete from {$this->wp_prefix}automatic_general where id={$ret->id}";
$this->db->query($query);
// if cache not active let's delete the cached videos and reset indexes
if (!in_array('OPT_IT_CACHE', $camp_opt)) {
echo '
Cache disabled claring cache ...';
$query = "delete from {$this->wp_prefix}automatic_general where item_type='te_{$camp->camp_id}_$keyword' ";
$this->db->query($query);
// reset index
$query = "update {$this->wp_prefix}automatic_keywords set keyword_start =1 where keyword_camp={$camp->camp_id}";
$this->db->query($query);
}
return $temp;
} else {
echo '
No links found for this keyword';
}
} // if trim
} // foreach keyword
}
}