Exemplo n.º 1
0
 function mySearchSql($var, $expr, $search, $addand = TRUE)
 {
     $sql = "";
     if (!empty($search)) {
         switch ($expr) {
             case "NLIKE":
                 $sql = "{$var} NOT LIKE " . $this->ds->qstr("%{$search}%");
                 break;
             case "EXACT":
                 $sql = "{$var} = " . $this->ds->qstr("{$search}");
                 break;
             case "RLIKE":
                 // default is RLIKE, need to protect for DBF's without RLIKE
                 if (preg_ispreg($search)) {
                     // invalid regex
                     return "";
                 }
                 if (DBF_TYPE == "mysql" or DBF_TYPE == "maxsql") {
                     $sql = "{$var} RLIKE " . $this->ds->qstr("{$search}");
                     break;
                 }
                 if (DBF_TYPE == "postgres7") {
                     $sql = "{$var} ~ " . $this->ds->qstr("{$search}");
                     break;
                 }
             case "NRLIKE":
                 if (preg_ispreg($search)) {
                     // invalid regex
                     return "";
                 }
                 if (DBF_TYPE == "mysql" or DBF_TYPE == "maxsql") {
                     $sql = "{$var} NOT RLIKE " . $this->ds->qstr("{$search}");
                     break;
                 }
                 if (DBF_TYPE == "postgres7") {
                     $sql = "{$var} NOT ~ " . $this->ds->qstr("{$search}");
                     break;
                 }
             case "LIKE":
                 $sql = "{$var} LIKE " . $this->ds->qstr("%{$search}%");
                 break;
             case "END":
                 $sql = "{$var} LIKE " . $this->ds->qstr("%{$search}");
                 break;
                 // default is START search
             // default is START search
             default:
                 $sql = "{$var} LIKE " . $this->ds->qstr("{$search}%");
         }
         // should there be an AND?
         if ($addand) {
             $sql = "AND " . $sql;
         }
     }
     return $sql;
 }
