Example #1
0
function mediashare_sourcesapi_scanSources()
{
    // Check access
    if (!SecurityUtil::checkPermission('mediashare::', '::', ACCESS_ADMIN)) {
        return LogUtil::registerPermissionError();
    }
    $dom = ZLanguage::getModuleDomain('mediashare');
    // Clear existing sources table
    if (!DBUtil::truncateTable('mediashare_sources')) {
        return LogUtil::registerError(__f('Error in %1$s: %2$s.', array('sourcesapi.scanSources', __f("Could not clear the '%s' table.", 'sources', $dom)), $dom));
    }
    // Scan for sources APIs
    $files = FileUtil::getFiles('modules/mediashare', false, true, 'php', 'f');
    foreach ($files as $file) {
        if (preg_match('/^pnsource_([-a-zA-Z0-9_]+)api.php$/', $file, $matches)) {
            $sourceName = $matches[1];
            $sourceApi = "source_{$sourceName}";
            // Force load - it is used during pninit
            pnModAPILoad('mediashare', $sourceApi, true);
            if (!($title = pnModAPIFunc('mediashare', $sourceApi, 'getTitle'))) {
                return false;
            }
            if (!pnModAPIFunc('mediashare', 'sources', 'addSource', array('title' => $title, 'name' => $sourceName))) {
                return false;
            }
        }
    }
    return true;
}
Example #2
0
function mediashare_source_zip_view(&$args)
{
    $albumId = mediashareGetIntUrl('aid', $args, 0);
    if (isset($_POST['saveButton'])) {
        return mediashareSourceZipUpload($args);
    }
    if (isset($_POST['moreButton']) || isset($_POST['continueButton'])) {
        // After upload - update items and then continue to next page
        if (!mediashareSourceZipUpdate()) {
            return false;
        }
    }
    if (isset($_POST['cancelButton']) || isset($_POST['continueButton'])) {
        return pnRedirect(pnModURL('mediashare', 'edit', 'view', array('aid' => $albumId)));
    }
    if (isset($_POST['moreButton'])) {
        return pnRedirect(pnModURL('mediashare', 'edit', 'addmedia', array('aid' => $albumId, 'source' => 'zip')));
    }
    // FIXME Required globals??
    pnModAPILoad('mediashare', 'edit');
    $uploadInfo = pnModAPIFunc('mediashare', 'source_zip', 'getUploadInfo');
    $render =& pnRender::getInstance('mediashare', false);
    $render->assign('imageNum', 1);
    $render->assign('uploadFields', array(1));
    $render->assign('post_max_size', $uploadInfo['post_max_size']);
    $render->assign('upload_max_filesize', $uploadInfo['upload_max_filesize']);
    return $render->fetch('mediashare_source_zip_view.html');
}
Example #3
0
/**
 * Scan for all media
 */
function mediashare_adminapi_scanAllPlugins()
{
    // Force load - it is used during pninit
    pnModAPILoad('mediashare', 'mediahandler', true);
    if (!pnModAPIFunc('mediashare', 'mediahandler', 'scanMediaHandlers')) {
        return false;
    }
    // Force load - it is used during pninit
    pnModAPILoad('mediashare', 'sources', true);
    return pnModAPIFunc('mediashare', 'sources', 'scanSources');
}
Example #4
0
function mediashare_mediahandlerapi_scanMediaHandlers()
{
    // Check access
    if (!SecurityUtil::checkPermission('mediashare::', '::', ACCESS_ADMIN)) {
        return LogUtil::registerPermissionError();
    }
    $dom = ZLanguage::getModuleDomain('mediashare');
    // Clear existing handler table
    if (!DBUtil::truncateTable('mediashare_mediahandlers')) {
        return LogUtil::registerError(__f('Error in %1$s: %2$s.', array('mediahandlerapi.scanMediaHandlers', __f("Could not clear the '%s' table.", 'mediahandlers', $dom)), $dom));
    }
    // Scan for handlers APIs
    $files = FileUtil::getFiles('modules/mediashare', false, true, 'php', 'f');
    foreach ($files as $file) {
        if (preg_match('/^pnmedia_([-a-zA-Z0-9_]+)api.php$/', $file, $matches)) {
            $handlerName = $matches[1];
            $handlerApi = "media_{$handlerName}";
            // Force load - it is used during pninit
            pnModAPILoad('mediashare', $handlerApi, true);
            if (!($handler = pnModAPIFunc('mediashare', $handlerApi, 'buildHandler'))) {
                return false;
            }
            $fileTypes = $handler->getMediaTypes();
            foreach ($fileTypes as $fileType) {
                $fileType['handler'] = $handlerName;
                $fileType['title'] = $handler->getTitle();
                if (!pnModAPIFunc('mediashare', 'mediahandler', 'addMediaHandler', $fileType)) {
                    return false;
                }
            }
        }
    }
    return true;
}
Example #5
0
 *  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 this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *  To read the license please read the docs/license.txt or visit
 *  http://www.gnu.org/copyleft/gpl.html
 *
 */
