diff --git a/include/ajax.forms.php b/include/ajax.forms.php index def1436d36c6a19fd29d02468f3a65c9891566d3..3217124435bbe624bd297b85738cc67b395ec717 100644 --- a/include/ajax.forms.php +++ b/include/ajax.forms.php @@ -32,7 +32,9 @@ class DynamicFormsAjaxAPI extends AjaxController { if (!$form->hasAnyVisibleFields()) continue; ob_start(); - $form->getForm($_SESSION[':form-data'])->render(!$client); + $form->getForm($_SESSION[':form-data'])->render(array( + 'staff' => !$client, + 'mode' => 'create')); $html .= ob_get_clean(); ob_start(); print $form->getMedia(); diff --git a/include/ajax.users.php b/include/ajax.users.php index c4e32cc9155e963911511ee081f9d3bd39712fcf..4e090889ad431b1efcf4aba157e652fd0523120b 100644 --- a/include/ajax.users.php +++ b/include/ajax.users.php @@ -73,19 +73,24 @@ class UsersAjaxAPI extends AjaxController { return $this->search($type, $fulltext); } } else { - $users->filter(Q::any(array( + $filter = Q::any(array( 'emails__address__contains' => $q, 'name__contains' => $q, 'org__name__contains' => $q, - 'cdata__phone__contains' => $q, - ))); + 'account__username__contains' => $q, + )); + if (UserForm::getInstance()->getField('phone')) { + UserForm::ensureDynamicDataView(); + $filter->add(array('cdata__phone__contains' => $q)); + } + + $users->filter($filter); } // Omit already-imported remote users if ($emails = array_filter($emails)) { $users->union(User::objects() ->values_flat('id', 'name', 'default_email__address') - ->annotate(array('__relevance__' => new SqlCode(1))) ->filter(array( 'emails__address__in' => $emails ))); diff --git a/include/class.crypto.php b/include/class.crypto.php index b169cbb29f4986fa40a989d73a8237e943ac0746..2fd967dba66a990bd8922b504a47492dc2a128da 100644 --- a/include/class.crypto.php +++ b/include/class.crypto.php @@ -69,7 +69,7 @@ class Crypto { * is only really useful for testing. The crypto library will be * automatically selected based on the available PHP extensions. */ - function encrypt($input, $key, $skey='encryption', $crypt=null) { + static function encrypt($input, $key, $skey='encryption', $crypt=null) { //Gets preffered crypto. if(!($crypto = Crypto::get($crypt))) @@ -97,7 +97,7 @@ class Crypto { * skey - (string_ sub key or namespace used originally for the * encryption */ - function decrypt($ciphertext, $key, $skey='encryption') { + static function decrypt($ciphertext, $key, $skey='encryption') { if(!$key || !$ciphertext || $ciphertext[0] != '$') return false; @@ -112,7 +112,7 @@ class Crypto { return $crypto->decrypt(base64_decode($ciphertext)); } - function get($crypt) { + static function get($crypt) { $cryptos = self::cryptos(); if(!$cryptos || ($crypt && !isset($cryptos[$crypt]))) @@ -133,7 +133,7 @@ class Crypto { * Returns list of supported cryptos * */ - function cryptos() { + static function cryptos() { static $cryptos = false; @@ -153,7 +153,7 @@ class Crypto { return $cryptos; } - function hash($string, $key) { + static function hash($string, $key) { $hash = new Crypt_Hash('sha512'); $hash->setKey($key); return $hash->hash($string); @@ -164,7 +164,7 @@ class Crypto { Credit: The routine borrows heavily from PHPSecLib's Crypt_Random package. */ - function random($len) { + static function random($len) { if(CRYPT_IS_WINDOWS) { if (function_exists('openssl_random_pseudo_bytes') diff --git a/include/class.dynamic_forms.php b/include/class.dynamic_forms.php index c47433fa371dcef4bdc14f644a03506d6895a9e0..f7f73a2682e1d83b2f45b34459de401ecd17c7b0 100644 --- a/include/class.dynamic_forms.php +++ b/include/class.dynamic_forms.php @@ -1171,8 +1171,9 @@ class DynamicFormEntry extends VerySimpleModel { ->filter(array('object_id'=>$object_id, 'object_type'=>$object_type)); } - function render($staff=true, $title=false, $options=array()) { - return $this->getForm()->render($staff, $title, $options); + function render($options=array()) { + $options += array('staff' => true); + return $this->getForm()->render($options); } function getChanges() { diff --git a/include/class.export.php b/include/class.export.php index 21e89bf809212a978ec92b83de4a5f9beb647c48..7721862600fb2f1adc5a3d167bb3a72622101dd1 100644 --- a/include/class.export.php +++ b/include/class.export.php @@ -328,7 +328,7 @@ class ResultSetExporter { function dump() { # Useful for debug output while ($row=$this->nextArray()) { - var_dump($row); + var_dump($row); //nolint } } } diff --git a/include/class.filter.php b/include/class.filter.php index 64ad3625db96aa98eb900b2d45ce68957361ea59..2ac1a0a686a6f3d45fd86ce93d250d19cfb6ebe3 100644 --- a/include/class.filter.php +++ b/include/class.filter.php @@ -803,7 +803,7 @@ class TicketFilter { * http://msdn.microsoft.com/en-us/library/ee219609(v=exchg.80).aspx */ /* static */ - function isAutoReply($headers) { + static function isAutoReply($headers) { if($headers && !is_array($headers)) $headers = Mail_Parse::splitHeaders($headers); diff --git a/include/class.forms.php b/include/class.forms.php index 02d59862cc8170d2e2b02ba6aa7219cd304965e7..084ff7cd9c5c6e1432ece39484994f0517922885 100644 --- a/include/class.forms.php +++ b/include/class.forms.php @@ -162,14 +162,14 @@ class Form { $this->validators[] = $function; } - function render($staff=true, $title=false, $options=array()) { - if ($title) - $this->title = $title; + function render($options=array()) { + if (isset($options['title'])) + $this->title = $options['title']; if (isset($options['instructions'])) $this->instructions = $options['instructions']; $form = $this; $template = $options['template'] ?: 'dynamic-form.tmpl.php'; - if ($staff) + if (isset($options['staff']) && $options['staff']) include(STAFFINC_DIR . 'templates/' . $template); else include(CLIENTINC_DIR . 'templates/' . $template); @@ -3905,7 +3905,7 @@ class FileUploadWidget extends Widget { ), ); - function render($options) { + function render($options=array()) { $config = $this->field->getConfiguration(); $name = $this->field->getFormName(); $id = substr(md5(spl_object_hash($this)), 10); @@ -4363,7 +4363,7 @@ class AssignmentForm extends Form { return !$this->errors(); } - function render($options) { + function render($options=array()) { switch(strtolower($options['template'])) { case 'simple': @@ -4493,7 +4493,7 @@ class TransferForm extends Form { return !$this->errors(); } - function render($options) { + function render($options=array()) { switch(strtolower($options['template'])) { case 'simple': diff --git a/include/class.mailparse.php b/include/class.mailparse.php index 1564cc07735a2d7460d65eaff8d4935c15ecd668..326c401e208faf3b212c9cf6e562ed3e0e15d8f1 100644 --- a/include/class.mailparse.php +++ b/include/class.mailparse.php @@ -152,7 +152,7 @@ class Mail_Parse { * the header key. If left as FALSE, only the value given in the last * occurance of the header is retained. */ - /* static */ function splitHeaders($headers_text, $as_array=false) { + static function splitHeaders($headers_text, $as_array=false) { $headers = preg_split("/\r?\n/", $headers_text); for ($i=0, $k=count($headers); $i<$k; $i++) { // first char might be whitespace (" " or "\t") diff --git a/include/client/edit.inc.php b/include/client/edit.inc.php index 6f364db394f3acaff7c52557764108802578b63e..27ae212eeaceeaf999174c23f43bdd58c6d58ea6 100644 --- a/include/client/edit.inc.php +++ b/include/client/edit.inc.php @@ -16,7 +16,7 @@ if(!defined('OSTCLIENTINC') || !$thisclient || !$ticket || !$ticket->checkUserAc <tbody id="dynamic-form"> <?php if ($forms) foreach ($forms as $form) { - $form->render(false); + $form->render(['staff' => false]); } ?> </tbody> </table> diff --git a/include/client/open.inc.php b/include/client/open.inc.php index d0f4c24d55bb14a8535221d6ac7fae75ccf79a85..a2858edd99db8940cf9a852c7d712d4c2d888362 100644 --- a/include/client/open.inc.php +++ b/include/client/open.inc.php @@ -42,7 +42,7 @@ if ($info['topicId'] && ($topic=Topic::lookup($info['topicId']))) { if (!$thisclient) { $uform = UserForm::getUserForm()->getForm($_POST); if ($_POST) $uform->isValid(); - $uform->render(false); + $uform->render(array('staff' => false)); } else { ?> <tr><td colspan="2"><hr /></td></tr> diff --git a/include/client/profile.inc.php b/include/client/profile.inc.php index 5a72f571033c02035b16c1505a4ca1f4d90dd749..c86becf95d4a369f87b9b51ee88942a237bd0ca2 100644 --- a/include/client/profile.inc.php +++ b/include/client/profile.inc.php @@ -8,7 +8,7 @@ <table width="800" class="padded"> <?php foreach ($user->getForms() as $f) { - $f->render(false); + $f->render(['staff' => false]); } if ($acct = $thisclient->getAccount()) { $info=$acct->getInfo(); diff --git a/include/client/register.inc.php b/include/client/register.inc.php index 4f683c718d8fc27cb7404ae21f722a289f51967a..a08e35fc910061156b7b9e4ee44012cf2133f3c0 100644 --- a/include/client/register.inc.php +++ b/include/client/register.inc.php @@ -27,7 +27,7 @@ $info = Format::htmlchars(($errors && $_POST)?$_POST:$info); <tbody> <?php $cf = $user_form ?: UserForm::getInstance(); - $cf->render(false, false, array('mode' => 'create')); + $cf->render(array('staff' => false, 'mode' => 'create')); ?> <tr> <td colspan="2"> diff --git a/include/staff/templates/org-lookup.tmpl.php b/include/staff/templates/org-lookup.tmpl.php index 07d6c7687f8d559d44c4fb0eb761b04c8d4ed58f..21a3f55fc018f968df6f9c9b88be5574d90d5e00 100644 --- a/include/staff/templates/org-lookup.tmpl.php +++ b/include/staff/templates/org-lookup.tmpl.php @@ -70,7 +70,7 @@ if ($info['error']) { <table width="100%" class="fixed"> <?php if (!$form) $form = OrganizationForm::getInstance(); - $form->render(true, __('Create New Organization')); ?> + $form->render(array('staff' => true, 'title' => __('Create New Organization'))); ?> </table> <hr> <p class="full-width"> diff --git a/include/staff/templates/user-lookup.tmpl.php b/include/staff/templates/user-lookup.tmpl.php index cfeeaddf65b5ce7640cef5158eac44a642e5c202..62547c99bc7e1d8e59f6222d3859116b89437a97 100644 --- a/include/staff/templates/user-lookup.tmpl.php +++ b/include/staff/templates/user-lookup.tmpl.php @@ -84,7 +84,7 @@ if ($user) { ?> <table width="100%" class="fixed"> <?php if(!$form) $form = UserForm::getInstance(); - $form->render(true, __('Create New User')); ?> + $form->render(['staff' => true, 'title' => __('Create New User')]); ?> </table> <hr> <p class="full-width"> diff --git a/include/staff/ticket-edit.inc.php b/include/staff/ticket-edit.inc.php index e15e8554d3d67afeea3ed47de83429638524dfbd..b082ab177dccf03ae72713654ce6dff6a9ef40d0 100644 --- a/include/staff/ticket-edit.inc.php +++ b/include/staff/ticket-edit.inc.php @@ -147,7 +147,7 @@ if ($_POST) <table class="form_table dynamic-forms" width="940" border="0" cellspacing="0" cellpadding="2"> <?php if ($forms) foreach ($forms as $form) { - $form->render(true, false, array('mode'=>'edit','width'=>160,'entry'=>$form)); + $form->render(array('staff'=>true,'mode'=>'edit','width'=>160,'entry'=>$form)); } ?> </table> <table class="form_table" width="940" border="0" cellspacing="0" cellpadding="2"> diff --git a/setup/test/tests/class.test.php b/setup/test/tests/class.test.php index 5dd6097dcb127a1a3391d36361872ed0e6b5dec2..8eec8a753a3d988f3b20b8eeeacd36ee8b6e73e2 100644 --- a/setup/test/tests/class.test.php +++ b/setup/test/tests/class.test.php @@ -31,10 +31,15 @@ class Test { function teardown() { } - static function getAllScripts($excludes=true, $root=false) { + static function ignore3rdparty() { + return true; + } + + static function getAllScripts($pattern='*.php', $root=false, $excludes=true) { $root = $root ?: get_osticket_root_path(); + $excludes = $excludes ?: static::ignore3rdparty(); $scripts = array(); - foreach (glob_recursive("$root/*.php") as $s) { + foreach (glob_recursive("$root/$pattern") as $s) { $found = false; if ($excludes) { foreach (self::$third_party_paths as $p) { @@ -64,11 +69,11 @@ class Test { fputs(STDOUT, 'w'); } - function assert($expr, $message) { + function assert($expr, $message=false) { if ($expr) $this->pass(); else - $this->fail('', '', $message); + $this->fail('', '', $message ?: 'Test case failed'); } function assertEqual($a, $b, $message=false) { @@ -88,20 +93,20 @@ class Test { foreach ($rc->getMethods() as $m) { if (stripos($m->name, 'test') === 0) { $this->setup(); - call_user_func(array($this, $m->name)); + @call_user_func(array($this, $m->name)); $this->teardown(); } } } - function line_number_for_offset($filename, $offset) { - $lines = file($filename); - $bytes = $line = 0; - while ($bytes < $offset) { - $bytes += strlen(array_shift($lines)); - $line += 1; - } - return $line; + function line_number_for_offset($file, $offset) { + + if (is_file($file)) + $content = file_get_contents($file, false, null, 0, $offset); + else + $content = @substr($file, 0, $offset); + + return count(explode("\n", $content)); } } diff --git a/setup/test/tests/stubs.php b/setup/test/tests/stubs.php index 0d59a25d9117449f1231f2735ae2f95aaca67d9a..c168b5da3dc980ef4bdd4e4aa4736672e77b5648 100644 --- a/setup/test/tests/stubs.php +++ b/setup/test/tests/stubs.php @@ -98,12 +98,17 @@ class DateTimeZone { static function listIdentifiers() {} } +class DateTimeImmutable { + function createFromMutable() {} +} + class Phar { static function isValidPharFilename() {} function setStub() {} function startBuffering() {} function stopBuffering() {} function setSignatureAlgorithm() {} + function compress() {} } class ZipArchive { @@ -114,6 +119,10 @@ class ZipArchive { function setExternalAttributesName() {} } +class Spyc { + function YAMLLoad() {} +} + class finfo { function file() {} function buffer() {} @@ -121,6 +130,7 @@ class finfo { class Locale { function getDisplayName() {} + function acceptFromHttp() {} } class IntlBreakIterator { static function createWordInstance() {} @@ -132,10 +142,12 @@ class SqlFunction { static function LENGTH() {} static function COALESCE() {} static function DATEDIFF() {} + static function timestampdiff() {} } class SqlExpression { static function plus() {} + static function minus() {} static function times() {} static function bitor() {} static function bitand() {} @@ -149,6 +161,8 @@ class SqlInterval { class SqlAggregate { static function COUNT() {} + static function SUM() {} + static function MAX() {} } class Q { @@ -171,6 +185,7 @@ class NumberFormatter { class Collator { function setStrength() {} + function compare() {} } class Aws_Route53_Client { @@ -184,4 +199,43 @@ class Memcache { function set() {} function get() {} } + +class Crypt_Hash { + function setKey() {} + function setIV() {} +} + +class Crypt_AES { + function setKey() {} + function setIV() {} + function enableContinuousBuffer() {} +} + +class PEAR { + function isError() {} + function mail() {} +} + +class mail { + function factory() {} + function connect() {} + function disconnect() {} +} + +class Mail_mime { + function headers() {} + function setTXTBody() {} + function setHTMLBody() {} +} + +class mPDF { + function Output() {} + function SetAutoFont() {} +} + +class HashPassword { + function CheckPassword() {} + function HashPassword() {} +} + ?> diff --git a/setup/test/tests/test.extra-whitespace.php b/setup/test/tests/test.extra-whitespace.php index 96d31ac8425e40a38e66ff90f7a59e9717697bb9..2565de6813510972794240d5752a1db9a2db4185 100644 --- a/setup/test/tests/test.extra-whitespace.php +++ b/setup/test/tests/test.extra-whitespace.php @@ -3,16 +3,17 @@ require_once "class.test.php"; class ExtraWhitespace extends Test { var $name = "PHP Leading and Trailing Whitespace"; - + function testFindWhitespace() { - foreach ($this->getAllScripts() as $s) { + foreach (static::getAllScripts() as $s) { $matches = array(); + $content = file_get_contents($s); if (preg_match_all('/^\s+<\?php|\?>\n\s+$/s', - file_get_contents($s), $matches, + $content, $matches, PREG_OFFSET_CAPTURE) > 0) { foreach ($matches[0] as $match) $this->fail( - $s, $this->line_number_for_offset($s, $match[1]), + $s, $this->line_number_for_offset($content, $match[1]), (strpos('?>', $match[0]) !== false) ? 'Leading whitespace' : 'Trailing whitespace'); diff --git a/setup/test/tests/test.mail-parse.php b/setup/test/tests/test.mail-parse.php index 8d1350f0f178cc4d9d81f73b5561e25a4075f66a..897851d06c548297654c92d6eb3ca358dcafa035 100644 --- a/setup/test/tests/test.mail-parse.php +++ b/setup/test/tests/test.mail-parse.php @@ -43,7 +43,7 @@ Q2hlZXJzISE= --=_28022448a1f58a3af7edf57ff2e3af44-- EOF; - $result = EmailDataParser::parse($email); + $result = @EmailDataParser::parse($email); $this->assert(count($result['recipients']) == 1, 'Expected 1 recipient'); $this->assert($result['recipients'][0]['source'] == 'delivered-to', 'Delivered-To header used as a collaborator'); diff --git a/setup/test/tests/test.shortopentags.php b/setup/test/tests/test.shortopentags.php index 571fc08e15e1c3af5c0c60216eeda7d494a6cfa6..9aacbd94c9eb21f9f94a7b15111fe507bbdb24b1 100644 --- a/setup/test/tests/test.shortopentags.php +++ b/setup/test/tests/test.shortopentags.php @@ -5,15 +5,16 @@ class ShortOpenTag extends Test { var $name = "PHP Short Open Checks"; function testFindShortOpens() { - foreach ($this->getAllScripts() as $s) { + foreach (static::getAllScripts() as $s) { $matches = array(); + $content = file_get_contents($s); if (preg_match_all('/<\?\s*(?!php|xml).*$/m', - file_get_contents($s), $matches, + $content, $matches, PREG_OFFSET_CAPTURE) > 0) { foreach ($matches[0] as $match) $this->fail( $s, - $this->line_number_for_offset($s, $match[1]), + $this->line_number_for_offset($content, $match[1]), $match[0]); } else $this->pass(); diff --git a/setup/test/tests/test.signals.php b/setup/test/tests/test.signals.php index 7ce888383ab0aee781450f3f908d8c4a36d96ae1..0176bf0cc2de42561894fa40f2bb7768d63a2159 100644 --- a/setup/test/tests/test.signals.php +++ b/setup/test/tests/test.signals.php @@ -8,7 +8,7 @@ class SignalsTest extends Test { * Ensures that each signal subscribed to has a sender somewhere else */ function testFindSignalPublisher() { - $scripts = $this->getAllScripts(); + $scripts = static::getAllScripts(); $matches = $published_signals = array(); foreach ($scripts as $s) if (preg_match_all("/^ *Signal::send\('([^']+)'/m", @@ -16,14 +16,15 @@ class SignalsTest extends Test { foreach ($matches as $match) $published_signals[] = $match[1]; foreach ($scripts as $s) { + $content = file_get_contents($s); if (preg_match_all("/^ *Signal::connect\('([^']+)'/m", - file_get_contents($s), $matches, + $content, $matches, PREG_OFFSET_CAPTURE|PREG_SET_ORDER) > 0) { foreach ($matches as $match) { $match = $match[1]; if (!in_array($match[0], $published_signals)) $this->fail( - $s, self::line_number_for_offset($s, $match[1]), + $s, $this->line_number_for_offset($content, $match[1]), "Signal '{$match[0]}' is never sent"); else $this->pass(); @@ -31,16 +32,6 @@ class SignalsTest extends Test { } } } - - function line_number_for_offset($filename, $offset) { - $lines = file($filename); - $bytes = $line = 0; - while ($bytes < $offset) { - $bytes += strlen(array_shift($lines)); - $line += 1; - } - return $line; - } } return 'SignalsTest'; diff --git a/setup/test/tests/test.syntax.php b/setup/test/tests/test.syntax.php index 0adf1465a3fcca066262efe308222e8da1e48720..38bb5accab0a0cb7d4a216a844dd4c8773eb01b3 100644 --- a/setup/test/tests/test.syntax.php +++ b/setup/test/tests/test.syntax.php @@ -4,9 +4,13 @@ require_once "class.test.php"; class SyntaxTest extends Test { var $name = "PHP Syntax Checks"; + static function ignore3rdparty() { + return false; + } + function testCompileErrors() { $exit = 0; - foreach ($this->getAllScripts(false) as $s) { + foreach (static::getAllScripts() as $s) { ob_start(); system("php -l $s", $exit); $line = ob_get_contents(); diff --git a/setup/test/tests/test.undefinedmethods.php b/setup/test/tests/test.undefinedmethods.php index c767ba6ac1490c265be68b821419d348ff30fdce..aaba663402cf55a41f2588c4a9311f18af0634df 100644 --- a/setup/test/tests/test.undefinedmethods.php +++ b/setup/test/tests/test.undefinedmethods.php @@ -4,8 +4,12 @@ require_once "class.test.php"; class UndefinedMethods extends Test { var $name = "Access to undefined object methods"; - function testFindShortOpen() { - $scripts = $this->getAllScripts(false); + static function ignore3rdparty() { + return false; + } + + function testUndefinedMethods() { + $scripts = static::getAllScripts(); $function_defs = array(); foreach ($scripts as $s) { $matches = array(); @@ -36,6 +40,10 @@ function find_function_calls($scripts) { $lineno=0; foreach ($lines as $line) { $lineno++; $matches=array(); + // Ignore what looks like within comments (#|/|*) + if (preg_match('/^(\s*?)(#|\/|\*)/m', $line)) + continue; + preg_match_all('/^.*\w+(?:-[>]|::)([a-zA-Z0-9_]+)\(.*/', $line, $matches, PREG_SET_ORDER); foreach ($matches as $m) diff --git a/setup/test/tests/test.var-dump.php b/setup/test/tests/test.var-dump.php new file mode 100644 index 0000000000000000000000000000000000000000..d87f393e580fcbe7f74d480f35c11e18ad623f34 --- /dev/null +++ b/setup/test/tests/test.var-dump.php @@ -0,0 +1,27 @@ +<?php +require_once "class.test.php"; + +class VarDump extends Test { + var $name = "var_dump Checks"; + + function testFindShortOpens() { + $re = '/^(([\t ]*?)var_dump\(.*[\)|,|;])((?!nolint).)*$/m'; + foreach (static::getAllScripts() as $s) { + $matches = array(); + $content = file_get_contents($s); + if (preg_match_all($re, + $content, $matches, + PREG_OFFSET_CAPTURE) > 0) { + foreach ($matches[0] as $match) { + $this->fail( + $s, + $this->line_number_for_offset($content, $match[1]), + trim($match[0])); + } + } + else $this->pass(); + } + } +} +return 'VarDump'; +?>