コード例 #1
0
 /**
  * Регистрируем хуки
  */
 public function RegisterHook()
 {
     if (F::AjaxRequest()) {
         return;
     }
     $xShowStats = Config::Get('general.show.stats');
     // if is null then show to admins only
     if (is_null($xShowStats) && E::IsAdmin() || $xShowStats === true || is_array($xShowStats) && in_array(E::UserId(), $xShowStats)) {
         $xShowStats = R::GetIsShowStats();
     } else {
         $xShowStats = false;
     }
     if ($xShowStats) {
         $this->AddHook('template_layout_body_end', 'Statistics', __CLASS__, -1000);
         // LS-compatibility
         $this->AddHook('template_body_end', 'Statistics', __CLASS__, -1000);
     }
 }
コード例 #2
0
ファイル: Action.class.php プロジェクト: anp135/altocms
 /**
  * Метод запрета доступа к ивенту
  * @param string $sEvent Наименование ивента
  * @return bool
  */
 public function AccessDenied($sEvent = null)
 {
     if (!F::AjaxRequest()) {
         return $this->EventNotFound();
     }
     echo 'Access denied';
     return null;
 }
コード例 #3
0
ファイル: ActionAjax.class.php プロジェクト: anp135/altocms
 /**
  * Загрузка изображения
  *
  */
 protected function EventUploadImage()
 {
     /*
      * Т.к. используется обработка отправки формы, то устанавливаем тип ответа 'jsonIframe'
      * (тот же JSON только обернутый в textarea)
      * Это позволяет избежать ошибок в некоторых браузерах, например, Opera
      */
     E::ModuleViewer()->SetResponseAjax(F::AjaxRequest(true) ? 'json' : 'jsonIframe', false);
     // * Пользователь авторизован?
     if (!$this->oUserCurrent) {
         E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('need_authorization'), E::ModuleLang()->Get('error'));
         return;
     }
     $sFile = null;
     // * Был выбран файл с компьютера и он успешно загрузился?
     if ($aUploadedFile = $this->GetUploadedFile('img_file')) {
         $aOptions = array();
         // Check options of uploaded image
         if ($nWidth = $this->GetPost('img_width')) {
             if ($this->GetPost('img_width_unit') == 'percent') {
                 // Max width according width of text area
                 if ($this->GetPost('img_width_ref') == 'text' && ($nWidthText = intval($this->GetPost('img_width_text')))) {
                     $nWidth = round($nWidthText * $nWidth / 100);
                     $aOptions['size']['width'] = $nWidth;
                 }
             }
         }
         $sFile = E::ModuleTopic()->UploadTopicImageFile($aUploadedFile, $this->oUserCurrent, $aOptions);
         if (!$sFile) {
             $sMessage = E::ModuleLang()->Get('uploadimg_file_error');
             if (E::ModuleUploader()->GetError()) {
                 $sMessage .= ' (' . E::ModuleUploader()->GetErrorMsg() . ')';
             }
             E::ModuleMessage()->AddErrorSingle($sMessage, E::ModuleLang()->Get('error'));
             return;
         }
     } elseif (($sUrl = $this->GetPost('img_url')) && $sUrl != 'http://') {
         // * Загрузка файла по URL
         if (preg_match('~(https?:\\/\\/)(\\w([\\w]+)?\\.[\\w\\.\\-\\/]+.*)$~i', $sUrl, $aM)) {
             // Иногда перед нормальным адресом встречается лишний 'http://' и прочий "мусор"
             $sUrl = $aM[1] . $aM[2];
             $sFile = E::ModuleTopic()->UploadTopicImageUrl($sUrl, $this->oUserCurrent);
         }
     } else {
         E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('uploadimg_file_error'));
         return;
     }
     // * Если файл успешно загружен, формируем HTML вставки и возвращаем в ajax ответе
     if ($sFile) {
         $sText = E::ModuleImg()->BuildHTML($sFile, $_REQUEST);
         E::ModuleViewer()->AssignAjax('sText', $sText);
     } else {
         E::ModuleMessage()->AddErrorSingle(E::ModuleUploader()->GetErrorMsg(), E::ModuleLang()->Get('error'));
     }
 }
コード例 #4
0
ファイル: Router.class.php プロジェクト: hard990/altocms
 /**
  * Проверяет запрос послан как ajax или нет
  *
  * @return bool
  */
 public static function GetIsAjaxRequest()
 {
     return F::AjaxRequest();
 }