Exemplo n.º 2
0
 function run($data, $params)
 {
     global $prefs, $page_regex;
     // Grab and handle our Tiki parameters...
     extract($params, EXTR_SKIP);
     if (!isset($ignore)) {
         $ignore = '';
     }
     if (!isset($splitby)) {
         $splitby = '+';
     }
     if (!isset($skipext)) {
         $skipext = false;
     }
     if (!isset($debug)) {
         $debug = false;
     }
     if (!isset($collect)) {
         $collect = 'from';
     }
     if (!isset($table)) {
         $table = 'sep';
     }
     if (!isset($level)) {
         $level = '';
     }
     // for regexes and external wiki details, see tikilib.php
     if ($level == "strict") {
         $level_reg = '([A-Za-z0-9_])([\\.: A-Za-z0-9_\\-])*([A-Za-z0-9_])';
     } elseif ($level == "full") {
         $level_reg = '([A-Za-z0-9_]|[\\x80-\\xFF])([\\.: A-Za-z0-9_\\-]|[\\x80-\\xFF])*([A-Za-z0-9_]|[\\x80-\\xFF])';
     } elseif ($level == "complete") {
         $level_reg = '([^|\\(\\)])([^|\\(\\)](?!\\)\\)))*?([^|\\(\\)])';
     } elseif ($level == "custom" && $data != "") {
         if (preg_ispreg($data)) {
             // custom regular expression
             $level_reg = $data;
         } elseif ($debug == 2) {
             echo "{$data}: " . tra("non-valid custom regex") . "<br />";
         }
     } else {
         // default
         $level_reg = $page_regex;
     }
     // define the separator
     if ($table == 'br') {
         $break = "<br />";
     } elseif ($table == 'co') {
         $break = tra(", ");
     } else {
         $break = "sep";
     }
     // get array of fromPages to be ignored
     $ignorepages = explode($splitby, $ignore);
     // Currently we only look in wiki pages.
     // Wiki links in articles, blogs, etc are ignored.
     $query = "select distinct tl.`toPage`, tl.`fromPage` from `tiki_links` tl";
     $query .= " left join `tiki_pages` tp on (tl.`toPage` = tp.`pageName`)";
     $categories = $this->get_jail();
     if ($categories) {
         $query .= " inner join `tiki_objects` as tob on (tob.`itemId`= tl.`fromPage` and tob.`type`= ?) inner join `tiki_category_objects` as tc on (tc.`catObjectId`=tob.`objectId` and tc.`categId` IN(" . implode(', ', array_fill(0, count($categories), '?')) . "))";
     }
     $query .= " where tp.`pageName` is null";
     $result = $this->query($query, $categories ? array_merge(array('wiki page'), $categories) : array());
     $tmp = array();
     while ($row = $result->fetchRow()) {
         foreach ($ignorepages as $ipage) {
             // test whether a substring ignores this page, ignore case
             if (fnmatch(strtolower($ipage), strtolower($row['fromPage'])) === true) {
                 if ($debug == 2) {
                     // the "hardcore case"
                     echo $row['toPage'] . " [from: " . $row['fromPage'] . "]: " . tra("ignored") . "<br />";
                 } elseif ($debug) {
                     // add this page to the table
                     $tmp[] = array($row['toPage'], $row['fromPage'], "ignored");
                 }
                 continue 2;
                 // no need to test other ignorepages or toPages
             }
         }
         // foreach ignorepage
         // if toPage contains colon, and exloding yields two parts => external Wiki
         if ($skipext && strstr($row['toPage'], ':') !== false) {
             $parts = explode(':', $row['toPage']);
             if (count($parts) == 2) {
                 if ($debug == 2) {
                     echo $row['toPage'] . " [from: " . $row['fromPage'] . "]: " . tra("External Wiki") . "<br />";
                 } elseif ($debug) {
                     $tmp[] = array($row['toPage'], $row['fromPage'], "External Wiki");
                 }
                 continue;
             }
         }
         // $skipext
         $dashWikiWord = preg_match("/^(?<=[ \n\t\r\\,\\;]|^)([A-Z][a-z0-9_\\-€-ÿ]+[A-Z][a-z0-9_\\-€-ÿ]+[A-Za-z0-9\\-_€-ÿ]*)(?=\$|[ \n\t\r\\,\\;\\.])\$/", $row['toPage']);
         $WikiWord = preg_match("/^(?<=[ \n\t\r\\,\\;]|^)([A-Z][a-z0-9€-ÿ]+[A-Z][a-z0-9€-ÿ]+[A-Za-z0-9€-ÿ]*)(?=\$|[ \n\t\r\\,\\;\\.])\$/", $row['toPage']);
         // test whether toPage is a valid wiki page under current syntax
         if ($dashWikiWord && !$WikiWord) {
             // a Dashed-WikiWord, can we allow this?
             if ($prefs['feature_wikiwords'] != 'y' || $prefs['feature_wikiwords_usedash'] != 'y') {
                 if ($debug == 2) {
                     echo $row['toPage'] . " [from: " . $row['fromPage'] . "]: " . tra("dash-WikiWord") . "<br />";
                 } elseif ($debug) {
                     $tmp[] = array($row['toPage'], $row['fromPage'], "dash-WikiWord");
                 }
                 continue;
             }
         } elseif ($WikiWord) {
             // a WikiWord, can we allow this?
             if ($prefs['feature_wikiwords'] != 'y') {
                 if ($debug == 2) {
                     echo $row['toPage'] . " [from: " . $row['fromPage'] . "]: " . tra("WikiWord") . "<br />";
                 } elseif ($debug) {
                     $tmp[] = array($row['toPage'], $row['fromPage'], "WikiWord");
                 }
                 continue;
             }
         } else {
             // no WikiWord, we can now filter with the level parameter
             if (!preg_match("/^({$level_reg})\$/", $row['toPage'])) {
                 if ($debug == 2) {
                     echo $row['toPage'] . " [from: " . $row['fromPage'] . "]: " . tra("not in level") . "<br />";
                 } elseif ($debug) {
                     $tmp[] = array($row['toPage'], $row['fromPage'], "not in level");
                 }
                 continue;
             }
         }
         // dashWikiWord, WikiWord, normal link
         if (!$debug) {
             // a normal, valid WantedPage:
             $tmp[] = array($row['toPage'], $row['fromPage']);
         } elseif ($debug == 2) {
             echo $row['toPage'] . " [from: " . $row['fromPage'] . "]: " . tra("valid") . "<br />";
         }
         // in simple debug mode, valid links are ignored
     }
     // while (each entry in tiki_links is handled)
     unset($result);
     // free memory
     if ($debug == 2) {
         return tra("End of debug output.");
     }
     $out = array();
     $linkin = !$debug ? "((" : "~np~";
     // this is how toPages are handled
     $linkout = !$debug ? "))" : "~/np~";
     foreach ($tmp as $row) {
         // row[toPage, fromPage, reason]
         if ($debug) {
             // modified rejected toPages with reason
             $row[0] = "*" . tra($row[2]) . "* " . $row[0];
         }
         $row[0] = $linkin . $row[0] . $linkout;
         // toPages
         $row[1] = "((" . $row[1] . "))";
         // fromPages
         // two identical keys may exist, they can either be displayed
         // each in its own table row, or be collected in one cell, separated by
         // either comma or <br />
         if ($collect == 'from') {
             if ($break == "sep") {
                 // toPages separated in each row, there might be duplicates!!!
                 $out[] = array($row[0], $row[1]);
             } elseif (!array_key_exists($row[0], $out)) {
                 // multiple fromPages (for one toPage) might be in one row, this is the first
                 $out[$row[0]] = $row[1];
             } else {
                 // multiple fromPages might be in one row, this is a follow-up
                 $out[$row[0]] = $out[$row[0]] . $break . $row[1];
             }
         } else {
             // $collect == to
             if ($break == "sep") {
                 // fromPages separated in each row, there might be duplicates!!!
                 $out[] = array($row[1], $row[0]);
             } elseif (!array_key_exists($row[1], $out)) {
                 // multiple toPages (for one fromPage) might be in one row, this is the first
                 $out[$row[1]] = $row[0];
             } else {
                 // multiple toPages might be in one row, this is a follow-up
                 $out[$row[1]] = $out[$row[1]] . $break . $row[0];
             }
         }
     }
     // foreach (received row) is handled
     unset($tmp);
     // free memory
     // sort the entries
     if ($break == "sep") {
         sort($out);
     } else {
         ksort($out);
     }
     $sOutput = "||\n&nbsp;&nbsp;__";
     if ($collect == 'from') {
         $sOutput .= tra("Wanted Page") . "__&nbsp;&nbsp;|&nbsp;&nbsp;__" . tra("Referenced By Page") . "__&nbsp;&nbsp;\n";
         if ($break == "sep") {
             foreach ($out as $link) {
                 $sOutput .= "{$link['0']} | {$link['1']}\n";
             }
         } else {
             foreach ($out as $to => $from) {
                 $sOutput .= "{$to} | {$from}\n";
             }
         }
     } else {
         // $collect == 'to'
         $sOutput .= tra("Referenced By Page") . "__&nbsp;&nbsp;|&nbsp;&nbsp;__" . tra("Wanted Page") . "__&nbsp;&nbsp;\n";
         if ($break == "sep") {
             foreach ($out as $link) {
                 $sOutput .= "{$link['0']} | {$link['1']}\n";
             }
         } else {
             foreach ($out as $from => $to) {
                 $sOutput .= "{$from} | {$to}\n";
             }
         }
     }
     $sOutput .= "||";
     return $sOutput;
 }
	function run($data, $params)
	{
		global $prefs, $page_regex;
	
		// Grab and handle our Tiki parameters...
		extract($params, EXTR_SKIP);
		if (!isset($ignore)) {
			$ignore = '';
		}
		if (!isset($splitby)) {
			$splitby = '+';
		}
		if (!isset($skipext)) {
			$skipext = false;
		}
		if (!isset($debug)) {
			$debug = false;
		}
		if (!isset($collect)) {
			$collect = 'from';
		}
		if (!isset($table)) {
			$table = 'sep';
		}
		if (!isset($level)) {
			$level = '';
		}
	
		// for regexes and external wiki details, see tikilib.php
		if ($level == 'strict') {
			$level_reg = '([A-Za-z0-9_])([\.: A-Za-z0-9_\-])*([A-Za-z0-9_])';
		} elseif ($level == 'full') {
			$level_reg = '([A-Za-z0-9_]|[\x80-\xFF])([\.: A-Za-z0-9_\-]|[\x80-\xFF])*([A-Za-z0-9_]|[\x80-\xFF])';
		} elseif ($level == 'complete') {
			$level_reg = '([^|\(\)])([^|\(\)](?!\)\)))*?([^|\(\)])';
		} elseif (($level == 'custom') && ($data != '')) {
			if (preg_ispreg($data)) { // custom regular expression
				$level_reg = $data;
			} elseif ($debug == 2) {
				echo $data . ': ' . tra('non-valid custom regex') . '<br />';
			}
		} else { // default
			$level_reg = $page_regex;
		}
	
		// define the separator
		if ($table == 'br') {
			$break = '<br />';
		} elseif ($table == 'co') {
			$break = tra(', ');
		} else {
			$break = 'sep';
		}
	
		// get array of fromPages to be ignored
		$ignorepages = explode($splitby, $ignore);
	
		// Currently we only look in wiki pages.
		// Wiki links in articles, blogs, etc are ignored.
		$query = 'select distinct tl.`toPage`, tl.`fromPage` from `tiki_links` tl';
		$query .= ' left join `tiki_pages` tp on (tl.`toPage` = tp.`pageName`)';

		$categories = $this->get_jail();
		if ($categories)
			$query .= ' inner join `tiki_objects` as tob on (tob.`itemId`= tl.`fromPage` and tob.`type`= ?) inner join `tiki_category_objects` as tc on (tc.`catObjectId`=tob.`objectId` and tc.`categId` IN(' . implode(', ', array_fill(0, count($categories), '?')) . '))';
		$query .= ' where tp.`pageName` is null';
		$result = $this->query($query, $categories ? array_merge(array('wiki page'), $categories) : array());
		$tmp = array();
	
		while ($row = $result->fetchRow()) {
			foreach ($ignorepages as $ipage) {
				// test whether a substring ignores this page, ignore case
				if (fnmatch(TikiLib::strtolower($ipage), TikiLib::strtolower($row['fromPage'])) === true) {
					if ($debug == 2) { // the "hardcore case"
						echo $row['toPage'] . ' [from: ' . $row['fromPage'] . ']: ' . tra('ignored') . '<br />';
					} elseif ($debug) { // add this page to the table
						$tmp[] = array($row['toPage'], $row['fromPage'], 'ignored');
					}
					continue 2; // no need to test other ignorepages or toPages
				}
			} // foreach ignorepage
	
			// if toPage contains colon, and exloding yields two parts => external Wiki
			if (($skipext) && (strstr($row['toPage'], ':') !== false)) {
				$parts = explode(':', $row['toPage']);
				if (count($parts) == 2) {
					if ($debug == 2) {
						echo $row['toPage'] . ' [from: ' . $row['fromPage'] . ']: ' . tra('External Wiki') . '<br />';
					} elseif ($debug) {
						$tmp[] = array($row['toPage'], $row['fromPage'], 'External Wiki');
					}
					continue;
				}
			} // $skipext
	
			$dashWikiWord = preg_match("/^(?<=[ \n\t\r\,\;]|^)([A-Z][a-z0-9_\-\x80-\xFF]+[A-Z][a-z0-9_\-\x80-\xFF]+[A-Za-z0-9\-_\x80-\xFF]*)(?=$|[ \n\t\r\,\;\.])$/", $row['toPage']);
			$WikiWord = preg_match("/^(?<=[ \n\t\r\,\;]|^)([A-Z][a-z0-9\x80-\xFF]+[A-Z][a-z0-9\x80-\xFF]+[A-Za-z0-9\x80-\xFF]*)(?=$|[ \n\t\r\,\;\.])$/", $row['toPage']);
			// test whether toPage is a valid wiki page under current syntax
			if ($dashWikiWord && !$WikiWord) { // a Dashed-WikiWord, can we allow this?
				if (($prefs['feature_wikiwords'] != 'y') || ($prefs['feature_wikiwords_usedash'] != 'y')) {
					$tmp = debug_print($row, $debug, tra('dash-WikiWord'));
					continue;
				}
			} elseif ($WikiWord) { // a WikiWord, can we allow this?
				if ($prefs['feature_wikiwords'] != 'y') {
					$tmp = debug_print($row, $debug, tra('WikiWord'));
					continue;
				}
			} else { // no WikiWord, we can now filter with the level parameter
				if (!preg_match("/^($level_reg)$/", $row['toPage'])) {
					$tmp = debug_print($row, $debug, tra('not in level'));
					continue;
				}
			} // dashWikiWord, WikiWord, normal link
	
			if (!$debug) { // a normal, valid WantedPage:
				$tmp[] = array($row['toPage'], $row['fromPage']);
			} elseif ($debug == 2) {
				debug_print($row, $debug, tra('valid'));
			} // in simple debug mode, valid links are ignored
		} // while (each entry in tiki_links is handled)
		unset($result); // free memory
	
		if ($debug == 2) {
			return(tra('End of debug output.'));
		}
	
		$out = array();
		$linkin  = (!$debug) ? '((' : '~np~'; // this is how toPages are handled
		$linkout = (!$debug) ? '))' : '~/np~';
		foreach ($tmp as $row) { // row[toPage, fromPage, reason]
			if ($debug) { // modified rejected toPages with reason
				$row[0] = '<em>' . tra($row[2]) . '</em>: ' . $row[0];
			}
			$row[0] = $linkin . $row[0] . $linkout; // toPages
			$row[1] = '((' . $row[1] . '))'; // fromPages
	
			// two identical keys may exist, they can either be displayed
			// each in its own table row, or be collected in one cell, separated by
			// either comma or <br />
			if ($collect == 'from') {
				if ($break == 'sep') {
					// toPages separated in each row, there might be duplicates!!!
					$out[] = array($row[0], $row[1]);
				} elseif (!array_key_exists($row[0], $out)) {
					// multiple fromPages (for one toPage) might be in one row, this is the first
					$out[$row[0]] = $row[1];
				} else {
					// multiple fromPages might be in one row, this is a follow-up
					$out[$row[0]] = $out[$row[0]].$break.$row[1];
				}
			} else { // $collect == to
				if ($break == 'sep') {
					// fromPages separated in each row, there might be duplicates!!!
					$out[] = array($row[1], $row[0]);
				} elseif (!array_key_exists($row[1], $out)) {
					// multiple toPages (for one fromPage) might be in one row, this is the first
					$out[$row[1]] = $row[0];
				} else { // multiple toPages might be in one row, this is a follow-up
					$out[$row[1]] = $out[$row[1]] . $break . $row[0];
				}
			}
		} // foreach (received row) is handled
		unset($tmp); // free memory
	
		// sort the entries
		if ($break == 'sep') {
			sort($out);
		} else {
			ksort($out);
		}
		
		$headerwant = tra('Wanted Page');
		$headerref = tra('Referenced By Page');		
		$rowbreak = "\n";
		$endtable = '||';
		if ($prefs['feature_wiki_tables'] != 'new') {
			$rowbreak = ' || ';
			$endtable = ''; 
		}
	
		$sOutput = '||' . '&nbsp;&nbsp;__';
		if ($collect == 'from') {
			$sOutput .= $headerwant . '__&nbsp;&nbsp;|&nbsp;&nbsp;__' . $headerref . '__&nbsp;&nbsp;' . $rowbreak;
			if ($break == 'sep') {
				foreach ($out as $link) {
					$sOutput .= $link[0] . ' | ' . $link[1] . $rowbreak;
				}
			} else {
				foreach ($out as $to => $from) {
					$sOutput .= $to . ' | ' . $from . $rowbreak;
				}
			}
		} else { // $collect == 'to'
			$sOutput .= $headerref . '__&nbsp;&nbsp;|&nbsp;&nbsp;__' . $headerwant . '__&nbsp;&nbsp;' . $rowbreak;
			if ($break == 'sep') {
				foreach ($out as $link) {
					$sOutput .= $link[0] . ' | ' . $link[1] . $rowbreak;
				}
			} else {
				foreach ($out as $from => $to) {
					$sOutput .= $from . ' | ' . $to . $rowbreak;
				}
			}
		}
		$sOutput .= $endtable;
		return $sOutput;
	} // run()
