Exemplo n.º 1
0
 /** Check params.
  * @var     array     $params */
 function _checkParams(&$params)
 {
     foreach ($this->__args as $name => $val) {
         // Deal with unfilled parameters
         if (!isset($params[$name]) || empty($params[$name])) {
             // Set default val if available
             if (!empty($this->__args[$name]['DEFAULT'])) {
                 $params[$name] = $this->__args[$name]['DEFAULT'];
             } else {
                 $errstack =& PEAR_ErrorStack::singleton($this->__module);
                 $errstack->push(MB_MISSING_ACTION_ARG, 'error', array('name' => $name));
                 return null;
             }
         } else {
             if (isset($this->__args[$name]['REGEX'])) {
                 if (!preg_match($this->__args[$name]['REGEX'], $params[$name])) {
                     $errstack =& PEAR_ErrorStack::singleton($this->__module);
                     $errstack->push(MB_INVALID_ACTION_ARG, 'error', array('module' => $this->__module, 'action' => $this->__name, 'name' => $name, 'val' => $params[$name], 'regex' => $this->__args[$name]['REGEX'], 'default' => $this->__args[$name]['DEFAULT']));
                     return null;
                 }
             }
         }
     }
     return true;
 }
Exemplo n.º 2
0
 /**
  * construcor
  */
 function __construct()
 {
     parent::__construct('CiviCRM');
     $log =& CRM_Core_Config::getLog();
     $this->setLogger($log);
     // set up error handling for Pear Error Stack
     $this->setDefaultCallback(array($this, 'handlePES'));
 }
Exemplo n.º 3
0
 /** Renvoie le chemin vers le module.
  * @param      string      $module_name
  */
 function _getModuleClassPath($module_name)
 {
     $path = MB_CONF_PREFIX . "/phplib/modules/{$module_name}/{$module_name}.php";
     if (!file_exists($path)) {
         $errstack =& PEAR_ErrorStack::singleton('MicroBuilder');
         $errstack->push(MB_NONEXISTENT_MODULE, 'error', array('module' => $module_name));
         return null;
     }
     return $path;
 }
Exemplo n.º 4
0
 /** Renvoie le chemin vers l'action.
  */
 function _getActionClassPath($module_name, $action_name)
 {
     $path = MB_CONF_PREFIX . "/phplib/modules/{$module_name}/actions/{$action_name}.php";
     if (!file_exists($path)) {
         $errstack =& PEAR_ErrorStack::singleton($module_name);
         $errstack->push(MB_NONEXISTENT_ACTION, 'error', array('module' => $module_name, 'action' => $action_name, 'file' => $path));
         return null;
     }
     return $path;
 }
Exemplo n.º 5
0
 /** Returns theme class path
  * @param      string      $theme_name
  */
 function _getThemeClassPath($theme_name)
 {
     $path = MB_CONF_PREFIX . "/phplib/themes/{$theme_name}/{$theme_name}.php";
     if (!file_exists($path)) {
         $errstack =& PEAR_ErrorStack::singleton('MicroBuilder');
         $errstack->push(MB_NONEXISTENT_THEME, 'fatal', array('theme' => $theme_name, 'path' => $path));
         return null;
     }
     return $path;
 }
 /** ErrorCallback */
 function errorCallback($err)
 {
     switch ($err['level']) {
         case 'error':
             break;
         case 'fatal':
             $mbstack =& PEAR_ErrorStack::singleton('MicroBuilder');
             $mbstack->push(5, 'error', array(), "Fatal error during module execution");
             break;
     }
 }
