Jelajahi Sumber

#4625 opencv integration (user options)

Alex Trofimov 2 tahun lalu
induk
melakukan
5c6c20ebe6

+ 10 - 2
modules/boonex/opencv/classes/BxOpencvAlerts.php

@@ -23,8 +23,16 @@ class BxOpencvAlerts extends BxDolAlertsResponse
             $sStorages = getParam('bx_opencv_option_storages');
             $aStorages = explode(',', $sStorages);
             if (in_array($o->aExtras['storage_object'], $aStorages)) {
-                $oModule = BxDolModule::getInstance('bx_opencv');
-                $oModule->serviceProcessImage($o->iSender, $o->aExtras['file_path'], isset($o->aExtras['ext']) ? $o->aExtras['ext'] : 'jpg');
+
+                $oProfile = BxDolProfile::getInstance($o->iSender);
+                if ($oProfile) {
+                    $aInfo = bx_srv($oProfile->getModule(), 'get_content_info_by_profile_id', [$o->iSender]);
+                    echoDbgLog($aInfo);
+                    if (isset($aInfo['obfuscate_faces']) && $aInfo['obfuscate_faces']) {
+                        $oModule = BxDolModule::getInstance('bx_opencv');
+                        $oModule->serviceProcessImage($o->aExtras['file_path'], isset($o->aExtras['ext']) ? $o->aExtras['ext'] : 'jpg');
+                    }
+                }
             }
         }
     }    

+ 1 - 1
modules/boonex/opencv/classes/BxOpencvModule.php

@@ -28,7 +28,7 @@ class BxOpencvModule extends BxDolModule
         return $a;
     }
 
-    public function serviceProcessImage($iProfileId, $sFilePath, $sExt = 'jpg')
+    public function serviceProcessImage($sFilePath, $sExt = 'jpg')
     {
         $src = imread($sFilePath);
         $blr = null;

+ 24 - 0
modules/boonex/opencv/install/installer.php

@@ -15,6 +15,30 @@ class BxOpencvInstaller extends BxDolStudioInstaller
     {
         parent::__construct($aConfig);
     }
+
+    public function install($aParams, $bAutoEnable = false)
+    {
+        $aResult = parent::install($aParams, $bAutoEnable);
+        if ($aResult['result']) {
+            if ($this->oDb->isTableExists('bx_persons_data') && !$this->oDb->isFieldExists('bx_persons_data', 'obfuscate_faces'))
+                $this->oDb->query("ALTER TABLE `bx_persons_data` ADD `obfuscate_faces` TINYINT NOT NULL DEFAULT '0'");
+            if ($this->oDb->isTableExists('bx_organizations_data') && !$this->oDb->isFieldExists('bx_organizations_data', 'obfuscate_faces'))
+                $this->oDb->query("ALTER TABLE `bx_organizations_data` ADD `obfuscate_faces` TINYINT NOT NULL DEFAULT '0'");
+        }
+        return $aResult;
+    }
+
+    public function uninstall($aParams, $bAutoDisable = false)
+    {
+        $aResult = parent::uninstall($aParams, $bAutoDisable);
+        if ($aResult['result']) {
+            if ($this->oDb->isTableExists('bx_persons_data') && $this->oDb->isFieldExists('bx_persons_data', 'obfuscate_faces'))
+                $this->oDb->query("ALTER TABLE `bx_persons_data` DROP `obfuscate_faces`");
+            if ($this->oDb->isTableExists('bx_organizations_data') && $this->oDb->isFieldExists('bx_organizations_data', 'obfuscate_faces'))
+                $this->oDb->query("ALTER TABLE `bx_organizations_data` DROP `obfuscate_faces`");
+        }
+        return $aResult;
+    }
 }
 
 /** @} */

+ 2 - 1
modules/boonex/opencv/install/langs/en.xml

@@ -12,6 +12,7 @@
 	<string name="_bx_opencv_information"><![CDATA[Information]]></string>
     <string name="_bx_opencv_information_block"><![CDATA[
                 <p>This module obfuscate people faces in users' photos.<p>
-                <p>PHP need to have OpenCV library installed.</p>
+                <p>PHP need to have <a target="_blank" href="https://github.com/php-opencv/php-opencv/wiki/Installation.-php-opencv">OpenCV library</a> <a target="_blank" href="https://github.com/php-opencv/php-opencv/wiki/Installation.-opencv">installed</a>.</p>
         ]]></string>
+	<string name="_bx_opencv_form_profile_input_obfuscate_faces"><![CDATA[Obfuscate faces]]></string>
 </resources>

+ 1 - 0
modules/boonex/opencv/install/sql/disable.sql

@@ -9,3 +9,4 @@ SET @iHandlerId := (SELECT `id` FROM `sys_alerts_handlers` WHERE `name` = 'bx_op
 
 DELETE FROM `sys_alerts_handlers` WHERE `id`  = @iHandlerId;
 DELETE FROM `sys_alerts` WHERE `handler_id` =  @iHandlerId ;
+

+ 8 - 0
modules/boonex/opencv/install/sql/install.sql

@@ -1,4 +1,12 @@
 
+-- Forms 
+
+INSERT INTO `sys_form_inputs`(`object`, `module`, `name`, `value`, `values`, `checked`, `type`, `caption_system`, `caption`, `info`, `required`, `collapsed`, `html`, `attrs`, `attrs_tr`, `attrs_wrapper`, `checker_func`, `checker_params`, `checker_error`, `db_pass`, `db_params`, `editable`, `deletable`, `rateable`) VALUES 
+('bx_person', 'bx_opencv', 'obfuscate_faces', '1', '', 0, 'switcher', '', '_bx_opencv_form_profile_input_obfuscate_faces', '', 0, 0, 0, '', '', '', '', '', '', 'Xss', '', 1, 0, '');
+
+INSERT INTO `sys_form_inputs`(`object`, `module`, `name`, `value`, `values`, `checked`, `type`, `caption_system`, `caption`, `info`, `required`, `collapsed`, `html`, `attrs`, `attrs_tr`, `attrs_wrapper`, `checker_func`, `checker_params`, `checker_error`, `db_pass`, `db_params`, `editable`, `deletable`) VALUES 
+('bx_organization', 'bx_opencv', 'obfuscate_faces', '1', '', 0, 'switcher', '', '_bx_opencv_form_profile_input_obfuscate_faces', '', 0, 0, 0, '', '', '', '', '', '', 'Xss', '', 1, 0);
+
 -- Studio page and widget
 
 INSERT INTO `sys_std_pages`(`index`, `name`, `header`, `caption`, `icon`) VALUES

+ 5 - 0
modules/boonex/opencv/install/sql/uninstall.sql

@@ -1,5 +1,10 @@
 
+-- Forms 
+
+DELETE FROM `sys_form_inputs` WHERE `module` = 'bx_opencv';
+
 -- Studio page and widget
+
 DELETE FROM `tp`, `tw`, `twb`, `tpw` 
 USING `sys_std_pages` AS `tp` LEFT JOIN `sys_std_widgets` AS `tw` ON `tp`.`id` = `tw`.`page_id` LEFT JOIN `sys_std_widgets_bookmarks` AS `twb` ON `tw`.`id` = `twb`.`widget_id` LEFT JOIN `sys_std_pages_widgets` AS `tpw` ON `tw`.`id` = `tpw`.`widget_id`
 WHERE  `tp`.`name` = 'bx_opencv';