diff --git a/include/ajax.kbase.php b/include/ajax.kbase.php index a89161a79ac305be96996608f29609e23109c677..e467f51300dee94c438e81762421f5202baf96e1 100644 --- a/include/ajax.kbase.php +++ b/include/ajax.kbase.php @@ -15,9 +15,9 @@ **********************************************************************/ if(!defined('INCLUDE_DIR')) die('!'); - + class KbaseAjaxAPI extends AjaxController { - + function cannedResp($id, $format='') { global $thisstaff, $_GET; @@ -52,20 +52,21 @@ class KbaseAjaxAPI extends AjaxController { } function faq($id, $format='html') { - global $thisstaff; //XXX: user ajax->getThisStaff() + //XXX: user ajax->getThisStaff() (nolint) + global $thisstaff; include_once(INCLUDE_DIR.'class.faq.php'); if(!($faq=FAQ::lookup($id))) return null; - //TODO: $fag->getJSON() for json format. + //TODO: $fag->getJSON() for json format. (nolint) $resp = sprintf( '<div style="width:650px;"> <strong>%s</strong><p>%s</p> <div class="faded">Last updated %s</div> <hr> <a href="faq.php?id=%d">View</a> | <a href="faq.php?id=%d">Attachments (%s)</a>', - $faq->getQuestion(), + $faq->getQuestion(), Format::safe_html($faq->getAnswer()), Format::db_daydatetime($faq->getUpdateDate()), $faq->getId(), @@ -77,7 +78,7 @@ class KbaseAjaxAPI extends AjaxController { } $resp.='</div>'; - return $resp; + return $resp; } } ?> diff --git a/include/ajax.reports.php b/include/ajax.reports.php index 2634bc8d58c7d574a94cd87cf75ef528d5ac22fa..603fb41685e0c752ca6091edb451dab256309ecd 100644 --- a/include/ajax.reports.php +++ b/include/ajax.reports.php @@ -22,7 +22,7 @@ include_once(INCLUDE_DIR.'class.ticket.php'); /** * Overview Report - * + * * The overview report allows for the display of basic ticket statistics in * both graphical and tabular formats. */ @@ -76,14 +76,14 @@ class OverviewReportAjaxAPI extends AjaxController { "headers" => array('Staff Member'), "filter" => ('T1.staff_id=S1.staff_id - AND + AND (T1.staff_id='.db_input($thisstaff->getId()) .(($depts=$thisstaff->getManagedDepartments())? (' OR T1.dept_id IN('.implode(',', db_input($depts)).')'):'') .(($thisstaff->canViewStaffStats())? (' OR T1.dept_id IN('.implode(',', db_input($thisstaff->getDepts())).')'):'') .')' - ) + ) ) ); $group = $this->get('group', 'dept'); @@ -98,10 +98,10 @@ class OverviewReportAjaxAPI extends AjaxController { COUNT(*)-COUNT(NULLIF(A1.state, "overdue")) AS Overdue, COUNT(*)-COUNT(NULLIF(A1.state, "closed")) AS Closed, COUNT(*)-COUNT(NULLIF(A1.state, "reopened")) AS Reopened - FROM '.$info['table'].' T1 - LEFT JOIN '.TICKET_EVENT_TABLE.' A1 + FROM '.$info['table'].' T1 + LEFT JOIN '.TICKET_EVENT_TABLE.' A1 ON (A1.'.$info['pk'].'=T1.'.$info['pk'].' - AND NOT annulled + AND NOT annulled AND (A1.timestamp BETWEEN '.$start.' AND '.$stop.')) LEFT JOIN '.STAFF_TABLE.' S1 ON (S1.staff_id=A1.staff_id) WHERE '.$info['filter'].' @@ -110,7 +110,7 @@ class OverviewReportAjaxAPI extends AjaxController { array(1, 'SELECT '.$info['fields'].', FORMAT(AVG(DATEDIFF(T2.closed, T2.created)),1) AS ServiceTime - FROM '.$info['table'].' T1 + FROM '.$info['table'].' T1 LEFT JOIN '.TICKET_TABLE.' T2 ON (T2.'.$info['pk'].'=T1.'.$info['pk'].') LEFT JOIN '.STAFF_TABLE.' S1 ON (S1.staff_id=T2.staff_id) WHERE '.$info['filter'].' AND T2.closed BETWEEN '.$start.' AND '.$stop.' @@ -119,7 +119,7 @@ class OverviewReportAjaxAPI extends AjaxController { array(1, 'SELECT '.$info['fields'].', FORMAT(AVG(DATEDIFF(B2.created, B1.created)),1) AS ResponseTime - FROM '.$info['table'].' T1 + FROM '.$info['table'].' T1 LEFT JOIN '.TICKET_TABLE.' T2 ON (T2.'.$info['pk'].'=T1.'.$info['pk'].') LEFT JOIN '.TICKET_THREAD_TABLE.' B2 ON (B2.ticket_id = T2.ticket_id AND B2.thread_type="R") @@ -174,7 +174,7 @@ class OverviewReportAjaxAPI extends AjaxController { function getPlotData() { - + if(($start = $this->get('start', 'last month'))) { $stop = $this->get('stop', 'now'); if (substr($stop, 0, 1) == '+') @@ -211,6 +211,7 @@ class OverviewReportAjaxAPI extends AjaxController { $time = null; $times = array(); # Iterate over result set, adding zeros for missing ticket events + $slots = array(); while ($row = db_fetch_row($res)) { $row_time = strtotime($row[1]); if ($time != $row_time) { diff --git a/include/class.api.php b/include/class.api.php index cbaf2e8116ade833a15084bb0639eedd3d577525..c55fec003e6c7c88a7a4684b282263779fa793cc 100644 --- a/include/class.api.php +++ b/include/class.api.php @@ -143,7 +143,7 @@ class API { $sql='INSERT INTO '.API_KEY_TABLE.' SET '.$sql .',created=NOW() ' .',ipaddr='.db_input($vars['ipaddr']) - .',apikey='.db_input(strtoupper(md5(time().$vars['ipaddr'].md5(Misc::randcode(16))))); + .',apikey='.db_input(strtoupper(md5(time().$vars['ipaddr'].md5(Misc::randCode(16))))); if(db_query($sql) && ($id=db_insert_id())) return $id; diff --git a/include/class.email.php b/include/class.email.php index 74f1c43cac6d091856d5b709b5c473bd0dd5410e..148787260c99df6a0c96863628a16ab866fc1aaa 100644 --- a/include/class.email.php +++ b/include/class.email.php @@ -21,12 +21,12 @@ class Email { var $dept; var $ht; - + function Email($id) { $this->id=0; $this->load($id); } - + function load($id=0) { if(!$id && !($id=$this->getId())) @@ -36,20 +36,20 @@ class Email { if(!($res=db_query($sql)) || !db_num_rows($res)) return false; - + $this->ht=db_fetch_array($res); $this->id=$this->ht['email_id']; $this->address=$this->ht['name']?($this->ht['name'].'<'.$this->ht['email'].'>'):$this->ht['email']; $this->dept = null; - + return true; } - + function reload() { return $this->load(); } - + function getId() { return $this->id; } @@ -57,11 +57,11 @@ class Email { function getEmail() { return $this->ht['email']; } - + function getAddress() { return $this->address; } - + function getName() { return $this->ht['name']; } @@ -78,7 +78,7 @@ class Email { if(!$this->dept && $this->getDeptId()) $this->dept=Dept::lookup($this->getDeptId()); - + return $this->dept; } @@ -93,7 +93,7 @@ class Email { function getHashtable() { return $this->ht; } - + function getInfo() { return $this->getHashtable(); } @@ -109,7 +109,7 @@ class Email { 'encryption' => $this->ht['mail_encryption'], 'username' => $this->ht['userid'], 'password' => Mcrypt::decrypt($this->ht['userpass'], SECRET_SALT), - //osTicket specific + //osTicket specific 'email_id' => $this->getId(), //Required for email routing to work. 'max_fetch' => $this->ht['mail_fetchmax'], 'delete_mail' => $this->ht['mail_delete'], @@ -128,7 +128,7 @@ class Email { } function getSMTPInfo() { - + $info = array ( 'host' => $this->ht['smtp_host'], 'port' => $this->ht['smtp_port'], @@ -167,7 +167,7 @@ class Email { return false; $this->reload(); - + return true; } @@ -191,13 +191,13 @@ class Email { /******* Static functions ************/ - + function getIdByEmail($email) { - + $sql='SELECT email_id FROM '.EMAIL_TABLE.' WHERE email='.db_input($email); - if(($res=db_query($sql)) && db_num_rows($res)) + if(($res=db_query($sql)) && db_num_rows($res)) list($id)=db_fetch_row($res); - + return $id; } @@ -227,7 +227,7 @@ class Email { $errors['email']='Email already exists'; }elseif($cfg && !strcasecmp($cfg->getAdminEmail(), $vars['email'])) { $errors['email']='Email already used as admin email!'; - }elseif(Staff::getIdByEmail($vars['email'])) { //make sure the email doesn't belong to any of the staff + }elseif(Staff::getIdByEmail($vars['email'])) { //make sure the email doesn't belong to any of the staff $errors['email']='Email in use by a staff member'; } @@ -237,11 +237,11 @@ class Email { if($vars['mail_active'] || ($vars['smtp_active'] && $vars['smtp_auth'])) { if(!$vars['userid']) $errors['userid']='Username missing'; - + if(!$id && !$vars['passwd']) $errors['passwd']='Password required'; } - + if($vars['mail_active']) { //Check pop/imapinfo only when enabled. if(!function_exists('imap_open')) @@ -266,7 +266,7 @@ class Email { elseif(!strcasecmp($vars['postfetch'],'archive') && !$vars['mail_archivefolder'] ) $errors['postfetch']='Valid folder required'; } - + if($vars['smtp_active']) { if(!$vars['smtp_host']) $errors['smtp_host']='Host name required'; @@ -276,17 +276,17 @@ class Email { //abort on errors if($errors) return false; - + if(!$errors && ($vars['mail_host'] && $vars['userid'])) { $sql='SELECT email_id FROM '.EMAIL_TABLE .' WHERE mail_host='.db_input($vars['mail_host']).' AND userid='.db_input($vars['userid']); if($id) $sql.=' AND email_id!='.db_input($id); - + if(db_num_rows(db_query($sql))) $errors['userid']=$errors['host']='Host/userid combination already in use.'; } - + $passwd=$vars['passwd']?$vars['passwd']:$vars['cpasswd']; if(!$errors && $vars['mail_active']) { //note: password is unencrypted at this point...MailFetcher expect plain text. @@ -308,7 +308,7 @@ class Email { $errors['mail']='Invalid or unknown archive folder!'; } } - + if(!$errors && $vars['smtp_active']) { //Check SMTP login only. require_once 'Mail.php'; // PEAR Mail package $smtp = mail::factory('smtp', @@ -328,7 +328,7 @@ class Email { $smtp->disconnect(); //Thank you, sir! } } - + if($errors) return false; //Default to default priority and dept.. @@ -336,7 +336,7 @@ class Email { $vars['priority_id']=$cfg->getDefaultPriorityId(); if(!$vars['dept_id'] && $cfg) $vars['dept_id']=$cfg->getDefaultDeptId(); - + $sql='updated=NOW(),mail_errors=0, mail_lastfetch=NULL'. ',email='.db_input($vars['email']). ',name='.db_input(Format::striptags($vars['name'])). @@ -365,15 +365,15 @@ class Email { $sql.=',mail_delete=0,mail_archivefolder='.db_input($vars['mail_archivefolder']); else $sql.=',mail_delete=0,mail_archivefolder=NULL'; - + if($vars['passwd']) //New password - encrypt. $sql.=',userpass='.db_input(Mcrypt::encrypt($vars['passwd'],SECRET_SALT)); - + if($id) { //update $sql='UPDATE '.EMAIL_TABLE.' SET '.$sql.' WHERE email_id='.db_input($id); if(db_query($sql) && db_affected_rows()) return true; - + $errors['err']='Unable to update email. Internal error occurred'; }else { $sql='INSERT INTO '.EMAIL_TABLE.' SET '.$sql.',created=NOW()'; @@ -382,7 +382,7 @@ class Email { $errors['err']='Unable to add email. Internal error'; } - + return false; } } diff --git a/include/class.faq.php b/include/class.faq.php index 447719fbda62e1eac0fd3fe68cc66cbefc069352..fb07e5effbdad6ab1f9e52ed12f9292c33af85c6 100644 --- a/include/class.faq.php +++ b/include/class.faq.php @@ -38,7 +38,7 @@ class FAQ { .' WHERE faq.faq_id='.db_input($id) .' GROUP BY faq.faq_id'; - if (!($res=db_query($sql)) || !db_num_rows($res)) + if (!($res=db_query($sql)) || !db_num_rows($res)) return false; $this->ht = db_fetch_array($res); @@ -66,9 +66,9 @@ class FAQ { function getCreateDate() { return $this->ht['created']; } function getUpdateDate() { return $this->ht['updated']; } - + function getCategoryId() { return $this->ht['category_id']; } - function getCategory() { + function getCategory() { if(!$this->category && $this->getCategoryId()) $this->category = Category::lookup($this->getCategoryId()); @@ -86,7 +86,7 @@ class FAQ { function getHelpTopics() { //XXX: change it to obj (when needed)! - + if (!isset($this->topics)) { $this->topics = array(); $sql='SELECT t.topic_id, CONCAT_WS(" / ", pt.topic, t.topic) as name FROM '.TOPIC_TABLE.' t ' @@ -159,7 +159,7 @@ class FAQ { return false; $this->updateTopics($vars['topics']); - + //Delete removed attachments. $keepers = $vars['files']?$vars['files']:array(); if(($attachments = $this->getAttachments())) { @@ -211,12 +211,12 @@ class FAQ { $str.=sprintf('<a class="Icon file" href="file.php?h=%s" target="%s">%s</a>%s %s', $hash, $target, Format::htmlchars($attachment['name']), $size, $separator); - + } } return $str; } - + function uploadAttachments($files) { $i=0; @@ -258,40 +258,40 @@ class FAQ { function delete() { - + $sql='DELETE FROM '.FAQ_TABLE .' WHERE faq_id='.db_input($this->getId()) .' LIMIT 1'; if(!db_query($sql) || !db_affected_rows()) return false; - + //Cleanup help topics. db_query('DELETE FROM '.FAQ_TOPIC_TABLE.' WHERE faq_id='.db_input($this->id)); //Cleanup attachments. $this->deleteAttachments(); - + return true; } /* ------------------> Static methods <--------------------- */ - + function add($vars, &$errors) { if(!($id=self::create($vars, $errors))) return false; if(($faq=self::lookup($id))) { $faq->updateTopics($vars['topics']); - + if($_FILES['attachments'] && ($files=AttachmentFile::format($_FILES['attachments']))) $faq->uploadAttachments($files); $faq->reload(); } - + return $faq; } - function create($vars, &$errors) { + function create($vars, &$errors) { return self::save(0, $vars, $errors); } @@ -319,12 +319,12 @@ class FAQ { function findByQuestion($question) { - if(($id=self::getIdByQuestion($question))) + if(($id=self::findIdByQuestion($question))) return self::lookup($id); return false; } - + function save($id, $vars, &$errors, $validation=false) { //Cleanup. @@ -359,7 +359,7 @@ class FAQ { $sql='UPDATE '.FAQ_TABLE.' SET '.$sql.' WHERE faq_id='.db_input($id); if(db_query($sql)) return true; - + $errors['err']='Unable to update FAQ.'; } else { diff --git a/include/class.filter.php b/include/class.filter.php index dfc0562096be68c5eb9cb72716ec8bae3bd1e97d..182e47ca05889335c8a0df05f9b3c96b27f34dda 100644 --- a/include/class.filter.php +++ b/include/class.filter.php @@ -36,10 +36,10 @@ class Filter { if(!($res=db_query($sql)) || !db_num_rows($res)) return false; - + $this->ht=db_fetch_array($res); $this->id=$this->ht['id']; - + return true; } @@ -130,7 +130,7 @@ class Filter { function disableAlerts() { return ($this->ht['disable_autoresponder']); } - + function sendAlerts() { return (!$this->disableAlerts()); } @@ -149,7 +149,7 @@ class Filter { return $this->ht['rules']; } - function getFlatRules() { //Format used on html... I'm ashamed + function getFlatRules() { //Format used on html... I'm ashamed $info=array(); if(($rules=$this->getRules())) { @@ -181,7 +181,7 @@ class Filter { return (db_query($sql) && db_affected_rows()); } - + function getRule($id) { return $this->getRuleById($id); } @@ -222,7 +222,7 @@ class Filter { * reply-to - reply-to email address * reply-to-name - name of sender to reply-to * headers - array of email headers - * emailId - osTicket system email id + * emailId - osTicket system email id */ function matches($what) { @@ -240,7 +240,7 @@ class Filter { $match = false; # Respect configured filter email-id - if ($this->getEmailId() + if ($this->getEmailId() && !strcasecmp($this->getTarget(), 'Email') && $this->getEmailId() != $what['emailId']) return false; @@ -259,7 +259,7 @@ class Filter { if (!$this->matchAllRules()) break; } else { # No match. Continue? - if ($this->matchAllRules()) { + if ($this->matchAllRules()) { $match = false; break; } @@ -268,7 +268,7 @@ class Filter { return $match; } - /** + /** * If the matches() method returns TRUE, send the initial ticket to this * method to apply the filter actions defined */ @@ -290,7 +290,7 @@ class Filter { # match if ($this->useReplyToEmail() && $info['reply-to']) { $ticket['email'] = $info['reply-to']; - if ($info['reply-to-name']) + if ($info['reply-to-name']) $ticket['name'] = $info['reply-to-name']; } @@ -323,12 +323,12 @@ class Filter { return false; $this->reload(); - + return true; } function delete() { - + $id=$this->getId(); $sql='DELETE FROM '.FILTER_TABLE.' WHERE id='.db_input($id).' LIMIT 1'; if(db_query($sql) && ($num=db_affected_rows())) { @@ -401,7 +401,7 @@ class Filter { if(!$id) return true; //When ID is 0 then assume it was just validation... - //Clear existing rules...we're doing mass replace on each save!! + //Clear existing rules...we're doing mass replace on each save!! db_query('DELETE FROM '.FILTER_RULE_TABLE.' WHERE filter_id='.db_input($id)); $num=0; foreach($rules as $rule) { @@ -410,7 +410,7 @@ class Filter { $num++; } - return $num; + return $num; } function save($id,$vars,&$errors) { @@ -420,7 +420,7 @@ class Filter { $errors['execorder'] = 'Order required'; elseif(!is_numeric($vars['execorder'])) $errors['execorder'] = 'Must be numeric value'; - + if(!$vars['name']) $errors['name'] = 'Name required'; elseif(($sid=self::getIdByName($vars['name'])) && $sid!=$id) @@ -459,7 +459,7 @@ class Filter { .',disable_autoresponder='.db_input(isset($vars['disable_autoresponder'])?1:0) .',canned_response_id='.db_input($vars['canned_response_id']) .',notes='.db_input($vars['notes']); - + //Auto assign ID is overloaded... if($vars['assign'] && $vars['assign'][0]=='s') @@ -484,7 +484,7 @@ class Filter { //Success with update/create...save the rules. We can't recover from any errors at this point. # Don't care about errors stashed in $xerrors self::save_rules($id,$vars,$xerrors); # nolint - + return true; } } @@ -507,15 +507,15 @@ class FilterRule { .' WHERE rule.id='.db_input($id); if($filterId) $sql.=' AND rule.filter_id='.db_input($filterId); - + if(!($res=db_query($sql)) || !db_num_rows($res)) return false; - + $this->ht=db_fetch_array($res); $this->id=$this->ht['id']; - + $this->filter=null; return true; @@ -546,7 +546,7 @@ class FilterRule { } function getFilter() { - + if(!$this->filter && $this->getFilterId()) $this->filter = Filter::lookup($this->getFilterId()); @@ -562,7 +562,7 @@ class FilterRule { } function delete() { - + $sql='DELETE FROM '.FILTER_RULE_TABLE.' WHERE id='.db_input($this->getId()).' AND filter_id='.db_input($this->getFilterId()); return (db_query($sql) && db_affected_rows()); @@ -579,14 +579,14 @@ class FilterRule { if($errors) return false; - + $sql=' updated=NOW() '. ',what='.db_input($vars['w']). ',how='.db_input($vars['h']). ',val='.db_input($vars['v']). ',isactive='.db_input(isset($vars['isactive'])?$vars['isactive']:1); - + if(isset($vars['notes'])) $sql.=',notes='.db_input($vars['notes']); @@ -640,12 +640,12 @@ class TicketFilter { * @see ::quickList() for more information. */ function TicketFilter($origin, $vars=null) { - + //Normalize the target based on ticket's origin. $this->target = self::origin2target($origin); - + //Extract the vars we care about (fields we filter by!). - $this->vars = array_filter(array_map('trim', + $this->vars = array_filter(array_map('trim', array( 'email' => $vars['email'], 'subject' => $vars['subject'], @@ -653,13 +653,13 @@ class TicketFilter { 'body' => $vars['message'], 'emailId' => $vars['emailId']) )); - + //Init filters. $this->build(); } function build() { - + //Clear any memoized filters $this->filters = array(); $this->short_list = null; @@ -722,13 +722,13 @@ class TicketFilter { if ($filter->stopOnMatch()) break; } } - + /* static */ function getAllActive() { $sql='SELECT id FROM '.FILTER_TABLE .' WHERE isactive=1 ' .' AND target IN ("Any", '.db_input($this->getTarget()).') '; - + #Take into account email ID. if($this->vars['emailId']) $sql.=' AND (email_id=0 OR email_id='.db_input($this->vars['emailId']).')'; @@ -746,7 +746,7 @@ class TicketFilter { * arguments. This method will request the database to make a first pass * and eliminate the filters from being considered that would never * match the received email. - * + * * Returns an array<Filter::Id> which will need to have their respective * matches() method queried to determine if the Filter actually matches * the email. @@ -775,13 +775,13 @@ class TicketFilter { # Filter by system's email-id if specified if($this->vars['emailId']) $sql.=' AND (filter.email_id=0 OR filter.email_id='.db_input($this->vars['emailId']).')'; - + # Include rules for sender-email, sender-name and subject as # requested $sql.=" AND ((what='email' AND LOCATE(val, ".db_input($this->vars['email']).'))'; - if($this->vars['name']) + if($this->vars['name']) $sql.=" OR (what='name' AND LOCATE(val, ".db_input($this->vars['name']).'))'; - if($this->vars['subject']) + if($this->vars['subject']) $sql.=" OR (what='subject' AND LOCATE(val, ".db_input($this->vars['subject']).'))'; @@ -799,7 +799,7 @@ class TicketFilter { if (!$this->vars['name']) $sql.=" AND COUNT(*)-COUNT(NULLIF(what,'name'))=0"; if (!$this->vars['subject']) $sql.=" AND COUNT(*)-COUNT(NULLIF(what,'subject'))=0"; # Also include filters that do not have match_all_rules set to and - # have at least one rule 'what' type that wasn't considered e.g body + # have at least one rule 'what' type that wasn't considered e.g body $sql.=") OR filter.id IN (" ." SELECT filter_id" ." FROM ".FILTER_RULE_TABLE." rule" @@ -828,7 +828,8 @@ class TicketFilter { * Filter::matches() method. * Peter - Let's keep it as a quick scan for obviously banned emails. */ - /* static */ function isBanned($addr) { + /* static */ + function isBanned($addr) { $sql='SELECT filter.id, what, how, UPPER(val) ' .' FROM '.FILTER_TABLE.' filter' @@ -849,7 +850,7 @@ class TicketFilter { $addr = strtoupper($addr); $how=array('equal' => array('strcmp', 0), 'contains' => array('strpos', null, false)); - + while ($row=db_fetch_array($res)) { list($func, $pos, $neg) = $how[$row['how']]; if (!$func) continue; @@ -869,7 +870,8 @@ class TicketFilter { * X-Auto-Response-Supress is outlined here, * http://msdn.microsoft.com/en-us/library/ee219609(v=exchg.80).aspx */ - /* static */ function isAutoResponse($headers) { + /* static */ + function isAutoResponse($headers) { if($headers && !is_array($headers)) $headers = Mail_Parse::splitHeaders($headers); @@ -936,13 +938,13 @@ class TicketFilter { return false; } - /** - * Normalize ticket source to supported filter target + /** + * Normalize ticket source to supported filter target * */ function origin2target($origin) { $sources=array('web' => 'Web', 'email' => 'Email', 'phone' => 'Web', 'staff' => 'Web', 'api' => 'API'); - + return $sources[strtolower($origin)]; } } diff --git a/include/class.format.php b/include/class.format.php index 1c493be0bf487f7aa97916bbeb6e566e103c906c..892cc42f17bd56fe2e934d6c1ffb0c2a6f305fa5 100644 --- a/include/class.format.php +++ b/include/class.format.php @@ -45,7 +45,7 @@ class Format { if($charset && in_array(strtolower(trim($charset)), array('default','x-user-defined','iso'))) $charset = 'ISO-8859-1'; - + if (strcasecmp($charset, $encoding) === 0) return $text; @@ -202,14 +202,14 @@ class Format { $token = $ost->getLinkToken(); //Not perfect but it works - please help improve it. $text=preg_replace_callback('/(((f|ht){1}tp(s?):\/\/)[-a-zA-Z0-9@:%_\+.~#?&;\/\/=]+)/', - create_function('$matches', - sprintf('return "<a href=\"l.php?url=".urlencode($matches[1])."&auth=%s\" target=\"_blank\">".$matches[1]."</a>";', + create_function('$matches', # nolint + sprintf('return "<a href=\"l.php?url=".urlencode($matches[1])."&auth=%s\" target=\"_blank\">".$matches[1]."</a>";', # nolint $token)), $text); $text=preg_replace_callback("/(^|[ \\n\\r\\t])(www\.([a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+)(\/[^\/ \\n\\r]*)*)/", - create_function('$matches', - sprintf('return "<a href=\"l.php?url=".urlencode("http://".$matches[2])."&auth=%s\" target=\"_blank\">".$matches[2]."</a>";', + create_function('$matches', # nolint + sprintf('return "<a href=\"l.php?url=".urlencode("http://".$matches[2])."&auth=%s\" target=\"_blank\">".$matches[2]."</a>";', # nolint $token)), $text); @@ -219,7 +219,7 @@ class Format { return $text; } - function stripEmptyLines ($string) { + function stripEmptyLines($string) { //return preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $string); //return preg_replace('/\s\s+/',"\n",$string); //Too strict?? return preg_replace("/\n{3,}/", "\n\n", $string); diff --git a/include/class.ticket.php b/include/class.ticket.php index fbec65c2a3a8de21c0e34d30a53e65c08b052001..2c6f52676d10dacf0b34f505797b9ebf6e0d6388 100644 --- a/include/class.ticket.php +++ b/include/class.ticket.php @@ -1674,7 +1674,7 @@ class Ticket { } - /*============== Static functions. Use Ticket::function(params); ==================*/ + /*============== Static functions. Use Ticket::function(params); =============nolint*/ function getIdByExtId($extId, $email=null) { if(!$extId || !is_numeric($extId)) diff --git a/include/class.upgrader.php b/include/class.upgrader.php index ded4a344f935d308313eccbfc65b43460fd2f5fb..b09aabe48d43ba70545556ac10b0c4c5c2199d28 100644 --- a/include/class.upgrader.php +++ b/include/class.upgrader.php @@ -272,7 +272,7 @@ class StreamUpgrader extends SetupWizard { } function readPatchInfo($patch) { - $info = array(); + $info = $matches = $matches2 = array(); if (preg_match(':/\*\*(.*)\*/:s', file_get_contents($patch), $matches)) { if (preg_match_all('/@([\w\d_-]+)\s+(.*)$/m', $matches[0], $matches2, PREG_SET_ORDER)) diff --git a/include/class.validator.php b/include/class.validator.php index c0659d7535334d93adb71352491563eed9b1b686..e8bf851a55f76dbc96f6e0d248e9866d180f0b03 100644 --- a/include/class.validator.php +++ b/include/class.validator.php @@ -133,7 +133,8 @@ class Validator { return $this->errors; } - /*** Functions below can be called directly without class instance. Validator::func(var..); ***/ + /*** Functions below can be called directly without class instance. + Validator::func(var..); (nolint) ***/ function is_email($email) { return preg_match('/^([*+!.&#$|\'\\%\/0-9a-z^_`{}=?~:-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})$/i',$email); } diff --git a/include/mysqli.php b/include/mysqli.php index ec369c652accad3f33af04eb085ee0e1ab88a584..ad545a5dbfd8a9fae8206c0e6e14189809e1105b 100644 --- a/include/mysqli.php +++ b/include/mysqli.php @@ -30,7 +30,7 @@ function db_connect($host, $user, $passwd, $options = array()) { // Setup SSL if enabled if (isset($options['ssl'])) - $__db->ssl_set( + $__db->ssl_set( # nolint $options['ssl']['key'], $options['ssl']['cert'], $options['ssl']['ca'], @@ -40,16 +40,16 @@ function db_connect($host, $user, $passwd, $options = array()) { //Connectr $start = microtime(true); - if(!@$__db->real_connect($host, $user, $passwd)) + if(!@$__db->real_connect($host, $user, $passwd)) # nolint return NULL; //Select the database, if any. - if(isset($options['db'])) $__db->select_db($options['db']); + if(isset($options['db'])) $__db->select_db($options['db']); # nolint //set desired encoding just in case mysql charset is not UTF-8 - Thanks to FreshMedia - @$__db->query('SET NAMES "utf8"'); - @$__db->query('SET CHARACTER SET "utf8"'); - @$__db->query('SET COLLATION_CONNECTION=utf8_general_ci'); + @$__db->query('SET NAMES "utf8"'); # nolint + @$__db->query('SET CHARACTER SET "utf8"'); # nolint + @$__db->query('SET COLLATION_CONNECTION=utf8_general_ci'); # nolint @db_set_variable('sql_mode', ''); @@ -92,13 +92,15 @@ function db_set_variable($variable, $value, $type='session') { function db_select_database($database) { global $__db; - return ($database && @$__db->select_db($database)); + return ($database && @$__db->select_db($database)); # nolint } function db_create_database($database, $charset='utf8', $collate='utf8_general_ci') { global $__db; - return @$__db->query(sprintf('CREATE DATABASE %s DEFAULT CHARACTER SET %s COLLATE %s', $database, $charset, $collate)); + return @$__db->query( # nolint + sprintf('CREATE DATABASE %s DEFAULT CHARACTER SET %s COLLATE %s', + $database, $charset, $collate)); } // execute sql query @@ -135,21 +137,21 @@ function db_result($res, $row=0) { if (!$res) return NULL; - $res->data_seek($row); + $res->data_seek($row); # nolint list($value) = db_output($res->fetch_row()); return $value; } function db_fetch_array($res, $mode=MYSQL_ASSOC) { - return ($res) ? db_output($res->fetch_array($mode)) : NULL; + return ($res) ? db_output($res->fetch_array($mode)) : NULL; # nolint } function db_fetch_row($res) { - return ($res) ? db_output($res->fetch_row()) : NULL; + return ($res) ? db_output($res->fetch_row()) : NULL; # nolint } function db_fetch_field($res) { - return ($res) ? $res->fetch_field() : NULL; + return ($res) ? $res->fetch_field() : NULL; # nolint } function db_assoc_array($res, $mode=false) { @@ -161,7 +163,7 @@ function db_assoc_array($res, $mode=false) { } function db_num_rows($res) { - return ($res) ? $res->num_rows : 0; + return ($res) ? $res->num_rows : 0; # nolint } function db_affected_rows() { @@ -170,7 +172,7 @@ function db_affected_rows() { } function db_data_seek($res, $row_number) { - return ($res && $res->data_seek($row_number)); + return ($res && $res->data_seek($row_number)); # nolint } function db_data_reset($res) { @@ -183,7 +185,7 @@ function db_insert_id() { } function db_free_result($res) { - return ($res && $res->free()); + return ($res && $res->free()); # nolint } function db_output($var) { @@ -220,7 +222,7 @@ function db_input($var, $quote=true) { function db_field_type($res, $col=0) { global $__db; - return $res->fetch_field_direct($col); + return $res->fetch_field_direct($col); # nolint } function db_connect_error() { diff --git a/include/pear/Auth/SASL/SCRAM.php b/include/pear/Auth/SASL/SCRAM.php index cbca500e47fcb522f8929265971c84af0b3b64f2..2607b61488cb7c71b953f1234887d4314ec5ffae 100644 --- a/include/pear/Auth/SASL/SCRAM.php +++ b/include/pear/Auth/SASL/SCRAM.php @@ -211,7 +211,7 @@ class Auth_SASL_SCRAM extends Auth_SASL_Common $channel_binding = 'c=' . base64_encode($this->gs2_header); // TODO: support channel binding. $final_message = $channel_binding . ',r=' . $nonce; // XXX: no extension. - // TODO: $password = $this->normalize($password); // SASLprep profile of stringprep. + // TODO: $password = $this->normalize($password); // SASLprep profile of stringprep. nolint $saltedPassword = $this->hi($password, $salt, $i); $this->saltedPassword = $saltedPassword; $clientKey = call_user_func($this->hmac, $saltedPassword, "Client Key", TRUE); diff --git a/setup/cli/modules/class.module.php b/setup/cli/modules/class.module.php index 437f87c609eb6b63f6799978ce324f437a456ca5..788cb21fbde330821ab9feb9855475ab9b156a57 100644 --- a/setup/cli/modules/class.module.php +++ b/setup/cli/modules/class.module.php @@ -72,10 +72,10 @@ class Option { $short = explode(':', $this->short); $long = explode(':', $this->long); if ($this->nargs === '?') - $switches = sprintf(' %s [%3$s], %s[=%3$s]', $short[0], + $switches = sprintf(' %s [%3$s], %s[=%3$s]', $short[0], # nolint $long[0], $this->metavar); elseif ($this->hasArg()) - $switches = sprintf(' %s %3$s, %s=%3$s', $short[0], $long[0], + $switches = sprintf(' %s %3$s, %s=%3$s', $short[0], $long[0], # nolint $this->metavar); else $switches = sprintf(" %s, %s", $short[0], $long[0]); @@ -143,7 +143,7 @@ class Module { echo "Usage:\n"; echo " " . str_replace( - array('$script', '$args'), + array('$script', '$args'), # nolint array($manager ." ". $this->module_name, implode(' ', array_keys($this->arguments))), $this->usage) . "\n"; diff --git a/setup/cli/modules/export.php b/setup/cli/modules/export.php index 9320fa7452687e9d45c5e3037e556dd2d2c4e8b2..f74647726e0c80ba632de5e61639582f1b01d62e 100644 --- a/setup/cli/modules/export.php +++ b/setup/cli/modules/export.php @@ -15,10 +15,6 @@ **********************************************************************/ require_once dirname(__file__) . "/class.module.php"; -require_once dirname(__file__) . '/../../../main.inc.php'; - -require_once INCLUDE_DIR . 'class.export.php'; - define('OSTICKET_BACKUP_SIGNATURE', 'osTicket-Backup'); define('OSTICKET_BACKUP_VERSION', 'A'); @@ -35,6 +31,9 @@ class Exporter extends Module { ); function run($args, $options) { + require_once dirname(__file__) . '/../../../main.inc.php'; + require_once INCLUDE_DIR . 'class.export.php'; + global $ost; $stream = $options['stream']; diff --git a/setup/cli/modules/import.php b/setup/cli/modules/import.php index 461b60ab0005f358885bc4fa2fc5e79a530c2c6c..e0f23d57a1a11e8b8b8c24df592edc4b36cd992e 100644 --- a/setup/cli/modules/import.php +++ b/setup/cli/modules/import.php @@ -1,4 +1,4 @@ -<? +<?php /********************************************************************* cli/import.php @@ -15,10 +15,6 @@ **********************************************************************/ require_once dirname(__file__) . "/class.module.php"; -require_once dirname(__file__) . '/../../../main.inc.php'; - -require_once INCLUDE_DIR . 'class.json.php'; - class Importer extends Module { var $prologue = "Imports data from a previous backup (using the exporter)"; @@ -222,6 +218,9 @@ class Importer extends Module { } function run($args, $options) { + require_once dirname(__file__) . '/../../../main.inc.php'; + require_once INCLUDE_DIR . 'class.json.php'; + $stream = $options['stream']; if ($options['compress']) $stream = "compress.zlib://$stream"; if (!($this->stream = fopen($stream, 'rb'))) { diff --git a/setup/cli/modules/unpack.php b/setup/cli/modules/unpack.php index e338c283a55af9a628dad89a29b1ae6a86b9cc91..50156ea7e77d9ecc1627de92887ba4f6f25e5c79 100644 --- a/setup/cli/modules/unpack.php +++ b/setup/cli/modules/unpack.php @@ -55,6 +55,7 @@ class Unpacker extends Module { else $include_path = "'$include_path'"; # Find the line that defines INCLUDE_DIR + $match = array(); foreach ($lines as &$line) { if (preg_match("/(\s*)define\s*\(\s*'INCLUDE_DIR'/", $line, $match)) { # Replace the definition with the new locatin @@ -117,8 +118,9 @@ class Unpacker extends Module { } } if ($recurse) { - foreach (glob(dirname($folder).'/'.basename($folder), - GLOB_BRACE|GLOB_ONLYDIR|GLOB_NOSORT) as $dir) { + $folders = glob(dirname($folder).'/'.basename($folder), + GLOB_BRACE|GLOB_ONLYDIR|GLOB_NOSORT); + foreach ($folders as $dir) { if (in_array(basename($dir), array('.','..'))) continue; elseif ($this->exclude($exclude, $dir)) diff --git a/setup/inc/class.installer.php b/setup/inc/class.installer.php index 90b915c1d5d5f1aa08f74421b5f7a43b7d751ecc..8a2b04a0d810c1ff7182f507cf47fd9044e9fb4a 100644 --- a/setup/inc/class.installer.php +++ b/setup/inc/class.installer.php @@ -119,8 +119,8 @@ class Installer extends SetupWizard { $this->errors['err']='Unable to open config file for writing. Permission denied! (#3)'; else { - foreach (DatabaseMigrater::getUpgradeStreams(INCLUDE_DIR.'upgrader/streams/') - as $stream=>$signature) { + $streams = DatabaseMigrater::getUpgradeStreams(INCLUDE_DIR.'upgrader/streams/'); + foreach ($streams as $stream=>$signature) { $schemaFile = INC_DIR."streams/$stream/install-mysql.sql"; if (!file_exists($schemaFile) || !($fp2 = fopen($schemaFile, 'rb'))) $this->errors['err'] = $stream @@ -211,7 +211,7 @@ class Installer extends SetupWizard { $configFile= str_replace('%CONFIG-DBUSER',$vars['dbuser'],$configFile); $configFile= str_replace('%CONFIG-DBPASS',$vars['dbpass'],$configFile); $configFile= str_replace('%CONFIG-PREFIX',$vars['prefix'],$configFile); - $configFile= str_replace('%CONFIG-SIRI',Misc::randcode(32),$configFile); + $configFile= str_replace('%CONFIG-SIRI',Misc::randCode(32),$configFile); if(!$fp || !ftruncate($fp,0) || !fwrite($fp,$configFile)) { $this->errors['err']='Unable to write to config file. Permission denied! (#5)'; return false; diff --git a/setup/test/tests/class.test.php b/setup/test/tests/class.test.php index a9da96b2d50e547eebd768b58de21df2a53c30be..4a82354cf23b4b1f8b2c40f3bf47db185d877ab1 100644 --- a/setup/test/tests/class.test.php +++ b/setup/test/tests/class.test.php @@ -26,15 +26,18 @@ class Test { function teardown() { } - /*static*/ function getAllScripts() { + /*static*/ + function getAllScripts($excludes=true) { $root = get_osticket_root_path(); $scripts = array(); foreach (glob_recursive("$root/*.php") as $s) { $found = false; - foreach ($this->third_party_paths as $p) { - if (strpos($s, $p) !== false) { - $found = true; - break; + if ($excludes) { + foreach ($this->third_party_paths as $p) { + if (strpos($s, $p) !== false) { + $found = true; + break; + } } } if (!$found) diff --git a/setup/test/tests/test.undefinedmethods.php b/setup/test/tests/test.undefinedmethods.php index 7062ec256b9b062b7858c1b94c0e50e82a3c5f0f..d5a0f6526697638f7dbc2abd7bdcf76594cbb450 100644 --- a/setup/test/tests/test.undefinedmethods.php +++ b/setup/test/tests/test.undefinedmethods.php @@ -5,15 +5,19 @@ class UndefinedMethods extends Test { var $name = "Access to undefined object methods"; function testFindShortOpen() { - $scripts = $this->getAllScripts(); - $php_script_content=''; + $scripts = $this->getAllScripts(false); + $function_defs = array(); foreach ($scripts as $s) { - $php_script_content .= file_get_contents($s); + $matches = array(); + preg_match_all('/^\s*(?:\/\*[^*]*\*\/)?\s*' + .'(?:private|public|static|abstract)?\s*' + .'function\s+&?\s*([^(\s]+)\s*\\(/m', + file_get_contents($s), $matches); + $function_defs = array_merge($function_defs, $matches[1]); } foreach (find_function_calls($scripts) as $call) { list($file, $no, $line, $func) = $call; - if (!preg_match('/^\s*(\/\*[^*]*\*\/)?'."\s*function\s+&?\s*$func\\(/m", - $php_script_content)) + if (!in_array($func, $function_defs)) $this->fail($file, $no, "$func: Definitely undefined"); else $this->pass(); @@ -28,11 +32,11 @@ function find_function_calls($scripts) { $lineno=0; foreach ($lines as $line) { $lineno++; $matches=array(); - preg_match_all('/-[>]([a-zA-Z0-9]*)\(/', $line, $matches, + preg_match_all('/(?:-[>]|::)([a-zA-Z0-9_]+)\(.*/', $line, $matches, PREG_SET_ORDER); - foreach ($matches as $m) { - $calls[] = array($s, $lineno, $line, $m[1]); - } + foreach ($matches as $m) + if (strpos($m[0], 'nolint') === false) + $calls[] = array($s, $lineno, $line, $m[1]); } } return $calls;