Exemplo n.º 7
0
 /**
  * PHP5 type constructor
  */
 function __construct()
 {
     global $wpdb;
     //get the PhotoQ error stack for easy access
     $this->_errStack =& PEAR_ErrorStack::singleton('PhotoQ');
     PhotoQHelper::debug('-----------start plugin-------------');
     // load text domain for localization
     load_plugin_textdomain('PhotoQ', '', 'photoq-photoblog-plugin/lang');
     // set names of database tables used and created by photoq
     $this->QUEUEMETA_TABLE = $wpdb->prefix . "photoqmeta";
     $this->QUEUE_TABLE = $wpdb->prefix . "photoq";
     $this->QFIELDS_TABLE = $wpdb->prefix . "photoqfields";
     $this->QCAT_TABLE = $wpdb->prefix . "photoq2cat";
     $this->POSTS_TABLE = $wpdb->prefix . "posts";
     // setting up database
     $this->_db =& PhotoQSingleton::getInstance('PhotoQDB');
     // setting up options
     $this->_oc =& PhotoQSingleton::getInstance('PhotoQOptionController');
     $this->_autoUpgrade();
     //creating queue
     $this->_queue =& PhotoQSingleton::getInstance('PhotoQQueue');
     // actions and filters are next
     // Insert the _actionAddAdminPages() sink into the plugin hook list for 'admin_menu'
     add_action('admin_menu', array(&$this, '_actionAddAdminPages'));
     // function executed when a post is deleted
     add_action('delete_post', array(&$this, '_actionCleanUp'));
     // Hook into the 'wp_dashboard_setup' action to setup the photoq dashboard widget
     add_action('wp_dashboard_setup', array(&$this, '_actionAddDashboardWidget'));
     add_action('admin_print_styles-index.php', array(&$this, '_actionEnqueueDashboardStyles'), 1);
     // the next two hooks are used to show a thumb in the manage post section
     add_filter('manage_posts_columns', array(&$this, '_filterAddThumbToListOfPosts'));
     add_action('manage_posts_custom_column', array(&$this, '_actionInsertThumbIntoListOfPosts'), 10, 2);
     // filter to show change photo form in post editing
     add_filter('edit_form_advanced', array(&$this, '_filterShowChangePostedPhotoBox'));
     // Only show description in content field when editing
     add_filter('edit_post_content', array(&$this, '_filterPrepareEditorContent'), 100, 2);
     // Get description back
     add_filter('wp_insert_post_data', array(&$this, '_filterPostProcessEditedPost'), 100, 2);
     register_activation_hook(PHOTOQ_PATH . 'whoismanu-photoq.php', array(&$this, 'activatePlugin'));
     register_deactivation_hook(PHOTOQ_PATH . 'whoismanu-photoq.php', array(&$this, 'deactivatePlugin'));
     add_filter('favorite_actions', array(&$this, '_filterAddFavoriteActions'));
     add_filter('contextual_help', array(&$this, '_filterAddContextualHelp'), 100, 2);
     /*foreach( $_POST as $key => $value){
     			PhotoQHelper::debug("POST $key: ".print_r($value,true)." <br />");
     			}
     
     		foreach( $_GET as $key => $value){
     			PhotoQHelper::debug("GET $key: ".print_r($value,true)." <br />");
     			}
     		*/
     PhotoQHelper::debug('leave __construct()');
 }
Exemplo n.º 8
0
 /**
  * PHP5 type constructor
  *
  * @access public
  */
 function __construct()
 {
     parent::__construct("wimpq_options", new PhotoQRenderOptionVisitor());
     //get the PhotoQ error stack for easy access and set it up properly
     $this->_errStack =& PEAR_ErrorStack::singleton('PhotoQ');
     //get alternative original identifier if available
     $originalID = get_option("wimpq_originalFolder");
     if ($originalID) {
         $this->ORIGINAL_IDENTIFIER = $originalID;
     }
     //establish default options
     $this->_defineAndRegisterOptions();
     //localize strings in js scripts etc. of option controller
     $this->localizeStrings(array("switchLinkLabel" => __('Switch Sides', 'PhotoQ')));
 }
Exemplo n.º 9
0
 /**
  * PHP5 type constructor
  *
  * @access public
  */
 function __construct()
 {
     global $wpdb;
     //get the PhotoQ error stack for easy access
     $this->_errStack =& PEAR_ErrorStack::singleton('PhotoQ');
     // set wordpress database
     $this->_wpdb =& $wpdb;
     // some methods need access to options so instantiate an OptionController
     $this->_oc =& PhotoQSingleton::getInstance('PhotoQOptionController');
     // set names of database tables used and created by photoq
     $this->QUEUEMETA_TABLE = $wpdb->prefix . "photoqmeta";
     $this->QUEUE_TABLE = $wpdb->prefix . "photoq";
     $this->QFIELDS_TABLE = $wpdb->prefix . "photoqfields";
     $this->QCAT_TABLE = $wpdb->prefix . "photoq2cat";
     $this->QBATCH_TABLE = $wpdb->prefix . "photoqbatch";
     // set names of wordpress database tables used by photoq
     $this->POSTS_TABLE = $wpdb->prefix . "posts";
     $this->POSTMETA_TABLE = $wpdb->prefix . "postmeta";
 }
 /**
  * vérifie qu'un objet DocInfos correspond à ce type de document
  * @param object $docinfos
  * @return boolean true si le document correspond au type
  */
 function check($docinfos)
 {
     $res = array();
     if (!$this->id) {
         return false;
     }
     /* On vérifie que l'accroche est correcte */
     if ($this->accroche && $docinfos->accroche == '') {
         $this->errors->push(OW_NO_ABSTRACT, 'error');
     }
     /* Nombre total de classements dans $docinfos */
     $nb = 0;
     /* On compte le nombre d'entrées dans $docinfos pour chaque critère
        qui se trouve dans $this->max ou $this->min. On calcule au passage
        également le nombre total d'entrées. */
     $compte = array();
     foreach (array_unique(array_merge(array_keys($this->max), array_keys($this->min))) as $critere) {
         $nb += $compte[$critere] = isset($docinfos->classement[$critere]) ? count($docinfos->classement[$critere]) : 0;
     }
     /* On vérifie que le nombre de classement pour chaque critère est dans
        le bon intervalle */
     foreach (array_keys($this->max) as $critere) {
         /* Il n'y a pas de maximum si $this->max[$critere] est négatif */
         if ($this->max[$critere] >= 0 && $compte[$critere] > $this->max[$critere]) {
             $this->errors->push(OW_TOO_MANY_SUBJECTS, 'error', array('criterion' => $critere, 'limit' => $this->max[$critere]));
         }
     }
     foreach (array_keys($this->min) as $critere) {
         if ($compte[$critere] < $this->min[$critere]) {
             $this->errors->push(OW_TOO_FEW_SUBJECTS, 'error', array('criterion' => $critere, 'limit' => $this->min[$critere]));
         }
     }
     /* Le nombre total de classements est-il compris entre les
        deux valeurs imposées ? */
     if ($nb > $this->total_max) {
         $this->errors->push(OW_TOO_MANY_SUBJECTS, 'error', array('limit' => $this->total_max));
     }
     if ($nb < $this->total_min) {
         $this->errors->push(OW_TOO_FEW_SUBJECTS, 'error', array('limit' => $this->total_min));
     }
     return !$this->errors->hasErrors();
 }
