From: <wis...@us...> - 2017-08-30 23:20:56
|
Revision: 13290 http://sourceforge.net/p/xoops/svn/13290 Author: wishcraft Date: 2017-08-30 23:20:53 +0000 (Wed, 30 Aug 2017) Log Message: ----------- Images module for releases.xoops.org -- still alpha1! Modified Paths: -------------- XoopsModules/images/trunk/modules/images/class/fields.php XoopsModules/images/trunk/modules/images/class/images.php XoopsModules/images/trunk/modules/images/image.php Added Paths: ----------- XoopsModules/images/trunk/modules/images/crons/refresh-images.php XoopsModules/images/trunk/modules/images/crons/refresh-users-avatar.php XoopsModules/images/trunk/modules/images/crons/refresh-users-icons.php XoopsModules/images/trunk/modules/images/crons/refresh-users-logo.php XoopsModules/images/trunk/modules/images/crons/refresh-users-photo.php Modified: XoopsModules/images/trunk/modules/images/class/fields.php =================================================================== --- XoopsModules/images/trunk/modules/images/class/fields.php 2017-08-30 22:08:50 UTC (rev 13289) +++ XoopsModules/images/trunk/modules/images/class/fields.php 2017-08-30 23:20:53 UTC (rev 13290) @@ -135,5 +135,62 @@ return false; } + /** + * get an Array of a field + * + * @param string $field + * @param string $return + * @return string[] + */ + function getFieldArray($field = '', $return = 'url') + { + $result = array(''); + $sql = "SELECT DISTINCT `$return` FROM `" . $GLOBALS['xoopsDB']->prefix('images_images') . "` WHERE `field` = '$field'"; + if ($query = $GLOBALS['xoopsDB']->queryF($sql)) + { + $value = 'https://'; + while(count($result)<$GLOBALS['xoopsDB']->getRowsNum($query)) + { + list($value) = $GLOBALS['xoopsDB']->fetchRow($query); + $result[] = $value; + } + if ($return == 'url') + { + $result[] = 'http://'; + $result[] = 'https://'; + $result[] = ''; + } + array_unique($result); + sort($result, SORT_ASC); + } + return $result; + } + + /** + * adds to the images count + * + * @param string $field + * @param string $typal + * @param number $number + */ + function addImages($field = '', $typal = '', $number = 1) + { + $sql = "UPDATE `" . $GLOBALS['xoopsDB']->prefix("images_fields") . "` SET `images` = `images` + '$number' WHERE `field` = '" . $field . "' AND `typal` = '" . $typal . "'"; + @$GLOBALS['xoopsDB']->queryF($sql); + } + + + /** + * adds to the error count + * + * @param string $field + * @param string $typal + * @param number $number + */ + function addErrors($field = '', $typal = '', $number = 1) + { + $sql = "UPDATE `" . $GLOBALS['xoopsDB']->prefix("images_fields") . "` SET `errors` = `errors` + '$number', `errored` = UNIX_TIMESTAMP() WHERE `field` = '" . $field . "' AND `typal` = '" . $typal . "'"; + @$GLOBALS['xoopsDB']->queryF($sql); + } } ?> \ No newline at end of file Modified: XoopsModules/images/trunk/modules/images/class/images.php =================================================================== --- XoopsModules/images/trunk/modules/images/class/images.php 2017-08-30 22:08:50 UTC (rev 13289) +++ XoopsModules/images/trunk/modules/images/class/images.php 2017-08-30 23:20:53 UTC (rev 13290) @@ -710,13 +710,25 @@ { if (strlen($object->getVar('field'))==0 || strlen($object->getVar('url'))== 0) return false; + + $fieldsHandler = xoops_getModuleHandler('fields', basename(__DIR__)); + $field = $fieldsHandler->create(); + $field->setVar('field', $object->getVar('field')); + $field->setVar('typal', $object->getFieldTypal()); + if (!$field = $fieldsHandler->get($fieldsHandler->insert($field, true))) + return false; + if ($object->getVar('uid')==0 && is_object($GLOBALS['xoopsUser'])) $object->setVar('uid', $GLOBALS['xoopsUser']->getVar('uid')); $object->setVar('created', time()); - $object->setVar('type', $imagesConfigList['format']); + if (strlen($object->getVar('type')) == 0 || $object->getVar('type') == 'unknown') + $object->setVar('type', $imagesConfigList['format']); $object->setVar('storage', $imagesConfigList['storage']); - $crc = new xcp($data = $object->getVar('uid').$imagesConfigList['format'].microtime().$object->getVar('url'), mt_rand(0,255), mt_rand(5,14)); - $object->setVar('hash', $crc->crc); + if (strlen($object->getVar('hash')) == 0) + { + $crc = new xcp($data = $field->getVar('hash').$object->getVar('uid').$imagesConfigList['format'].microtime().$object->getVar('url'), mt_rand(0,255), mt_rand(5,14)); + $object->setVar('hash', $crc->crc); + } $criteria = new CriteriaCompo(new Criteria('uid', $object->getVar('uid'))); $criteria->add(new Criteria('field', $object->getVar('field'))); if (!in_array($object->getVar('field'), $imagesConfigList['ascii_fields'])) @@ -756,6 +768,7 @@ unset($asciiobjs); } } + $fieldsHandler->addImages($object->getVar('field'), $object->getFieldTypal()); } $object->setVar('updated', time()); return parent::insert($object, true); Added: XoopsModules/images/trunk/modules/images/crons/refresh-images.php =================================================================== --- XoopsModules/images/trunk/modules/images/crons/refresh-images.php (rev 0) +++ XoopsModules/images/trunk/modules/images/crons/refresh-images.php 2017-08-30 23:20:53 UTC (rev 13290) @@ -0,0 +1,33 @@ +<?php +/** + * XOOPS Remote Images URL Cache and Management in Profile Module + * + * You may not change or alter any portion of this comment or credits + * of supporting developers from this source code or any supporting source code + * which is considered copyrighted (c) material of the original comment or credit authors. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ + * @license General Public License version 3 + * @author Simon Roberts <wis...@us...> + * @subpackage images + * @description Module for importing image URL listed in profile module + * @version 1.0.1 + * @link https://sourceforge.net/projects/chronolabs/files/XOOPS%202.5/Modules/images + * @link https://sourceforge.net/projects/chronolabs/files/XOOPS%202.6/Modules/images + * @link https://sourceforge.net/p/xoops/svn/HEAD/tree/XoopsModules/images + * @link http://internetfounder.wordpress.com + */ + +global $imagesConfigList; + +include_once dirname(__DIR__) . "/header.php"; + +$imagesHandler = xoops_getModuleHandler('images', basename(dirname(__DIR__))); +$criteria = new Criteria('checked', time(), "<="); +foreach($imagesHandler->getObjects($criteria) as $image) + $image->check(); + +?> \ No newline at end of file Property changes on: XoopsModules/images/trunk/modules/images/crons/refresh-images.php ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Added: XoopsModules/images/trunk/modules/images/crons/refresh-users-avatar.php =================================================================== --- XoopsModules/images/trunk/modules/images/crons/refresh-users-avatar.php (rev 0) +++ XoopsModules/images/trunk/modules/images/crons/refresh-users-avatar.php 2017-08-30 23:20:53 UTC (rev 13290) @@ -0,0 +1,57 @@ +<?php +/** + * XOOPS Remote Images URL Cache and Management in Profile Module + * + * You may not change or alter any portion of this comment or credits + * of supporting developers from this source code or any supporting source code + * which is considered copyrighted (c) material of the original comment or credit authors. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ + * @license General Public License version 3 + * @author Simon Roberts <wis...@us...> + * @subpackage images + * @description Module for importing image URL listed in profile module + * @version 1.0.1 + * @link https://sourceforge.net/projects/chronolabs/files/XOOPS%202.5/Modules/images + * @link https://sourceforge.net/projects/chronolabs/files/XOOPS%202.6/Modules/images + * @link https://sourceforge.net/p/xoops/svn/HEAD/tree/XoopsModules/images + * @link http://internetfounder.wordpress.com + */ + +global $imagesConfigList; + +include_once dirname(__DIR__) . "/header.php"; + +$userHandler = xoops_getHandler('users'); +$imagesHandler = xoops_getModuleHandler('images', basename(dirname(__DIR__))); +$profileHandler = xoops_getModuleHandler('profile', 'profile'); + +foreach($imageConfigList['avatar_fields'] as $field) +{ + $criteria = new CriteriaCompo(new Criteria($field, "('" . implode("', '", $imagesHandler->getFieldArray($field, 'url')) . "')", "NOT IN")); + foreach($profileHandler->getObjects($criteria) as $profile) + { + $populate = false; + if ($user = $userHandler->get($profile->getVar('profile_id'))) + { + foreach($user->getGroups() as $groupid) + if (in_array($groupid, $imageConfigList['populate_groups'])) + { + $populate = true; + continue; + } + } + if ($populate == true) + { + $image = $imagesHandler->create(); + $image->setVar('uid', $profile->getVar('profile_id')); + $image->setVar('field', $field); + $image->setVar('url', $profile->getVar($field)); + $imagesHandler->insert($image, true); + } + } +} +?> \ No newline at end of file Property changes on: XoopsModules/images/trunk/modules/images/crons/refresh-users-avatar.php ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Added: XoopsModules/images/trunk/modules/images/crons/refresh-users-icons.php =================================================================== --- XoopsModules/images/trunk/modules/images/crons/refresh-users-icons.php (rev 0) +++ XoopsModules/images/trunk/modules/images/crons/refresh-users-icons.php 2017-08-30 23:20:53 UTC (rev 13290) @@ -0,0 +1,58 @@ +<?php +/** + * XOOPS Remote Images URL Cache and Management in Profile Module + * + * You may not change or alter any portion of this comment or credits + * of supporting developers from this source code or any supporting source code + * which is considered copyrighted (c) material of the original comment or credit authors. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ + * @license General Public License version 3 + * @author Simon Roberts <wis...@us...> + * @subpackage images + * @description Module for importing image URL listed in profile module + * @version 1.0.1 + * @link https://sourceforge.net/projects/chronolabs/files/XOOPS%202.5/Modules/images + * @link https://sourceforge.net/projects/chronolabs/files/XOOPS%202.6/Modules/images + * @link https://sourceforge.net/p/xoops/svn/HEAD/tree/XoopsModules/images + * @link http://internetfounder.wordpress.com + */ + +global $imagesConfigList; + +include_once dirname(__DIR__) . "/header.php"; + +$userHandler = xoops_getHandler('users'); +$imagesHandler = xoops_getModuleHandler('images', basename(dirname(__DIR__))); +$profileHandler = xoops_getModuleHandler('profile', 'profile'); + +foreach($imageConfigList['icons_fields'] as $field) +{ + $criteria = new CriteriaCompo(new Criteria($field, "('" . implode("', '", $imagesHandler->getFieldArray($field, 'url')) . "')", "NOT IN")); + foreach($profileHandler->getObjects($criteria) as $profile) + { + $populate = false; + if ($user = $userHandler->get($profile->getVar('profile_id'))) + { + foreach($user->getGroups() as $groupid) + if (in_array($groupid, $imageConfigList['populate_groups'])) + { + $populate = true; + continue; + } + } + if ($populate == true) + { + $image = $imagesHandler->create(); + $image->setVar('uid', $profile->getVar('profile_id')); + $image->setVar('field', $field); + $image->setVar('url', $profile->getVar($field)); + $imagesHandler->insert($image, true); + } + } + +} +?> \ No newline at end of file Property changes on: XoopsModules/images/trunk/modules/images/crons/refresh-users-icons.php ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Added: XoopsModules/images/trunk/modules/images/crons/refresh-users-logo.php =================================================================== --- XoopsModules/images/trunk/modules/images/crons/refresh-users-logo.php (rev 0) +++ XoopsModules/images/trunk/modules/images/crons/refresh-users-logo.php 2017-08-30 23:20:53 UTC (rev 13290) @@ -0,0 +1,58 @@ +<?php +/** + * XOOPS Remote Images URL Cache and Management in Profile Module + * + * You may not change or alter any portion of this comment or credits + * of supporting developers from this source code or any supporting source code + * which is considered copyrighted (c) material of the original comment or credit authors. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ + * @license General Public License version 3 + * @author Simon Roberts <wis...@us...> + * @subpackage images + * @description Module for importing image URL listed in profile module + * @version 1.0.1 + * @link https://sourceforge.net/projects/chronolabs/files/XOOPS%202.5/Modules/images + * @link https://sourceforge.net/projects/chronolabs/files/XOOPS%202.6/Modules/images + * @link https://sourceforge.net/p/xoops/svn/HEAD/tree/XoopsModules/images + * @link http://internetfounder.wordpress.com + */ + +global $imagesConfigList; + +include_once dirname(__DIR__) . "/header.php"; + +$userHandler = xoops_getHandler('users'); +$imagesHandler = xoops_getModuleHandler('images', basename(dirname(__DIR__))); +$profileHandler = xoops_getModuleHandler('profile', 'profile'); + +foreach($imageConfigList['logo_fields'] as $field) +{ + $criteria = new CriteriaCompo(new Criteria($field, "('" . implode("', '", $imagesHandler->getFieldArray($field, 'url')) . "')", "NOT IN")); + foreach($profileHandler->getObjects($criteria) as $profile) + { + $populate = false; + if ($user = $userHandler->get($profile->getVar('profile_id'))) + { + foreach($user->getGroups() as $groupid) + if (in_array($groupid, $imageConfigList['populate_groups'])) + { + $populate = true; + continue; + } + } + if ($populate == true) + { + $image = $imagesHandler->create(); + $image->setVar('uid', $profile->getVar('profile_id')); + $image->setVar('field', $field); + $image->setVar('url', $profile->getVar($field)); + $imagesHandler->insert($image, true); + } + } + +} +?> \ No newline at end of file Property changes on: XoopsModules/images/trunk/modules/images/crons/refresh-users-logo.php ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Added: XoopsModules/images/trunk/modules/images/crons/refresh-users-photo.php =================================================================== --- XoopsModules/images/trunk/modules/images/crons/refresh-users-photo.php (rev 0) +++ XoopsModules/images/trunk/modules/images/crons/refresh-users-photo.php 2017-08-30 23:20:53 UTC (rev 13290) @@ -0,0 +1,58 @@ +<?php +/** + * XOOPS Remote Images URL Cache and Management in Profile Module + * + * You may not change or alter any portion of this comment or credits + * of supporting developers from this source code or any supporting source code + * which is considered copyrighted (c) material of the original comment or credit authors. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ + * @license General Public License version 3 + * @author Simon Roberts <wis...@us...> + * @subpackage images + * @description Module for importing image URL listed in profile module + * @version 1.0.1 + * @link https://sourceforge.net/projects/chronolabs/files/XOOPS%202.5/Modules/images + * @link https://sourceforge.net/projects/chronolabs/files/XOOPS%202.6/Modules/images + * @link https://sourceforge.net/p/xoops/svn/HEAD/tree/XoopsModules/images + * @link http://internetfounder.wordpress.com + */ + +global $imagesConfigList; + +include_once dirname(__DIR__) . "/header.php"; + +$userHandler = xoops_getHandler('users'); +$imagesHandler = xoops_getModuleHandler('images', basename(dirname(__DIR__))); +$profileHandler = xoops_getModuleHandler('profile', 'profile'); + +foreach($imageConfigList['photo_fields'] as $field) +{ + $criteria = new CriteriaCompo(new Criteria($field, "('" . implode("', '", $imagesHandler->getFieldArray($field, 'url')) . "')", "NOT IN")); + foreach($profileHandler->getObjects($criteria) as $profile) + { + $populate = false; + if ($user = $userHandler->get($profile->getVar('profile_id'))) + { + foreach($user->getGroups() as $groupid) + if (in_array($groupid, $imageConfigList['populate_groups'])) + { + $populate = true; + continue; + } + } + if ($populate == true) + { + $image = $imagesHandler->create(); + $image->setVar('uid', $profile->getVar('profile_id')); + $image->setVar('field', $field); + $image->setVar('url', $profile->getVar($field)); + $imagesHandler->insert($image, true); + } + } + +} +?> \ No newline at end of file Property changes on: XoopsModules/images/trunk/modules/images/crons/refresh-users-photo.php ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Modified: XoopsModules/images/trunk/modules/images/image.php =================================================================== --- XoopsModules/images/trunk/modules/images/image.php 2017-08-30 22:08:50 UTC (rev 13289) +++ XoopsModules/images/trunk/modules/images/image.php 2017-08-30 23:20:53 UTC (rev 13290) @@ -21,6 +21,7 @@ * @link http://internetfounder.wordpress.com */ +global $imagesConfigList; include_once __DIR__ . "/header.php"; @@ -36,14 +37,16 @@ { if ($image = $imagesHandler->getByHash($_REQUEST['hash'], $field->getVar('field'))) { - if (isset($_REQUEST['width']) && !empty($_REQUEST['width'])) - $width = $_REQUEST['width']; - if (isset($_REQUEST['height']) && !empty($_REQUEST['height'])) - $height = $_REQUEST['height']; + if (isset($_REQUEST['width']) && !empty($_REQUEST['width']) && ((integer)$_REQUEST['width'] > $image->getMinimumWidth() && (integer)$_REQUEST['width'] < $image->getMaximumWidth())) + $width = (integer)$_REQUEST['width']; else - $height = $width; + $width = $image->getWidth(); + if (isset($_REQUEST['height']) && !empty($_REQUEST['height']) && ((integer)$_REQUEST['height'] > $image->getMinimumHeight() && (integer)$_REQUEST['height'] < $image->getMaximumHeight())) + $height = (integer)$_REQUEST['height']; + else + $height = $image->getHeight(); - switch((isset($_REQUEST['format']) && !empty($_REQUEST['format'])?$_REQUEST['format']:'default')) + switch((isset($_REQUEST['format']) && !empty($_REQUEST['format'])?$_REQUEST['format']:$imagesConfigList['png'])) { default: case $imagesConfigList['png']: |