コード例 #5
0
ファイル: Security.class.php プロジェクト: ZeoNish/altocms
 /**
  * Generates security key for the current session
  *
  * @return string
  */
 protected function _generateSecurityKey()
 {
     // Сохраняем текущий ключ для ajax-запросов
     if (F::AjaxRequest() && ($sKey = E::ModuleSession()->Get($this->sSecurityKeyName))) {
         return $sKey;
     }
     if (Config::Get('module.security.randomkey')) {
         return F::RandomStr($this->sSecurityKeyLen);
     } else {
         //return md5(E::ModuleSession()->GetId().Config::Get('module.security.hash'));
         return md5($this->GetUniqKey() . $this->GetClientHash() . Config::Get('module.security.hash'));
     }
 }
コード例 #6
0
ファイル: function.php プロジェクト: AntiqS/altocms
/**
 * DEPRECATED FUNCTIONS
 */
function isAjaxRequest()
{
    return F::AjaxRequest();
}
コード例 #7
0
ファイル: ActionApi.class.php プロジェクト: ZeoNish/altocms
 /**
  * Проверка на право доступа к методу API
  *
  * @param string $sEvent
  * @return bool|string
  */
 public function Access($sEvent)
 {
     /**
      * Возможно это ajax-запрос, тогда нужно проверить разрешены ли
      * вообще такие запросы к нашему API
      */
     if (F::AjaxRequest()) {
         if (C::Get('module.api.ajax')) {
             $this->bIsAjax = TRUE;
             E::ModuleViewer()->SetResponseAjax('json');
         } else {
             return $this->_Error(E::ModuleApi()->ERROR_CODE_0014);
         }
     } else {
         /**
          * Проверим, разрешённые типы запросов к АПИ
          */
         foreach (array('post' => E::ModuleApi()->ERROR_CODE_0010, 'get' => E::ModuleApi()->ERROR_CODE_0011, 'put' => E::ModuleApi()->ERROR_CODE_0012, 'delete' => E::ModuleApi()->ERROR_CODE_0013) as $sRequestMethod => $aErrorDescription) {
             if ($this->_CheckRequestMethod($sRequestMethod) && !C::Get("module.api.{$sRequestMethod}")) {
                 return $this->_Error($aErrorDescription);
             }
         }
     }
     return TRUE;
 }
コード例 #8
0
 /**
  * Загрузка временной картинки фото для последущего ресайза
  */
 protected function EventUploadPhoto()
 {
     if (isset($_FILES['foto']) && !isset($_FILES['photo'])) {
         $_FILES['photo'] = $_FILES['foto'];
     }
     // * Устанавливаем формат Ajax ответа
     $this->Viewer_SetResponseAjax(F::AjaxRequest(true) ? 'json' : 'jsonIframe', false);
     if (!($aUploadedFile = $this->GetUploadedFile('photo')) && !($aUploadedFile = $this->GetUploadedFile('foto'))) {
         $this->Message_AddError($this->Lang_Get('settings_profile_photo_error'), $this->Lang_Get('error'));
         return;
     }
     $sError = '';
     $sTmpFile = $this->Uploader_UploadLocal($aUploadedFile);
     if ($sTmpFile && $this->Img_MimeType($sTmpFile)) {
         /**
          * Ресайзим и сохраняем уменьшенную копию
          * Храним две копии - мелкую для показа пользователю и крупную в качестве исходной для ресайза
          */
         $sPreviewFile = $this->Uploader_GetUserAvatarDir($this->oUserCurrent->getId()) . 'photo-preview.' . F::File_GetExtension($sTmpFile, true);
         if ($sPreviewFile = $this->Img_Copy($sTmpFile, $sPreviewFile, self::PREVIEW_RESIZE, self::PREVIEW_RESIZE)) {
             // * Сохраняем в сессии временный файл с изображением
             $this->Session_Set('sPhotoTmp', $sTmpFile);
             $this->Session_Set('sPhotoPreview', $sPreviewFile);
             $this->Viewer_AssignAjax('sTmpFile', $this->Uploader_Dir2Url($sPreviewFile));
             return;
         }
     } else {
         $sError = $this->Uploader_GetErrorMsg();
         if (!$sError) {
             $sError = $this->Lang_Get('settings_profile_photo_error');
         }
     }
     $this->Message_AddError($sError, $this->Lang_Get('error'));
     F::File_Delete($sTmpFile);
 }