function test_get_social_icons_links()
 {
     $this->assertEmpty(PW_Functions::get_social_icons_links());
     $array_to_test = array(99 => new stdClass(), 'pw-test' => 'test', 'pw-two' => 'test2', 'hey-two' => 'test2', 'foo' => null, 0 => 123);
     $this->assertEquals(array('pw-two' => 'test2', 'pw-test' => 'test'), PW_Functions::get_social_icons_links($array_to_test), 'return only entries with keys starting with default: pw-');
     $this->assertEquals(array('hey-two' => 'test2'), PW_Functions::get_social_icons_links($array_to_test, 'hey'), 'return only entries with keys starting with some custom string');
     $this->assertEmpty(PW_Functions::get_social_icons_links($array_to_test, 'primoz'), 'test with the starting key that doesnt exist');
     $this->assertEmpty(PW_Functions::get_social_icons_links($array_to_test, 'foo'), 'empty values should not be included');
     $array_to_test['foo'] = 42;
     $this->assertEquals(array('foo' => 42), PW_Functions::get_social_icons_links($array_to_test, 'foo'), 'now the foo can be included');
 }
 /**
  * Front-end display of widget.
  */
 public function widget($args, $instance)
 {
     // Prepare data for mustache template
     $selected_user_id = intval($instance['selected_user_id']);
     $social_icons = array();
     if (is_callable('PW_Functions::get_social_icons_links')) {
         $icons = PW_Functions::get_social_icons_links(get_user_meta($selected_user_id));
         foreach ($icons as $service => $url) {
             $service_icon = substr($service, 3);
             array_push($social_icons, array('icon' => $service_icon, 'url' => $url[0]));
         }
     }
     // Mustache author-widget template rendering
     echo $this->mustache->render(apply_filters('pw/widget_author_view', 'widget-author'), array('args' => $args, 'author-avatar' => get_avatar($selected_user_id, 90), 'author-posts' => get_author_posts_url($selected_user_id), 'author-meta-name' => $args['before_title'] . get_the_author_meta('display_name', $selected_user_id) . $args['after_title'], 'author-meta-description' => wpautop(get_the_author_meta('description', $selected_user_id)), 'author-meta-user-url' => get_the_author_meta('user_url', $selected_user_id), 'social-icons' => intval(count($social_icons)), 'social-icons-list' => $social_icons));
 }
 /**
  * Front-end display of widget.
  *
  * @see WP_Widget::widget()
  *
  * @param array $args
  * @param array $instance
  */
 public function widget($args, $instance)
 {
     // Prepare the data for mustache template
     $counters = isset($instance['counters']) ? array_values($instance['counters']) : array();
     foreach ($counters as $key => $counter) {
         $counters[$key]['title'] = esc_html($counter['title']);
         $counters[$key]['number'] = absint($counter['number']);
         $counters[$key]['leading_zeros'] = esc_html(PW_Functions::leading_zeros(strlen($counter['number'])));
         if ($this->fields['icon']) {
             $counters[$key]['icon'] = esc_attr($counter['icon']);
         }
     }
     // Mustache widget-number-counter template rendering
     echo $this->mustache->render(apply_filters('pw/widget_number_counter_view', 'widget-number-counter'), array('args' => $args, 'instance' => $instance, 'counters' => $counters));
 }
 public function register_shortcode($atts, $content = null)
 {
     $atts = shortcode_atts(array('layout' => 'block', 'order_number' => 1, 'order_number_from' => 1, 'order_number_to' => 3, 'show_more_link' => ''), $atts);
     $instance = array('type' => $atts['layout'], 'from' => absint($atts['order_number']), 'to' => absint($atts['order_number']), 'more_news' => $atts['show_more_link']);
     // If the inline layout is selected then set the from and to variables
     if ('inline' === $atts['layout']) {
         $instance['from'] = absint($atts['order_number_from']);
         $instance['to'] = absint($atts['order_number_to']);
     }
     // Bound from and to between 1 and max_post_number
     $instance['from'] = PW_Functions::bound($instance['from'], 1, $this->max_post_number);
     $instance['to'] = PW_Functions::bound($instance['to'], 1, $this->max_post_number);
     // to can't be lower than from
     if ($instance['from'] > $instance['to']) {
         $instance['to'] = $instance['from'];
     }
     ob_start();
     the_widget('PW_Latest_News', $instance);
     return ob_get_clean();
 }
 /**
  * Sanitize widget form values as they are saved.
  *
  * @param array $new_instance The new options
  * @param array $old_instance The previous options
  */
 public function update($new_instance, $old_instance)
 {
     $instance = array();
     $instance['type'] = sanitize_key($new_instance['type']);
     $instance['from'] = sanitize_text_field($new_instance['from']);
     $instance['to'] = sanitize_text_field($new_instance['to']);
     if (!empty($new_instance['more_news'])) {
         $instance['more_news'] = sanitize_text_field($new_instance['more_news']);
     } else {
         $instance['more_news'] = '';
     }
     // Bound from and to between 1 and max_post_number
     $instance['from'] = PW_Functions::bound($instance['from'], 1, $this->max_post_number);
     $instance['to'] = PW_Functions::bound($instance['to'], 1, $this->max_post_number);
     // to can't be lower than from
     if ($instance['from'] > $instance['to']) {
         $instance['to'] = $instance['from'];
     }
     $instance['read_more_text'] = sanitize_text_field($new_instance['read_more_text']);
     return $instance;
 }
 /**
  * Front-end display of widget.
  *
  * @see WP_Widget::widget()
  *
  * @param array $args
  * @param array $instance
  */
 public function widget($args, $instance)
 {
     // Prepare data for mustache template
     $page_id = absint($instance['page_id']);
     /**
      * Support for the Polylang plugin.
      * https://proteusthemes.zendesk.com/agent/tickets/5175
      * https://polylang.wordpress.com/documentation/documentation-for-developers/functions-reference/#pll_get_post
      */
     if (function_exists('pll_get_post')) {
         $page_id = pll_get_post($page_id);
     }
     $instance['layout'] = sanitize_key($instance['layout']);
     $instance['read_more_text'] = empty($instance['read_more_text']) ? esc_html__('Read more', 'proteuswidgets') : sanitize_text_field($instance['read_more_text']);
     $thumbnail_size = 'inline' === $instance['layout'] ? 'pw-inline' : 'pw-page-box';
     // Get basic page info
     if ($page_id) {
         $page = (array) get_post($page_id);
     }
     // Prepare the excerpt text
     $excerpt = !empty($page['post_excerpt']) ? $page['post_excerpt'] : $page['post_content'];
     if ('inline' === $instance['layout'] && strlen($excerpt) > $this->excerpt_lengths['inline_excerpt']) {
         $strpos = strpos($excerpt, ' ', $this->excerpt_lengths['inline_excerpt']);
         $excerpt = false !== $strpos ? substr($excerpt, 0, $strpos) . ' …' : $excerpt;
     } elseif (strlen($excerpt) > $this->excerpt_lengths['block_excerpt']) {
         $strpos = strpos($excerpt, ' ', $this->excerpt_lengths['block_excerpt']);
         $excerpt = false !== $strpos ? substr($excerpt, 0, $strpos) . ' …' : $excerpt;
     }
     $page['post_excerpt'] = sanitize_text_field($excerpt);
     $page['link'] = get_permalink($page_id);
     $page['thumbnail'] = get_the_post_thumbnail($page_id, $thumbnail_size);
     if ('block' === $instance['layout']) {
         $attachment_image_id = get_post_thumbnail_id($page_id);
         $attachment_image_data = wp_get_attachment_image_src($attachment_image_id, 'pw-page-box');
         $page['image_url'] = $attachment_image_data[0];
         $page['image_width'] = $attachment_image_data[1];
         $page['image_height'] = $attachment_image_data[2];
         $page['srcset'] = PW_Functions::get_attachment_image_srcs($attachment_image_id, array('pw-page-box', 'full'));
     }
     // Mustache widget-featured-page template rendering
     echo $this->mustache->render(apply_filters('pw/widget_featured_page_view', 'widget-featured-page'), array('args' => $args, 'page' => $page, 'instance' => $instance, 'block' => 'block' === $instance['layout']));
 }