/**
  * Retrieve the citation output filter that will be
  * used to transform citations.
  * @return TemplateBasedFilter
  */
 function getCitationOutputFilterInstance()
 {
     $citationOutputFilterName = $this->getData('citationOutputFilterName');
     assert(!is_null($citationOutputFilterName));
     list($inputTypeDescription, $outputTypeDescription) = $this->getCitationOutputFilterTypeDescriptions();
     $filterGroup = PersistableFilter::tempGroup($inputTypeDescription, $outputTypeDescription);
     return instantiate($citationOutputFilterName, 'TemplateBasedFilter', null, null, $filterGroup);
 }
Exemple #2
0
/**
 * get_callable() is used to retrieve a PHP callable from a specification.
 * 
 * P framework allows callables to be anything that passes is_callable()
 * or anything in the form "Class->method"
 *
 * @param callable|string $specification
 * @param array|\ArrayAccess $parameters
 * @return \callable
 */
function get_callable($specification, $parameters = array())
{
    if (is_callable($specification)) {
        return $specification;
    } elseif (is_instantiable($specification)) {
        return instantiate($specification, $parameters);
    }
    throw new \InvalidArgumentException('Provided specification cannot become callable');
}
 /**
  * Get the supported meta-data schema (lazy load)
  * @return MetadataSchema
  */
 function &getMetadataSchema()
 {
     // Lazy-load the meta-data schema if this has
     // not been done before.
     if (is_null($this->_metadataSchema)) {
         $this->_metadataSchema =& instantiate($this->getMetadataSchemaName(), 'MetadataSchema');
         assert(is_object($this->_metadataSchema));
     }
     return $this->_metadataSchema;
 }
Exemple #4
0
 /**
  * Retrieve a reference to the specified DAO.
  * @param $name string the class name of the requested DAO
  * @param $dbconn ADONewConnection optional
  * @return DAO
  */
 function &getDAO($name, $dbconn = null)
 {
     $daos =& DAORegistry::getDAOs();
     if (!isset($daos[$name])) {
         // Import the required DAO class.
         $application =& PKPApplication::getApplication();
         $className = $application->getQualifiedDAOName($name);
         if (!$className) {
             fatalError('Unrecognized DAO ' . $name . '!');
         }
         // Only instantiate each class of DAO a single time
         $daos[$name] =& instantiate($className, array('DAO', 'XMLDAO'));
         if ($dbconn != null) {
             $daos[$name]->setDataSource($dbconn);
         }
     }
     return $daos[$name];
 }
 /**
  * Retrieve a reference to the specified DAO.
  * @param $name string the class name of the requested DAO
  * @param $dbconn ADONewConnection optional
  * @return DAO
  */
 function &getDAO($name, $dbconn = null)
 {
     $daos =& DAORegistry::getDAOs();
     if (!isset($daos[$name])) {
         // Import the required DAO class.
         $application =& PKPApplication::getApplication();
         $className = $application->getQualifiedDAOName($name);
         if (!$className) {
             fatalError('Unrecognized DAO ' . $name . '!');
         }
         // Only instantiate each class of DAO a single time
         $daos[$name] =& instantiate($className, array('DAO', 'XMLDAO'));
         if ($dbconn != null) {
             // FIXME Needed by installer but shouldn't access member variable directly
             $daos[$name]->_dataSource = $dbconn;
         }
     }
     return $daos[$name];
 }
 /**
  * Takes a plain text type descriptor, identifies the namespace
  * and instantiates the corresponding type description object.
  *
  * @param $typeDescription string A plain text type description.
  *
  *  Type descriptions consist of two parts:
  *  * a type namespace
  *  * a type name (optionally including parameters like cardinality, etc.)
  *
  *  Example:
  *    primitive::string[5]
  *    -> namespace: primitive - type name: string[5]
  *
  *  Each namespace will be mapped to one subclass of the TypeDescription
  *  class which will then be responsible to parse the given type name.
  *
  * @return TypeDescription or null if the type description is invalid.
  */
 function &instantiateTypeDescription($typeDescription)
 {
     $nullVar = null;
     // Identify the namespace
     $typeDescriptionParts = explode('::', $typeDescription);
     if (count($typeDescriptionParts) != 2) {
         return $nullVar;
     }
     // Map the namespace to a type description class
     $typeDescriptionClass = $this->_namespaceMap($typeDescriptionParts[0]);
     if (is_null($typeDescriptionClass)) {
         return $nullVar;
     }
     // Instantiate and return the type description object
     $typeDescriptionObject =& instantiate($typeDescriptionClass, 'TypeDescription', null, null, $typeDescriptionParts[1]);
     if (!is_object($typeDescriptionObject)) {
         return $nullVar;
     }
     return $typeDescriptionObject;
 }
