$value) { $result .= $key . "=" . urlencode($value) . "&"; } return $result; } function csyn_curl_post($url, $data, &$info) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_REFERER, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, csyn_mk_post_data($data)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); $result = trim(curl_exec($ch)); $info = curl_getinfo($ch); curl_close($ch); return $result; } function csyn_short_str($url, $max = 0) { $length = strlen($url); if ($max > 1 && $length > $max) { $ninety = $max * 0.9; $length = $length - $ninety; $first = substr($url, 0, -$length); $last = substr($url, $ninety - $max); $url = $first . "…" . $last; } return $url; } function csyn_sanitize_checkbox($value) { if ($value == 'on') { return $value; } return ''; } function csyn_REQUEST_URI() { return strtok($_SERVER['REQUEST_URI'], "?") . "?" . strtok("?"); } function csyn_fix_white_spaces($str) { return preg_replace('/\s\s+/', ' ', preg_replace('/\s\"/', ' "', preg_replace('/\s\'/', ' \'', $str))); } function csyn_delete_post_images($post_id) { $post = get_post($post_id, ARRAY_A); $wp_upload_dir = wp_upload_dir(); preg_match_all('//is', $post['post_content'] . $post['post_excerpt'], $matches); $image_urls = $matches[2]; preg_match_all('//is', $post['post_content'] . $post['post_excerpt'], $matches); foreach ($matches[2] as $scrset) { $srcset_images = explode(',', $scrset); foreach ($srcset_images as $image) { if (strpos($image, ' ') !== false) { $image = substr($image, 0, strrpos($image, ' ')); } $image_urls[] = trim($image); } } $image_urls = array_values(array_unique($image_urls)); if (count($image_urls)) { $image_urls = array_unique($image_urls); foreach ($image_urls as $url) { preg_match("/\/wp-content\/(.*?)$/", $url, $link_match); preg_match("/.*?\/wp-content\//", $wp_upload_dir['path'], $path_match); if (isset($path_match[0]) && isset($link_match[1])) { @unlink($path_match[0] . $link_match[1]); } else { @unlink(str_replace($wp_upload_dir['url'], $wp_upload_dir['path'], $url)); } } } } function csyn_addslash($url) { if ($url[strlen($url) - 1] !== "/") { $url .= "/"; } return $url; } function csyn_file_get_contents($url, $as_array = false, $useragent = '') { global $csyn_last_effective_url; if (@parse_url($url, PHP_URL_SCHEME) != "" && function_exists('curl_init')) { $max_redirects = CSYN_MAX_CURL_REDIRECTS; $ch = curl_init(); if ($useragent != '') { curl_setopt($ch, CURLOPT_USERAGENT, $useragent); } curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_REFERER, $url); curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); if (ini_get('open_basedir') == '' && (ini_get('safe_mode' == 'Off') || !ini_get('safe_mode'))) { curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_MAXREDIRS, $max_redirects); } else { $base_url = $url; curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); $rch = curl_copy_handle($ch); curl_setopt($rch, CURLOPT_HEADER, true); curl_setopt($rch, CURLOPT_NOBODY, true); curl_setopt($rch, CURLOPT_FORBID_REUSE, false); curl_setopt($rch, CURLOPT_RETURNTRANSFER, true); do { curl_setopt($rch, CURLOPT_URL, $url); curl_setopt($rch, CURLOPT_REFERER, $url); $header = curl_exec($rch); if (curl_errno($rch)) { $code = 0; } else { $code = curl_getinfo($rch, CURLINFO_HTTP_CODE); if ($code == 301 || $code == 302) { preg_match('/Location:(.*?)\n/', $header, $matches); $url = trim(array_pop($matches)); if (strlen($url) && substr($url, 0, 1) == '/') { $url = $base_url . $url; } } else { $code = 0; } } } while ($code && --$max_redirects); curl_close($rch); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_REFERER, $url); } $attempts = 0; $code = 206; while ($code == 206 && $attempts++ < CSYN_MAX_DONLOAD_ATTEMPTS) { curl_setopt($ch, CURLOPT_HEADER, false); $content = curl_exec($ch); $csyn_last_effective_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); $c_length = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD); $c_download = curl_getinfo($ch, CURLINFO_SIZE_DOWNLOAD); if ($c_length > $c_download) { $code = 206; } else { $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); } } curl_close($ch); if ($code != 200 || $c_length > $c_download) { $content = false; } elseif ($as_array) { $content = @explode("\n", trim($content)); } } if (!isset($content) || $content === false) { if ($as_array) { $content = @file($url, FILE_IGNORE_NEW_LINES); } else { $content = @file_get_contents($url); } $csyn_last_effective_url = $url; } return $content; } function csyn_update_options(&$options) { $defaults = array('interval' => 1440, 'max_items' => 1, 'post_status' => 'publish', 'comment_status' => 'open', 'ping_status' => 'closed', 'post_author' => 1, 'synonymizer_mode' => 0, 'base_date' => 'post', 'duplicate_check_method' => 'guid_and_title', 'undefined_category' => 'use_default', 'create_tags' => '', 'post_tags' => '', 'post_category' => array(), 'date_min' => 0, 'date_max' => 0, 'insert_media_attachments' => 'no', 'set_thumbnail' => 'no_thumb', 'convert_encoding' => '', 'require_thumbnail' => '', 'store_images' => '', 'post_footer' => '', 'extract_full_articles' => '', 'wpml_language' => '', 'include_post_footers' => '', 'shorten_excerpts' => '', 'embed_videos' => '', 'translator' => 'none', 'yandex_translation_dir' => '', 'yandex_api_key' => '', 'google_translation_source' => '', 'google_translation_target' => '', 'google_api_key' => ''); $result = 0; foreach ($defaults as $key => $value) { if (!isset($options[$key])) { $options[$key] = $value; $result = 1; } } return $result; } function csyn_preset_options() { $default_url = get_option(CSYN_FULL_TEXT_EXTRACTOR); if ($default_url === false || trim($default_url) == "") { if (file_exists('../fivefilters-full-text-rss/makefulltextfeed.php')) { $default_url = get_site_url() . '/fivefilters-full-text-rss/makefulltextfeed.php'; } elseif (file_exists('../wp-content/fivefilters-full-text-rss/makefulltextfeed.php')) { $default_url = get_site_url() . '/wp-content/fivefilters-full-text-rss/makefulltextfeed.php'; } elseif (file_exists('../wp-content/plugins/fivefilters-full-text-rss/makefulltextfeed.php')) { $default_url = get_site_url() . '/wp-content/plugins/fivefilters-full-text-rss/makefulltextfeed.php'; } elseif (file_exists('../wp-content/plugins/cybersyn/fivefilters-full-text-rss/makefulltextfeed.php')) { $default_url = get_site_url() . '/wp-content/plugins/cybersyn/fivefilters-full-text-rss/makefulltextfeed.php'; } update_option(CSYN_FULL_TEXT_EXTRACTOR, $default_url); } if (get_option(CSYN_ENABLE_DEBUG_MODE) === false) { update_option(CSYN_ENABLE_DEBUG_MODE, ''); } if (get_option(CSYN_SYNDICATED_FEEDS) === false) { update_option(CSYN_SYNDICATED_FEEDS, array()); } if (get_option(CSYN_CRON_MAGIC) === false) { update_option(CSYN_CRON_MAGIC, md5(time())); } if (get_option(CSYN_RSS_PULL_MODE) === false) { update_option(CSYN_RSS_PULL_MODE, 'auto'); } if (get_option(CSYN_PSEUDO_CRON_INTERVAL) === false) { update_option(CSYN_PSEUDO_CRON_INTERVAL, '10'); } if (get_option(CSYN_CANONICAL_LINK) === false) { update_option(CSYN_CANONICAL_LINK, 'auto'); } if (get_option(CSYN_LINK_TO_SOURCE) === false) { update_option(CSYN_LINK_TO_SOURCE, 'auto'); } $langs = array('az-ru' => 'Azerbaijani-Russian', 'be-bg' => 'Belarusian-Bulgarian', 'be-cs' => 'Belarusian-Czech', 'be-de' => 'Belarusian-German', 'be-en' => 'Belarusian-English', 'be-es' => 'Belarusian-Spanish', 'be-fr' => 'Belarusian-French', 'be-it' => 'Belarusian-Italian', 'be-pl' => 'Belarusian-Polish', 'be-ro' => 'Belarusian-Romanian', 'be-ru' => 'Belarusian-Russian', 'be-sr' => 'Belarusian-Serbian', 'be-tr' => 'Belarusian-Turkish', 'bg-be' => 'Bulgarian-Belarusian', 'bg-ru' => 'Bulgarian-Russian', 'bg-uk' => 'Bulgarian-Ukrainian', 'ca-en' => 'Catalan-English', 'ca-ru' => 'Catalan-Russian', 'zh-de' => 'Chinese-German', 'zh-en' => 'Chinese-English', 'zh-fr' => 'Chinese-French', 'zh-it' => 'Chinese-Italian', 'zh-ru' => 'Chinese-Russian', 'zh-es' => 'Chinese-Spanish', 'cs-be' => 'Czech-Belarusian', 'cs-en' => 'Czech-English', 'cs-ru' => 'Czech-Russian', 'cs-uk' => 'Czech-Ukrainian', 'da-en' => 'Danish-English', 'da-ru' => 'Danish-Russian', 'de-be' => 'German-Belarusian', 'de-zh' => 'German-Chinese', 'de-en' => 'German-English', 'de-es' => 'German-Spanish', 'de-fr' => 'German-French', 'de-it' => 'German-Italian', 'de-ru' => 'German-Russian', 'de-tr' => 'German-Turkish', 'de-uk' => 'German-Ukrainian', 'el-en' => 'Greek-English', 'el-ru' => 'Greek-Russian', 'en-be' => 'English-Belarusian', 'en-ca' => 'English-Catalan', 'en-zh' => 'English-Chinese', 'en-cs' => 'English-Czech', 'en-da' => 'English-Danish', 'en-de' => 'English-German', 'en-el' => 'English-Greek', 'en-es' => 'English-Spanish', 'en-et' => 'English-Estonian', 'en-fi' => 'English-Finnish', 'en-fr' => 'English-French', 'en-hu' => 'English-Hungarian', 'en-it' => 'English-Italian', 'en-lt' => 'English-Lithuanian', 'en-lv' => 'English-Latvian', 'en-mk' => 'English-Macedonian', 'en-nl' => 'English-Dutch', 'en-no' => 'English-Norwegian', 'en-pt' => 'English-Portuguese', 'en-ru' => 'English-Russian', 'en-sk' => 'English-Slovak', 'en-sl' => 'English-Slovenian', 'en-sq' => 'English-Albanian', 'en-sv' => 'English-Swedish', 'en-tr' => 'English-Turkish', 'en-uk' => 'English-Ukrainian', 'es-be' => 'Spanish-Belarusian', 'es-zh' => 'Spanish-Chinese', 'es-de' => 'Spanish-German', 'es-en' => 'Spanish-English', 'es-ru' => 'Spanish-Russian', 'es-uk' => 'Spanish-Ukrainian', 'et-en' => 'Estonian-English', 'et-ru' => 'Estonian-Russian', 'fi-en' => 'Finnish-English', 'fi-ru' => 'Finnish-Russian', 'fr-be' => 'French-Belarusian', 'fr-zh' => 'French-Chinese', 'fr-de' => 'French-German', 'fr-en' => 'French-English', 'fr-it' => 'French-Italian', 'fr-ru' => 'French-Russian', 'fr-uk' => 'French-Ukrainian', 'hr-ru' => 'Croatian-Russian', 'hu-en' => 'Hungarian-English', 'hu-ru' => 'Hungarian-Russian', 'hy-ru' => 'Armenian-Russian', 'it-be' => 'Italian-Belarusian', 'it-zh' => 'Italian-Chinese', 'it-de' => 'Italian-German', 'it-en' => 'Italian-English', 'it-fr' => 'Italian-French', 'it-ru' => 'Italian-Russian', 'it-uk' => 'Italian-Ukrainian', 'lt-en' => 'Lithuanian-English', 'lt-ru' => 'Lithuanian-Russian', 'lv-en' => 'Latvian-English', 'lv-ru' => 'Latvian-Russian', 'mk-en' => 'Macedonian-English', 'mk-ru' => 'Macedonian-Russian', 'nl-en' => 'Dutch-English', 'nl-ru' => 'Dutch-Russian', 'no-en' => 'Norwegian-English', 'no-ru' => 'Norwegian-Russian', 'pl-be' => 'Polish-Belarusian', 'pl-ru' => 'Polish-Russian', 'pl-uk' => 'Polish-Ukrainian', 'pt-en' => 'Portuguese-English', 'pt-ru' => 'Portuguese-Russian', 'ro-be' => 'Romanian-Belarusian', 'ro-ru' => 'Romanian-Russian', 'ro-uk' => 'Romanian-Ukrainian', 'ru-az' => 'Russian-Azerbaijani', 'ru-be' => 'Russian-Belarusian', 'ru-bg' => 'Russian-Bulgarian', 'ru-ca' => 'Russian-Catalan', 'ru-cs' => 'Russian-Czech', 'ru-da' => 'Russian-Danish', 'ru-de' => 'Russian-German', 'ru-el' => 'Russian-Greek', 'ru-en' => 'Russian-English', 'ru-es' => 'Russian-Spanish', 'ru-et' => 'Russian-Estonian', 'ru-fi' => 'Russian-Finnish', 'ru-fr' => 'Russian-French', 'ru-hr' => 'Russian-Croatian', 'ru-hu' => 'Russian-Hungarian', 'ru-hy' => 'Russian-Armenian', 'ru-it' => 'Russian-Italian', 'ru-lt' => 'Russian-Lithuanian', 'ru-lv' => 'Russian-Latvian', 'ru-mk' => 'Russian-Macedonian', 'ru-nl' => 'Russian-Dutch', 'ru-no' => 'Russian-Norwegian', 'ru-pl' => 'Russian-Polish', 'ru-pt' => 'Russian-Portuguese', 'ru-ro' => 'Russian-Romanian', 'ru-sk' => 'Russian-Slovak', 'ru-sl' => 'Russian-Slovenian', 'ru-sq' => 'Russian-Albanian', 'ru-sr' => 'Russian-Serbian', 'ru-sv' => 'Russian-Swedish', 'ru-tr' => 'Russian-Turkish', 'ru-uk' => 'Russian-Ukrainian', 'sk-en' => 'Slovak-English', 'sk-ru' => 'Slovak-Russian', 'sl-en' => 'Slovenian-English', 'sl-ru' => 'Slovenian-Russian', 'sq-en' => 'Albanian-English', 'sq-ru' => 'Albanian-Russian', 'sr-be' => 'Serbian-Belarusian', 'sr-ru' => 'Serbian-Russian', 'sr-uk' => 'Serbian-Ukrainian', 'sv-en' => 'Swedish-English', 'sv-ru' => 'Swedish-Russian', 'tr-be' => 'Turkish-Belarusian', 'tr-de' => 'Turkish-German', 'tr-en' => 'Turkish-English', 'tr-ru' => 'Turkish-Russian', 'tr-uk' => 'Turkish-Ukrainian', 'uk-bg' => 'Ukrainian-Bulgarian', 'uk-cs' => 'Ukrainian-Czech', 'uk-de' => 'Ukrainian-German', 'uk-en' => 'Ukrainian-English', 'uk-es' => 'Ukrainian-Spanish', 'uk-fr' => 'Ukrainian-French', 'uk-it' => 'Ukrainian-Italian', 'uk-pl' => 'Ukrainian-Polish', 'uk-ro' => 'Ukrainian-Romanian', 'uk-ru' => 'Ukrainian-Russian', 'uk-sr' => 'Ukrainian-Serbian', 'uk-tr' => 'Ukrainian-Turkish'); update_option(CSYN_YANDEX_TRANSLATE_LANGS, $langs); $langs = array('af' => 'Afrikaans', 'sq' => 'Albanian', 'ar' => 'Arabic', 'az' => 'Azerbaijani', 'eu' => 'Basque', 'be' => 'Belarusian', 'bn' => 'Bengali', 'bg' => 'Bulgarian', 'ca' => 'Catalan', 'zh-CN' => 'Chinese Simplified', 'zh-TW' => 'Chinese Traditional', 'hr' => 'Croatian', 'cs' => 'Czech', 'da' => 'Danish', 'nl' => 'Dutch', 'en' => 'English', 'eo' => 'Esperanto', 'et' => 'Estonian', 'tl' => 'Filipino', 'fi' => 'Finnish', 'fr' => 'French', 'gl' => 'Galician', 'ka' => 'Georgian', 'de' => 'German', 'el' => 'Greek', 'gu' => 'Gujarati', 'ht' => 'Haitian Creole', 'iw' => 'Hebrew', 'hi' => 'Hindi', 'hu' => 'Hungarian', 'is' => 'Icelandic', 'id' => 'Indonesian', 'ga' => 'Irish', 'it' => 'Italian', 'ja' => 'Japanese', 'kn' => 'Kannada', 'ko' => 'Korean', 'la' => 'Latin', 'lv' => 'Latvian', 'lt' => 'Lithuanian', 'mk' => 'Macedonian', 'ms' => 'Malay', 'mt' => 'Maltese', 'no' => 'Norwegian', 'fa' => 'Persian', 'pl' => 'Polish', 'pt' => 'Portuguese', 'ro' => 'Romanian', 'ru' => 'Russian', 'sr' => 'Serbian', 'sk' => 'Slovak', 'sl' => 'Slovenian', 'es' => 'Spanish', 'sw' => 'Swahili', 'sv' => 'Swedish', 'ta' => 'Tamil', 'te' => 'Telugu', 'th' => 'Thai', 'tr' => 'Turkish', 'uk' => 'Ukrainian', 'ur' => 'Urdu', 'vi' => 'Vietnamese', 'cy' => 'Welsh', 'yi' => 'Yiddish'); update_option(CSYN_GOOGLE_TRANSLATE_LANGS, $langs); } function csyn_get_yandex_translate_lang_list($apikey) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://translate.yandex.net/api/v1.5/tr.json/getLangs'); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, 'key=' . $apikey . '&ui=en'); $json = json_decode(curl_exec($ch), true); curl_close($ch); if (isset($json['dirs']) && isset($json['langs'])) { $langs = array(); foreach ($json['dirs'] as $dir) { list($from, $to) = explode('-', $dir); $langs[$dir] = $json['langs'][$from] . '-' . $json['langs'][$to]; } return $langs; } else { return false; } } function csyn_yandex_translate($apikey, $text, $dir, $return_emty = false) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://translate.yandex.net/api/v1.5/tr.json/translate'); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, 'key=' . $apikey . '&lang=' . $dir . '&format=html&text=' . urlencode($text)); $json = json_decode(curl_exec($ch), true); curl_close($ch); if ($json['code'] == 200) { return $json['text'][0]; } else { if ($return_emty) { return ''; } else { return $text; } } } function csyn_google_translate($apikey, $text, $source, $target, $return_emty = false) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://translation.googleapis.com/language/translate/v2'); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, 'key=' . $apikey . '&source=' . $source . '&target=' . $target . '&q=' . urlencode($text)); $json = json_decode(curl_exec($ch), true); curl_close($ch); if ($json['data']['translations']['0']['translatedText']) { return $json['data']['translations']['0']['translatedText']; } else { if ($return_emty) { return ''; } else { return $text; } } } function csyn_compare_files($file_name_1, $file_name_2) { $file1 = csyn_file_get_contents($file_name_1); $file2 = csyn_file_get_contents($file_name_2); if ($file1 && $file2) { return (md5($file1) == md5($file2)); } return false; } function csyn_save_image($image_url, $preferred_name = '', $width = 0, $height = 0, $compression = 0) { $wp_upload_dir = wp_upload_dir(); $temp_name = wp_unique_filename($wp_upload_dir['path'], md5(time()) . '.tmp'); $image_url = trim($image_url); if (strpos($image_url, '//') === 0) { $image_url = 'http:' . $image_url; } if (is_writable($wp_upload_dir['path']) && function_exists("gd_info") && function_exists("getimagesize") && function_exists("image_type_to_extension")) { $image_file = csyn_file_get_contents($image_url); file_put_contents($wp_upload_dir['path'] . '/' . $temp_name, $image_file); $image_info = @getimagesize($wp_upload_dir['path'] . '/' . $temp_name); if ($image_info !== false) { $image_type = $image_info[2]; $ext = str_replace("jpeg", "jpg", image_type_to_extension($image_type, true)); if ($image_type == IMAGETYPE_JPEG) { $image = imagecreatefromjpeg($wp_upload_dir['path'] . '/' . $temp_name); } elseif ($image_type == IMAGETYPE_GIF) { $image = imagecreatefromgif($wp_upload_dir['path'] . '/' . $temp_name); } elseif ($image_type == IMAGETYPE_PNG) { $image = imagecreatefrompng($wp_upload_dir['path'] . '/' . $temp_name); } elseif ($image_type == IMAGETYPE_BMP) { $image = imagecreatefromwbmp($wp_upload_dir['path'] . '/' . $temp_name); } $doscale = (intval($width) != 0 || intval($height) != 0 || intval($compression) != 0); $default_file_name = sanitize_file_name(sanitize_title($preferred_name) . $ext); if ($preferred_name != "" && strpos($default_file_name, "%") === false) { $file_name = $default_file_name; } else { $file_name = basename($image_url); } if (file_exists($wp_upload_dir['path'] . '/' . $file_name)) { if (!$doscale && csyn_compare_files($wp_upload_dir['path'] . '/' . $temp_name, $wp_upload_dir['path'] . '/' . $file_name)) { imagedestroy($image); unlink($wp_upload_dir['path'] . '/' . $temp_name); return $wp_upload_dir['url'] . '/' . $file_name; } $file_name = wp_unique_filename($wp_upload_dir['path'], $file_name); } $image_path = $wp_upload_dir['path'] . '/' . $file_name; $local_image_url = $wp_upload_dir['url'] . '/' . $file_name; if ($doscale) { $img_width = imagesx($image); $img_height = imagesy($image); if ($width[strlen($width) - 1] == "%") { $width = $img_width * intval($width) / 100; } else { $width = intval($width); } if ($height[strlen($height) - 1] == "%") { $height = $img_height * intval($height) / 100; } else { $height = intval($height); } if ($width == 0) { $height = $img_height; $width = $img_width * ($height / $img_height); } if ($height == 0) { $width = $img_width; $height = $img_height * ($width / $img_width); } if ($compression == 0) { $compression = 95; } $new_image = imagecreatetruecolor($width, $height); imagecopyresampled($new_image, $image, 0, 0, 0, 0, $width, $height, $img_width, $img_height); imagedestroy($image); unlink($wp_upload_dir['path'] . '/' . $temp_name); switch ($image_type) { case IMAGETYPE_JPEG: $result = imagejpeg($new_image, $image_path, intval($compression)); break; case IMAGETYPE_GIF: $result = imagegif($new_image, $image_path); break; case IMAGETYPE_PNG: $result = imagepng($new_image, $image_path); break; case IMAGETYPE_BMP: $result = imagewbmp($new_image, $image_path); break; default: $result = false; } imagedestroy($new_image); if ($result) { $default_image_path = $wp_upload_dir['path'] . '/' . $default_file_name; if ($default_file_name != $file_name) { if (csyn_compare_files($default_image_path, $image_path)) { if (@unlink($image_path)) { $local_image_url = $wp_upload_dir['url'] . '/' . $default_file_name; } } } return $local_image_url; } } else { imagedestroy($image); if (@rename($wp_upload_dir['path'] . '/' . $temp_name, $image_path)) { return $local_image_url; } } } @unlink($wp_upload_dir['path'] . '/' . $temp_name); } return $image_url; } function csyn_add_image_to_library($image_url, $title, $post_id) { $title = trim($title); $upload_dir = wp_upload_dir(); if (!file_exists($upload_dir['path'] . '/' . basename($image_url))) { $image_url = csyn_save_image($image_url, $title); } $img_path = str_replace($upload_dir['url'], $upload_dir['path'], $image_url); if (file_exists($img_path) && filesize($img_path)) { $wp_filetype = wp_check_filetype($upload_dir['path'] . basename($image_url), null); $attachment = array( 'post_mime_type' => $wp_filetype['type'], 'post_title' => preg_replace('/\.[^.]+$/', '', $title), 'post_content' => '', 'post_parent' => $post_id, 'guid' => $upload_dir['path'] . basename($image_url), 'post_status' => 'inherit' ); $attach_id = wp_insert_attachment($attachment, $upload_dir['path'] . '/' . basename($image_url), $post_id); require_once(ABSPATH . 'wp-admin/includes/image.php'); $attach_data = wp_generate_attachment_metadata($attach_id, $upload_dir['path'] . '/' . basename($image_url)); wp_update_attachment_metadata($attach_id, $attach_data); return $attach_id; } return false; } function csyn_attach_post_thumbnail($post_id, $image_url, $title) { $attach_id = csyn_add_image_to_library($image_url, $title, $post_id); if ($attach_id !== false) { set_post_thumbnail($post_id, $attach_id); return $attach_id; } return false; } class CyberSyn_Syndicator { var $post = array(); var $insideitem; var $element_tag; var $tag; var $count; var $failure; var $posts_found; var $max; var $current_feed = array(); var $current_feed_url = ""; var $feeds = array(); var $update_period; var $feed_title; var $blog_charset; var $feed_charset; var $feed_charset_convert; var $preview; var $global_options = array(); var $edit_existing; var $current_category; var $current_custom_field; var $current_custom_field_attr = array(); var $generator; var $xml_parse_error; var $show_report = false; function fixURL($url) { $url = trim($url); if (strlen($url) > 0 && !preg_match('!^https?://.+!i', $url)) { $url = "http://" . $url; } return $url; } function resetPost() { global $csyn_urls_to_check; $this->post['post_title'] = ""; $this->post['post_content'] = ""; $this->post['post_excerpt'] = ""; $this->post['media_description'] = ""; $this->post['guid'] = ""; $this->post['post_date'] = time(); $this->post['post_date_gmt'] = time(); $this->post['post_name'] = ""; $this->post['categories'] = array(); $this->post['comments'] = array(); $this->post['media_content'] = array(); $this->post['media_thumbnail'] = array(); $this->post['enclosure_url'] = ""; $this->post['link'] = ""; $this->post['options'] = array(); $csyn_urls_to_check = array(); } function __construct() { $this->blog_charset = strtoupper(get_option('blog_charset')); $this->global_options = get_option(CSYN_FEED_OPTIONS); if (csyn_update_options($this->global_options)) { update_option(CSYN_FEED_OPTIONS, $this->global_options); } $this->feeds = get_option(CSYN_SYNDICATED_FEEDS); $changed = 0; for ($i = 0; $i < count($this->feeds); $i++) { $changed += csyn_update_options($this->feeds[$i]['options']); } if ($changed) { update_option(CSYN_SYNDICATED_FEEDS, $this->feeds); } } function parse_w3cdtf($w3cdate) { if (preg_match("/^\s*(\d{4})(-(\d{2})(-(\d{2})(T(\d{2}):(\d{2})(:(\d{2})(\.\d+)?)?(?:([-+])(\d{2}):?(\d{2})|(Z))?)?)?)?\s*\$/", $w3cdate, $match)) { list($year, $month, $day, $hours, $minutes, $seconds) = array($match[1], $match[3], $match[5], $match[7], $match[8], $match[10]); if (is_null($month)) { $month = (int) gmdate('m'); } if (is_null($day)) { $day = (int) gmdate('d'); } if (is_null($hours)) { $hours = (int) gmdate('H'); $seconds = $minutes = 0; } $epoch = gmmktime($hours, $minutes, $seconds, $month, $day, $year); if ($match[14] != 'Z') { list($tz_mod, $tz_hour, $tz_min) = array($match[12], $match[13], $match[14]); $tz_hour = (int) $tz_hour; $tz_min = (int) $tz_min; $offset_secs = (($tz_hour * 60) + $tz_min) * 60; if ($tz_mod == "+") { $offset_secs *= - 1; } $offset = $offset_secs; } $epoch = $epoch + $offset; return $epoch; } else { return -1; } } function parseFeed($feed_url) { $this->tag = ""; $this->insideitem = false; $this->element_tag = ""; $this->feed_title = ""; $this->generator = ""; $this->current_feed_url = $feed_url; $this->feed_charset_convert = ""; $this->posts_found = 0; $this->failure = false; if ($this->preview) { $options = $this->global_options; } else { $options = $this->current_feed['options']; } $feed_url = $this->current_feed_url; $rss_lines = csyn_file_get_contents($feed_url, true, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5'); if (!is_array($rss_lines) || stripos($rss_lines[0], ' 0) { preg_match("/encoding[. ]?=[. ]?[\"'](.*?)[\"']/i", $rss_lines[0], $matches); if (isset($matches[1]) && $matches[1] != "") { $this->feed_charset = trim($matches[1]); } else { $this->feed_charset = "not defined"; } $xml_parser = xml_parser_create(); xml_parser_set_option($xml_parser, XML_OPTION_TARGET_ENCODING, $this->blog_charset); xml_set_object($xml_parser, $this); xml_set_element_handler($xml_parser, "startElement", "endElement"); xml_set_character_data_handler($xml_parser, "charData"); $do_mb_convert_encoding = ($options['convert_encoding'] == 'on' && $this->feed_charset != "not defined" && $this->blog_charset != strtoupper($this->feed_charset)); $this->xml_parse_error = 0; foreach ($rss_lines as $line) { if ($this->count >= $this->max || $this->failure) { break; } if ($do_mb_convert_encoding && function_exists("mb_convert_encoding")) { $line = mb_convert_encoding($line, $this->blog_charset, $this->feed_charset); } if (!xml_parse($xml_parser, $line . "\n")) { $this->xml_parse_error = xml_get_error_code($xml_parser); xml_parser_free($xml_parser); return false; } } xml_parser_free($xml_parser); return $this->count; } else { return false; } } function syndicateFeeds($feed_ids, $check_time) { $this->preview = false; $feeds_cnt = count($this->feeds); if (is_array($feed_ids) && count($feed_ids) > 0) { if ($this->show_report) { ob_end_flush(); ob_implicit_flush(); echo "
\n";
flush();
}
@set_time_limit(60 * 60);
for ($i = 0; $i < $feeds_cnt; $i++) {
if (in_array($i, $feed_ids) && !is_object($this->feeds[$i]['updated'])) {
if (!$check_time || $this->getUpdateTime($this->feeds[$i]) == "asap") {
$this->feeds[$i]['updated'] = time();
update_option(CSYN_SYNDICATED_FEEDS, $this->feeds);
$this->current_feed = $this->feeds[$i];
$this->resetPost();
$this->max = (int) $this->current_feed['options']['max_items'];
if ($this->show_report) {
echo 'Syndicating ' . $this->current_feed['title'] . "...\n";
flush();
}
if ($this->current_feed['options']['undefined_category'] == 'use_global') {
$this->current_feed['options']['undefined_category'] = $this->global_options['undefined_category'];
}
$this->count = 0;
$result = $this->parseFeed($this->current_feed['url']);
if ($this->show_report) {
if ($this->count == 1) {
echo $this->count . " post was added";
} else {
echo $this->count . " posts were added";
}
if ($result === false) {
echo " [!]";
}
echo "
\n";
flush();
}
}
}
}
if (isset($save_options)) {
update_option(CSYN_SYNDICATED_FEEDS, $this->feeds);
}
if ($this->show_report) {
echo "
Feed Title: ' . $this->feed_title . '
';
echo 'URL: ' . htmlspecialchars($this->current_feed_url) . '
';
if (mb_strlen(trim($this->post['post_content'])) == 0) {
$this->post['post_content'] = $this->post['post_excerpt'];
}
echo '
This feed is already in use.
Feed Info and Preview |
---|
resetPost();
$this->count = 0;
$result = $this->parseFeed($feed_url);
if (!$result) {
if (!is_object($feed_url)) {
echo ' No feed found at ' . htmlspecialchars($feed_url) . ' Parse errror. '; } } ?> |
\n"; echo "Deleting. Please wait..."; flush(); if ($delete_posts) { $to_delete = "("; $cnt = count($feed_ids); for ($i = 0; $i < $cnt; $i++) { $to_delete .= "'" . $this->feeds[$feed_ids[$i]]['url'] . "', "; } $to_delete .= ")"; $to_delete = str_replace(", )", ")", $to_delete); $post_ids = $wpdb->get_col("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'cyberseo_rss_source' AND meta_value IN {$to_delete}"); if (count($post_ids) > 0) { foreach ($post_ids as $post_id) { @wp_delete_post($post_id, true); echo(str_repeat(' ', 512)); flush(); } } } if ($defele_feeds) { $feeds = array(); $feeds_cnt = count($this->feeds); for ($i = 0; $i < $feeds_cnt; $i++) { if (!in_array($i, $feed_ids)) { $feeds[] = $this->feeds[$i]; } } $this->feeds = $feeds; sort($this->feeds); } update_option(CSYN_SYNDICATED_FEEDS, $this->feeds); echo " Done!
,');
} elseif (strpos($this->post['link'], 'flickr.com/') !== false) {
$post['post_excerpt'] = $post['post_content'] = $this->post['link'] . "\n ,');
} elseif (strpos($this->post['link'], 'ign.com/') !== false) {
$post['post_excerpt'] = $post['post_content'] = $this->post['post_excerpt'];
$this->current_feed['options']['insert_media_attachments'] = 'top';
} elseif (strpos($this->post['link'], 'dailymotion.com/') !== false) {
$post['post_excerpt'] = $post['post_content'] = $this->post['link'] . "\n ,');
} elseif (strpos($this->post['guid'], 'ustream.tv/') !== false) {
$post['post_excerpt'] = $post['post_content'] = '' . "\n ,');
}
}
$attachment = '';
if ($this->current_feed['options']['insert_media_attachments'] != 'no') {
$attachment = '';
$video_extensions = wp_get_video_extensions();
if ($this->post['enclosure_url'] != '') {
$ext = mb_strtolower(pathinfo($this->post['enclosure_url'], PATHINFO_EXTENSION));
if (in_array($ext, $video_extensions)) {
$attachment .= '[video src="' . $this->post['enclosure_url'] . '"';
if (isset($this->post['media_thumbnail'][0])) {
if ($this->current_feed['options']['store_images'] == 'on') {
$this->post['media_thumbnail'][0] = csyn_save_image($this->post['media_thumbnail'][0], $this->post['post_title']);
}
$attachment .= ' poster="' . $this->post['media_thumbnail'][0] . '"';
}
$attachment .= ']';
} else {
if ($this->current_feed['options']['store_images'] == 'on') {
$this->post['enclosure_url'] = csyn_save_image($this->post['enclosure_url'], $this->post['post_title']);
}
$attachment .= '';
}
} else {
if (sizeof($this->post['media_content'])) {
$attachment .= ' ' . $title . '
" . strip_tags($this->post['post_content'], '
,,
" . strip_tags($this->post['post_excerpt'], '
,,
" . strip_tags($this->post['post_excerpt'], '
,,
Error: " . $post_id->get_error_message($post_id->get_error_code()) . "
\n";
} else {
if ($this->current_feed['options']['set_thumbnail'] != 'no_thumb') {
if (isset($image_url)) {
$attach_id = csyn_attach_post_thumbnail($post_id, $image_url, $this->post['post_title']);
}
if (($this->current_feed['options']['require_thumbnail'] == 'on') && (!has_post_thumbnail($post_id) || (isset($attach_id) && $attach_id === false))) {
@wp_delete_post($post_id, true);
return;
}
}
$this->count++;
$this->failure = false;
add_post_meta($post_id, 'cyberseo_rss_source', $this->current_feed['url']);
add_post_meta($post_id, 'cyberseo_post_link', $this->post['link']);
}
}
}
}
function getCategoryIds($category_names) {
global $wpdb;
$cat_ids = array();
foreach ($category_names as $cat_name) {
if (function_exists('term_exists')) {
$cat_id = term_exists($cat_name, 'category');
if ($cat_id) {
$cat_ids[] = $cat_id['term_id'];
} elseif ($this->current_feed['options']['undefined_category'] == 'create_new') {
$term = wp_insert_term($cat_name, 'category');
$cat_ids[] = $term['term_id'];
}
} else {
$cat_name_escaped = addslashes($cat_name);
$results = $wpdb->get_results("SELECT cat_ID FROM $wpdb->categories WHERE (LOWER(cat_name) = LOWER('$cat_name_escaped'))");
if ($results) {
foreach ($results as $term) {
$cat_ids[] = (int) $term->cat_ID;
}
} elseif ($this->current_feed['options']['undefined_category'] == 'create_new') {
if (function_exists('wp_insert_category')) {
$cat_id = wp_insert_category(array('cat_name' => $cat_name));
} else {
$cat_name_sanitized = sanitize_title($cat_name);
$wpdb->query("INSERT INTO $wpdb->categories SET cat_name='$cat_name_escaped', category_nicename='$cat_name_sanitized'");
$cat_id = $wpdb->insert_id;
}
$cat_ids[] = $cat_id;
}
}
}
if ((count($cat_ids) != 0)) {
$cat_ids = array_unique($cat_ids);
}
return $cat_ids;
}
function categoryChecklist($post_id = 0, $descendents_and_self = 0, $selected_cats = false) {
wp_category_checklist($post_id, $descendents_and_self, $selected_cats);
}
function categoryListBox($checked, $title) {
echo '' . "\n";
echo '
' . "\n";
echo '' . "\n";
$this->categoryChecklist(NULL, false, $checked);
echo '
' . "\n";
echo '
' . "\n";
echo '