Exemplo n.º 11
0
 /**
  * PHP5 type constructor
  */
 function __construct($id, $title, $descr, $exif, $path, $imgname, $tags = '', $slug = '', $edited = false)
 {
     //get the PhotoQ error stack for easy access
     $this->_errStack =& PEAR_ErrorStack::singleton('PhotoQ');
     //get the other singletons
     $this->_oc =& PhotoQSingleton::getInstance('PhotoQOptionController');
     $this->_db =& PhotoQSingleton::getInstance('PhotoQDB');
     $this->id = $id;
     $this->imgname = $imgname;
     $this->_tags = $tags;
     $this->title = $title;
     $this->descr = $descr;
     $this->exif = maybe_unserialize($exif);
     if (empty($path)) {
         $this->_path = $this->_oc->getQDir() . $this->imgname;
     } else {
         $this->_path = $path;
     }
     //mute this one because it can issue warnings if the original does not exist.
     @$this->initImageSizes();
 }
Exemplo n.º 12
0
 function __construct(&$context, $id = NULL)
 {
     //get the PhotoQ error stack for easy access
     $this->_errStack =& PEAR_ErrorStack::singleton('PhotoQ');
     $this->_db =& PhotoQSingleton::getInstance('PhotoQDB');
     if (is_null($id)) {
         //create a new empty BatchProcessor
         //PhotoQHelper::debug('creating empty BatchProcessor');
         $this->_batchSets = array();
         $this->_totalSets = 0;
         $this->_id = $id;
         //no id yet
     } else {
         //load it from the database
         //PhotoQHelper::debug('creating BatchProcessor no:' . $id);
         $this->_context =& $context;
         $this->load($id);
         //PhotoQHelper::debug('sets from db: ' . print_r($this->_batchSets,true));
     }
     //at the end of script execution we need to make the batch persistent
     //such that execution can go on in the next request
     register_shutdown_function(array(&$this, '_makeBatchPersistent'));
 }
Exemplo n.º 13
0
 /**
  * Returns the error-stack
  *
  * @static
  * @access   public
  * @return   object PEAR_ErrorStack  error-stack
  */
 function &getErrorStack()
 {
     return PEAR_ErrorStack::singleton('Date_Holidays', false, false, true);
 }
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * @package    Piece_Unity
 * @subpackage Piece_Unity_Component_KernelConfigurator
 * @copyright  2006-2008 KUBO Atsuhiro <*****@*****.**>
 * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License (revised)
 * @version    SVN: $Id$
 * @since      File available since Release 1.0.0
 */
error_reporting(E_ALL);
if (file_exists(dirname(__FILE__) . '/../../../Piece/Unity.php')) {
    set_include_path(realpath(dirname(__FILE__) . '/../../..') . PATH_SEPARATOR . get_include_path());
}
if (file_exists(dirname(__FILE__) . '/../Piece/Unity/Plugin/KernelConfigurator.php')) {
    set_include_path(realpath(dirname(__FILE__) . '/..') . PATH_SEPARATOR . get_include_path());
}
require_once 'PEAR/ErrorStack.php';
PEAR_ErrorStack::setDefaultCallback(create_function('$error', 'var_dump($error); return ' . PEAR_ERRORSTACK_DIE . ';'));
/*
 * Local Variables:
 * mode: php
 * coding: iso-8859-1
 * tab-width: 4
 * c-basic-offset: 4
 * c-hanging-comment-ender-p: nil
 * indent-tabs-mode: nil
 * End:
 */
Exemplo n.º 15
0
 /**
  * Wrapper method to get the Error Stack
  *
  * @return array  an array of the errors
  *
  * @access public
  */
 function getErrors()
 {
     if (is_object($this->stack)) {
         return $this->stack->getErrors();
     }
     return false;
 }
Exemplo n.º 16
0
 /**
  * 
  * Pushes an error onto the PEAR_ErrorStack.
  * 
  * @return void
  * 
  */
 function error()
 {
     // push an error onto the stack
     PEAR_ErrorStack::staticPush('Savant2', $this->code, null, $this->info, $this->text);
 }
