From 91587d9bcc82a3f6d6d792cbd94d204e9781e997 Mon Sep 17 00:00:00 2001 From: danpros Date: Fri, 2 Feb 2024 20:56:48 +0700 Subject: [PATCH] Cleanup --- system/admin/admin.php | 38 +++---- system/includes/functions.php | 233 +++++++++++++++++++++++------------------- 2 files changed, 150 insertions(+), 121 deletions(-) diff --git a/system/admin/admin.php b/system/admin/admin.php index f7524d0..665d77c 100644 --- a/system/admin/admin.php +++ b/system/admin/admin.php @@ -1300,36 +1300,38 @@ function toolbar() $user = $_SESSION[site_url()]['user']; $role = user('role', $user); $base = site_url(); + $toolbar = ''; - echo << EOF; - echo '
'; + echo $toolbar; } // save the i18n tag diff --git a/system/includes/functions.php b/system/includes/functions.php index e87874c..97f83dd 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -976,6 +976,7 @@ function category_list($custom = null) $tmp = array(); $cat = array(); $list = array(); + $cList = ''; if (!is_dir($dir)) { mkdir($dir, 0775, true); @@ -997,15 +998,16 @@ function category_list($custom = null) return $cat; } - echo ''; + return $cList; } @@ -1255,6 +1257,7 @@ function get_related($tag, $custom = null, $count = null) $tmp = array(); $exp = explode(',', $tag); $posts = get_category($exp[0], 1, $count + 1, true); + $related = ''; foreach ($posts as $post) { if ($post->url !== $exp[1]) { @@ -1265,15 +1268,17 @@ function get_related($tag, $custom = null, $count = null) if (empty($custom)) { if (!empty($tmp)) { $i = 1; - echo ''; + return $related; } else { - echo ''; + $related .= ''; + return $related; } } else { @@ -1437,6 +1442,7 @@ function recent_posts($custom = null, $count = null) $filename = "cache/widget/recent.cache"; $tmp = array(); $posts = array(); + $recent = ''; if (!is_dir($dir)) { mkdir($dir, 0775, true); @@ -1458,15 +1464,15 @@ function recent_posts($custom = null, $count = null) if (!empty($custom)) { return $posts; } else { - - echo ''; + return $recent; } } @@ -1483,6 +1489,7 @@ function recent_type($type, $custom = null, $count = null) $dir = 'cache/widget'; $filename = 'cache/widget/recent.' . $type . '.cache'; $tmp = array(); + $recent = ''; if (!is_dir($dir)) { mkdir($dir, 0775, true); @@ -1505,14 +1512,15 @@ function recent_type($type, $custom = null, $count = null) return $posts; } else { - echo ''; + return $recent; } } @@ -1522,6 +1530,7 @@ function popular_posts($custom = null, $count = null) static $_views = array(); $tmp = array(); $posts_list = get_blog_posts(); + $pop = ''; if (empty($count)) { $count = config('popular.count'); @@ -1575,24 +1584,27 @@ function popular_posts($custom = null, $count = null) } if (empty($custom)) { - echo ''; + return $pop; } else { return $posts; } } else { if(empty($custom)) { - echo ''; + $pop .= ''; + return $pop; } else { return $tmp; } } } else { if (empty($custom)) { - echo ''; + $pop .= ''; + return $pop; } else { return $tmp; } @@ -1600,7 +1612,8 @@ function popular_posts($custom = null, $count = null) } } else { if (empty($custom)) { - echo ''; + $pop .= ''; + return $pop; } else { return $tmp; } @@ -1613,6 +1626,7 @@ function archive_list($custom = null) $dir = "cache/widget"; $filename = "cache/widget/archive.cache"; $ar = array(); + $arch = ''; if (!is_dir($dir)) { mkdir($dir, 0775, true); @@ -1673,23 +1687,24 @@ function archive_list($custom = null) $script = << -1){this.parentNode.className = 'collapsed';this.innerHTML = '►';} else {this.parentNode.className = 'expanded';this.innerHTML = '▼';} EOF; - echo '
    '; - echo '
  • '; - echo '' . $arrow . ' '; - echo '' . $year . ' '; - echo '(' . count($months) . ')'; - echo '
      '; + $arch .= '
        '; + $arch .= '
      • '; + $arch .= '' . $arrow . ' '; + $arch .= '' . $year . ' '; + $arch .= '(' . count($months) . ')'; + $arch .= '
          '; foreach ($by_month as $month => $count) { $name = format_date(mktime(0, 0, 0, $month, 1, 2010), 'F'); - echo '
        • ' . $name . ''; - echo ' (' . $count . ')
        • '; + $arch .= '
        • ' . $name . ''; + $arch .= ' (' . $count . ')
        • '; } - echo '
        '; - echo '
      • '; - echo '
      '; + $arch .= '
    '; + $arch .= '
  • '; + $arch .= '