Exemple #7
0
 /**
  * Constructs XML_HTMLSax selecting concrete StateParser subclass
  * depending on PHP version being used as well as setting the default
  * NullHandler for all callbacks<br />
  * @access public
  */
 function XML_HTMLSax()
 {
     if (version_compare(phpversion(), '4.3', 'ge')) {
         $this->state_parser = instantiate('XML_HTMLSax_StateParser_Gtet430', $this);
     } else {
         $this->state_parser = instantiate('XML_HTMLSax_StateParser_Lt430', $this);
     }
     $nullhandler = instantiate('XML_HTMLSax_NullHandler');
     $this->set_object($nullhandler);
     $this->set_element_handler('DoNothing', 'DoNothing');
     $this->set_data_handler('DoNothing');
     $this->set_pi_handler('DoNothing');
     $this->set_jasp_handler('DoNothing');
     $this->set_escape_handler('DoNothing');
 }
 /**
  * Installs filter template entries into the filters table.
  * FIXME: Move this to plug-in installation when moving filters to plug-ins, see #5157.
  */
 function installFilterTemplates()
 {
     // Filters are supported on PHP5+ only.
     if (!checkPhpVersion('5.0.0')) {
         return true;
     }
     $filterDao =& DAORegistry::getDAO('FilterDAO');
     $filtersToBeInstalled = array('lib.pkp.classes.citation.lookup.crossref.CrossrefNlmCitationSchemaFilter', 'lib.pkp.classes.citation.lookup.pubmed.PubmedNlmCitationSchemaFilter', 'lib.pkp.classes.citation.lookup.worldcat.WorldcatNlmCitationSchemaFilter', 'lib.pkp.classes.citation.parser.freecite.FreeciteRawCitationNlmCitationSchemaFilter', 'lib.pkp.classes.citation.parser.paracite.ParaciteRawCitationNlmCitationSchemaFilter', 'lib.pkp.classes.citation.parser.parscit.ParscitRawCitationNlmCitationSchemaFilter', 'lib.pkp.classes.citation.parser.regex.RegexRawCitationNlmCitationSchemaFilter', 'lib.pkp.classes.citation.output.abnt.NlmCitationSchemaAbntFilter', 'lib.pkp.classes.citation.output.apa.NlmCitationSchemaApaFilter', 'lib.pkp.classes.citation.output.mla.NlmCitationSchemaMlaFilter', 'lib.pkp.classes.citation.output.vancouver.NlmCitationSchemaVancouverFilter', 'lib.pkp.classes.importexport.nlm.PKPSubmissionNlmXmlFilter');
     import('lib.pkp.classes.citation.output.PlainTextReferencesListFilter');
     foreach ($filtersToBeInstalled as $filterToBeInstalled) {
         // Instantiate filter.
         $filter =& instantiate($filterToBeInstalled, 'Filter');
         // Install citation output filters as non-configurable site-wide filter instances.
         if (is_a($filter, 'NlmCitationSchemaCitationOutputFormatFilter') || is_a($filter, 'PKPSubmissionNlmXmlFilter')) {
             $filter->setIsTemplate(false);
             // Check whether the filter instance has been
             // installed before.
             $existingFilters =& $filterDao->getObjectsByClass($filterToBeInstalled, 0, false);
             // Install other filter as configurable templates.
         } else {
             $filter->setIsTemplate(true);
             // Check whether the filter template has been
             // installed before.
             $existingFilters =& $filterDao->getObjectsByClass($filterToBeInstalled, 0, true);
         }
         // Guarantee idempotence.
         if ($existingFilters->getCount()) {
             continue;
         }
         // Install the filter or template.
         $filterDao->insertObject($filter, 0);
         // If this is a citation output filter then also install a corresponding references list filter.
         if (is_a($filter, 'NlmCitationSchemaCitationOutputFormatFilter')) {
             // Only Vancouver Style listings require numerical ordering.
             if (is_a($filter, 'NlmCitationSchemaVancouverFilter')) {
                 $ordering = REFERENCES_LIST_ORDERING_NUMERICAL;
             } else {
                 $ordering = REFERENCES_LIST_ORDERING_ALPHABETICAL;
             }
             // Instantiate the filter.
             $referencesListFilter = new PlainTextReferencesListFilter($filter->getDisplayName(), $filter->getClassName(), $ordering);
             $referencesListFilter->setIsTemplate(false);
             // Install the filter.
             $filterDao->insertObject($referencesListFilter, 0);
             unset($referencesListFilter);
         }
         unset($filter);
     }
     // Composite filters are more complex to install because they
     // need to be constructed first:
     // 1) Check and install the ISBNdb filter template.
     $alreadyInstalled = false;
     $existingTemplatesFactory =& $filterDao->getObjectsByClass('lib.pkp.classes.filter.GenericSequencerFilter', 0, true);
     $existingTemplates =& $existingTemplatesFactory->toArray();
     foreach ($existingTemplates as $existingTemplate) {
         $subFilters =& $existingTemplate->getFilters();
         if (count($subFilters) != 2) {
             continue;
         }
         if (!(isset($subFilters[1]) && is_a($subFilters[1], 'IsbndbNlmCitationSchemaIsbnFilter'))) {
             continue;
         }
         if (!(isset($subFilters[2]) && is_a($subFilters[2], 'IsbndbIsbnNlmCitationSchemaFilter'))) {
             continue;
         }
         $alreadyInstalled = true;
         break;
     }
     if (!$alreadyInstalled) {
         // Instantiate the filter as a configurable template.
         $isbndbTransformation = array('metadata::lib.pkp.classes.metadata.nlm.NlmCitationSchema(CITATION)', 'metadata::lib.pkp.classes.metadata.nlm.NlmCitationSchema(CITATION)');
         import('lib.pkp.classes.filter.GenericSequencerFilter');
         $isbndbFilter = new GenericSequencerFilter('ISBNdb', $isbndbTransformation);
         $isbndbFilter->setIsTemplate(true);
         // Instantiate and add the NLM-to-ISBN filter.
         import('lib.pkp.classes.citation.lookup.isbndb.IsbndbNlmCitationSchemaIsbnFilter');
         $nlmToIsbnFilter = new IsbndbNlmCitationSchemaIsbnFilter();
         $isbndbFilter->addFilter($nlmToIsbnFilter);
         // Instantiate and add the ISBN-to-NLM filter.
         import('lib.pkp.classes.citation.lookup.isbndb.IsbndbIsbnNlmCitationSchemaFilter');
         $isbnToNlmFilter = new IsbndbIsbnNlmCitationSchemaFilter();
         $isbndbFilter->addFilter($isbnToNlmFilter);
         // Add the settings mapping.
         $isbndbFilter->setSettingsMapping(array('apiKey' => array('seq' . $nlmToIsbnFilter->getSeq() . '_apiKey', 'seq' . $isbnToNlmFilter->getSeq() . '_apiKey'), 'isOptional' => array('seq' . $nlmToIsbnFilter->getSeq() . '_isOptional', 'seq' . $isbnToNlmFilter->getSeq() . '_isOptional')));
         // Persist the composite filter.
         $filterDao->insertObject($isbndbFilter, 0);
     }
     // 3) Check and install the NLM XML 2.3 output filter.
     $alreadyInstalled = false;
     $existingTemplatesFactory =& $filterDao->getObjectsByClass('lib.pkp.classes.filter.GenericSequencerFilter', 0, false);
     $existingTemplates =& $existingTemplatesFactory->toArray();
     foreach ($existingTemplates as $existingTemplate) {
         $subFilters =& $existingTemplate->getFilters();
         if (count($subFilters) != 2) {
             continue;
         }
         if (!(isset($subFilters[1]) && is_a($subFilters[1], 'PKPSubmissionNlmXmlFilter'))) {
             continue;
         }
         if (!(isset($subFilters[2]) && is_a($subFilters[2], 'XSLTransformationFilter'))) {
             continue;
         }
         $alreadyInstalled = true;
         break;
     }
     if (!$alreadyInstalled) {
         // Instantiate the filter as a non-configurable filter instance.
         $nlm23Transformation = array('class::lib.pkp.classes.submission.Submission', 'xml::*');
         $nlm23Filter = new GenericSequencerFilter('NLM Journal Publishing V2.3 ref-list', $nlm23Transformation);
         $nlm23Filter->setIsTemplate(false);
         // Instantiate and add the NLM 3.0 export filter.
         import('lib.pkp.classes.importexport.nlm.PKPSubmissionNlmXmlFilter');
         $nlm30Filter = new PKPSubmissionNlmXmlFilter();
         $nlm23Filter->addFilter($nlm30Filter);
         // Instantiate, configure and add the NLM 3.0 to 2.3 downgrade XSL transformation.
         import('lib.pkp.classes.xslt.XSLTransformationFilter');
         $downgradeFilter = new XSLTransformationFilter('NLM 3.0 to 2.3 ref-list downgrade', array('xml::*', 'xml::*'));
         $downgradeFilter->setXSLFilename('lib/pkp/classes/importexport/nlm/nlm-ref-list-30-to-23.xsl');
         $nlm23Filter->addFilter($downgradeFilter);
         // Persist the composite filter.
         $filterDao->insertObject($nlm23Filter, 0);
     }
     return true;
 }
 /**
  * Get the (validated) RPC service endpoint from the request.
  * If no such RPC service endpoint can be constructed then the method
  * returns null.
  * @param $request PKPRequest the request to be routed
  * @return callable an array with the handler instance
  *  and the handler operation to be called by call_user_func().
  */
 function &getRpcServiceEndpoint(&$request)
 {
     if ($this->_rpcServiceEndpoint === false) {
         // We have not yet resolved this request. Mark the
         // state variable so that we don't try again next
         // time.
         $this->_rpcServiceEndpoint = $nullVar = null;
         //
         // Component Handler
         //
         // Retrieve requested component handler
         $component = $this->getRequestedComponent($request);
         if (empty($component)) {
             return $nullVar;
         }
         // Construct the component handler file name and test its existence.
         $component = 'controllers.' . $component;
         $componentFileName = str_replace('.', '/', $component) . '.inc.php';
         switch (true) {
             case file_exists($componentFileName):
                 break;
             case file_exists('lib/pkp/' . $componentFileName):
                 $component = 'lib.pkp.' . $component;
                 break;
             default:
                 // Request to non-existent handler
                 return $nullVar;
         }
         // We expect the handler to be part of one
         // of the following packages:
         $allowedPackages = array('controllers', 'lib.pkp.controllers');
         // Retrieve requested component operation
         $op = $this->getRequestedOp($request);
         assert(!empty($op));
         // A handler at least needs to implement the
         // following methods:
         $requiredMethods = array($op, 'authorize', 'validate', 'initialize');
         $componentInstance =& instantiate($component, 'PKPHandler', $allowedPackages, $requiredMethods);
         if (!is_object($componentInstance)) {
             return $nullVar;
         }
         //
         // Callable service endpoint
         //
         // Construct the callable array
         $this->_rpcServiceEndpoint = array($componentInstance, $op);
     }
     return $this->_rpcServiceEndpoint;
 }
 /**
  * Return the requested SubmissionFileDAODelegate.
  * @param $fileImplementation string the class name of
  *  a file implementation that the requested delegate
  *  should serve.
  * @return SubmissionFileDAODelegate
  */
 private function _getDaoDelegate($fileImplementation)
 {
     // Normalize the file implementation name.
     $fileImplementation = strtolower_codesafe($fileImplementation);
     // Did we already instantiate the requested delegate?
     if (!isset($this->_delegates[$fileImplementation])) {
         // Instantiate the requested delegate.
         $delegateClasses = $this->getDelegateClassNames();
         assert(isset($delegateClasses[$fileImplementation]));
         $delegateClass = $delegateClasses[$fileImplementation];
         $this->_delegates[$fileImplementation] = instantiate($delegateClass, 'SubmissionFileDAODelegate', null, null, $this);
     }
     // Return the delegate.
     return $this->_delegates[$fileImplementation];
 }
 /**
  * Instantiate a plugin.
  *
  * This method can be called statically.
  *
  * @param $category string
  * @param $categoryDir string
  * @param $file string
  * @param $classToCheck string set null to maintain pre-2.3.x backwards compatibility
  * @return Plugin
  */
 function &_instantiatePlugin($category, $categoryDir, $file, $classToCheck = null)
 {
     if (!is_null($classToCheck) && !preg_match('/[a-zA-Z0-9]+/', $file)) {
         fatalError('Invalid product name "' . $file . '"!');
     }
     $pluginPath = "{$categoryDir}/{$file}";
     $plugin = null;
     // Try the plug-in wrapper first for backwards
     // compatibility.
     $pluginWrapper = "{$pluginPath}/index.php";
     if (file_exists($pluginWrapper)) {
         $plugin = (include $pluginWrapper);
         if ($classToCheck) {
             assert(is_a($plugin, $classToCheck));
         }
     } else {
         // Try the well-known plug-in class name next.
         $pluginClassName = ucfirst($file) . ucfirst($category) . 'Plugin';
         $pluginClassFile = $pluginClassName . '.inc.php';
         if (file_exists("{$pluginPath}/{$pluginClassFile}")) {
             // Try to instantiate the plug-in class.
             $pluginPackage = 'plugins.' . $category . '.' . $file;
             $plugin =& instantiate($pluginPackage . '.' . $pluginClassName, $pluginClassName, $pluginPackage, 'register');
         }
     }
     // Make sure that the plug-in inherits from the right class.
     if (is_object($plugin)) {
         assert(is_a($plugin, 'Plugin'));
     } else {
         assert(is_null($plugin));
     }
     return $plugin;
 }
 /**
  * Instantiates the given class from the given
  * package
  * @param $packageName string
  * @param $className string
  * @return object
  */
 function &instantiateClass($packageName, $className)
 {
     assert(!empty($packageName) && !empty($className));
     $object =& instantiate($packageName . '.' . $className, $className);
     return $object;
 }
 /**
  * @see TemplateBasedReferencesListFilter::getCitationOutputFilterInstance()
  */
 function &getCitationOutputFilterInstance()
 {
     $citationOutputFilterName = $this->getData('citationOutputFilterName');
     $nlmCitationOutputFilter =& instantiate($citationOutputFilterName, 'NlmCitationSchemaCitationOutputFormatFilter');
     return $nlmCitationOutputFilter;
 }