Exemplo n.º 17
0
 /**
  * Analyze the source code of the given PHP file
  *
  * @param  string Filename of the PHP file
  * @param  boolean whether to analyze $file as the file contents
  * @return mixed
  */
 function analyzeSourceCode($file, $string = false)
 {
     if (!function_exists("token_get_all")) {
         return false;
     }
     if (!defined('T_DOC_COMMENT')) {
         define('T_DOC_COMMENT', T_COMMENT);
     }
     if (!defined('T_INTERFACE')) {
         define('T_INTERFACE', -1);
     }
     if (!defined('T_IMPLEMENTS')) {
         define('T_IMPLEMENTS', -1);
     }
     if ($string) {
         $contents = $file;
     } else {
         if (!($fp = @fopen($file, "r"))) {
             return false;
         }
         if (function_exists('file_get_contents')) {
             fclose($fp);
             $contents = file_get_contents($file);
         } else {
             $contents = @fread($fp, filesize($file));
             fclose($fp);
         }
     }
     $tokens = token_get_all($contents);
     /*
             for ($i = 0; $i < sizeof($tokens); $i++) {
                 @list($token, $data) = $tokens[$i];
                 if (is_string($token)) {
                     var_dump($token);
                 } else {
                     print token_name($token) . ' ';
                     var_dump(rtrim($data));
                 }
             }
     */
     $look_for = 0;
     $paren_level = 0;
     $bracket_level = 0;
     $brace_level = 0;
     $lastphpdoc = '';
     $current_class = '';
     $current_interface = '';
     $current_class_level = -1;
     $current_function = '';
     $current_function_level = -1;
     $declared_classes = array();
     $declared_interfaces = array();
     $declared_functions = array();
     $declared_methods = array();
     $used_classes = array();
     $used_functions = array();
     $extends = array();
     $implements = array();
     $nodeps = array();
     $inquote = false;
     $interface = false;
     for ($i = 0; $i < sizeof($tokens); $i++) {
         if (is_array($tokens[$i])) {
             list($token, $data) = $tokens[$i];
         } else {
             $token = $tokens[$i];
             $data = '';
         }
         if ($inquote) {
             if ($token != '"' && $token != T_END_HEREDOC) {
                 continue;
             } else {
                 $inquote = false;
             }
         }
         switch ($token) {
             case T_WHITESPACE:
                 continue;
             case ';':
                 if ($interface) {
                     $current_function = '';
                     $current_function_level = -1;
                 }
                 break;
             case '"':
             case T_START_HEREDOC:
                 $inquote = true;
                 break;
             case T_CURLY_OPEN:
             case T_DOLLAR_OPEN_CURLY_BRACES:
             case '{':
                 $brace_level++;
                 continue 2;
             case '}':
                 $brace_level--;
                 if ($current_class_level == $brace_level) {
                     $current_class = '';
                     $current_class_level = -1;
                 }
                 if ($current_function_level == $brace_level) {
                     $current_function = '';
                     $current_function_level = -1;
                 }
                 continue 2;
             case '[':
                 $bracket_level++;
                 continue 2;
             case ']':
                 $bracket_level--;
                 continue 2;
             case '(':
                 $paren_level++;
                 continue 2;
             case ')':
                 $paren_level--;
                 continue 2;
             case T_INTERFACE:
                 $interface = true;
             case T_CLASS:
                 if ($current_class_level != -1 || $current_function_level != -1) {
                     $this->_stack->push(__FUNCTION__, 'error', array('file' => $file), 'Parser error: invalid PHP found in file "%file%"');
                     return false;
                 }
             case T_FUNCTION:
             case T_NEW:
             case T_EXTENDS:
             case T_IMPLEMENTS:
                 $look_for = $token;
                 continue 2;
             case T_STRING:
                 if (version_compare(zend_version(), '2.0', '<')) {
                     if (in_array(strtolower($data), array('public', 'private', 'protected', 'abstract', 'interface', 'implements', 'clone', 'throw'))) {
                         $this->_stack->push(__FUNCTION__, 'warning', array(), 'Error, PHP5 token encountered, analysis should be in PHP5');
                     }
                 }
                 if ($look_for == T_CLASS) {
                     $current_class = $data;
                     $current_class_level = $brace_level;
                     $declared_classes[] = $current_class;
                 } elseif ($look_for == T_INTERFACE) {
                     $current_interface = $data;
                     $current_class_level = $brace_level;
                     $declared_interfaces[] = $current_interface;
                 } elseif ($look_for == T_IMPLEMENTS) {
                     $implements[$current_class] = $data;
                 } elseif ($look_for == T_EXTENDS) {
                     $extends[$current_class] = $data;
                 } elseif ($look_for == T_FUNCTION) {
                     if ($current_class) {
                         $current_function = "{$current_class}::{$data}";
                         $declared_methods[$current_class][] = $data;
                     } elseif ($current_interface) {
                         $current_function = "{$current_interface}::{$data}";
                         $declared_methods[$current_interface][] = $data;
                     } else {
                         $current_function = $data;
                         $declared_functions[] = $current_function;
                     }
                     $current_function_level = $brace_level;
                     $m = array();
                 } elseif ($look_for == T_NEW) {
                     $used_classes[$data] = true;
                 }
                 $look_for = 0;
                 continue 2;
             case T_VARIABLE:
                 $look_for = 0;
                 continue 2;
             case T_DOC_COMMENT:
             case T_COMMENT:
                 if (preg_match('!^/\\*\\*\\s!', $data)) {
                     $lastphpdoc = $data;
                     if (preg_match_all('/@nodep\\s+(\\S+)/', $lastphpdoc, $m)) {
                         $nodeps = array_merge($nodeps, $m[1]);
                     }
                 }
                 continue 2;
             case T_DOUBLE_COLON:
                 if (!($tokens[$i - 1][0] == T_WHITESPACE || $tokens[$i - 1][0] == T_STRING)) {
                     $this->_stack->push(__FUNCTION__, 'warning', array('file' => $file), 'Parser error: invalid PHP found in file "%file%"');
                     return false;
                 }
                 $class = $tokens[$i - 1][1];
                 if (strtolower($class) != 'parent') {
                     $used_classes[$class] = true;
                 }
                 continue 2;
         }
     }
     return array("source_file" => $file, "declared_classes" => $declared_classes, "declared_interfaces" => $declared_interfaces, "declared_methods" => $declared_methods, "declared_functions" => $declared_functions, "used_classes" => array_diff(array_keys($used_classes), $nodeps), "inheritance" => $extends, "implements" => $implements);
 }
