Alex Trofimov 12 лет назад
Родитель
Сommit
2fde2956e8

+ 22 - 10
inc/utils.inc.php

@@ -567,20 +567,33 @@ function genSiteStatCache() {
 }
 
 /**
- * import class file, it detect class path by its prefix or module array
+ * Import class file, it automatically detects class path by its prefix or module array/name
  *
- * @param $sClassName - full class name or class postfix in a case of module class
- * @param $aModule - module array or true to get module array from global variable
+ * @param $sClassName - full class name or class postfix(withoit prefix) in the case of module class
+ * @param $mixedModule - module array or module name in the case of module class
  */
-function bx_import($sClassName, $aModule = array()) {
+function bx_import($sClassName, $mixedModule = array()) {
     if (class_exists($sClassName))
         return;
 
+    $aModule = false;
+    if ($mixedModule) {
+        if (is_array($mixedModule)) {
+            $aModule = $mixedModule;
+        } elseif (is_string($mixedModule)) {
+            bx_import('BxDolModule');
+            $o = BxDolModule::getInstance($mixedModule);
+            $aModule = $o->_aModule;
+        } elseif (is_bool($mixedModule) && true === $mixedModule) {
+            $aModule = $GLOABLS['aModule'];
+        }
+    }
+
     if ($aModule) {
-        $a = (true === $aModule) ? $GLOABLS['aModule'] : $aModule;
-        if (class_exists($a['class_prefix'] . $sClassName))
+        if (class_exists($aModule['class_prefix'] . $sClassName))
             return;
-        require_once (BX_DIRECTORY_PATH_MODULES . $a['path'] . 'classes/' . $a['class_prefix'] . $sClassName . '.php');
+        require_once (BX_DIRECTORY_PATH_MODULES . $aModule['path'] . 'classes/' . $aModule['class_prefix'] . $sClassName . '.php');
+        return;
     }
 
     if (0 == strncmp($sClassName, 'BxDol', 5)) {
@@ -609,13 +622,12 @@ function bx_import($sClassName, $aModule = array()) {
             $sPath = BX_DIRECTORY_PATH_MODULES . BxDolTemplate::getInstance()->getPath() . 'data/template/system/scripts/' . $sClassName . '.php';
         }
 
-        if(file_exists($sPath)) {
+        if (file_exists($sPath)) {
             require_once($sPath);
             return;
         }
 
-        echo "<b>Fatal error:</b> Class (" . $sClassName . ") not found.";
-        exit;
+        trigger_error ("bx_import fatal error: class (" . $sClassName . ") wasn't found", E_USER_ERROR);
     }
 }
 

+ 32 - 0
modules/boonex/notes/classes/BxNotesConfig.php

@@ -13,6 +13,38 @@ bx_import('BxDolModuleConfig');
 
 class BxNotesConfig extends BxDolModuleConfig {
 
+    public $CNF = array (
+        'FIELD_ID' => 'id',
+        'FIELD_AUTHOR' => 'author',
+        'FIELD_ADDED' => 'added',
+        'FIELD_CHANGED' => 'changed',
+        'FIELD_TITLE' => 'title',
+        'FIELD_TEXT' => 'text',
+        'FIELD_TEXT_ID' => 'note-text',
+        'FIELD_SUMMARY' => 'summary',
+        'FIELD_SUMMARY_ID' => 'note-summary',
+        'FIELD_ALLOW_VIEW_TO' => 'allow_view_to',
+        'FIELD_PHOTO' => 'pictures',
+        'FIELD_THUMB' => 'thumb',
+
+        'OBJECT_STORAGE' => 'bx_notes_photos',
+        'OBJECT_IMAGES_TRANSCODER_PREVIEW' => 'bx_notes_preview',
+        'OBJECT_VIEWS' => 'bx_notes',
+        'OBJECT_VOTES' => 'bx_notes',
+        'OBJECT_COMMENTS' => 'bx_notes',
+        'OBJECT_PRIVACY_VIEW' => 'bx_notes_allow_view_to',
+
+        'MENU_ITEM_TO_METHOD' => array (
+            'bx_notes_my' => array (
+                'create-note' => 'isAllowedAdd',
+            ),
+            'bx_notes_view' => array (
+                'edit-note' => 'isAllowedEdit',
+                'delete-note' => 'isAllowedDelete',
+            ),
+        ),
+    );
+
     public static $FIELD_ID = 'id';
     public static $FIELD_AUTHOR = 'author';
     public static $FIELD_ADDED = 'added';

+ 1 - 1
modules/boonex/notes/classes/BxNotesDb.php

@@ -12,7 +12,7 @@
 bx_import('BxDolModuleDb');
 
 /*
- * Notes module database queries
+ * Module database queries
  */
 class BxNotesDb extends BxDolModuleDb {
 

+ 221 - 0
modules/boonex/notes/classes/BxNotesFormEntry.php

@@ -0,0 +1,221 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    Notes Notes
+ * @ingroup     DolphinModules
+ *
+ * @{
+ */
+
+bx_import('BxTemplFormView');
+
+/**
+ * Create/Edit entry form
+ */
+class BxNotesFormEntry extends BxTemplFormView 
+{
+    protected static $MODULE = 'bx_notes';
+
+    protected $_oModule;
+
+    public function __construct($aInfo, $oTemplate = false) 
+    {
+        parent::__construct($aInfo, $oTemplate);
+        
+        $this->_oModule = BxDolModule::getInstance(self::$MODULE);
+
+        $CNF = &$this->_oModule->_oConfig->CNF;
+
+        if (isset($this->aInputs[$CNF['FIELD_TEXT']])) {            
+            $this->aInputs[$CNF['FIELD_TEXT']]['attrs'] = array_merge (
+                array ('id' => $CNF['FIELD_TEXT_ID']),
+                is_array($this->aInputs[$CNF['FIELD_TEXT']]['attrs']) ? $this->aInputs[$CNF['FIELD_TEXT']]['attrs'] : array ()
+            );            
+        }
+
+        if (isset($this->aInputs[$CNF['FIELD_SUMMARY']])) {
+            $this->aInputs[$CNF['FIELD_SUMMARY']]['attrs'] = array_merge (
+                array ('id' => $CNF['FIELD_SUMMARY_ID']),
+                is_array($this->aInputs[$CNF['FIELD_SUMMARY']]['attrs']) ? $this->aInputs[$CNF['FIELD_SUMMARY']]['attrs'] : array ()
+            );            
+        }
+
+        if (isset($this->aInputs[$CNF['FIELD_PHOTO']])) {
+            $this->aInputs[$CNF['FIELD_PHOTO']]['storage_object'] = $CNF['OBJECT_STORAGE'];
+            $this->aInputs[$CNF['FIELD_PHOTO']]['uploaders'] = array('sys_simple', 'sys_html5');
+            $this->aInputs[$CNF['FIELD_PHOTO']]['images_transcoder'] = $CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW'];
+            $this->aInputs[$CNF['FIELD_PHOTO']]['multiple'] = true;
+            $this->aInputs[$CNF['FIELD_PHOTO']]['content_id'] = 0;
+            $this->aInputs[$CNF['FIELD_PHOTO']]['ghost_template'] = '';
+        }
+
+        if (isset($this->aInputs[$CNF['FIELD_ALLOW_VIEW_TO']])) {
+            bx_import('BxDolPrivacy');
+            $this->aInputs[$CNF['FIELD_ALLOW_VIEW_TO']] = BxDolPrivacy::getGroupChooser($CNF['OBJECT_PRIVACY_VIEW']);
+        }
+    }
+
+    function initChecker ($aValues = array (), $aSpecificValues = array())  
+    {
+        $CNF = &$this->_oModule->_oConfig->CNF;
+
+        if (isset($this->aInputs[$CNF['FIELD_PHOTO']])) {
+
+            $aContentInfo = false;
+            if ($aValues && !empty($aValues['id'])) {
+                $aContentInfo = $this->_oModule->_oDb->getContentInfoById ($aValues['id']);
+                $this->aInputs[$CNF['FIELD_PHOTO']]['content_id'] = $aValues['id'];
+            }
+            
+            $aVars = array (
+                'name' => $this->aInputs[$CNF['FIELD_PHOTO']]['name'],
+                'content_id' => $this->aInputs[$CNF['FIELD_PHOTO']]['content_id'],
+                'editor_id' => $CNF['FIELD_TEXT_ID'],
+                'summary_id' => $CNF['FIELD_SUMMARY_ID'],
+                'thumb_id' => $aContentInfo[$CNF['FIELD_THUMB']],
+                'bx_if:set_thumb' => array (
+                    'condition' => CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->isAllowedSetThumb(),
+                    'content' => array (
+                        'name_thumb' => $CNF['FIELD_THUMB'],
+                    ),
+                ),
+            );
+            $this->aInputs[$CNF['FIELD_PHOTO']]['ghost_template'] = $this->_oModule->_oTemplate->parseHtmlByName('form_ghost_template.html', $aVars);
+        }
+        
+        return parent::initChecker($aValues, $aSpecificValues);
+    }
+
+    public function insert ($aValsToAdd = array(), $isIgnore = false) 
+    {
+        $CNF = &$this->_oModule->_oConfig->CNF;
+
+        $aValsToAdd[$CNF['FIELD_AUTHOR']] = bx_get_logged_profile_id ();
+        $aValsToAdd[$CNF['FIELD_ADDED']] = time();
+        $aValsToAdd[$CNF['FIELD_CHANGED']] = time();
+
+        if (CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->isAllowedSetThumb()) {
+            $aThumb = isset($_POST[$CNF['FIELD_THUMB']]) ? bx_process_input ($_POST[$CNF['FIELD_THUMB']], BX_DATA_INT) : false;
+            $aValsToAdd[$CNF['FIELD_THUMB']] = 0;
+            if (!empty($aThumb) && is_array($aThumb) && ($iFileThumb = array_pop($aThumb)))
+                $aValsToAdd[$CNF['FIELD_THUMB']] = $iFileThumb;
+        }
+
+        if ($iContentId = parent::insert ($aValsToAdd, $isIgnore)) 
+            $this->_processFiles ($this->getCleanValue($CNF['FIELD_PHOTO']), $iContentId, true);
+        return $iContentId;
+    }
+
+    function update ($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null) 
+    {
+        $CNF = &$this->_oModule->_oConfig->CNF;
+
+        $aValsToAdd[$CNF['FIELD_CHANGED']] = time();
+
+        if (CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->isAllowedSetThumb()) {
+            $aThumb = bx_process_input ($_POST[$CNF['FIELD_THUMB']], BX_DATA_INT);
+            $aValsToAdd[$CNF['FIELD_THUMB']] = 0;
+            if (!empty($aThumb) && is_array($aThumb) && ($iFileThumb = array_pop($aThumb)))
+                $aValsToAdd[$CNF['FIELD_THUMB']] = $iFileThumb;
+        }
+
+        if ($iRet = parent::update ($iContentId, $aValsToAdd, $aTrackTextFieldsChanges)) 
+            $this->_processFiles ($this->getCleanValue($CNF['FIELD_PHOTO']), $iContentId, false);
+        return $iRet;
+    }
+
+    function delete ($iContentId) 
+    {
+        $CNF = &$this->_oModule->_oConfig->CNF;
+
+        // delete associated files
+
+        bx_import('BxDolStorage');
+        $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
+        if (!$oStorage)
+            return false;
+
+        $aGhostFiles = $oStorage->getGhosts (bx_get_logged_profile_id(), $iContentId);
+        if ($aGhostFiles)
+            foreach ($aGhostFiles as $aFile)
+                $this->_deleteFile($aFile['id']);
+
+        // delete db record
+
+        bx_import('BxDolView');
+		BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $iContentId)->onObjectDelete();
+
+		bx_import('BxDolVote');
+		BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContentId)->onObjectDelete();
+
+		bx_import('BxDolCmts');
+		BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId)->onObjectDelete();
+
+        return parent::delete($iContentId);
+    }
+
+    function _processFiles ($mixedFileIds, $iContentId = 0, $isAssociateWithContent = false) 
+    {
+        $CNF = &$this->_oModule->_oConfig->CNF;
+
+        if (!$mixedFileIds)
+            return true;
+
+        bx_import('BxDolStorage');
+        $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
+        if (!$oStorage)
+            return false;
+
+        $iProfileId = bx_get_logged_profile_id();
+
+        $aGhostFiles = $oStorage->getGhosts ($iProfileId, $isAssociateWithContent ? 0 : $iContentId);
+        if (!$aGhostFiles)
+            return true;
+
+        foreach ($aGhostFiles as $aFile) {
+            if ($aFile['private'])
+                $oStorage->setFilePrivate ($aFile['id'], 0);
+            if ($isAssociateWithContent && $iContentId)
+                $oStorage->updateGhostsContentId ($aFile['id'], $iProfileId, $iContentId);
+        }
+
+        return true;
+    }
+
+    function _deleteFile ($iFileId) 
+    {
+        $CNF = &$this->_oModule->_oConfig->CNF;
+
+        if (!$iFileId)
+            return true;        
+
+        bx_import('BxDolStorage');
+        if (!($oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE'])))
+            return false;
+
+        if (!$oStorage->getFile($iFileId))
+            return true;
+
+        $iProfileId = bx_get_logged_profile_id(); 
+        return $oStorage->deleteFile($iFileId, $iProfileId);
+    }
+
+
+    function addCssJs () 
+    {
+        if (!isset($this->aParams['view_mode']) || !$this->aParams['view_mode']) {
+            if (self::$_isCssJsAdded)
+                return;
+            $this->_oModule->_oTemplate->addJs('forms.js');
+            $this->_oModule->_oTemplate->addCss('forms.css');
+        }
+
+        return parent::addCssJs ();
+    }
+
+
+}
+
+/** @} */

+ 0 - 205
modules/boonex/notes/classes/BxNotesFormNote.php

@@ -1,205 +0,0 @@
-<?php defined('BX_DOL') or die('hack attempt');
-/**
- * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
- * CC-BY License - http://creativecommons.org/licenses/by/3.0/
- *
- * @defgroup    Notes Notes
- * @ingroup     DolphinModules
- *
- * @{
- */
-
-bx_import('BxTemplFormView');
-
-/**
- * Create/Edit Note Form.
- */
-class BxNotesFormNote extends BxTemplFormView {
-
-    protected $_oModule;
-
-    public function __construct($aInfo, $oTemplate = false) {                
-        parent::__construct($aInfo, $oTemplate);
-
-        $this->_oModule = BxDolModule::getInstance('bx_notes');
-
-        if (isset($this->aInputs[BxNotesConfig::$FIELD_TEXT])) {            
-            $this->aInputs[BxNotesConfig::$FIELD_TEXT]['attrs'] = array_merge (
-                array ('id' => BxNotesConfig::$FIELD_TEXT_ID),
-                is_array($this->aInputs[BxNotesConfig::$FIELD_TEXT]['attrs']) ? $this->aInputs[BxNotesConfig::$FIELD_TEXT]['attrs'] : array ()
-            );
-            
-        }
-        if (isset($this->aInputs[BxNotesConfig::$FIELD_SUMMARY])) {
-            $this->aInputs[BxNotesConfig::$FIELD_SUMMARY]['attrs'] = array_merge (
-                array ('id' => BxNotesConfig::$FIELD_SUMMARY_ID),
-                is_array($this->aInputs[BxNotesConfig::$FIELD_SUMMARY]['attrs']) ? $this->aInputs[BxNotesConfig::$FIELD_SUMMARY]['attrs'] : array ()
-            );
-            
-        }
-
-        if (isset($this->aInputs[BxNotesConfig::$FIELD_PHOTO])) {
-            $this->aInputs[BxNotesConfig::$FIELD_PHOTO]['storage_object'] = BxNotesConfig::$OBJECT_STORAGE;
-            $this->aInputs[BxNotesConfig::$FIELD_PHOTO]['uploaders'] = array('sys_simple', 'sys_html5');
-            $this->aInputs[BxNotesConfig::$FIELD_PHOTO]['images_transcoder'] = BxNotesConfig::$OBJECT_IMAGES_TRANSCODER_PREVIEW;
-            $this->aInputs[BxNotesConfig::$FIELD_PHOTO]['multiple'] = true;
-            $this->aInputs[BxNotesConfig::$FIELD_PHOTO]['content_id'] = 0;
-            //$this->aInputs[BxNotesConfig::$FIELD_PHOTO]['upload_buttons_titles'] = _t('_bx_notes_form_note_input_photo_btn_upload');
-            $this->aInputs[BxNotesConfig::$FIELD_PHOTO]['ghost_template'] = '';
-        }
-
-        if (isset($this->aInputs[BxNotesConfig::$FIELD_ALLOW_VIEW_TO])) {
-            bx_import('BxDolPrivacy');
-            $this->aInputs[BxNotesConfig::$FIELD_ALLOW_VIEW_TO] = BxDolPrivacy::getGroupChooser(BxNotesConfig::$OBJECT_PRIVACY_VIEW);
-        }
-    }
-
-    function initChecker ($aValues = array (), $aSpecificValues = array())  {
-
-        if (isset($this->aInputs[BxNotesConfig::$FIELD_PHOTO])) {
-
-            $aContentInfo = false;
-            if ($aValues && !empty($aValues['id'])) {
-                $aContentInfo = $this->_oModule->_oDb->getContentInfoById ($aValues['id']);
-                $this->aInputs[BxNotesConfig::$FIELD_PHOTO]['content_id'] = $aValues['id'];
-            }
-            
-            $aVars = array (
-                'name' => $this->aInputs[BxNotesConfig::$FIELD_PHOTO]['name'],
-                'content_id' => $this->aInputs[BxNotesConfig::$FIELD_PHOTO]['content_id'],
-                'editor_id' => BxNotesConfig::$FIELD_TEXT_ID,
-                'summary_id' => BxNotesConfig::$FIELD_SUMMARY_ID,
-                'thumb_id' => $aContentInfo[BxNotesConfig::$FIELD_THUMB],
-                'bx_if:set_thumb' => array (
-                    'condition' => CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->isAllowedSetThumb(),
-                    'content' => array (
-                        'name_thumb' => BxNotesConfig::$FIELD_THUMB,
-                    ),
-                ),
-            );
-            $this->aInputs[BxNotesConfig::$FIELD_PHOTO]['ghost_template'] = $this->_oModule->_oTemplate->parseHtmlByName('form_ghost_template.html', $aVars);
-        }
-        
-        return parent::initChecker($aValues, $aSpecificValues);
-    }
-
-    public function insert ($aValsToAdd = array(), $isIgnore = false) {
-
-        $aValsToAdd[BxNotesConfig::$FIELD_AUTHOR] = bx_get_logged_profile_id ();
-        $aValsToAdd[BxNotesConfig::$FIELD_ADDED] = time();
-        $aValsToAdd[BxNotesConfig::$FIELD_CHANGED] = time();
-
-        if (CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->isAllowedSetThumb()) {
-            $aThumb = isset($_POST[BxNotesConfig::$FIELD_THUMB]) ? bx_process_input ($_POST[BxNotesConfig::$FIELD_THUMB], BX_DATA_INT) : false;
-            $aValsToAdd[BxNotesConfig::$FIELD_THUMB] = 0;
-            if (!empty($aThumb) && is_array($aThumb) && ($iFileThumb = array_pop($aThumb)))
-                $aValsToAdd[BxNotesConfig::$FIELD_THUMB] = $iFileThumb;
-        }
-
-        if ($iContentId = parent::insert ($aValsToAdd, $isIgnore)) 
-            $this->_processFiles ($this->getCleanValue(BxNotesConfig::$FIELD_PHOTO), $iContentId, true);
-        return $iContentId;
-    }
-
-    function update ($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null) {
-
-        $aValsToAdd[BxNotesConfig::$FIELD_CHANGED] = time();
-
-        if (CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->isAllowedSetThumb()) {
-            $aThumb = bx_process_input ($_POST[BxNotesConfig::$FIELD_THUMB], BX_DATA_INT);
-            $aValsToAdd[BxNotesConfig::$FIELD_THUMB] = 0;
-            if (!empty($aThumb) && is_array($aThumb) && ($iFileThumb = array_pop($aThumb)))
-                $aValsToAdd[BxNotesConfig::$FIELD_THUMB] = $iFileThumb;
-        }
-
-        if ($iRet = parent::update ($iContentId, $aValsToAdd, $aTrackTextFieldsChanges)) 
-            $this->_processFiles ($this->getCleanValue(BxNotesConfig::$FIELD_PHOTO), $iContentId, false);
-        return $iRet;
-    }
-
-    function delete ($iContentId) {
-
-        // delete associated files
-
-        bx_import('BxDolStorage');
-        $oStorage = BxDolStorage::getObjectInstance(BxNotesConfig::$OBJECT_STORAGE);
-        if (!$oStorage)
-            return false;
-
-        $aGhostFiles = $oStorage->getGhosts (bx_get_logged_profile_id(), $iContentId);
-        if ($aGhostFiles)
-            foreach ($aGhostFiles as $aFile)
-                $this->_deleteFile($aFile['id']);
-
-        // delete db record
-
-        bx_import('BxDolView');
-		BxDolView::getObjectInstance(BxNotesConfig::$OBJECT_VIEWS, $iContentId)->onObjectDelete();
-
-		bx_import('BxDolVote');
-		BxDolVote::getObjectInstance(BxNotesConfig::$OBJECT_VOTES, $iContentId)->onObjectDelete();
-
-		bx_import('BxDolCmts');
-		BxDolCmts::getObjectInstance(BxNotesConfig::$OBJECT_COMMENTS, $iContentId)->onObjectDelete();
-
-        return parent::delete($iContentId);
-    }
-
-    function _processFiles ($mixedFileIds, $iContentId = 0, $isAssociateWithContent = false) {
-        if (!$mixedFileIds)
-            return true;
-
-        bx_import('BxDolStorage');
-        $oStorage = BxDolStorage::getObjectInstance(BxNotesConfig::$OBJECT_STORAGE);
-        if (!$oStorage)
-            return false;
-
-        $iProfileId = bx_get_logged_profile_id();
-
-        $aGhostFiles = $oStorage->getGhosts ($iProfileId, $isAssociateWithContent ? 0 : $iContentId);
-        if (!$aGhostFiles)
-            return true;
-
-        foreach ($aGhostFiles as $aFile) {
-            if ($aFile['private'])
-                $oStorage->setFilePrivate ($aFile['id'], 0);
-            if ($isAssociateWithContent && $iContentId)
-                $oStorage->updateGhostsContentId ($aFile['id'], $iProfileId, $iContentId);
-        }
-
-        return true;
-    }
-
-    function _deleteFile ($iFileId) {
-
-        if (!$iFileId)
-            return true;        
-
-        bx_import('BxDolStorage');
-        if (!($oStorage = BxDolStorage::getObjectInstance(BxNotesConfig::$OBJECT_STORAGE)))
-            return false;
-
-        if (!$oStorage->getFile($iFileId))
-            return true;
-
-        $iProfileId = bx_get_logged_profile_id(); 
-        return $oStorage->deleteFile($iFileId, $iProfileId);
-    }
-
-
-    function addCssJs () {
-
-        if (!isset($this->aParams['view_mode']) || !$this->aParams['view_mode']) {
-            if (self::$_isCssJsAdded)
-                return;
-            $this->_oModule->_oTemplate->addJs('forms.js');
-            $this->_oModule->_oTemplate->addCss('forms.css');
-        }
-
-        return parent::addCssJs ();
-    }
-
-
-}
-
-/** @} */

+ 1 - 1
modules/boonex/notes/classes/BxNotesNoteForms.php → modules/boonex/notes/classes/BxNotesFormsEntryHelper.php

@@ -16,7 +16,7 @@ bx_import('BxDolForm');
 /**
  * Note forms functions
  */
-class BxNotesNoteForms extends BxDolProfileForms {
+class BxNotesFormsEntryHelper extends BxDolProfileForms {
 
     protected $_oModule;
 

+ 56 - 0
modules/boonex/notes/classes/BxNotesMenu.php

@@ -0,0 +1,56 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    Notes Notes
+ * @ingroup     DolphinModules
+ *
+ * @{
+ */
+
+bx_import('BxTemplMenu');
+
+/**
+ * General class for module menu.
+ */
+class BxNotesMenu extends BxTemplMenu 
+{
+    protected static $MODULE = 'bx_notes';
+
+    protected $_oModule;
+    protected $_aContentInfo;
+
+    public function __construct($aObject, $oTemplate = false) 
+    {
+        parent::__construct($aObject, $oTemplate);
+
+        bx_import('BxDolModule');
+        $this->_oModule = BxDolModule::getInstance(self::$MODULE);
+    }
+
+    /**
+     * Check if menu items is visible.
+     * @param $a menu item array
+     * @return boolean
+     */ 
+    protected function _isVisible ($a) 
+    {
+        $CNF = $this->_oModule->_oConfig->CNF;
+        $sFuncCheckAccess = false;
+
+        // get custom function name to check menu item visibility
+        if (isset($CNF['MENU_ITEM_TO_METHOD'][$this->_sObject][$a['name']]))
+            $sFuncCheckAccess = $CNF['MENU_ITEM_TO_METHOD'][$this->_sObject][$a['name']];
+
+        // check custom visibility settings defined in module config class
+        if ($sFuncCheckAccess && CHECK_ACTION_RESULT_ALLOWED === call_user_func_array(array($this->_oModule, $sFuncCheckAccess), isset($this->_aContentInfo) ? array(&$this->_aContentInfo) : array()))
+            return true;
+
+        // default visible settings
+        bx_import('BxDolAcl');
+        return BxDolAcl::getInstance()->isMemberLevelInSet($a['visible_for_levels']);
+    }
+}
+
+/** @} */

+ 0 - 51
modules/boonex/notes/classes/BxNotesMenuMy.php

@@ -1,51 +0,0 @@
-<?php defined('BX_DOL') or die('hack attempt');
-/**
- * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
- * CC-BY License - http://creativecommons.org/licenses/by/3.0/
- *
- * @defgroup    Notes Notes
- * @ingroup     DolphinModules
- *
- * @{
- */
-
-bx_import('BxTemplMenu');
-
-/**
- * 'View Note' menu.
- */
-class BxNotesMenuMy extends BxTemplMenu {
-
-    protected $_oModule;
-
-    public function __construct($aObject, $oTemplate = false) {
-        parent::__construct($aObject, $oTemplate);
-
-        bx_import('BxDolModule');
-        $this->_oModule = BxDolModule::getInstance('bx_notes');
-    }
-
-    /**
-     * Check if menu items is visible.
-     * @param $a menu item array
-     * @return boolean
-     */ 
-    protected function _isVisible ($a) {
-
-        $sFuncCheckAccess = false;
-        switch ($a['name']) {
-            case 'create-note':
-                $sFuncCheckAccess = 'isAllowedAdd';
-                break;
-        }
-
-        if ($sFuncCheckAccess && CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->$sFuncCheckAccess())
-            return true;
-
-        // default visible settings
-        bx_import('BxDolAcl');
-        return BxDolAcl::getInstance()->isMemberLevelInSet($a['visible_for_levels']);
-    }
-}
-
-/** @} */

+ 6 - 49
modules/boonex/notes/classes/BxNotesMenuView.php

@@ -10,66 +10,23 @@
  */
 
 bx_import('BxTemplMenu');
+bx_import('Menu', 'bx_notes');
 
 /**
- * 'View Note' menu.
+ * 'View Entry' menu.
  */
-class BxNotesMenuView extends BxTemplMenu {
-
-    protected $_aContentInfo;
-    protected $_oModule;
-
-    public function __construct($aObject, $oTemplate = false) {
+class BxNotesMenuView extends BxNotesMenu
+{
+    public function __construct($aObject, $oTemplate = false) 
+    {
         parent::__construct($aObject, $oTemplate);
 
         $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
 
-        bx_import('BxDolModule');
-        $this->_oModule = BxDolModule::getInstance('bx_notes');
         $this->_aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
         if ($this->_aContentInfo)
             $this->addMarkers(array('content_id' => $this->_aContentInfo['id']));
     }
-
-    /**
-     * Check if menu items is visible.
-     * @param $a menu item array
-     * @return boolean
-     */ 
-    protected function _isVisible ($a) {
-
-        $iProfileId = bx_get_logged_profile_id();
-
-        // don't show current item, also this will solve problem when only one view note item is visible
-        if ('bx_notes_view' == $this->_sObject && $this->_isSelected($a))
-            return false;
-
-        $sFuncCheckAccess = false;
-        switch ($a['name']) {
-            case 'view-note':
-                $sFuncCheckAccess = 'isAllowedView';
-                break;
-            case 'edit-note':
-                $sFuncCheckAccess = 'isAllowedEdit';
-                break;
-            case 'delete-note':
-                $sFuncCheckAccess = 'isAllowedDelete';
-                break;
-        }
-
-        if ($sFuncCheckAccess && CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->$sFuncCheckAccess($this->_aContentInfo))
-            return true;
-
-        // default visible settings
-        bx_import('BxDolAcl');
-        return BxDolAcl::getInstance()->isMemberLevelInSet($a['visible_for_levels']);
-    }
-
-    protected function _addJsCss() {
-        parent::_addJsCss();
-        $this->_oModule->_oTemplate->addJs('forms.js');
-    }
-
 }
 
 /** @} */

+ 10 - 10
modules/boonex/notes/classes/BxNotesModule.php

@@ -60,8 +60,8 @@ class BxNotesModule extends BxDolModule {
     }
 
     public function serviceEntityCreate () {
-        bx_import('NoteForms', $this->_aModule);
-        $oProfileForms = new BxNotesNoteForms($this);
+        bx_import('FormsEntryHelper', $this->_aModule);
+        $oProfileForms = new BxNotesFormsEntryHelper($this);
         return $oProfileForms->addDataForm();
     }
 
@@ -73,8 +73,8 @@ class BxNotesModule extends BxDolModule {
             $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
         if (!$iContentId)
             return false;
-        bx_import('NoteForms', $this->_aModule);
-        $oProfileForms = new BxNotesNoteForms($this);
+        bx_import('FormsEntryHelper', $this->_aModule);
+        $oProfileForms = new BxNotesFormsEntryHelper($this);
         return $oProfileForms->editDataForm((int)$iContentId);
     }
 
@@ -86,8 +86,8 @@ class BxNotesModule extends BxDolModule {
             $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
         if (!$iContentId)
             return false;
-        bx_import('NoteForms', $this->_aModule);
-        $oProfileForms = new BxNotesNoteForms($this);
+        bx_import('FormsEntryHelper', $this->_aModule);
+        $oProfileForms = new BxNotesFormsEntryHelper($this);
         return $oProfileForms->deleteDataForm((int)$iContentId);
     }
 
@@ -100,8 +100,8 @@ class BxNotesModule extends BxDolModule {
         if (!$iContentId)
             return false;
 
-        bx_import('NoteForms', $this->_aModule);
-        $oProfileForms = new BxNotesNoteForms($this);
+        bx_import('FormsEntryHelper', $this->_aModule);
+        $oProfileForms = new BxNotesFormsEntryHelper($this);
         return $oProfileForms->viewDataEntry((int)$iContentId);
     }
 
@@ -110,8 +110,8 @@ class BxNotesModule extends BxDolModule {
             $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
         if (!$iContentId)
             return false;
-        bx_import('NoteForms', $this->_aModule);
-        $oProfileForms = new BxNotesNoteForms($this);
+        bx_import('FormsEntryHelper', $this->_aModule);
+        $oProfileForms = new BxNotesFormsEntryHelper($this);
         return $oProfileForms->viewDataForm((int)$iContentId);
     }
 

+ 1 - 2
modules/boonex/notes/install/sql/enable.sql

@@ -132,7 +132,6 @@ INSERT INTO `sys_menu_sets`(`set_name`, `module`, `title`, `deletable`) VALUES
 ('bx_notes_view', 'bx_notes', '_bx_notes_menu_set_title_view_note', 0);
 
 INSERT INTO `sys_menu_items`(`set_name`, `module`, `name`, `title_system`, `title`, `link`, `onclick`, `target`, `icon`, `submenu_object`, `visible_for_levels`, `active`, `copyable`, `order`) VALUES 
-('bx_notes_view', 'bx_notes', 'view-note', '_bx_notes_menu_item_title_system_view_note', '_bx_notes_menu_item_title_view_note', 'page.php?i=view-note&id={content_id}', '', '', 'eye', '', 0, 1, 0, 0),
 ('bx_notes_view', 'bx_notes', 'edit-note', '_bx_notes_menu_item_title_system_edit_note', '_bx_notes_menu_item_title_edit_note', 'page.php?i=edit-note&id={content_id}', '', '', 'pencil', '', 0, 1, 0, 1),
 ('bx_notes_view', 'bx_notes', 'delete-note', '_bx_notes_menu_item_title_system_delete_note', '_bx_notes_menu_item_title_delete_note', 'page.php?i=delete-note&id={content_id}', '', '', 'remove', '', 0, 1, 0, 2);
 
@@ -140,7 +139,7 @@ INSERT INTO `sys_menu_items`(`set_name`, `module`, `name`, `title_system`, `titl
 -- Dumping data for 'bx_notes_my' menu
 --
 INSERT INTO `sys_objects_menu`(`object`, `title`, `set_name`, `module`, `template_id`, `deletable`, `active`, `override_class_name`, `override_class_file`) VALUES 
-('bx_notes_my', '_bx_notes_menu_title_notes_my', 'bx_notes_my', 'bx_notes', 9, 0, 1, 'BxNotesMenuMy', 'modules/boonex/notes/classes/BxNotesMenuMy.php');
+('bx_notes_my', '_bx_notes_menu_title_notes_my', 'bx_notes_my', 'bx_notes', 9, 0, 1, 'BxNotesMenu', 'modules/boonex/notes/classes/BxNotesMenu.php');
 
 INSERT INTO `sys_menu_sets`(`set_name`, `module`, `title`, `deletable`) VALUES 
 ('bx_notes_my', 'bx_notes', '_bx_notes_menu_set_title_notes_my', 0);

+ 1 - 1
modules/boonex/notes/install/sql/install.sql

@@ -98,7 +98,7 @@ CREATE TABLE `bx_notes_views_track` (
 
 -- FORMS
 INSERT INTO `sys_objects_form`(`object`, `module`, `title`, `action`, `form_attrs`, `table`, `key`, `uri`, `uri_title`, `submit_name`, `params`, `deletable`, `active`, `override_class_name`, `override_class_file`) VALUES 
-('bx_notes', 'bx_notes', '_bx_notes_form_note', '', 'a:1:{s:7:\"enctype\";s:19:\"multipart/form-data\";}', 'bx_notes_posts', 'id', '', '', 'do_submit', '', 0, 1, 'BxNotesFormNote', 'modules/boonex/notes/classes/BxNotesFormNote.php');
+('bx_notes', 'bx_notes', '_bx_notes_form_note', '', 'a:1:{s:7:\"enctype\";s:19:\"multipart/form-data\";}', 'bx_notes_posts', 'id', '', '', 'do_submit', '', 0, 1, 'BxNotesFormEntry', 'modules/boonex/notes/classes/BxNotesFormEntry.php');
 
 INSERT INTO `sys_form_displays`(`object`, `display_name`, `module`, `view_mode`, `title`) VALUES 
 ('bx_notes', 'bx_notes_note_add', 'bx_notes', 0, '_bx_notes_form_note_display_add'),