Ejemplo n.º 1
0
 function get()
 {
     $o = '';
     if (!local_channel()) {
         notice(t('Permission denied.') . EOL);
         return;
     }
     $post_id = argc() > 1 ? intval(argv(1)) : 0;
     if (!$post_id) {
         notice(t('Item not found') . EOL);
         return;
     }
     $itm = q("SELECT * FROM `item` WHERE `id` = %d AND ( owner_xchan = '%s' OR author_xchan = '%s' ) LIMIT 1", intval($post_id), dbesc(get_observer_hash()), dbesc(get_observer_hash()));
     if (!count($itm)) {
         notice(t('Item is not editable') . EOL);
         return;
     }
     if ($itm[0]['resource_type'] === 'event' && $itm[0]['resource_id']) {
         goaway(z_root() . '/events/' . $itm[0]['resource_id'] . '?expandform=1');
     }
     $owner_uid = $itm[0]['uid'];
     $channel = \App::get_channel();
     if (intval($itm[0]['item_obscured'])) {
         $key = get_config('system', 'prvkey');
         if ($itm[0]['title']) {
             $itm[0]['title'] = crypto_unencapsulate(json_decode_plus($itm[0]['title']), $key);
         }
         if ($itm[0]['body']) {
             $itm[0]['body'] = crypto_unencapsulate(json_decode_plus($itm[0]['body']), $key);
         }
     }
     $category = '';
     $catsenabled = feature_enabled($owner_uid, 'categories') ? 'categories' : '';
     if ($catsenabled) {
         $itm = fetch_post_tags($itm);
         $cats = get_terms_oftype($itm[0]['term'], TERM_CATEGORY);
         foreach ($cats as $cat) {
             if (strlen($category)) {
                 $category .= ', ';
             }
             $category .= $cat['term'];
         }
     }
     if ($itm[0]['attach']) {
         $j = json_decode($itm[0]['attach'], true);
         if ($j) {
             foreach ($j as $jj) {
                 $itm[0]['body'] .= "\n" . '[attachment]' . basename($jj['href']) . ',' . $jj['revision'] . '[/attachment]' . "\n";
             }
         }
     }
     $x = array('nickname' => $channel['channel_address'], 'editor_autocomplete' => true, 'bbco_autocomplete' => 'bbcode', 'return_path' => $_SESSION['return_url'], 'button' => t('Edit'), 'hide_voting' => true, 'hide_future' => true, 'hide_location' => true, 'mimetype' => $itm[0]['mimetype'], 'ptyp' => $itm[0]['obj_type'], 'body' => undo_post_tagging($itm[0]['body']), 'post_id' => $post_id, 'defloc' => $channel['channel_location'], 'visitor' => true, 'title' => htmlspecialchars($itm[0]['title'], ENT_COMPAT, 'UTF-8'), 'category' => $category, 'showacl' => false, 'profile_uid' => $owner_uid, 'catsenabled' => $catsenabled, 'hide_expire' => true, 'bbcode' => true);
     $editor = status_editor($a, $x);
     $o .= replace_macros(get_markup_template('edpost_head.tpl'), array('$title' => t('Edit post'), '$editor' => $editor));
     return $o;
 }
Ejemplo n.º 2
0
Archivo: zot.php Proyecto: 23n/hubzilla
/**
 * @brief
 *
 * @param array $sender an associative array with
 *   * \e string \b hash a xchan_hash
 * @param array $arr an associative array
 *   * \e int \b verb
 *   * \e int \b obj_type
 *   * \e int \b mid
 * @param int $uid
 */
function remove_community_tag($sender, $arr, $uid)
{
    if (!(activity_match($arr['verb'], ACTIVITY_TAG) && $arr['obj_type'] == ACTIVITY_OBJ_TAGTERM)) {
        return;
    }
    logger('remove_community_tag: invoked');
    if (!get_pconfig($uid, 'system', 'blocktags')) {
        logger('remove_community tag: permission denied.');
        return;
    }
    $r = q("select * from item where mid = '%s' and uid = %d limit 1", dbesc($arr['mid']), intval($uid));
    if (!$r) {
        logger('remove_community_tag: no item');
        return;
    }
    if ($sender['hash'] != $r[0]['owner_xchan'] && $sender['hash'] != $r[0]['author_xchan']) {
        logger('remove_community_tag: sender not authorised.');
        return;
    }
    $i = $r[0];
    if ($i['target']) {
        $i['target'] = json_decode_plus($i['target']);
    }
    if ($i['object']) {
        $i['object'] = json_decode_plus($i['object']);
    }
    if (!($i['target'] && $i['object'])) {
        logger('remove_community_tag: no target/object');
        return;
    }
    $message_id = $i['target']['id'];
    $r = q("select id from item where mid = '%s' and uid = %d limit 1", dbesc($message_id), intval($uid));
    if (!$r) {
        logger('remove_community_tag: no parent message');
        return;
    }
    q("delete from term where uid = %d and oid = %d and otype = %d and type = %d and term = '%s' and url = '%s'", intval($uid), intval($r[0]['id']), intval(TERM_OBJ_POST), intval(TERM_HASHTAG), dbesc($i['object']['title']), dbesc(get_rel_link($i['object']['link'], 'alternate')));
}
Ejemplo n.º 3
0
/**
 * @brief Called when we deliver things that might be tagged in ways that require delivery processing.
 *
 * Handles community tagging of posts and also look for mention tags and sets up
 * a second delivery chain if appropriate.
 *
 * @param int $uid
 * @param int $item_id
 */
