title = __("Misc Shortcodes", "dagsopt"); $this->pluginname = $ns->pluginname; $this->file = $ns->file; $this->ns = $ns; } function start() { add_filter('the_content', array(&$this, 'CSV_Parse')); add_filter('the_content', array(&$this, 'CSV_Parse2')); add_shortcode('acc-page', array(&$this, 'getpage')); add_shortcode('posts', array(&$this, 'r_get_posts')); add_shortcode('domposts', array(&$this, 'r_get_dom_posts')); } function r_get_dom_posts($atts, $content = null) { extract(shortcode_atts(array( "num" => '5', "cat" => '', "tpl" => 'default', "wrap" => 'box', ), $atts)); global $post, $r_get_posts_excluded, $r_get_posts_cat_collect; $oldpost = $post; if (defined("DOM_SLUG")) { $caten = get_category_by_slug(DOM_SLUG); } else { $caten = get_category_by_slug($cat); } $ret = ''; if ($caten) { $catid = $caten->cat_ID; } else { $catid = 3; } $r_get_posts_cat_collect[] = $catid; $myposts = get_posts('numberposts=' . $num . '&order=DESC&orderby=post_date&category=' . $catid . "&exclude=" . implode(",", $r_get_posts_excluded)); ob_start(); ob_clean(); foreach ($myposts as $post): $r_get_posts_excluded[] = $post->ID; setup_postdata($post); if (file_exists(TEMPLATEPATH . '/tpl_' . $tpl . '.php')) { include TEMPLATEPATH . '/tpl_' . $tpl . '.php'; } else { include TEMPLATEPATH . '/tpl_default.php'; } endforeach; if (isset($_REQUEST['debug'])) { echo ("atts:" . print_r($atts, true) . "\n"); echo ("CAT:" . $cat . "\n"); echo ("caten:" . print_r($caten, true) . "\n"); echo ("posts:" . print_r($myposts, true) . "\n"); echo ("r_get_posts_cat_collect:" . print_r($r_get_posts_cat_collect, true) . "\n"); echo ("r_get_posts_excluded:" . print_r($r_get_posts_excluded, true) . "\n"); } $ret = ob_get_contents(); ob_clean(); $ret .= ''; $post = $oldpost; return $ret; } function r_get_posts($atts, $content = null) { extract(shortcode_atts(array( "num" => '5', "cat" => '', "tpl" => '1big', "wrap" => 'box', ), $atts)); global $post, $r_get_posts_excluded, $r_get_posts_cat_collect; $oldpost = $post; $caten = get_category_by_slug($cat); $ret = ''; if ($caten) { $catid = $caten->cat_ID; } else { $catid = 3; } $r_get_posts_cat_collect[] = $catid; $myposts = get_posts('numberposts=' . $num . '&order=DESC&orderby=post_date&category=' . $catid . "&exclude=" . implode(",", $r_get_posts_excluded)); ob_start(); ob_clean(); foreach ($myposts as $post): $r_get_posts_excluded[] = $post->ID; setup_postdata($post); if (file_exists(TEMPLATEPATH . '/tpl_' . $tpl . '.php')) { include TEMPLATEPATH . '/tpl_' . $tpl . '.php'; } else { include TEMPLATEPATH . '/tpl_default.php'; } endforeach; if (isset($_REQUEST['debug'])) { echo ("atts:" . print_r($atts, true) . "\n"); echo ("CAT:" . $cat . "\n"); echo ("caten:" . print_r($caten, true) . "\n"); echo ("posts:" . print_r($myposts, true) . "\n"); echo ("r_get_posts_cat_collect:" . print_r($r_get_posts_cat_collect, true) . "\n"); echo ("r_get_posts_excluded:" . print_r($r_get_posts_excluded, true) . "\n"); } $ret = ob_get_contents(); ob_clean(); $ret .= ''; $post = $oldpost; return $ret; } function getpage($atts) { extract(shortcode_atts(array( 'id' => 0, ), $atts)); $s = ""; if ($id !== 0) { $page = get_page($id); $s .= '
'; } return $s; } function CSV_Parse2($content) { $content = preg_replace_callback("/\(.*)\<\/a\>/i", array(&$this, "CSV_Render2"), $content); return $content; } function CSV_Render2($matches) { //0 full 1 filename 2 attributes 3 title $filen = explode("/", $matches[1]); $class = array_pop($filen); $filen[] = $class; $filen = implode("/", $filen) . ".csv"; $arguments = array(); $arguments['filename'] = $filen; $arguments['class'] = "tablesorter " . $class; $arguments['id'] = "" . $class; $arguments['title'] = "" . $matches[3]; return $this->CSV_Render_($arguments); } function CSV_Render($matches) { $matches[1] = str_replace(array('”', '″'), '', $matches[1]); preg_match_all('/(\w*)=(.*?)" /i', $matches[1], $attributes); $arguments = array(); foreach ((array) $attributes[1] as $key => $value) { $arguments[$value] = str_replace('"', '', $attributes[2][$key]); } if (!isset($arguments['filename']) || !is_file(ABSPATH . $arguments['filename'])) { return "csv error: filename " . ABSPATH . $arguments['filename'] . " not readable"; } return $this->CSV_Render_($arguments); } function CSV_Parse($content) { $content = preg_replace_callback("/\[\[csv ([^]]*)\/\]\]/i", array(&$this, "CSV_Render"), $content); return $content; } function CSV_Render_($arguments) { if (!isset($arguments['filename']) || !is_file(ABSPATH . $arguments['filename'])) { return "csv error: filename " . ABSPATH . $arguments['filename'] . " not readable"; } $maxread = isset($arguments['read']) ? $arguments['read'] : (1024 * 1024 * 5); $delimiter = isset($arguments['delimiter']) ? $arguments['delimiter'] : ','; $quotechar = isset($arguments['quotechar']) ? $arguments['quotechar'] : '"'; $headers = isset($arguments['headers']) ? $arguments['headers'] : false; $fields = isset($arguments['fields']) ? explode(",", $arguments['fields']) : false; $tid = isset($arguments['id']) ? $arguments['id'] : 'mytable'; $class = isset($arguments['class']) ? $arguments['class'] : 'tablesorter'; $tables = array(); $rows = array(); $tmp = ""; $tmpheaders = array(); $handle = fopen(ABSPATH . $arguments['filename'], "r"); while (($data = fgetcsv($handle, $maxread, $delimiter, $quotechar)) !== FALSE) { if (substr($data[0], 0, 1) == "!") { $tables[] = array($tmp, $tmpheaders, $rows); $rows = array(); $tmp = substr($data[0], 1); if ($fields) { $tmpheaders = array(); $num = count($fields); for ($c = 0; $c < $num; $c++) { $tmpheaders[] = $data[$fields[$c]]; } } else { array_shift($data); $tmpheaders = $data; //print_r($tmpheaders); //die(); } } else { if ($fields) { $num = count($fields); $obj = array(); for ($c = 0; $c < $num; $c++) { $obj[] = $data[$fields[$c]]; } $rows[] = $obj; } else { $num = count($data); $diff = count($tmpheaders) < $num ? $num - count($tmpheaders) : 0; $obj = array(); for ($c = 0; $c < $num; $c++) { $obj[] = $data[$c + $diff]; } $rows[] = $obj; } } } if ($headers) { $tmpheaders = explode(",", $headers); } else { if (count($tmpheaders) == 0) { $tmpheaders = array_shift($rows); } } $tables[] = array($tmp, $tmpheaders, $rows); if (count($tables) > 1) { array_shift($tables); } fclose($handle); $sa = ""; $index = 0; $menu = ""; foreach ($tables as $table) { $title = $table[0]; $tt = explode("\n", $title); if (count($tt) > 1) { $title = array_shift($tt); } $menu .= '' . implode("
", $tt) . '
'; $sa .= $heads[$y]; $sa .= ' | '; } $sa .= '
---|
';
$tt = explode("\n", $row[$y]);
if (count($tt) > 1) {
$sa .= '' . array_shift($tt) . ' '; } $sa .= implode(" ", $tt); $sa .= ' | ';
}
$sa .= '