Prechádzať zdrojové kódy

#8 - special undefined/unknown profile class

Alex Trofimov 13 rokov pred
rodič
commit
52fa515aa4

+ 1 - 1
inc/classes/BxDolAccount.php

@@ -157,7 +157,7 @@ class BxDolAccount extends BxDol {
      * Get account url
      */
     public function getUrl($iAccountId = false) {
-        return '';
+        return 'javascript:void(0);';
     }
 
     /**

+ 93 - 0
inc/classes/BxDolProfileUndefined.php

@@ -0,0 +1,93 @@
+<?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    DolphinCore Dolphin Core
+ * @{
+ */
+
+
+/**
+ * When profile is not available (for example profile is deleted) then use this special class.
+ *
+ * @section example Example of usage
+ *
+ * @code 
+ * bx_import('BxDolProfile');
+ * $oProfile = BxDolProfile::getInstance($iId);
+ * if (!$oProfile) {
+ *     bx_import('BxDolProfileUndefined');
+ *     $oProfile = BxDolProfileUndefined::getInstance();
+ * }
+ * @endcode
+ */
+class BxDolProfileUndefined extends BxDol {
+
+    /**
+     * Constructor
+     */
+    protected function __construct () {
+        parent::__construct();
+    }
+
+    /**
+     * Prevent cloning the instance
+     */
+    public function __clone() {
+        $sClass = get_class($this);
+        if (isset($GLOBALS['bxDolClasses'][$sClass]))
+            trigger_error('Clone is not allowed for the class: ' . get_class($this), E_USER_ERROR);
+    }
+
+    /**
+     * Get singleton instance of the class
+     */
+    public static function getInstance() {
+
+        $sClass = __CLASS__;
+        if(!isset($GLOBALS['bxDolClasses'][$sClass]))
+            $GLOBALS['bxDolClasses'][$sClass] = new $sClass();
+
+        return $GLOBALS['bxDolClasses'][$sClass];
+    }
+
+    /**
+     * Get profile id
+     */
+    public function id() {
+        return 0;
+    }
+
+    /**
+     * Get profile display name
+     */
+    public function getDisplayName() {
+        return _t('_uknown');
+    }
+
+    /**
+     * Get profile url
+     */
+    public function getUrl() {
+        return 'javascript:void(0);';
+    }
+
+    /**
+     * Get profile unit
+     */
+    public function getUnit() {
+        return '<div>' . $this->getDisplayName() . '</div>';
+    }
+
+    /**
+     * Get profile thumb
+     */
+    public function getThumb() {
+        return '';
+    }
+
+}
+
+/** @} */
+

+ 4 - 0
modules/boonex/notes/classes/BxNotesTemplate.php

@@ -41,6 +41,10 @@ class BxNotesTemplate extends BxDolTwigTemplate {
 
         bx_import('BxDolProfile');
         $oProfile = BxDolProfile::getInstance($aData['author']);
+        if (!$oProfile) {
+            bx_import('BxDolProfileUndefined');
+            $oProfile = BxDolProfileUndefined::getInstance();
+        }
 
         $sSummary = $aData['summary'];
         if (!$sSummary) {