From af1326791ac8bb2406ef839cbac5ffecd0a09525 Mon Sep 17 00:00:00 2001 From: saxmatt Date: Thu, 18 Dec 2003 10:12:34 +0000 Subject: [PATCH] Moved wp-links files to wp-includes or wp-images where appropiate. Updated necessary paths. git-svn-id: http://svn.automattic.com/wordpress/trunk@630 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/link-import.php | 1 - wp-admin/link-manager.php | 1 - wp-images/links/rating-0.gif | Bin 0 -> 882 bytes wp-images/links/rating-1.gif | Bin 0 -> 909 bytes wp-images/links/rating-2.gif | Bin 0 -> 918 bytes wp-images/links/rating-3.gif | Bin 0 -> 926 bytes wp-images/links/rating-4.gif | Bin 0 -> 950 bytes wp-images/links/rating-5.gif | Bin 0 -> 960 bytes wp-images/links/rating-6.gif | Bin 0 -> 967 bytes wp-images/links/rating-7.gif | Bin 0 -> 989 bytes wp-images/links/rating-8.gif | Bin 0 -> 996 bytes wp-images/links/rating-9.gif | Bin 0 -> 981 bytes wp-images/links/star.gif | Bin 0 -> 895 bytes wp-images/links/tick.png | Bin 0 -> 334 bytes wp-includes/links-update-xml.php | 172 +++++++++ wp-includes/links.php | 577 +++++++++++++++++++++++++++++++ wp-settings.php | 2 +- 17 files changed, 750 insertions(+), 3 deletions(-) create mode 100644 wp-images/links/rating-0.gif create mode 100644 wp-images/links/rating-1.gif create mode 100644 wp-images/links/rating-2.gif create mode 100644 wp-images/links/rating-3.gif create mode 100644 wp-images/links/rating-4.gif create mode 100644 wp-images/links/rating-5.gif create mode 100644 wp-images/links/rating-6.gif create mode 100644 wp-images/links/rating-7.gif create mode 100644 wp-images/links/rating-8.gif create mode 100644 wp-images/links/rating-9.gif create mode 100644 wp-images/links/star.gif create mode 100644 wp-images/links/tick.png create mode 100644 wp-includes/links-update-xml.php create mode 100644 wp-includes/links.php diff --git a/wp-admin/link-import.php b/wp-admin/link-import.php index ef334f463b..3f7ab46127 100644 --- a/wp-admin/link-import.php +++ b/wp-admin/link-import.php @@ -3,7 +3,6 @@ // Copyright (C) 2002 Mike Little -- mike@zed1.com require_once('../wp-config.php'); -include_once("../wp-links/links.php"); $parent_file = 'link-manager.php'; $title = 'Import Blogroll'; diff --git a/wp-admin/link-manager.php b/wp-admin/link-manager.php index fe3706a128..8b724d0469 100644 --- a/wp-admin/link-manager.php +++ b/wp-admin/link-manager.php @@ -3,7 +3,6 @@ // Copyright (C) 2002, 2003 Mike Little -- mike@zed1.com require_once('../wp-config.php'); -require_once("../wp-links/links.php"); $title = 'Manage Links'; $this_file = 'link-manager.php'; diff --git a/wp-images/links/rating-0.gif b/wp-images/links/rating-0.gif new file mode 100644 index 0000000000000000000000000000000000000000..6c7c50fa8b2e3ee662e83219cf8aba2ce8302438 GIT binary patch literal 882 zcmZ?wbhEHbOkv<+_|5$$7(9p~w ztQB)&!@|Su0?JN09)XLFc1svXEr|$Ne7s*ly+}r4(~^_@%AWILPJT-CYSc|WW%J|G agEO<$vmf1&3{pQoU$T}-R?1L;!5RP<4Ig6w literal 0 HcmV?d00001 diff --git a/wp-images/links/rating-1.gif b/wp-images/links/rating-1.gif new file mode 100644 index 0000000000000000000000000000000000000000..3a849307383d1227c0c94ca72e38ee805e197d21 GIT binary patch literal 909 zcmZ?wbhEHbOkv<+_|5;Yuj2to^0uBw$ z9D+;&2R1A`+%BN(HOFJ)B3DLMW3@XwJ}f%kui$KUCZZtuP@hupsu0gf3p`u3lTYor zQS{(+vqt)>JDnSs9h_}h$(8!@b6Ud!=gD;M1& literal 0 HcmV?d00001 diff --git a/wp-images/links/rating-2.gif b/wp-images/links/rating-2.gif new file mode 100644 index 0000000000000000000000000000000000000000..e50dcee1f03d4d2aef135874082ab1f3d781d80b GIT binary patch literal 918 zcmZ?wbhEHbOkv<+_|5?J_j2to^0uBw$ z9D-6lGXxqM+69!o=6GyebhKMSQS8o%4T?)Aj2to^0uBw$ z9D-6lGYS+BH#4w!%<J^q0vX*z}w7pUS4AuZ&)HEXi literal 0 HcmV?d00001 diff --git a/wp-images/links/rating-4.gif b/wp-images/links/rating-4.gif new file mode 100644 index 0000000000000000000000000000000000000000..a1c44ec9a77131cd37acdfb30053729c5bff6526 GIT binary patch literal 950 zcmZ?wbhEHbOkv<+_|5TDNcA(V8IK~OVj%a4sqPfr(j z7PEQzAk()Cfugdk_^y2pB!pY}KPl>;}yC(O`Dg(;p!T zSLT?nSIXVFbyILWy zt}F^=jk`N@vi5~#&ijLSt+%D$T$dKR%2dis+iO|=`D3k?;yTfL8aBQ=DzP>H?5F#KQZ^nVnLhQJ650mYvzj0_Ac3_75k0Ll{#9J?48 zIb=Kp8XB581f_gt6eu2UW?=J}V_~S|+9js%#Uij^v3oxQM~95(CY6&-8uD5poD-Ke z^hhPfP3io&`0NC=;%P3C7nUAwx0k%MX2ryei;Ob4O;=8asQ5S8E#4%v>!U`{YR{=` z2X2}?zuXuU%9h))_07dKUOUU~{w#fSYNg#-v87!h+3s7j-M5wA7J3)5({SUhyR)u8 rxwpaL@jO-QEA$ZJv(giqyr$vf_G@0u0swZF#KQZ^nVnLhQJ650mYvzj0_Ac3_75k0Ll{#90wT~ zIb=Kp8XB581f_gt6eu2UW?=J}V_~S|+9js%#Uij^v3tLaeI1L#f+e1lS%d9Db_gYT zGfJ8s+hZZT_{2nW$9Z>VZhGL|&fjRXCNeNNa51yfvyiIEPyD9Xvj3ZNYtjq1C7v6N zM0b`x30@J{YPMw8rL3?eX}g=w+`Rbm`Ua+xY=2j7)r;E3cxBt)D4}%`(?VY^+L|4b zAGarO{;#RlAq9ztj0BaRc_$P;IGw6^`HI%e+@yI0lKpE}Nh+tGpZt@Jg~1vC*Mv}4 literal 0 HcmV?d00001 diff --git a/wp-images/links/rating-9.gif b/wp-images/links/rating-9.gif new file mode 100644 index 0000000000000000000000000000000000000000..9257b4865b1391a87fd0eeb8f0c6dcb8c2a568e0 GIT binary patch literal 981 zcmZ?wbhEHbOkv<+_|5F#KQZ^nVnLhQJ650mYvzj0_Ac3_75k0Ll{#9Ge&z zIb=Kp8XB581f_gt6eu2UW?=J}V_~S|+9js%#Uij^v3tLaeI1YHrsRW@`9+tt>($pkb|gY5#doqf^BkQUmmWIL=SdH{Vlm|f!z9&-T_ILQ&kxKC2C2FWD^nb#<7Bf-R-c=bw!3QTudnKni-P+X&0QUudwYTH{X=`awx>ny&S7r8sy%uA jwSAt9&3m=C=_Jl-SNf5XH}vC+H&Usvx2wh_J|Fktxap6;~7mgUi}1mMIp+FQ9B$Hf^v>^95n6 zU^HkmOpr|`gUMhp2=dbSo2#F}TOPyQd**k}{NJ6sx364%d{oQ&t-r@4mqJRZL}ey( zS;$gW-E@iX#ba()&*|f4VU}jq zW2xND!#vHaDQJdUghg6ZLvc6VGAz@wVC1QlTZL6xF%@dWfQAw*dJIMzX|#A;ZK!Kb zxTkxyKgLo;c%(916%GcYjWk-- z$#t8WlM&TH;*YUZnUO`V*oA^-R7Q~_NfQ8ETqkJU5+!+n$!p?(3Bx#q8Zn@G2^Jg- zMjPqs74>b})SO~t1c^V!Qe{;yaIC*6#zuReV@VA)a_{wyD4TJl)7u_~8+mx>CKJv60DaPKUjP6A literal 0 HcmV?d00001 diff --git a/wp-images/links/tick.png b/wp-images/links/tick.png new file mode 100644 index 0000000000000000000000000000000000000000..cf8b6842c1f6938bdaa99fb9ebe8da442834e99a GIT binary patch literal 334 zcmeAS@N?(olHy`uVBq!ia0vp^oFL4>3?#4ne^UZdIwh_VCC){ui6xo&c?uz!xv2~x zrKt)=Mhae~ISNJw2F3~o23A01WT~KQ00br1OJ)J}v6p!Iy0Twp7ZvB1ddKzt4#?aB zkH}&M25un`X1sK_?hjCqCEd~2k%3`jKlh(RRv_Oyz$e7@|NsA`rKNd!c|k!z6%`ed zl9KG~>^?p|#l^)UA|f_6HmJf(&5k{ zo*n+Cl@y%N-WH*%&ns=EzNC)r;mUXL(ECWgL$@JJAsBV Nc)I$ztaD0e0stg)WB>pF literal 0 HcmV?d00001 diff --git a/wp-includes/links-update-xml.php b/wp-includes/links-update-xml.php new file mode 100644 index 0000000000..0d059569b4 --- /dev/null +++ b/wp-includes/links-update-xml.php @@ -0,0 +1,172 @@ +get_results("SELECT link_id, link_url FROM $tablelinks WHERE link_visible = 'Y' AND link_url <> ''"); + foreach ($links as $link) { + $link_url = transform_url($link->link_url); + $all_links[$link_url] = array($link->link_id, 0); + } +} + +/** + ** update_links() + ** Update in the db the links which have been updated ($all_links[url][1] != 0) + **/ +function update_links() { + global $tablelinks, $all_links, $wpdb; + reset($all_links); + while (list($id, $val) = each($all_links)) { + if ($val[1]) { + $wpdb->query("UPDATE $tablelinks SET link_updated = '$val[1]' WHERE link_id = $val[0]"); + } + } // end while +} + +/** + ** get_weblogs_updatedfile() + ** Retrieves and caches a copy of the weblogs.com changed blogs xml file. + ** If the file exists check it's age, get new copy if old. + ** If a new or updated file has been written return true (needs processing) + ** otherwise return false (nothing to do) + **/ +function get_weblogs_updatedfile() { + global $ignore_weblogs_cache,ABSPATH; + $update = false; + + if ($ignore_weblogs_cache) { + $update = true; + } else { + if (file_exists(get_settings('weblogs_cache_file'))) { + // is it old? + $modtime = filemtime(get_settings('weblogs_cache_file')); + if ((time() - $modtime) > (get_settings('weblogs_cacheminutes') * 60)) { + $update = true; + } + } else { // doesn't exist + $update = true; + } + } + + if ($update) { + // get a new copy + $a = @file(get_settings('weblogs_xml_url')); + if ($a != false && count($a) && $a[0]) { + $contents = implode('', $a); + + // Clean up the input, because weblogs.com doesn't output clean XML + $contents = preg_replace("/'/",''',$contents); + $contents = preg_replace('|[^[:space:][:punct:][:alpha:][:digit:]]|','',$contents); + + $cachefp = fopen(get_settings('weblogs_cache_file'), "w"); + fwrite($cachefp, $contents); + fclose($cachefp); + } else { + return false; //don't try to process + } + } + return $update; +} + +/** + ** startElement() + ** Callback function. Called at the start of a new xml tag. + **/ +function startElement($parser, $tagName, $attrs) { + global $updated_timestamp, $all_links; + if ($tagName == 'WEBLOGUPDATES') { + //convert 'updated' into php date variable + $updated_timestamp = strtotime($attrs['UPDATED']); + //echo('got timestamp of ' . gmdate('F j, Y, H:i:s', $updated_timestamp) . "\n"); + } else if ($tagName == 'WEBLOG') { + // is this url in our links? + $link_url = transform_url($attrs['URL']); + if (isset($all_links[$link_url])) { + $all_links[$link_url][1] = date('YmdHis', $updated_timestamp - $attrs['WHEN']); + //echo('set link id ' . $all_links[$link_url][0] . ' to date ' . $all_links[$link_url][1] . "\n"); + } + } +} + +/** + ** endElement() + ** Callback function. Called at the end of an xml tag. + **/ +function endElement($parser, $tagName) { + // nothing to do. +} + +/** + ** transform_url() + ** Transforms a url to a minimal identifier. + ** + ** Remove www, remove index.* or default.*, remove + ** trailing slash + **/ +function transform_url($url) { + global ABSPATH; + //echo("transform_url(): $url "); + $url = str_replace('www.', '', $url); + $url = str_replace('WWW.', '', $url); + $url = preg_replace('/(?:index|default)\.[a-z]{2,}/i', '', $url); + if (substr($url, -1, 1) == '/') { + $url = substr($url, 0, -1); + } + //echo(" now equals $url\n"); + return $url; +} // end transform_url + +// get/update the cache file. +// true return means new copy +if (get_weblogs_updatedfile()) { + //echo('
');
+	// pre-load the links
+	preload_links();
+
+	// Create an XML parser
+	$xml_parser = xml_parser_create();
+
+	// Set the functions to handle opening and closing tags
+	xml_set_element_handler($xml_parser, "startElement", "endElement");
+
+	// Open the XML file for reading
+	$fp = fopen(ABSPATH.get_settings('weblogs_cache_file'), "r")
+		  or die("Error reading XML data.");
+
+	// Read the XML file 16KB at a time
+	while ($data = fread($fp, 16384)) {
+		// Parse each 4KB chunk with the XML parser created above
+		xml_parse($xml_parser, $data, feof($fp))
+				or die(sprintf("XML error: %s at line %d",
+					xml_error_string(xml_get_error_code($xml_parser)),
+					xml_get_current_line_number($xml_parser)));
+	}
+
+	// Close the XML file
+	fclose($fp);
+
+	// Free up memory used by the XML parser
+	xml_parser_free($xml_parser);
+
+	// now update the db with latest times
+	update_links();
+
+	//echo('
'); +} // end if updated cache file + +?> \ No newline at end of file diff --git a/wp-includes/links.php b/wp-includes/links.php new file mode 100644 index 0000000000..6bdf464050 --- /dev/null +++ b/wp-includes/links.php @@ -0,0 +1,577 @@ +') - the html to output after the link + ** between (default ' ') - the html to output between the link/image + ** and it's description. Not used if no image or show_images == true + ** show_images (default true) - whether to show images (if defined). + ** orderby (default 'id') - the order to output the links. E.g. 'id', 'name', + ** 'url', 'description' or 'rating'. Or maybe owner. If you start the + ** name with an underscore the order will be reversed. + ** You can also specify 'rand' as the order which will return links in a + ** random order. + ** show_description (default true) - whether to show the description if + ** show_images=false/not defined + ** show_rating (default false) - show rating stars/chars + ** limit (default -1) - Limit to X entries. If not specified, all entries + ** are shown. + ** show_updated (default 0) - whether to show last updated timestamp + */ +function get_linksbyname($cat_name = "noname", $before = '', $after = '
', + $between = " ", $show_images = true, $orderby = 'id', + $show_description = true, $show_rating = false, + $limit = -1, $show_updated = 0) { + global $tablelinkcategories, $wpdb; + $cat_id = -1; + $results = $wpdb->get_results("SELECT cat_id FROM $tablelinkcategories WHERE cat_name='$cat_name'"); + if ($results) { + foreach ($results as $result) { + $cat_id = $result->cat_id; + } + } + get_links($cat_id, $before, $after, $between, $show_images, $orderby, + $show_description, $show_rating, $limit, $show_updated); +} + +function bool_from_yn($yn) { + if ($yn == 'Y') return 1; + return 0; +} + +/** function wp_get_linksbyname() + ** Gets the links associated with the named category. + ** Parameters: + ** category (no default) - The category to use. + **/ +function wp_get_linksbyname($category) { + global $wpdb, $tablelinkcategories; + + $cat = $wpdb->get_row("SELECT cat_id, cat_name, auto_toggle, show_images, show_description, " + . " show_rating, show_updated, sort_order, sort_desc, text_before_link, text_after_link, " + . " text_after_all, list_limit FROM $tablelinkcategories WHERE cat_name='$category'"); + if ($cat) { + if ($cat->sort_desc == 'Y') { + $cat->sort_order = '_'.$cat->sort_order; + } + get_links($cat->cat_id, $cat->text_before_link, $cat->text_after_all, + $cat->text_after_link, bool_from_yn($cat->show_images), $cat->sort_order, + bool_from_yn($cat->show_description), bool_from_yn($cat->show_rating), + $cat->list_limit, bool_from_yn($cat->show_updated)); + } +} // end wp_get_linksbyname + +/** function wp_get_links() + ** Gets the links associated with category n. + ** Parameters: + ** category (no default) - The category to use. + **/ +function wp_get_links($category) { + global $wpdb, $tablelinkcategories; + + $cat = $wpdb->get_row("SELECT cat_id, cat_name, auto_toggle, show_images, show_description, " + . " show_rating, show_updated, sort_order, sort_desc, text_before_link, text_after_link, " + . " text_after_all, list_limit FROM $tablelinkcategories WHERE cat_id=$category"); + if ($cat) { + if ($cat->sort_desc == 'Y') { + $cat->sort_order = '_'.$cat->sort_order; + } + get_links($cat->cat_id, $cat->text_before_link, $cat->text_after_all, + $cat->text_after_link, bool_from_yn($cat->show_images), $cat->sort_order, + bool_from_yn($cat->show_description), bool_from_yn($cat->show_rating), + $cat->list_limit, bool_from_yn($cat->show_updated)); + } +} // end wp_get_links + +/** function get_links() + ** Gets the links associated with category n. + ** Parameters: + ** category (default -1) - The category to use. If no category supplied + ** uses all + ** before (default '') - the html to output before the link + ** after (default '
') - the html to output after the link + ** between (default ' ') - the html to output between the link/image + ** and it's description. Not used if no image or show_images == true + ** show_images (default true) - whether to show images (if defined). + ** orderby (default 'id') - the order to output the links. E.g. 'id', 'name', + ** 'url', 'description', or 'rating'. Or maybe owner. If you start the + ** name with an underscore the order will be reversed. + ** You can also specify 'rand' as the order which will return links in a + ** random order. + ** show_description (default true) - whether to show the description if + ** show_images=false/not defined . + ** show_rating (default false) - show rating stars/chars + ** limit (default -1) - Limit to X entries. If not specified, all entries + ** are shown. + ** show_updated (default 0) - whether to show last updated timestamp + */ +function get_links($category = -1, $before = '', $after = '
', + $between = ' ', $show_images = true, $orderby = 'name', + $show_description = true, $show_rating = false, + $limit = -1, $show_updated = 1, $echo = true) { + + global $tablelinks, $wpdb; + + $direction = ' ASC'; + $category_query = ""; + if ($category != -1) { + $category_query = " AND link_category = $category "; + } + if (get_settings('links_recently_updated_time')) { + $recently_updated_test = ", IF (DATE_ADD(link_updated, INTERVAL ".get_settings('links_recently_updated_time')." MINUTE) >= NOW(), 1,0) as recently_updated "; + } + if ($show_updated) { + $get_updated = ", UNIX_TIMESTAMP(link_updated) AS link_updated_f "; + } + + $orderby=strtolower($orderby); + if ($orderby == '') + $orderby = 'id'; + if (substr($orderby,0,1) == '_') { + $direction = ' DESC'; + $orderby = substr($orderby,1); + } + + switch($orderby) { + case 'length': + $length = ",CHAR_LENGTH(link_name) AS length"; + break; + case 'rand': + $orderby = 'rand()'; + break; + default: + $orderby = " link_" . $orderby; + } + + if (!isset($length)) { + $length = ""; + } + + $sql = "SELECT link_url, link_name, link_image, link_target, + link_description, link_rating, link_rel $length $recently_updated_test $get_updated + FROM $tablelinks + WHERE link_visible = 'Y' " . + $category_query; + $sql .= ' ORDER BY ' . $orderby; + $sql .= $direction; + /* The next 2 lines implement LIMIT TO processing */ + if ($limit != -1) + $sql .= " LIMIT $limit"; + //echo $sql; + $results = $wpdb->get_results($sql); + if (!$results) { + return; + } + foreach ($results as $row) { + echo($before); + if ($show_updated && $row->recently_updated) { + echo get_settings('links_recently_updated_prepend'); + } + $the_link = '#'; + if (($row->link_url != null) && ($row->link_url != '')) { + $the_link = htmlspecialchars(stripslashes($row->link_url)); + } + $rel = stripslashes($row->link_rel); + if ($rel != '') { + $rel = " rel='$rel'"; + } + $desc = htmlspecialchars(stripslashes($row->link_description), ENT_QUOTES); + if ($show_updated) { + if (substr($row->link_updated_f,0,2) != '00') { + $desc .= ' (Last updated ' . date(get_settings('links_updated_date_format'), $row->link_updated_f + (get_settings('time_difference') * 3600)) .')'; + } + } + if ('' != $desc) { + $desc = " title='$desc'"; + } + + $target = $row->link_target; + if ('' != $target) { + $target = " target='$target'"; + } + echo("'); + if (($row->link_image != null) && $show_images) { + echo("link_image\" border=\"0\" alt=\"" . + stripslashes($row->link_name) . "\" title=\"" . + stripslashes($row->link_description) . "\" />"); + } else { + echo(stripslashes($row->link_name)); + } + echo(''); + if ($show_updated && $row->recently_updated) { + echo get_settings('links_recently_updated_append'); + } + + if ($show_description && ($row->link_description != '')) { + echo($between.stripslashes($row->link_description)); + } + + // now do the rating + if ($show_rating) { + + if (get_settings('links_rating_type') == 'number') { + if (($row->link_rating != 0) || (get_settings('links_rating_ignore_zero') != 1)) { + echo($between." $row->link_rating\n"); + } + } else if (get_settings('links_rating_type') == 'char') { + echo($between); + for ($r = $row->link_rating; $r > 0; $r--) { + echo(get_settings('links_rating_char')); + } + } else if (get_settings('links_rating_type') == 'image') { + echo($between); + if (get_settings('links_rating_single_image')) { + for ($r = $row->link_rating; $r > 0; $r--) { + echo(' ' .
+                             $row->link_rating.''."\n"); + } + } else { + if (($row->link_rating != 0) || (get_settings('links_rating_ignore_zero') != 1)) { + $b = 'links_rating_image'.$row->link_rating; + echo(' ' .
+                             $row->link_rating.''."\n"); + } + } + } // end if image + } // end if show_rating + echo("$after\n"); + } // end while +} + + +/** function get_linkobjectsbyname() + ** Gets an array of link objects associated with category 'cat_name'. + ** Parameters: + ** cat_name (default 'noname') - The category name to use. If no + ** match is found uses all + ** orderby (default 'id') - the order to output the links. E.g. 'id', 'name', + ** 'url', 'description', or 'rating'. Or maybe owner. If you start the + ** name with an underscore the order will be reversed. + ** You can also specify 'rand' as the order which will return links in a + ** random order. + ** limit (default -1) - Limit to X entries. If not specified, all entries + ** are shown. + ** + ** Use this like: + ** $links = get_linkobjectsbyname('fred'); + ** foreach ($links as $link) { + ** echo '
  • '.stripslashes($link->link_name).'
  • '; + ** } + **/ +function get_linkobjectsbyname($cat_name = "noname" , $orderby = 'name', $limit = -1) { + global $tablelinkcategories, $wpdb; + $cat_id = -1; + $results = $wpdb->get_results("SELECT cat_id FROM $tablelinkcategories WHERE cat_name='$cat_name'"); + if ($results) { + foreach ($results as $result) { + $cat_id = $result->cat_id; + } + } + return get_linkobjects($cat_id, $orderby, $limit); +} + +/** function get_linkobjects() + ** Gets an array of link objects associated with category n. + ** Parameters: + ** category (default -1) - The category to use. If no category supplied + ** uses all + ** orderby (default 'id') - the order to output the links. E.g. 'id', 'name', + ** 'url', 'description', or 'rating'. Or maybe owner. If you start the + ** name with an underscore the order will be reversed. + ** You can also specify 'rand' as the order which will return links in a + ** random order. + ** limit (default -1) - Limit to X entries. If not specified, all entries + ** are shown. + ** + ** Use this like: + ** $links = get_linkobjects(1); + ** if ($links) { + ** foreach ($links as $link) { + ** echo '
  • '.$link->link_name.'
    '.$link->link_description.'
  • '; + ** } + ** } + ** Fields are: + ** link_id + ** link_url + ** link_name + ** link_image + ** link_target + ** link_category + ** link_description + ** link_visible + ** link_owner + ** link_rating + ** link_updated + ** link_rel + ** link_notes + **/ +function get_linkobjects($category = -1, $orderby = 'name', $limit = -1) { + global $tablelinks, $wpdb; + + $sql = "SELECT * FROM $tablelinks WHERE link_visible = 'Y'"; + if ($category != -1) { + $sql .= " AND link_category = $category "; + } + if ($orderby == '') + $orderby = 'id'; + if (substr($orderby,0,1) == '_') { + $direction = ' DESC'; + $orderby = substr($orderby,1); + } + if (strcasecmp('rand',$orderby) == 0) { + $orderby = 'rand()'; + } else { + $orderby = " link_" . $orderby; + } + $sql .= ' ORDER BY ' . $orderby; + $sql .= $direction; + /* The next 2 lines implement LIMIT TO processing */ + if ($limit != -1) + $sql .= " LIMIT $limit"; + + $results = $wpdb->get_results($sql); + if ($results) { + foreach ($results as $result) { + $result->link_url = stripslashes($result->link_url); + $result->link_name = stripslashes($result->link_name); + $result->link_description = stripslashes($result->link_description); + $result->link_notes = stripslashes($result->link_notes); + $newresults[] = $result; + } + } + return $newresults; +} + +/** function get_linkrating() + ** Returns the appropriate html for the link rating based on the configuration. + ** Parameters: + ** link - The link object returned from get_linkobjects + **/ +function get_linkrating($link) { + if (get_settings('links_rating_type') == 'number') { + if (($link->link_rating != 0) || (get_settings('links_rating_ignore_zero') != 1)) { + $s = "$link->link_rating"; + } + } else if (get_settings('links_rating_type') == 'char') { + for ($r = $link->link_rating; $r > 0; $r--) { + $s .= get_settings('links_rating_char'); + } + } else if (get_settings('links_rating_type') == 'image') { + if (get_settings('links_rating_single_image')) { + for ($r = $link->link_rating; $r > 0; $r--) { + $s .= '' .
