get_items(0, 3) as $item) { $item_tmp = array(); $item_tmp['url'] = esc_url_raw($item->get_link()); $title = sanitize_text_field($item->get_title()); if (empty($title)) { $title = __('Untitled'); } $item_tmp['title'] = $title; $desc = str_replace(array("\n", "\r"), ' ', sanitize_post($item->get_description())); $desc = wp_html_excerpt($desc, 360); if (strstr($desc, 'Continue reading →')) { $desc = str_replace('Continue reading →', 'Continue reading →', $desc); } $item_tmp['desc'] = $desc; $date = $item->get_date(); $diff = ''; if ($date) { $diff = human_time_diff(strtotime($date, time())); $date_stamp = strtotime($date); if ($date_stamp) { $date = '' . date_i18n(get_option('date_format'), $date_stamp) . ''; } else { $date = ''; } } $item_tmp['date'] = $date; $item_tmp['diff'] = $diff; $result[] = $item_tmp; } } $output = ''; if (count($result) > 0) { $output .= '
'; //$output .= '

' . __('ASA News', 'asa1') . '

'; $output .= ''; } $output .= '
'; return $output; } } if (!function_exists('asa_debug')) { /** * @param $var * @param bool $backtrace * @param bool $verbose * @return void */ function asa_debug($var, $backtrace = false, $verbose = true) { if (WP_DEBUG === true) { $bt = debug_backtrace(); $pathinfo = pathinfo($bt[0]['file']); $output = ''; if ($verbose) { $output .= date('Y-m-d H:i:s') . ' ' . __FUNCTION__ . ' in '; $output .= $pathinfo['dirname'] . DIRECTORY_SEPARATOR . $pathinfo['basename'] . ':' . $bt[0]['line'] . ':' . ' ('. gettype($var) . ') '; } if (is_array($var) || is_object($var)) { $output .= print_r($var, true); } elseif (is_bool($var)) { $output .= var_export($var, true); } else { $output .= $var; } //error_log($output); $output .= PHP_EOL; file_put_contents(WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'debug.log', $output, FILE_APPEND); if ($backtrace) { $backtrace = array_reverse(debug_backtrace()); $backtrace_output = ''; $counter = 0; foreach ($backtrace as $row) { if ((count($backtrace)-1) == $counter) { break; } $file = (isset($row['file'])) ? $row['file'] : ''; $line = (isset($row['line'])) ? $row['line'] : ''; $class = (isset($row['class'])) ? $row['class'] : ''; $function = (isset($row['function'])) ? $row['function'] : ''; $backtrace_output .= $counter .': '. $file .':'. $line . ', class: '. $class .', function: '. $function . PHP_EOL; $counter++; } error_log(__FUNCTION__ . ' backtrace:' . PHP_EOL . $backtrace_output); } } } } if (!function_exists('asa_compress_css')) { /** * @param $css * @return mixed */ function asa_compress_css($css) { // Remove comments $css = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $css); // Remove space after colons $css = str_replace(': ', ':', $css); // Remove whitespace $css = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $css); return $css; } } if (!function_exists('asa_compress_html')) { /** * @param $html * @return mixed */ function asa_compress_html($html) { // Remove whitespace $html = asa_remove_comments($html); $html = asa_strip_script($html); $search = array( '/\>[^\S ]+/s', // strip whitespaces after tags, except space '/[^\S ]+\/' // Remove HTML comments ); $replace = array( '>', '<', '\\1', '' ); $html = preg_replace($search, $replace, $html); $html = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $html); return $html; } } if (!function_exists('asa_remove_comments')) { /** * @param $html * @return mixed */ function asa_remove_comments($html) { return preg_replace('//', '', $html); } } if (!function_exists('asa_strip_script')) { /** * @param $html * @return mixed */ function asa_strip_script($html) { do { if (isset($result)) { $html = $result; } $result = preg_replace('/]*>(.*?)<\/script>/is', "", $html); } while ($result != $html); return $result; } } if (!function_exists('asa_sanitize_shortcode_option_value')) { /** * @param $value * @return mixed */ function asa_sanitize_shortcode_option_value($value) { $value = str_replace( array(','), array(''), $value ); $value = trim($value); return $value; } } if (!function_exists('asa_is_pa_api_5')) { /** * @return bool */ function asa_is_pa_api_5() { return true; } } if (!function_exists('asa_should_use_creators_api')) { /** * Check if Creators API should be used instead of PA API * * Conditions: * 1. PHP version >= 8.1 * 2. No GuzzleHttp conflict (ASA2 not active) * 3. Creators API is enabled * 4. Valid credentials are configured * * @return bool */ function asa_should_use_creators_api() { // Quick PHP version check first (avoid loading class if not needed) if (version_compare(PHP_VERSION, '8.1.0', '<')) { return false; } // Check for GuzzleHttp conflict (e.g., ASA2 is active) if (asa_creators_api_conflict_detected()) { return false; } // Load credentials class if (!class_exists('Asa_Service_CreatorsApi_Credentials')) { require_once ASA_LIB_DIR . 'Asa/Service/CreatorsApi/Credentials.php'; } $credentials = Asa_Service_CreatorsApi_Credentials::getInstance(); return $credentials->isUsable(); } } if (!function_exists('asa_is_creators_api_php_supported')) { /** * Check if PHP version supports Creators API * * @return bool */ function asa_is_creators_api_php_supported() { return version_compare(PHP_VERSION, '8.1.0', '>='); } } if (!function_exists('asa_is_asa2_active')) { /** * Check if ASA2 plugin is active * * When ASA2 is active, the Creators API in ASA1 cannot be used because * ASA2 loads the original GuzzleHttp namespace which conflicts with * ASA1's prefixed AsaGuzzleHttp namespace. * * @return bool */ function asa_is_asa2_active() { // Check for ASA2 specific constants or classes if (defined('ASA2_PLUGIN_FILE') || defined('ASA2_VERSION')) { return true; } // Check for ASA2 main class if (class_exists('Asa2', false)) { return true; } // Check if original GuzzleHttp is loaded (indicates potential conflict) // ASA1 uses AsaGuzzleHttp, if GuzzleHttp\Client exists, another plugin loaded it if (class_exists('GuzzleHttp\Client', false)) { return true; } return false; } } if (!function_exists('asa_creators_api_conflict_detected')) { /** * Check if there's a GuzzleHttp conflict that prevents Creators API usage * * @return bool */ function asa_creators_api_conflict_detected() { // If GuzzleHttp\Client exists (not AsaGuzzleHttp), there's a conflict return class_exists('GuzzleHttp\Client', false); } }