Exemple #14
0
$image->descriptionHtmlSyndicated = FEED_DESCRIPTION_HTML;
$rss->image = $image;
$n = (int) $n;
// get feed items
// To optimize memory usage, we should load the minimum items. But, we must load
// more than what we need, because we may have no rights on some items.
// Twice the number we need is just an arbitrary value!!! (2*$n)
if ($comments = $this->LoadRecentComments(2 * $n)) {
    $c = 0;
    foreach ($comments as $comment) {
        if (!$this->HasAccess('comment_read', $comment['page_tag'])) {
            continue;
        }
        $c++;
        #$item = new FeedItem();
        $item = instantiate('FeedItem');
        $item->title = $comment['page_tag'];
        $item->link = str_replace('&amp;', '&', $this->Href('', $comment['page_tag'], 'show_comments=1') . '#comment_' . $comment['id']);
        // @@@ ^ uses &amp;amp; in all formats - this is FC escaping the &amp; that Href() outputs
        // WARNING: the double escape comes from the use of htmlspecialchars()
        // see also recentchanges.xml.php
        $item->date = date('r', strtotime($comment['time']));
        $item->description = 'By ' . $comment['user'] . ': ' . $comment['comment'] . "\n";
        // @@@ ^ JW: should link to actual comment, or (maybe) the page that has the comment
        /*
        http://dublincore.org/documents/1999/07/02/dces/
        Element: Source
        
          Name:        Source
          Identifier:  Source
          Definition:  A Reference to a resource from which the present resource
Exemple #15
0
 /**
  * Construct a new configured filter instance (transformation).
  * @param $filterClassName string a fully qualified class name
  * @param $inputType string
  * @param $outputType string
  * @return Filter
  */
 function &_newDataObject($filterClassName, $inputType, $outputType)
 {
     // Instantiate the filter
     $filter =& instantiate($filterClassName, 'Filter');
     if (!is_object($filter)) {
         fatalError('Error while instantiating class "' . $filterClassName . '" as filter!');
     }
     // Set input/output data types (transformation type).
     // NB: This will raise a fatal error if the transformation is not
     // supported by this filter.
     $filter->setTransformationType($inputType, $outputType);
     return $filter;
 }
Exemple #16
0
    if (preg_match("#^(.*)\$#", $wakka, $matches)) {
        list(, $page) = $matches;
    }
}
//Fix lowercase mod_rewrite bug: URL rewriting makes pagename lowercase. #135
if (strtolower($page) == $page && isset($_SERVER['REQUEST_URI'])) {
    $pattern = preg_quote($page, '/');
    if (preg_match("/({$pattern})/i", urldecode($_SERVER['REQUEST_URI']), $match_url)) {
        $page = $match_url[1];
    }
}
//$page = preg_replace('/_/', ' ', $page);
/**
 * Create Wakka object
 */
$wakka = instantiate('Wakka', $wakkaConfig);
/**
 * Check for database access.
 */
if (!$wakka->dblink) {
    echo '<em class="error">' . T_("Error: Unable to connect to the database.") . '</em>';
    exit;
}
/**
 * Save session ID
 */
$user = $wakka->GetUser();
// Only store sessions for real users!
if (NULL != $user) {
    $res = $wakka->LoadSingle("SELECT * FROM " . $wakka->config['table_prefix'] . "sessions WHERE sessionid='" . session_id() . "' AND userid='" . $user['name'] . "'");
    if (isset($res)) {
Exemple #17
0
 /**
  * Construct a new configured filter instance (transformation).
  * @param $filterClassName string a fully qualified class name
  * @param $filterGroupId integer
  * @return PersistableFilter
  */
 function &_newDataObject($filterClassName, $filterGroupId)
 {
     // Instantiate the filter group.
     $filterGroupDao =& DAORegistry::getDAO('FilterGroupDAO');
     /* @var $filterGroupDao FilterGroupDAO */
     $filterGroup =& $filterGroupDao->getObjectById($filterGroupId);
     assert(is_a($filterGroup, 'FilterGroup'));
     // Instantiate the filter
     $filter =& instantiate($filterClassName, 'PersistableFilter', null, 'execute', $filterGroup);
     /* @var $filter PersistableFilter */
     if (!is_object($filter)) {
         fatalError('Error while instantiating class "' . $filterClassName . '" as filter!');
     }
     return $filter;
 }
Exemple #18
0
                if ($this->debugMode) {
                    $errortext = sprintf($this->error, $line, $err);
                    echo '<!-- ' . $errortext . ' -->' . "\n";
                }
            }
        }
    }
}
if (preg_match("/^(http|https):\\/\\/([^\\s\"<>]+)\$/i", $rss_path)) {
    if ($caching) {
        // Create unique cache file name based on URL
        $rss_cache_file = md5($rss_path) . ".xml";
    }
    //Load the RSS Feed: workaround to hide error messages within HTML comments:
    #$rss =& new Wikka_Onyx();
    $rss = instantiate('Wikka_Onyx');
    $rss->setCachePath($rss_cache_path);
    $rss->parse($rss_path, $rss_cache_file, $rss_cache_time);
    $meta = $rss->getData(ONYX_META);
    //List the feed's items
    $cached_output = "<h3>" . $meta['title'] . "</h3>";
    $cached_output .= "<ul>\n";
    while ($max_items > 0 && ($item = $rss->getNextItem())) {
        $cached_output .= "<li><a href=\"" . $item['link'] . "\">" . $item['title'] . "</a><br />\n";
        if (isset($item['description'])) {
            $cached_output .= $item['description'];
        }
        $cached_output .= "</li>\n";
        $max_items = $max_items - 1;
    }
    $cached_output .= "</ul>\n";
Exemple #19
0
 /**
  * Highlight a code block with GeSHi.
  *
  * The path to GeSHi and the GeSHi language files must be defined in the configuration.
  *
  * This implementation fits in with general Wikka behavior; e.g., we use classes and an external
  * stylesheet to render hilighting.
  *
  * Apart from this fixed general behavior, WikiAdmin can configure a few behaviors via the
  * configuration file:
  * geshi_header			- wrap code in div (default) or pre
  * geshi_line_numbers	- disable line numbering, or enable normal or fancy line numbering
  * geshi_tab_width		- override tab width (default is 8 but 4 is more commonly used in code)
  *
  * Limitation: while line numbering is supported, extra GeSHi styling for line numbers is not.
  * When line numbering is enabled, the end user can "turn it on" by specifying a starting line
  * number together with the language code in a code block, e.g., (php;260); this number is then
  * passed as the $start parameter for this method.
  *
  * @since	wikka 1.1.6.0
  *
  * @access	public
  * @uses	Config::$geshi_path
  * @uses	Config::$geshi_languages_path
  * @uses	Config::$geshi_header
  * @uses	Config::$geshi_line_numbers
  * @uses	Config::$geshi_tab_width
  * @uses	GeShi
  *
  * @param	string	$sourcecode	required: source code to be highlighted
  * @param	string	$language	required: language spec to select highlighter
  * @param	integer	$start		optional: start line number; if supplied and >= 1 line numbering
  *			will be turned on if it is enabled in the configuration.
  * @return	string	code block with syntax highlighting classes applied
  * @todo		support for GeSHi line number styles
  * @todo		enable error handling
  */
 function GeSHi_Highlight($sourcecode, $language, $start = 0)
 {
     // create GeSHi object
     include_once $this->GetConfigValue('geshi_path') . DIRECTORY_SEPARATOR . 'geshi.php';
     $geshi = instantiate('GeSHi', $sourcecode, $language, $this->GetConfigValue('geshi_languages_path'));
     # create object by reference
     $geshi->enable_classes();
     # use classes for hilighting (must be first after creating object)
     $geshi->set_overall_class('code');
     # enables using a single stylesheet for multiple code fragments
     // configure user-defined behavior
     $geshi->set_header_type(GESHI_HEADER_DIV);
     # set default
     if (NULL !== $this->GetConfigValue('geshi_header')) {
         if ('pre' == $this->GetConfigValue('geshi_header')) {
             $geshi->set_header_type(GESHI_HEADER_PRE);
         }
     }
     $geshi->enable_line_numbers(GESHI_NO_LINE_NUMBERS);
     # set default
     if ($start > 0) {
         if (NULL !== $this->GetConfigValue('geshi_line_numbers')) {
             if ('1' == $this->GetConfigValue('geshi_line_numbers')) {
                 $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
             } elseif ('2' == $this->GetConfigValue('geshi_line_numbers')) {
                 $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS);
             }
             if ($start > 1) {
                 $geshi->start_line_numbers_at($start);
             }
         }
     }
     if (NULL !== $this->GetConfigValue('geshi_tab_width')) {
         $geshi->set_tab_width($this->GetConfigValue('geshi_tab_width'));
     }
     // parse and return highlighted code
     // comments added to make GeSHi-highlighted block visible in code JW/20070220
     return '<!--start GeSHi-->' . "\n" . $geshi->parse_code() . "\n" . '<!--end GeSHi-->' . "\n";
 }
