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', "cols" => '1', "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(); $myposts_length = count($myposts); $myposts_index = 0; 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 { if (file_exists(TEMPLATEPATH . '/tpl_default.php')) { include TEMPLATEPATH . '/tpl_default.php'; } else { include dirname(__file__) . '/tpl_default.php'; } } $myposts_index++; 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 = '
' . $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 .= '
'; $s .= '
' . $page->post_title . '
'; $s .= '
'; $s .= apply_filters('the_content', $page->post_content); $s .= '
'; $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 .= '
  • ' . $title . '
  • '; } $sa .= ''; foreach ($tables as $table) { $index++; $title = $table[0]; $heads = $table[1]; $rows = $table[2]; $hhe = ""; $tt = explode("\n", $title); if (count($tt) > 1) { $title = array_shift($tt); $hhe .= '

    ' . $title . '

    '; $hhe .= '

    ' . implode("
    ", $tt) . '

    '; } else { $hhe .= '

    ' . $title . '

    '; } $sa .= ' '; $sa .= '
    '; $sa .= $hhe; $sa .= ''; $sa .= ''; $cols = count($heads); for ($y = 0; $y < $cols; $y++) { $sa .= ''; } $sa .= ''; for ($i = 0, $n = count($rows); $i < $n; $i++) { $row = $rows[$i]; if (strlen(join("", $row)) == 0) { } else { $sa .= ''; for ($y = 0; $y < $cols; $y++) { $sa .= ''; } $sa .= ''; } } $sa .= '
    '; $sa .= $heads[$y]; $sa .= '
    '; $tt = explode("\n", $row[$y]); if (count($tt) > 1) { $sa .= '' . array_shift($tt) . '
    '; } $sa .= implode("
    ", $tt); $sa .= '
    '; } /*file_put_contents($cachefn,$sa);*/ return $sa; } function help() { ?> [csv filename="" read="" delimiter="," quotechar='"' headers=false fields=false id="mytable" class="tablesorter"]
    < a href='test.csv' >Title < /a > dagsopt['plug_shortcodes'] = $plug_shortcodes; } if (!function_exists("post_image_")) { function post_image_($postid, $format = "thumbnail") { global $wpdb; $image = array(); if (isset($postid)) { $post_image_attachments = @$wpdb->get_results("SELECT ID, post_title, post_excerpt, post_content FROM {$wpdb->posts} WHERE post_parent = '{$postid}' AND post_type = 'attachment' AND post_mime_type LIKE '%image%' ORDER BY ID ASC LIMIT 1"); foreach ($post_image_attachments as $attachment) { $url = get_attachment_link($attachment->ID); $id = $attachment->ID; $img_title = apply_filters('the_title', $attachment->post_title); $srcc = wp_get_attachment_image_src($attachment->ID, $format); if (defined("WP_SITEURL_SEC")) { $srcc[0] = str_replace(WP_SITEURL_SEC, WP_SITEURL_CDN, $srcc[0]); } $image = array('title' => $img_title, 'id' => $id, 'url' => $url, 'src' => $srcc, 'caption' => $attachment->post_excerpt, 'description' => $attachment->post_content); } } return $image; } } if (!function_exists("post_badge")) { function post_badge() { if (is_restricted()) { echo '
    Køb abonnement
    '; } else { if (in_category('492') && !(in_category('9') || in_category(125))) { echo '
    Perspektiv
    '; } else { if (in_category('9') || in_category(125)) { if (in_category('492')) { echo '
    Perspektiv Kun for abonnenter
    '; } else { echo '
    Kun for abonnenter
    '; } } } } } } if (!function_exists("post_images")) { function post_images($postid) { global $wpdb; if (isset($postid)) { $images = array(); $post_image_attachments = @$wpdb->get_results("SELECT ID, post_title, post_excerpt, post_content FROM $wpdb->posts WHERE post_parent = '$postid' AND post_type = 'attachment' AND post_mime_type LIKE '%image%' ORDER BY menu_order ASC"); foreach ($post_image_attachments as $attachment) { $url = get_attachment_link($attachment->ID); $id = $attachment->ID; $img_title = apply_filters('the_title', $attachment->post_title); $thumbnail = wp_get_attachment_image_src($attachment->ID, 'thumbnail'); $medium = wp_get_attachment_image_src($attachment->ID, 'medium'); $large = wp_get_attachment_image_src($attachment->ID, 'large'); $xlarge = wp_get_attachment_image_src($attachment->ID, 'xlarge'); $full = wp_get_attachment_image_src($attachment->ID, 'full'); $image = array('title' => $img_title, 'id' => $id, 'url' => $url, 'thumbnail' => $thumbnail, 'medium' => $medium, 'large' => $large, 'xlarge' => $xlarge, 'full' => $full, 'caption' => $attachment->post_excerpt, 'description' => $attachment->post_content); array_push($images, $image); } return $images; } } function post_content_images($postid) { global $wpdb; if (isset($postid)) { $content_post = get_post($postid); $content = $content_post->post_content; $content = apply_filters('the_content', $content); preg_match_all('/< *img[^>]*src *= *["\']?([^"\']*)/i', $content, $matches); return $matches[1]; } } } function post_images2($postid) { global $wpdb; if (isset($postid)) { $images = array(); $post_image_attachments = @$wpdb->get_results("SELECT ID, post_title, post_excerpt, post_content FROM $wpdb->posts WHERE post_parent = '$postid' AND post_type = 'attachment' AND post_mime_type LIKE '%image%' ORDER BY menu_order ASC"); foreach ($post_image_attachments as $attachment) { $url = get_attachment_link($attachment->ID); $id = $attachment->ID; $img_title = apply_filters('the_title', $attachment->post_title); $thumbnail = wp_get_attachment_image_src($attachment->ID, 'thumbnail'); $medium = wp_get_attachment_image_src($attachment->ID, 'medium'); $large = wp_get_attachment_image_src($attachment->ID, 'large'); $xlarge = wp_get_attachment_image_src($attachment->ID, 'xlarge'); $full = wp_get_attachment_image_src($attachment->ID, 'full'); $image = array('title' => $img_title, 'id' => $id, 'url' => $url, 'thumbnail' => $thumbnail, 'medium' => $medium, 'large' => $large, 'xlarge' => $xlarge, 'full' => $full, 'caption' => $attachment->post_excerpt, 'description' => $attachment->post_content); array_push($images, $image); } return $images; } }