Exemplo n.º 18
0
 /**
  * Constructor
  *
  * @access protected
  * @param  mixed      configuration array
  * @return void
  */
 function LiveUser_Perm_Storage()
 {
     $this->_stack =& PEAR_ErrorStack::singleton('LiveUser');
 }
 /**
  * Scan through the SVN directory looking for subclasses.
  *
  * @return  mixed    array on success, false on failure
  * @access  public
  */
 function fetchCommands()
 {
     $commands = array();
     $dir = realpath(dirname(__FILE__)) . '/SVN';
     $dp = @opendir($dir);
     if (empty($dp)) {
         PEAR_ErrorStack::staticPush('VersionControl_SVN', VERSIONCONTROL_SVN_ERROR, 'error', array('errstr' => "fetchCommands: opendir({$dir}) failed"));
         return false;
     }
     while ($entry = readdir($dp)) {
         if ($entry[0] == '.' || substr($entry, -4) != '.php') {
             continue;
         }
         $commands[] = substr($entry, 0, -4);
     }
     closedir($dp);
     return $commands;
 }
Exemplo n.º 20
0
 /**
  * Validation warning.  Does not mark the object contents invalid.
  * @param error code
  * @param array error information
  * @access private
  */
 function _validateWarning($code, $params = array())
 {
     $this->_stack->push($code, 'warning', $params, false, false, debug_backtrace());
 }
Exemplo n.º 21
0
 /**
  * Wrapper to {@link PEAR_ErrorStack::getErrors()}
  * @param boolean determines whether to purge the error stack after retrieving
  * @return array
  */
 function getValidationWarnings($purge = true)
 {
     return $this->_stack->getErrors($purge);
 }
Exemplo n.º 22
0
 /**
  * Create a PEAR_PackageFile_v* from an XML string.
  * @access  public
  * @param   string $data contents of package.xml file
  * @param   int $state package state (one of PEAR_VALIDATE_* constants)
  * @param   string $file full path to the package.xml file (and the files
  *          it references)
  * @param   string $archive optional name of the archive that the XML was
  *          extracted from, if any
  * @return  PEAR_PackageFile_v1|PEAR_PackageFile_v2
  * @uses    parserFactory() to construct a parser to load the package.
  */
 function &fromXmlString($data, $state, $file, $archive = false)
 {
     if (preg_match('/<package[^>]+version="([0-9]+\\.[0-9]+)"/', $data, $packageversion)) {
         if (!in_array($packageversion[1], array('1.0', '2.0', '2.1'))) {
             return PEAR::raiseError('package.xml version "' . $packageversion[1] . '" is not supported, only 1.0, 2.0, and 2.1 are supported.');
         }
         $object =& $this->parserFactory($packageversion[1]);
         if ($this->_logger) {
             $object->setLogger($this->_logger);
         }
         $object->setConfig($this->_config);
         $pf = $object->parse($data, $file, $archive);
         if (PEAR::isError($pf)) {
             return $pf;
         }
         if ($this->_rawReturn) {
             return $pf;
         }
         if ($pf->validate($state)) {
             if ($this->_logger) {
                 if ($pf->getValidationWarnings(false)) {
                     foreach ($pf->getValidationWarnings() as $warning) {
                         $this->_logger->log(0, 'WARNING: ' . $warning['message']);
                     }
                 }
             }
             if (method_exists($pf, 'flattenFilelist')) {
                 $pf->flattenFilelist();
                 // for v2
             }
             return $pf;
         } else {
             if ($this->_config->get('verbose') > 0) {
                 if ($this->_logger) {
                     if ($pf->getValidationWarnings(false)) {
                         foreach ($pf->getValidationWarnings(false) as $warning) {
                             $this->_logger->log(0, 'ERROR: ' . $warning['message']);
                         }
                     }
                 }
             }
             $a = PEAR::raiseError('Parsing of package.xml from file "' . $file . '" failed', 2, null, null, $pf->getValidationWarnings());
             return $a;
         }
     } elseif (preg_match('/<package[^>]+version="([^"]+)"/', $data, $packageversion)) {
         $a = PEAR::raiseError('package.xml file "' . $file . '" has unsupported package.xml <package> version "' . $packageversion[1] . '"');
         return $a;
     } else {
         if (!class_exists('PEAR_ErrorStack')) {
             require_once 'PEAR/ErrorStack.php';
         }
         PEAR_ErrorStack::staticPush('PEAR_PackageFile', PEAR_PACKAGEFILE_ERROR_NO_PACKAGEVERSION, 'warning', array('xml' => $data), 'package.xml "' . $file . '" has no package.xml <package> version');
         $object =& $this->parserFactory('1.0');
         $object->setConfig($this->_config);
         $pf = $object->parse($data, $file, $archive);
         if (PEAR::isError($pf)) {
             return $pf;
         }
         if ($this->_rawReturn) {
             return $pf;
         }
         if ($pf->validate($state)) {
             if ($this->_logger) {
                 if ($pf->getValidationWarnings(false)) {
                     foreach ($pf->getValidationWarnings() as $warning) {
                         $this->_logger->log(0, 'WARNING: ' . $warning['message']);
                     }
                 }
             }
             if (method_exists($pf, 'flattenFilelist')) {
                 $pf->flattenFilelist();
                 // for v2
             }
             return $pf;
         } else {
             $a = PEAR::raiseError('Parsing of package.xml from file "' . $file . '" failed', 2, null, null, $pf->getValidationWarnings());
             return $a;
         }
     }
 }