//=========================================================================
//  Load the API Functions and Language defines
//=========================================================================
pnModAPILoad(__POSTCALENDAR__, 'user');
// Added to improve security and standardization of input data to be used in
//  database insertion.
require_once $GLOBALS['srcdir'] . "/formdata.inc.php";
//=========================================================================
//  start the main postcalendar application
//=========================================================================
function postcalendar_user_main()
{
    // check the authorization
    if (!pnSecAuthAction(0, 'PostCalendar::', '::', ACCESS_OVERVIEW)) {
        return _POSTCALENDARNOAUTH;
    }
    // get the date and go to the view function
    $Date = postcalendar_getDate();
    return postcalendar_user_view(array('Date' => $Date));
Example #6
0
function postcalendar_admin_submit($args)
{
    if (!PC_ACCESS_ADMIN) {
        return _POSTCALENDAR_NOAUTH;
    }
    pnModAPILoad(__POSTCALENDAR__, 'user');
    $output = postcalendar_adminmenu();
    // get the theme globals :: is there a better way to do this?
    pnThemeLoad(pnUserGetTheme());
    global $bgcolor1, $bgcolor2, $bgcolor3, $bgcolor4, $bgcolor5, $textcolor1, $textcolor2;
    extract($args);
    $Date = postcalendar_getDate();
    $year = substr($Date, 0, 4);
    $month = substr($Date, 4, 2);
    $day = substr($Date, 6, 2);
    // basic event information
    $event_subject = pnVarCleanFromInput('event_subject');
    $event_desc = pnVarCleanFromInput('event_desc');
    $event_sharing = pnVarCleanFromInput('event_sharing');
    $event_category = pnVarCleanFromInput('event_category');
    $event_topic = pnVarCleanFromInput('event_topic');
    // event start information
    $event_startmonth = pnVarCleanFromInput('event_startmonth');
    $event_startday = pnVarCleanFromInput('event_startday');
    $event_startyear = pnVarCleanFromInput('event_startyear');
    $event_starttimeh = pnVarCleanFromInput('event_starttimeh');
    $event_starttimem = pnVarCleanFromInput('event_starttimem');
    $event_startampm = pnVarCleanFromInput('event_startampm');
    // event end information
    $event_endmonth = pnVarCleanFromInput('event_endmonth');
    $event_endday = pnVarCleanFromInput('event_endday');
    $event_endyear = pnVarCleanFromInput('event_endyear');
    $event_endtype = pnVarCleanFromInput('event_endtype');
    $event_dur_hours = pnVarCleanFromInput('event_dur_hours');
    $event_dur_minutes = pnVarCleanFromInput('event_dur_minutes');
    $event_duration = 60 * 60 * $event_dur_hours + 60 * $event_dur_minutes;
    $event_allday = pnVarCleanFromInput('event_allday');
    // location data
    $event_location = pnVarCleanFromInput('event_location');
    $event_street1 = pnVarCleanFromInput('event_street1');
    $event_street2 = pnVarCleanFromInput('event_street2');
    $event_city = pnVarCleanFromInput('event_city');
    $event_state = pnVarCleanFromInput('event_state');
    $event_postal = pnVarCleanFromInput('event_postal');
    $event_location_info = serialize(compact('event_location', 'event_street1', 'event_street2', 'event_city', 'event_state', 'event_postal'));
    // contact data
    $event_contname = pnVarCleanFromInput('event_contname');
    $event_conttel = pnVarCleanFromInput('event_conttel');
    $event_contemail = pnVarCleanFromInput('event_contemail');
    $event_website = pnVarCleanFromInput('event_website');
    $event_fee = pnVarCleanFromInput('event_fee');
    // event repeating data
    $event_repeat = pnVarCleanFromInput('event_repeat');
    $event_repeat_freq = pnVarCleanFromInput('event_repeat_freq');
    $event_repeat_freq_type = pnVarCleanFromInput('event_repeat_freq_type');
    $event_repeat_on_num = pnVarCleanFromInput('event_repeat_on_num');
    $event_repeat_on_day = pnVarCleanFromInput('event_repeat_on_day');
    $event_repeat_on_freq = pnVarCleanFromInput('event_repeat_on_freq');
    $event_recurrspec = serialize(compact('event_repeat_freq', 'event_repeat_freq_type', 'event_repeat_on_num', 'event_repeat_on_day', 'event_repeat_on_freq'));
    $pc_html_or_text = pnVarCleanFromInput('pc_html_or_text');
    $form_action = pnVarCleanFromInput('form_action');
    $pc_event_id = pnVarCleanFromInput('pc_event_id');
    $data_loaded = pnVarCleanFromInput('data_loaded');
    $is_update = pnVarCleanFromInput('is_update');
    $authid = pnVarCleanFromInput('authid');
    if (pnUserLoggedIn()) {
        $uname = pnUserGetVar('uname');
    } else {
        $uname = pnConfigGetVar('anonymous');
    }
    if (!isset($event_repeat)) {
        $event_repeat = 0;
    }
    // lets wrap all the data into array for passing to submit and preview functions
    if (!isset($pc_event_id) || empty($pc_event_id) || $data_loaded) {
        $eventdata = compact('event_subject', 'event_desc', 'event_sharing', 'event_category', 'event_topic', 'event_startmonth', 'event_startday', 'event_startyear', 'event_starttimeh', 'event_starttimem', 'event_startampm', 'event_endmonth', 'event_endday', 'event_endyear', 'event_endtype', 'event_dur_hours', 'event_dur_minutes', 'event_duration', 'event_allday', 'event_location', 'event_street1', 'event_street2', 'event_city', 'event_state', 'event_postal', 'event_location_info', 'event_contname', 'event_conttel', 'event_contemail', 'event_website', 'event_fee', 'event_repeat', 'event_repeat_freq', 'event_repeat_freq_type', 'event_repeat_on_num', 'event_repeat_on_day', 'event_repeat_on_freq', 'event_recurrspec', 'uname', 'Date', 'year', 'month', 'day', 'pc_html_or_text');
        $eventdata['is_update'] = $is_update;
        $eventdata['pc_event_id'] = $pc_event_id;
        $eventdata['data_loaded'] = true;
    } else {
        $event = postcalendar_userapi_pcGetEventDetails($pc_event_id);
        $eventdata['event_subject'] = $event['title'];
        $eventdata['event_desc'] = $event['hometext'];
        $eventdata['event_sharing'] = $event['sharing'];
        $eventdata['event_category'] = $event['catid'];
        $eventdata['event_topic'] = $event['topic'];
        $eventdata['event_startmonth'] = substr($event['eventDate'], 5, 2);
        $eventdata['event_startday'] = substr($event['eventDate'], 8, 2);
        $eventdata['event_startyear'] = substr($event['eventDate'], 0, 4);
        $eventdata['event_starttimeh'] = substr($event['startTime'], 0, 2);
        $eventdata['event_starttimem'] = substr($event['startTime'], 3, 2);
        $eventdata['event_startampm'] = $eventdata['event_starttimeh'] < 12 ? _PC_AM : _PC_PM;
        $eventdata['event_endmonth'] = substr($event['endDate'], 5, 2);
        $eventdata['event_endday'] = substr($event['endDate'], 8, 2);
        $eventdata['event_endyear'] = substr($event['endDate'], 0, 4);
        $eventdata['event_endtype'] = $event['endDate'] == '0000-00-00' ? '0' : '1';
        $eventdata['event_dur_hours'] = $event['duration_hours'];
        $eventdata['event_dur_minutes'] = $event['duration_minutes'];
        $eventdata['event_duration'] = $event['duration'];
        $eventdata['event_allday'] = $event['alldayevent'];
        $loc_data = unserialize($event['location']);
        $eventdata['event_location'] = $loc_data['event_location'];
        $eventdata['event_street1'] = $loc_data['event_street1'];
        $eventdata['event_street2'] = $loc_data['event_street2'];
        $eventdata['event_city'] = $loc_data['event_city'];
        $eventdata['event_state'] = $loc_data['event_state'];
        $eventdata['event_postal'] = $loc_data['event_postal'];
        $eventdata['event_location_info'] = $loc_data;
        $eventdata['event_contname'] = $event['contname'];
        $eventdata['event_conttel'] = $event['conttel'];
        $eventdata['event_contemail'] = $event['contemail'];
        $eventdata['event_website'] = $event['website'];
        $eventdata['event_fee'] = $event['fee'];
        $eventdata['event_repeat'] = $event['recurrtype'];
        $eventdata['event_pid'] = $event['pid'];
        $eventdata['event_aid'] = $event['aid'];
        $rspecs = unserialize($event['recurrspec']);
        $eventdata['event_repeat_freq'] = $rspecs['event_repeat_freq'];
        $eventdata['event_repeat_freq_type'] = $rspecs['event_repeat_freq_type'];
        $eventdata['event_repeat_on_num'] = $rspecs['event_repeat_on_num'];
        $eventdata['event_repeat_on_day'] = $rspecs['event_repeat_on_day'];
        $eventdata['event_repeat_on_freq'] = $rspecs['event_repeat_on_freq'];
        $eventdata['event_recurrspec'] = $rspecs;
        $eventdata['uname'] = $uname;
        $eventdata['Date'] = $Date;
        $eventdata['year'] = $year;
        $eventdata['month'] = $month;
        $eventdata['day'] = $day;
        $eventdata['is_update'] = true;
        $eventdata['pc_event_id'] = $pc_event_id;
        $eventdata['data_loaded'] = true;
        $eventdata['pc_html_or_text'] = $pc_html_or_text;
    }
    // lets get the module's information
    $modinfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
    $categories = pnModAPIFunc(__POSTCALENDAR__, 'user', 'getCategories');
    //================================================================
    //	ERROR CHECKING
    //================================================================
    $required_vars = array('event_subject', 'event_desc');
    $required_name = array(_PC_EVENT_TITLE, _PC_EVENT_DESC);
    $error_msg = '';
    $reqCount = count($required_vars);
    for ($r = 0; $r < $reqCount; $r++) {
        if (empty(${$required_vars}[$r]) || !preg_match('/\\S/i', ${$required_vars}[$r])) {
            $error_msg .= '<b>' . $required_name[$r] . '</b> ' . _PC_SUBMIT_ERROR4 . '<br />';
        }
    }
    unset($reqCount);
    // check repeating frequencies
    if ($event_repeat == REPEAT) {
        if (!isset($event_repeat_freq) || $event_repeat_freq < 1 || empty($event_repeat_freq)) {
            $error_msg .= _PC_SUBMIT_ERROR5 . '<br />';
        } elseif (!is_numeric($event_repeat_freq)) {
            $error_msg .= _PC_SUBMIT_ERROR6 . '<br />';
        }
    } elseif ($event_repeat == REPEAT_ON) {
        if (!isset($event_repeat_on_freq) || $event_repeat_on_freq < 1 || empty($event_repeat_on_freq)) {
            $error_msg .= _PC_SUBMIT_ERROR5 . '<br />';
        } elseif (!is_numeric($event_repeat_on_freq)) {
            $error_msg .= _PC_SUBMIT_ERROR6 . '<br />';
        }
    }
    // check date validity
    if (_SETTING_TIME_24HOUR) {
        $startTime = $event_starttimeh . ':' . $event_starttimem;
        $endTime = $event_endtimeh . ':' . $event_endtimem;
    } else {
        if ($event_startampm == _AM_VAL) {
            $event_starttimeh = $event_starttimeh == 12 ? '00' : $event_starttimeh;
        } else {
            $event_starttimeh = $event_starttimeh != 12 ? $event_starttimeh += 12 : $event_starttimeh;
        }
        $startTime = $event_starttimeh . ':' . $event_starttimem;
    }
    $sdate = strtotime($event_startyear . '-' . $event_startmonth . '-' . $event_startday);
    $edate = strtotime($event_endyear . '-' . $event_endmonth . '-' . $event_endday);
    $tdate = strtotime(date('Y-m-d'));
    if ($edate < $sdate && $event_endtype == 1) {
        $error_msg .= _PC_SUBMIT_ERROR1 . '<br />';
    }
    if (!checkdate($event_startmonth, $event_startday, $event_startyear)) {
        $error_msg .= _PC_SUBMIT_ERROR2 . '<br />';
    }
    if (!checkdate($event_endmonth, $event_endday, $event_endyear)) {
        $error_msg .= _PC_SUBMIT_ERROR3 . '<br />';
    }
    //================================================================
    //	Preview the event
    //================================================================
    if ($form_action == 'preview') {
        if (!empty($error_msg)) {
            $preview = false;
            $output .= '<table border="0" width="100%" cellpadding="1" cellspacing="0"><tr><td bgcolor="red">';
            $output .= '<table border="0" width="100%" cellpadding="1" cellspacing="0"><tr><td bgcolor="pink">';
            $output .= '<center><b>' . _PC_SUBMIT_ERROR . '</b></center>';
            $output .= '<br />';
            $output .= $error_msg;
            $output .= '</td></td></table>';
            $output .= '</td></td></table>';
            $output .= '<br /><br />';
        } else {
            $output .= pnModAPIFunc(__POSTCALENDAR__, 'user', 'eventPreview', $eventdata);
            $output .= '<br />';
        }
    }
    //================================================================
    //	Enter the event into the DB
    //================================================================
    if ($form_action == 'commit') {
        //if (!pnSecConfirmAuthKey()) { return(_NO_DIRECT_ACCESS); }
        if (!empty($error_msg)) {
            $preview = false;
            $output .= '<table border="0" width="100%" cellpadding="1" cellspacing="0"><tr><td bgcolor="red">';
            $output .= '<table border="0" width="100%" cellpadding="1" cellspacing="0"><tr><td bgcolor="pink">';
            $output .= '<center><b>' . _PC_SUBMIT_ERROR . '</b></center>';
            $output .= '<br />';
            $output .= $error_msg;
            $output .= '</td></td></table>';
            $output .= '</td></td></table>';
            $output .= '<br /><br />';
        } else {
            if (!pnModAPIFunc(__POSTCALENDAR__, 'admin', 'submitEvent', $eventdata)) {
                $output .= '<center><div style="padding:5px; border:1px solid red; background-color: pink;">';
                $output .= "<b>" . _PC_EVENT_SUBMISSION_FAILED . "</b>";
                $output .= '</div></center><br />';
                $output .= '<br />';
            } else {
                // clear the Smarty cache
                $tpl = new pcSmarty();
                $tpl->clear_all_cache();
                $output .= '<center><div style="padding:5px; border:1px solid green; background-color: lightgreen;">';
                if ($is_update) {
                    $output .= "<b>" . _PC_EVENT_EDIT_SUCCESS . "</b>";
                } else {
                    $output .= "<b>" . _PC_EVENT_SUBMISSION_SUCCESS . "</b>";
                }
                $output .= '</div></center><br />';
                $output .= '<br />';
                // clear the form vars
                $event_subject = $event_desc = $event_sharing = $event_category = $event_topic = $event_startmonth = $event_startday = $event_startyear = $event_starttimeh = $event_starttimem = $event_startampm = $event_endmonth = $event_endday = $event_endyear = $event_endtype = $event_dur_hours = $event_dur_minutes = $event_duration = $event_allday = $event_location = $event_street1 = $event_street2 = $event_city = $event_state = $event_postal = $event_location_info = $event_contname = $event_conttel = $event_contemail = $event_website = $event_fee = $event_repeat = $event_repeat_freq = $event_repeat_freq_type = $event_repeat_on_num = $event_repeat_on_day = $event_repeat_on_freq = $event_recurrspec = $uname = $Date = $year = $month = $day = $pc_html_or_text = null;
                $is_update = false;
                $pc_event_id = 0;
                // lets wrap all the data into array for passing to submit and preview functions
                $eventdata = compact('event_subject', 'event_desc', 'event_sharing', 'event_category', 'event_topic', 'event_startmonth', 'event_startday', 'event_startyear', 'event_starttimeh', 'event_starttimem', 'event_startampm', 'event_endmonth', 'event_endday', 'event_endyear', 'event_endtype', 'event_dur_hours', 'event_dur_minutes', 'event_duration', 'event_allday', 'event_location', 'event_street1', 'event_street2', 'event_city', 'event_state', 'event_postal', 'event_location_info', 'event_contname', 'event_conttel', 'event_contemail', 'event_website', 'event_fee', 'event_repeat', 'event_repeat_freq', 'event_repeat_freq_type', 'event_repeat_on_num', 'event_repeat_on_day', 'event_repeat_on_freq', 'event_recurrspec', 'uname', 'Date', 'year', 'month', 'day', 'pc_html_or_text', 'is_update', 'pc_event_id');
            }
        }
    }
    $output .= pnModAPIFunc('PostCalendar', 'admin', 'buildSubmitForm', $eventdata);
    return $output;
}
Example #7
0
/**
 * carry out hook operations for module
 * @param hookobject the object the hook is called for - either 'item' or 'category'
 * @param hookaction the action the hook is called for - one of 'create', 'delete', 'transform', or 'display'
 * @param hookid the id of the object the hook is called for (module-specific)
 * @param extrainfo extra information for the hook, dependent on hookaction
 * @returns string
 * @return output from hooks
 */
function pnModCallHooks($hookobject, $hookaction, $hookid, $extrainfo)
{
    // Get database info
    list($dbconn) = pnDBGetConn();
    $pntable = pnDBGetTables();
    $hookstable = $pntable['hooks'];
    $hookscolumn =& $pntable['hooks_column'];
    // Get applicable hooks
    $sql = "SELECT {$hookscolumn['tarea']},\n                   {$hookscolumn['tmodule']},\n                   {$hookscolumn['ttype']},\n                   {$hookscolumn['tfunc']}\n            FROM {$hookstable}\n            WHERE {$hookscolumn['smodule']} = '" . pnVarPrepForStore(pnModGetName()) . "'\n            AND {$hookscolumn['object']} = '" . pnVarPrepForStore($hookobject) . "'\n            AND {$hookscolumn['action']} = '" . pnVarPrepForStore($hookaction) . "'";
    $result = $dbconn->Execute($sql);
    if ($dbconn->ErrorNo() != 0) {
        return null;
    }
    $output = '';
    // Call each hook
    for (; !$result->EOF; $result->MoveNext()) {
        list($hookarea, $hookmodule, $hooktype, $hookfunc) = $result->fields;
        if ($hookarea == 'GUI') {
            if (pnModAvailable($hookmodule, $hooktype) && pnModLoad($hookmodule, $hooktype)) {
                $output .= pnModFunc($hookmodule, $hooktype, $hookfunc, array('objectid' => $hookid, 'extrainfo' => $extrainfo));
            }
        } else {
            if (pnModAvailable($hookmodule, $hooktype) && pnModAPILoad($hookmodule, $hooktype)) {
                $extrainfo = pnModAPIFunc($hookmodule, $hooktype, $hookfunc, array('objectid' => $hookid, 'extrainfo' => $extrainfo));
            }
        }
    }
    if ($hookaction == 'display') {
        return $output;
    } else {
        return $extrainfo;
    }
}
Example #8
0
 *
 *  To read the license please read the docs/license.txt or visit
 *  http://www.gnu.org/copyleft/gpl.html
 *
 */
// grab the form variables
$tplview = pnVarCleanFromInput('tplview');
$viewtype = pnVarCleanFromInput('viewtype');
$eid = pnVarCleanFromInput('eid');
$Date = pnVarCleanFromInput('Date');
$print = pnVarCleanFromInput('print');
$uid = pnUserGetVar('uid');
$pc_username = pnVarCleanFromInput('pc_username');
$output =& new pnHTML();
$output->SetInputMode(_PNH_VERBATIMINPUT);
if (!pnModAPILoad('postcalendar', 'user')) {
    die('Could not load PostCalendar user API');
}
$theme = pnUserGetTheme();
if (!pnThemeLoad($theme)) {
    die('Could not load theme');
}
$output->Text('<html><head>');
$output->Text("<title>" . pnConfigGetVar('sitename') . ' :: ' . pnConfigGetVar('slogan') . "</title>\n");
$output->Text('<link rel="StyleSheet" href="themes/' . $theme . '/style/styleNN.css" type="text/css" />');
$output->Text('<style type="text/css">@import url("themes/' . $theme . '/style/style.css"); </style>');
$output->Text('</head>');
$output->Text('<body bgcolor="#ffffff">');
// setup our cache id
$cacheid = md5($Date . $viewtype . $tplview . _SETTING_TEMPLATE . $eid . $print . $uid . $pc_username . $theme);
// display the correct view
Example #9
0
/**
 * carry out hook operations for module
 * @author Jim McDonald <*****@*****.**>
 * @link http://www.mcdee.net
 * @param 'hookobject' the object the hook is called for - one of 'item', 'category' or 'module'
 * @param 'hookaction' the action the hook is called for - one of 'new', 'create', 'modify', 'update', 'delete', 'transform', 'display', 'modifyconfig', 'updateconfig'
 * @param 'hookid' the id of the object the hook is called for (module-specific)
 * @param 'extrainfo' extra information for the hook, dependent on hookaction
 * @param 'implode' implode collapses all display hooks into a single string - default to true for compatability with .7x
 * @return mixed string output from GUI hooks, extrainfo array for API hooks
 */
function pnModCallHooks($hookobject, $hookaction, $hookid, $extrainfo = array(), $implode = true)
{
    static $modulehooks;
    if (!isset($hookaction)) {
        return null;
    }
    if (isset($extrainfo['module']) && (pnModAvailable($extrainfo['module']) || strtolower($hookobject) == 'module')) {
        $modname = $extrainfo['module'];
    } else {
        $modname = pnModGetName();
    }
    if (!isset($modulehooks[strtolower($modname)])) {
        // Get database info
        $dbconn =& pnDBGetConn(true);
        $pntable =& pnDBGetTables();
        $hookstable = $pntable['hooks'];
        $hookscolumn =& $pntable['hooks_column'];
        // Get applicable hooks
        $sql = "SELECT {$hookscolumn['tarea']},\n\t\t\t\t\t   {$hookscolumn['tmodule']},\n\t\t\t\t\t   {$hookscolumn['ttype']},\n\t\t\t\t\t   {$hookscolumn['tfunc']},\n\t\t\t\t\t   {$hookscolumn['action']},\n\t\t\t\t\t   {$hookscolumn['object']}\n\t\t\t\tFROM {$hookstable}\n\t\t\t\tWHERE {$hookscolumn['smodule']} = '" . pnVarPrepForStore($modname) . "'";
        $result =& $dbconn->Execute($sql);
        if ($dbconn->ErrorNo() != 0) {
            return null;
        }
        $hooks = array();
        for (; !$result->EOF; $result->MoveNext()) {
            list($area, $module, $type, $func, $action, $object) = $result->fields;
            $hooks[] = array('area' => $area, 'module' => $module, 'type' => $type, 'func' => $func, 'action' => $action, 'object' => $object);
        }
        $modulehooks[strtolower($modname)] = $hooks;
    }
    $gui = false;
    $output = array();
    // Call each hook
    foreach ($modulehooks[strtolower($modname)] as $modulehook) {
        if ($modulehook['action'] == $hookaction && $modulehook['object'] == $hookobject) {
            if ($modulehook['area'] == 'GUI') {
                $gui = true;
                if (pnModAvailable($modulehook['module'], $modulehook['type']) && pnModLoad($modulehook['module'], $modulehook['type'])) {
                    $output[$modulehook['module']] = pnModFunc($modulehook['module'], $modulehook['type'], $modulehook['func'], array('objectid' => $hookid, 'extrainfo' => $extrainfo));
                }
            } else {
                if (pnModAvailable($modulehook['module'], $modulehook['type']) && pnModAPILoad($modulehook['module'], $modulehook['type'])) {
                    $extrainfo = pnModAPIFunc($modulehook['module'], $modulehook['type'], $modulehook['func'], array('objectid' => $hookid, 'extrainfo' => $extrainfo));
                }
            }
        }
    }
    // check what type of information we need to return
    // credit to the xaraya team for the eregi check
    // itevo
    if ($gui || strtolower($hookaction) == 'display' || strtolower($hookaction) == 'new' || strtolower($hookaction) == 'modify' || strtolower($hookaction) == 'modifyconfig') {
        if ($implode || empty($output)) {
            $output = implode("\n", $output);
        }
        return $output;
    } else {
        return $extrainfo;
    }
}
/**
 * update a template item
 * @param $args['tid'] the ID of the item
 * @param $args['name'] the new name of the item
 * @param $args['number'] the new number of the item
 */
function template_adminapi_update($args)
{
    // Get arguments from argument array - all arguments to this function
    // should be obtained from the $args array, getting them from other
    // places such as the environment is not allowed, as that makes
    // assumptions that will not hold in future versions of PostNuke
    extract($args);
    // Argument check - make sure that all required arguments are present,
    // if not then set an appropriate error message and return
    if (!isset($tid) || !isset($name) || !isset($number)) {
        pnSessionSetVar('errormsg', _MODARGSERROR);
        return false;
    }
    // Load API.  Note that this is loading the user API in addition to
    // the administration API, that is because the user API contains
    // the function to obtain item information which is the first thing
    // that we need to do.  If the API fails to load an appropriate error
    // message is posted and the function returns
    if (!pnModAPILoad('Template', 'user')) {
        $output->Text(_LOADFAILED);
        return $output->GetOutput();
    }
    // The user API function is called.  This takes the item ID which
    // we obtained from the input and gets us the information on the
    // appropriate item.  If the item does not exist we post an appropriate
    // message and return
    $item = pnModAPIFunc('Template', 'user', 'get', array('tid' => $tid));
    if ($item == false) {
        $output->Text(_TEMPLATENOSUCHITEM);
        return $output->GetOutput();
    }
    // Security check - important to do this as early on as possible to
    // avoid potential security holes or just too much wasted processing.
    // However, in this case we had to wait until we could obtain the item
    // name to complete the instance information so this is the first
    // chance we get to do the check
    // Note that at this stage we have two sets of item information, the
    // pre-modification and the post-modification.  We need to check against
    // both of these to ensure that whoever is doing the modification has
    // suitable permissions to edit the item otherwise people can potentially
    // edit areas to which they do not have suitable access
    if (!pnSecAuthAction(0, 'Template::Item', "{$item['name']}::{$tid}", ACCESS_EDIT)) {
        pnSessionSetVar('errormsg', _TEMPLATENOAUTH);
        return false;
    }
    if (!pnSecAuthAction(0, 'Template::Item', "{$name}::{$tid}", ACCESS_EDIT)) {
        pnSessionSetVar('errormsg', _TEMPLATENOAUTH);
        return false;
    }
    // Get datbase setup - note that both pnDBGetConn() and pnDBGetTables()
    // return arrays but we handle them differently.  For pnDBGetConn()
    // we currently just want the first item, which is the official
    // database handle.  For pnDBGetTables() we want to keep the entire
    // tables array together for easy reference later on
    list($dbconn) = pnDBGetConn();
    $pntable = pnDBGetTables();
    // It's good practice to name the table and column definitions you
    // are getting - $table and $column don't cut it in more complex
    // modules
    $templatetable = $pntable['template'];
    $templatecolumn =& $pntable['template_column'];
    // Update the item - the formatting here is not mandatory, but it does
    // make the SQL statement relatively easy to read.  Also, separating
    // out the sql statement from the Execute() command allows for simpler
    // debug operation if it is ever needed
    $sql = "UPDATE {$templatetable}\n            SET {$templatecolumn['name']} = '" . pnVarPrepForStore($name) . "',\n                {$templatecolumn['number']} = '" . pnVarPrepForStore($number) . "'\n            WHERE {$templatecolumn['tid']} = '" . pnVarPrepForStore($tid) . "'";
    $dbconn->Execute($sql);
    // Check for an error with the database code, and if so set an
    // appropriate error message and return
    if ($dbconn->ErrorNo() != 0) {
        pnSessionSetVar('errormsg', _DELETEFAILED);
        return false;
    }
    // Let the calling process know that we have finished successfully
    return true;
}
Example #11
0
function modules_admin_regenerate()
{
    // Security check
    if (!pnSecConfirmAuthKey()) {
        pnSessionSetVar('errormsg', _BADAUTHKEY);
        pnRedirect(pnModURL('Modules', 'admin', 'list'));
        return true;
    }
    // Load in API
    pnModAPILoad('Modules', 'admin');
    // Regenerate modules
    if (pnModAPIFunc('Modules', 'admin', 'regenerate')) {
        // Success
        pnSessionSetVar('statusmsg', _MODREGENERATED);
    }
    pnRedirect(pnModURL('Modules', 'admin', 'list'));
    return true;
}
Example #12
0
function mediashare_editapi_updateItemFileUpload(&$args)
{
    // Ignore empty uploads
    if (!isset($args['fileSize']) || $args['fileSize'] == 0) {
        return true;
    }
    $dom = ZLanguage::getModuleDomain('mediashare');
    $mediaId = (int) $args['mediaId'];
    $uploadFilename = $args['uploadFilename'];
    // Fetch media data - we need it to locate the media files
    if (!($mediaItem = pnModAPIFunc('mediashare', 'user', 'getMediaItem', array('mediaId' => $mediaId)))) {
        return false;
    }
    // Must store items in the same way always (ignore current VFS settings)
    $vfsHandlerName = mediashareGetVFSHandlerName($mediaItem['thumbnailRef']);
    // Check upload limits
    if (!($userInfo = pnModAPIFunc('mediashare', 'edit', 'getUserInfo'))) {
        return false;
    }
    if (!isset($args['ignoreSizeLimits']) || !$args['ignoreSizeLimits']) {
        $fileSize = $args['fileSize'];
        if ($fileSize > $userInfo['mediaSizeLimitSingle']) {
            return LogUtil::registerError($args['filename'] . ': ' . __('Media file too big', $dom));
        }
        if ($fileSize + $userInfo['totalCapacityUsed'] > $userInfo['mediaSizeLimitTotal']) {
            return LogUtil::registerError(__('Media file too big - total quota would be exceeded', $dom));
        }
    }
    // Find a media handler
    if (!($handlerInfo = pnModAPIFunc('mediashare', 'mediahandler', 'getHandlerInfo', array('mimeType' => $args['mimeType'], 'filename' => $args['filename'])))) {
        return false;
    }
    $handlerName = $handlerInfo['handlerName'];
    // Make sure we use sanitized results from the database (like "image/pjpeg" => "image/jpeg")
    $args['mimeType'] = $handlerInfo['mimeType'];
    $args['fileType'] = $handlerInfo['fileType'];
    // Load media handler
    $handlerApi = "media_{$handlerName}";
    $handler = pnModAPIFunc('mediashare', $handlerApi, 'buildHandler');
    // For OPEN_BASEDIR reasons we move the uploaded file to an accessible place
    // MUST remember to remove it afterwards!!!
    // Create and check tmpfilename
    $tmpDir = pnModGetVar('mediashare', 'tmpDirName');
    if (($tmpFilename = tempnam($tmpDir, 'Upload_')) === false) {
        return LogUtil::registerError(__f("Unable to create a temporary file in '%s'", $tmpDir, $dom) . ' - ' . __('(uploading image)', $dom));
    }
    if (is_uploaded_file($uploadFilename)) {
        if (move_uploaded_file($uploadFilename, $tmpFilename) === false) {
            unlink($tmpFilename);
            return LogUtil::registerError(__f('Unable to move uploaded file from \'%1$s\' to \'%2$s\'', array($uploadFilename, $tmpFilename), $dom) . ' - ' . __('(uploading image)', $dom));
        }
    } else {
        if (!copy($uploadFilename, $tmpFilename)) {
            unlink($tmpFilename);
            return LogUtil::registerError(__f('editapi_updateItemFileUpload Unable to copy the file from \'%1$s\' to \'%2$s\'', array($uploadFilename, $tmpFilename), $dom) . ' - ' . __('(adding image)', $dom));
        }
    }
    $args['mediaFilename'] = $tmpFilename;
    // Check mimetypes/media-handler - must be the same (cannot allow the target of a <img src="..."/> to change to a Flash file!)
    if ($mediaItem['mediaHandler'] != $handlerName) {
        return LogUtil::registerError(__('New media type does not match the existing.', $dom));
    }
    // Ask media handler to generate thumbnail and preview files
    if (($thumbnailFilename = tempnam($tmpDir, 'Preview')) === false) {
        @unlink($tmpFilename);
        return LogUtil::registerError(__f("Failed to create the thumbnail file in '%s'.", 'editapi.updateItemFileUpload', $dom));
    }
    if (($previewFilename = tempnam($tmpDir, 'Preview')) === false) {
        @unlink($tmpFilename);
        @unlink($thumbnailFilename);
        return LogUtil::registerError(__f("Failed to create the preview file in '%s'.", 'editapi.updateItemFileUpload', $dom));
    }
    $thumbnailSize = (int) pnModGetVar('mediashare', 'thumbnailSize');
    $previews = array(array('outputFilename' => $thumbnailFilename, 'imageSize' => $thumbnailSize, 'isThumbnail' => true), array('outputFilename' => $previewFilename, 'imageSize' => (int) pnModGetVar('mediashare', 'previewSize'), 'isThumbnail' => false));
    $previewResult = $handler->createPreviews($args, $previews);
    if ($previewResult === false) {
        @unlink($tmpFilename);
        @unlink($thumbnailFilename);
        @unlink($previewFilename);
        return false;
    }
    // Get virtual file system handler
    // Must store items in the same way always (ignore current VFS settings)
    $vfsHandlerName = mediashareGetVFSHandlerName($mediaItem['thumbnailRef']);
    $vfsHandlerApi = "vfs_{$vfsHandlerName}";
    if (!pnModAPILoad('mediashare', $vfsHandlerApi)) {
        @unlink($tmpFilename);
        @unlink($thumbnailFilename);
        @unlink($previewFilename);
        return LogUtil::registerError(__f('Missing [%1$s] in \'%2$s\'', array($vfsHandlerApi, 'editapi.updateItemFileUpload'), $dom));
    }
    $vfsHandler = pnModAPIFunc('mediashare', $vfsHandlerApi, 'buildHandler');
    // FIXME better step handling
    // Update thumbnail, preview, and original in virtual file system
    if ($vfsHandler === false) {
        @unlink($tmpFilename);
        @unlink($thumbnailFilename);
        @unlink($previewFilename);
        return false;
    }
    if ($vfsHandler->updateFile($mediaItem['thumbnailRef'], $thumbnailFilename) === false) {
        @unlink($tmpFilename);
        @unlink($thumbnailFilename);
        @unlink($previewFilename);
        return false;
    }
    if ($vfsHandler->updateFile($mediaItem['previewRef'], $previewFilename) === false) {
        @unlink($tmpFilename);
        @unlink($thumbnailFilename);
        @unlink($previewFilename);
        return false;
    }
    if ($vfsHandler->updateFile($mediaItem['originalRef'], $tmpFilename) === false) {
        @unlink($tmpFilename);
        @unlink($thumbnailFilename);
        @unlink($previewFilename);
        return false;
    }
    // Clean up
    @unlink($tmpFilename);
    @unlink($thumbnailFilename);
    @unlink($previewFilename);
    // Update media info
    $previewResult[0]['storageId'] = $mediaItem['thumbnailId'];
    $previewResult[1]['storageId'] = $mediaItem['previewId'];
    $previewResult[2]['storageId'] = $mediaItem['originalId'];
    if (!pnModAPIFunc('mediashare', 'edit', 'updateMediaStorage', $previewResult[0])) {
        LogUtil::registerError(__('There was a problem updating the media storage.', $dom));
    }
    if (!pnModAPIFunc('mediashare', 'edit', 'updateMediaStorage', $previewResult[1])) {
        LogUtil::registerError(__('There was a problem updating the media storage.', $dom));
    }
    if (!pnModAPIFunc('mediashare', 'edit', 'updateMediaStorage', $previewResult[2])) {
        LogUtil::registerError(__('There was a problem updating the media storage.', $dom));
    }
    return true;
}
Example #13
0
/**
* send an email
*
* e-mail messages should now be send with a pnModAPIFunc call to the mailer module
*
* @deprecated
* @param to $ - recipient of the email
* @param subject $ - title of the email
* @param message $ - body of the email
* @param headers $ - extra headers for the email
* @param html $ - message is html formatted
* @param debug $ - if 1, echo mail content
* @return bool true if the email was sent, false if not
*/
function pnMail($to, $subject, $message = '', $headers = '', $html = 0, $debug = 0)
{
    if (empty($to) || !isset($subject)) {
        return false;
    }
    // set initial return value until we know we have a valid return
    $return = false;
    // check if the mailer module is availble and if so call the API
    if (pnModAvailable('Mailer') && pnModAPILoad('Mailer', 'user')) {
        $return = pnModAPIFunc('Mailer', 'user', 'sendmessage', array('toaddress' => $to, 'subject' => $subject, 'headers' => $headers, 'body' => $message, 'headers' => $headers, 'html' => $html));
    }
    return $return;
}
/**
 * pnThemeInfo()
 * <br />
 * This function returns information about a certain theme. 
 * For this purpose, it includes the xaninfo.php file (for 
 * Xanthia themes) or the themeinfo.php (for other themes).
 * <br />
 * If the name passed isn't a valid theme, false is returned. 
 * <br />
 * For a valid theme, at least these values are returned:
 * xanthia (boolean, true if this is a Xanthia theme)
 * hidden  (boolean, true if this is a hidden theme)
 * active  (boolean, true if the theme is active)
 * 
 * @author Joerg Napp
 * @since PostNuke .760
 * @param string $theme the name of the theme
 * @return array the theme information
 **/
function pnThemeInfo($theme)
{
    $theme = isset($theme) ? $theme : '';
    if (!pnVarValidate($theme, 'theme')) {
        return false;
    }
    $themepath = pnVarPrepForOS($theme);
    // determine if this is a valid theme
    if (!file_exists(WHERE_IS_PERSO . "themes/{$themepath}/theme.php") && !file_exists("themes/{$themepath}/theme.php")) {
        return false;
    }
    $themeinfo = array();
    // Setting the defaults
    $themeinfo['name'] = $theme;
    // might be useful
    $themeinfo['hidden'] = false;
    // A theme isn't hidden unless explicitly marked as hidden
    $themeinfo['xanthia'] = false;
    // assume the theme not to be a Xanthia theme unless xaninfo.php is present.
    $themeinfo['active'] = true;
    // assume the theme to be active unless it isn't
    if (file_exists($file = WHERE_IS_PERSO . "themes/{$themepath}/themeinfo.php")) {
        include $file;
    } elseif (file_exists($file = "themes/{$themepath}/themeinfo.php")) {
        include $file;
    } elseif (file_exists($file = WHERE_IS_PERSO . "themes/{$themepath}/xaninfo.php")) {
        $themeinfo['xanthia'] = true;
        include $file;
    } elseif (file_exists($file = "themes/{$themepath}/xaninfo.php")) {
        $themeinfo['xanthia'] = true;
        include $file;
    }
    if ($themeinfo['xanthia']) {
        if (pnModAPILoad('Xanthia', 'user')) {
            // see if the skin is in the database (=active)
            $skinid = pnModAPIFunc('Xanthia', 'user', 'getSkinID', array('skin' => $theme));
            $themeinfo['active'] = (bool) $skinid;
        } else {
            // don't use Xanthia themes without Xanthia.
            // Maybe the function should return false (= not a valid theme) in this case?
            $themeinfo['active'] = false;
        }
    }
    return $themeinfo;
}
Example #15
0
/**
 * view items
 */
function template_admin_view()
{
    // Get parameters from whatever input we need.  All arguments to this
    // function should be obtained from pnVarCleanFromInput(), getting them
    // from other places such as the environment is not allowed, as that makes
    // assumptions that will not hold in future versions of PostNuke
    $startnum = pnVarCleanFromInput('startnum');
    // Create output object - this object will store all of our output so that
    // we can return it easily when required
    $output = new pnHTML();
    if (!pnSecAuthAction(0, 'Template::', '::', ACCESS_EDIT)) {
        $output->Text(_TEMPLATENOAUTH);
        return $output->GetOutput();
    }
    // Add menu to output - it helps if all of the module pages have a standard
    // menu at their head to aid in navigation
    $output->SetInputMode(_PNH_VERBATIMINPUT);
    $output->Text(template_adminmenu());
    $output->SetInputMode(_PNH_PARSEINPUT);
    // Title - putting a title ad the head of each page reminds the user what
    // they are doing
    $output->Title(_VIEWTEMPLATE);
    // Load API.  Note that this is loading the user API, that is because the
    // user API contains the function to obtain item information which is the
    // first thing that we need to do.  If the API fails to load an appropriate
    // error message is posted and the function returns
    if (!pnModAPILoad('Template', 'user')) {
        $output->Text(_LOADFAILED);
        return $output->GetOutput();
    }
    // The user API function is called.  This takes the number of items
    // required and the first number in the list of all items, which we
    // obtained from the input and gets us the information on the appropriate
    // items.
    $items = pnModAPIFunc('Template', 'user', 'getall', array('startnum' => $startnum, 'numitems' => pnModGetVar('Template', 'itemsperpage')));
    // Start output table
    $output->TableStart('', array(_TEMPLATENAME, _TEMPLATENUMBER, _TEMPLATEOPTIONS), 3);
    foreach ($items as $item) {
        $row = array();
        if (pnSecAuthAction(0, 'Template::', "{$item['name']}::{$item['tid']}", ACCESS_READ)) {
            // Name and number.  Note that unlike the user function we do not
            // censor the text that is being displayed.  This is so the
            // administrator can see the text as exists in the database rather
            // than the munged output version
            $row[] = $item['name'];
            $row[] = $item['number'];
            // Options for the item.  Note that each item has the appropriate
            // levels of authentication checked to ensure that it is suitable
            // for display
            $options = array();
            $output->SetOutputMode(_PNH_RETURNOUTPUT);
            if (pnSecAuthAction(0, 'Template::', "{$item['name']}::{$item['tid']}", ACCESS_EDIT)) {
                $options[] = $output->URL(pnVarPrepForDisplay(pnModURL('Template', 'admin', 'modify', array('tid' => $item['tid']))), _EDIT);
                if (pnSecAuthAction(0, 'Template::', "{$item['name']}::{$item['tid']}", ACCESS_DELETE)) {
                    $options[] = $output->URL(pnVarPrepForDisplay(pnModURL('Template', 'admin', 'delete', array('tid' => $item['tid']))), _DELETE);
                }
            }
            $options = join(' | ', $options);
            $output->SetInputMode(_PNH_VERBATIMINPUT);
            $row[] = $output->Text($options);
            $output->SetOutputMode(_PNH_KEEPOUTPUT);
            $output->TableAddRow($row);
            $output->SetInputMode(_PNH_PARSEINPUT);
        }
    }
    $output->TableEnd();
    // Call the pnHTML helper function to produce a pager in case of there
    // being many items to display.
    //
    // Note that this function includes another user API function.  The
    // function returns a simple count of the total number of items in the item
    // table so that the pager function can do its job properly
    $output->Pager($startnum, pnModAPIFunc('Template', 'user', 'countitems'), pnModURL('Template', 'admin', 'view', array('startnum' => '%%')), pnModGetVar('Template', 'itemsperpage'));
    // Return the output that has been generated by this function
    return $output->GetOutput();
}
Example #16
0
function mediashare_upgrade_to_2_1_1()
{
    pnModSetVar('mediashare', 'defaultAlbumTemplate', 'Lightbox');
    pnModAPILoad('mediashare', 'admin', true);
    if (!pnModAPIFunc('mediashare', 'admin', 'setTemplateGlobally', array('template' => 'Lightbox'))) {
        return false;
    }
    return true;
}
Example #17
0
// ----------------------------------------------------------------------
// LICENSE
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License (GPL)
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// 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.  See the
// GNU General Public License for more details.
//
// To read the license please visit http://www.gnu.org/copyleft/gpl.html
// ----------------------------------------------------------------------
// Original Author of file: Gregor J. Rothfuss
// Purpose of file: XML-RPC server for postnuke
// ----------------------------------------------------------------------
include 'includes/pnAPI.php';
pnInit();
// Load user API for xmlrpc module
if (!pnModAPILoad('xmlrpc', 'user')) {
    die('Could not load xmlrpc module');
}
/* create an instance of an xmlrpc server and define the apis we export
   and the mapping to the functions.
 */
$server = pnModAPIFunc('xmlrpc', 'user', 'initServer');
if (!$server) {
    die('Could not load server');
}
Example #18
0
/**
 *	Upgrades an old install of PostCalendar
 *
 *	This function is used to upgrade an old version
 *	of PostCalendar.  It is accessed via the PostNuke
 *	Admin interface and should not be called directly.
 *
 *	@return boolean	true/false
 *	@param  string	$oldversion Version we're upgrading
 *	@access  public
 *	@author  Roger Raymond <*****@*****.**>
 *	@copyright	The PostCalendar Team 2002
 */
function postcalendar_upgrade($oldversion)
{
    /**
     *	Until PostNuke fixes the bugs
     *	with the module upgrade we are
     *	going to have to do it ourselves.
     *
     *	Please do not use the Modules admin
     *	to upgrade PostCalendar.  Use the
     *	link provided in the PostCalendar
     *	Admin section.
     */
    $pcModInfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
    $pcDir = pnVarPrepForOS($pcModInfo['directory']);
    list($dbconn) = pnDBGetConn();
    $pntable = pnDBGetTables();
    $events_table = $pntable['postcalendar_events'];
    $cat_table = $pntable['postcalendar_categories'];
    switch ($oldversion) {
        case '3.0':
        case '3.01':
        case '3.02':
        case '3.03':
        case '3.04':
            // we need the Date_Calc class
            require_once "modules/{$pcDir}/pnincludes/Date/Calc.php";
            // Update PostCalendar Variables
            pnModSetVar(__POSTCALENDAR__, 'pcTime24Hours', pnModGetVar(__POSTCALENDAR__, 'time24hours'));
            pnModSetVar(__POSTCALENDAR__, 'pcEventsOpenInNewWindow', pnModGetVar(__POSTCALENDAR__, 'eventsopeninnewwindow'));
            pnModSetVar(__POSTCALENDAR__, 'pcUseInternationalDates', pnModGetVar(__POSTCALENDAR__, 'useinternationaldates'));
            pnModSetVar(__POSTCALENDAR__, 'pcFirstDayOfWeek', pnModGetVar(__POSTCALENDAR__, 'firstdayofweek'));
            pnModSetVar(__POSTCALENDAR__, 'pcDayHighlightColor', pnModGetVar(__POSTCALENDAR__, 'dayhighlightcolor'));
            pnModSetVar(__POSTCALENDAR__, 'pcUsePopups', pnModGetVar(__POSTCALENDAR__, 'usepopups'));
            pnModSetVar(__POSTCALENDAR__, 'pcDisplayTopics', pnModGetVar(__POSTCALENDAR__, 'displaytopics'));
            pnModSetVar(__POSTCALENDAR__, 'pcAllowDirectSubmit', '0');
            pnModSetVar(__POSTCALENDAR__, 'pcListHowManyEvents', pnModGetVar(__POSTCALENDAR__, 'listhowmanyevents'));
            pnModSetVar(__POSTCALENDAR__, 'pcTimeIncrement', '15');
            pnModSetVar(__POSTCALENDAR__, 'pcAllowSiteWide', '0');
            pnModSetVar(__POSTCALENDAR__, 'pcAllowUserCalendar', '1');
            pnModSetVar(__POSTCALENDAR__, 'pcEventDateFormat', '%Y-%m-%d');
            pnModSetVar(__POSTCALENDAR__, 'pcTemplate', 'default');
            pnModSetVar(__POSTCALENDAR__, 'pcUseCache', '1');
            pnModSetVar(__POSTCALENDAR__, 'pcCacheLifetime', '3600');
            pnModSetVar(__POSTCALENDAR__, 'pcDefaultView', 'month');
            pnModSetVar(__POSTCALENDAR__, 'pcSafeMode', '0');
            // alter the events table and change some old columns
            $sql = "ALTER TABLE {$events_table}\n                    ADD pc_catid int(11) default '0' NOT NULL,\n\t\t\t\t\tADD pc_duration bigint(20) default '0' NOT NULL,\n                    ADD pc_sharing int(11) default '0' NOT NULL,\n                    ADD pc_language varchar(30) default '',\n\t\t\t\t\tCHANGE pc_eid pc_eid int(11) unsigned NOT NULL auto_increment,\n                    CHANGE pc_location pc_location text,\n                    CHANGE pc_conttel pc_conttel varchar(50),\n                    CHANGE pc_contname pc_contname varchar(150),\n                    CHANGE pc_contemail pc_contemail varchar(255),\n                    CHANGE pc_website pc_website varchar(255),\n                    CHANGE pc_fee pc_fee varchar(50),\n                    CHANGE pc_recurrspec pc_recurrspec text default ''\n                    ";
            $dbconn->Execute($sql);
            if ($dbconn->ErrorNo() != 0) {
                die('event table alter error : ' . $dbconn->ErrorMsg());
                return false;
            }
            // create the new categories table
            $sql = "CREATE TABLE {$cat_table} (\n                    pc_catid int(11) unsigned NOT NULL auto_increment,\n                    pc_catname varchar(100) NOT NULL default 'Undefined',\n                    pc_catcolor varchar(50) NOT NULL default '#EEEEEE',\n                    pc_catdesc text default '',\n                    PRIMARY KEY(pc_catid)\n                    )";
            $dbconn->Execute($sql);
            if ($dbconn->ErrorNo() != 0) {
                die('cat table create error : ' . $dbconn->ErrorMsg());
                return false;
            }
            // insert the current hardcoded categories into the new categories table
            $category1 = pnVarPrepForStore(pnModGetVar(__POSTCALENDAR__, 'category1'));
            $category2 = pnVarPrepForStore(pnModGetVar(__POSTCALENDAR__, 'category2'));
            $category3 = pnVarPrepForStore(pnModGetVar(__POSTCALENDAR__, 'category3'));
            $category4 = pnVarPrepForStore(pnModGetVar(__POSTCALENDAR__, 'category4'));
            $category5 = pnVarPrepForStore(pnModGetVar(__POSTCALENDAR__, 'category5'));
            $inserts = array("INSERT INTO {$cat_table} (pc_catid,pc_catname,pc_catcolor) VALUES ('1','{$category1}','#EEEEEE')", "INSERT INTO {$cat_table} (pc_catid,pc_catname,pc_catcolor) VALUES ('2','{$category2}','#00ff00')", "INSERT INTO {$cat_table} (pc_catid,pc_catname,pc_catcolor) VALUES ('3','{$category3}','#0000ff')", "INSERT INTO {$cat_table} (pc_catid,pc_catname,pc_catcolor) VALUES ('4','{$category4}','#ffffff')", "INSERT INTO {$cat_table} (pc_catid,pc_catname,pc_catcolor) VALUES ('5','{$category5}','#ffcc00')");
            foreach ($inserts as $insert) {
                $dbconn->Execute($insert);
                if ($dbconn->ErrorNo() != 0) {
                    die('cat table insert error : ' . $dbconn->ErrorMsg());
                    return false;
                }
            }
            // update the current events to reflect the category system change
            $updates = array("UPDATE {$events_table} SET pc_catid = 1 WHERE pc_barcolor = 'r' ", "UPDATE {$events_table} SET pc_catid = 2 WHERE pc_barcolor = 'g' ", "UPDATE {$events_table} SET pc_catid = 3 WHERE pc_barcolor = 'b' ", "UPDATE {$events_table} SET pc_catid = 4 WHERE pc_barcolor = 'w' ", "UPDATE {$events_table} SET pc_catid = 5 WHERE pc_barcolor = 'y' ");
            foreach ($updates as $update) {
                $dbconn->Execute($update);
                if ($dbconn->ErrorNo() != 0) {
                    die('event table update error : ' . $dbconn->ErrorMsg());
                    return false;
                }
            }
            // alter the events table and drop the old barcolor column
            $sql = "ALTER TABLE {$events_table} DROP pc_barcolor";
            $dbconn->Execute($sql);
            if ($dbconn->ErrorNo() != 0) {
                die('cat table alter error : ' . $dbconn->ErrorMsg());
                return false;
            }
            // remove the old vars as they are no longer needed
            pnModDelVar(__POSTCALENDAR__, 'category1');
            pnModDelVar(__POSTCALENDAR__, 'category2');
            pnModDelVar(__POSTCALENDAR__, 'category3');
            pnModDelVar(__POSTCALENDAR__, 'category4');
            pnModDelVar(__POSTCALENDAR__, 'category5');
            pnModDelVar(__POSTCALENDAR__, 'time24hours');
            pnModDelVar(__POSTCALENDAR__, 'eventsopeninnewwindow');
            pnModDelVar(__POSTCALENDAR__, 'useinternationaldates');
            pnModDelVar(__POSTCALENDAR__, 'firstdayofweek');
            pnModDelVar(__POSTCALENDAR__, 'dayhighlightcolor');
            pnModDelVar(__POSTCALENDAR__, 'displaytopics');
            pnModDelVar(__POSTCALENDAR__, 'usepopups');
            pnModDelVar(__POSTCALENDAR__, 'listhowmanyevents');
            pnModDelVar(__POSTCALENDAR__, 'allowdirectsubmit');
            pnModDelVar(__POSTCALENDAR__, 'showeventsinyear');
            //======================================================
            //  now, ideally, we will convert old events to the new
            //  style. this consists of reconfiguring the repeating
            //  events vars.
            //
            //  we need to establish the current repeating
            //  conditions and convert them to the new system
            //======================================================
            //  old repeating defines
            //======================================================
            @define('_EVENT_NONE', -1);
            @define('_EVENT_DAILY', 0);
            @define('_EVENT_WEEKLY', 1);
            @define('_EVENT_MONTHLY', 2);
            @define('_EVENT_YEARLY', 3);
            @define('_RECUR_SAME_DAY', 0);
            @define('_RECUR_SAME_DATE', 1);
            //======================================================
            //  new repeating defines
            //  $recurrspec['event_repeat']
            //======================================================
            @define('NO_REPEAT', 0);
            @define('REPEAT', 1);
            @define('REPEAT_ON', 2);
            //======================================================
            //  $recurrspec['event_repeat_freq']
            //======================================================
            @define('REPEAT_EVERY', 1);
            @define('REPEAT_EVERY_OTHER', 2);
            @define('REPEAT_EVERY_THIRD', 3);
            @define('REPEAT_EVERY_FOURTH', 4);
            //======================================================
            //  $recurrspec['event_repeat_freq_type']
            //======================================================
            @define('REPEAT_EVERY_DAY', 0);
            @define('REPEAT_EVERY_WEEK', 1);
            @define('REPEAT_EVERY_MONTH', 2);
            @define('REPEAT_EVERY_YEAR', 3);
            //======================================================
            //  $recurrspec['event_repeat_on_num']
            //======================================================
            @define('REPEAT_ON_1ST', 1);
            @define('REPEAT_ON_2ND', 2);
            @define('REPEAT_ON_3RD', 3);
            @define('REPEAT_ON_4TH', 4);
            @define('REPEAT_ON_LAST', 5);
            //======================================================
            //  $recurrspec['event_repeat_on_day']
            //======================================================
            @define('REPEAT_ON_SUN', 0);
            @define('REPEAT_ON_MON', 1);
            @define('REPEAT_ON_TUE', 2);
            @define('REPEAT_ON_WED', 3);
            @define('REPEAT_ON_THU', 4);
            @define('REPEAT_ON_FRI', 5);
            @define('REPEAT_ON_SAT', 6);
            //======================================================
            //  $recurrspec['event_repeat_on_freq']
            //======================================================
            @define('REPEAT_ON_MONTH', 1);
            @define('REPEAT_ON_2MONTH', 2);
            @define('REPEAT_ON_3MONTH', 3);
            @define('REPEAT_ON_4MONTH', 4);
            @define('REPEAT_ON_6MONTH', 6);
            @define('REPEAT_ON_YEAR', 12);
            //======================================================
            //  Set Sharing Paramaters
            //======================================================
            @define('SHARING_PRIVATE', 0);
            @define('SHARING_PUBLIC', 1);
            @define('SHARING_BUSY', 2);
            @define('SHARING_GLOBAL', 3);
            //======================================================
            //  Here's some psuedo-code for the conversion
            //
            //  if _EVENT_NONE
            //      $rtype = NO_REPEAT
            //      $rspec = 0 for all;
            //      $duration = endTime - startTime
            //
            //  if _EVENT_DAILY
            //      $rtype = REPEAT
            //      $rspec = REPEAT_EVERY|REPEAT_EVERY_DAY
            //      $duration = endTime - startTime
            //
            //  if _EVENT_WEEKLY
            //      $rtype = REPEAT
            //      $rspec = REPEAT_EVERY|REPEAT_EVERY_WEEK
            //      $duration = endTime - startTime
            //
            //  if _EVENT_MONTHLY
            //      if _RECUR_SAME_DAY
            //          $rtype = REPEAT_ON
            //          $rspec = REPEAT_ON_NUM|REPEAT_ON_DAY|REPEAT_ON_FREQ
            //      if _RECUR_SAME_DATE
            //          $rtype = REPEAT
            //          $rspec = REPEAT_EVERY|REPEAT_EVERY_MONTH
            //      $duration = endTime - startTime
            //
            //  if _EVENT_YEARLY
            //      if _RECUR_SAME_DAY
            //          $rtype = REPEAT_ON
            //          $rspec = REPEAT_ON_NUM|REPEAT_ON_DAY|REPEAT_ON_FREQ
            //      if _RECUR_SAME_DATE
            //          $rtype = REPEAT
            //          $rspec = REPEAT_EVERY|REPEAT_EVERY_YEAR
            //      $duration = endTime - startTime
            //======================================================
            //  attempt reconfiguration
            //======================================================
            $sql = "SELECT pc_eid, pc_eventDate, pc_startTime, pc_endTime, pc_recurrtype, pc_recurrfreq\n                    FROM {$events_table}";
            $result = $dbconn->Execute($sql);
            if ($dbconn->ErrorNo() != 0) {
                die($dbconn->ErrorMsg());
                return false;
            }
            if (!isset($result)) {
                return false;
            }
            // grab the results and start the conversion
            for (; !$result->EOF; $result->MoveNext()) {
                $recurrspec = array();
                list($eid, $eventdate, $start, $end, $rtype, $rfreq) = $result->fields;
                if ($rtype == null) {
                    $rtype = _EVENT_NONE;
                }
                switch ($rtype) {
                    case _EVENT_NONE:
                        $recurrtype = NO_REPEAT;
                        $recurrspec['event_repeat_freq'] = 0;
                        $recurrspec['event_repeat_freq_type'] = 0;
                        $recurrspec['event_repeat_on_num'] = 0;
                        $recurrspec['event_repeat_on_day'] = 0;
                        $recurrspec['event_repeat_on_freq'] = 0;
                        break;
                    case _EVENT_DAILY:
                        $recurrtype = REPEAT;
                        $recurrspec['event_repeat_freq'] = REPEAT_EVERY;
                        $recurrspec['event_repeat_freq_type'] = REPEAT_EVERY_DAY;
                        $recurrspec['event_repeat_on_num'] = 0;
                        $recurrspec['event_repeat_on_day'] = 0;
                        $recurrspec['event_repeat_on_freq'] = 0;
                        break;
                    case _EVENT_WEEKLY:
                        $recurrtype = REPEAT;
                        $recurrspec['event_repeat_freq'] = REPEAT_EVERY;
                        $recurrspec['event_repeat_freq_type'] = REPEAT_EVERY_WEEK;
                        $recurrspec['event_repeat_on_num'] = 0;
                        $recurrspec['event_repeat_on_day'] = 0;
                        $recurrspec['event_repeat_on_freq'] = 0;
                        break;
                    case _EVENT_MONTHLY:
                        if ($rfreq == _RECUR_SAME_DATE) {
                            $recurrtype = REPEAT;
                            $recurrspec['event_repeat_freq'] = REPEAT_EVERY;
                            $recurrspec['event_repeat_freq_type'] = REPEAT_EVERY_MONTH;
                            $recurrspec['event_repeat_on_num'] = 0;
                            $recurrspec['event_repeat_on_day'] = 0;
                            $recurrspec['event_repeat_on_freq'] = 0;
                        } elseif ($rfreq == _RECUR_SAME_DAY) {
                            $recurrtype = REPEAT_ON;
                            list($y, $m, $d) = explode('-', $eventdate);
                            $recurrspec['event_repeat_freq'] = 0;
                            $recurrspec['event_repeat_freq_type'] = 0;
                            // event day of week
                            $edow = Date_Calc::dayOfWeek($d, $m, $y);
                            // date of first event day of week
                            $firstDay = Date_Calc::NWeekdayOfMonth(1, $edow, $m, $y, '%Y-%m-%d');
                            // find difference between 1st day and event day
                            list($y2, $m2, $d2) = explode('-', $firstDay);
                            $diff = Date_Calc::dateDiff($d, $m, $y, $d2, $m2, $y2);
                            // assuming $diff is going to be a multiple of 7
                            if ($diff > 0) {
                                $diff /= 7;
                            }
                            if ($diff > REPEAT_ON_4TH) {
                                $diff = REPEAT_ON_LAST;
                            }
                            $recurrspec['event_repeat_on_num'] = $diff;
                            $recurrspec['event_repeat_on_day'] = $edow;
                            $recurrspec['event_repeat_on_freq'] = REPEAT_ON_MONTH;
                        }
                        break;
                    case _EVENT_YEARLY:
                        if ($rfreq == _RECUR_SAME_DATE) {
                            $recurrtype = REPEAT;
                            $recurrspec['event_repeat_freq'] = REPEAT_EVERY;
                            $recurrspec['event_repeat_freq_type'] = REPEAT_EVERY_YEAR;
                            $recurrspec['event_repeat_on_num'] = 0;
                            $recurrspec['event_repeat_on_day'] = 0;
                            $recurrspec['event_repeat_on_freq'] = 0;
                        } elseif ($rfreq == _RECUR_SAME_DAY) {
                            $recurrtype = REPEAT_ON;
                            list($y, $m, $d) = explode('-', $eventdate);
                            $recurrspec['event_repeat_freq'] = 0;
                            $recurrspec['event_repeat_freq_type'] = 0;
                            // event day of week
                            $edow = Date_Calc::dayOfWeek($d, $m, $y);
                            // date of first event day of week
                            $firstDay = Date_Calc::NWeekdayOfMonth(1, $edow, $m, $y, '%Y-%m-%d');
                            // find difference between 1st day and event day
                            list($y2, $m2, $d2) = explode('-', $firstDay);
                            $diff = Date_Calc::dateDiff($d, $m, $y, $d2, $m2, $y2);
                            // assuming $diff is going to be a multiple of 7
                            if ($diff > 0) {
                                $diff /= 7;
                            }
                            if ($diff > REPEAT_ON_4TH) {
                                $diff = REPEAT_ON_LAST;
                            }
                            $recurrspec['event_repeat_on_num'] = $diff;
                            $recurrspec['event_repeat_on_day'] = $edow;
                            $recurrspec['event_repeat_on_freq'] = REPEAT_ON_YEAR;
                        }
                        break;
                }
                // ok, figure out the event's duration
                list($sh, $sm, $ss) = explode(':', $start);
                list($eh, $em, $es) = explode(':', $end);
                $stime = mktime($sh, $sm, $ss, 1, 1, 1970);
                // if the ending hour is less than the starting hour
                // assume that the event spans to the next day
                if ($eh < $sh) {
                    $etime = mktime($eh, $em, $es, 1, 2, 1970);
                } else {
                    $etime = mktime($eh, $em, $es, 1, 1, 1970);
                }
                $duration = $etime - $stime;
                // prep the vars for the sql statement
                $eid = pnVarPrepForStore($eid);
                $recurrtype = pnVarPrepForStore($recurrtype);
                $recurrspec = pnVarPrepForStore(serialize($recurrspec));
                // create our sql statement
                $updatesql = "UPDATE {$events_table} SET \n                              pc_aid = '0',\n\t\t\t\t\t\t\t  pc_recurrtype = {$recurrtype},\n                              pc_recurrspec = '{$recurrspec}',\n                              pc_duration = {$duration},\n\t\t\t\t\t\t\t  pc_sharing = " . SHARING_GLOBAL . "\n                              WHERE pc_eid = {$eid}";
                // execute our sql statement
                $dbconn->Execute($updatesql);
                if ($dbconn->ErrorNo() != 0) {
                    die($dbconn->ErrorMsg());
                    return false;
                }
                // next event please
            }
            // all done, proceed with next upgrade step if available/necessary
            return postcalendar_upgrade('3.1');
            break;
        case '3.1':
        case '3.1.1':
        case '3.1.2':
        case '3.1.3':
        case '3.1.4':
            return postcalendar_upgrade('3.9.0');
            break;
        case '3.9.0':
        case '3.9.1':
        case '3.9.2':
            // ading pcSafeMode
            pnModSetVar(__POSTCALENDAR__, 'pcSafeMode', '0');
            return postcalendar_upgrade('3.9.3');
            break;
        case '3.9.3':
        case '3.9.3.1':
            // adding indexes
            $sql = "ALTER TABLE {$events_table} \n\t\t\t\t\tADD INDEX basic_event (pc_catid,pc_aid,pc_eventDate,pc_endDate,pc_eventstatus,pc_sharing,pc_topic)";
            $dbconn->Execute($sql);
            if ($dbconn->ErrorNo() != 0) {
                die($dbconn->ErrorMsg());
                return false;
            }
            // adding indexes
            $sql = "ALTER TABLE {$cat_table} \n\t\t\t\t\tADD INDEX basic_cat (pc_catname, pc_catcolor)";
            $dbconn->Execute($sql);
            if ($dbconn->ErrorNo() != 0) {
                die($dbconn->ErrorMsg());
                return false;
            }
            return postcalendar_upgrade('3.9.4');
            break;
        case '3.9.4':
        case '3.9.5':
        case '3.9.6':
        case '3.9.7':
            return postcalendar_upgrade('3.9.8');
            break;
        case '3.9.8':
            pnModDelVar(__POSTCALENDAR__, 'pcSafeMode');
            pnModSetVar(__POSTCALENDAR__, 'pcNotifyAdmin', '0');
            pnModSetVar(__POSTCALENDAR__, 'pcNotifyEmail', pnConfigGetVar('adminmail'));
            break;
        case '3.9.9':
            break;
    }
    // if we get this far - load the userapi and clear the cache
    if (!pnModAPILoad(__POSTCALENDAR__, 'user')) {
        return false;
    }
    $tpl =& new pcSmarty();
    $tpl->clear_all_cache();
    $tpl->clear_compiled_tpl();
    return true;
}