From: <wis...@us...> - 2015-12-07 14:25:25
|
Revision: 13180 http://sourceforge.net/p/xoops/svn/13180 Author: wishcraft Date: 2015-12-07 14:25:21 +0000 (Mon, 07 Dec 2015) Log Message: ----------- PingTrax Pre-alpha :: More done\!\!\! Added Paths: ----------- XoopsModules/pingtrax/trunk/ XoopsModules/pingtrax/trunk/class/ XoopsModules/pingtrax/trunk/class/smarty/ XoopsModules/pingtrax/trunk/class/smarty/xoops_plugins/ XoopsModules/pingtrax/trunk/class/smarty/xoops_plugins/function.xoTrackbacks.php XoopsModules/pingtrax/trunk/modules/ XoopsModules/pingtrax/trunk/modules/pingtrax/ XoopsModules/pingtrax/trunk/modules/pingtrax/admin/ XoopsModules/pingtrax/trunk/modules/pingtrax/admin/index.html XoopsModules/pingtrax/trunk/modules/pingtrax/api/ XoopsModules/pingtrax/trunk/modules/pingtrax/api/.htaccess XoopsModules/pingtrax/trunk/modules/pingtrax/api/index.php XoopsModules/pingtrax/trunk/modules/pingtrax/blocks/ XoopsModules/pingtrax/trunk/modules/pingtrax/blocks/index.html XoopsModules/pingtrax/trunk/modules/pingtrax/class/ XoopsModules/pingtrax/trunk/modules/pingtrax/class/index.html XoopsModules/pingtrax/trunk/modules/pingtrax/class/items.php XoopsModules/pingtrax/trunk/modules/pingtrax/class/items_pings.php XoopsModules/pingtrax/trunk/modules/pingtrax/class/items_sitemaps.php XoopsModules/pingtrax/trunk/modules/pingtrax/class/pings.php XoopsModules/pingtrax/trunk/modules/pingtrax/class/plugins.php XoopsModules/pingtrax/trunk/modules/pingtrax/class/simple_html_dom.php XoopsModules/pingtrax/trunk/modules/pingtrax/class/sitemaps.php XoopsModules/pingtrax/trunk/modules/pingtrax/class/trackback.php XoopsModules/pingtrax/trunk/modules/pingtrax/images/ XoopsModules/pingtrax/trunk/modules/pingtrax/images/link.png XoopsModules/pingtrax/trunk/modules/pingtrax/images/logo.png XoopsModules/pingtrax/trunk/modules/pingtrax/include/ XoopsModules/pingtrax/trunk/modules/pingtrax/include/category-id-names.txt XoopsModules/pingtrax/trunk/modules/pingtrax/include/exclude-names.txt XoopsModules/pingtrax/trunk/modules/pingtrax/include/index.html XoopsModules/pingtrax/trunk/modules/pingtrax/include/item-id-names.txt XoopsModules/pingtrax/trunk/modules/pingtrax/language/ XoopsModules/pingtrax/trunk/modules/pingtrax/language/english/ XoopsModules/pingtrax/trunk/modules/pingtrax/language/english/help/ XoopsModules/pingtrax/trunk/modules/pingtrax/language/english/help/help.html XoopsModules/pingtrax/trunk/modules/pingtrax/language/english/help/index.html XoopsModules/pingtrax/trunk/modules/pingtrax/language/english/index.html XoopsModules/pingtrax/trunk/modules/pingtrax/language/english/modinfo.php XoopsModules/pingtrax/trunk/modules/pingtrax/language/index.html XoopsModules/pingtrax/trunk/modules/pingtrax/plugins/ XoopsModules/pingtrax/trunk/modules/pingtrax/plugins/default.php XoopsModules/pingtrax/trunk/modules/pingtrax/plugins/index.html XoopsModules/pingtrax/trunk/modules/pingtrax/preloads/ XoopsModules/pingtrax/trunk/modules/pingtrax/preloads/index.html XoopsModules/pingtrax/trunk/modules/pingtrax/preloads/items.php XoopsModules/pingtrax/trunk/modules/pingtrax/preloads/ping.php XoopsModules/pingtrax/trunk/modules/pingtrax/preloads/sitemap.php XoopsModules/pingtrax/trunk/modules/pingtrax/preloads/trackback.php XoopsModules/pingtrax/trunk/modules/pingtrax/sql/ XoopsModules/pingtrax/trunk/modules/pingtrax/sql/index.html XoopsModules/pingtrax/trunk/modules/pingtrax/sql/mysql.sql XoopsModules/pingtrax/trunk/modules/pingtrax/sql/tables.json XoopsModules/pingtrax/trunk/modules/pingtrax/templates/ XoopsModules/pingtrax/trunk/modules/pingtrax/templates/admin/ XoopsModules/pingtrax/trunk/modules/pingtrax/templates/admin/index.html XoopsModules/pingtrax/trunk/modules/pingtrax/templates/blocks/ XoopsModules/pingtrax/trunk/modules/pingtrax/templates/blocks/index.html XoopsModules/pingtrax/trunk/modules/pingtrax/templates/index.html XoopsModules/pingtrax/trunk/modules/pingtrax/templates/sitemaps.xml.html XoopsModules/pingtrax/trunk/modules/pingtrax/templates/xoTrackback.html XoopsModules/pingtrax/trunk/modules/pingtrax/xoops_version.php Removed Paths: ------------- XoopsModules/pingtrax/trunk/ Added: XoopsModules/pingtrax/trunk/class/smarty/xoops_plugins/function.xoTrackbacks.php =================================================================== --- XoopsModules/pingtrax/trunk/class/smarty/xoops_plugins/function.xoTrackbacks.php (rev 0) +++ XoopsModules/pingtrax/trunk/class/smarty/xoops_plugins/function.xoTrackbacks.php 2015-12-07 14:25:21 UTC (rev 13180) @@ -0,0 +1,51 @@ +<?php +/** + * PingTrax Smarty Trackback Function + * + * 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 Chronolabs Cooperative http://sourceforge.net/projects/chronolabs/ + * @license GNU GPL 3 (http://labs.coop/briefs/legal/general-public-licence/13,3.html) + * @author Simon Antony Roberts <wis...@us...> + * @see http://sourceforge.net/projects/xoops/ + * @see http://sourceforge.net/projects/chronolabs/ + * @see http://sourceforge.net/projects/chronolabsapi/ + * @see http://labs.coop + * @version 1.0.1 + * @since 1.0.1 + */ + +function smarty_function_xoTrackbacks($tag_args, &$comp) +{ + $attrs = $comp->_parse_attrs($tag_args); + foreach ($attrs as $arg_name => $arg_value) { + if ($arg_name == 'dirname') { + $dirname = $arg_value; + continue; + } + } + global $pingtraxitem; + if (is_a($pingtraxitem, "PingtraxItems")) + { + $GLOBALS['xoTheme']->addStylesheet(XOOPS_URL . "/modules/pingtrax/pingtrax.css"); + $trackbacksTpl = new XoopsTpl(); + $trackbacksTpl->assign('permlink', $pingtraxitem->getVar('item-protocol').$pingtraxitem->getVar('item-domain').$pingtraxitem->getVar('item-referer-uri')); + $commentHandler = xoops_gethandler('comment'); + $moduleHandler = xoops_gethandler('module'); + $criteria = new CriteriaCompo(new Criteria('com_modid', $moduleHandler->getByDirname('pingtrax')->getVar('mid'))); + $criteria->add(new Criteria('com_itemid', $pingtraxitem->getVar('id'))); + $criteria->setOrder('com_created'); + $criteria->setSort('DESC'); + foreach($commentHandler->getObjects($criteria) as $comid => $comment) + $trackbacksTpl->append('trackbacks', array('subject'=>$comment->getVar('com_title'), 'comment'=>$comment->getVar('com_text'))); + ob_start(); + $trackbacksTpl->display($GLOBALS['xoops']->path('/modules/pingtrax/templates/xoTrackback.html')); + return ob_get_clean(); + } + return ''; +} Added: XoopsModules/pingtrax/trunk/modules/pingtrax/admin/index.html =================================================================== --- XoopsModules/pingtrax/trunk/modules/pingtrax/admin/index.html (rev 0) +++ XoopsModules/pingtrax/trunk/modules/pingtrax/admin/index.html 2015-12-07 14:25:21 UTC (rev 13180) @@ -0,0 +1 @@ + <script>history.go(-1);</script> \ No newline at end of file Property changes on: XoopsModules/pingtrax/trunk/modules/pingtrax/admin/index.html ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Added: XoopsModules/pingtrax/trunk/modules/pingtrax/api/.htaccess =================================================================== --- XoopsModules/pingtrax/trunk/modules/pingtrax/api/.htaccess (rev 0) +++ XoopsModules/pingtrax/trunk/modules/pingtrax/api/.htaccess 2015-12-07 14:25:21 UTC (rev 13180) @@ -0,0 +1,2 @@ +RewriteEngine On +RewriteRule ^([0-9a-z]{32})$ index.php?referer=$1 [L] \ No newline at end of file Added: XoopsModules/pingtrax/trunk/modules/pingtrax/api/index.php =================================================================== --- XoopsModules/pingtrax/trunk/modules/pingtrax/api/index.php (rev 0) +++ XoopsModules/pingtrax/trunk/modules/pingtrax/api/index.php 2015-12-07 14:25:21 UTC (rev 13180) @@ -0,0 +1,50 @@ +<?php + +require_once dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR . "mainfile.php"; +require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . "class". DIRECTORY_SEPARATOR . "trackback.php"; + +$trackback = new PingtraxTrackback($GLOBALS['xoopsConfig']['sitename'], $GLOBALS['xoopsConfig']['sitename'], 'UTF-8'); + +if (!isset($_GET['referer'])) + die($trackback->recieve(false, "\$_GET['referer'] not specified and is required for trackback API!")); + +xoops_load("XoopsUserUtility"); +$moduleHandler = xoops_gethandler('module'); +$commentHandler = xoops_gethandler('comment'); +$itemsHandler = xoops_getmodulehandler('items', 'pingtrax'); +$item = $itemsHandler->getByReferer($_GET['referer']); + +if (!is_a($item, "PingtraxItems")) + die($trackback->recieve(false, $_GET['referer'] . " does not match any recorded item on the trackback API!")); + +$url = $_REQUEST["url"]; +if ($url) { + $excerpt = $_REQUEST["excerpt"]; + $name = ($_REQUEST["blog_name"]) ? $_REQUEST["blog_name"] : $url; + $subject = ($_REQUEST["title"]) ? $_REQUEST["title"] : $url; + $comment = "<strong> TrackBack from <a href=\"$url\">$name</a>:</strong><br />"; + $comment .= "<blockquote>$excerpt</blockquote>"; + + $pluginHandler = xoops_getmodulehandler('plugins', 'pingtrax'); + $remoteitem = $pluginHandler->getRemoteObject($item, $url, $name, $subject, $comment); + if (is_a($remoteitem, "PingtraxItems")) + { + $comment = $commentHandler->create(); + $comment->setVar('com_modid', $moduleHandler->getByDirname('pingtrax')->getVar('mid')); + $comment->setVar('com_title', $subject); + $comment->setVar('com_text', $comment); + $comment->setVar('com_created', time()); + $comment->setVar('com_url', $url); + $comment->setVar('com_ip', XoopsUserUtility::getIP(true)); + $comment->setVar('com_itemid', $item->getVar('id')); + $comment->setVar('dohtml', true); + $comment->setVar('dosmiley', true); + $comment->setVar('doxcode', true); + $comment->setVar('doimage', true); + $comment->setVar('dobr', true); + $commentHandler->insert($comment); + } +} else { + die($trackback->recieve(false, "Missing URL for trackback API!")); +} +die($trackback->recieve(true, "")); Added: XoopsModules/pingtrax/trunk/modules/pingtrax/blocks/index.html =================================================================== --- XoopsModules/pingtrax/trunk/modules/pingtrax/blocks/index.html (rev 0) +++ XoopsModules/pingtrax/trunk/modules/pingtrax/blocks/index.html 2015-12-07 14:25:21 UTC (rev 13180) @@ -0,0 +1 @@ + <script>history.go(-1);</script> \ No newline at end of file Property changes on: XoopsModules/pingtrax/trunk/modules/pingtrax/blocks/index.html ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Added: XoopsModules/pingtrax/trunk/modules/pingtrax/class/index.html =================================================================== --- XoopsModules/pingtrax/trunk/modules/pingtrax/class/index.html (rev 0) +++ XoopsModules/pingtrax/trunk/modules/pingtrax/class/index.html 2015-12-07 14:25:21 UTC (rev 13180) @@ -0,0 +1 @@ + <script>history.go(-1);</script> \ No newline at end of file Property changes on: XoopsModules/pingtrax/trunk/modules/pingtrax/class/index.html ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Added: XoopsModules/pingtrax/trunk/modules/pingtrax/class/items.php =================================================================== --- XoopsModules/pingtrax/trunk/modules/pingtrax/class/items.php (rev 0) +++ XoopsModules/pingtrax/trunk/modules/pingtrax/class/items.php 2015-12-07 14:25:21 UTC (rev 13180) @@ -0,0 +1,242 @@ +<?php +/** + * Pingtrax Database Class Handler 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 Chronolabs Cooperative http://sourceforge.net/projects/chronolabs/ + * @license GNU GPL 3 (http://labs.coop/briefs/legal/general-public-licence/13,3.html) + * @author Simon Antony Roberts <wis...@us...> + * @see http://sourceforge.net/projects/xoops/ + * @see http://sourceforge.net/projects/chronolabs/ + * @see http://sourceforge.net/projects/chronolabsapi/ + * @see http://labs.coop + * @version 1.0.1 + * @since 1.0.1 + */ + + +/** + * Class PingtraxItems + * + * @subpackage pingtrax + * + * Database MySQL Table:- + * + * CREATE TABLE `pingtrax_items` ( + * `id` mediumint(20) NOT NULL AUTO_INCREMENT, + * `parent-id` mediumint(20) NOT NULL DEFAULT '0', + * `referer` varchar(44) NOT NULL DEFAULT '', + * `type` enum('local','remote','unknown') NOT NULL DEFAULT 'unknown', + * `module-dirname` varchar(30) NOT NULL DEFAULT '', + * `module-class` varchar(100) NOT NULL DEFAULT '', + * `module-item-id` mediumint(30) NOT NULL DEFAULT '0', + * `module-php-self` varchar(150) NOT NULL DEFAULT '', + * `module-get` tinytext, + * `item-author-uid` int(13) NOT NULL DEFAULT '0', + * `item-author-name` varchar(64) NOT NULL DEFAULT '', + * `item-category-id` int(20) NOT NULL DEFAULT '0', + * `item-title` varchar(180) NOT NULL DEFAULT '', + * `item-description` varchar(250) NOT NULL DEFAULT '', + * `item-protocol` enum('https://','http://') NOT NULL DEFAULT 'http://', + * `item-domain` varchar(150) NOT NULL DEFAULT '', + * `item-referer-uri` varchar(250) NOT NULL DEFAULT '', + * `item-php-self` varchar(250) NOT NULL DEFAULT '', + * `feed-protocol` enum('https://','http://') NOT NULL DEFAULT 'http://', + * `feed-domain` varchar(150) NOT NULL DEFAULT '', + * `feed-referer-uri` varchar(250) NOT NULL DEFAULT '', + * `discovery-hook` enum('php','preloader','smarty','combination','unknown') NOT NULL DEFAULT 'unknown', + * `user-session` enum('admin','user','guest','unknown') NOT NULL DEFAULT 'unknown', + * `created` int(12) NOT NULL DEFAULT '0', + * `updated` int(12) NOT NULL DEFAULT '0', + * `offlined` int(12) NOT NULL DEFAULT '0', + * PRIMARY KEY (`id`), + * KEY `SEARCH` (`referer`,`item-author-uid`,`item-author-name`,`module-dirname`,`item-protocol`,`item-domain`,`item-referer-uri`,`module-php-self`,`item-php-self`,`discovery-hook`,`id`) KEY_BLOCK_SIZE=128, + * KEY `CHRONOLOGISTICS` (`id`,`referer`,`created`,`updated`,`offlined`) USING BTREE KEY_BLOCK_SIZE=64 + * ) ENGINE=InnoDB DEFAULT CHARSET=utf8 PACK_KEYS=1 DELAY_KEY_WRITE=1 ROW_FORMAT=DYNAMIC KEY_BLOCK_SIZE=16; + */ +class PingtraxItems extends XoopsObject +{ + /** + * + * @var unknown + */ + var $_configs = array(); + + /** + * + */ + function __construct() + { + $moduleHandler = xoops_gethandler('module'); + $configHandler = xoops_gethandler('config'); + $this->_configs = $configHandler->getConfigList($moduleHandler->getByDirname(basename(dirname(__DIR__)))->getVar('mid')); + + $this->XoopsObject(); + $this->initVar('id', XOBJ_DTYPE_INT, null, false); + $this->initVar('parent-id', XOBJ_DTYPE_INT, null, false); + $this->initVar('referer', XOBJ_DTYPE_OTHER, sha1(NULL), false, 44); + $this->initVar('type', XOBJ_DTYPE_ENUM, 'unknown', true, false, false, false, array('local','remote','unknown')); + $this->initVar('module-dirname', XOBJ_DTYPE_OTHER, '', false, 30); + $this->initVar('module-class', XOBJ_DTYPE_OTHER, '', false, 100); + $this->initVar('module-item-id', XOBJ_DTYPE_INT, 0, false); + $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, '', false, 64); + $this->initVar('item-category-id', XOBJ_DTYPE_INT, null, false); + $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); + $this->initVar('item-php-self', XOBJ_DTYPE_TXTBOX, str_replace(XOOPS_ROOT_PATH, "", $_SERVER["PHP_SELF"]), true, 250); + $this->initVar('feed-protocol', XOBJ_DTYPE_ENUM, parse_url(str_replace("%xoops_url%", XOOPS_URL, $this->_configs['default_feed_url']), PHP_URL_SCHEME), true, false, false, false, array('https://','http://')); + $this->initVar('feed-domain', XOBJ_DTYPE_TXTBOX, parse_url(str_replace("%xoops_url%", XOOPS_URL, $this->_configs['default_feed_url']), PHP_URL_HOST), true, 150); + $this->initVar('feed-referer-uri', XOBJ_DTYPE_TXTBOX, parse_url(str_replace("%xoops_url%", XOOPS_URL, $this->_configs['default_feed_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('created', XOBJ_DTYPE_INT, 0, false); + $this->initVar('updated', XOBJ_DTYPE_INT, 0, false); + $this->initVar('offline', XOBJ_DTYPE_INT, 0, false); + } + + /** + * + * @return string + */ + function getPingXML() + { + $xml = "<?xml version=\"1.0\"?>\n"; + $xml .= "<methodCall>\n"; + $xml .= "\t<methodName>weblogUpdates.extendedPing</methodName>\n"; + $xml .= "\t<params>\n"; + $xml .= "\t\t<param>\n"; + $xml .= "\t\t\t<value>".$this->getVar('item-title')."</value>\n"; + $xml .= "\t\t</param>\n"; + $xml .= "\t\t<param>\n"; + $xml .= "\t\t\t<value>".$this->getVar('item-protocol').$this->getVar('item-domain')."</value>\n"; + $xml .= "\t\t</param>\n"; + $xml .= "\t\t<param>\n"; + $xml .= "\t\t\t<value>".$this->getVar('item-protocol').$this->getVar('item-domain').$this->getVar('item-referer-uri')."</value>\n"; + $xml .= "\t\t</param>\n"; + $xml .= "\t\t<param>\n"; + $xml .= "\t\t\t<value>".$this->getVar('feed-protocol').$this->getVar('feed-domain').$this->getVar('feed-referer-uri')."</value>\n"; + $xml .= "\t\t</param>\n"; + $xml .= "\t</params>\n"; + $xml .= "</methodCall>"; + return $xml; + } +} + +/** + * Class PingtraxItemsHandler + */ +class PingtraxItemsHandler extends XoopsPersistableObjectHandler +{ + + /** + * @param null|object $db + */ + function __construct(&$db) + { + parent::__construct($db, "pingtrax_items", 'PingtraxItems', 'id', 'referer'); + } + + + function insert($object = NULL, $force = true) + { + if ($object->isNew()) + { + $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; + } + if ($object->getVar('type') == 'local') + { + $sitemapsHandler = xoops_getmodulehandler('sitemaps', 'pingtrax'); + $criteria = new CriteriaCompo(new Criteria('protocol', XOOPS_PROT)); + $criteria->add(new Criteria('domain', parse_url(XOOPS_URL, PHP_URL_HOST))); + $criteria->add(new Criteria('baseurl', parse_url(XOOPS_URL, PHP_URL_PATH))); + if ($sitemapsHandler->getCount($criteria)==0) + { + $sitemap = $sitemapsHandler->create(); + $sitemap->setVar('referer', md5(XOOPS_URL.microtime(true).XOOPS_DB_USER.XOOPS_DB_PASS)); + $sitemap->setVar('protocol', XOOPS_PROT); + $sitemap->setVar('domain', parse_url(XOOPS_URL, PHP_URL_HOST)); + $sitemap->setVar('baseurl', parse_url(XOOPS_URL, PHP_URL_PATH)); + $sitemap->setVar('filename', 'sitemap.'.str_replace("://", "", XOOPS_PROT) . "." . parse_url(XOOPS_URL, PHP_URL_HOST) . '.xml'); + $sitemap = $sitemapsHandler->get($sitemap = $sitemapsHandler->insert($sitemap, true)); + } else { + $obj = $sitemapsHandler->getObjects($criteria, false); + if (is_object($obj[0])) + $sitemap = $obj[0]; + } + $items_sitemapsHandler = xoops_getmodulehandler('items_sitemaps', 'pingtrax'); + $itemsitemap = $items_sitemapsHandler->create(); + $itemsitemap->setVar('map-referer', $sitemap->getVar('referer')); + $itemsitemap->setVar('item-referer', $object->getVar('referer')); + $items_sitemapsHandler->insert($itemsitemap, true); + $items_pingsHandler = xoops_getmodulehandler('items_pings', 'pingtrax'); + $pingsHandler = xoops_getmodulehandler('pings', 'pingtrax'); + $criteria = new CriteriaCompo(new Criteria('type', 'XML-RPC')); + $criteria->add(new Criteria('offline', 0)); + foreach($pingsHandler->getObjects($criteria, true) as $id => $ping) + { + $itemping = $items_pingsHandler->create(); + $itemping->setVar('ping-referer', $ping->getVar('referer')); + $itemping->setVar('item-referer', $object->getVar('referer')); + $items_pingsHandler->insert($itemping, true); + } + } + } else { + $object->setVar('updated', time()); + } + switch ($object->getVar('user-session')) + { + default: + case 'unknown': + if (is_object($GLOBALS['xoopsUser'])) + { + if ($GLOBALS['xoopsUser']->isAdmin()) + $object->setVar('user-session', 'admin'); + } + case 'admin': + if (is_object($GLOBALS['xoopsUser'])) + { + if (!$GLOBALS['xoopsUser']->isAdmin()) + $object->setVar('user-session', 'user'); + } + case 'user': + if (!is_object($GLOBALS['xoopsUser'])) + $object->setVar('user-session', 'guest'); + case 'guest': + break; + } + return parent::insert($object, $force); + } + + function getByReferer($referer = '') + { + $criteria = new CriteriaCompo(new Criteria('referer', $referer)); + $criteria->add(new Criteria('offline', 0)); + if ($this->getCount($criteria)==0) + return NULL; + $objs = $this->getObjects($criteria, false); + if (isset($objs[0]) && is_a($objs[0], "PingtraxItems")) + return $objs[0]; + return NULL; + } +} Added: XoopsModules/pingtrax/trunk/modules/pingtrax/class/items_pings.php =================================================================== --- XoopsModules/pingtrax/trunk/modules/pingtrax/class/items_pings.php (rev 0) +++ XoopsModules/pingtrax/trunk/modules/pingtrax/class/items_pings.php 2015-12-07 14:25:21 UTC (rev 13180) @@ -0,0 +1,73 @@ +<?php +/** + * Pingtrax Database Class Handler 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 Chronolabs Cooperative http://sourceforge.net/projects/chronolabs/ + * @license GNU GPL 3 (http://labs.coop/briefs/legal/general-public-licence/13,3.html) + * @author Simon Antony Roberts <wis...@us...> + * @see http://sourceforge.net/projects/xoops/ + * @see http://sourceforge.net/projects/chronolabs/ + * @see http://sourceforge.net/projects/chronolabsapi/ + * @see http://labs.coop + * @version 1.0.1 + * @since 1.0.1 + */ + + +/** + * Class PingtraxItems_pings + * + * @subpackage itemtrax + * + * Database MySQL Table:- + * + * CREATE TABLE `pingtrax_items_pings` ( + * `id` mediumint(32) NOT NULL AUTO_INCREMENT, + * `ping-referer` varchar(44) NOT NULL DEFAULT '', + * `item-referer` varchar(44) NOT NULL DEFAULT '', + * `when` int(12) NOT NULL DEFAULT '0', + * PRIMARY KEY (`id`), + * KEY `SEARCH` (`id`,`ping-referer`,`item-referer`) USING BTREE, + * KEY `CHRONOLOGISTICS` (`ping-referer`,`item-referer`,`when`) USING BTREE KEY_BLOCK_SIZE=64 + * ) ENGINE=InnoDB DEFAULT CHARSET=utf8 PACK_KEYS=1 CHECKSUM=1 DELAY_KEY_WRITE=1 ROW_FORMAT=DYNAMIC KEY_BLOCK_SIZE=8; + * + */ +class PingtraxItems_pings extends XoopsObject +{ + /** + * + */ + function __construct() + { + $this->XoopsObject(); + $this->initVar('id', XOBJ_DTYPE_INT, null, false); + $this->initVar('ping-referer', XOBJ_DTYPE_TXTBOX, null, true, 44); + $this->initVar('item-referer', XOBJ_DTYPE_TXTBOX, null, true, 44); + $this->initVar('when', XOBJ_DTYPE_INT, 0, false); + } + +} + +/** + * Class PingtraxItems_pingsHandler + */ +class PingtraxItems_pingsHandler extends XoopsPersistableObjectHandler +{ + + /** + * @param null|object $db + */ + function __construct(&$db) + { + parent::__construct($db, "pingtrax_items_pings", 'PingtraxItems_pings', 'id', 'ping-referer'); + } + + +} Added: XoopsModules/pingtrax/trunk/modules/pingtrax/class/items_sitemaps.php =================================================================== --- XoopsModules/pingtrax/trunk/modules/pingtrax/class/items_sitemaps.php (rev 0) +++ XoopsModules/pingtrax/trunk/modules/pingtrax/class/items_sitemaps.php 2015-12-07 14:25:21 UTC (rev 13180) @@ -0,0 +1,353 @@ +<?php +/** + * Pingtrax Database Class Handler 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 Chronolabs Cooperative http://sourceforge.net/projects/chronolabs/ + * @license GNU GPL 3 (http://labs.coop/briefs/legal/general-public-licence/13,3.html) + * @author Simon Antony Roberts <wis...@us...> + * @see http://sourceforge.net/projects/xoops/ + * @see http://sourceforge.net/projects/chronolabs/ + * @see http://sourceforge.net/projects/chronolabsapi/ + * @see http://labs.coop + * @version 1.0.1 + * @since 1.0.1 + */ + +require_once __DIR__ . DIRECTORY_SEPARATOR . 'simple_html_dom.php'; + +/** + * Class PingtraxItems_sitemaps + * + * @subpackage itemtrax + * + * Database MySQL Table:- + * + * CREATE TABLE `pingtrax_items_sitemaps` ( + * `id` mediumint(32) NOT NULL AUTO_INCREMENT, + * `map-referer` varchar(44) NOT NULL DEFAULT '', + * `item-referer` varchar(44) NOT NULL DEFAULT '', + * `frequency` enum('monthly','fortnightly','weekly','daily') NOT NULL DEFAULT 'monthly', + * `priority` float(2,1) NOT NULL DEFAULT '0.9', + * `checking` int(12) NOT NULL DEFAULT '0', + * `changed` int(12) NOT NULL DEFAULT '0', + * `changes` int(12) NOT NULL DEFAULT '0', + * `when` int(12) NOT NULL DEFAULT '0', + * `header-md5` varchar(32) NOT NULL DEFAULT '0', + * `header-changes` int(12) NOT NULL DEFAULT '0', + * `header-changed` int(12) NOT NULL DEFAULT '0', + * `header-bytes` int(12) NOT NULL DEFAULT '0', + * `body-md5` varchar(32) NOT NULL DEFAULT '0', + * `body-changes` int(12) NOT NULL DEFAULT '0', + * `body-changed` int(12) NOT NULL DEFAULT '0', + * `body-bytes` int(12) NOT NULL DEFAULT '0', + * `tabled-md5` varchar(32) NOT NULL DEFAULT '0', + * `tabled-changes` int(12) NOT NULL DEFAULT '0', + * `tabled-changed` int(12) NOT NULL DEFAULT '0', + * `tabled-bytes` int(12) NOT NULL DEFAULT '0', + * `dived-md5` varchar(32) NOT NULL DEFAULT '0', + * `dived-changes` int(12) NOT NULL DEFAULT '0', + * `dived-changed` int(12) NOT NULL DEFAULT '0', + * `dived-bytes` int(12) NOT NULL DEFAULT '0', + * `header-md5-last` varchar(32) NOT NULL DEFAULT '0', + * `header-changes-last` int(12) NOT NULL DEFAULT '0', + * `header-changed-last` int(12) NOT NULL DEFAULT '0', + * `header-bytes-last` int(12) NOT NULL DEFAULT '0', + * `body-md5-last` varchar(32) NOT NULL DEFAULT '0', + * `body-changes-last` int(12) NOT NULL DEFAULT '0', + * `body-changed-last` int(12) NOT NULL DEFAULT '0', + * `body-bytes-last` int(12) NOT NULL DEFAULT '0', + * `tabled-md5-last` varchar(32) NOT NULL DEFAULT '0', + * `tabled-changes-last` int(12) NOT NULL DEFAULT '0', + * `tabled-changed-last` int(12) NOT NULL DEFAULT '0', + * `tabled-bytes-last` int(12) NOT NULL DEFAULT '0', + * `dived-md5-last` varchar(32) NOT NULL DEFAULT '0', + * `dived-changes-last` int(12) NOT NULL DEFAULT '0', + * `dived-changed-last` int(12) NOT NULL DEFAULT '0', + * `dived-bytes-last` int(12) NOT NULL DEFAULT '0', + * PRIMARY KEY (`id`), + * KEY `SEARCH` (`id`,`map-referer`,`item-referer`) USING BTREE, + * KEY `CHRONOLOGISTICS` (`map-referer`,`item-referer`) USING BTREE KEY_BLOCK_SIZE=64 + * ) ENGINE=InnoDB DEFAULT CHARSET=utf8 PACK_KEYS=1 CHECKSUM=1 DELAY_KEY_WRITE=1 ROW_FORMAT=DYNAMIC KEY_BLOCK_SIZE=8; + * + */ +class PingtraxItems_sitemaps extends XoopsObject +{ + /** + * + */ + function __construct() + { + $this->XoopsObject(); + $this->initVar('id', XOBJ_DTYPE_INT, null, false); + $this->initVar('map-referer', XOBJ_DTYPE_TXTBOX, null, true, 44); + $this->initVar('item-referer', XOBJ_DTYPE_TXTBOX, null, true, 44); + $this->initVar('frequency', XOBJ_DTYPE_ENUM, 'daily', false, false, false, false, false, array('monthly','fortnightly','weekly','daily')); + $this->initVar('priority', XOBJ_DTYPE_FLOAT, 0.9, false); + $this->initVar('checking', XOBJ_DTYPE_INT, time(), false); + $this->initVar('changed', XOBJ_DTYPE_INT, time(), false); + $this->initVar('changes', XOBJ_DTYPE_INT, 0, false); + $this->initVar('when', XOBJ_DTYPE_INT, time(), false); + $this->initVar('header-md5', XOBJ_DTYPE_OTHER, md5(NULL), false, 32); + $this->initVar('header-changes', XOBJ_DTYPE_INT, 0, false); + $this->initVar('header-changed', XOBJ_DTYPE_INT, time(), false); + $this->initVar('header-bytes', XOBJ_DTYPE_INT, 0, false); + $this->initVar('body-md5', XOBJ_DTYPE_OTHER, md5(NULL), false, 32); + $this->initVar('body-changes', XOBJ_DTYPE_INT, 0, false); + $this->initVar('body-changed', XOBJ_DTYPE_INT, time(), false); + $this->initVar('body-bytes', XOBJ_DTYPE_INT, 0, false); + $this->initVar('tabled-md5', XOBJ_DTYPE_OTHER, md5(NULL), false, 32); + $this->initVar('tabled-changes', XOBJ_DTYPE_INT, 0, false); + $this->initVar('tabled-changed', XOBJ_DTYPE_INT, time(), false); + $this->initVar('tabled-bytes', XOBJ_DTYPE_INT, 0, false); + $this->initVar('dived-md5', XOBJ_DTYPE_OTHER, md5(NULL), false, 32); + $this->initVar('dived-changes', XOBJ_DTYPE_INT, 0, false); + $this->initVar('dived-changed', XOBJ_DTYPE_INT, time(), false); + $this->initVar('dived-bytes', XOBJ_DTYPE_INT, 0, false); + $this->initVar('header-md5-last', XOBJ_DTYPE_OTHER, md5(NULL), false, 32); + $this->initVar('header-changes-last', XOBJ_DTYPE_INT, 0, false); + $this->initVar('header-changed-last', XOBJ_DTYPE_INT, time(), false); + $this->initVar('header-bytes-last', XOBJ_DTYPE_INT, 0, false); + $this->initVar('body-md5-last', XOBJ_DTYPE_OTHER, md5(NULL), false, 32); + $this->initVar('body-changes-last', XOBJ_DTYPE_INT, 0, false); + $this->initVar('body-changed-last', XOBJ_DTYPE_INT, time(), false); + $this->initVar('body-bytes-last', XOBJ_DTYPE_INT, 0, false); + $this->initVar('tabled-md5-last', XOBJ_DTYPE_OTHER, md5(NULL), false, 32); + $this->initVar('tabled-changes-last', XOBJ_DTYPE_INT, 0, false); + $this->initVar('tabled-changed-last', XOBJ_DTYPE_INT, time(), false); + $this->initVar('tabled-bytes-last', XOBJ_DTYPE_INT, 0, false); + $this->initVar('dived-md5-last', XOBJ_DTYPE_OTHER, md5(NULL), false, 32); + $this->initVar('dived-changes-last', XOBJ_DTYPE_INT, 0, false); + $this->initVar('dived-changed-last', XOBJ_DTYPE_INT, time(), false); + $this->initVar('dived-bytes-last', XOBJ_DTYPE_INT, 0, false); + } + + /** + * + */ + function checkForChanges() + { + $changes = 0; + $itemsHandler = xoops_getmodulehandler('items', 'pingtrax'); + $item = $itemsHandler->getByReferer($this->getVar('item-referer')); + if (is_a($item, "PingtraxItems")) + { + $html = $this->getURIData($item->getVar('item-protocol').$item->getVar('item-domain').$item->getVar('item-referer-uri'), 65, 65, $item->getVar('module-get')); + if (strlen($html)==0) + { + foreach($item->getVar('module-get') as $item => $value) + $get[$item] = $value; + $html = $this->getURIData($item->getVar('item-protocol').$item->getVar('item-domain').$item->getVar('item-php-self')."?".http_build_query($get), 65, 65, $get); + } + if (strlen($html)!=0) + { + $dom = str_get_html($html); + // Does headers + $head = $dom->find("head"); + $changes .+ $this->setVars(array('header-md5' => md5($head->innertext), 'header-bytes' => strlen($head->innertext))); + // Does Full Body + $body = $dom->find("body"); + $changes .+ $this->setVars(array('body-md5' => md5($body->plaintext), 'body-bytes' => strlen($body->plaintext))); + // Does Tables + $tablesbytes = 0; + $tablesmd5 = ''; + foreach($dom->find('table') as $table) + { + $tablesmd5 = md5($tablesmd5 . sha1($table->plaintext)); + $tablesbytes = $tablesbytes + strlen($table->plaintext); + } + $changes .+ $this->setVars(array('tabled-md5' => $tablesmd5, 'tabled-bytes' => $tablesbytes)); + // Does Div's + $divsbytes = 0; + $divsmd5 = ''; + foreach($dom->find('div') as $div) + { + $divsmd5 = md5($divsmd5 . sha1($div->plaintext)); + $divsbytes = $divsbytes + strlen($div->plaintext); + } + $changes .+ $this->setVars(array('dived-md5' => $divsmd5, 'dived-bytes' => $divsbytes)); + } + } + return $changes; + } + + /** + * + * {@inheritDoc} + * @see XoopsObject::setVars() + */ + function setVars($var_arr = array()) + { + $changes = 0; + $lasting = array('header' => array('-md5', '-bytes'), 'body' => array('-md5', '-bytes'), 'tabled' => array('-md5', '-bytes'), 'dived' => array('-md5', '-bytes')); + foreach($lasting as $key=> $values) + { + $found = false; + foreach($values as $value) + if (in_array($key.$value, array_keys($var_arr))) + { + if ($this->getVar($key.$value)!=$var_arr[$key.$value]) + foreach($values as $val) + $this->setVar($key.$val.'-last', $this->getVar($key.$val)); + $found = true; + } + if ($found == true) + { + $changes .+ 1; + $this->setVar($key.'-changes', $this->getVar($key.'-changes')+1); + $this->setVar($key.'-changed', time()); + if ($this->getVar('changed')>0) + { + if (time() - $this->getVar('changed') < (3600 * 24)) + { + $this->setvar('frequency', 'daily'); + } elseif (time() - $this->getVar('changed') < (3600 * 24 * 7)) + { + $this->setvar('frequency', 'weekly'); + } elseif (time() - $this->getVar('changed') < (3600 * 24 * 14)) + { + $this->setvar('frequency', 'fortnightly'); + } else { + $this->setvar('frequency', 'monthly'); + } + } else + $this->setvar('frequency', 'daily'); + $this->setVar('changed', time()); + $this->setVar('changes', $this->getVar('changes')+1); + if ($this->getvar('priority') < 0.9) + $this->setVar('priority', $this->getVar('priority') + 0.1); + } else { + if ($this->getVar('changed')>0) + { + if (time() - $this->getVar('changed') < (3600 * 24)) + { + $this->setvar('frequency', 'daily'); + } elseif (time() - $this->getVar('changed') < (3600 * 24 * 7)) + { + $this->setvar('frequency', 'weekly'); + } elseif (time() - $this->getVar('changed') < (3600 * 24 * 14)) + { + $this->setvar('frequency', 'fortnightly'); + } else { + $this->setvar('frequency', 'monthly'); + } + } else { + $this->setvar('frequency', 'daily'); + $this->setVar('changed', time()); + } + if ($this->getvar('frequency')=='') + $this->setvar('frequency', 'daily'); + if ($this->getvar('priority') > 0.1) + $this->setVar('priority', $this->getVar('priority') - 0.1); + } + } + + switch($this->getVar('frequency')) + { + case 'daily': + default: + $this->setvar('frequency', 'daily'); + $this->setVar('checking', time() + (3600 * 24 - 900)); + break; + case 'weekly': + $this->setVar('checking', time() + (3600 * 24 * 7 - 900)); + break; + case 'fortnightly': + $this->setVar('checking', time() + (3600 * 24 * 14 - 900)); + break; + case 'monthly': + $this->setVar('checking', time() + (3600 * 24 * 7 * 4 - 900)); + break; + } + parent::setVars($var_arr); + return ($changes>0?$changes:false); + } + + + /* function getURIData() + * + * cURL Routine + * @author Simon Roberts (Chronolabs) si...@la... + * + * @return float() + */ + private function getURIData($uri = '', $timeout = 65, $connectout = 65, $post_data = array()) + { + if (!function_exists("curl_init")) + { + return file_get_contents($uri); + } + if (!$btt = curl_init($uri)) { + return false; + } + curl_setopt($btt, CURLOPT_HEADER, 0); + curl_setopt($btt, CURLOPT_POST, (count($posts)==0?false:true)); + if (count($posts)!=0) + curl_setopt($btt, CURLOPT_POSTFIELDS, http_build_query($post_data)); + curl_setopt($btt, CURLOPT_CONNECTTIMEOUT, $connectout); + curl_setopt($btt, CURLOPT_TIMEOUT, $timeout); + curl_setopt($btt, CURLOPT_RETURNTRANSFER, true); + curl_setopt($btt, CURLOPT_VERBOSE, false); + curl_setopt($btt, CURLOPT_SSL_VERIFYHOST, false); + curl_setopt($btt, CURLOPT_SSL_VERIFYPEER, false); + $data = curl_exec($btt); + curl_close($btt); + return $data; + } + + +} + +/** + * Class PingtraxItems_sitemapsHandler + */ +class PingtraxItems_sitemapsHandler extends XoopsPersistableObjectHandler +{ + + /** + * @param null|object $db + */ + function __construct(&$db) + { + parent::__construct($db, "itemtrax_items_sitemaps", 'PingtraxItems_sitemaps', 'id', 'map-referer'); + } + + + /** + * + * @param array $array + */ + private function addTimeLimit($seconds = 30) + { + global $timelimit; + $timelimit .+ $seconds; + set_time_limit($timelimit); + } + + /** + * + * @param string $mapreferer + */ + function checkForChanges($mapreferer = '') + { + $changes = 0; + $this->addTimeLimit(120); + $criteria = new CriteriaCompo(new Criteria('checking', time(), "<=")); + if (!empty($mapreferer)) + $criteria->add(new Criteria('map-referer', $mapreferer)); + foreach($this->getObjects($criteria, true) as $id => $item) + { + $start = microtime(true); + if (is_a($item, "PingtraxItems_sitemaps")) + $changes = $changes + $item->checkForChanges(); + $this->addTimeLimit(microtime(true)-$start+5); + } + return $changes; + } +} Added: XoopsModules/pingtrax/trunk/modules/pingtrax/class/pings.php =================================================================== --- XoopsModules/pingtrax/trunk/modules/pingtrax/class/pings.php (rev 0) +++ XoopsModules/pingtrax/trunk/modules/pingtrax/class/pings.php 2015-12-07 14:25:21 UTC (rev 13180) @@ -0,0 +1,252 @@ +<?php +/** + * Pingtrax Database Class Handler 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 Chronolabs Cooperative http://sourceforge.net/projects/chronolabs/ + * @license GNU GPL 3 (http://labs.coop/briefs/legal/general-public-licence/13,3.html) + * @author Simon Antony Roberts <wis...@us...> + * @see http://sourceforge.net/projects/xoops/ + * @see http://sourceforge.net/projects/chronolabs/ + * @see http://sourceforge.net/projects/chronolabsapi/ + * @see http://labs.coop + * @version 1.0.1 + * @since 1.0.1 + */ + + +/** + * Class PingtraxPings + * + * @subpackage pingtrax + * + * Database MySQL Table:- + * + * CREATE TABLE `pingtrax_pings` ( + * `id` int(14) NOT NULL AUTO_INCREMENT, + * `referer` varchar(44) NOT NULL DEFAULT '', + * `type` enum('XML-RPC','SITEMAPS') NOT NULL DEFAULT 'XML-RPC', + * `uri` varchar(250) NOT NULL DEFAULT '', + * `last-item-referer` varchar(44) NOT NULL DEFAULT '', + * `successful-pings` int(18) NOT NULL DEFAULT '0', + * `failed-pings` int(18) NOT NULL DEFAULT '0', + * `sleep-till` int(12) NOT NULL DEFAULT '0', + * `success-time` int(12) NOT NULL DEFAULT '0', + * `failure-time` int(12) NOT NULL DEFAULT '0', + * `created` int(12) NOT NULL DEFAULT '0', + * `updated` int(12) NOT NULL DEFAULT '0', + * `offlined` int(12) NOT NULL DEFAULT '0', + * PRIMARY KEY (`id`,`referer`,`type`,`uri`), + * KEY `SEARCH` (`referer`,`type`,`uri`,`last-item-referer`,`successful-pings`,`failed-pings`,`id`) USING BTREE, + * KEY `CHRONOLOGISTICS` (`id`,`referer`,`created`,`updated`,`offlined`,`failure-time`,`success-time`,`sleep-till`) USING BTREE KEY_BLOCK_SIZE=128 + * ) ENGINE=InnoDB AUTO_INCREMENT=150 DEFAULT CHARSET=utf8 PACK_KEYS=1 CHECKSUM=1 DELAY_KEY_WRITE=1 ROW_FORMAT=DYNAMIC KEY_BLOCK_SIZE=16; + * + */ +class PingtraxPings extends XoopsObject +{ + /** + * + */ + function __construct() + { + $this->XoopsObject(); + $this->initVar('id', XOBJ_DTYPE_INT, null, false); + $this->initVar('referer', XOBJ_DTYPE_OTHER, sha1(NULL), false, 44); + $this->initVar('type', XOBJ_DTYPE_ENUM, 'XML-RPC', true, false, false, false, array('XML-RPC','SITEMAPS')); + $this->initVar('uri', XOBJ_DTYPE_TXTBOX, null, true, 250); + $this->initVar('last-item-referer', XOBJ_DTYPE_OTHER, sha1(NULL), false, 44); + $this->initVar('successful-pings', XOBJ_DTYPE_INT, 0, false); + $this->initVar('failed-pings', XOBJ_DTYPE_INT, 0, false); + $this->initVar('sleep-till', XOBJ_DTYPE_INT, 0, false); + $this->initVar('success-time', XOBJ_DTYPE_INT, 0, false); + $this->initVar('failure-time', 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); + } + + /** + * + * @param PingtraxItems $item + * @return mixed + */ + function getPingURL(PingtraxItems $item) + { + $uri = $this->getVar('uri'); + $uri = str_replace(urlencode($item->getVar('item-title')), '%title', $uri); + $uri = str_replace(urlencode($item->getVar('item-decription')), '%description', $uri); + $uri = str_replace(urlencode($item->getVar('item-protocol').$item->getVar('item-domain').$item->getVar('item-referer-uri')), '%url', $uri); + $uri = str_replace(urlencode($item->getVar('feed-protocol').$item->getVar('feed-domain').$item->getVar('feed-referer-uri')), '%feed', $uri); + return $uri; + } + /** + * + * @param PingtraxItems $item + * @return mixed + */ + function getSitemapURL(PingtraxSitemaps $sitemap) + { + $uri = $this->getVar('uri'); + $uri = str_replace(urlencode($sitemap->getVar('protocol').$sitemap->getVar('domain').(strlen($sitemap->getVar('baseurl'))>1?((substr($sitemap->getVar('baseurl'),0,1)!="/"?"/":"").$sitemap->getVar('baseurl').(substr($sitemap->getVar('baseurl'),strlen($sitemap->getVar('baseurl'))-1,1)!="/"?"/":"")):"/")).$sitemap->getVar('filename'), '%url', $uri); + return $uri; + } + +} + +/** + * Class PingtraxPingsHandler + */ +class PingtraxPingsHandler extends XoopsPersistableObjectHandler +{ + /** + * + * @var unknown + */ + var $_configs = array(); + + /** + * var string URL of JSON Resource for Install + */ + var $_resource = "https://sourceforge.net/p/xoops/svn/HEAD/tree/XoopsModules/pingtrax/data/ping-resources.json?format=raw"; + + /** + * @param null|object $db + */ + function __construct(&$db) + { + $moduleHandler = xoops_gethandler('module'); + $configHandler = xoops_gethandler('config'); + $this->_configs = $configHandler->getConfigList($moduleHandler->getByDirname(basename(dirname(__DIR__)))->getVar('mid')); + + parent::__construct($db, "pingtrax_pings", 'PingtraxPings', 'id', 'referer'); + + $criteria = new Criteria('id',0,"<>"); + if ($this->getCount($criteria)==0) + { + $data = json_decode(file_get_contents($this->_resource), true); + foreach($data as $referer => $values) + { + $obj = $this->create(true); + $obj->setVar('referer', $referer); + $obj->setVar('type', $values['type']); + $obj->setVar('uri', $values['uri']); + $this->insert($obj); + } + } + } + + function insert($object = NULL, $force = true) + { + if ($object->isNew()) + { + $object->setVar('created', time()); + } else { + $object->setVar('updated', time()); + } + return parent::insert($object, $force); + } + + + function makePings($referer = '') + { + $this->addTimeLimit(120); + $items_pingsHandler = xoops_getmodulehandler('items_pings', 'pingtrax'); + $itemsHandler = xoops_getmodulehandler('items', 'pingtrax'); + $criteria = new CriteriaCompo(new Criteria('offline', 0)); + if (!empty($referer)) + $criteria->add(new Criteria('referer', $referer)); + $sleepcriteria = new CriteriaCompo(new Criteria('sleep-till', 0), 'OR'); + $sleepcriteria->add(new Criteria('sleep-till', time(), "<="), 'OR'); + $criteria->add($sleepcriteria, 'AND'); + $criteria->add(new Criteria('type', 'XML-RPC'), 'AND'); + foreach($this->getObjects($criteria, true) as $id => $ping) + { + $start = microtime(true); + $criteria = new CriteriaCompo(new Criteria('when', 0)); + $criteria->add(new Criteria('ping-referer', $ping->getVar('referer'))); + foreach($items_pingsHandler->getObjects($criteria, true) as $piid => $itemping) + { + $item = $itemsHandler->getByReferer($itemping->getVar('item-referer')); + if (is_a($item, "PingtraxItems")) + { + $context = stream_context_create(array('http' => array( + 'method' => "POST", + 'header' => "Content-Type: text/xml\r\n", + 'content' => $item->getPingXML() + ))); + $file = @file_get_contents($ping->getPingURL($item), false, $context); + if ($file === false) { + $ping->setVar('failed-pings', $this->getVar('failed-pings') + 1); + $ping->setVar('failure-time', time()); + } + elseif ($file) { + $ping->setVar('successful-pings', $this->getVar('successful-pings') + 1); + $ping->setVar('success-time', time()); + $itemping->setVar('when', time()); + $items_pingsHandler->insert($itemping, true); + } + + } + } + switch($this->_config['pings_sleep_till']) + { + case 0: + $ping->setVar('sleep-till', time() + mt_rand(600, 3600*24)); + break; + default: + $ping->setVar('sleep-till', time() + $this->_config['pings_sleep_till']); + break; + } + $this->insert($ping, true); + } + } + + + function sendSitemap(PingtraxSitemaps $sitemap) + { + $this->addTimeLimit(120); + $items_pingsHandler = xoops_getmodulehandler('items_pings', 'pingtrax'); + $itemsHandler = xoops_getmodulehandler('items', 'pingtrax'); + $criteria = new CriteriaCompo(new Criteria('offline', 0)); + if (!empty($referer)) + $criteria->add(new Criteria('referer', $referer)); + $sleepcriteria = new CriteriaCompo(new Criteria('sleep-till', 0), 'OR'); + $sleepcriteria->add(new Criteria('sleep-till', time(), "<="), 'OR'); + $criteria->add($sleepcriteria, 'AND'); + $criteria->add(new Criteria('type', 'SITEMAPS'), 'AND'); + foreach($this->getObjects($criteria, true) as $id => $ping) + { + $start = microtime(true); + if (is_a($sitemap, "PingtraxSitemaps")) + { + $file = @file_get_contents($ping->getSitemapURL($sitemap), false); + if ($file === false) { + $ping->setVar('failed-pings', $this->getVar('failed-pings') + 1); + $ping->setVar('failure-time', time()); + } + elseif ($file) { + $ping->setVar('successful-pings', $this->getVar('successful-pings') + 1); + $ping->setVar('success-time', time()); + $itemping->setVar('when', time()); + $items_pingsHandler->insert($itemping, true); + } + } + switch($this->_config['pings_sleep_till']) + { + case 0: + $ping->setVar('sleep-till', time() + mt_rand(600, 3600*24)); + break; + default: + $ping->setVar('sleep-till', time() + $this->_config['pings_sleep_till']); + break; + } + $this->insert($ping, true); + } + } +} Added: XoopsModules/pingtrax/trunk/modules/pingtrax/class/plugins.php =================================================================== --- XoopsModules/pingtrax/trunk/modules/pingtrax/class/plugins.php (rev 0) +++ XoopsModules/pingtrax/trunk/modules/pingtrax/class/plugins.php 2015-12-07 14:25:21 UTC (rev 13180) @@ -0,0 +1,520 @@ +<?php +/** + * PingTrax Constructor for Plugin's + * + * 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 Chronolabs Cooperative http://sourceforge.net/projects/chronolabs/ + * @license GNU GPL 3 (http://labs.coop/briefs/legal/general-public-licence/13,3.html) + * @author Simon Antony Roberts <wis...@us...> + * @see http://sourceforge.net/projects/xoops/ + * @see http://sourceforge.net/projects/chronolabs/ + * @see http://sourceforge.net/projects/chronolabsapi/ + * @see http://labs.coop + * @version 1.0.1 + * @since 1.0.1 + */ + +defined('XOOPS_ROOT_PATH') || die('XOOPS root path not defined'); + +/** + * Class PingtraxPlugins + */ +class PingtraxPlugins extends XoopsObject +{ + + /** + * @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')); + } + } + + /** + * + */ + function getModuleDirname() + { + if (is_a($GLOBALS['xoopsModule'], 'XoopsModule')) + { + return $GLOBALS['xoopsModule']->getVar('dirname'); + } + } + + /** + * + */ + function getModuleClass() + { + switch ($this->getModulePHPSelf()) + { + default: + + foreach(get_declared_classes() as $class) + { + if ($this->getModuleDirname() != '' && substr(strtolower($class), 0, strlen($this->getModuleDirname()))==strtolower($this->getModuleDirname()) && (!strpos(strtolower($class), 'categor') && !strpos(strtolower($this->getModulePHPSelf()), 'categor'))) + { + @$obj = new $class(); + if (is_a($obj, "XoopsPersistableObjectHandler")) + return strtolower(str_replace(array(ucfirst($this->getModuleDirname()), $this->getModuleDirname(), 'handler', 'Handler'), '', $class)); + } + } + + break; + } + } + + /** + * + */ + function getModuleItemID() + { + $id = 0; + switch ($this->getModulePHPSelf()) + { + default: + + $idnaming = explode(PHP_EOL, file_get_contents(dirname(__DIR__) . DIRECTORY_SEPARATOR . 'include' . DIRECTORY_SEPARATOR . 'item-id-names.txt')); + foreach($_GET as $key => $value) + { + if (!is_array($value)) + { + foreach($idnaming as $idname) + { + if (strpos($key, $idname) && is_numeric($_GET[$key])) + $id = $_GET[$key]; + elseif (is_numeric($_GET[$key]) && !in_array($key, explode(PHP_EOL, file_get_contents(dirname(__DIR__) . DIRECTORY_SEPARATOR . 'include' . DIRECTORY_SEPARATOR . 'exclude-names.txt')))) + $id = $_GET[$key]; + } + } + } + } + return $id; + } + + /** + * + */ + function getModulePHPSelf() + { + $parts = explode(DIRECTORY_SEPARATOR, $this->getItemPHPSelf()); + $found = false; + foreach($parts as $id => $value) + { + if ($found == false) + unset($parts[$id]); + if ($value == 'modules') + $found = true; + } + return implode(DIRECTORY_SEPARATOR, $parts); + } + + /** + * + */ + function getModuleGet() + { + return $_GET; + } + + + /** + * + */ + function getItemCategoryID() + { + $id = 0; + switch ($this->getModulePHPSelf()) + { + default: + + $idnaming = explode(PHP_EOL, file_get_contents(dirname(__DIR__) . DIRECTORY_SEPARATOR . 'include' . DIRECTORY_SEPARATOR . 'category-id-names.txt')); + foreach($_GET as $key => $value) + { + if (!is_array($value)) + { + foreach($idnaming as $idname) + { + if (strpos($key, $idname) && is_numeric($_GET[$key])) + $id = $_GET[$key]; + elseif ($id = 0 && is_numeric($_GET[$key]) && !in_array($key, explode(PHP_EOL, file_get_contents(dirname(__DIR__) . DIRECTORY_SEPARATOR . 'include' . DIRECTORY_SEPARATOR . 'exclude-names.txt')))) + $id = $_GET[$key]; + } + } + } + } + return $id; + } + + /** + * + */ + function getItemProtocol() + { + return strtolower(XOOPS_PROT); + } + + /** + * + */ + function getItemDomain() + { + return parse_url(strtolower(XOOPS_URL), PHP_URL_HOST); + } + + /** + * + */ + function getItemRefererURI() + { + return $_SERVER["REQUEST_URI"]; + } + + /** + * + */ + function getItemPHPSelf() + { + if (XOOPS_ROOT_PATH == substr(strtolower($_SERVER["REQUEST_URI"]), 0, strlen(XOOPS_ROOT_PATH))) + 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(str_replace("%xoops_url%", XOOPS_URL, $this->_configs['default_feed_url'])), PHP_URL_SCHEME); + } + + /** + * + */ + function getFeedDomain() + { + return parse_url(strtolower(str_replace("%xoops_url%", XOOPS_URL, $this->_configs['default_feed_url'])), PHP_URL_HOST); + } + + /** + * + */ + function getFeedRefererURI() + { + return parse_url(strtolower(str_replace("%xoops_url%", XOOPS_URL, $this->_configs['default_feed_url'])), PHP_URL_PATH) . "?" .parse_url(strtolower($this->_configs['default_feed_url']), PHP_URL_QUERY); + } + +} + + +/** + * Class PingtraxPluginsHandler + */ +class PingtraxPluginsHandler extends XoopsPersistableObjectHandler +{ + + /** + * @var string + */ + var $_default = 'default'; + + /** + * @var array + */ + var $_plugins = array(); + + /** + * @param null|object $db + */ + function __construct(&$db) + { + parent::__construct($db); + } + + + function getRemoteObject(PingtraxItems $item, $url = '', $name = '', $subject = '', $comment = '') +... [truncated message content] |