ID))) { $display_link = get_post_custom_values('articles2sidebar_display_link', $a2spost->ID); $display_link = $display_link[0]; } else { $display_link = 1; } echo $before_widget; echo $before_title; if (($options['link']>0 || $display_link>0) && (!$display_link == 0)) echo ''; echo $a2spost->post_title; if (($options['link']>0 || $display_link>0) && (!$display_link == 0)) echo ''; echo $after_title; if ($a2spost->post_excerpt != '') { echo '

'; $imgBeg = strpos($a2spost->post_content, 'post_content, $imgBeg); $imgEnd = strpos($post, '>'); $postOutput = substr($post, 0, $imgEnd+1); $result = preg_match('/width="([0-9]*)" height="([0-9]*)"/', $postOutput, $matches); if ($result) { if ($matches[1]>45 || $matches[2]>45) { $pagestring = $matches[0]; $postOutput = str_replace($pagestring, "", $postOutput); } } if($postOutput != "

") { if (($options['link']>0 || $display_link>0) && (!$display_link == 0)) echo ''; if ($matches[1]>45 || $matches[2]>45) { echo preg_replace('/height="([0-9]*)"/i','',str_replace('0 || $display_link>0) && (!$display_link == 0)) echo ''; } echo $a2spost->post_excerpt; if (($options['link']>0 || $display_link>0) && (!$display_link == 0)) echo '
' . $options['lmtext'] . ''; echo '

'; } else { $extended = get_extended($a2spost->post_content); if ($extended['extended'] !='') { $content = $extended['main'].'[…]'; } else { $tmp = explode(' ',strip_tags(strip_shortcodes($a2spost->post_content)),55); $tmp[54] = '[…]'; $content = implode(' ',$tmp); } echo '

'; $imgBeg = strpos($a2spost->post_content, 'post_content, $imgBeg); $imgEnd = strpos($post, '>'); $postOutput = substr($post, 0, $imgEnd+1); $result = preg_match('/width="([0-9]*)" height="([0-9]*)"/', $postOutput, $matches); if ($result) { if ($matches[1]>45 || $matches[2]>45) { $pagestring = $matches[0]; $postOutput = str_replace($pagestring, "", $postOutput); } } if($postOutput != "

") { if (($options['link']>0 || $display_link>0) && (!$display_link == 0)) echo ''; if ($matches[1]>45 || $matches[2]>45) { echo preg_replace('/height="([0-9]*)"/i','',str_replace('0 || $display_link>0) && (!$display_link == 0)) echo ''; } echo $content; if (($options['link']>0 || $display_link>0) && (!$display_link == 0)) echo '
' . $options['rmtext'] . ''; echo '

'; } echo $after_widget; } function widget_articles2sidebar($args) { if (is_page()) { extract($args); $options = get_option('widget_articles2sidebar'); if ( !is_array($options) ) $options = array('origin'=>'auto', 'cat' => '', 'link' => 1, 'lmtext' => __('Learn more').' »', 'rmtext' => __('Read more').' »'); $options['link'] = $options['link']; $options['lmtext'] = htmlspecialchars($options['lmtext'], ENT_QUOTES); $options['rmtext'] = htmlspecialchars($options['lmtext'], ENT_QUOTES); switch($options['origin']) { case 'auto': case 'both': case 'page': // retrieve the category that correspond to the page title $cat = get_category_by_slug(the_title('','',false)); if ($cat) { // retrieve that category's posts $a2sposts = get_posts('category='.$cat->term_id.'&orderby=ID&order=ASC'); foreach ($a2sposts as $a2spost) { // dislay them widget_articles2sidebar_content($a2spost,$options,$before_widget,$before_title,$after_title,$after_widget); } } case 'auto': if (count($a2sposts)) break; case 'both': case 'cat': // retrieve the categories $cats = get_categories(); foreach ($cats as $cat) { // retrieve the posts if ($cat->cat_name == $options['cat']) { $a2sposts = get_posts('category='.$cat->cat_ID.'&orderby=ID&order=ASC'); foreach ($a2sposts as $a2spost) { // dislay them widget_articles2sidebar_content($a2spost,$options,$before_widget,$before_title,$after_title,$after_widget); } break; } } } } } function widget_articles2sidebar_control() { $options = get_option('widget_articles2sidebar'); if ( !is_array($options) ) $options = array('origin'=>'auto', 'cat' => '', 'link' => 1, 'lmtext' => __('Learn more').' »', 'rmtext' => __('Read more').' »'); if ( $_POST['articles2sidebar-submit'] ) { $options['origin'] = strip_tags(stripslashes($_POST['articles2sidebar-origin'])); $options['cat'] = strip_tags(stripslashes($_POST['articles2sidebar-cat'])); (intval($_POST['articles2sidebar-link'])>0) ? $options['link'] = 1 : $options['link'] = 0; $options['lmtext'] = strip_tags(stripslashes($_POST['articles2sidebar-lmtext'])); $options['rmtext'] = strip_tags(stripslashes($_POST['articles2sidebar-rmtext'])); if (strip_tags(stripslashes($_POST['articles2sidebar-cat2'])) != '') $options['cat'] = strip_tags(stripslashes($_POST['articles2sidebar-cat2'])); update_option('widget_articles2sidebar', $options); } $origin = $options['origin']; $cat = htmlspecialchars($options['cat'], ENT_QUOTES); $link = $options['link']; $lmtext = htmlspecialchars($options['lmtext'], ENT_QUOTES); $rmtext = htmlspecialchars($options['rmtext'], ENT_QUOTES); ?>