function tag_deliver($uid, $item_id)
{
    $mention = false;
    /*
     * Fetch stuff we need - a channel and an item
     */
    $u = q("select * from channel left join xchan on channel_hash = xchan_hash where channel_id = %d limit 1", intval($uid));
    if (!$u) {
        return;
    }
    $i = q("select * from item where id = %d and uid = %d limit 1", intval($item_id), intval($uid));
    if (!$i) {
        return;
    }
    $i = fetch_post_tags($i);
    $item = $i[0];
    if ($item['source_xchan'] && $item['item_flags'] & ITEM_UPLINK && $item['item_flags'] & ITEM_THREAD_TOP && $item['edited'] != $item['created']) {
        // this is an update (edit) to a post which was already processed by us and has a second delivery chain
        // Just start the second delivery chain to deliver the updated post
        proc_run('php', 'include/notifier.php', 'tgroup', $item['id']);
        return;
    }
    /*
     * Seems like a good place to plug in a poke notification.
     */
    if (stristr($item['verb'], ACTIVITY_POKE)) {
        $poke_notify = true;
        if ($item['obj_type'] == "" || $item['obj_type'] !== ACTIVITY_OBJ_PERSON || !$item['object']) {
            $poke_notify = false;
        }
        $obj = json_decode_plus($item['object']);
        if ($obj) {
            if ($obj['id'] !== $u[0]['channel_hash']) {
                $poke_notify = false;
            }
        }
        if ($item['item_restrict'] & ITEM_DELETED) {
            $poke_notify = false;
        }
        $verb = urldecode(substr($item['verb'], strpos($item['verb'], '#') + 1));
        if ($poke_notify) {
            require_once 'include/enotify.php';
            notification(array('to_xchan' => $u[0]['channel_hash'], 'from_xchan' => $item['author_xchan'], 'type' => NOTIFY_POKE, 'item' => $item, 'link' => $i[0]['llink'], 'verb' => ACTIVITY_POKE, 'activity' => $verb, 'otype' => 'item'));
        }
    }
    /*
     * Do community tagging
     */
    if ($item['obj_type'] === ACTIVITY_OBJ_TAGTERM) {
        // We received a community tag activity for a post.
        // See if we are the owner of the parent item and have given permission to tag our posts.
        // If so tag the parent post.
        logger('tag_deliver: community tag activity received');
        if ($item['owner_xchan'] === $u[0]['channel_hash'] && !get_pconfig($u[0]['channel_id'], 'system', 'blocktags')) {
            logger('tag_deliver: community tag recipient: ' . $u[0]['channel_name']);
            $j_tgt = json_decode_plus($item['target']);
            if ($j_tgt && $j_tgt['id']) {
                $p = q("select * from item where mid = '%s' and uid = %d limit 1", dbesc($j_tgt['id']), intval($u[0]['channel_id']));
                if ($p) {
                    $j_obj = json_decode_plus($item['object']);
                    logger('tag_deliver: tag object: ' . print_r($j_obj, true), LOGGER_DATA);
                    if ($j_obj && $j_obj['id'] && $j_obj['title']) {
                        if (is_array($j_obj['link'])) {
                            $taglink = get_rel_link($j_obj['link'], 'alternate');
                        }
                        store_item_tag($u[0]['channel_id'], $p[0]['id'], TERM_OBJ_POST, TERM_HASHTAG, $j_obj['title'], $j_obj['id']);
                        $x = q("update item set edited = '%s', received = '%s', changed = '%s' where mid = '%s' and uid = %d", dbesc(datetime_convert()), dbesc(datetime_convert()), dbesc(datetime_convert()), dbesc($j_tgt['id']), intval($u[0]['channel_id']));
                        proc_run('php', 'include/notifier.php', 'edit_post', $p[0]['id']);
                    }
                }
            }
        } else {
            logger('tag_deliver: tag permission denied for ' . $u[0]['channel_address']);
        }
    }
    /*
     * A "union" is a message which our channel has sourced from another channel.
     * This sets up a second delivery chain just like forum tags do.
     * Find out if this is a source-able post.
     */
    $union = check_item_source($uid, $item);
    if ($union) {
        logger('check_item_source returns true');
    }
    // This might be a followup (e.g. comment) by the original post author to a tagged forum
    // If so setup a second delivery chain
    if (!($item['item_flags'] & ITEM_THREAD_TOP)) {
        $x = q("select * from item where id = parent and parent = %d and uid = %d limit 1", intval($item['parent']), intval($uid));
        if ($x && $x[0]['item_flags'] & ITEM_UPLINK) {
            start_delivery_chain($u[0], $item, $item_id, $x[0]);
        }
    }
    /*
     * Now we've got those out of the way. Let's see if this is a post that's tagged for re-delivery
     */
    $terms = get_terms_oftype($item['term'], TERM_MENTION);
    if ($terms) {
        logger('tag_deliver: post mentions: ' . print_r($terms, true), LOGGER_DATA);
    }
    $link = normalise_link($u[0]['xchan_url']);
    if ($terms) {
        foreach ($terms as $term) {
            if (link_compare($term['url'], $link)) {
                $mention = true;
                break;
            }
        }
    }
    if ($mention) {
        logger('tag_deliver: mention found for ' . $u[0]['channel_name']);
        $r = q("update item set item_flags = ( item_flags | %d ) where id = %d", intval(ITEM_MENTIONSME), intval($item_id));
        // At this point we've determined that the person receiving this post was mentioned in it or it is a union.
        // Now let's check if this mention was inside a reshare so we don't spam a forum
        // If it's private we may have to unobscure it momentarily so that we can parse it.
        $body = '';
        if ($item['item_flags'] & ITEM_OBSCURED) {
            $key = get_config('system', 'prvkey');
            if ($item['body']) {
                $body = crypto_unencapsulate(json_decode_plus($item['body']), $key);
            }
        } else {
            $body = $item['body'];
        }
        $body = preg_replace('/\\[share(.*?)\\[\\/share\\]/', '', $body);
        $tagged = false;
        $plustagged = false;
        $matches = array();
        $pattern = '/@\\!?\\[zrl\\=' . preg_quote($term['url'], '/') . '\\]' . preg_quote($term['term'], '/') . '\\[\\/zrl\\]/';
        if (preg_match($pattern, $body, $matches)) {
            $tagged = true;
        }
        $pattern = '/@\\!?\\[zrl\\=([^\\]]*?)\\]((?:.(?!\\[zrl\\=))*?)\\+\\[\\/zrl\\]/';
        if (preg_match_all($pattern, $body, $matches, PREG_SET_ORDER)) {
            $max_forums = get_config('system', 'max_tagged_forums');
            if (!$max_forums) {
                $max_forums = 2;
            }
            $matched_forums = 0;
            foreach ($matches as $match) {
                $matched_forums++;
                if ($term['url'] === $match[1] && $term['term'] === $match[2]) {
                    if ($matched_forums <= $max_forums) {
                        $plustagged = true;
                        break;
                    }
                    logger('forum ' . $term['term'] . ' exceeded max_tagged_forums - ignoring');
                }
            }
        }
        if (!($tagged || $plustagged)) {
            logger('tag_deliver: mention was in a reshare or exceeded max_tagged_forums - ignoring');
            return;
        }
        $arr = array('channel_id' => $uid, 'item' => $item, 'body' => $body);
        call_hooks('tagged', $arr);
        /*
         * Kill two birds with one stone. As long as we're here, send a mention notification.
         */
        require_once 'include/enotify.php';
        notification(array('to_xchan' => $u[0]['channel_hash'], 'from_xchan' => $item['author_xchan'], 'type' => NOTIFY_TAGSELF, 'item' => $item, 'link' => $i[0]['llink'], 'verb' => ACTIVITY_TAG, 'otype' => 'item'));
        // Just a normal tag?
        if (!$plustagged) {
            logger('tag_deliver: not a plus tag', LOGGER_DEBUG);
            return;
        }
        // plustagged - keep going, next check permissions
        if (!perm_is_allowed($uid, $item['author_xchan'], 'tag_deliver')) {
            logger('tag_delivery denied for uid ' . $uid . ' and xchan ' . $item['author_xchan']);
            return;
        }
    }
    if (!$mention && !$union) {
        logger('tag_deliver: no mention and no union.');
        return;
    }
    // tgroup delivery - setup a second delivery chain
    // prevent delivery looping - only proceed
    // if the message originated elsewhere and is a top-level post
    if ($item['item_flags'] & ITEM_WALL || $item['item_flags'] & ITEM_ORIGIN || !($item['item_flags'] & ITEM_THREAD_TOP) || $item['id'] != $item['parent']) {
        logger('tag_deliver: item was local or a comment. rejected.');
        return;
    }
    logger('tag_deliver: creating second delivery chain.');
    start_delivery_chain($u[0], $item, $item_id, null);
}
Ejemplo n.º 4
0
/**
 * Render actions localized
 */