Exemplo n.º 23
0
 /**
  * Standard error message generation callback
  * 
  * This method may also be called by a custom error message generator
  * to fill in template values from the params array, simply
  * set the third parameter to the error message template string to use
  * 
  * The special variable %__msg% is reserved: use it only to specify
  * where a message passed in by the user should be placed in the template,
  * like so:
  * 
  * Error message: %msg% - internal error
  * 
  * If the message passed like so:
  * 
  * <code>
  * $stack->push(ERROR_CODE, 'error', array(), 'server error 500');
  * </code>
  * 
  * The returned error message will be "Error message: server error 500 -
  * internal error"
  * @param PEAR_ErrorStack
  * @param array
  * @param string|false Pre-generated error message template
  * @static
  * @return string
  */
 function getErrorMessage(&$stack, $err, $template = false)
 {
     if ($template) {
         $mainmsg = $template;
     } else {
         $mainmsg = $stack->getErrorMessageTemplate($err['code']);
     }
     $mainmsg = str_replace('%__msg%', $err['message'], $mainmsg);
     if (is_array($err['params']) && count($err['params'])) {
         foreach ($err['params'] as $name => $val) {
             if (is_array($val)) {
                 // @ is needed in case $val is a multi-dimensional array
                 $val = @implode(', ', $val);
             }
             if (is_object($val)) {
                 if (method_exists($val, '__toString')) {
                     $val = $val->__toString();
                 } else {
                     PEAR_ErrorStack::staticPush('PEAR_ErrorStack', PEAR_ERRORSTACK_ERR_OBJTOSTRING, 'warning', array('obj' => get_class($val)), 'object %obj% passed into getErrorMessage, but has no __toString() method');
                     $val = 'Object';
                 }
             }
             $mainmsg = str_replace('%' . $name . '%', $val, $mainmsg);
         }
     }
     return $mainmsg;
 }