Exemple #20
0
 /**
  *
  * @deprecated
  */
 function PersistentObject($tablename, $unique_set, $cache_by = NULL, $use_cache = true, $is_transient = false, $allowCreate = true)
 {
     deprecated_functions::PersistentObject();
     return instantiate($tablename, $unique_set, $cache_by, $use_cache, $is_transient, $allowCreate);
 }
 /**
  * Execute the specified task.
  * @param $className string the class name to execute
  * @param $args array the array of arguments to pass to the class constructors
  */
 function executeTask($className, $args)
 {
     // Load and execute the task
     if (!is_object($task =& instantiate($className, null, null, 'execute', $args))) {
         fatalError('Cannot instantiate task class.');
     }
     $task->execute();
     $this->taskDao->updateLastRunTime($className);
 }
 /**
  * Instantiate a new data object of the
  * correct type.
  *
  * NB: This can be overridden by sub-classes for more complex
  * data objects. The standard implementation assumes there are
  * no constructor args to be set or configurations to be made.
  *
  * @return DataObject
  */
 function &instantiateDataObject()
 {
     $dataObjectName = $this->getDataObjectName();
     assert(!is_null($dataObjectName));
     $dataObject =& instantiate($dataObjectName, $this->getDataObjectClass());
     return $dataObject;
 }
Exemple #23
0
 /**
  * Instantiate a router
  * @param $routerName string
  * @param $shortcut string
  */
 function &_instantiateRouter($routerName, $shortcut)
 {
     if (!isset($this->_routerInstances[$shortcut])) {
         // Routers must belong to the classes.core or lib.pkp.classes.core package
         // NB: This prevents code inclusion attacks.
         $allowedRouterPackages = array('classes.core', 'lib.pkp.classes.core');
         // Instantiate the router
         $router =& instantiate($routerName, 'PKPRouter', $allowedRouterPackages);
         if (!is_object($router)) {
             fatalError('Cannot instantiate requested router. Routers must belong to the core package and be of type "PKPRouter".');
         }
         $router->setApplication($this->_application);
         $router->setDispatcher($this);
         // Save the router instance for later re-use
         $this->_routerInstances[$shortcut] =& $router;
     }
     return $this->_routerInstances[$shortcut];
 }
Exemple #24
0
 public function addFeature($feature)
 {
     if (is_string($feature)) {
         $feature = instantiate($feature, $this->applicationState);
     }
     if (!$feature instanceof Feature\AbstractFeature) {
         throw new \InvalidArgumentException('Provided feature is not a valid feature');
     }
     $feature->register($this);
     return $this;
 }