function localize_item(&$item)
{
    if (activity_match($item['verb'], ACTIVITY_LIKE) || activity_match($item['verb'], ACTIVITY_DISLIKE)) {
        if (!$item['object']) {
            return;
        }
        if ($item['item_flags'] & ITEM_THREAD_TOP) {
            return;
        }
        $obj = json_decode_plus($item['object']);
        if (!$obj && $item['object']) {
            logger('localize_item: failed to decode object: ' . print_r($item['object'], true));
        }
        if ($obj['author'] && $obj['author']['link']) {
            $author_link = get_rel_link($obj['author']['link'], 'alternate');
        } else {
            $author_link = '';
        }
        $author_name = $obj['author'] && $obj['author']['name'] ? $obj['author']['name'] : '';
        $item_url = get_rel_link($obj['link'], 'alternate');
        $Bphoto = '';
        switch ($obj['type']) {
            case ACTIVITY_OBJ_PHOTO:
                $post_type = t('photo');
                break;
            case ACTIVITY_OBJ_EVENT:
                $post_type = t('event');
                break;
            case ACTIVITY_OBJ_PERSON:
                $post_type = t('channel');
                $author_name = $obj['title'];
                if ($obj['link']) {
                    $author_link = get_rel_link($obj['link'], 'alternate');
                    $Bphoto = get_rel_link($obj['link'], 'photo');
                }
                break;
            case ACTIVITY_OBJ_THING:
                $post_type = $obj['title'];
                if ($obj['owner']) {
                    if (array_key_exists('name', $obj['owner'])) {
                        $obj['owner']['name'];
                    }
                    if (array_key_exists('link', $obj['owner'])) {
                        $author_link = get_rel_link($obj['owner']['link'], 'alternate');
                    }
                }
                if ($obj['link']) {
                    $Bphoto = get_rel_link($obj['link'], 'photo');
                }
                break;
            case ACTIVITY_OBJ_NOTE:
            default:
                $post_type = t('status');
                if ($obj['mid'] != $obj['parent_mid']) {
                    $post_type = t('comment');
                }
                break;
        }
        // If we couldn't parse something useful, don't bother translating.
        // We need something better than zid here, probably magic_link(), but it needs writing
        if ($author_link && $author_name && $item_url) {
            $author = '[zrl=' . chanlink_url($item['author']['xchan_url']) . ']' . $item['author']['xchan_name'] . '[/zrl]';
            $objauthor = '[zrl=' . chanlink_url($author_link) . ']' . $author_name . '[/zrl]';
            $plink = '[zrl=' . zid($item_url) . ']' . $post_type . '[/zrl]';
            if (activity_match($item['verb'], ACTIVITY_LIKE)) {
                $bodyverb = t('%1$s likes %2$s\'s %3$s');
            } elseif (activity_match($item['verb'], ACTIVITY_DISLIKE)) {
                $bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s');
            }
            $item['body'] = $item['localize'] = sprintf($bodyverb, $author, $objauthor, $plink);
            if ($Bphoto != "") {
                $item['body'] .= "\n\n\n" . '[zrl=' . chanlink_url($author_link) . '][zmg=80x80]' . $Bphoto . '[/zmg][/zrl]';
            }
        } else {
            logger('localize_item like failed: link ' . $author_link . ' name ' . $author_name . ' url ' . $item_url);
        }
    }
    if (activity_match($item['verb'], ACTIVITY_FRIEND)) {
        if ($item['obj_type'] == "" || $item['obj_type'] !== ACTIVITY_OBJ_PERSON) {
            return;
        }
        $Aname = $item['author']['xchan_name'];
        $Alink = $item['author']['xchan_url'];
        $obj = json_decode_plus($item['object']);
        $Blink = $Bphoto = '';
        if ($obj['link']) {
            $Blink = get_rel_link($obj['link'], 'alternate');
            $Bphoto = get_rel_link($obj['link'], 'photo');
        }
        $Bname = $obj['title'];
        $A = '[zrl=' . chanlink_url($Alink) . ']' . $Aname . '[/zrl]';
        $B = '[zrl=' . chanlink_url($Blink) . ']' . $Bname . '[/zrl]';
        if ($Bphoto != "") {
            $Bphoto = '[zrl=' . chanlink_url($Blink) . '][zmg=80x80]' . $Bphoto . '[/zmg][/zrl]';
        }
        $item['body'] = $item['localize'] = sprintf(t('%1$s is now connected with %2$s'), $A, $B);
        $item['body'] .= "\n\n\n" . $Bphoto;
    }
    if (stristr($item['verb'], ACTIVITY_POKE)) {
        /** @FIXME for obscured private posts, until then leave untranslated */
        return;
        $verb = urldecode(substr($item['verb'], strpos($item['verb'], '#') + 1));
        if (!$verb) {
            return;
        }
        if ($item['obj_type'] == "" || $item['obj_type'] !== ACTIVITY_OBJ_PERSON) {
            return;
        }
        $Aname = $item['author']['xchan_name'];
        $Alink = $item['author']['xchan_url'];
        $obj = json_decode_plus($item['object']);
        $Blink = $Bphoto = '';
        if ($obj['link']) {
            $Blink = get_rel_link($obj['link'], 'alternate');
            $Bphoto = get_rel_link($obj['link'], 'photo');
        }
        $Bname = $obj['title'];
        $A = '[zrl=' . chanlink_url($Alink) . ']' . $Aname . '[/zrl]';
        $B = '[zrl=' . chanlink_url($Blink) . ']' . $Bname . '[/zrl]';
        if ($Bphoto != "") {
            $Bphoto = '[zrl=' . chanlink_url($Blink) . '][zmg=80x80]' . $Bphoto . '[/zmg][/zrl]';
        }
        // we can't have a translation string with three positions but no distinguishable text
        // So here is the translate string.
        $txt = t('%1$s poked %2$s');
        // now translate the verb
        $txt = str_replace(t('poked'), t($verb), $txt);
        // then do the sprintf on the translation string
        $item['body'] = $item['localize'] = sprintf($txt, $A, $B);
        $item['body'] .= "\n\n\n" . $Bphoto;
    }
    if (stristr($item['verb'], ACTIVITY_MOOD)) {
        $verb = urldecode(substr($item['verb'], strpos($item['verb'], '#') + 1));
        if (!$verb) {
            return;
        }
        $Aname = $item['author']['xchan_name'];
        $Alink = $item['author']['xchan_url'];
        $A = '[zrl=' . chanlink_url($Alink) . ']' . $Aname . '[/zrl]';
        $txt = t('%1$s is %2$s', 'mood');
        $item['body'] = sprintf($txt, $A, t($verb));
    }
    /*
    // FIXME store parent item as object or target
    // (and update to json storage)
    
     	if (activity_match($item['verb'],ACTIVITY_TAG)) {
    		$r = q("SELECT * from `item`,`contact` WHERE 
    		`item`.`contact-id`=`contact`.`id` AND `item`.`mid`='%s';",
    		 dbesc($item['parent_mid']));
    		if(count($r)==0) return;
    		$obj=$r[0];
    		
    		$author	 = '[zrl=' . zid($item['author-link']) . ']' . $item['author-name'] . '[/zrl]';
    		$objauthor =  '[zrl=' . zid($obj['author-link']) . ']' . $obj['author-name'] . '[/zrl]';
    		
    		switch($obj['verb']){
    			case ACTIVITY_POST:
    				switch ($obj['obj_type']){
    					case ACTIVITY_OBJ_EVENT:
    						$post_type = t('event');
    						break;
    					default:
    						$post_type = t('status');
    				}
    				break;
    			default:
    				if($obj['resource_id']){
    					$post_type = t('photo');
    					$m=array(); preg_match("/\[[zu]rl=([^]]*)\]/", $obj['body'], $m);
    					$rr['plink'] = $m[1];
    				} else {
    					$post_type = t('status');
    				}
    		}
    		$plink = '[zrl=' . $obj['plink'] . ']' . $post_type . '[/zrl]';
    
    		$parsedobj = parse_xml_string($xmlhead.$item['object']);
    
    		$tag = sprintf('#[zrl=%s]%s[/zrl]', $parsedobj->id, $parsedobj->content);
    		$item['body'] = sprintf( t('%1$s tagged %2$s\'s %3$s with %4$s'), $author, $objauthor, $plink, $tag );
    
    	}
    
    	if (activity_match($item['verb'],ACTIVITY_FAVORITE)){
    
    		if ($item['obj_type']== "")
    			return;
    
    		$Aname = $item['author']['xchan_name'];
    		$Alink = $item['author']['xchan_url'];
    
    		$xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
    
    		$obj = parse_xml_string($xmlhead.$item['object']);
    		if(strlen($obj->id)) {
    			$r = q("select * from item where mid = '%s' and uid = %d limit 1",
    					dbesc($obj->id),
    					intval($item['uid'])
    			);
    			if(count($r) && $r[0]['plink']) {
    				$target = $r[0];
    				$Bname = $target['author-name'];
    				$Blink = $target['author-link'];
    				$A = '[zrl=' . zid($Alink) . ']' . $Aname . '[/zrl]';
    				$B = '[zrl=' . zid($Blink) . ']' . $Bname . '[/zrl]';
    				$P = '[zrl=' . $target['plink'] . ']' . t('post/item') . '[/zrl]';
    				$item['body'] = sprintf( t('%1$s marked %2$s\'s %3$s as favorite'), $A, $B, $P)."\n";
    
    			}
    		}
    	}
    */
    /*
    	$matches = null;
    	if(strpos($item['body'],'[zrl') !== false) {
    		if(preg_match_all('/@\[zrl=(.*?)\]/is',$item['body'],$matches,PREG_SET_ORDER)) {
    			foreach($matches as $mtch) {
    				if(! strpos($mtch[1],'zid='))
    					$item['body'] = str_replace($mtch[0],'@[zrl=' . zid($mtch[1]). ']',$item['body']);
    			}
    		}
    	}
    
    	if(strpos($item['body'],'[zmg') !== false) {
    		// add zid's to public images
    		if(preg_match_all('/\[zrl=(.*?)\/photos\/(.*?)\/image\/(.*?)\]\[zmg(.*?)\]h(.*?)\[\/zmg\]\[\/zrl\]/is',$item['body'],$matches,PREG_SET_ORDER)) {
    			foreach($matches as $mtch) {
    				$item['body'] = str_replace($mtch[0],'[zrl=' . zid( $mtch[1] . '/photos/' . $mtch[2] . '/image/' . $mtch[3]) . '][zmg' . $mtch[4] . ']h' . $mtch[5]  . '[/zmg][/zrl]',$item['body']);
    			}
    		}
    	}
    */
    // add sparkle links to appropriate permalinks
    //	$x = stristr($item['plink'],'/display/');
    //	if($x) {
    //		$sparkle = false;
    //		$y = best_link_url($item,$sparkle,true);
    //	if($sparkle)
    //			$item['plink'] = $y . '?f=&url=' . $item['plink'];
    //	}
    // if item body was obscured and we changed it, re-obscure it
    // FIXME - we need a better filter than just the string 'data'; try and
    // match the fact that it's json encoded
    if ($item['item_flags'] & ITEM_OBSCURED && strlen($item['body']) && !strpos($item['body'], 'data')) {
        $item['body'] = json_encode(crypto_encapsulate($item['body'], get_config('system', 'pubkey')));
    }
}
Ejemplo n.º 5
0
function theme_attachments(&$item)
{
    $arr = json_decode_plus($item['attach']);
    if (is_array($arr) && count($arr)) {
        $attaches = array();
        foreach ($arr as $r) {
            $icon = getIconFromType($r['type']);
            $label = $r['title'] ? urldecode(htmlspecialchars($r['title'], ENT_COMPAT, 'UTF-8')) : t('Unknown Attachment');
            //some feeds provide an attachment where title an empty space
            if ($label == ' ') {
                $label = t('Unknown Attachment');
            }
            $title = t('Size') . ' ' . ($r['length'] ? userReadableSize($r['length']) : t('unknown'));
            require_once 'include/identity.php';
            if (is_foreigner($item['author_xchan'])) {
                $url = $r['href'];
            } else {
                $url = z_root() . '/magic?f=&hash=' . $item['author_xchan'] . '&dest=' . $r['href'] . '/' . $r['revision'];
            }
            //$s .= '<a href="' . $url . '" title="' . $title . '" class="attachlink"  >' . $icon . '</a>';
            $attaches[] = array('label' => $label, 'url' => $url, 'icon' => $icon, 'title' => $title);
        }
        $s = replace_macros(get_markup_template('item_attach.tpl'), array('$attaches' => $attaches));
    }
    return $s;
}
Ejemplo n.º 6
0
function private_messages_fetch_conversation($channel_id, $messageitem_id, $updateseen = false)
{
    // find the parent_mid of the message being requested
    $r = q("SELECT parent_mid from mail WHERE channel_id = %d and id = %d limit 1", intval($channel_id), intval($messageitem_id));
    if (!$r) {
        return array();
    }
    $messages = q("select * from mail where parent_mid = '%s' and channel_id = %d order by created asc", dbesc($r[0]['parent_mid']), intval($channel_id));
    if (!$messages) {
        return array();
    }
    $chans = array();
    foreach ($messages as $rr) {
        $s = "'" . dbesc(trim($rr['from_xchan'])) . "'";
        if (!in_array($s, $chans)) {
            $chans[] = $s;
        }
        $s = "'" . dbesc(trim($rr['to_xchan'])) . "'";
        if (!in_array($s, $chans)) {
            $chans[] = $s;
        }
    }
    $c = q("select * from xchan where xchan_hash in (" . implode(',', $chans) . ")");
    foreach ($messages as $k => $message) {
        $messages[$k]['from'] = find_xchan_in_array($message['from_xchan'], $c);
        $messages[$k]['to'] = find_xchan_in_array($message['to_xchan'], $c);
        if ($messages[$k]['mail_flags'] & MAIL_OBSCURED) {
            $key = get_config('system', 'prvkey');
            if ($messages[$k]['title']) {
                $messages[$k]['title'] = crypto_unencapsulate(json_decode_plus($messages[$k]['title']), $key);
            }
            if ($messages[$k]['body']) {
                $messages[$k]['body'] = crypto_unencapsulate(json_decode_plus($messages[$k]['body']), $key);
            }
        }
    }
    if ($updateseen) {
        $r = q("UPDATE `mail` SET mail_flags = (mail_flags ^ %d) where not (mail_flags & %d) and parent_mid = '%s' AND channel_id = %d", intval(MAIL_SEEN), intval(MAIL_SEEN), dbesc($r[0]['parent_mid']), intval($channel_id));
    }
    return $messages;
}
Ejemplo n.º 7
0
 function get()
 {
     if (!\App::$profile) {
         notice(t('Requested profile is not available.') . EOL);
         \App::$error = 404;
         return;
     }
     $which = argv(1);
     $uid = local_channel();
     $owner = 0;
     $channel = null;
     $observer = \App::get_observer();
     $channel = \App::get_channel();
     if (\App::$is_sys && is_site_admin()) {
         $sys = get_sys_channel();
         if ($sys && intval($sys['channel_id'])) {
             $uid = $owner = intval($sys['channel_id']);
             $channel = $sys;
             $observer = $sys;
         }
     }
     if (!$owner) {
         // Figure out who the page owner is.
         $r = q("select channel_id from channel where channel_address = '%s'", dbesc($which));
         if ($r) {
             $owner = intval($r[0]['channel_id']);
         }
     }
     $ob_hash = $observer ? $observer['xchan_hash'] : '';
     if (!perm_is_allowed($owner, $ob_hash, 'write_pages')) {
         notice(t('Permission denied.') . EOL);
         return;
     }
     $is_owner = $uid && $uid == $owner ? true : false;
     $o = '';
     // Figure out which post we're editing
     $post_id = argc() > 2 ? intval(argv(2)) : 0;
     if (!$post_id) {
         notice(t('Item not found') . EOL);
         return;
     }
     $ob_hash = $observer ? $observer['xchan_hash'] : '';
     $perms = get_all_perms($owner, $ob_hash);
     if (!$perms['write_pages']) {
         notice(t('Permission denied.') . EOL);
         return;
     }
     // We've already figured out which item we want and whose copy we need,
     // so we don't need anything fancy here
     $sql_extra = item_permissions_sql($owner);
     $itm = q("SELECT * FROM `item` WHERE `id` = %d and uid = %s {$sql_extra} LIMIT 1", intval($post_id), intval($owner));
     if (!$itm) {
         notice(t('Permission denied.') . EOL);
         return;
     }
     if (intval($itm[0]['item_obscured'])) {
         $key = get_config('system', 'prvkey');
         if ($itm[0]['title']) {
             $itm[0]['title'] = crypto_unencapsulate(json_decode_plus($itm[0]['title']), $key);
         }
         if ($itm[0]['body']) {
             $itm[0]['body'] = crypto_unencapsulate(json_decode_plus($itm[0]['body']), $key);
         }
     }
     $item_id = q("select * from item_id where service = 'WEBPAGE' and iid = %d limit 1", intval($itm[0]['id']));
     if ($item_id) {
         $page_title = $item_id[0]['sid'];
     }
     $mimetype = $itm[0]['mimetype'];
     if ($mimetype === 'application/x-php') {
         if (!$uid || $uid != $itm[0]['uid']) {
             notice(t('Permission denied.') . EOL);
             return;
         }
     }
     $layout = $itm[0]['layout_mid'];
     $tpl = get_markup_template("jot.tpl");
     $rp = 'webpages/' . $which;
     $x = array('nickname' => $channel['channel_address'], 'bbco_autocomplete' => $mimetype == 'text/bbcode' ? 'bbcode' : '', 'return_path' => $rp, 'webpage' => ITEM_TYPE_WEBPAGE, 'ptlabel' => t('Page link'), 'pagetitle' => $page_title, 'writefiles' => $mimetype == 'text/bbcode' ? perm_is_allowed($owner, get_observer_hash(), 'write_storage') : false, 'button' => t('Edit'), 'weblink' => $mimetype == 'text/bbcode' ? t('Insert web link') : false, 'hide_location' => true, 'hide_voting' => true, 'ptyp' => $itm[0]['type'], 'body' => undo_post_tagging($itm[0]['body']), 'post_id' => $post_id, 'visitor' => $is_owner ? true : false, 'acl' => populate_acl($itm[0], false, \PermissionDescription::fromGlobalPermission('view_pages')), 'showacl' => $is_owner ? true : false, 'mimetype' => $mimetype, 'mimeselect' => true, 'layout' => $layout, 'layoutselect' => true, 'title' => htmlspecialchars($itm[0]['title'], ENT_COMPAT, 'UTF-8'), 'lockstate' => strlen($itm[0]['allow_cid']) || strlen($itm[0]['allow_gid']) || strlen($itm[0]['deny_cid']) || strlen($itm[0]['deny_gid']) ? 'lock' : 'unlock', 'profile_uid' => intval($owner), 'bbcode' => $mimetype == 'text/bbcode' ? true : false);
     $editor = status_editor($a, $x);
     $o .= replace_macros(get_markup_template('edpost_head.tpl'), array('$title' => t('Edit Webpage'), '$delete' => $itm[0]['author_xchan'] === $ob_hash || $itm[0]['owner_xchan'] === $ob_hash ? t('Delete') : false, '$editor' => $editor, '$id' => $itm[0]['id']));
     return $o;
 }
