/** * Constructor of the container class. * * $options can have these keys: * 'servers' an array containing an array: servername, port, * sharedsecret, timeout, maxtries * 'configfile' The filename of the configuration file * 'authtype' The type of authentication, one of: PAP, CHAP_MD5, * MSCHAPv1, MSCHAPv2, default is PAP * * @param $options associative array * @return object Returns an error object if something went wrong */ function Auth_Container_RADIUS($options) { $this->authtype = 'PAP'; if (isset($options['authtype'])) { $this->authtype = $options['authtype']; } $classname = 'Auth_RADIUS_' . $this->authtype; if (!class_exists($classname)) { PEAR::raiseError("Unknown Authtype, please use on of: PAP, CHAP_MD5, MSCHAPv1, MSCHAPv2!", 41, PEAR_ERROR_DIE); } $this->radius = new $classname(); if (isset($options['configfile'])) { $this->radius->setConfigfile($options['configfile']); } $servers = $options['servers']; if (is_array($servers)) { foreach ($servers as $server) { $servername = $server[0]; $port = isset($server[1]) ? $server[1] : 0; $sharedsecret = isset($server[2]) ? $server[2] : 'testing123'; $timeout = isset($server[3]) ? $server[3] : 3; $maxtries = isset($server[4]) ? $server[4] : 3; $this->radius->addServer($servername, $port, $sharedsecret, $timeout, $maxtries); } } if (!$this->radius->start()) { PEAR::raiseError($this->radius->getError(), 41, PEAR_ERROR_DIE); } }
function _getResult() { if ($this->progress->hasErrors()) { $err = $this->progress->getError(); $this->assertTrue(false, $err['message']); } else { $this->assertTrue(true); } }
/** * Create or update a record to * DB from POST data or input array of data * * @param array $dataArray an array holding data to save. If empty, $_POST is used * @return integer id of created or updated record */ public function save($dataArray = null) { // get required tools jimport('joomla.database.table'); $this->_data = JTable::getInstance($this->_defaultTable, 'Sh404sefTable'); $post = is_null($dataArray) ? JRequest::get('post') : $dataArray; // use table save method try { $status = $this->_data->save($post); } catch (Exception $e) { ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage()); $this->_data->setError($e->getMessage()); $status = false; } // report error if (!$status) { JFactory::getApplication()->enqueuemessage($this->_data->getError()); return 0; } // if success, fetch last insert id and return that $tableDb = $this->_data->getDBO(); $keyName = $this->_data->getKeyName(); $id = empty($post[$keyName]) ? 0 : intval($post[$keyName]); $savedId = empty($id) ? $tableDb->insertid() : $id; return $savedId; }
/** * 开始处理上传 * * @return false|string */ public function upload() { //是否上传出错 if (!$this->file->isValid() or $this->file->getError() != UPLOAD_ERR_OK) { return false; } //保存的路径 $savePath = $this->setSavePath(); //保存的文件名 $saveFileName = $this->getSaveFileName() . '.' . $this->file->getClientOriginalExtension(); //保存 $this->file->move($savePath, $saveFileName); //文件是否存在 $realFile = $savePath . $saveFileName; if (!file_exists($realFile)) { return false; } //是否加上水印 if (isset($this->params['waterSetting']) and $this->params['waterSetting'] === true) { $waterImage = $this->params['waterImage']; if (!isset($this->params['waterImage']) or empty($this->params['waterImage'])) { $waterImage = $this->getWaterFile(); } $this->waterImage($realFile, $waterImage); } //返回文件 $realFileUrl[] = str_replace('/', '', str_replace($this->getConfigSavePath(), '', $realFile)); $thumbRealFileUrl = []; //是否要裁剪 if (isset($this->params['thumbSetting']) and !empty($this->params['thumbSetting'])) { $thumbRealFileUrl = $this->cutImage($realFile, $savePath); } $returnFileUrl = implode('|', array_merge($realFileUrl, $thumbRealFileUrl)); return $returnFileUrl; }
/** * returns one error (as String!) */ public function getError() { if ($this->SofortLib_Multipay) { if ($this->SofortLib_Multipay->isError('sr')) { return $this->SofortLib_Multipay->getError('sr'); } } if ($this->ConfirmSr) { if ($this->ConfirmSr->isError('sr')) { return $this->ConfirmSr->getError('sr'); } } if ($this->EditSr) { if ($this->EditSr->isError('sr')) { return $this->EditSr->getError('sr'); } } if ($this->CancelSr) { if ($this->CancelSr->isError('sr')) { return $this->CancelSr->getError('sr'); } } if ($this->SofortLib_TransactionData) { if ($this->SofortLib_TransactionData->isError('sr')) { return $this->SofortLib_TransactionData->getError('sr'); } } return ''; }
/** * 批量插入 * @param $list 数组 */ public function addAll($list) { $result = $this->model->addAll($list); if ($result === FALSE) { return $this->apiReturnErr($this->model->getError()); } else { return $this->apiReturnSuc($result); } }
/** * Default implementation for patch function. * Patch requests are routed here by the main Sync function. * These requests are usually coming from lists togglers and state buttons. * Usually there will be no need to override this function. * * @return void */ protected function patch() { // Check for token JSession::checkToken() or K2Response::throwError(JText::_('JINVALID_TOKEN')); // Batch update $ids = $this->input->get('id', array(), 'array'); JArrayHelper::toInteger($ids); $states = $this->input->get('states', array(), 'array'); $mode = $this->input->get('mode', 'apply', 'string'); // Ensure we have ids $ids = array_filter($ids); if (!count($ids)) { K2Response::throwError(JText::_('K2_NO_ROWS_SELECTED'), 401); } foreach ($ids as $key => $id) { $data = array(); $data['id'] = $id; foreach ($states as $state => $values) { $value = is_array($values) ? $values[$key] : $values; if ($value != '') { $data[$state] = $value; } } if ($mode == 'clone') { $sourceData = $this->model->getCopyData($id); $data = array_merge($sourceData, $data); $data['id'] = null; $this->model->setState('patch', false); } else { $this->model->setState('patch', true); } $this->model->setState('data', $data); $result = $this->model->save(); if (!$result) { K2Response::throwError($this->model->getError()); } } // Trigger change state event for items and categories if ($mode != 'clone' && isset($states['state']) && in_array($this->resourceType, array('items', 'categories'))) { // Get dispatcher $dispatcher = JDispatcher::getInstance(); // Import content plugins JPluginHelper::importPlugin('content'); if ($this->resourceType == 'items') { $eventName = 'onContentChangeState'; $context = 'com_k2.' . $this->resourceType; } else { if ($this->resourceType == 'categories') { $eventName = 'onCategoryChangeState'; $context = 'com_k2'; } } $dispatcher->trigger($eventName, array($context, $ids, $states['state'])); } K2Response::setResponse($result); }
/** * init * initialize the module * sets up our sockets and loads the configuration settings * * @access public * @return void */ public function init() { // Set up the constants require_once('modules/source_rcon/defines.php'); $this->readConfig(); // Set up TCP sending socket $this->m_oSendSock = new connection($this->m_aConfig['server']['ip'], $this->m_aConfig['server']['port'], 5); $this->m_oSendSock->setSocketClass($this->socketClass); $this->m_oSendSock->setIrcClass($this->ircClass); $this->m_oSendSock->setTimerClass($this->timerClass); $this->m_oSendSock->setCallbackClass($this); $this->m_oSendSock->init(); if ($this->m_oSendSock->getError()) { $this->destroy('Error creating TCP socket: ' . $this->m_oSendSock->getErrorMsg()); return; } $this->m_oSendSock->connect(); $this->m_iSendSock = $this->m_oSendSock->getSockInt(); // setup UDP socket for recieviing server logs if (!$this->m_oRecvSock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP)) { $this->destroy('Error creating UDP socket [1]'); return; } if (!socket_bind($this->m_oRecvSock, '0.0.0.0', $this->m_aConfig['local']['port'])) { $this->destroy('Error creating UDP socket [2]'); return; } if (!socket_set_nonblock($this->m_oRecvSock)) { $this->destroy('Error creating UDP socket [3]'); return; } // set up udp reading process $this->timerClass->addTimer('parseReadLog', $this, 'parseReadLog', '', 0.1, true); // add the status timer, call it every 5 minutes $this->timerClass->addTimer('statusQuery', $this, 'statusQuery', '', 300, false); // add our UDP handlers $this->registerHandlers(); // initiate logging to file $this->openLogfile(); }
/** * Method to get category by catid. * * @param integer $pk Category id. * * @return mixed Category object or false. */ public function getCategory($pk = null) { if (!empty($this->category)) { return $this->category; } $pk = $pk ? $pk : $this->getItem()->catid; $this->category = JTable::getInstance('Category'); if (!$this->category->load($pk)) { $this->setError($this->category->getError()); return false; } return $this->category; }
/** * Defines the calendar by a Unix timestamp, replacing values * passed to the constructor * @param int Unix timestamp * @return boolean * @access public */ function setTimestamp($ts) { if (!$this->validator->validTimestamp($ts)) { trigger_error('Calendar::setTimestamp ' . $this->validator->getError()); return false; } $this->year = date('Y', $ts); $this->month = date('m', $ts); $this->day = date('d', $ts); $this->hour = date('H', $ts); $this->minute = date('i', $ts); $this->second = date('s', $ts); return true; }
/** * Delete a record * * @return boolean True on success, false on error */ public function delete() { // Can't delete what doesn't exist if (!$this->exists()) { return true; } // Remove record from the database if (!$this->_tbl->delete()) { $this->setError($this->_tbl->getError()); return false; } // Hey, no errors! return true; }
/** * Table delete method * * @param mixed Can either be a row, an array of rows or a query object * @throws KDatabaseTableException * @return boolean True if successful otherwise returns false */ public function delete($where) { $table = $this->getTableName(); //Create where statement if (!$where instanceof KDatabaseQuery) { $rows = (array) $where; //Create where statement if (count($rows)) { $where = $this->_db->getQuery()->where($this->getPrimaryKey(), 'IN', $rows); } } $result = $this->_db->delete($table, $where); if ($err = $this->_db->getError()) { throw new KDatabaseTableException($err); } return $result; }
/** * 开始处理上传 * * @return false|array */ public function upload() { if (!$this->file->isValid() or $this->file->getError() != UPLOAD_ERR_OK) { return false; } $saveFileName = $this->getSaveFileName() . '.' . $this->file->getClientOriginalExtension(); $savePath = $this->setSavePath(); $this->file->move($savePath, $saveFileName); $realFile = $savePath . $saveFileName; if (!file_exists($realFile)) { return false; } $this->doWaterImage($realFile); $realFileUrl[] = substr(str_replace($this->getConfigSavePath(), '', $realFile), 1); $thumbRealFileUrl = $this->doCutImage($realFile, $savePath); return array_merge($realFileUrl, $thumbRealFileUrl); }
/** * returns one error (as String!) */ function getError() { if ($this->multipay) { if ($this->multipay->isError('sr')) { return $this->multipay->getError('sr'); } } if ($this->confirmSr) { if ($this->confirmSr->isError('sr')) { return $this->confirmSr->getError('sr'); } } if ($this->transactionData) { if ($this->transactionData->isError('sr')) { return $this->transactionData->getError('sr'); } } return ''; }
/** * Create or update a record to * DB from POST data or input array of data * * @param array $dataArray an array holding data to save. If empty, $_POST is used * @return integer id of created or updated record */ public function save($dataArray = null) { // get required tools jimport('joomla.database.table'); $this->_data =& JTable::getInstance($this->_defaultTable, 'Sh404sefTable'); $post = is_null($dataArray) ? JRequest::get('post') : $dataArray; // use table save method $status = $this->_data->save($post); // report error if (!$status) { $app =& JFactory::getApplication(); $app->enqueuemessage($this->_data->getError()); return 0; } // if success, fetch last insert id and return that $tableDb =& $this->_data->getDBO(); $keyName = $this->_data->getKeyName(); $id = empty($post[$keyName]) ? 0 : intval($post[$keyName]); $savedId = empty($id) ? $tableDb->insertid() : $id; return $savedId; }
/** * Method to run batch operations. * * @param object $model The model of the component being processed. * * @return boolean True if successful, false otherwise and internal error is set. * * @since 11.1 */ public function batch($model) { // Initialise variables. $app = JFactory::getApplication(); $vars = JRequest::getVar('batch', array(), 'post', 'array'); $cid = JRequest::getVar('cid', array(), 'post', 'array'); // Attempt to run the batch operation. if ($model->batch($vars, $cid)) { $this->setMessage(JText::_('JLIB_APPLICATION_SUCCESS_BATCH')); return true; } else { $this->setMessage(JText::sprintf('JLIB_APPLICATION_ERROR_BATCH_FAILED', $model->getError())); return false; } }
/** * returns formated sql errors from rex_sql object * @param object $obj rex_sql object * @return string $err_msg formated Error message */ function rex_formated_sqlerror($obj) { $err_msg = '<strong style="display:inline-block;width:50px;">Query</strong> <code style="color:#000;">' . $obj->query . '</code><br />' . PHP_EOL . '<strong style="display:inline-block;width:50px;">Error</strong> <code style="color:#000;">#' . $obj->getErrno() . ' - ' . $obj->getError() . '</code><br /><hr />' . PHP_EOL; return $err_msg; }
/** * Method to run batch operations. * * @param object $model The model of the component being processed. * * @return boolean True if successful, false otherwise and internal error is set. * * @since 11.1 */ public function batch($model) { // Initialise variables. $input = JFactory::getApplication()->input; $vars = $input->post->get('batch', array(), 'array'); $cid = $input->post->get('cid', array(), 'array'); // Build an array of item contexts to check $contexts = array(); foreach ($cid as $id) { // If we're coming from com_categories, we need to use extension vs. option if (isset($this->extension)) { $option = $this->extension; } else { $option = $this->option; } $contexts[$id] = $option . '.' . $this->context . '.' . $id; } // Attempt to run the batch operation. if ($model->batch($vars, $cid, $contexts)) { $this->setMessage(JText::_('JLIB_APPLICATION_SUCCESS_BATCH')); return true; } else { $this->setMessage(JText::sprintf('JLIB_APPLICATION_ERROR_BATCH_FAILED', $model->getError())); return false; } }
/** * Method to copy/move the files for a new image. * This method also creates new file names for the images and stores the row. * * @param object $row Holds the data of the new image. * @param string $catpath The catpath of the new image * @param string $detail_catpath The catpath of the detail image to copy * @param string $thumb_catpath The catpath of the thumbnail to copy * @param int $copy_original Indicates whether the original image should be copied, too * @return boolean True on success, false otherwise * @since 1.5.5 */ protected function _newImage($row, $catpath, $detail_catpath, $thumb_catpath, $copy_original) { jimport('joomla.filesystem.file'); // Create new file names $date = date('Ymd'); $filename = JoomFile::fixFilename($row->imgtitle); $img_tag = JFile::getExt($row->imgfilename); $thumb_tag = JFile::getExt($row->imgthumbname); $src_imgfilename = $row->imgfilename; $src_imgthumbname = $row->imgthumbname; do { mt_srand(); $randomnumber = mt_rand(1000000000, 2099999999); // New filename $newfilename = $filename . '_' . $date . '_' . $randomnumber; } while (JFile::exists($this->_ambit->getImg('orig_path', $newfilename . '.' . $img_tag, null, $row->catid)) || JFile::exists($this->_ambit->getImg('img_path', $newfilename . '.' . $img_tag, null, $row->catid)) || JFile::exists($this->_ambit->getImg('thumb_path', $newfilename . '.' . $thumb_tag, null, $row->catid))); $row->imgfilename = $newfilename . '.' . $img_tag; $row->imgthumbname = $newfilename . '.' . $thumb_tag; // If the destination thumbnail directory doesn't exist if (!JFolder::exists($this->_ambit->get('thumb_path') . $catpath)) { // Raise an error message and abort $this->_mainframe->enqueueMessage(JText::sprintf('COM_JOOMGALLERY_FOLDER_NOT_EXISTENT', $this->_ambit->get('thumb_path') . $catpath), 'error'); return false; } // Try to copy the thumbnail from source to destination $result = JFile::copy(JPath::clean($this->_ambit->get('thumb_path') . $thumb_catpath . $src_imgthumbname), JPath::clean($this->_ambit->get('thumb_path') . $catpath . $row->imgthumbname)); if (!$result) { // Raise an error message and abort $this->_mainframe->enqueueMessage(JText::sprintf('COM_JOOMGALLERY_ERROR_COPYING_THUMB', $this->_ambit->get('thumb_path') . $catpath . $row->imgthumbname), 'error'); return false; } // Same procedure like thumbnail for copying the detail image // In case of error delete the copied thumbnail from destination if (!JFolder::exists($this->_ambit->get('img_path') . $catpath)) { JFile::delete($this->_ambit->get('thumb_path') . $catpath . $row->imgthumbname); $this->_mainframe->enqueueMessage(JText::sprintf('COM_JOOMGALLERY_FOLDER_NOT_EXISTENT', $this->_ambit->get('img_path') . $catpath), 'error'); return false; } $result = JFile::copy(JPath::clean($this->_ambit->get('img_path') . $detail_catpath . $src_imgfilename), JPath::clean($this->_ambit->get('img_path') . $catpath . $row->imgfilename)); if (!$result) { JFile::delete($this->_ambit->get('thumb_path') . $catpath . $row->imgthumbname); $this->_mainframe->enqueueMessage(JText::sprintf('COM_JOOMGALLERY_ERROR_COPYING_IMAGE', $this->_ambit->get('img_path') . $catpath . $row->imgfilename), 'error'); return false; } // If setted to create an original image do the following action, // otherwise do not copy the image $orig_created = false; if ($copy_original) { if (JFile::exists($this->_ambit->get('orig_path') . $detail_catpath . $src_imgfilename)) { // Use the path to original images from now on $imagepath = $this->_ambit->get('orig_path') . $detail_catpath; } else { // Image doesn't exist // Use the path to detail images from now and use detail image as original image $imagepath = $this->_ambit->get('img_path') . $detail_catpath; } if (!JFolder::exists($this->_ambit->get('orig_path') . $catpath)) { // Directory doesn't exist, so delete the thumbnail and the detail image JFile::delete($this->_ambit->get('thumb_path') . $catpath . $row->imgthumbname); JFile::delete($this->_ambit->get('img_path') . $catpath . $row->imgfilename); // Raise an error message and abort $this->_mainframe->enqueueMessage(JText::sprintf('COM_JOOMGALLERY_FOLDER_NOT_EXISTENT', $this->_ambit->get('orig_path') . $catpath), 'error'); return false; } // Destination directory exists, so try to copy the image from source to destination $result = JFile::copy(JPath::clean($imagepath . $src_imgfilename), JPath::clean($this->_ambit->get('orig_path') . $catpath . $row->imgfilename)); if (!$result) { // Delete thumbnail and detail image JFile::delete($this->_ambit->get('thumb_path') . $catpath . $row->imgthumbname); JFile::delete($this->_ambit->get('img_path') . $catpath . $row->imgfilename); $this->_mainframe->enqueueMessage(JText::sprintf('COM_JOOMGALLERY_ERROR_COPYING_ORIGINAL%s', $this->_ambit->get('orig_path') . $catpath . $row->imgfilename), 'error'); return false; } $orig_created = true; } // Store the record // If not succesful raise an error messages and abort if (!$row->store()) { // Delete the thumbnail, detail image and original image JFile::delete($this->_ambit->get('thumb_path') . $catpath . $row->imgthumbname); JFile::delete($this->_ambit->get('img_path') . $catpath . $row->imgfilename); if ($orig_created) { JFile::delete($this->_ambit->get('orig_path') . $catpath . $row->imgfilename); } $this->_mainframe->enqueueMessage($row->getError(), 'error'); return false; } return true; }
/** * Upload file * * @param object $file Slim fileUpload object * @param string $fileName Filename to be renamed after uploading * @return boolean File upload successful or not */ protected function upload($file, $fileName = null) { if ($fileName === null) { $fileName = $this->getFileName($file->getClientFilename()); } if ($file->getError() === UPLOAD_ERR_OK) { $file->moveTo($this->path . $fileName); return true; } return false; }
/** * Method to determine if a NuSoap fault or error occurred. * If so, output any relevant info and stop the code from executing. * * @param object $nsc NuSoap client */ public function hasFaultOrError($nsc, $showErrors = false) { //$this->error = NULL; try { if ($nsc->fault || $nsc->getError()) { if (!$nsc->fault) { $message = $nsc->getError(); } else { $code = $nsc->faultcode; $message = $nsc->faultstring; } throw new EtapestryAPIException($message); } } catch (EtapestryAPIException $e) { $this->error = $e->getMessage(); $e->log_error($e->getMessage()); if ($showErrors) { echo $this->error . "\n"; } return true; } return false; }
/** * Creates the database entry for a successfully uploaded image * * @param object $row The JTable object of the images table to work with * @param string $origfilename The original file name of the uploaded image * @param string $newfilename The new file name for the image * @param string $tag The extension of the uploaded image * @param int $serial The counter for the numbering of the image titles * @return boolean True on success, false otherwise * @since 1.5.7 */ protected function registerImage($row, $origfilename, $newfilename, $tag, $serial = null) { // Get the specified image information (either from session or from post) $old_info = $this->_mainframe->getUserState('joom.upload.post'); $cur_info = !is_null($old_info) ? $old_info : array(); $new_info = JRequest::get('post'); // Prevent setting access level in frontend if (isset($new_info['access']) && $this->_site) { unset($new_info['access']); } // Save the new value only if it was set in this request if (count($new_info)) { $this->_mainframe->setUserState('joom.upload.post', $new_info); $data = $new_info; } else { $data = $cur_info; } if (!$row->bind($data)) { $this->_debugoutput .= $row->getError(); $this->debug = true; return false; } // Image title if ($this->_site && $this->_config->get('jg_useruseorigfilename') || !$this->_site && $this->_config->get('jg_useorigfilename')) { $taglength = strlen($tag); $filenamelength = strlen($origfilename); $row->imgtitle = substr($origfilename, -$filenamelength, -$taglength - 1); } // Add counter number if set in backend if (!is_null($serial)) { $imgname_separator = JText::_('COM_JOOMGALLERY_UPLOAD_IMAGENAME_SEPARATOR'); if ($imgname_separator == 'space') { $imgname_separator = ' '; } $row->imgtitle = $row->imgtitle . $imgname_separator . $serial; } // Owner if ($this->_site) { $row->owner = $this->_user->get('id'); } else { $row->owner = 0; } // Date $date = JFactory::getDate(); $row->imgdate = $date->toSQL(); // Check whether images are approved directly if we are in frontend if ($this->_site && $this->_config->get('jg_approve') == 1) { $row->approved = 0; } else { $row->approved = 1; } $row->imgfilename = $newfilename; $row->imgthumbname = $newfilename; $row->useruploaded = intval($this->_site); $row->ordering = $this->_getOrdering($row); if (!$row->check()) { $this->_debugoutput .= $row->getError() . '<br />'; $this->debug = true; return false; } if (!$row->store()) { $this->_debugoutput .= $row->getError() . '<br />'; $this->debug = true; return false; } return true; }
/** * 返回数据库的错误信息 * * @author liu21st <*****@*****.**> * @lastmodify 2013-01-21 15:10:46 by mrmsl * * @return string 数据库错误信息 * */ public function getDbError() { return $this->_db->getError(); }