From: <wis...@us...> - 2015-12-01 14:58:35
|
Revision: 13173 http://sourceforge.net/p/xoops/svn/13173 Author: wishcraft Date: 2015-12-01 14:58:33 +0000 (Tue, 01 Dec 2015) Log Message: ----------- Pingtrax -- the Pinglist and Trackback Automated module -- Pre-alpha 1.01 -- Planning Modified Paths: -------------- XoopsModules/pingtrax/trunk/class/items.php XoopsModules/pingtrax/trunk/class/plugins.php XoopsModules/pingtrax/trunk/plugins/default.php XoopsModules/pingtrax/trunk/preloads/items.php Modified: XoopsModules/pingtrax/trunk/class/items.php =================================================================== --- XoopsModules/pingtrax/trunk/class/items.php 2015-12-01 13:44:06 UTC (rev 13172) +++ XoopsModules/pingtrax/trunk/class/items.php 2015-12-01 14:58:33 UTC (rev 13173) @@ -76,9 +76,9 @@ $this->initVar('module-php-self', XOBJ_DTYPE_OTHER, '', false, 150); $this->initVar('module-get', XOBJ_DTYPE_ARRAY, array(), false); $this->initVar('item-author-uid', XOBJ_DTYPE_INT, 0, false); - $this->initVar('item-author-name', XOBJ_DTYPE_TXTBOX, 0, false, 64); - $this->initVar('item-title', XOBJ_DTYPE_TXTBOX, 0, false, 180); - $this->initVar('item-description', XOBJ_DTYPE_TXTBOX, 0, false, 250); + $this->initVar('item-author-name', XOBJ_DTYPE_TXTBOX, '', false, 64); + $this->initVar('item-title', XOBJ_DTYPE_TXTBOX, '', false, 180); + $this->initVar('item-description', XOBJ_DTYPE_TXTBOX, '', false, 250); $this->initVar('item-protocol', XOBJ_DTYPE_ENUM, XOOPS_PROT, true, false, false, false, array('https://','http://')); $this->initVar('item-domain', XOBJ_DTYPE_TXTBOX, parse_url(XOOPS_URL, PHP_URL_HOST), true, 150); $this->initVar('item-referer-uri', XOBJ_DTYPE_TXTBOX, $_SERVER["REQUEST_URI"], true, 250); @@ -88,7 +88,6 @@ $this->initVar('feed-referer-uri', XOBJ_DTYPE_TXTBOX, parse_url(XOOPS_URL, PHP_URL_PATH) . '/backend.php', true, 250); $this->initVar('discovery-hook', XOBJ_DTYPE_ENUM, 'unknown', true, false, false, false, array('php','preloader','smarty','combination','unknown')); $this->initVar('user-session', XOBJ_DTYPE_ENUM, 'unknown', true, false, false, false, array('admin','user','guest','unknown')); - $this->initVar('written', XOBJ_DTYPE_INT, 0, false); $this->initVar('created', XOBJ_DTYPE_INT, 0, false); $this->initVar('updated', XOBJ_DTYPE_INT, 0, false); $this->initVar('offline', XOBJ_DTYPE_INT, 0, false); @@ -115,7 +114,17 @@ { if ($object->isNew()) { - $object->setVar('created', time()); + $criteria = new Criteria('referer', $object->getVar('referer')); + if ($this->getCount($criteria)==0) + $object->setVar('created', time()); + else + { + $objs = $this->getObjects($criteria, false); + if (isset($objs[0])) + return $objs[0]->getVar('id'); + else + return false; + } } else { $object->setVar('updated', time()); } Modified: XoopsModules/pingtrax/trunk/class/plugins.php =================================================================== --- XoopsModules/pingtrax/trunk/class/plugins.php 2015-12-01 13:44:06 UTC (rev 13172) +++ XoopsModules/pingtrax/trunk/class/plugins.php 2015-12-01 14:58:33 UTC (rev 13173) @@ -29,11 +29,25 @@ { /** + * @var array + */ + var $_configs = array(); + + /** * */ function __construct() { $this->XoopsObject(); + + // Load Module Config's into object array + $moduleHandler = xoops_gethandler('module'); + $module = $moduleHandler->getByDirname('pingtrax'); + if (is_a($module, 'XoopsModule')) + { + $configHandler = xoops_gethandler('config'); + $this->_configs = $configHandler->getConfigList($module->getVar('mid')); + } } /** @@ -60,8 +74,8 @@ { if (substr(strtolower($class), 0, strlen($this->getModuleDirname()))==strtolower($this->getModuleDirname()) && (!strpos(strtolower($class), 'categor') && !strpos(strtolower($this->getModulePHPSelf()), 'categor'))) { - if (is_a(new $class(), "XoopsPersistableObjectHandler")) - return $class; + if (is_a(@new $class(), "XoopsPersistableObjectHandler")) + return strtolower(str_replace(array(ucfirst($this->getModuleDirname()), $this->getModuleDirname(), 'handler', 'Handler'), '', $class)); } } @@ -186,6 +200,165 @@ return substr($_SERVER["PHP_SELF"], strlen(XOOPS_ROOT_PATH)-1); return $_SERVER["PHP_SELF"]; } + + + /** + * + */ + function getItemTitle() + { + switch ($this->getModulePHPSelf()) + { + default: + + if (is_object($GLOBALS['xoopsTpl'])) + return $GLOBALS['xoopsTpl']->_tpl_vars['xoops_pagetitle']; + break; + } + return $GLOBALS["xoopsConfig"]['sitename']; + } + + + /** + * + */ + function getItemDescription() + { + switch ($this->getModulePHPSelf()) + { + default: + + if (is_object($GLOBALS['xoopsTpl'])) + return $GLOBALS['xoopsTpl']->_tpl_vars['xoops_meta_description']; + break; + } + return $GLOBALS["xoopsConfigMetaFooter"]['meta_description']; + } + + /** + * + */ + function getItemAuthorUID() + { + static $uid = 0; + if ($uid = 0) + switch ($this->getModulePHPSelf()) + { + default: + foreach($GLOBALS['xoopsTpl']->_tpl_vars as $key => $values) + { + if ($key = 'uid' && is_numeric($values)) + $uid = $values; + elseif(is_array($values)) + $uid = explore_array($values, 'uid', 'uid=([0-9]+)'); + elseif(is_string($values)) + { + preg_match('uid=([0-9])+', $values, $matches); + if (!empty($matches)) + { + foreach($matches as $match) + { + if (is_array($match)) + { + foreach($match as $value) + if (is_numeric($value)) + { + $uid = $value; + continue; + continue; + continue; + continue; + } + } else { + $uid = $match; + continue; + continue; + continue; + } + } + } + } + if ($uid>0) + continue; + } + } + return $uid; + } + + function explore_array($array = array(), $key = 'uid', $pattern = 'uid=([0-9]+)') + { + foreach($array as $key => $values) + { + if ($key = 'uid' && is_numeric($values)) + return $values; + elseif(is_array($values)) + return explore_array($values, 'uid', 'uid=([0-9]+)'); + elseif(is_string($values)) + { + preg_match('uid=([0-9])+', $values, $matches); + if (!empty($matches)) + foreach($matches as $match) + if (is_array($match)) + foreach($match as $value) + if (is_numeric($value)) + { + return $value; + } + else + return $match; + } + } + } + + /** + * + */ + function getItemAuthorName() + { + switch ($this->getModulePHPSelf()) + { + default: + if ($this->getItemAuthorUID()>0) + { + $userHandler = xoops_gethandler('user'); + $user = $userHandler->get($this->getItemAuthorUID()); + if (is_a($user, "XoopsUser")) + { + if (trim($user->getVar('name'))!='') + return trim($user->getVar('name')); + else + return trim($user->getVar('uname')); + } + } + } + return $GLOBALS["xoopsConfig"]['sitename']; + } + + + /** + * + */ + function getFeedProtocol() + { + return parse_url(strtolower($this->_configs['default_feed_url']), PHP_URL_SCHEME); + } + + /** + * + */ + function getFeedDomain() + { + return parse_url(strtolower($this->_configs['default_feed_url']), PHP_URL_HOST); + } + + /** + * + */ + function getFeedRefererURI() + { + return parse_url(strtolower($this->_configs['default_feed_url']), PHP_URL_PATH) . "?" .parse_url(strtolower($this->_configs['default_feed_url']), PHP_URL_QUERY); + } + } @@ -213,7 +386,7 @@ parent::__construct($db); } - function getIntialItemArray() + function getItemObject() { $ret = array(); if (is_a($GLOBALS['xoopsModule'], 'XoopsModule')) @@ -244,14 +417,55 @@ $ret['item-protocol'] = $this->_plugins[$dirname]->getItemProtocol(); $ret['item-domain'] = $this->_plugins[$dirname]->getItemDomain(); $ret['item-referer-uri'] = $this->_plugins[$dirname]->getItemRefererURI(); + $ret['feed-protocol'] = $this->_plugins[$dirname]->getFeedProtocol(); + $ret['feed-domain'] = $this->_plugins[$dirname]->getFeedDomain(); + $ret['feed-referer-uri'] = $this->_plugins[$dirname]->getFeedRefererURI(); $ret['item-php-self'] = $this->_plugins[$dirname]->getItemPHPSelf(); $ret['referer'] = $this->getReferer($ret); } + if (!empty($ret)) + { + $itemsHandler = xoops_getmodulehandler('items', 'pingtrax'); + $item = $itemHandler->create(true); + $item->setVars($ret); + $ret = $itemHandler->get($itemHandler->insert($item)); + } return $ret; } function getReferer($ret = array()) { - return sha1($ret['item-php-self'] . $ret['item-referer-uri'] . $ret['module-dirname'] . $ret['module-class'] . $ret['item-category-id'] . $ret['module-item-id'] . $ret['module-php-self'] . json_encode($ret['module-get'], true) . $ret['item-protocol'] . $ret['item-domain']); + return sha1($ret['item-php-self'] . $ret['item-referer-uri'] . $ret['feed-protocol'] . $ret['feed-domain'] . $ret['feed-referer-uri'] . $ret['module-dirname'] . $ret['module-class'] . $ret['item-category-id'] . $ret['module-item-id'] . $ret['module-php-self'] . json_encode($ret['module-get'], true) . $ret['item-protocol'] . $ret['item-domain']); } + + function setFooterItem(PingtraxItems $item) + { + if (is_a($GLOBALS['xoopsModule'], 'XoopsModule')) + { + if (file_exists($file = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . ($dirname = $GLOBALS['xoopsModule']->getVar('dirname')) . '.php')) + { + require_once $file; + } elseif (file_exists($file = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . ($dirname = $this->_default) . '.php')) + { + require_once $file; + } + } elseif (file_exists($file = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . ($dirname = $this->_default) . '.php')) + { + require_once $file; + } + if (class_exists($class = "PingtraxPlugins".ucfirst(strtolower($dirname))) && empty($this->_plugins[$dirname])) + { + $this->_plugins[$dirname] = new $class(); + } + if (is_object($this->_plugins[$dirname])) + { + $item->setVar('item-author-uid', $this->_plugins[$dirname]->getItemAuthorUID()); + $item->setVar('item-author-name', $this->_plugins[$dirname]->getItemAuthorName()); + $item->setVar('item-title', $this->_plugins[$dirname]->getItemTitle()); + $item->setVar('item-description', $this->_plugins[$dirname]->getItemTitle()); + $itemsHandler = xoops_getmodulehandler('items', 'pingtrax'); + return $itemHandler->get($itemHandler->insert($item)); + } + return $item; + } } Modified: XoopsModules/pingtrax/trunk/plugins/default.php =================================================================== --- XoopsModules/pingtrax/trunk/plugins/default.php 2015-12-01 13:44:06 UTC (rev 13172) +++ XoopsModules/pingtrax/trunk/plugins/default.php 2015-12-01 14:58:33 UTC (rev 13173) @@ -27,25 +27,6 @@ */ class PingtraxPluginsDefault extends PingtraxPlugins { - /** - * @param $args - - function eventCoreIncludeFunctionsRedirectheader($args) - { - $context = stream_context_create(array('http' => array( - 'method' => "POST", - 'header' => "Content-Type: text/xml\r\n", - 'content' => $xml - ))); - $file = @file_get_contents($post_to, false, $context); - if ($file === false) { echo '<p>Couldn\'t connect!</p>'; } - elseif ($file) { - echo '<p>The following response was returned:</p>'; - echo '<pre>'.htmlspecialchars($file).'</pre>'; - } else { - echo '<p>Empty response!</p>'; - } - } - */ + } Modified: XoopsModules/pingtrax/trunk/preloads/items.php =================================================================== --- XoopsModules/pingtrax/trunk/preloads/items.php 2015-12-01 13:44:06 UTC (rev 13172) +++ XoopsModules/pingtrax/trunk/preloads/items.php 2015-12-01 14:58:33 UTC (rev 13173) @@ -33,9 +33,23 @@ */ function eventCoreIncludeCommonEnd($args) { - global $moduleitem; + global $pingtraxitem; $pluginHandler = xoops_getmodulehandler('plugins', 'pingtrax'); - $moduleitem = $pluginHandler->getIntialItemArray(); + $pingtraxitem = $pluginHandler->getItemObject(); } - + + /** + * @param $args + */ + function eventCoreFooterEnd($args) + { + global $pingtraxitem; + if (is_a($pingtraxitem, "PingtraxItems")) + { + $pluginHandler = xoops_getmodulehandler('plugins', 'pingtrax'); + if ($pingtraxitem->getVar('discover-hook')=='unknown') + $pingtraxitem->setVar('discover-hook', 'preloader'); + $pingtraxitem = $pluginHandler->setFooterItem($pingtraxitem); + } + } } |