public static function instance($argHandlerKey = null) { self::$handlers = eZINI::instance('nxcsocialnetworks.ini')->variable('General', 'LinkShortenHandlers'); if ($argHandlerKey != null) { self::$handlerKey = $argHandlerKey; } else { self::$handlerKey = eZINI::instance('nxcsocialnetworks.ini')->variable('General', 'LinkShortenHandlerDefault'); } self::$handlerClassName = self::$handlers[self::$handlerKey]; if (class_exists(self::$handlerClassName)) { return new self::$handlerClassName(); } }
public function shorten($url, $handler = null) { if ($handler != null) { return nxcSocialNetworksLinkShortenHandler::instance($handler)->shorten($url); } else { return nxcSocialNetworksLinkShortenHandler::instance()->shorten($url); } }
**/ /** Script autoloads initialization **/ require 'autoload.php'; /** Script startup and initialization **/ $cli = eZCLI::instance(); $script = eZScript::instance(array('description' => "NXC Social Networks Link Shortening Service Test Script\n\n" . "nxcLinkShortenTest.php --url=https://google.com --service=goo.gl", 'use-session' => false, 'use-modules' => true, 'use-extensions' => true, 'user' => true)); $script->startup(); $options = $script->getOptions("[url;][service;][list-handlers;]", "", array('url' => 'Use this parameter to specify which url string to shorten. Example: ' . "'--url=https://google.com'" . ' is an optional parameter which defaults to string https://google.com', 'service' => 'Use this parameter to specify which url shortening service handler to use. Use the ' . "'--list-handlers'" . ' parameter for a list of handlers available. Example: ' . "'--service=goo.gl'" . ' is an optional parameter which defaults to value specified by the LinkShortenHandlerDefault ini setting ', 'list-handlers' => 'Use this parameter to display which url shortening service handlers are available for use. Example: ' . "'--list-handlers'" . ' is an optional parameter which defaults to false'), false, array('user' => true)); $script->initialize(); /** Test for required script arguments **/ $url = isset($options['url']) ? $options['url'] : 'https://google.com'; $service = isset($options['service']) && $options['service'] != '' && $options['service'] != 1 ? $options['service'] : eZINI::instance('nxcsocialnetworks.ini')->variable('General', 'LinkShortenHandlerDefault'); $listHandlers = isset($options['list-handlers']) ? true : false; /** Test to determin action to take: display handlers or shorten url **/ if ($listHandlers) { /** Dispaly a list of all url shortening service handlers available **/ $handlers = eZINI::instance('nxcsocialnetworks.ini')->variable('General', 'LinkShortenHandlers'); $cli->output("\nUrl shortening service handlers available:\n"); foreach ($handlers as $handlerNameShort => $handlerClassName) { $cli->output('Service: ' . $handlerNameShort . "\n"); } } else { /** Perform url service shorten test **/ $shortUrl = nxcSocialNetworksLinkShortenHandler::instance($service)->shorten($url); $cli->output("\nUrl shortening test complete!\n"); $cli->output('Service: ' . $service . "\n"); $cli->output('Url: ' . $url . "\n"); $cli->output('Short Url: ' . $shortUrl . "\n"); } /** Shutdown script **/ $script->shutdown();
public function attributeDecoder($event, $attr) { switch ($attr) { case 'handlers': return nxcSocialNetworksPublishHandler::fetchList($event->attribute('id')); case 'available_handler_names': if (count(self::$handlerNames) === 0) { $types = nxcSocialNetworksPublishHandler::getTypes(); foreach ($types as $type => $handlerClass) { try { $handler = new $handlerClass(array()); self::$handlerNames[$type] = $handler->attribute('name'); unset($handler); } catch (Exception $e) { } } } return self::$handlerNames; case 'available_shorten_handler_names': if (count(self::$shortenHandlerNames) === 0) { $types = nxcSocialNetworksLinkShortenHandler::getHandlers(); foreach ($types as $type => $shortenHandlerClass) { try { $shortenHandler = new $shortenHandlerClass(array()); self::$shortenHandlerNames[$type] = $shortenHandler->name; unset($shortenHandler); } catch (Exception $e) { } } } return self::$shortenHandlerNames; case 'available_message_handler_names': if (count(self::$messageHandlerNames) === 0) { $types = nxcSocialNetworksMessageHandler::getHandlers(); foreach ($types as $type => $messageHandlerClass) { try { $messageHandler = new $messageHandlerClass(array()); self::$messageHandlerNames[$type] = $messageHandler->name; unset($messageHandler); } catch (Exception $e) { } } } return self::$messageHandlerNames; case 'contentclass_attribute_list': if (count(self::$classAttributes) === 0) { $classAttributes = eZContentClassAttribute::fetchList(true, array('data_type' => array(array(eZStringType::DATA_TYPE_STRING, eZTextType::DATA_TYPE_STRING)))); // Sorting class attributes $sort = array(); $attrIDs = array(); foreach ($classAttributes as $attribute) { $class = eZContentClass::fetch($attribute->attribute('contentclass_id')); $sort[$attribute->attribute('id')] = $class->attribute('name') . $attribute->attribute('name'); $attrIDs[$attribute->attribute('id')] = $attribute; } asort($sort); self::$classAttributes = array(); foreach ($sort as $id => $sortString) { self::$classAttributes[$id] = $attrIDs[$id]; } } return self::$classAttributes; case 'affected_class_ids': return unserialize($event->attribute('data_text1')); default: return null; } }