Exemplo n.º 24
0
 /**
  * Analyze the source code of the given PHP file
  *
  * @param  string Filename of the PHP file
  * @param  boolean whether to analyze $file as the file contents
  * @return mixed
  */
 function analyzeSourceCode($file, $string = false)
 {
     if (!function_exists("token_get_all")) {
         $this->_stack->push(__FUNCTION__, 'error', array('file' => $file), 'Parser error: token_get_all() function must exist to analyze source code, PHP may have been compiled with --disable-tokenizer');
         return false;
     }
     if (!defined('T_DOC_COMMENT')) {
         define('T_DOC_COMMENT', T_COMMENT);
     }
     if (!defined('T_INTERFACE')) {
         define('T_INTERFACE', -1);
     }
     if (!defined('T_IMPLEMENTS')) {
         define('T_IMPLEMENTS', -1);
     }
     if ($string) {
         $contents = $file;
     } else {
         if (!($fp = @fopen($file, "r"))) {
             return false;
         }
         fclose($fp);
         $contents = file_get_contents($file);
     }
     // Silence this function so we can catch PHP Warnings and show our own custom message
     $tokens = @token_get_all($contents);
     if (isset($php_errormsg)) {
         if (isset($this->_stack)) {
             $pn = $this->_pf->getPackage();
             $this->_stack->push(__FUNCTION__, 'warning', array('file' => $file, 'package' => $pn), 'in %file%: Could not process file for unkown reasons,' . ' possibly a PHP parse error in %file% from %package%');
         }
     }
     /*
             for ($i = 0; $i < sizeof($tokens); $i++) {
                 @list($token, $data) = $tokens[$i];
                 if (is_string($token)) {
                     var_dump($token);
                 } else {
                     print token_name($token) . ' ';
                     var_dump(rtrim($data));
                 }
             }
     */
     $look_for = 0;
     $paren_level = 0;
     $bracket_level = 0;
     $brace_level = 0;
     $lastphpdoc = '';
     $current_class = '';
     $current_interface = '';
     $current_class_level = -1;
     $current_function = '';
     $current_function_level = -1;
     $declared_classes = array();
     $declared_interfaces = array();
     $declared_functions = array();
     $declared_methods = array();
     $used_classes = array();
     $used_functions = array();
     $extends = array();
     $implements = array();
     $nodeps = array();
     $inquote = false;
     $interface = false;
     for ($i = 0; $i < sizeof($tokens); $i++) {
         if (is_array($tokens[$i])) {
             list($token, $data) = $tokens[$i];
         } else {
             $token = $tokens[$i];
             $data = '';
         }
         if ($inquote) {
             if ($token != '"' && $token != T_END_HEREDOC) {
                 continue;
             } else {
                 $inquote = false;
                 continue;
             }
         }
         switch ($token) {
             case T_WHITESPACE:
                 continue;
             case ';':
                 if ($interface) {
                     $current_function = '';
                     $current_function_level = -1;
                 }
                 break;
             case '"':
             case T_START_HEREDOC:
                 $inquote = true;
                 break;
             case T_CURLY_OPEN:
             case T_DOLLAR_OPEN_CURLY_BRACES:
             case '{':
                 $brace_level++;
                 continue 2;
             case '}':
                 $brace_level--;
                 if ($current_class_level == $brace_level) {
                     $current_class = '';
                     $current_class_level = -1;
                 }
                 if ($current_function_level == $brace_level) {
                     $current_function = '';
                     $current_function_level = -1;
                 }
                 continue 2;
             case '[':
                 $bracket_level++;
                 continue 2;
             case ']':
                 $bracket_level--;
                 continue 2;
             case '(':
                 $paren_level++;
                 continue 2;
             case ')':
                 $paren_level--;
                 continue 2;
             case T_INTERFACE:
                 $interface = true;
             case T_CLASS:
                 if ($current_class_level != -1 || $current_function_level != -1) {
                     if (isset($this->_stack)) {
                         $this->_stack->push(__FUNCTION__, 'error', array('file' => $file), 'Parser error: invalid PHP found in file "%file%"');
                     } else {
                         PEAR::raiseError("Parser error: invalid PHP found in file \"{$file}\"", PEAR_COMMON_ERROR_INVALIDPHP);
                     }
                     return false;
                 }
             case T_FUNCTION:
             case T_NEW:
             case T_EXTENDS:
             case T_IMPLEMENTS:
                 $look_for = $token;
                 continue 2;
             case T_STRING:
                 if (version_compare(zend_version(), '2.0', '<')) {
                     if (in_array(strtolower($data), array('public', 'private', 'protected', 'abstract', 'interface', 'implements', 'throw'))) {
                         if (isset($this->_stack)) {
                             $this->_stack->push(__FUNCTION__, 'warning', array('file' => $file), 'Error, PHP5 token encountered in %file%,' . ' analysis should be in PHP5');
                         } else {
                             PEAR::raiseError('Error: PHP5 token encountered in ' . $file . 'packaging should be done in PHP 5');
                             return false;
                         }
                     }
                 }
                 if ($look_for == T_CLASS) {
                     $current_class = $data;
                     $current_class_level = $brace_level;
                     $declared_classes[] = $current_class;
                 } elseif ($look_for == T_INTERFACE) {
                     $current_interface = $data;
                     $current_class_level = $brace_level;
                     $declared_interfaces[] = $current_interface;
                 } elseif ($look_for == T_IMPLEMENTS) {
                     $implements[$current_class] = $data;
                 } elseif ($look_for == T_EXTENDS) {
                     $extends[$current_class] = $data;
                 } elseif ($look_for == T_FUNCTION) {
                     if ($current_class) {
                         $current_function = "{$current_class}::{$data}";
                         $declared_methods[$current_class][] = $data;
                     } elseif ($current_interface) {
                         $current_function = "{$current_interface}::{$data}";
                         $declared_methods[$current_interface][] = $data;
                     } else {
                         $current_function = $data;
                         $declared_functions[] = $current_function;
                     }
                     $current_function_level = $brace_level;
                     $m = array();
                 } elseif ($look_for == T_NEW) {
                     $used_classes[$data] = true;
                 }
                 $look_for = 0;
                 continue 2;
             case T_VARIABLE:
                 $look_for = 0;
                 continue 2;
             case T_DOC_COMMENT:
             case T_COMMENT:
                 if (preg_match('!^/\\*\\*\\s!', $data)) {
                     $lastphpdoc = $data;
                     if (preg_match_all('/@nodep\\s+(\\S+)/', $lastphpdoc, $m)) {
                         $nodeps = array_merge($nodeps, $m[1]);
                     }
                 }
                 continue 2;
             case T_DOUBLE_COLON:
                 if (!($tokens[$i - 1][0] == T_WHITESPACE || $tokens[$i - 1][0] == T_STRING)) {
                     if (isset($this->_stack)) {
                         $this->_stack->push(__FUNCTION__, 'warning', array('file' => $file), 'Parser error: invalid PHP found in file "%file%"');
                     } else {
                         PEAR::raiseError("Parser error: invalid PHP found in file \"{$file}\"", PEAR_COMMON_ERROR_INVALIDPHP);
                     }
                     return false;
                 }
                 $class = $tokens[$i - 1][1];
                 if (strtolower($class) != 'parent') {
                     $used_classes[$class] = true;
                 }
                 continue 2;
         }
     }
     return array("source_file" => $file, "declared_classes" => $declared_classes, "declared_interfaces" => $declared_interfaces, "declared_methods" => $declared_methods, "declared_functions" => $declared_functions, "used_classes" => array_diff(array_keys($used_classes), $nodeps), "inheritance" => $extends, "implements" => $implements);
 }
