Author: glen                         Date: Thu Jul 22 09:30:46 2010 GMT
Module: packages                      Tag: HEAD
---- Log message:
- initial plugin for building best article url. issue 33426

---- Files affected:
packages:
   function.alturl.php (NONE -> 1.1)  (NEW)

---- Diffs:

================================================================
Index: packages/function.alturl.php
diff -u /dev/null packages/function.alturl.php:1.1
--- /dev/null   Thu Jul 22 11:30:46 2010
+++ packages/function.alturl.php        Thu Jul 22 11:30:40 2010
@@ -0,0 +1,79 @@
+<?php
+/*
+ * @see: https://eventum.dev.delfi.ee/view.php?id=33426
+ *
+ * Pick best match from alturls
+ *
+ * alturls structure:
+ * <code>
+ * array(
+ *  1 => array(
+ *      120 => 
http://www.elfride.delfi.ee/news/paevauudised/eesti/sorra-eesti-siga-tahab-et-eestlane-ta-ara-sooks.d?id=30440255,
+ *  ),
+ *  3 => array(
+ *      150312 => 
http://naistekas.delfi.ee/suhted/suhted/sorra-eesti-siga-tahab-et-eestlane-ta-ara-sooks.d?id=30440255,
+ *      150034 => 
http://naistekas.delfi.ee/suhted/seks/sorra-eesti-siga-tahab-et-eestlane-ta-ara-sooks.d?id=30440255,
+ *  ),
+ *  11 => array(
+ *      7591174 => 
http://taheke.delfi.ee/meelelahutus/nuputa/sorra-eesti-siga-tahab-et-eestlane-ta-ara-sooks.d?id=30440255,
+ *  ),
+ * )
+ * </code>
+ */
+
+function smarty_function_alturl($params, &$smarty)
+{
+       // allows us to debug input
+       if (!empty($params['debug'])) {
+               echo "<pre>Smarty::function::alturl: ", print_r($params, 1), 
"</pre>";
+       }
+
+       foreach (array('alturls', 'url') as $param) {
+               if (empty($params[$param])) {
+                       $smarty->_trigger_fatal_error("[plugin] parameter 
'$param' cannot be empty");
+                       return;
+               }
+               $$param = $params[$param];
+               unset($params[$param]);
+       }
+       foreach (array('channel', 'category', 'debug') as $param) {
+               // optional params default to 0
+               $$param = !empty($params[$param]) ? (int )$params[$param] : 0;
+               unset($params[$param]);
+       }
+
+       if (!empty($params)) {
+               $smarty->_trigger_fatal_error("[plugin] unknown parameters: ". 
join(',', array_keys($params)));
+               return;
+       }
+
+#      if ($debug) {
+#              echo "<pre>vars:";
+#              unset($smarty);
+#              unset($params);
+#              print_r(get_defined_vars());
+#              echo "</pre>";
+#      }
+
+       // empty channel id, we have no way pick anything
+       if (!$channel) {
+               return $url;
+       }
+
+       // direct match
+       if (isset($alturls[$channel][$category])) {
+               return $alturls[$channel][$category];
+       }
+
+       // fist from matching channel
+       foreach ($alturls as $k => $v) {
+               if ($k == $channel) {
+                       foreach ($v as $url) {
+                               return $url;
+                       }
+               }
+       }
+
+       // just return url
+       return $url;
+}
================================================================
_______________________________________________
pld-cvs-commit mailing list
[email protected]
http://lists.pld-linux.org/mailman/listinfo/pld-cvs-commit

Reply via email to