Exemplo n.º 1
0
 function check_plugin_dependencies($plugin_name, $force_inclusion = FALSE)
 {
     $dependencies = get_plugin_dependencies($plugin_name, $force_inclusion);
     if (!$dependencies) {
         return TRUE;
     }
     if ($dependencies === SQ_INCOMPATIBLE) {
         return $dependencies;
     }
     $missing_or_bad = array();
     foreach ($dependencies as $depend_name => $depend_requirements) {
         // check for core plugins first
         //
         if (strpos(strtoupper($depend_requirements['version']), 'CORE') === 0) {
             // see if the plugin is in the core (just check if the directory exists)
             //
             if (!file_exists(SM_PATH . 'plugins/' . $depend_name)) {
                 $missing_or_bad[$depend_name] = $depend_requirements;
             } else {
                 if ($depend_requirements['activate'] && !is_plugin_enabled($depend_name)) {
                     $missing_or_bad[$depend_name] = $depend_requirements;
                 } else {
                     if (strpos($depend_requirements['version'], ':') !== FALSE) {
                         $version = explode('.', substr($depend_requirements['version'], strpos($depend_requirements['version'], ':') + 1), 3);
                         $version[0] = intval($version[0]);
                         if (isset($version[1])) {
                             $version[1] = intval($version[1]);
                         } else {
                             $version[1] = 0;
                         }
                         if (isset($version[2])) {
                             $version[2] = intval($version[2]);
                         } else {
                             $version[2] = 0;
                         }
                         if (!check_sm_version($version[0], $version[1], $version[2])) {
                             $missing_or_bad[$depend_name] = $depend_requirements;
                         }
                     }
                 }
             }
             continue;
         }
         // if the plugin is actually incompatible; check that it
         // is not activated
         //
         if ($depend_requirements['version'] == SQ_INCOMPATIBLE) {
             if (is_plugin_enabled($depend_name)) {
                 $missing_or_bad[$depend_name] = $depend_requirements;
             }
             continue;
         }
         // check for normal plugins
         //
         $version = explode('.', $depend_requirements['version'], 3);
         $version[0] = intval($version[0]);
         if (isset($version[1])) {
             $version[1] = intval($version[1]);
         } else {
             $version[1] = 0;
         }
         if (isset($version[2])) {
             $version[2] = intval($version[2]);
         } else {
             $version[2] = 0;
         }
         $force_dependency_inclusion = !$depend_requirements['activate'];
         if (!check_plugin_version($depend_name, $version[0], $version[1], $version[2], $force_dependency_inclusion)) {
             $missing_or_bad[$depend_name] = $depend_requirements;
         }
     }
     if (empty($missing_or_bad)) {
         return TRUE;
     }
     // get non-parsed required versions
     //
     $non_parsed_dependencies = get_plugin_dependencies($plugin_name, $force_inclusion, FALSE);
     $return_array = array();
     foreach ($missing_or_bad as $depend_name => $ignore) {
         $return_array[$depend_name] = $non_parsed_dependencies[$depend_name];
     }
     return $return_array;
 }
Exemplo n.º 2
0
 * Demo plugin 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.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Demo plugin; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * @version $Id$
 * @package plugins
 * @subpackage demo
 */
/** SquirrelMail init */
if (file_exists('../../include/init.php')) {
    /* sm 1.5.2+*/
    include_once '../../include/init.php';
} else {
    /* sm 1.4.0+ */
    /** @ignore */
    define('SM_PATH', '../../');
    /* main init script */
    include_once SM_PATH . 'include/validate.php';
}
displayPageHeader($color, 'None');
var_dump(defined('SMDEMO'));
if (check_sm_version(1, 5, 1)) {
    $oTemplate->display('footer.tpl');
} else {
    echo '</body></html>';
}
Exemplo n.º 3
0
/**
 * Determines what plugin hook is currently executing,
 * if any, in a SquirrelMail version-independent fashion.
 *
 * @param mixed $args The current plugin function argument,
 *                    which must be exactly as received by
 *                    the plugin function that is calling
 *                    this code.
 *
 * @return string The name of the currently executing plugin
 *                hook, or an empty string if either no hook
 *                is running or the hook name could not be
 *                determined.
 *
 */
function get_current_hook_name($args = '')
{
    if (check_sm_version(1, 5, 1)) {
        global $currentHookName;
        if (!empty($currentHookName)) {
            return $currentHookName;
        }
    }
    //TODO: should we ALWAYS backtrace instead of assuming that $args[0] is the hook name?
    if (!empty($args[0]) && is_string($args[0])) {
        return $args[0];
    } else {
        // plugin args not given or didn't have a hook
        // name in them, so try backtracing instead
        //
        $backtrace = debug_backtrace();
        foreach ($backtrace as $trace) {
            if ($trace['function'] == 'do_hook' || $trace['function'] == 'do_hook_function' || $trace['function'] == 'concat_hook_function' || $trace['function'] == 'boolean_hook_function') {
                return $trace['args'][0];
            }
        }
        // nothing found at all
        //
        return '';
    }
}
Exemplo n.º 4
0
/**
 * Main function attached to options_identities_table hook
 * @return string html formated  table rows added to identity table
 */
function demo_options_identities_table_do(&$args)
{
    global $demo_id;
    // first key in $args - color or style - string type
    if (!isset($args[0]) || empty($args[0])) {
        // is not set or empty string
        $bgstyle = '';
    } elseif (check_sm_version(1, 5, 1) || check_sm_version(1, 4, 5) && !check_sm_version(1, 5, 0)) {
        // row style (1.4.5+ and 1.5.1+, not in 1.5.0)
        $bgstyle = $args[0];
    } else {
        // background color (1.4.4 or older and 1.5.0)
        $bgstyle = 'bgcolor="' . $args[0] . '"';
    }
    // switch gettext domain
    bindtextdomain('demo', SM_PATH . 'locale');
    textdomain('demo');
    // second key - is hook called by new id form or id form is empty - boolean type
    if ($args[1]) {
        $suffix = _("This new id");
    } else {
        $suffix = _("This existing id");
    }
    // third key - identity number or null (default id) - integer type.
    $id = (int) $args[2];
    // FIXME: can be broken if SMPREF_NONE is int 0. SquirrelMail 1.4.0-1.4.5 uses string 'none'
    if ($demo_id !== SMPREF_NONE && $demo_id == $id) {
        $checked = ' checked="checked"';
    } else {
        $checked = '';
    }
    $ret = html_tag('tr', html_tag('td', _("Set as demo identity:"), 'right') . html_tag('td', '<input type="radio" name="demo_id_select" value="' . $id . '"' . $checked . '>&nbsp;' . $suffix, 'left'), '', '', $bgstyle);
    // revert gettext domain
    bindtextdomain('squirrelmail', SM_PATH . 'locale');
    textdomain('squirrelmail');
    return $ret;
}