Ejemplo n.º 8
0
function editwebpage_content(&$a)
{
    if (!App::$profile) {
        notice(t('Requested profile is not available.') . EOL);
        App::$error = 404;
        return;
    }
    $which = argv(1);
    $uid = local_channel();
    $owner = 0;
    $channel = null;
    $observer = App::get_observer();
    $channel = App::get_channel();
    if (App::$is_sys && is_site_admin()) {
        $sys = get_sys_channel();
        if ($sys && intval($sys['channel_id'])) {
            $uid = $owner = intval($sys['channel_id']);
            $channel = $sys;
            $observer = $sys;
        }
    }
    if (!$owner) {
        // Figure out who the page owner is.
        $r = q("select channel_id from channel where channel_address = '%s'", dbesc($which));
        if ($r) {
            $owner = intval($r[0]['channel_id']);
        }
    }
    $ob_hash = $observer ? $observer['xchan_hash'] : '';
    if (!perm_is_allowed($owner, $ob_hash, 'write_pages')) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    $is_owner = $uid && $uid == $owner ? true : false;
    $o = '';
    // Figure out which post we're editing
    $post_id = argc() > 2 ? intval(argv(2)) : 0;
    if (!$post_id) {
        notice(t('Item not found') . EOL);
        return;
    }
    $ob_hash = $observer ? $observer['xchan_hash'] : '';
    $perms = get_all_perms($owner, $ob_hash);
    if (!$perms['write_pages']) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    // We've already figured out which item we want and whose copy we need,
    // so we don't need anything fancy here
    $sql_extra = item_permissions_sql($owner);
    $itm = q("SELECT * FROM `item` WHERE `id` = %d and uid = %s {$sql_extra} LIMIT 1", intval($post_id), intval($owner));
    if (!$itm) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    if (intval($itm[0]['item_obscured'])) {
        $key = get_config('system', 'prvkey');
        if ($itm[0]['title']) {
            $itm[0]['title'] = crypto_unencapsulate(json_decode_plus($itm[0]['title']), $key);
        }
        if ($itm[0]['body']) {
            $itm[0]['body'] = crypto_unencapsulate(json_decode_plus($itm[0]['body']), $key);
        }
    }
    $item_id = q("select * from item_id where service = 'WEBPAGE' and iid = %d limit 1", intval($itm[0]['id']));
    if ($item_id) {
        $page_title = $item_id[0]['sid'];
    }
    $plaintext = true;
    $mimetype = $itm[0]['mimetype'];
    if ($mimetype === 'application/x-php') {
        if (!$uid || $uid != $itm[0]['uid']) {
            notice(t('Permission denied.') . EOL);
            return;
        }
    }
    $mimeselect = '';
    if ($mimetype != 'text/bbcode') {
        $plaintext = true;
    }
    if (get_config('system', 'page_mimetype')) {
        $mimeselect = '<input type="hidden" name="mimetype" value="' . $mimetype . '" />';
    } else {
        $mimeselect = mimetype_select($itm[0]['uid'], $mimetype);
    }
    $layout = get_config('system', 'page_layout');
    if ($layout) {
        $layoutselect = '<input type="hidden" name="layout_mid" value="' . $layout . '" />';
    } else {
        $layoutselect = layout_select($itm[0]['uid'], $itm[0]['layout_mid']);
    }
    App::$page['htmlhead'] .= replace_macros(get_markup_template('jot-header.tpl'), array('$baseurl' => z_root(), '$editselect' => $plaintext ? 'none' : '/(profile-jot-text|prvmail-text)/', '$pretext' => '', '$ispublic' => '&nbsp;', '$geotag' => $geotag, '$nickname' => $channel['channel_address'], '$confirmdelete' => t('Delete webpage?'), '$bbco_autocomplete' => $mimetype == 'text/bbcode' ? 'bbcode' : ''));
    $tpl = get_markup_template("jot.tpl");
    $jotplugins = '';
    $jotnets = '';
    call_hooks('jot_tool', $jotplugins);
    call_hooks('jot_networks', $jotnets);
    // FIXME A return path with $_SESSION doesn't always work for observer - it may WSoD
    // instead of loading a sensible page.  So, send folk to the webpage list.
    $rp = 'webpages/' . $which;
    $editor = replace_macros($tpl, array('$return_path' => $rp, '$webpage' => ITEM_TYPE_WEBPAGE, '$placeholdpagetitle' => t('Page link title'), '$pagetitle' => $page_title, '$writefiles' => perm_is_allowed($owner, get_observer_hash(), 'write_storage'), '$action' => 'item', '$share' => t('Edit'), '$bold' => t('Bold'), '$italic' => t('Italic'), '$underline' => t('Underline'), '$quote' => t('Quote'), '$code' => t('Code'), '$upload' => t('Upload photo'), '$attach' => t('Attach file'), '$weblink' => t('Insert web link'), '$youtube' => t('Insert YouTube video'), '$video' => t('Insert Vorbis [.ogg] video'), '$audio' => t('Insert Vorbis [.ogg] audio'), '$setloc' => t('Set your location'), '$noloc' => get_pconfig($uid, 'system', 'use_browser_location') ? t('Clear browser location') : '', '$wait' => t('Please wait'), '$permset' => t('Permission settings'), '$ptyp' => $itm[0]['type'], '$content' => undo_post_tagging($itm[0]['body']), '$post_id' => $post_id, '$baseurl' => z_root(), '$defloc' => $itm[0]['location'], '$visitor' => $is_owner ? true : false, '$acl' => populate_acl($itm[0], false), '$showacl' => $is_owner ? true : false, '$public' => t('Public post'), '$jotnets' => $jotnets, '$mimeselect' => $mimeselect, '$layoutselect' => $layoutselect, '$title' => htmlspecialchars($itm[0]['title'], ENT_COMPAT, 'UTF-8'), '$placeholdertitle' => t('Title (optional)'), '$category' => '', '$placeholdercategory' => t('Categories (optional, comma-separated list)'), '$emtitle' => t('Example: bob@example.com, mary@example.com'), 'lockstate' => strlen($itm[0]['allow_cid']) || strlen($itm[0]['allow_gid']) || strlen($itm[0]['deny_cid']) || strlen($itm[0]['deny_gid']) ? 'lock' : 'unlock', '$bang' => '', '$profile_uid' => intval($owner), '$preview' => t('Preview'), '$jotplugins' => $jotplugins, '$sourceapp' => App::$sourcename, '$defexpire' => '', '$feature_expire' => false, '$expires' => t('Set expiration date'), '$bbcode' => $mimetype == 'text/bbcode' ? true : false));
    $o .= replace_macros(get_markup_template('edpost_head.tpl'), array('$title' => t('Edit Webpage'), '$delete' => $itm[0]['author_xchan'] === $ob_hash || $itm[0]['owner_xchan'] === $ob_hash ? t('Delete') : false, '$editor' => $editor, '$id' => $itm[0]['id']));
    return $o;
}
Ejemplo n.º 9
0
function diaspora_send_mail($item, $owner, $contact)
{
    $a = get_app();
    $myaddr = $owner['channel_address'] . '@' . get_app()->get_hostname();
    $r = q("select * from conv where id = %d and uid = %d limit 1", intval($item['convid']), intval($item['channel_id']));
    if (!count($r)) {
        logger('diaspora_send_mail: conversation not found.');
        return;
    }
    $cnv = $r[0];
    $conv = array('guid' => xmlify($cnv['guid']), 'subject' => xmlify($cnv['subject']), 'created_at' => xmlify(datetime_convert('UTC', 'UTC', $cnv['created'], 'Y-m-d H:i:s \\U\\T\\C')), 'diaspora_handle' => xmlify($cnv['creator']), 'participant_handles' => xmlify($cnv['recips']));
    if (array_key_exists('mail_flags', $item) && $item['mail_flags'] & MAIL_OBSCURED) {
        $key = get_config('system', 'prvkey');
        //		if($item['title'])
        //			$item['title'] = crypto_unencapsulate(json_decode_plus($item['title']),$key);
        if ($item['body']) {
            $item['body'] = crypto_unencapsulate(json_decode_plus($item['body']), $key);
        }
    }
    $body = bb2diaspora($item['body']);
    $created = datetime_convert('UTC', 'UTC', $item['created'], 'Y-m-d H:i:s \\U\\T\\C');
    $signed_text = $item['mid'] . ';' . $cnv['guid'] . ';' . $body . ';' . $created . ';' . $myaddr . ';' . $cnv['guid'];
    $sig = base64_encode(rsa_sign($signed_text, $owner['channel_prvkey'], 'sha256'));
    $msg = array('guid' => xmlify($item['mid']), 'parent_guid' => xmlify($cnv['guid']), 'parent_author_signature' => $item['reply'] ? null : xmlify($sig), 'author_signature' => xmlify($sig), 'text' => xmlify($body), 'created_at' => xmlify($created), 'diaspora_handle' => xmlify($myaddr), 'conversation_guid' => xmlify($cnv['guid']));
    if ($item['reply']) {
        $tpl = get_markup_template('diaspora_message.tpl');
        $xmsg = replace_macros($tpl, array('$msg' => $msg));
    } else {
        $conv['messages'] = array($msg);
        $tpl = get_markup_template('diaspora_conversation.tpl');
        $xmsg = replace_macros($tpl, array('$conv' => $conv));
    }
    logger('diaspora_conversation: ' . print_r($xmsg, true), LOGGER_DATA);
    $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($xmsg, $owner, $contact, $owner['channel_prvkey'], $contact['xchan_pubkey'], false)));
    return diaspora_transmit($owner, $contact, $slap, false);
}
Ejemplo n.º 10
0
function theme_attachments(&$item)
{
    $arr = json_decode_plus($item['attach']);
    if (is_array($arr) && count($arr)) {
        $attaches = array();
        foreach ($arr as $r) {
            $icon = '';
            $icontype = substr($r['type'], 0, strpos($r['type'], '/'));
            /**
             * @FIXME This should probably be a giant "if" statement in the
             * template so that we don't have icon names embedded in php code.
             */
            switch ($icontype) {
                case 'video':
                    $icon = 'icon-facetime-video';
                    break;
                case 'audio':
                    $icon = 'icon-volume-up';
                    break;
                case 'image':
                    $icon = 'icon-picture';
                    break;
                case 'text':
                    $icon = 'icon-align-justify';
                    break;
                default:
                    $icon = 'icon-question';
                    break;
            }
            $title = htmlspecialchars($r['title'], ENT_COMPAT, 'UTF-8');
            if (!$title) {
                $title = t('unknown.???');
            }
            $title .= ' ' . $r['length'] . ' ' . t('bytes');
            require_once 'include/identity.php';
            if (is_foreigner($item['author_xchan'])) {
                $url = $r['href'];
            } else {
                $url = z_root() . '/magic?f=&hash=' . $item['author_xchan'] . '&dest=' . $r['href'] . '/' . $r['revision'];
            }
            $s .= '<a href="' . $url . '" title="' . $title . '" class="attachlink"  >' . $icon . '</a>';
            $attaches[] = array('title' => $title, 'url' => $url, 'icon' => $icon);
        }
    }
    $s = replace_macros(get_markup_template('item_attach.tpl'), array('$attaches' => $attaches));
    return $s;
}
Ejemplo n.º 11
0
function editwebpage_content(&$a)
{
    // We first need to figure out who owns the webpage, grab it from an argument
    $which = argv(1);
    // $a->get_channel() and stuff don't work here, so we've got to find the owner for ourselves.
    $r = q("select channel_id from channel where channel_address = '%s'", dbesc($which));
    if ($r) {
        $owner = intval($r[0]['channel_id']);
        //logger('owner: ' . print_r($owner,true));
    }
    $is_owner = local_user() && local_user() == $owner ? true : false;
    $o = '';
    // Figure out which post we're editing
    $post_id = argc() > 2 ? intval(argv(2)) : 0;
    if (!$post_id) {
        notice(t('Item not found') . EOL);
        return;
    }
    // Now we've got a post and an owner, let's find out if we're allowed to edit it
    $observer = $a->get_observer();
    $ob_hash = $observer ? $observer['xchan_hash'] : '';
    $perms = get_all_perms($owner, $ob_hash);
    if (!$perms['write_pages']) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    // We've already figured out which item we want and whose copy we need, so we don't need anything fancy here
    $itm = q("SELECT * FROM `item` WHERE `id` = %d and uid = %s LIMIT 1", intval($post_id), intval($owner));
    if ($itm[0]['item_flags'] & ITEM_OBSCURED) {
        $key = get_config('system', 'prvkey');
        if ($itm[0]['title']) {
            $itm[0]['title'] = crypto_unencapsulate(json_decode_plus($itm[0]['title']), $key);
        }
        if ($itm[0]['body']) {
            $itm[0]['body'] = crypto_unencapsulate(json_decode_plus($itm[0]['body']), $key);
        }
    }
    $item_id = q("select * from item_id where service = 'WEBPAGE' and iid = %d limit 1", $itm[0]['id']);
    if ($item_id) {
        $page_title = $item_id[0]['sid'];
    }
    $plaintext = true;
    //	if(feature_enabled($itm[0]['uid'],'richtext'))
    //		$plaintext = false;
    $mimetype = $itm[0]['mimetype'];
    if ($mimetype === 'application/x-php') {
        if (!local_user() || local_user() != $itm[0]['uid']) {
            notice(t('Permission denied.') . EOL);
            return;
        }
    }
    $mimeselect = '';
    if ($mimetype != 'text/bbcode') {
        $plaintext = true;
    }
    if (get_config('system', 'page_mimetype')) {
        $mimeselect = '<input type="hidden" name="mimetype" value="' . $mimetype . '" />';
    } else {
        $mimeselect = mimetype_select($itm[0]['uid'], $mimetype);
    }
    $layout = get_config('system', 'page_layout');
    if ($layout) {
        $layoutselect = '<input type="hidden" name="layout_mid" value="' . $layout . '" />';
    } else {
        $layoutselect = layout_select($itm[0]['uid'], $itm[0]['layout_mid']);
    }
    $o .= replace_macros(get_markup_template('edpost_head.tpl'), array('$title' => t('Edit Webpage')));
    $a->page['htmlhead'] .= replace_macros(get_markup_template('jot-header.tpl'), array('$baseurl' => $a->get_baseurl(), '$editselect' => $plaintext ? 'none' : '/(profile-jot-text|prvmail-text)/', '$ispublic' => '&nbsp;', '$geotag' => $geotag, '$nickname' => $a->user['nickname'], '$confirmdelete' => t('Delete webpage?')));
    $tpl = get_markup_template("jot.tpl");
    $jotplugins = '';
    $jotnets = '';
    call_hooks('jot_tool', $jotplugins);
    call_hooks('jot_networks', $jotnets);
    $channel = $a->get_channel();
    //$tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
    //FIXME A return path with $_SESSION doesn't always work for observer - it may WSoD instead of loading a sensible page.  So, send folk to the webpage list.
    $rp = 'webpages/' . $which;
    $o .= replace_macros($tpl, array('$return_path' => $rp, '$webpage' => ITEM_WEBPAGE, '$placeholdpagetitle' => t('Page link title'), '$pagetitle' => $page_title, '$action' => 'item', '$share' => t('Edit'), '$upload' => t('Upload photo'), '$attach' => t('Attach file'), '$weblink' => t('Insert web link'), '$youtube' => t('Insert YouTube video'), '$video' => t('Insert Vorbis [.ogg] video'), '$audio' => t('Insert Vorbis [.ogg] audio'), '$setloc' => t('Set your location'), '$noloc' => t('Clear browser location'), '$wait' => t('Please wait'), '$permset' => t('Permission settings'), '$ptyp' => $itm[0]['type'], '$content' => undo_post_tagging($itm[0]['body']), '$post_id' => $post_id, '$baseurl' => $a->get_baseurl(), '$defloc' => $itm[0]['location'], '$visitor' => $is_owner ? true : false, '$acl' => populate_acl($itm[0], false), '$showacl' => $is_owner ? true : false, '$public' => t('Public post'), '$jotnets' => $jotnets, '$mimeselect' => $mimeselect, '$layoutselect' => $layoutselect, '$title' => htmlspecialchars($itm[0]['title'], ENT_COMPAT, 'UTF-8'), '$placeholdertitle' => t('Set title'), '$category' => '', '$placeholdercategory' => t('Categories (comma-separated list)'), '$emtitle' => t('Example: bob@example.com, mary@example.com'), 'lockstate' => strlen($itm[0]['allow_cid']) || strlen($itm[0]['allow_gid']) || strlen($itm[0]['deny_cid']) || strlen($itm[0]['deny_gid']) ? 'lock' : 'unlock', '$bang' => '', '$profile_uid' => intval($owner), '$preview' => feature_enabled(local_user(), 'preview') ? t('Preview') : '', '$jotplugins' => $jotplugins, '$sourceapp' => t($a->sourcename), '$defexpire' => '', '$feature_expire' => false, '$expires' => t('Set expiration date')));
    $ob = get_observer_hash();
    if ($itm[0]['author_xchan'] === $ob || $itm[0]['owner_xchan'] === $ob) {
        $o .= '<br /><br /><a class="page-delete-link" href="item/drop/' . $itm[0]['id'] . '" >' . t('Delete Webpage') . '</a><br />';
    }
    return $o;
}
Ejemplo n.º 12
0
function editpost_content(&$a)
{
    $o = '';
    if (!local_channel()) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    $post_id = argc() > 1 ? intval(argv(1)) : 0;
    if (!$post_id) {
        notice(t('Item not found') . EOL);
        return;
    }
    $itm = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d and author_xchan = '%s' LIMIT 1", intval($post_id), intval(local_channel()), dbesc(get_observer_hash()));
    if (!count($itm)) {
        notice(t('Item is not editable') . EOL);
        return;
    }
    $plaintext = true;
    //	if(feature_enabled(local_channel(),'richtext'))
    //		$plaintext = false;
    $channel = $a->get_channel();
    $a->page['htmlhead'] .= replace_macros(get_markup_template('jot-header.tpl'), array('$baseurl' => $a->get_baseurl(), '$editselect' => $plaintext ? 'none' : '/(profile-jot-text|prvmail-text)/', '$ispublic' => '&nbsp;', '$geotag' => $geotag, '$nickname' => $channel['channel_address'], '$expireswhen' => t('Expires YYYY-MM-DD HH:MM'), '$confirmdelete' => t('Delete item?')));
    if ($itm[0]['item_flags'] & ITEM_OBSCURED) {
        $key = get_config('system', 'prvkey');
        if ($itm[0]['title']) {
            $itm[0]['title'] = crypto_unencapsulate(json_decode_plus($itm[0]['title']), $key);
        }
        if ($itm[0]['body']) {
            $itm[0]['body'] = crypto_unencapsulate(json_decode_plus($itm[0]['body']), $key);
        }
    }
    $tpl = get_markup_template("jot.tpl");
    $jotplugins = '';
    $jotnets = '';
    call_hooks('jot_tool', $jotplugins);
    call_hooks('jot_networks', $jotnets);
    $channel = $a->get_channel();
    //$tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
    $voting = feature_enabled(local_channel(), 'consensus_tools');
    $category = '';
    $catsenabled = feature_enabled(local_channel(), 'categories') ? 'categories' : '';
    if ($catsenabled) {
        $itm = fetch_post_tags($itm);
        $cats = get_terms_oftype($itm[0]['term'], TERM_CATEGORY);
        foreach ($cats as $cat) {
            if (strlen($category)) {
                $category .= ', ';
            }
            $category .= $cat['term'];
        }
    }
    if ($itm[0]['attach']) {
        $j = json_decode($itm[0]['attach'], true);
        if ($j) {
            foreach ($j as $jj) {
                $itm[0]['body'] .= "\n" . '[attachment]' . basename($jj['href']) . ',' . $jj['revision'] . '[/attachment]' . "\n";
            }
        }
    }
    $cipher = get_pconfig(get_app()->profile['profile_uid'], 'system', 'default_cipher');
    if (!$cipher) {
        $cipher = 'aes256';
    }
    $editor = replace_macros($tpl, array('$return_path' => $_SESSION['return_url'], '$action' => 'item', '$share' => t('Edit'), '$bold' => t('Bold'), '$italic' => t('Italic'), '$underline' => t('Underline'), '$quote' => t('Quote'), '$code' => t('Code'), '$upload' => t('Upload photo'), '$attach' => t('Attach file'), '$weblink' => t('Insert web link'), '$youtube' => t('Insert YouTube video'), '$video' => t('Insert Vorbis [.ogg] video'), '$audio' => t('Insert Vorbis [.ogg] audio'), '$setloc' => t('Set your location'), '$noloc' => t('Clear browser location'), '$voting' => t('Toggle voting'), '$feature_voting' => $voting, '$consensus' => $itm[0]['item_flags'] & ITEM_CONSENSUS ? 1 : 0, '$wait' => t('Please wait'), '$permset' => t('Permission settings'), '$ptyp' => $itm[0]['type'], '$content' => undo_post_tagging($itm[0]['body']), '$post_id' => $post_id, '$parent' => $itm[0]['parent'] != $itm[0]['id'] ? $itm[0]['parent'] : '', '$baseurl' => $a->get_baseurl(), '$defloc' => $channel['channel_location'], '$visitor' => false, '$public' => t('Public post'), '$jotnets' => $jotnets, '$title' => htmlspecialchars($itm[0]['title'], ENT_COMPAT, 'UTF-8'), '$placeholdertitle' => t('Title (optional)'), '$category' => $category, '$placeholdercategory' => t('Categories (optional, comma-separated list)'), '$emtitle' => t('Example: bob@example.com, mary@example.com'), '$lockstate' => $lockstate, '$acl' => '', '$bang' => '', '$profile_uid' => local_channel(), '$preview' => t('Preview'), '$jotplugins' => $jotplugins, '$sourceapp' => t($a->sourcename), '$catsenabled' => $catsenabled, '$defexpire' => datetime_convert('UTC', date_default_timezone_get(), $itm[0]['expires']), '$feature_expire' => feature_enabled(get_app()->profile['profile_uid'], 'content_expire') && !$webpage ? true : false, '$expires' => t('Set expiration date'), '$feature_encrypt' => feature_enabled(get_app()->profile['profile_uid'], 'content_encrypt') && !$webpage ? true : false, '$encrypt' => t('Encrypt text'), '$cipher' => $cipher, '$expiryModalOK' => t('OK'), '$expiryModalCANCEL' => t('Cancel')));
    $o .= replace_macros(get_markup_template('edpost_head.tpl'), array('$title' => t('Edit post'), '$editor' => $editor));
    return $o;
}