'; } + return $arch; } elseif ($custom === 'month-year') { foreach ($by_year as $year => $months) { $by_month = array_count_values($months); @@ -1697,16 +1712,18 @@ EOF; krsort($by_month); foreach ($by_month as $month => $count) { $name = format_date(mktime(0, 0, 0, $month, 1, 2010), 'F'); - echo '
  • ' . $name . ' ' . $year .' ('.$count.')
  • '; + $arch .= '
  • ' . $name . ' ' . $year .' ('.$count.')
  • '; } } + return $arch; } elseif ($custom === 'year') { foreach ($by_year as $year => $months) { $by_month = array_count_values($months); # Sort the months krsort($by_month); - echo '
  • ' . $year .' ('. count($months) .')
  • '; + $arch .= '
  • ' . $year .' ('. count($months) .')
  • '; } + return $arch; } else { return $by_year; } @@ -1770,14 +1787,15 @@ function tag_cloud($custom = null) // this is the increase per tag quantity (times used) $step = ($max_size - $min_size)/($spread); - + $wrapper = ''; arsort($tag_collection); $sliced_tags = array_slice($tag_collection, 0, $tagcloud_count, true); ksort($sliced_tags); foreach ($sliced_tags as $tag => $count) { $size = $min_size + (($count - $min_qty) * $step); - echo ' '.tag_i18n($tag).' '; + $wrapper .= ' '.tag_i18n($tag).' '; } + return $wrapper; } else { return $tag_collection; @@ -2165,15 +2183,17 @@ function tab($p) { $user = $_SESSION[site_url()]['user']; $role = user('role', $user); + $tab = ''; if (isset($p->author)) { if ($user === $p->author || $role === 'admin') { - echo ''; + $tab = ''; } } else { if ($p->url) { - echo ''; + $tab = ''; } } + return $tab; } // Social links. Deprecated @@ -2183,24 +2203,26 @@ function social($imgDir = null) $facebook = config('social.facebook'); $tumblr = config('social.tumblr'); $rss = site_url() . 'feed/rss'; + $social = ''; if ($imgDir === null) { $imgDir = "readable/img/"; } if (!empty($twitter)) { - echo 'Twitter'; + $social .= 'Twitter'; } if (!empty($facebook)) { - echo 'Facebook'; + $social .= 'Facebook'; } if (!empty($tumblr)) { - echo 'Tumblr'; + $social .= 'Tumblr'; } - echo 'RSS Feed'; + $social .= 'RSS Feed'; + return $social; } // Copyright @@ -2442,7 +2464,7 @@ function menu($class = null) $json = json_decode(file_get_contents('content/data/menu.json', true)); $nodes = json_decode($json); if (empty($nodes)) { - get_menu($class); + return get_menu($class); } else { $html = parseNodes($nodes, null, $class); libxml_use_internal_errors(true); @@ -2468,7 +2490,7 @@ function menu($class = null) } } else { - get_menu($class); + return get_menu($class); } } @@ -2489,25 +2511,26 @@ function get_menu($custom = null, $auto = null) { $posts = get_static_pages(); $req = $_SERVER['REQUEST_URI']; + $menu = ''; if (!empty($posts)) { asort($posts); - echo ''; + return $menu; } else { - echo ''; + return $menu; } } @@ -2812,60 +2837,61 @@ function sitemap_page_path() function generate_sitemap($str) { $default_priority = '0.5'; + $map = ''; header('X-Robots-Tag: noindex'); - echo ''; + $map .= ''; if ($str == 'index.xml') { - echo ''; + $map .= ''; if (config('sitemap.priority.base') !== 'false') { - echo '' . site_url() . 'sitemap.base.xml'; + $map .= '' . site_url() . 'sitemap.base.xml'; } if (config('sitemap.priority.post') !== 'false') { - echo '' . site_url() . 'sitemap.post.xml'; + $map .= '' . site_url() . 'sitemap.post.xml'; } if (config('sitemap.priority.static') !== 'false') { - echo '' . site_url() . 'sitemap.static.xml'; + $map .= '' . site_url() . 'sitemap.static.xml'; } if (config('sitemap.priority.category') !== 'false') { - echo '' . site_url() . 'sitemap.category.xml'; + $map .= '' . site_url() . 'sitemap.category.xml'; } if (config('sitemap.priority.tag') !== 'false') { - echo '' . site_url() . 'sitemap.tag.xml'; + $map .= '' . site_url() . 'sitemap.tag.xml'; } if (config('sitemap.priority.archiveDay') !== 'false' || config('sitemap.priority.archiveMonth') !== 'false' || config('sitemap.priority.archiveYear') !== 'false') { - echo '' . site_url() . 'sitemap.archive.xml'; + $map .= '' . site_url() . 'sitemap.archive.xml'; } if (config('sitemap.priority.author') !== 'false') { - echo '' . site_url() . 'sitemap.author.xml'; + $map .= '' . site_url() . 'sitemap.author.xml'; } if (config('sitemap.priority.type') !== 'false') { - echo '' . site_url() . 'sitemap.type.xml'; + $map .= '' . site_url() . 'sitemap.type.xml'; } - echo ''; + $map .= ''; } elseif ($str == 'base.xml') { $priority = (config('sitemap.priority.base')) ? config('sitemap.priority.base') : '1.0'; - echo ''; + $map .= ''; if ($priority !== 'false') { - echo '' . site_url() . '' . $priority . ''; + $map .= '' . site_url() . '' . $priority . ''; } - echo ''; + $map .= ''; } elseif ($str == 'post.xml') { @@ -2876,14 +2902,14 @@ function generate_sitemap($str) $posts = sitemap_post_path(); } - echo ''; + $map .= ''; foreach ($posts as $p) { - echo '' . $p->url . '' . $priority . '' . date('Y-m-d\TH:i:sP', $p->lastMod) . ''; + $map .= '' . $p->url . '' . $priority . '' . date('Y-m-d\TH:i:sP', $p->lastMod) . ''; } - echo ''; + $map .= ''; } elseif ($str == 'static.xml') { @@ -2894,14 +2920,14 @@ function generate_sitemap($str) $posts = sitemap_page_path(); } - echo ''; + $map .= ''; foreach ($posts as $p) { - echo '' . $p->url . '' . $priority . '' . date('Y-m-d\TH:i:sP', $p->lastMod) . ''; + $map .= '' . $p->url . '' . $priority . '' . date('Y-m-d\TH:i:sP', $p->lastMod) . ''; } - echo ''; + $map .= ''; } elseif ($str == 'tag.xml') { @@ -2914,7 +2940,7 @@ function generate_sitemap($str) $tags = array(); - echo ''; + $map .= ''; if($posts) { foreach ($posts as $index => $v) { @@ -2936,12 +2962,12 @@ function generate_sitemap($str) $tag = array_unique($tag, SORT_REGULAR); foreach ($tag as $t) { - echo '' . $t . '' . $priority . ''; + $map .= '' . $t . '' . $priority . ''; } } } - echo ''; + $map .= ''; } elseif ($str == 'archive.xml') { @@ -2964,27 +2990,27 @@ function generate_sitemap($str) $month = array_unique($month, SORT_REGULAR); $year = array_unique($year, SORT_REGULAR); - echo ''; + $map .= ''; if ($priorityDay !== 'false') { foreach ($day as $d) { - echo '' . $d . '' . $priorityDay . ''; + $map .= '' . $d . '' . $priorityDay . ''; } } if ($priorityMonth !== 'false') { foreach ($month as $m) { - echo '' . $m . '' . $priorityMonth . ''; + $map .= '' . $m . '' . $priorityMonth . ''; } } if ($priorityYear !== 'false') { foreach ($year as $y) { - echo '' . $y . '' . $priorityYear . ''; + $map .= '' . $y . '' . $priorityYear . ''; } } - echo ''; + $map .= ''; } elseif ($str == 'author.xml') { @@ -3002,15 +3028,15 @@ function generate_sitemap($str) $author = array_unique($author, SORT_REGULAR); } - echo ''; + $map .= ''; if ($priority !== 'false') { foreach ($author as $a) { - echo '' . $a . '' . $priority . ''; + $map .= '' . $a . '' . $priority . ''; } } - echo ''; + $map .= ''; } elseif ($str == 'category.xml') { @@ -3023,7 +3049,7 @@ function generate_sitemap($str) $cats = array(); - echo ''; + $map .= ''; if($posts) { foreach ($posts as $index => $v) { @@ -3043,12 +3069,12 @@ function generate_sitemap($str) $cat = array_unique($cat, SORT_REGULAR); foreach ($cat as $c) { - echo '' . $c . '' . $priority . ''; + $map .= '' . $c . '' . $priority . ''; } } } - echo ''; + $map .= ''; } elseif ($str == 'type.xml') { @@ -3061,7 +3087,7 @@ function generate_sitemap($str) $cats = array(); - echo ''; + $map .= ''; if($posts) { foreach ($posts as $index => $v) { @@ -3080,13 +3106,14 @@ function generate_sitemap($str) $type = array_unique($type, SORT_REGULAR); foreach ($type as $t) { - echo '' . $t . '' . $priority . ''; + $map .= '' . $t . '' . $priority . ''; } } } - echo ''; + $map .= ''; } + echo $map; } // Function to generate OPML file @@ -3113,7 +3140,7 @@ function generate_opml() ); $opml = new opml($opml_data); - echo $opml->render(); + return $opml->render(); } // Turn an array of posts into a JSON