+                      $link->link_rating.''."\n"; + } + } else { + if (($link->link_rating != 0) || (get_settings('links_rating_ignore_zero') != 1)) { + $b = 'links_rating_image'.$row->link_rating; + $s = ' ' .
+                     $link->link_rating.''."\n"; + } + } + } // end if image + return $s; +} + + +/** function get_linksbyname_withrating() + ** Gets the links associated with category 'cat_name' and display rating stars/chars. + ** Parameters: + ** cat_name (default 'noname') - The category name to use. If no + ** match is found uses all + ** before (default '') - the html to output before the link + ** after (default '
    ') - the html to output after the link + ** between (default ' ') - the html to output between the link/image + ** and it's description. Not used if no image or show_images == true + ** show_images (default true) - whether to show images (if defined). + ** orderby (default 'id') - the order to output the links. E.g. 'id', 'name', + ** 'url' or 'description'. Or maybe owner. If you start the + ** name with an underscore the order will be reversed. + ** You can also specify 'rand' as the order which will return links in a + ** random order. + ** show_description (default true) - whether to show the description if + ** show_images=false/not defined + ** limit (default -1) - Limit to X entries. If not specified, all entries + ** are shown. + ** show_updated (default 0) - whether to show last updated timestamp + */ +function get_linksbyname_withrating($cat_name = "noname", $before = '', + $after = '
    ', $between = " ", + $show_images = true, $orderby = 'id', + $show_description = true, $limit = -1, $show_updated = 0) { + + get_linksbyname($cat_name, $before, $after, $between, $show_images, + $orderby, $show_description, true, $limit, $show_updated); +} + +/** function get_links_withrating() + ** Gets the links associated with category n and display rating stars/chars. + ** Parameters: + ** category (default -1) - The category to use. If no category supplied + ** uses all + ** before (default '') - the html to output before the link + ** after (default '
    ') - the html to output after the link + ** between (default ' ') - the html to output between the link/image + ** and it's description. Not used if no image or show_images == true + ** show_images (default true) - whether to show images (if defined). + ** orderby (default 'id') - the order to output the links. E.g. 'id', 'name', + ** 'url' or 'description'. Or maybe owner. If you start the + ** name with an underscore the order will be reversed. + ** You can also specify 'rand' as the order which will return links in a + ** random order. + ** show_description (default true) - whether to show the description if + ** show_images=false/not defined . + ** limit (default -1) - Limit to X entries. If not specified, all entries + ** are shown. + ** show_updated (default 0) - whether to show last updated timestamp + */ +function get_links_withrating($category = -1, $before = '', $after = '
    ', + $between = " ", $show_images = true, + $orderby = 'id', $show_description = true, + $limit = -1, $show_updated = 0) { + + get_links($category, $before, $after, $between, $show_images, $orderby, + $show_description, true, $limit, $show_updated); +} + +/** function get_linkcatname() + ** Gets the name of category n. + ** Parameters: id (default 0) - The category to get. If no category supplied + ** uses 0 + */ +function get_linkcatname($id = 0) { + global $tablelinkcategories, $wpdb; + $cat_name = ''; + if ('' != $id) { + $cat_name = $wpdb->get_var("SELECT cat_name FROM $tablelinkcategories WHERE cat_id=$id"); + } + return stripslashes($cat_name); +} + +/** function get_get_autotoggle() + ** Gets the auto_toggle setting of category n. + ** Parameters: id (default 0) - The category to get. If no category supplied + ** uses 0 + */ +function get_autotoggle($id = 0) { + global $tablelinkcategories, $wpdb; + $auto_toggle = $wpdb->get_var("SELECT auto_toggle FROM $tablelinkcategories WHERE cat_id=$id"); + if ('' == $auto_toggle) + $auto_toggle = 'N'; + return $auto_toggle; +} + +/** function links_popup_script() + ** This function contributed by Fullo -- http://sprite.csr.unibo.it/fullo/ + ** Show the link to the links popup and the number of links + ** Parameters: + ** text (default Links) - the text of the link + ** width (default 400) - the width of the popup window + ** height (default 400) - the height of the popup window + ** file (default linkspopup.php) - the page to open in the popup window + ** count (default true) - the number of links in the db + */ +function links_popup_script($text = 'Links', $width=400, $height=400, + $file='links.all.php', $count = true) { + global $tablelinks; + if ($count == true) { + $counts = $wpdb->get_var("SELECT count(*) FROM $tablelinks"); + } + + $javascript = ""; + $javascript .= $text; + + if ($count == true) { + $javascript .= " ($counts)"; + } + + $javascript .="\n\n"; + echo $javascript; +} + + +/* + * function get_links_list() + * + * added by Dougal + * + * Output a list of all links, listed by category, using the + * settings in $tablelinkcategories and output it as a nested + * HTML unordered list. + * + * Parameters: + * order (default 'name') - Sort link categories by 'name' or 'id' + * hide_if_empty (default true) - Supress listing empty link categories + */ +function get_links_list($order = 'name', $hide_if_empty = true) { + global $tablelinkcategories, $tablelinks, $wpdb; + + $order = strtolower($order); + + // Handle link category sorting + if (substr($order,0,1) == '_') { + $direction = ' DESC'; + $order = substr($order,1); + } + + // if 'name' wasn't specified, assume 'id': + $cat_order = ('name' == $order)?'cat_name':'cat_id'; + + if ($hide_if_empty) { + $extra_join = "LEFT JOIN $tablelinks ON link_category = cat_id"; + $group_by_having = 'GROUP BY cat_id HAVING count(link_id) > 0'; + } + + // Fetch the link category data as an array of hashes + $cats = $wpdb->get_results("SELECT cat_id, cat_name, show_images, + show_description, show_rating, show_updated, sort_order, sort_desc, list_limit + FROM $tablelinkcategories $extra_join + $group_by_having + ORDER BY $cat_order $direction ",ARRAY_A); + + // Display each category + if ($cats) { + // Start the unordered list + echo "
      \n"; + + foreach ($cats as $cat) { + // Handle each category. + + // First, fix the sort_order info + $orderby = $cat['sort_order']; + $orderby = (bool_from_yn($cat['sort_desc'])?'_':'') . $orderby; + + // Display the category name + echo '
    • ' . stripslashes($cat['cat_name']) . "\n
        \n"; + + // Call get_links() with all the appropriate params + get_links($cat['cat_id'], + '
      • ',"
      • ","\n", + bool_from_yn($cat['show_images']), + $orderby, + bool_from_yn($cat['show_description']), + bool_from_yn($cat['show_rating']), + $cat['list_limit'], + bool_from_yn($cat['show_updated'])); + + // Close the last category + echo "
      \n
    • \n"; + + } + // Close out our category list. + echo "
    \n"; + } +} + +?> \ No newline at end of file diff --git a/wp-settings.php b/wp-settings.php index 43ee596093..a1731b9415 100644 --- a/wp-settings.php +++ b/wp-settings.php @@ -27,7 +27,7 @@ require (ABSPATH . WPINC . '/functions.php'); require (ABSPATH . WPINC . '/template-functions.php'); require (ABSPATH . WPINC . '/class-xmlrpc.php'); require (ABSPATH . WPINC . '/class-xmlrpcs.php'); -require (ABSPATH . '/wp-links/links.php'); +require (ABSPATH . WPINC . '/links.php'); //setup the old globals from b2config.php //