JezK
Edit File: InfoBlocks.php
<?php namespace WPForms\Emails; /** * Fetching and formatting Info Blocks for Email Summaries class. * * @since 1.5.4 */ class InfoBlocks { /** * Source of info blocks content. * * @since 1.5.4 */ const SOURCE_URL = 'https://wpformsapi.com/feeds/v1/email-summaries/%s'; /** * Get info blocks info from the cache file or remote. * * @since 1.6.4 * * @return array */ public function get_all() { $cache_file = $this->get_cache_file_path(); if ( empty( $cache_file ) || ! is_readable( $cache_file ) ) { return $this->fetch_all(); } // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents $contents = file_get_contents( $cache_file ); $contents = json_decode( $contents, true ); return $this->verify_fetched( $contents ); } /** * Fetch info blocks info from remote. * * @since 1.5.4 * * @return array */ public function fetch_all() { $info = []; $res = wp_remote_get( $this->get_remote_source(), [ 'timeout' => 10, 'user-agent' => wpforms_get_default_user_agent(), ] ); if ( is_wp_error( $res ) ) { return $info; } $body = wp_remote_retrieve_body( $res ); if ( empty( $body ) ) { return $info; } $body = json_decode( $body, true ); return $this->verify_fetched( $body ); } /** * Verify fetched blocks data. * * @since 1.5.4 * * @param array $fetched Fetched blocks data. * * @return array */ protected function verify_fetched( $fetched ) { $info = []; if ( ! \is_array( $fetched ) ) { return $info; } foreach ( $fetched as $item ) { if ( empty( $item['id'] ) ) { continue; } $id = \absint( $item['id'] ); if ( empty( $id ) ) { continue; } $info[ $id ] = $item; } return $info; } /** * Get info blocks relevant to customer's licence. * * @since 1.5.4 * * @return array */ protected function get_by_license() { $data = $this->get_all(); $filtered = []; if ( empty( $data ) || ! \is_array( $data ) ) { return $filtered; } // When there is no license, we assume it's a Lite version. // This is needed to show blocks for Lite users, as they don't have a license type. $license_type = wpforms_setting( 'type', 'lite', 'wpforms_license' ); foreach ( $data as $key => $item ) { if ( ! isset( $item['type'] ) || ! \is_array( $item['type'] ) ) { continue; } if ( ! \in_array( $license_type, $item['type'], true ) ) { continue; } $filtered[ $key ] = $item; } return $filtered; } /** * Get the first block with a valid id. * Needed to ignore blocks with invalid/missing ids. * * @since 1.5.4 * * @param array $data Blocks array. * * @return array */ protected function get_first_with_id( $data ) { if ( empty( $data ) || ! \is_array( $data ) ) { return []; } foreach ( $data as $item ) { $item_id = \absint( $item['id'] ); if ( ! empty( $item_id ) ) { return $item; } } return []; } /** * Get next info block that wasn't sent yet. * * @since 1.5.4 * * @return array */ public function get_next() { $data = $this->get_by_license(); $block = []; if ( empty( $data ) || ! \is_array( $data ) ) { return $block; } $blocks_sent = \get_option( 'wpforms_emails_infoblocks_sent' ); if ( empty( $blocks_sent ) || ! \is_array( $blocks_sent ) ) { $block = $this->get_first_with_id( $data ); } if ( empty( $block ) ) { $data = \array_diff_key( $data, \array_flip( $blocks_sent ) ); $block = $this->get_first_with_id( $data ); } return $block; } /** * Register a block as sent. * * @since 1.5.4 * * @param array $info_block Info block. */ public function register_sent( $info_block ) { $block_id = isset( $info_block['id'] ) ? absint( $info_block['id'] ) : false; if ( empty( $block_id ) ) { return; } $option_name = 'wpforms_email_summaries_info_blocks_sent'; $blocks = get_option( $option_name ); if ( empty( $blocks ) || ! is_array( $blocks ) ) { update_option( $option_name, [ $block_id ] ); return; } if ( in_array( $block_id, $blocks, true ) ) { return; } $blocks[] = $block_id; update_option( $option_name, $blocks ); } /** * Get a path of the blocks cache file. * * @since 1.6.4 * * @return string */ public function get_cache_file_path() { $upload_dir = wpforms_upload_dir(); if ( ! isset( $upload_dir['path'] ) ) { return ''; } $cache_dir = trailingslashit( $upload_dir['path'] ) . 'cache'; return wp_normalize_path( trailingslashit( $cache_dir ) . 'email-summaries.json' ); } /** * Fetch and cache blocks in a file. * * @since 1.6.4 */ public function cache_all() { $file_path = $this->get_cache_file_path(); if ( empty( $file_path ) ) { return; } $dir = dirname( $file_path ); if ( ! wp_mkdir_p( $dir ) ) { return; } wpforms_create_index_html_file( $dir ); wpforms_create_upload_dir_htaccess_file(); $info_blocks = $this->fetch_all(); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents file_put_contents( $file_path, wp_json_encode( $info_blocks ) ); } /** * Retrieve the source URL. * * @since 1.9.5 * * @return string */ protected function get_remote_source(): string { $license_type = wpforms()->is_pro() ? wpforms_get_license_type() : 'lite'; return sprintf( self::SOURCE_URL, $license_type ); } }
BanaBridge News
https://validator.w3.org/feed/docs/rss2.html
Court Orders Ex-Weah Protocol Chief Jailed on US$8 Million Bail, Sends 15 Jurors to Prison Over Misconduct
Women Renew Call for War and Economic Crimes Court at Liberia’s Historic Peace Prayer Site
Finance Minister Ngafuan Urges Transparency, Accountability as Liberia Advances ARREST Agenda at UN Retreat
PPCC Donates ICT Equipment to 50 Government Institutions to Expand Electronic Procurement System
Liberia Commissions €100,000 Elemental Analyzer to Strengthen Environmental Research and Food Security
EPA Ends 16 Years of Renting with Purchase of Permanent Headquarters
West African Tax Bodies Deepen Partnership to Boost Revenue Mobilization, Launch Carbon Tax Study
Liberia Hosts Sierra Leone Procurement Delegation for E-GP Reform Study Tour
World Bank Praises Liberia’s Central Bank for Economic Stability and Private Sector Progress
Liberians See Slight Improvement in Corruption Fight, But Graft Still Viewed as Widespread, CENTAL Report Finds
Canada Afrique Care Foundation Set for Official Launch, Expanding Free Mental Health Access Across Canada and Africa
Weah Claims Liberia Has Become a “Narco State” as Opposition Rallies Behind Calls for Independent Probe into US$19 Million Cocaine Bust
EPA Boss Calls for Stronger Student Engagement, Unveils Push for Academic Partnership at UL Climate Symposium
Education Minister Urges Students to Embrace Tax Responsibility at National Student Tax Day
CDC Secretary General Urges U.S. Government to Review Support to Liberia National Police
Liberia Partners with CACFO to Expand Mental Health Services Ahead of Global Launch
Wreh-Toe Appointed Board Chair of CACFO as Foundation Strengthens Mental Health Push
GIABA Opens New Information Center Headquarters in Abidjan
Liberia Wins Fresh Backing as World Bank Group Executive Praises Progress, Pushes Faster Project Delivery
LRA Honors Liberia’s Top Taxpayers as Revenue Collections Hit Historic High
Root Cause in Question as Border Tensions Persist After Conakry Peace Deal
From Enforcement to Innovation: EPA Marks 2025 as a Defining Year for Liberia’s Environment
Weah Declares ‘Road to 2029 Begins Today’ as CDC Marks 22nd Anniversary in Zwedru
500 Documented Governance Failures: Activist Publishes Sweeping End-of-Year Indictment of Boakai Administration
CDC Calls for Probe into Border Crisis, Cites Alleged Mining Activities
Liberia Moves to Strengthen Small Businesses with $672,000 Packaging Solution Initiative
Former Public Works Minister Ruth Coker Collins Defends Zwedru Corridor Strategy, Calls for “Facts Over Rhetoric” in Infrastructure Debate
Power Shake-Up in CDC Diaspora: NEC Dissolves CDC-USA Interim Leadership, Appoints Rev. Muin to Lead U.S. Chapter
Tweah Reemerges, Sparks Fierce National Debate Over Governance and Liberia’s Future
Koijee Slams Tribal Politics and Political Manipulation in Lofa, Accuses Boakai Government
Mali and Burkina Faso Impose Reciprocal Travel Ban on U.S. Citizens
Guinea Election: A Turn Toward Continuity Amid Questions of Democratic Credibility
Liberia’s Revenue Grows Stronger as LRA Exceeds National Target for Second Year
Liberia’s Gender Legal Landscape: Laws in Place, Systems Lag Far Behind
Liberia’s Economy Gains Momentum as CBL Governor Highlights Progress at ECOWAS Meeting
Liberia Positions Itself for Eco Currency Entry as Economy Expands by 5.1%
From Overcrowded Classrooms to Renewal: NPA Mobilizes $1 Million to Transform UL
Ex-Public Works Minister Ruth Coker Collins Slams Ministry’s “Lack of Capacity,” Defends Her Infrastructure Record
CDC Expels Three Senior Members, Citing Alleged Alignment With Government and Undermining Party Ideology
UL to Celebrate 75 Years of Excellence
Saudi Fund Advances Liberia’s Push for Major Infrastructure Development
West African Financial Leaders Convene in Monrovia for ECOWAS Statutory Meetings
Unlocking Liberia’s Potential: Government Launches Major Revenue and Transparency Reforms
Incremental Gains, Enduring Impunity: Liberia’s CPI Improvement Fails the Test of Reform
Boakai’s Call for Unity Faces Scrutiny as Opposition, Citizens Question Actions Behind the Words
REMAPSEN Liberia Set to Strengthen Health and Environmental Reporting
Energy Sector Women Step Into the Spotlight at Liberia’s International Women’s Day Celebration
FeJAL Concludes Three-Day Retreat, Honors Outstanding Women Journalists
Dr. Rasha Kelej Named Among Africa’s 100 Most Influential Leaders
LAVA Honored for Strengthening Liberia–U.S. Ties at 2025 Military Ball