123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495 |
- <?php
- if (!defined('DOM_SLUG')) {
- define('DOM_SLUG', str_replace(".", "-", $_SERVER['HTTP_HOST']));
- }
- if (!class_exists("plug_shortcodes")) {
- class plug_shortcodes {
- function __construct($ns) {
- $this->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 = '<div class="container mx-auto flex flex-wrap-reverse ">' . $ret . '</div>';
- $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 {
- if (file_exists(TEMPLATEPATH . '/tpl_default.php')) {
- include TEMPLATEPATH . '/tpl_default.php';
- } else {
- include dirname(__file__) . '/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 .= '<div class="hbox embed-page page-id-' . $id . '" >';
- $s .= '<div class="arrow">' . $page->post_title . '</div>';
- $s .= '<div class="box">';
- $s .= apply_filters('the_content', $page->post_content);
- $s .= '</div>';
- $s .= '</div>';
- }
- return $s;
- }
- function CSV_Parse2($content) {
- $content = preg_replace_callback("/\<a href=\'(.*).csv\'(.*)\>(.*)\<\/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 .= '<li><a href="#' . $title . '">' . $title . '</a></li>';
- }
- $sa .= '<ul id="' . $tid . '_menu" class="csvelement anchormenu">' . $menu . '</ul>';
- 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 .= '<h3>' . $title . '</a></h3>';
- $hhe .= '<p>' . implode("<br>", $tt) . '</p>';
- } else {
- $hhe .= '<h3>' . $title . '</h3>';
- }
- $sa .= '<a name="' . $title . '" class="anchor"> </a>';
- $sa .= '<div id="' . $tid . '_' . $index . '" class="csvelement ' . $tid . '">';
- $sa .= $hhe;
- $sa .= '<table class="' . $class . '">';
- $sa .= '<thead><tr>';
- $cols = count($heads);
- for ($y = 0; $y < $cols; $y++) {
- $sa .= '<th class="col' . $y . '">';
- $sa .= $heads[$y];
- $sa .= '</th>';
- }
- $sa .= '</tr></thead><tbody>';
- for ($i = 0, $n = count($rows); $i < $n; $i++) {
- $row = $rows[$i];
- if (strlen(join("", $row)) == 0) {
- } else {
- $sa .= '<tr>';
- for ($y = 0; $y < $cols; $y++) {
- $sa .= '<td class="col' . $y . '">';
- $tt = explode("\n", $row[$y]);
- if (count($tt) > 1) {
- $sa .= '<strong>' . array_shift($tt) . '</strong><br>';
- }
- $sa .= implode("<br>", $tt);
- $sa .= '</td>';
- }
- $sa .= '</tr>';
- }
- }
- $sa .= '</tbody></table><div class="totoplink"><a href="#TOP">Top</a></div></div>';
- }
- /*file_put_contents($cachefn,$sa);*/
- return $sa;
- }
- function help() {
- ?>
- [csv filename="" read="" delimiter="," quotechar='"' headers=false fields=false id="mytable" class="tablesorter"] <br>
- < a href='test.csv' >Title < /a >
- <?php
- }
- function admin_line() {
- ?>
- <?php
- }
- }
- global $plug_shortcodes, $r_get_posts_excluded, $r_get_posts_cat_collect;
- $r_get_posts_excluded = array();
- $r_get_posts_cat_collect = array();
- $plug_shortcodes = new plug_shortcodes($this);
- $this->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("is_restricted")) {
- function is_restricted() {
- return false;
- }
- }
- if (!function_exists("post_badge")) {
- function post_badge() {
- if (is_restricted()) {
- echo '<div class="badge_buy"><a href="/abonnement/">Køb abonnement</a></div>';
- } else {
- if (in_category('492') && !(in_category('9') || in_category(125))) {
- echo '<div class="badge_member"><a href="/wp-admin" style="float: left; margin-left: -100px; background-color: #777777;">Perspektiv</a></div>';
- } else {
- if (in_category('9') || in_category(125)) {
- if (in_category('492')) {
- echo '<div class="badge_member"><a href="/wp-admin" style="float: left; margin-left: -100px; background-color: #777777;">Perspektiv</a> <a href="/wp-admin">Kun for abonnenter</a></div>';
- } else {
- echo '<div class="badge_member"><a href="/wp-admin">Kun for abonnenter</a></div>';
- }
- }
- }
- }
- }
- }
- 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;
- }
- }
|