function json_encode($value) { function _is_array($array) { $keys = array_keys($array); for ($i = 0; $i < count($array); $i++) { if ($i !== $keys[$i]) { return false; } } return true; } $is_array = _is_array($value); $res = $is_array ? '[' : '{'; foreach ($value as $key => $val) { if (!$is_array) { if (is_numeric($key)) { $res .= $key . ":"; } else { if (is_string($key)) { $res .= string_escape($key) . ":"; } } } if (is_numeric($val)) { $res .= $val . ","; } else { if (is_string($val)) { $res .= string_escape($val) . ","; } else { if ($val === NULL) { $res .= 'null,'; } else { if ($val === TRUE) { $res .= 'true,'; } else { if ($val === FALSE) { $res .= 'false,'; } else { if (is_array($val)) { $res .= json_encode($val) . ','; } else { $res .= 'undefined,'; } } } } } } } return substr($res, 0, -1) . ($is_array ? ']' : '}'); }
/** * Fetches bugs history per client * * @author Abhinav Kumar * * @param int $_ticketID * * @throws SWIFT_Exception * @return bool "true" on Success, "false" otherwise */ public function History($_ticketID) { $_JIRABridge = SWIFT_JIRABridge::GetInstance(); if (!$this->GetIsClassLoaded()) { throw new SWIFT_Exception(SWIFT_CLASSNOTLOADED); } else { if (!$_JIRABridge || !$_JIRABridge instanceof SWIFT_JIRABridge || !$_JIRABridge->GetIsClassLoaded()) { throw new SWIFT_Exception(SWIFT_INVALIDDATA); } } $_ticketID = (int) $_ticketID; $_issuesContainer = $_JIRABridge->GetIssuesBy('ticketid', $_ticketID); if (_is_array($_issuesContainer)) { $this->View->RenderHistoryTab($_issuesContainer); } else { echo $this->Language->Get('jira_noissuefound'); } return true; }
/** * Renders the 'Add Comment to JIRA' form * * @param string $_issueKey The JIRA issue key * * @return boolean 'TRUE' on success and 'FALSE' otherwise * @throws SWIFT_Exception if class is not loaded or $_issueKey is empty */ public function RenderCommentForm($_issueKey) { if (!$this->GetIsClassLoaded()) { throw new SWIFT_Exception(__CLASS__ . ' ' . SWIFT_CLASSNOTLOADED); } if (empty($_issueKey)) { throw new SWIFT_Exception('Issue Key' . $this->Language->Get('jira_noempty')); } $_buttonText = '<input type="button" name="submitbutton" id="%formid%_submit" class="rebuttonblue" onclick="javascript: $(\'#%formid%\').submit();PreventDoubleClicking(this);" value="' . $this->Language->Get('jira_post') . '"/> <input type="button" name="submitbutton" id="%formid%_cancel" class="rebuttonred" onclick="javascript: $(\'.ui-icon-closethick\').click();" value="' . $this->Language->Get('jira_cancel') . '" onfocus="blur();" />'; $this->UserInterface->OverrideButtonText($_buttonText); $_GeneralTabObject = $this->UserInterface->AddTab($this->Language->Get('tabgeneral'), SWIFT::Get('swiftpath') . '__modules/jira/resources/postbugtojira_b.gif', 'general', true, false); $this->Load->Library('JIRA:JIRABridge', false, false, 'jira'); $_JIRABridge = SWIFT_JIRABridge::GetInstance(); if (!$_JIRABridge || !$_JIRABridge instanceof SWIFT_JIRABridge || !$_JIRABridge->GetIsClassLoaded()) { SWIFT::Notify(SWIFT::NOTIFICATION_ERROR, $this->Language->Get('jira_error')); return false; } $_JIRAIssue = $_JIRABridge->GetIssueBy('issuekey', $_issueKey); if ($_JIRAIssue && $_JIRAIssue instanceof SWIFT_JIRAIssueManager && $_JIRAIssue->GetIsClassLoaded()) { $this->Load->Library('Ticket:Ticket', false, false, APP_TICKETS); $_project = $_JIRAIssue->GetProject(); $_RolesContainer = $_JIRABridge->GetProjectRoles($_project); $_RolesOptionContainer = array(); if ($_RolesContainer && _is_array($_RolesContainer)) { foreach ($_RolesContainer as $_Role => $_RoleURL) { $_RolesOptionContainer[] = array('title' => $_Role, 'value' => $_Role); } } $_SWIFT_TicketObject = SWIFT_Ticket::GetObjectOnID($_JIRAIssue->GetKayakoTicketID()); $_GeneralTabObject->Title('<label for="comment">' . $this->Language->Get('jira_comment') . '</label><br/><span class="tabledescription">' . $this->Language->Get('jira_sensitive') . '</span>'); $_GeneralTabObject->TextArea('comment', '', '', '', 50, 6); $_GeneralTabObject->Select('visibility', $this->Language->Get('jira_comment_visibility'), '', $_RolesOptionContainer); $_GeneralTabObject->Hidden('issueKey', $_issueKey); $this->UserInterface->Hidden('jira_ticketid', $_SWIFT_TicketObject->GetTicketID()); $this->UserInterface->Hidden('jira_listtype', 'inbox'); $this->UserInterface->Hidden('jira_departmentid', $_SWIFT_TicketObject->GetProperty('departmentid')); $this->UserInterface->Hidden('jira_ticketstatusid', $_SWIFT_TicketObject->GetProperty('ticketstatusid')); $this->UserInterface->Hidden('jira_tickettypeid', $_SWIFT_TicketObject->GetProperty('tickettypeid')); } else { SWIFT::Notify(SWIFT::NOTIFICATION_ERROR, $this->Language->Get('jira_noissuefound') . $_issueKey); } return true; }
/** * Set Visibility * * @author Varun Shoor * * @param string $_visibility * * @return bool "true" on Success, "false" otherwise * @throws SWIFT_Exception If the Class is not Loaded */ public function SetVisibility($_visibility) { if (!$this->GetIsClassLoaded()) { throw new SWIFT_Exception(SWIFT_CLASSNOTLOADED); } if ($_visibility && _is_array($_visibility) && array_key_exists('type', $_visibility) && array_key_exists('value', $_visibility)) { $this->_visibility = $_visibility; return $this; } return false; }
/** * Import the MailChimp Integration Settings * * @author Ruchi Kothari * @return bool "true" on Success, "false" otherwise */ private function ImportSettings() { $_SWIFT = SWIFT::GetInstance(); $this->Load->Library('Language:LanguageManager'); $_languageIDList = SWIFT_Language::GetMasterLanguageIDList(); try { $this->SettingsManager->Import('./' . SWIFT_APPSDIRECTORY . '/mailchimp/config/settings.xml'); } catch (SWIFT_Exception $_SWIFT_ExceptionObject) { } // Adding merge language to first found master language if (_is_array($_languageIDList)) { $this->LanguageManager->Merge($_languageIDList[0], './' . SWIFT_APPSDIRECTORY . '/mailchimp/config/mailchimp.language.xml'); } return true; }
/** * Does the actual initialization * Checks if $_Data is an array & $_key is a key then reads and sets the value * to the corresponding class attribute * * @author Abhinav Kumar * * @param string $_key The key to read - This also relate to the class attribute * @param array $_data The associative array containing all the keys * @param bool $_isRequired whether mandatory or not. If set to 'true' will throw an \SWIFT_Exception if no value is passed * * @return boolean 'TRUE' on success & 'FALSE' otherwise * @throws SWIFT_Exception */ protected function SetFromArray($_key, $_data, $_isRequired) { if (!_is_array($_data)) { throw new SWIFT_Exception(SWIFT_INVALIDDATA); } if (array_key_exists($_key, $_data)) { // && $_data[$_key] != '') $_Var = '_' . $_key; $this->{$_Var} = $_data[$_key]; return true; } if ($_isRequired) { $_SWIFT = SWIFT::GetInstance(); $_SWIFT->Language->LoadApp('jira', 'jira'); throw new SWIFT_Exception(__CLASS__ . '::' . $_key . $_SWIFT->Language->Get('jira_noempty')); } return false; }
/** * Renders the Issue History Tab * * @param mixed $_issuesContainer array of issues associated with current ticket * * @author Abhinav Kumar * @return boolean 'true' on success and 'false' otherwise * @throws SWIFT_Exception if class is not loaded */ public function RenderHistoryTab($_issuesContainer) { $_SWIFT = SWIFT::GetInstance(); $_JIRABridge = SWIFT_JIRABridge::GetInstance(); if (!$this->GetIsClassLoaded()) { throw new SWIFT_Exception(__CLASS__ . ' ' . SWIFT_CLASSNOTLOADED); } else { if (!is_array($_issuesContainer)) { throw new SWIFT_Exception(SWIFT_INVALIDDATA); } } $this->UserInterface->Start(get_class($this), '', SWIFT_UserInterface::MODE_INSERT, false); $_IssueHistoryTabObject = new SWIFT_UserInterfaceTab($this->UserInterface, 'history', '', 1, 'history', false, false, 4, ''); $_columnContainer = array(); // Issue ID $_columnContainer[0]['value'] = $this->Language->Get('jira_issueid'); $_columnContainer[0]['align'] = 'left'; $_columnContainer[0]['width'] = '10'; // Summary $_columnContainer[1]['value'] = $this->Language->Get('jira_summary'); $_columnContainer[1]['align'] = 'left'; $_columnContainer[1]['width'] = '100'; // Updated $_columnContainer[3]['value'] = $this->Language->Get('jira_updated'); $_columnContainer[3]['align'] = 'left'; $_columnContainer[3]['width'] = '10'; // Priority $_columnContainer[4]['value'] = $this->Language->Get('jira_priority'); $_columnContainer[4]['align'] = 'left'; $_columnContainer[4]['width'] = '10'; // Status $_columnContainer[5]['value'] = $this->Language->Get('jira_status'); $_columnContainer[5]['align'] = 'left'; $_columnContainer[5]['width'] = '10'; // Assigned To $_columnContainer[6]['value'] = $this->Language->Get('jira_assignedto'); $_columnContainer[6]['align'] = 'left'; $_columnContainer[6]['width'] = '10'; // Action $_columnContainer[7]['value'] = $this->Language->Get('jira_action'); $_columnContainer[7]['align'] = 'left'; $_columnContainer[7]['width'] = '10'; $_IssueHistoryTabObject->Row($_columnContainer, 'gridtabletitlerow'); if (empty($_issuesContainer)) { $_columnContainer = array(); $_columnContainer[0]['value'] = $this->Language->Get('jira_noissuefound'); $_columnContainer[0]['align'] = 'left'; $_columnContainer[0]['width'] = '100%'; $_IssueHistoryTabObject->Row($_columnContainer); $_renderHTML = $_IssueHistoryTabObject->GetDisplayHTML(true); $_renderHTML .= '<script language="Javascript" type="text/javascript">'; $_renderHTML .= 'ClearFunctionQueue();'; $_renderHTML .= '</script>'; echo $_renderHTML; return true; } foreach ($_issuesContainer as $_Issue) { $_columnContainer = array(); $_issueURL = $_SWIFT->Settings->Get('bj_jiraurl') . 'browse/' . $_Issue->GetKey(); // Key $_columnContainer[0]['value'] = '<a href="' . $_issueURL . '" target="_blank">' . htmlspecialchars($_Issue->GetKey()) . '</a>'; $_columnContainer[0]['align'] = 'left'; $_columnContainer[0]['width'] = '10'; // Summary $_columnContainer[1]['value'] = '<a href="' . $_issueURL . '" target="_blank">' . IIF(strlen($_Issue->GetSummary()) > 100, htmlspecialchars(substr($_Issue->GetSummary(), 0, 100)) . '...', htmlspecialchars($_Issue->GetSummary())) . '</a>'; $_columnContainer[1]['align'] = 'left'; $_columnContainer[1]['width'] = '100'; // Updated $_columnContainer[3]['value'] = htmlspecialchars(SWIFT_Date::EasyDate($_Issue->GetUpdated()) . IIF(SWIFT_Date::EasyDate($_Issue->GetUpdated()) == $this->Language->Get('edjustnow'), '', ' ago')); $_columnContainer[3]['align'] = 'left'; $_columnContainer[3]['width'] = '10'; // Priority $_columnContainer[4]['value'] = htmlspecialchars($_Issue->GetPriority()); $_columnContainer[4]['align'] = 'left'; $_columnContainer[4]['width'] = '10'; // Status $_columnContainer[5]['value'] = htmlspecialchars($_Issue->GetStatus()); $_columnContainer[5]['align'] = 'left'; $_columnContainer[5]['width'] = '10'; // Comments $_columnContainer[6]['value'] = htmlspecialchars($_Issue->GetAssignee()); $_columnContainer[6]['align'] = 'left'; $_columnContainer[6]['width'] = '10'; // Unlink $_columnContainer[7]['value'] = '<a title="' . $this->Language->Get('postJIRAComment') . '" href="#" onclick="postJIRAComment(\'' . $_Issue->GetKey() . '\')"> <img src="' . SWIFT::Get('swiftpath') . SWIFT_APPSDIRECTORY . '/jira/resources/icon-comment.gif' . '"/> </a>' . ' | ' . '<a title="' . $this->Language->Get('jira_unlinkissue') . '" href="#" onclick="unlinkJIRAIssue(\'' . $_Issue->GetKey() . '\')"> <img src="' . SWIFT::Get('swiftpath') . SWIFT_APPSDIRECTORY . '/jira/resources/edit_delete.png' . '"/> </a>'; $_columnContainer[7]['align'] = 'left'; $_columnContainer[7]['width'] = '10'; $_IssueHistoryTabObject->Row($_columnContainer, '', $_Issue->GetKey()); //Fetch the issue comments now if ($_JIRABridge) { $_commentsContainer = $_JIRABridge->FetchAllCommentsBy('issuekey', $_Issue->GetKey()); if (isset($_columnContainer) && _is_array($_commentsContainer)) { $_renderedNotes = array(); foreach ($_commentsContainer as $_JIRAComment) { $_renderedNotes[] = '<div class="notebackground"> <div class="notecontainer"> <div class="note">' . nl2br($_JIRAComment->GetRawBody(), true) . '</div> </div> <cite class="tip"> <strong> <img border="0" align="absmiddle" src="' . SWIFT::Get('themepath') . 'images/icon_user2.png"/> ' . $_JIRAComment->GetAuthor() . ' ' . htmlspecialchars(SWIFT_Date::EasyDate($_JIRAComment->GetUpdated())) . ' ago </strong><div style="float: right; padding-right: 4px;"></div> </cite> </div>'; } $_renderedNotes = implode('', $_renderedNotes); $_commentContainer[0]['value'] = '<div class="allnotes">' . $_renderedNotes . '</div>'; $_commentContainer[0]['width'] = '100'; $_commentContainer[0]['align'] = 'left'; $_commentContainer[0]['colspan'] = '7'; $_commentContainer[0]['style'] = 'background: none repeat scroll 0pt 0pt #F6F1E7; padding: 0px;'; $_IssueHistoryTabObject->Row($_commentContainer, '', $_Issue->GetKey()); } } } $_renderHTML = $_IssueHistoryTabObject->GetDisplayHTML(true); echo $_renderHTML; return true; }
/** * Log errors from mailchimp results * * @author Ruchi Kothari * * @param array $_mailchimpResult Result recieved from MailChimp after performing various operations * * @return bool "true" on Success, "false" otherwise * @throws SWIFT_Exception If class is not loaded */ private function LogError($_mailchimpResult) { if (!$this->GetIsClassLoaded()) { throw new SWIFT_Exception(SWIFT_CLASSNOTLOADED); return false; } if (!_is_array($_mailchimpResult)) { return true; } $_errorString = ''; foreach ($_mailchimpResult as $_list) { if (!empty($_list['errors'])) { $_errorString .= "*****" . $_list['name'] . " Error***** :"; foreach ($_list['errors'] as $_error) { $_errorString .= ' Message: ' . $_error['message'] . SWIFT_CRLF; $_errorString .= ' Code: ' . $_error['code']; } } } if (!empty($_errorString)) { $_errorString = $this->Language->Get('mc_error') . $_errorString; // SWIFT_Loader::LoadLibrary('ErrorLog:ErrorLog'); SWIFT_ErrorLog::Create(SWIFT_ErrorLog::TYPE_GENERAL, $_errorString); } return true; }
/** * Get project security level * * @author Varun Shoor * * @param string $_projectKey * @param string $_issueType (OPTIONAL) * * @return bool "true" on Success, "false" otherwise * @throws SWIFT_Exception If the Class is not Loaded */ public function GetSecurityLevel($_projectKey, $_issueType = '') { header('content-type: application/json'); if (!$this->GetIsClassLoaded()) { throw new SWIFT_Exception(SWIFT_CLASSNOTLOADED); } if (empty($_projectKey)) { throw new SWIFT_Exception('Project Key ' . $this->Language->Get('jira_noempty')); } $_JIRABridge = SWIFT_JIRABridge::GetInstance(); $_securityLevelContainer = array(); if ($_JIRABridge && $_JIRABridge instanceof SWIFT_JIRABridge && $_JIRABridge->GetIsClassLoaded()) { $_ProjectSecurityLevels = $_JIRABridge->GetSecurityLevelsByProject($_projectKey, $_issueType); if ($_ProjectSecurityLevels && _is_array($_ProjectSecurityLevels)) { foreach ($_ProjectSecurityLevels as $_value => $_title) { $_securityLevelContainer[] = array('title' => $_title, 'value' => $_value); } echo json_encode(array('code' => 200, 'data' => $_securityLevelContainer)); } else { echo json_encode(array('code' => 204, 'data' => 'No security settings for this project')); return true; } } return false; }
/** * Unsubscribe Users(General function) * * @author Ruchi Kothari * * @param array $_membersList list of users grouprd by list id * @param bool $_deleteMember Delete a member on unsubscription or not * * @return array $_subscriptionResult Subscription result from mailchimp * @throws SWIFT_User_Exception If the Class is not Loaded or if object is not the instance of class * @throws SWIFT_Exception If error occured while Batch Subscribe */ public function Unsubscribe($_membersList, $_deleteMember) { if (!$this->GetIsClassLoaded()) { throw new SWIFT_Exception(SWIFT_CLASSNOTLOADED); return false; } if (!_is_array($_membersList)) { return false; } $_subscriptionResult = array(); foreach ($_membersList as $_listID => $_list) { if (count($_list) > 1) { $_subscriptionResult[$_listID] = $this->ListBatchUnubscribe($_listID, $_list, $_deleteMember); $_subscriptionResult[$_listID]['name'] = $this->_lists[$_listID]['name']; } else { $_subscriptionResult[$_listID][] = $this->ListUnsubscribe($_listID, current($_list), $_deleteMember); $_subscriptionResult[$_listID]['name'] = $this->_lists[$_listID]['name']; } } return $_subscriptionResult; }
/** * Posts a remote link to JIRA * * @author Abhinav Kumar * * @param string $_issueKey The JIRA issue key to the send to the request to * @param string $_ticketURL Kayako ticket URL for backlinking * @param string $_title Remote link title * @param string $_summary Remote link summary * @param int $_status Kayako ticket status * * @return bool "true" on Success, "false" otherwise * @throws SWIFT_Exception If the Class is not Loaded */ public function PostRemoteLink($_issueKey, $_ticketURL, $_title = '', $_summary = '', $_status = 1) { if (!$this->GetIsClassLoaded()) { throw new SWIFT_Exception(SWIFT_CLASSNOTLOADED); } if (empty($_issueKey) || empty($_ticketURL)) { throw new SWIFT_Exception(SWIFT_INVALIDDATA); } if (!$this->IsIssueValid($_issueKey)) { throw new SWIFT_Exception('Invalid Issue'); } $_SWIFT = SWIFT::GetInstance(); $_apiURL = $this->_url . 'rest/api/latest/issue/' . $_issueKey . '/remotelink'; $this->Client->SetURI($_apiURL); $_globalID = 'system=' . $_ticketURL; $objectPayload = ['url' => $_ticketURL, 'title' => $_title, 'icon' => ['url16x16' => SWIFT::Get('swiftpath') . '/favicon.ico', 'title' => SWIFT_PRODUCT]]; if ($_SWIFT->Settings->Get('bj_includesubjectinlink')) { $objectPayload['summary'] = $_summary; } $_ticketStatusClosed = false; $_ticketStatusCache = $_SWIFT->Cache->Get('statuscache'); if (_is_array($_ticketStatusCache)) { foreach ($_SWIFT->Cache->Get('statuscache') as $_ticketStatus) { if ($_ticketStatus['markasresolved']) { $_ticketStatusClosed = $_ticketStatus['ticketstatusid']; } } } if ($_ticketStatusClosed && $_status == $_ticketStatusClosed) { $objectPayload['status'] = ['resolved' => true, 'icon' => ['url16x16' => SWIFT::Get('swiftpath') . '__modules/jira/resources/resolved.png', 'title' => $this->Language->Get('jira_ticketclosed'), 'link' => $_ticketURL]]; } $this->Client->SetParameterPost('globalId', $_globalID); $this->Client->SetParameterPost('object', $objectPayload); $_Response = $this->Client->Request(SWIFT_HTTPBase::POST, $this->_connectionTimeout); if ($_Response && $_Response->isSuccessful()) { return true; } else { $_ResponseDecoded = json_decode($_Response->getBody()); $_responseContainer = get_object_vars($_ResponseDecoded); return $_responseContainer['errorMessages'][0]; } }
/** * Public Wrapper function on top of _setParameter * Sets the GET parameters * Accepts simple string as well as associative arrays * * @param string $_name * @param string $_value * * @author Abhinav Kumar * @throws SWIFT_Exception */ public function SetParameterGet($_name, $_value = null) { if (!$this->GetIsClassLoaded()) { throw new SWIFT_Exception(__CLASS__ . ' ' . SWIFT_CLASSNOTLOADED); } if (_is_array($_name)) { foreach ($_name as $_key => $_val) { $this->_setParameter(self::GET, $_key, $_val); } } else { $this->_setParameter(self::GET, $_name, $_value); } }
/** * Shorthand for Input * * @param mixed $fields Fields whatever. * @see _is_array */ protected function input($fields = null) { return is_null($fields) ? Input::all() : Input::only(_is_array($fields) ? $fields : [$fields]); }
/** * Makes an HTTP request based on the specified $_Method * to an $_Url with an optional array of string of $_Vars * * @param string $_Method * @param string $_Url * @param array $_Vars * * @return \SWIFT_HTTPResponse on success or 'false' otherwise */ public function Request($_Method = self::GET, $_Url = '', $_Vars = array()) { /** * Reset the error string */ $this->_error = 'No Error'; /** * Initialize the request */ $this->_Request = curl_init(); /** * Build query string */ if (_is_array($_Vars) && $_Method == self::GET) { $_Vars = http_build_query($_Vars, '', '&'); } /** * Set the request type */ $this->setRequestMethod($_Method); /** * Set the required CURLOPT options */ $this->setRequestOptions($_Url, $_Vars, $_Method); /** * Sets the required headers from $_Headers to CURLOPT */ $this->setRequestHeaders(); /** * Finally, fire the request */ $_Response = curl_exec($this->_Request); if ($_Response !== false) { curl_close($this->_Request); return $_Response; //= new SWIFT_HTTPResponse($_Response); } else { $this->_error = curl_errno($this->_Request) . ' - ' . curl_error($this->_Request); } //echo $this->_error; /** * Close the connection */ curl_close($this->_Request); return false; }