Exemplo n.º 25
0
 /**
  * Get an instance of PEAR_ErrorStack.
  *
  * @return  object  PEAR_ErrorStack
  * @access  public
  * @static
  */
 public static function getStack()
 {
     if (!self::$_stack) {
         self::$_stack =& PEAR_ErrorStack::singleton('Services_HyperEstraier');
     }
     return self::$_stack;
 }
Exemplo n.º 26
0
 /**
  * Get an instance of PEAR_ErrorStack.
  *
  * @return  object  PEAR_ErrorStack
  * @access  public
  * @static
  */
 function &errorstack()
 {
     $stack =& PEAR_ErrorStack::singleton('EstraierPure');
     return $stack;
 }
Exemplo n.º 27
0
 /**
  * Updates the properties of the containers from the original source.
  *
  * @param bool if the auth container should be updated
  * @param bool if the perm container should be updated
  * @return bool true on success and false on failure
  *
  * @access public
  */
 function updateProperty($auth, $perm = null, $accountId = 0)
 {
     if (!is_a($this->_auth, 'LiveUser_Auth_Common')) {
         $this->stack->push(LIVEUSER_ERROR, 'error', array(), 'Cannot update container if no auth container instance is available');
         return false;
     }
     if ($auth && !$this->_auth->readUserData(null, null, $this->_auth->getProperty('auth_user_id'), $accountId)) {
         return false;
     }
     if (is_null($perm)) {
         $perm = is_a($this->_perm, 'LiveUser_Perm_Simple');
     }
     if ($perm) {
         if (!is_a($this->_perm, 'LiveUser_Perm_Simple')) {
             $this->stack->push(LIVEUSER_ERROR, 'error', array(), 'Cannot update container if no perm container instance is available');
             return false;
         }
         if (!$this->_perm->mapUser($this->_auth->getProperty('auth_user_id'), $this->_auth->containerName)) {
             return false;
         }
     }
     $this->_freeze();
     return true;
 }
Exemplo n.º 28
0
 /**
  * Executes the constructed VersionControl_SVN instance
  *
  * @param array Additional arguments to pass to SVN.
  * @param array Switches to pass to SVN.
  * @return string Output generated by SVN.
  */
 protected function run($args = array(), $switches = array())
 {
     $svnstack = PEAR_ErrorStack::singleton('VersionControl_SVN');
     $tempArgs = $this->svnArgs;
     $tempArgs = array_merge($tempArgs, $args);
     $tempSwitches = $this->svnSwitches;
     $tempSwitches = array_merge($tempSwitches, $switches);
     if ($output = $this->svn->run($tempArgs, $tempSwitches)) {
         return $output;
     } else {
         if (count($errs = $svnstack->getErrors())) {
             $err = current($errs);
             throw new BuildException("Failed to run the 'svn " . $this->mode . "' command: " . $err['params']['errstr']);
         }
     }
 }
Exemplo n.º 29
0
 /**
  * Validation warning.  Does not mark the object contents invalid.
  * @param error code
  * @param array error information
  * @access private
  */
 function _validateWarning($code, $params = array())
 {
     $this->_stack->push($code, 'warning', $params);
 }
Exemplo n.º 30
-1
 /**
  * updates the properties of the containers from the original source
  *
  * @param  boolean $auth if the auth container should be updated
  * @param  boolean $perm if the perm container should be updated
  * @return boolean
  *
  * @access public
  */
 function updateProperty($auth, $perm = null)
 {
     if (!is_a($this->_auth, 'LiveUser_Auth_Common')) {
         $this->_stack->push(LIVEUSER_ERROR, 'error', array(), 'Cannot update container if no auth container instance is available');
         return false;
     }
     if ($auth && !$this->_auth->readUserData('', '', true)) {
         return false;
     }
     if (is_null($perm)) {
         $perm = is_a($this->_perm, 'LiveUser_Perm_Simple');
     }
     if ($perm) {
         if (!is_a($this->_perm, 'LiveUser_Perm_Simple')) {
             $this->_stack->push(LIVEUSER_ERROR, 'error', array(), 'Cannot update container if no perm container instance is available');
             return false;
         }
         if (!$this->_perm->mapUser($this->_auth->getProperty('auth_user_id'), $this->_auth->backendArrayIndex)) {
             return false;
         }
     }
     return true;
 }