Exemplo n.º 4
0
                                $where = "WHERE ipaddr.ipaddr=ipaddradd.ipaddr AND ipaddr.baseindex = ipaddradd.baseindex AND \n                 ipaddradd.info RLIKE " . $ds->ds->qstr($search);
                            } else {
                                if ($field == "template" and $tmplfield != "any") {
                                    $addtables = ", ipaddradd";
                                    $where = "WHERE ipaddr.ipaddr=ipaddradd.ipaddr AND ipaddr.baseindex = ipaddradd.baseindex AND\n                 ipaddradd.info RLIKE " . $ds->ds->qstr(".*\\:\"" . $tmplfield . "\"\\;.*\".*" . $search . ".*\"\\;");
                                }
                            }
                        }
                    }
                }
            }
        }
    }
} else {
    if (DBF_TYPE == "postgres7") {
        if (preg_ispreg($search)) {
            myError($w, $p, my_("Regular expression repetition-operator operand invalid"));
        }
        /*
           if ($field == "any") {
              $where ="WHERE ipaddr.userinf ~ ".$ds->ds->qstr($search);
              $where.=" OR ipaddr.location ~ ".$ds->ds->qstr($search);
              $where.=" OR ipaddr.telno ~ ".$ds->ds->qstr($search);
              $where.=" OR ipaddr.descrip ~ ".$ds->ds->qstr($search);
              $where.=" OR ipaddr.hname ~ ".$ds->ds->qstr($search);
              $where.=" OR (ipaddr.ipaddr=ipaddradd.ipaddr AND 
                         ipaddradd.info ~ ".$ds->ds->qstr($search).")";
           }
           else */
        if ($field == "userinf") {
            $where = "WHERE ipaddr.userinf ~ " . $ds->ds->qstr($search);