From: <zy...@us...> - 2014-12-08 20:21:41
|
Revision: 12890 http://sourceforge.net/p/xoops/svn/12890 Author: zyspec Date: 2014-12-08 20:21:32 +0000 (Mon, 08 Dec 2014) Log Message: ----------- include files missing in previous commit for v2.1 Beta 1 Added Paths: ----------- XoopsModules/randomquote/branches/zyspec/randomquote/assets/images/icons/quote.png XoopsModules/randomquote/branches/zyspec/randomquote/class/constants.php XoopsModules/randomquote/branches/zyspec/randomquote/include/action.module.php XoopsModules/randomquote/branches/zyspec/randomquote/include/plugin.tag.php XoopsModules/randomquote/branches/zyspec/randomquote/include/search.inc.php Added: XoopsModules/randomquote/branches/zyspec/randomquote/assets/images/icons/quote.png =================================================================== (Binary files differ) Index: XoopsModules/randomquote/branches/zyspec/randomquote/assets/images/icons/quote.png =================================================================== --- XoopsModules/randomquote/branches/zyspec/randomquote/assets/images/icons/quote.png 2014-12-08 20:18:04 UTC (rev 12889) +++ XoopsModules/randomquote/branches/zyspec/randomquote/assets/images/icons/quote.png 2014-12-08 20:21:32 UTC (rev 12890) Property changes on: XoopsModules/randomquote/branches/zyspec/randomquote/assets/images/icons/quote.png ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Added: XoopsModules/randomquote/branches/zyspec/randomquote/class/constants.php =================================================================== --- XoopsModules/randomquote/branches/zyspec/randomquote/class/constants.php (rev 0) +++ XoopsModules/randomquote/branches/zyspec/randomquote/class/constants.php 2014-12-08 20:21:32 UTC (rev 12890) @@ -0,0 +1,78 @@ +<?php +/* + 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. +*/ +/** + * RandomQuote module + * + * Class to define Random Quote module constant values. These constants are + * used to make the code easier to read and to keep values in central + * location if they need to be changed. These should not normally need + * to be modified. If they are to be modified it is recommended to change + * the value(s) before module installation. Additionally the module may not + * work correctly if trying to upgrade if these values have been changed. + * + * @category Module + * @package randomquote + * @copyright:: {@link http://sourceforge.net/projects/xoops/ The XOOPS Project} + * @license:: {@link http://www.gnu.org/licenses/gpl-2.0.html GNU Public License} + * @author:: zyspec <ow...@zy...> + * @since:: 2.11 + * @version:: $Id: $ + **/ + +defined('XOOPS_ROOT_PATH') or die('Restricted access'); + +interface RandomquoteConstants +{ +/**#@+ + * Constant definition + */ + /** + * indicates a quote is inactive + */ + const STATUS_OFFLINE = 0; + /** + * indicates a quote is active + */ + const STATUS_ONLINE = 1; + /** + * indicates a quote is waiting approval + */ + const STATUS_WAITING = 2; + /** + * indicates default quote ID + */ + const DEFAULT_ID = 0; + /** + * no delay XOOPS redirect delay (in seconds) + */ + const REDIRECT_DELAY_NONE = 0; + /** + * short XOOPS redirect delay (in seconds) + */ + const REDIRECT_DELAY_SHORT = 1; + /** + * medium XOOPS redirect delay (in seconds) + */ + const REDIRECT_DELAY_MEDIUM = 3; + /** + * long XOOPS redirect delay (in seconds) + */ + const REDIRECT_DELAY_LONG = 7; + /** + * confirm not ok to take action + */ + const CONFIRM_NOT_OK = 0; + /** + * confirm ok to take action + */ + const CONFIRM_OK = 1; +/**#@-*/ +} \ No newline at end of file Added: XoopsModules/randomquote/branches/zyspec/randomquote/include/action.module.php =================================================================== --- XoopsModules/randomquote/branches/zyspec/randomquote/include/action.module.php (rev 0) +++ XoopsModules/randomquote/branches/zyspec/randomquote/include/action.module.php 2014-12-08 20:21:32 UTC (rev 12890) @@ -0,0 +1,300 @@ +<?php +/* + 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. +*/ + +/** + * XOOPS Randomquote management module + * + * @package randomquote + * @copyright The XOOPS project http://sourceforge.net/projects/xoops/ + * @license http://www.fsf.org/copyleft/gpl.html GNU public license + * @since 1.00 + * @author Taiwen Jiang <ph...@us...> + * @author ZySpec <ow...@zy...> + * @version $Id: $ + * */ + +/** + * @internal {Make sure you PROTECT THIS FILE + * + * This code has the potential to be extremely dangerous!!} + */ + +if ((!defined('XOOPS_ROOT_PATH')) + || !($GLOBALS['xoopsUser'] instanceof XoopsUser) + || !($GLOBALS['xoopsUser']->IsAdmin())) +{ + exit("Restricted access" . PHP_EOL); +} + +/** + * @param string $tablename + * + * @return bool + */ +function tableExists($tablename) +{ + $result = $GLOBALS['xoopsDB']->queryF("SHOW TABLES LIKE '$tablename'"); + return ($GLOBALS['xoopsDB']->getRowsNum($result) > 0) ? true : false; +} + +/** + * + * Verifies XOOPS version meets minimum requirements for this module + * @param obj $module {@link XoopsModule} + * + * @return bool true if meets requirements, false if not + */ +function randomquoteCheckXoopsVer(&$module) { + //check for minimum XOOPS version + $currentVer = substr(XOOPS_VERSION, 6); // get the numeric part of string + $currArray = explode('.', $currentVer); + $requiredVer = "" . $module->getInfo('min_xoops'); //making sure it's a string + $reqArray = explode('.', $requiredVer); + $success = true; + foreach ($reqArray as $k=>$v) { + if (isset($currArray[$k])) { + if ($currArray[$k] >= $v) { + continue; + } else { + $success = false; + break; + } + } else { + if ($v > 0) { + $success = false; + break; + } + } + } + + if (!$success) { + $module->setErrors(sprintf(_AM_RANDOMQUOTE_ERROR_BAD_XOOPS, $requiredVer, $currentVer)); + } + + return $success; +} + +/** + * + * Verifies PHP version meets minimum requirements for this module + * @param obj $module {@link XoopsModule} + * + * @return bool true if meets requirements, false if not + */ +function randomquoteCheckPHPVer(&$module) { + // check for minimum PHP version + $phpLen = strlen(PHP_VERSION); + $extraLen = strlen(PHP_EXTRA_VERSION); + $verNum = substr(PHP_VERSION, 0, ($phpLen-$extraLen)); + $reqVer = $module->getInfo('min_php'); + + $success = true; + if ($verNum >= $reqVer) { + $module->setErrors(sprintf(_AM_RANDOMQUOTE_ERROR_BAD_PHP, $reqVer, $verNum)); + $success = false; + } + + return $success; +} + +/** + * + * Performs tasks required during installation of the module + * @param obj $module {@link XoopsModule} + * + * @return bool true if installation successful, false if not + */ +function xoops_module_install_randomquote(&$module) { + return true; +} + +/** + * + * Prepares system prior to attempting to install module + * @param obj $module {@link XoopsModule} + * + * @return bool true if ready to install, false if not + */ +function xoops_module_pre_install_randomquote(&$module) +{ + //check for minimum XOOPS version + if (!randomquoteCheckXoopsVer($module)) { + return false; + } + + // check for minimum PHP version + if (!randomquoteCheckPHPVer($module)) { + return false; + } + return true; +} + +/** + * + * Prepares system prior to attempting to update module + * @param obj $module {@link XoopsModule} + */ +function xoops_module_pre_update_randomquote(&$module) +{ + //check for minimum XOOPS version + if (!randomquoteCheckXoopsVer($module)) { + return false; + } + + // check for minimum PHP version + if (!randomquoteCheckPHPVer($module)) { + return false; + } + return true; +} + + +function xoops_module_pre_uninstall_randomquote(&$module) +{ + /* Do some synchronization with tags to remove tags associated with this module + * + * @todo: write this code... + * + * pseudo code + * if (tag module installed) { + * get quote handler + * get all items with tags + * get tag handler + * delete all tags for this module + * } + */ + $success = true; + $tagModule =& XoopsModule::getByDirname('tag'); + if (($tagModule instanceof XoopsModule) && ($tagModule->isactive())) { + // first delete all quotes + $quotes_handler =& xoops_getmodulehandler('quotes', 'randomquote'); + $quoteObjs = $quotes_handler->deleteAll(); + //now 'unlink' the quote tags from Tag modules + include_once $GLOBALS['xoops']->path("/modules/tag/include/functions.recon.php"); + $success = tag_synchronization(); + if (!$success) { + $module->setErrors(_AM_RANDOMQUOTE_ERROR_TAG_REMOVAL); + } + } + + return $success; +} + +function xoops_module_uninstall_randomquote(&$module) +{ + return $success; +} + +/** + * + * Functions to upgrade from previous version of the module + * + * @param obj $module {@link XoopsModule} + * @param int $curr_version version number of module currently installed + * + * @return bool true if successfully updated module, false if not + */ +function xoops_module_update_randomquote(&$module, $curr_version = null) +{ + $errors = 0; + if (tableExists($GLOBALS['xoopsDB']->prefix('citas'))) { + + $sql = sprintf('ALTER TABLE ' + . $GLOBALS['xoopsDB']->prefix('citas') + . ' CHANGE `citas` `quote` TEXT' + ); + $result = $GLOBALS['xoopsDB']->queryF($sql); + if (!$result) { + $module->setErrors(_AM_RANDOMQUOTE_UPGRADEFAILED0); + ++$errors; + } + + $sql = sprintf('ALTER TABLE ' + . $GLOBALS['xoopsDB']->prefix('citas') + . " ADD COLUMN `quote_status` int (10) NOT NULL default '0'," + . " ADD COLUMN `quote_waiting` int (10) NOT NULL default '0'," + . " ADD COLUMN `quote_online` int (10) NOT NULL default '0';" + ); + $result = $GLOBALS['xoopsDB']->queryF($sql); + if (!$result) { + $module->setErrors(_AM_RANDOMQUOTE_UPGRADEFAILED1); + ++$errors; + } + + $sql = sprintf('ALTER TABLE ' + . $GLOBALS['xoopsDB']->prefix('citas') + . ' RENAME ' + . $GLOBALS['xoopsDB']->prefix('quotes') + ); + $result = $GLOBALS['xoopsDB']->queryF($sql); + if (!$result) { + $module->setErrors(_AM_RANDOMQUOTE_UPGRADEFAILED2); + ++$errors; + } + } elseif (tableExists($GLOBALS['xoopsDB']->prefix('randomquote_quotes'))) { + + // change status to indicate quote waiting approval + $sql = "UPDATE " . $GLOBALS['xoopsDB']->prefix('randomquote_quotes') . " SET quote_status=2 WHERE `quote_waiting` > 0"; + $result = $GLOBALS['xoopsDB']->queryF($sql); + if (!$result) { + $module->setErrors(_AM_RANDOMQUOTE_UPGRADEFAILED1); + ++$errors; + } + + // change status to indicate quote online + $sql = "UPDATE " . $GLOBALS['xoopsDB']->prefix('randomquote_quotes') . " SET quote_status=1 WHERE `quote_online` > 0"; + $result = $GLOBALS['xoopsDB']->queryF($sql); + if (!$result) { + $module->setErrors(_AM_RANDOMQUOTE_UPGRADEFAILED1); + ++$errors; + } + + // drop the waiting and online columns + $sql = sprintf('ALTER TABLE ' + . $GLOBALS['xoopsDB']->prefix('randomquote_quotes') + . " DROP COLUMN `quote_waiting`," + . " DROP COLUMN `quote_online`;" + ); + $result = $GLOBALS['xoopsDB']->queryF($sql); + if (!$result) { + $module->setErrors(_AM_RANDOMQUOTE_UPGRADEFAILED1); + ++$errors; + } + + // change the table name (drops the module name prefix) + $sql = sprintf('ALTER TABLE ' + . $GLOBALS['xoopsDB']->prefix('randomquote_quotes') + . ' RENAME ' + . $GLOBALS['xoopsDB']->prefix('quotes') + ); + $result = $GLOBALS['xoopsDB']->queryF($sql); + if (!$result) { + $module->setErrors(_AM_RANDOMQUOTE_UPGRADEFAILED2); + ++$errors; + } + } + + // add column for randomquote create_date for versions prior to 2.33 + if ($installedVersion < 233) { + $result = $db->queryF("SHOW COLUMNS FROM " . $db->prefix('quotes') . " LIKE 'create_date'"); + $foundColumn = $db->getRowsNum($result); + if (empty($foundColumn)) { + // column doesn't exist, so try and add it + $success = $db->queryF("ALTER TABLE " . $db->prefix('quotes') . " ADD create_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP AFTER quote_status"); + if (!$success) { + $module->setErrors(sprintf(_AM_RANDOMQUOTE_ERROR_COLUMN, 'create_date')); + ++$errors; + } + } + } + + return ($errors) ? false : true; +} Added: XoopsModules/randomquote/branches/zyspec/randomquote/include/plugin.tag.php =================================================================== --- XoopsModules/randomquote/branches/zyspec/randomquote/include/plugin.tag.php (rev 0) +++ XoopsModules/randomquote/branches/zyspec/randomquote/include/plugin.tag.php 2014-12-08 20:21:32 UTC (rev 12890) @@ -0,0 +1,112 @@ +<?php +/* + 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. +*/ + +/** + * XOOPS tag management module + * + * @package randomquote + * @copyright {@link http://sourceforge.net/projects/xoops/ The XOOPS Project} + * @license {@link http://www.fsf.org/copyleft/gpl.html GNU public license} + * @author Taiwen Jiang <ph...@us...> + * @author ZySpec <ow...@zy...> + * @since 2.11 + * @version $Id: $ + */ + +defined('XOOPS_ROOT_PATH') || exit('Restricted access'); + +XoopsLoad::load('XoopsFilterInput'); + +/** Get item fields: title, content, time, link, uid, tags + * + * Note that $items is "by reference" so modifying it in this + * routine in effect passes it back... + * + * @param array $items + * + * @return bool always returns true + **/ +function randomquote_tag_iteminfo(&$items) +{ + xoops_load('constants', 'randomquote'); + + $items_id = array(); + $cats_id = array(); + + foreach (array_keys($items) as $cat_id) { + $cats_id[] = intval($cat_id); + foreach (array_keys($items[$cat_id]) as $item_id) { + $items_id[] = intval($item_id); + } + } + + $criteria = new CriteriaCompo(); + $criteria->add(new Criteria("id", "(" . implode(",", $items_id) . ")", "IN")); + $criteria->add(new Criteria('quote_status', RandomquoteConstants::STATUS_ONLINE)); + + $quote_handler =& xoops_getmodulehandler('quotes', 'randomquote'); + $quoteObjs = $quote_handler->getObjects($criteria, true); + + foreach ($cats_id as $cat_id) { + foreach ($items_id as $item_id) { + $quoteObj = $quoteObjs[$item_id]; + $items[$cat_id][$item_id] = array("title" => $quoteObj, +// "uid" => $quoteObj->getVar("uid"), + "link" => "index.php?id={$item_id}", + "time" => strtotime($quoteObj->getVar("create_date")), +// "tags" => tag_parse_tag($quoteObj->getVar("item_tag", "n")), // optional + "content" => "", + ); + } + } + + unset($items_obj); + return true; +} + +/** + * Remove orphan tag-item links + * + * @param int $mid module ID + */ +function mymodule_tag_synchronization($mid) +{ + xoops_load('constants', 'randomquote'); + $item_handler =& xoops_getmodulehandler('quotes', 'randomquote'); + $link_handler =& xoops_getmodulehandler('link', 'tag'); + + if (!$item_handler || !$link_handler) { + $result = false; + } else { + $mid = XoopsFilterInput::clean($mid, 'INT'); + $module_handler =& xoops_gethandler('module'); + $rqModule =& XoopsModule::getByDirname('randomquote'); + + // check to make sure module is active and trying to sync randomquote + if (($rqModule instanceof XoopsModule) && ($rqModule->isactive()) && ($rqModule->mid() == $mid)) { + // clear tag-item links + $sql = "DELETE FROM {$link_handler->table}" + . " WHERE tag_modid = {$mid}" + . " AND " + . " (tag_itemid NOT IN " + . " (SELECT DISTINCT {$item_handler->keyName} " + . " FROM {$item_handler->table} " + . " WHERE {$item_handler->table}.quote_status = " . RandomquoteConstants::STATUS_ONLINE + . " )" + . " )"; + $result = $link_handler->db->queryF($sql); + } else { + $result = false; + } + } + + return ($result) ? true : false; +} Added: XoopsModules/randomquote/branches/zyspec/randomquote/include/search.inc.php =================================================================== --- XoopsModules/randomquote/branches/zyspec/randomquote/include/search.inc.php (rev 0) +++ XoopsModules/randomquote/branches/zyspec/randomquote/include/search.inc.php 2014-12-08 20:21:32 UTC (rev 12890) @@ -0,0 +1,66 @@ +<?php +/* + 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. +*/ + +/** + * Module: RandomQuote + * + * @category Module + * @package randomquote + * @author XOOPS Module Development Team + * @copyright {@link http://sourceforge.net/projects/xoops/ The XOOPS Project} + * @license {@link http://www.fsf.org/copyleft/gpl.html GNU public license} + * @version $Id: admin_footer.php 12702 2014-07-11 17:18:50Z beckmi $ + * @link http://sourceforge.net/projects/xoops/ + * @since 2.0.0 + */ + +xoops_load('constants', 'randomquote'); + +function randomquote_search($queryarray, $andor, $limit, $offset, $userid) +{ + $ret = array(); + if (0 != (int) $userid) { + return $ret; + } + $quote_handler =& xoops_getmodulehandler('quotes', 'randomquote'); + $entryFields = array('id', 'quote', 'author', 'create_date'); + $criteria = new CriteriaCompo(); + $criteria->add(new Criteria('quote_status', RandomquoteConstants::STATUS_ONLINE)); + $criteria->setSort('create_date'); + $criteria->setOrder('DESC'); + $criteria->setLimit((int) $limit); + $criteria->setStart((int) $offset); + + if ((is_array($queryarray)) && !empty($queryarray)) { + $criteria->add(new Criteria('quote', "%{$queryarray[0]}%", 'LIKE')); + $criteria->add(new Criteria('author', "%{$queryarray[0]}%", 'LIKE'), 'OR'); + array_shift($queryarray); //get rid of first element + + foreach ($queryarray as $query) { + $criteria->add(new Criteria('quote', "%{$query}%", 'LIKE'), $andor); + $criteria->add(new Criteria('author', "%{$query}%", 'LIKE'), 'OR'); + } + } + $quoteObjs = $quote_handler->getAll($criteria, $entryFields); + foreach ($quoteObjs as $thisQuote) { + $ret[] = array ( + 'image' => 'assets/images/icons/quote.png', + 'link' => "index.php?id=" . $thisQuote->getVar('id'), + 'title' => (string) $thisQuote, //uses magic __toString() + 'time' => strtotime($thisQuote->getVar('create_date')), +// 'uid' => $entry['uid'] + ); + + } + + unset($quoteObjs); + return $ret; +} |